C Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming LanguagesC Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
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  
Old April 28th, 2003, 11:11 PM
namotco namotco is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Feb 2003
Location: Madison
Posts: 374 namotco User rank is Sergeant Major (2000 - 5000 Reputation Level)namotco User rank is Sergeant Major (2000 - 5000 Reputation Level)namotco User rank is Sergeant Major (2000 - 5000 Reputation Level)namotco User rank is Sergeant Major (2000 - 5000 Reputation Level)namotco User rank is Sergeant Major (2000 - 5000 Reputation Level)namotco User rank is Sergeant Major (2000 - 5000 Reputation Level) 
Time spent in forums: 1 Day 18 h 8 m 52 sec
Reputation Power: 30
Send a message via AIM to namotco
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!

Reply With Quote
  #2  
Old April 29th, 2003, 09:46 AM
dwise1_aol's Avatar
dwise1_aol dwise1_aol is offline
Contributing User
Dev Shed Expert (3500 - 3999 posts)
 
Join Date: Jan 2003
Location: USA
Posts: 3,803 dwise1_aol User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)dwise1_aol User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)dwise1_aol User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)dwise1_aol User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)dwise1_aol User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)dwise1_aol User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)dwise1_aol User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)dwise1_aol User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)dwise1_aol User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)dwise1_aol User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)dwise1_aol User rank is Lieutenant Colonel (40000 - 50000 Reputation Level) 
Time spent in forums: 1 Month 11 h 40 m 35 sec
Reputation Power: 437
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/ .

Reply With Quote
  #3  
Old April 29th, 2003, 03:32 PM
Scorpions4ever's Avatar
Scorpions4ever Scorpions4ever is offline
Banned ;)
Dev Shed God 5th Plane (7000 - 7499 posts)
 
Join Date: Nov 2001
Location: Glendale, Los Angeles County, California, USA
Posts: 7,442 Scorpions4ever User rank is Major General (70000 - 90000 Reputation Level)Scorpions4ever User rank is Major General (70000 - 90000 Reputation Level)Scorpions4ever User rank is Major General (70000 - 90000 Reputation Level)Scorpions4ever User rank is Major General (70000 - 90000 Reputation Level)Scorpions4ever User rank is Major General (70000 - 90000 Reputation Level)Scorpions4ever User rank is Major General (70000 - 90000 Reputation Level)Scorpions4ever User rank is Major General (70000 - 90000 Reputation Level)Scorpions4ever User rank is Major General (70000 - 90000 Reputation Level)Scorpions4ever User rank is Major General (70000 - 90000 Reputation Level)Scorpions4ever User rank is Major General (70000 - 90000 Reputation Level)Scorpions4ever User rank is Major General (70000 - 90000 Reputation Level)Scorpions4ever User rank is Major General (70000 - 90000 Reputation Level)Scorpions4ever User rank is Major General (70000 - 90000 Reputation Level)Scorpions4ever User rank is Major General (70000 - 90000 Reputation Level) 
Time spent in forums: 1 Month 1 h 22 m 8 sec
Reputation Power: 797
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.

Reply With Quote
  #4  
Old April 30th, 2003, 04:58 PM
namotco namotco is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Feb 2003
Location: Madison
Posts: 374 namotco User rank is Sergeant Major (2000 - 5000 Reputation Level)namotco User rank is Sergeant Major (2000 - 5000 Reputation Level)namotco User rank is Sergeant Major (2000 - 5000 Reputation Level)namotco User rank is Sergeant Major (2000 - 5000 Reputation Level)namotco User rank is Sergeant Major (2000 - 5000 Reputation Level)namotco User rank is Sergeant Major (2000 - 5000 Reputation Level) 
Time spent in forums: 1 Day 18 h 8 m 52 sec
Reputation Power: 30
Send a message via AIM to namotco
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

Reply With Quote
  #5  
Old April 30th, 2003, 05:56 PM
dwise1_aol's Avatar
dwise1_aol dwise1_aol is offline
Contributing User
Dev Shed Expert (3500 - 3999 posts)
 
Join Date: Jan 2003
Location: USA
Posts: 3,803 dwise1_aol User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)dwise1_aol User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)dwise1_aol User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)dwise1_aol User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)dwise1_aol User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)dwise1_aol User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)dwise1_aol User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)dwise1_aol User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)dwise1_aol User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)dwise1_aol User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)dwise1_aol User rank is Lieutenant Colonel (40000 - 50000 Reputation Level) 
Time spent in forums: 1 Month 11 h 40 m 35 sec
Reputation Power: 437
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.

Reply With Quote
  #6  
Old April 30th, 2003, 06:58 PM
Scorpions4ever's Avatar
Scorpions4ever Scorpions4ever is offline
Banned ;)
Dev Shed God 5th Plane (7000 - 7499 posts)
 
Join Date: Nov 2001
Location: Glendale, Los Angeles County, California, USA
Posts: 7,442 Scorpions4ever User rank is Major General (70000 - 90000 Reputation Level)Scorpions4ever User rank is Major General (70000 - 90000 Reputation Level)Scorpions4ever User rank is Major General (70000 - 90000 Reputation Level)Scorpions4ever User rank is Major General (70000 - 90000 Reputation Level)Scorpions4ever User rank is Major General (70000 - 90000 Reputation Level)Scorpions4ever User rank is Major General (70000 - 90000 Reputation Level)Scorpions4ever User rank is Major General (70000 - 90000 Reputation Level)Scorpions4ever User rank is Major General (70000 - 90000 Reputation Level)Scorpions4ever User rank is Major General (70000 - 90000 Reputation Level)Scorpions4ever User rank is Major General (70000 - 90000 Reputation Level)Scorpions4ever User rank is Major General (70000 - 90000 Reputation Level)Scorpions4ever User rank is Major General (70000 - 90000 Reputation Level)Scorpions4ever User rank is Major General (70000 - 90000 Reputation Level)Scorpions4ever User rank is Major General (70000 - 90000 Reputation Level) 
Time spent in forums: 1 Month 1 h 22 m 8 sec
Reputation Power: 797
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

Reply With Quote
  #7  
Old May 1st, 2003, 05:51 PM
namotco namotco is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Feb 2003
Location: Madison
Posts: 374 namotco User rank is Sergeant Major (2000 - 5000 Reputation Level)namotco User rank is Sergeant Major (2000 - 5000 Reputation Level)namotco User rank is Sergeant Major (2000 - 5000 Reputation Level)namotco User rank is Sergeant Major (2000 - 5000 Reputation Level)namotco User rank is Sergeant Major (2000 - 5000 Reputation Level)namotco User rank is Sergeant Major (2000 - 5000 Reputation Level) 
Time spent in forums: 1 Day 18 h 8 m 52 sec
Reputation Power: 30
Send a message via AIM to namotco
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.

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesC Programming > richard stevens unp.h


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 4 hosted by Hostway