Thread: Problems with sockets under linux

Threaded View

Previous Post Previous Post   Next Post Next Post
  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

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