Compile the 'sock' program in the book 'TCP/IP Illustrated Vol.1'
Web Server forum
Back To The Forum Home!Search!Private Messaging System

Web Server Talk Web Server Talk > Unix and Linux reviews > Free Unix support > Unix Programming > Compile the 'sock' program in the book 'TCP/IP Illustrated Vol.1'




  Last Thread   Next Thread Next
  Show Printable Version Email this Page Subscribe to this Thread      Post New Thread    Post A Reply      

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


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
11-20-05 10:51 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 t
he
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 simil
ar
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 XXXX 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)





[ Post a follow-up to this message ]



    Re: Compile the 'sock' program in the book 'TCP/IP Illustrated Vol.1'  
Michael Wojcik


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
11-21-05 07:49 AM


In article <87lkzjpbsw.fsf@narke.yellow.line>, Steven Woody <anti-spam.narkewoody@gmail.com.
dont-post-to> writes:
>
> i am running Linux and want to compile and use the 'sock' program comes wi
th
> 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 cad
dr_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 sim
ilar
> 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                  michael.wojcik@microfocus.com

Today's Carnivore bait: Distracted by the Anthrax song, I let my bin,
laden with goods, crash into a bush.





[ Post a follow-up to this message ]



    Re: Compile the 'sock' program in the book 'TCP/IP Illustrated Vol.1'  
Steven Woody


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
11-21-05 12:49 PM


Michael Wojcik wrote:
> In article <87lkzjpbsw.fsf@narke.yellow.line>, Steven Woody <anti-spam.nar
kewoody@gmail.com.dont-post-to> writes: 
>
> 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.)
> 
>
> 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.

> 
>
> 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                  michael.wojcik@microfocus.com
>
> Today's Carnivore bait: Distracted by the Anthrax song, I let my bin,
> laden with goods, crash into a bush.






[ Post a follow-up to this message ]



    Sponsored Links  




 





   All times are GMT. The time now is 04:54 PM.      Post New Thread    Post A Reply      
  Last Thread   Next Thread Next


Most Popular forums 

Forum Jump:
Rate This Thread:

Forum Rules:
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is OFF
vB code is ON
Smilies are ON
[IMG] code is OFF
 
Medical and Health forum | Computer Games Reviews | Graphics design forum

Back To The Top
Home | Usercp | Faq | Register