Thread: Problems with sockets under linux

  1. #1
    Registered User
    Join Date
    Sep 2004
    Posts
    17

    Problems with sockets under linux

    I've been screwing around with Sockets programming for a little while - just to see what it's like.

    Code:
    #include "../unp.h"
    #include <time.h>
    
    int main(int argc, char **argv)
    {
            int     listenfd, connfd;
            struct sockaddr_in servaddr;
            char    buff[MAXLINE];
            time_t  ticks;
    
            listenfd = Socket(AF_INET, SOCK_STREAM, 0);
    
            bzero(&servaddr, sizeof(servaddr));
            servaddr.sin_family = AF_INET; bzero(&servaddr, sizeof(servaddr));
            servaddr.sin_family = AF_INET;
            servaddr.sin_addr.s_addr = hton1(INADDR_ANY);
            servaddr.sin_port = htons(13);
    
            Bind(listenfd, (SA *) &servaddr, sizeof(servaddr));
    
            Listen(listenfd, LISTENQ);
    
            for (;;)
            {
                    connfd = Accept (listenfd, (SA *) NULL, NULL);
    
                    ticks = time(NULL);
                    snprintf(buff, sizeof(buff), "%.24s\r\n", ctime(&ticks));
                    Write(connfd, buff, strlen(buff));
    
                    Close(connfd);
            }
    }
    That's the code i'm using for a simple daytime server. Here are the errors that I'm getting:
    fatality Server # gcc server.c -o server
    In file included from server.c:1:
    ../unp.h:7:75: config.h: No such file or directory
    In file included from server.c:1:
    ../unp.h:115: error: redefinition of `struct in_pktinfo'
    ../unp.h:202:36: ../lib/addrinfo.h: No such file or directory
    ../unp.h:216: error: redefinition of `struct timespec'
    ../unp.h:296: error: conflicting types for `gai_strerror'
    /usr/include/netdb.h:639: error: previous declaration of `gai_strerror'
    ../unp.h:301: error: conflicting types for `getnameinfo'
    /usr/include/netdb.h:648: error: previous declaration of `getnameinfo'
    ../unp.h:305: error: conflicting types for `gethostname'
    /usr/include/unistd.h:783: error: previous declaration of `gethostname'
    ../unp.h:325: error: conflicting types for `inet_aton'
    /usr/include/arpa/inet.h:74: error: previous declaration of `inet_aton'
    Last edited by principii; 09-17-2004 at 03:23 PM. Reason: editing topic - said it wrong

  2. #2
    Registered User linuxdude's Avatar
    Join Date
    Mar 2003
    Location
    Louisiana
    Posts
    926
    Something is wrong withy your headers, your ../unp.h is including files that don't exist. You are also somewhere including a header that trying to define functions already included. Check your headers.

  3. #3
    Registered User
    Join Date
    Jul 2003
    Posts
    85
    or, only include what's needed... check man or your book (i'm assuming unix net prog)

  4. #4
    Registered User
    Join Date
    Sep 2004
    Posts
    17
    scrappy - I downloaded the source code for all of the programs included with unix net prog, and took unp.h from it (i didn't want to type it up myself), stuck it in a directory with subdirectories Server and Client each containing the two programs specified in chapter one of unix net prog.

  5. #5
    Crazy Fool Perspective's Avatar
    Join Date
    Jan 2003
    Location
    Canada
    Posts
    2,640
    In file included from server.c:1:
    ../unp.h:7:75: config.h: No such file or directory
    so where is config.h?

    if you want to learn socket prgramming i suggest taking a look at Beej's Guide . Its more or less the bible of learning socket programmming under unix.

  6. #6
    Registered User
    Join Date
    Sep 2004
    Posts
    17
    I figured it out. I had to use autoconf.

  7. #7
    Registered User
    Join Date
    Oct 2010
    Posts
    1
    Quote Originally Posted by principii View Post
    I figured it out. I had to use autoconf.
    can you plz explain how to use autoconf?

  8. #8
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,660
    Yes, you can read the manual page and the forum rules.

    One in particular is not bumping long dead threads.

    Another is to show that you at least tried to RTFM
    How To Ask Questions The Smart Way
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Linux problems
    By Dark_Phoenix in forum Tech Board
    Replies: 1
    Last Post: 03-22-2008, 05:30 AM
  2. HPUX sockets vs Linux?
    By cpjust in forum Linux Programming
    Replies: 4
    Last Post: 12-06-2007, 02:51 PM
  3. Segfault with C sockets on Linux
    By arti_valekar in forum C Programming
    Replies: 3
    Last Post: 02-16-2005, 02:25 AM
  4. Linux To FreeBSD Porting Compile Problems
    By Geolingo in forum Linux Programming
    Replies: 4
    Last Post: 03-17-2004, 08:17 AM
  5. Replies: 3
    Last Post: 10-29-2003, 09:39 AM