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:
  #1  
Old April 29th, 2003, 12:11 AM
namotco namotco is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Feb 2003
Location: Madison
Posts: 419 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: 2 Days 1 h 41 m 56 sec
Reputation Power: 31
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, 10:46 AM
dwise1_aol's Avatar
dwise1_aol dwise1_aol is offline
Contributing User
Dev Shed Demi-God (4500 - 4999 posts)
 
Join Date: Jan 2003
Location: USA
Posts: 4,503 dwise1_aol User rank is General 3rd Grade (Above 100000 Reputation Level)dwise1_aol User rank is General 3rd Grade (Above 100000 Reputation Level)dwise1_aol User rank is General 3rd Grade (Above 100000 Reputation Level)dwise1_aol User rank is General 3rd Grade (Above 100000 Reputation Level)dwise1_aol User rank is General 3rd Grade (Above 100000 Reputation Level)dwise1_aol User rank is General 3rd Grade (Above 100000 Reputation Level)dwise1_aol User rank is General 3rd Grade (Above 100000 Reputation Level)dwise1_aol User rank is General 3rd Grade (Above 100000 Reputation Level)dwise1_aol User rank is General 3rd Grade (Above 100000 Reputation Level)dwise1_aol User rank is General 3rd Grade (Above 100000 Reputation Level)dwise1_aol User rank is General 3rd Grade (Above 100000 Reputation Level)dwise1_aol User rank is General 3rd Grade (Above 100000 Reputation Level)dwise1_aol User rank is General 3rd Grade (Above 100000 Reputation Level)dwise1_aol User rank is General 3rd Grade (Above 100000 Reputation Level)dwise1_aol User rank is General 3rd Grade (Above 100000 Reputation Level)dwise1_aol User rank is General 3rd Grade (Above 100000 Reputation Level) 
Time spent in forums: 1 Month 2 Weeks 12 h 57 m 35 sec
Reputation Power: 1165
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, 04:32 PM
Scorpions4ever's Avatar
Scorpions4ever Scorpions4ever is offline
Banned ;)
Dev Shed God 8th Plane (8500 - 8999 posts)
 
Join Date: Nov 2001
Location: Glendale, Los Angeles County, California, USA
Posts: 8,504 Scorpions4ever User rank is General 27th Grade (Above 100000 Reputation Level)Scorpions4ever User rank is General 27th Grade (Above 100000 Reputation Level)Scorpions4ever User rank is General 27th Grade (Above 100000 Reputation Level)Scorpions4ever User rank is General 27th Grade (Above 100000 Reputation Level)Scorpions4ever User rank is General 27th Grade (Above 100000 Reputation Level)Scorpions4ever User rank is General 27th Grade (Above 100000 Reputation Level)Scorpions4ever User rank is General 27th Grade (Above 100000 Reputation Level)Scorpions4ever User rank is General 27th Grade (Above 100000 Reputation Level)Scorpions4ever User rank is General 27th Grade (Above 100000 Reputation Level)Scorpions4ever User rank is General 27th Grade (Above 100000 Reputation Level)Scorpions4ever User rank is General 27th Grade (Above 100000 Reputation Level)Scorpions4ever User rank is General 27th Grade (Above 100000 Reputation Level)Scorpions4ever User rank is General 27th Grade (Above 100000 Reputation Level)Scorpions4ever User rank is General 27th Grade (Above 100000 Reputation Level)Scorpions4ever User rank is General 27th Grade (Above 100000 Reputation Level)Scorpions4ever User rank is General 27th Grade (Above 100000 Reputation Level) 
Time spent in forums: 1 Month 1 Week 6 Days 15 h 38 m 6 sec
Reputation Power: 2790
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 04:35 PM.

Reply With Quote
  #4  
Old April 30th, 2003, 05:58 PM
namotco namotco is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Feb 2003
Location: Madison
Posts: 419 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: 2 Days 1 h 41 m 56 sec
Reputation Power: 31
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, 06:56 PM
dwise1_aol's Avatar
dwise1_aol dwise1_aol is offline
Contributing User
Dev Shed Demi-God (4500 - 4999 posts)
 
