#1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2003
    Location
    Madison
    Posts
    419
    Rep Power
    36

    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. #2
  3. Contributing User
    Devshed Supreme Being (6500+ posts)

    Join Date
    Jan 2003
    Location
    USA
    Posts
    7,156
    Rep Power
    2222
    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/ .
  4. #3
  5. Banned ;)
    Devshed Supreme Being (6500+ posts)

    Join Date
    Nov 2001
    Location
    Woodland Hills, Los Angeles County, California, USA
    Posts
    9,625
    Rep Power
    4247
    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.
  6. #4
  7. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2003
    Location
    Madison
    Posts
    419
    Rep Power
    36
    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
  8. #5
  9. Contributing User
    Devshed Supreme Being (6500+ posts)

    Join Date
    Jan 2003
    Location
    USA
    Posts
    7,156
    Rep Power
    2222
    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/3...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.
  10. #6
  11. Banned ;)
    Devshed Supreme Being (6500+ posts)

    Join Date
    Nov 2001
    Location
    Woodland Hills, Los Angeles County, California, USA
    Posts
    9,625
    Rep Power
    4247
    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.h...5&pagenumber=2

    Hope this helps :)
  12. #7
  13. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2003
    Location
    Madison
    Posts
    419
    Rep Power
    36
    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.
  14. #8
  15. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2014
    Posts
    2
    Rep Power
    0
    Originally Posted by 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.
    I am completely new to all this but wish to benefit from Steven's book and facing same issue.
    Could somebody make a tutorial on how to compile and run daytimetcpcli.c on ubuntu ?
  16. #9
  17. Contributing User
    Devshed Supreme Being (6500+ posts)

    Join Date
    Jan 2003
    Location
    USA
    Posts
    7,156
    Rep Power
    2222
    First, pj_dev, it is rather rude to hijack somebody else's thread, especially when it's been inactive for more than a decade. If you have a question or request, then you need to start your own thread.

    In order to compile a C program under Linux, of which ubuntu is a distribution, you simply compile it just as you would any other C program. You do have gcc, don't you? You do know how to use gcc, don't you? Fortunately, sockets are such an integral part of UNIX and Linux that you don't need to do anything special to compile a sockets program, unlike the situation under Windows.

    To run an executable that you create, you run it. Just as you would any executable under Linux. I really don't understand why you would need to have asked that question.

    I had started writing a quick-start page for sockets programming, one that addresses both Linux and Windows. It's still very rough and definitely not ready for prime time. It's not linked to yet, but I did upload it to my site in response to another forum member's questions regarding Winsock (the Windows version of sockets). The URL is DWise1's Sockets Quick Start. Share and enjoy!
  18. #10
  19. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2014
    Posts
    2
    Rep Power
    0
    I innocently asked that question?
    I really didn't get how I could be rude !
    Anyways I am really enthusiastic about socket programming :)
  20. #11
  21. Contributing User
    Devshed Supreme Being (6500+ posts)

    Join Date
    Jan 2003
    Location
    USA
    Posts
    7,156
    Rep Power
    2222
    Already explained it to you. Basic common forum etiquette. Just let you know so that you can behave properly next time. Now please deal with the programming questions rather than make a show of how much your delicate feelings have been hurt.
  22. #12
  23. Contributing User
    Devshed Supreme Being (6500+ posts)

    Join Date
    Jan 2003
    Location
    USA
    Posts
    7,156
    Rep Power
    2222
    I had never bought Stevens' books, deeming them too expensive, but a co-worker has added UNIX Network Programming to our departmental library. I tried looking for that sample program, daytimetcpcli.c, but it's not listed in the table of contents nor in the index. At the very least, why don't you indicate what page it's listed on? If you expect to receive help for free, then you shouldn't make it harder for us to help you.

    One thing I noticed about the code is that it is not ANSI C (AKA C89), but rather K&R C. K&R C has been deprecated and, I believe, is no longer supported by most, if not by any, modern compilers. Unless your compiler has an option that allows it to compile K&R, then you will need to convert that code to ANSI C. Have you already done this? I do not know, because you didn't give us any indication of what your problem is.

    In the absence of any information about your own skill and knowledge levels, we naturally assume certain things:
    1. That you have learned C and are sufficiently conversant in it.
    2. That you know how to write code using an editor.
    3. That you know how to compile code.
    4. That you know what error messages and warnings are and know how to read them.
    5. That you know how to run the executable that you have built.

    The question that you posted makes it appear that you have no idea how to use a compile nor how to run an executable. If that impression that you had given is incorrect, then you need to correct it. If you have indeed tried to compile the code and encountered problems in that attempt, then that is not the question that you had asked and you need to describe the problem to us. Until you clearly state the problem to us, we are left to trying to make guesses and hence cannot help you.

    BTW, I did point you to a tutorial describing how to compile and run a sockets program under Linux, which is what you asked for. I believe that the proper response would have been a "thank you" instead of the bitch-and-moan you posted.

IMN logo majestic logo threadwatch logo seochat tools logo