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'