Join Date: Jan 2003
Location: USA
Posts: 4,503 dwise1_aol User rank is General 3rd Grade (Above 100000 Reputation Level)dwise1_aol User rank is General 3rd Grade (Above 100000 Reputation Level)dwise1_aol User rank is General 3rd Grade (Above 100000 Reputation Level)dwise1_aol User rank is General 3rd Grade (Above 100000 Reputation Level)dwise1_aol User rank is General 3rd Grade (Above 100000 Reputation Level)dwise1_aol User rank is General 3rd Grade (Above 100000 Reputation Level)dwise1_aol User rank is General 3rd Grade (Above 100000 Reputation Level)dwise1_aol User rank is General 3rd Grade (Above 100000 Reputation Level)dwise1_aol User rank is General 3rd Grade (Above 100000 Reputation Level)dwise1_aol User rank is General 3rd Grade (Above 100000 Reputation Level)dwise1_aol User rank is General 3rd Grade (Above 100000 Reputation Level)dwise1_aol User rank is General 3rd Grade (Above 100000 Reputation Level)dwise1_aol User rank is General 3rd Grade (Above 100000 Reputation Level)dwise1_aol User rank is General 3rd Grade (Above 100000 Reputation Level)dwise1_aol User rank is General 3rd Grade (Above 100000 Reputation Level)dwise1_aol User rank is General 3rd Grade (Above 100000 Reputation Level) 
Time spent in forums: 1 Month 2 Weeks 12 h 57 m 35 sec
Reputation Power: 1165
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 : May 1st, 2003 at 12:16 AM.

Reply With Quote
  #6  
Old April 30th, 2003, 07:58 PM
Scorpions4ever's Avatar
Scorpions4ever Scorpions4ever is offline
Banned ;)
Dev Shed God 8th Plane (8500 - 8999 posts)
 
Join Date: Nov 2001
Location: Glendale, Los Angeles County, California, USA
Posts: 8,504 Scorpions4ever User rank is General 27th Grade (Above 100000 Reputation Level)Scorpions4ever User rank is General 27th Grade (Above 100000 Reputation Level)Scorpions4ever User rank is General 27th Grade (Above 100000 Reputation Level)Scorpions4ever User rank is General 27th Grade (Above 100000 Reputation Level)Scorpions4ever User rank is General 27th Grade (Above 100000 Reputation Level)Scorpions4ever User rank is General 27th Grade (Above 100000 Reputation Level)Scorpions4ever User rank is General 27th Grade (Above 100000 Reputation Level)Scorpions4ever User rank is General 27th Grade (Above 100000 Reputation Level)Scorpions4ever User rank is General 27th Grade (Above 100000 Reputation Level)Scorpions4ever User rank is General 27th Grade (Above 100000 Reputation Level)Scorpions4ever User rank is General 27th Grade (Above 100000 Reputation Level)Scorpions4ever User rank is General 27th Grade (Above 100000 Reputation Level)Scorpions4ever User rank is General 27th Grade (Above 100000 Reputation Level)Scorpions4ever User rank is General 27th Grade (Above 100000 Reputation Level)Scorpions4ever User rank is General 27th Grade (Above 100000 Reputation Level)Scorpions4ever User rank is General 27th Grade (Above 100000 Reputation Level) 
Time spent in forums: 1 Month 1 Week 6 Days 15 h 38 m 6 sec
Reputation Power: 2790
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, 06:51 PM
namotco namotco is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Feb 2003
Location: Madison
Posts: 419 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: 2 Days 1 h 41 m 56 sec
Reputation Power: 31
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




 Free IT White Papers!
 
How to Present Effectively Online
This white paper offers practical and actionable advice on the key steps that any presenter should consider as they plan and execute a Webinar or online meeting.

 
Open Source Security Myths
Open Source Software (OSS) is computer software whose source code is available to the general public with relaxed or non-existent intellectual property restrictions (or arrangement such as the public domain), and is usually developed with the input of many contributors.

 
Power and Cooling Capacity Management for Data Centers
This paper describes the principles for achieving power and cooling capacity management.

 
Scalable, Fault-Tolerant NAS for Oracle - The Next Generation
For several years NAS has been evolving as a storage alternative for Oracle databases, and for good reason: NAS is quite often the simplest, most cost-effective storage approach for Oracle. Learn about the benefits that HP's approach to scalable NAS brings to Oracle environments in this comprehensive white paper.

 
Understanding Web Application Security Challenges
This white paper discusses many common threats and preventive measures for Web application security, and explains what you can do to help protect your organization.

 

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




© 2003-2010 by Developer Shed. All rights reserved. DS Cluster 5 Hosted by Hostway
For more Enterprise Application Development news, visit eWeek