Thread: Linux/Unix time server

  1. #1
    Registered User Annonymous's Avatar
    Join Date
    Apr 2011
    Location
    Jackson, New Jersey, United States
    Posts
    302

    Linux/Unix time server

    Hey, I just bought a book to teach myself how to program Linux/Unix sockets. The first exercise is to take the time server from the book as is, and code it on my box. Now the problem is that when I compile and "TRY" to run the program it give this error: ~/Documents$ gcc time_server.c -o time
    time_server.c:1:17: fatal error: unp.h: No such file or directory
    compilation terminated.

    Here is the code=>
    Code:
    #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);
        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;
        if (fputs(recvline, stdout) == EOF)
            err_sys("fputs error");
        }
        if (n < 0)
            err_sys("read error");
        exit(1);
    }
    Why won't it compile? Maybe the header is wrong. Maybe I do not have the required libraries downloaded...Any help will be appreciated!
    Last edited by Annonymous; 04-17-2011 at 07:33 PM.

  2. #2
    Registered User Annonymous's Avatar
    Join Date
    Apr 2011
    Location
    Jackson, New Jersey, United States
    Posts
    302
    wow everyone here has been a great help lol

  3. #3
    Registered User
    Join Date
    Sep 2004
    Location
    California
    Posts
    3,268
    Quote Originally Posted by Annonymous View Post
    wow everyone here has been a great help lol
    Probably because no one here has heard of unp.h. A quick google search tells us why. unp.h is a custom header file written by the author of the book.

    Next time, instead of waiting 2 days for someone to answer your question for you, maybe you should spend 10 seconds searching google first.
    bit∙hub [bit-huhb] n. A source and destination for information.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. UNIX (Linux, BSD, etc) Programming :: UNIX
    By kuphryn in forum Linux Programming
    Replies: 6
    Last Post: 04-01-2004, 08:44 PM
  2. Server Client on UNIX
    By Wisefool in forum C Programming
    Replies: 5
    Last Post: 10-23-2003, 04:05 PM
  3. Unix/Linux
    By xiao guang in forum Tech Board
    Replies: 5
    Last Post: 07-30-2003, 08:06 AM
  4. Linux - Unix
    By MethodMan in forum Linux Programming
    Replies: 3
    Last Post: 04-01-2002, 08:40 PM

Tags for this Thread