|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
Stop making mediocre tutorials.The best tutorials are video! Camtasia Studio makes it easy to create engaging, buzz-building screen videos at any size, in any popular format. Download the free trial!
|
|
#1
|
|||
|
|||
|
richard stevens unp.h
I am trying to start with UNIX Network Programming, I'm on Linux and FreeBSD 5.0.
I followed the instructions, but when I try make in "intro" I get: make gcc -g -O2 -Wall -o daytimetcpcli daytimetcpcli.o ../libunp.a daytimetcpcli.o: In function `main': /root/Desktop/netprog/1/unpv12e/intro/daytimetcpcli.c:11: undefined reference to `err_quit' /root/Desktop/netprog/1/unpv12e/intro/daytimetcpcli.c:28: undefined reference to `err_sys' /root/Desktop/netprog/1/unpv12e/intro/daytimetcpcli.c:31: undefined reference to `err_sys' /root/Desktop/netprog/1/unpv12e/intro/daytimetcpcli.c:23: undefined reference to `err_sys' /root/Desktop/netprog/1/unpv12e/intro/daytimetcpcli.c:20: undefined reference to `err_quit' /root/Desktop/netprog/1/unpv12e/intro/daytimetcpcli.c:14: undefined reference to `err_sys' *** Error code 1 Additionally, when I try to complie the first example: cc daytimetcpcli.c /var/tmp//ccrc1hKZ.o: In function `main': /var/tmp//ccrc1hKZ.o(.text+0x22): undefined reference to `err_quit' /var/tmp//ccrc1hKZ.o(.text+0x4c): undefined reference to `err_sys' /var/tmp//ccrc1hKZ.o(.text+0xb6): undefined reference to `err_quit' /var/tmp//ccrc1hKZ.o(.text+0xe1): undefined reference to `err_sys' /var/tmp//ccrc1hKZ.o(.text+0x140): undefined reference to `err_sys' /var/tmp//ccrc1hKZ.o(.text+0x158): undefined reference to `err_sys' Here is the source: #include "unp.h" int main(int argc, char **argv) { int sockfd, n; char recvline[MAXLINE + 1]; struct sockaddr_in servaddr; if (argc != 2) err_quit("usage: a.out <IPaddress>"); if ( (sockfd = socket(AF_INET, SOCK_STREAM, 0)) < 0) err_sys("socket error"); bzero(&servaddr, sizeof(servaddr)); servaddr.sin_family = AF_INET; servaddr.sin_port = htons(13); /* daytime server */ if (inet_pton(AF_INET, argv[1], &servaddr.sin_addr) <= 0) err_quit("inet_pton error for %s", argv[1]); if (connect(sockfd, (SA *) &servaddr, sizeof(servaddr)) < 0) err_sys("connect error"); while ( (n = read(sockfd, recvline, MAXLINE)) > 0) { recvline[n] = 0; /* null terminate */ if (fputs(recvline, stdout) == EOF) err_sys("fputs error"); } if (n < 0) err_sys("read error"); exit(0); } And unp.h can be viewed at madisonip.com/netprog/unp.h I'm quite new to all this, your help is much appreciated. Thanks for your time! |
|
#2
|
||||
|
||||
|
Those are linker errors. The code for the err_* functions must be in a library that you have not linked in.
From your header file, it appears that the author had created the err_* functions along with all those wrappers, so there should either be a library that contains them or the source code should be listed somewhere from which you can create the library yourself or include the code in your program. BTW, although Stevens' books are considered something of the "Bible", if you get bogged down in the details you might consider a "tract" to help you get started. "The Pocket Guide to TCP/IP Sockets: C Version" by Michael J. Donahoo and Kenneth L. Calvert (second edition title: "TCP/IP Sockets in C: Practical Guide for Programmers") is about 130 pages long and costs $15. Instead of wrappers, they use the actual BSD sockets API -- it's a lot simpler from what I saw in that header file. It'll get you started quickly, then with Stevens you can dig deeper into the subject. The book's web site with code listing and other materials is at http://cs.baylor.edu/~donahoo/PocketSocket/ . |
|
#3
|
||||
|
||||
|
You need to build libunp.a first before you compile the intro code. Here's the top part of the README file:
Code:
cd <some-directory-of-your-choosing>
gunzip -c unpv12e.tar.gz | tar xvf -
cd unpv12e
./configure # try to figure out all implementation differences
cd lib # build the basic library that all programs need
make # use "gmake" everywhere on BSD/OS systems
cd ../libfree # continue building the basic library
make
cd ../libgai # the getaddrinfo() and getnameinfo() functions
make
cd ../libroute # only if your system supports 4.4BSD style routing sockets
make # only if your system supports 4.4BSD style routing sockets
cd ../libxti # only if your system supports XTI
make # only if your system supports XTI
cd ../intro # build and test a basic client program
make daytimetcpcli
./daytimetcpcli 127.0.0.1
At the very minimum, you need to build lib before you compile some of the intro programs. BTW most of rstevens's wrapper functions are very thin wrappers around the API functions. All that his wrapper functions do is to execute the API function, check the return code to make sure there's no error and, exit if there's an error or, return the value if there is no error. For example: Code:
void *
Calloc(size_t n, size_t size)
{
void *ptr;
if ( (ptr = calloc(n, size)) == NULL)
err_sys("calloc error");
return(ptr);
}
void
Close(int fd)
{
if (close(fd) == -1)
err_sys("close error");
}
Hope this helps ![]() Last edited by Scorpions4ever : April 29th, 2003 at 03:35 PM. |
|
#4
|
|||
|
|||
|
This is the problem, it won't build:
madisonip# cd lib madisonip# make gcc -g -O2 -Wall -c mcast_leave.c mcast_leave.c: In function `mcast_leave': mcast_leave.c:26: `IPV6_DROP_MEMBERSHIP' undeclared (first use in this function) mcast_leave.c:26: (Each undeclared identifier is reported only once mcast_leave.c:26: for each function it appears in.) *** Error code 1 Stop in /root/Desktop/netprog/1/unpv12e/lib. OR with gmake: madisonip# gmake gcc -g -O2 -Wall -c -o mcast_leave.o mcast_leave.c mcast_leave.c: In function `mcast_leave': mcast_leave.c:26: `IPV6_DROP_MEMBERSHIP' undeclared (first use in this function) mcast_leave.c:26: (Each undeclared identifier is reported only once mcast_leave.c:26: for each function it appears in.) gmake: *** [mcast_leave.o] Error 1 After a make clean: madisonip# gmake clean rm -f core core.* *.core *.o temp.* *.out typescript* *.lc *.lh *.bsdi *.sparc *.uw madisonip# gmake gcc -g -O2 -Wall -c -o connect_nonb.o connect_nonb.c gcc -g -O2 -Wall -c -o connect_timeo.o connect_timeo.c gcc -g -O2 -Wall -c -o daemon_inetd.o daemon_inetd.c gcc -g -O2 -Wall -c -o daemon_init.o daemon_init.c gcc -g -O2 -Wall -c -o dg_cli.o dg_cli.c gcc -g -O2 -Wall -c -o dg_echo.o dg_echo.c gcc -g -O2 -Wall -c -o error.o error.c gcc -g -O2 -Wall -c -o get_ifi_info.o get_ifi_info.c gcc -g -O2 -Wall -c -o gf_time.o gf_time.c gf_time.c: In function `gf_time': gf_time.c:14: warning: passing arg 1 of `ctime' from incompatible pointer type gcc -g -O2 -Wall -c -o host_serv.o host_serv.c gcc -g -O2 -Wall -c -o isfdtype.o isfdtype.c gcc -g -O2 -Wall -c -o mcast_leave.o mcast_leave.c mcast_leave.c: In function `mcast_leave': mcast_leave.c:26: `IPV6_DROP_MEMBERSHIP' undeclared (first use in this function) mcast_leave.c:26: (Each undeclared identifier is reported only once mcast_leave.c:26: for each function it appears in.) gmake: *** [mcast_leave.o] Error 1 So I'm still lost. I'd really like to get this working (obviously, I can't even start the book yet!) Any ideas? Thanks again! Also feel free to email me, nleonard@madisonip.com |
|
#5
|
||||
|
||||
|
Do a Google on IPV6_DROP_MEMBERSHIP
A number of the hits talk about IPV6_DROP_MEMBERSHIP not being defined in FreeBSD and some that it's an obsolete socket option. Here's one link that offers a patch: http://www.geocrawler.com/archives/.../2/100/3263505/ This option has to do with IPv6, which does not apply to what most any of us are doing or will do (we're still in version 4). Before private networks and NAT, IPv6 was supposed to save us from running out of IP addresses, but now its future seems less certain. It's supposed to make routing more efficient, I've heard, so it might have a future in the backbone. Unfortunately, Stevens has died. But someone has made his home page available again at http://www.kohala.com/start/ . Perhaps there's something there about this problem. EDIT: At http://www.kohala.com/start/unp.html there are links to an errata sheet, to a missing netdefs.h file, and to source-code tarballs. My suspicion is that the header file that used to contain the IPV6_DROP_MEMBERSHIP definition got changed and IPV6_DROP_MEMBERSHIP got dropped. My suggestion would be to go in and remove that reference from the source code, if that is feasible. SECOND EDIT: What Scorpions says below. Last edited by dwise1_aol : April 30th, 2003 at 11:16 PM. |
|
#6
|
||||
|
||||
|
You'll need to change the following:
mcast_leave.c: Change IPV6_DROP_MEMBERSHIP to IPV6_LEAVE_GROUP mcast_join.c: Change IPV6_ADD_MEMBERSHIP to IPV6_JOIN_GROUP IIRC these names were changed by a later RFC (2553, which obsoletes 2133 and is obsoleted by 3493). Matter of fact, I was grousing about this, a while ago, about this very issue: http://forums.devshed.com/t53905/s....15&pagenumber=2 Hope this helps ![]() |
|
#7
|
|||
|
|||
|
THANKS! That did it. You guys are pretty helpful....
Any chance anyone knows of a good college to study networking and network programming? (looking for something more advanced than most general CS programs as I'm already a CCNP and have a bit of background...) Anyway, thank you very much!!! Scorpions4ever's reply did the trick. |
![]() |
| Viewing: Dev Shed Forums > Programming Languages > C Programming > richard stevens unp.h |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|