Networking Forums

Networking Forums > Computer Networking > Linux Networking > Compile the 'sock' program in the book 'TCP/IP Illustrated Vol.1'

Reply
Thread Tools Display Modes

Compile the 'sock' program in the book 'TCP/IP Illustrated Vol.1'

 
 
Steven Woody
Guest
Posts: n/a

 
      11-20-2005, 02:40 PM
hi,

i am running Linux and want to compile and use the 'sock' program comes with
Stevens's book 'TCP/IP Illustrated Vol.1'. but the code simply can't pass the
compiler with following error,

,----
| bash-3.00$ make
| gcc -ansi -Wall -Dsun -D__STDC__=0 -c -o loop.o loop.c
| <command line>:5:1: warning: "__STDC__" redefined
| loop.c: In function `loop':
| loop.c:117: error: `caddr_t' undeclared (first use in this function)
| loop.c:117: error: (Each undeclared identifier is reported only once
| loop.c:117: error: for each function it appears in.)
| loop.c:127: error: parse error before numeric constant
| make: *** [loop.o] Error 1
`----

in fact, in the Linux system, there is a sys/types.h which defined the caddr_t
type and this file seems have been already included in the source code, so i
don't know why the type still can not be recognized.

had anyone here compiled the code with success? or, is there any other similar
tool freely available ?

thanks.

--
steven woody (id: narke)

Jesse: You want to know why I wrote that stupid book?
Celine: Why?
Jesse: So that you might come to a reading in Paris and I could walk
up to you and ask, "Where the fuck were you?"
Celine: [laughing] No - you thought I'd be here today?
Jesse: I'm serious. I think I wrote it, in a way, to try to find you.
Celine: Okay, that's - I know that's not true, but that's sweet of you
to say.
Jesse: I think it is true.

- Before Sunset (2004)
 
Reply With Quote
 
 
 
 
Michael Wojcik
Guest
Posts: n/a

 
      11-21-2005, 04:09 AM

In article <(E-Mail Removed)>, Steven Woody <anti-(E-Mail Removed)-post-to> writes:
>
> i am running Linux and want to compile and use the 'sock' program comes with
> Stevens's book 'TCP/IP Illustrated Vol.1'. but the code simply can't pass the
> compiler with following error,
>
> | bash-3.00$ make
> | gcc -ansi -Wall -Dsun -D__STDC__=0 -c -o loop.o loop.c
> | <command line>:5:1: warning: "__STDC__" redefined


Why are you defining __STDC__ at all, much less to 0? __STDC__
should always be defined by the implementation. If this is from the
makefile that you got with the source for sock, be aware that _TCP/IP
Illustrated_ v1, while an excellent book, is more than ten years old,
and the makefile might require some reworking for newer systems.
(Though even in 1994 defining __STDC__ explicitly was almost certain-
ly wrong.)

> | loop.c: In function `loop':
> | loop.c:117: error: `caddr_t' undeclared (first use in this function)
> ...
>
> in fact, in the Linux system, there is a sys/types.h which defined the caddr_t
> type and this file seems have been already included in the source code, so i
> don't know why the type still can not be recognized.


Because it hasn't been defined. Including sys/types.h very likely
doesn't guarantee that a particular typedef in it has been processed,
because in most implementations sys/types.h is full of conditional-
inclusion directives (#if and friends).

In the Linux sys/types.h I'm looking at now, caddr_t is only defined
if the macro __USE_BSD is defined. Note that this is an identifier
reserved to the implementation, so you shouldn't be defining it
(unless instructed to by the implementation's documentation - and
that would be a poor choice by the implementor).

As it turns out, __USE_BSD is defined for you (in features.h, which
is automatically included by a raft of other headers) if the "feature
test macro" _BSD_SOURCE is defined. You define _BSD_SOURCE and you
get caddr_t. The GCC default on Linux (and, I think, most Unix
platforms, using the stock GCC build) is to define _BSD_SOURCE unless
you use the -ansi flag. If you do use -ansi (or an equivalent), you
have to define _BSD_SOURCE to get the BSD types, macros, and so on.

You can read more about feature test macros in the Single Unix
Specification, which is available free of charge at [1].

So as a first attempt, I suggest getting rid of that bogus definition
of __STDC__ and substituting a -D_BSD_SOURCE.

> had anyone here compiled the code with success? or, is there any other similar
> tool freely available ?


Stevens mentions some similar tools right in _TCP/IP Illustrated_, in
the appendix that discusses the sock program. One he doesn't mention
(I believe it appeared later) is netcat, which you may already have
as "nc".


1. http://www.opengroup.org/

--
Michael Wojcik (E-Mail Removed)

Today's Carnivore bait: Distracted by the Anthrax song, I let my bin,
laden with goods, crash into a bush.
 
Reply With Quote
 
Steven Woody
Guest
Posts: n/a

 
      11-21-2005, 08:16 AM

Michael Wojcik wrote:
> In article <(E-Mail Removed)>, Steven Woody <anti-(E-Mail Removed)-post-to> writes:
> >
> > i am running Linux and want to compile and use the 'sock' program comes with
> > Stevens's book 'TCP/IP Illustrated Vol.1'. but the code simply can't pass the
> > compiler with following error,
> >
> > | bash-3.00$ make
> > | gcc -ansi -Wall -Dsun -D__STDC__=0 -c -o loop.o loop.c
> > | <command line>:5:1: warning: "__STDC__" redefined

>
> Why are you defining __STDC__ at all, much less to 0? __STDC__
> should always be defined by the implementation. If this is from the
> makefile that you got with the source for sock, be aware that _TCP/IP
> Illustrated_ v1, while an excellent book, is more than ten years old,
> and the makefile might require some reworking for newer systems.
> (Though even in 1994 defining __STDC__ explicitly was almost certain-
> ly wrong.)
>
> > | loop.c: In function `loop':
> > | loop.c:117: error: `caddr_t' undeclared (first use in this function)
> > ...
> >
> > in fact, in the Linux system, there is a sys/types.h which defined the caddr_t
> > type and this file seems have been already included in the source code, so i
> > don't know why the type still can not be recognized.

>
> Because it hasn't been defined. Including sys/types.h very likely
> doesn't guarantee that a particular typedef in it has been processed,
> because in most implementations sys/types.h is full of conditional-
> inclusion directives (#if and friends).
>
> In the Linux sys/types.h I'm looking at now, caddr_t is only defined
> if the macro __USE_BSD is defined. Note that this is an identifier
> reserved to the implementation, so you shouldn't be defining it
> (unless instructed to by the implementation's documentation - and
> that would be a poor choice by the implementor).
>
> As it turns out, __USE_BSD is defined for you (in features.h, which
> is automatically included by a raft of other headers) if the "feature
> test macro" _BSD_SOURCE is defined. You define _BSD_SOURCE and you
> get caddr_t. The GCC default on Linux (and, I think, most Unix
> platforms, using the stock GCC build) is to define _BSD_SOURCE unless
> you use the -ansi flag. If you do use -ansi (or an equivalent), you
> have to define _BSD_SOURCE to get the BSD types, macros, and so on.
>
> You can read more about feature test macros in the Single Unix
> Specification, which is available free of charge at [1].
>
> So as a first attempt, I suggest getting rid of that bogus definition
> of __STDC__ and substituting a -D_BSD_SOURCE.


thank you and i will try. but 'nc' you mentioned is enough to me.

>
> > had anyone here compiled the code with success? or, is there any other similar
> > tool freely available ?

>
> Stevens mentions some similar tools right in _TCP/IP Illustrated_, in
> the appendix that discusses the sock program. One he doesn't mention
> (I believe it appeared later) is netcat, which you may already have
> as "nc".
>
>
> 1. http://www.opengroup.org/
>
> --
> Michael Wojcik (E-Mail Removed)
>
> Today's Carnivore bait: Distracted by the Anthrax song, I let my bin,
> laden with goods, crash into a bush.


 
Reply With Quote
 
 
 
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
tcp/ip illustrated volume2 page4 code (recvfrom function)does notwork westnorth Linux Networking 1 08-13-2008 06:34 PM
Program Scheduler to start and end a program? Kevin Wooloff Home Networking 1 09-05-2006 04:10 PM
Anyone know a good program to compile Syslog data into reports? Andrew Vital Windows Networking 3 03-22-2006 04:38 PM
Dante as a sock server: HELP! Stef Linux Networking 0 08-07-2004 02:28 PM
Calling close(sock) in one thread doesn't make recv(sock,...) return Boris Bak Linux Networking 1 01-31-2004 11:52 PM



1 2 3 4 5 6 7 8 9 10 11