C Board  

Go Back   C Board > Platform Specific Boards > Linux Programming

Reply
 
LinkBack Thread Tools Display Modes
Old 09-17-2004, 03:23 PM   #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:
Quote:
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
principii is offline   Reply With Quote
Old 09-17-2004, 09:28 PM   #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.
linuxdude is offline   Reply With Quote
Old 09-17-2004, 09:53 PM   #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)
__________________
Free iPod?!
scrappy is offline   Reply With Quote
Old 09-18-2004, 12:55 PM   #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.
principii is offline   Reply With Quote
Old 09-18-2004, 01:03 PM   #5
Crazy Fool
 
Perspective's Avatar
 
Join Date: Jan 2003
Location: Canada
Posts: 2,596
Quote:
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.
Perspective is offline   Reply With Quote
Old 09-18-2004, 03:09 PM   #6
Registered User
 
Join Date: Sep 2004
Posts: 17
I figured it out. I had to use autoconf.
principii is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Linux problems Dark_Phoenix Tech Board 1 03-22-2008 05:30 AM
HPUX sockets vs Linux? cpjust Linux Programming 4 12-06-2007 02:51 PM
Segfault with C sockets on Linux arti_valekar C Programming 3 02-16-2005 02:25 AM
Linux To FreeBSD Porting Compile Problems DeepBlackMagic Linux Programming 4 03-17-2004 08:17 AM
Red Hat Linux 8.0 Loading Failure? + Many other Problems! jawwadalam Tech Board 3 10-29-2003 09:39 AM


All times are GMT -6. The time now is 08:20 PM.


Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.3.2

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22