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.