/* IPv6 TCP server that accepts a connection, print out information about the peer (the IPv6 address), and then reads from standard input and forwards to the TCP socket. Also sends to stdout anything received from the socket. uses functions defined in common.c */ #include /* standard C i/o facilities */ #include /* Unix System Calls */ #include /* system data type definitions */ #include /* socket specific definitions */ #include /* INET constants and stuff */ #include /* IP address conversion stuff */ #include /* malloc */ #include /* gethostname */ #include #include "common.h" int main( int argc, char **argv ) { int passive; int sd; struct sockaddr_in6 from; int addrlen; /* create a passive mode socket with an IPv6 address and any port */ passive = tcp_serversock(PF_INET6,0); /* print information about the socket (uses getnameinfo) */ printlocalinfo(passive); while (1) { printf("Ready for a connection...\n"); addrlen=sizeof(from); if ( (sd = accept( passive, (struct sockaddr*) &from, &addrlen)) < 0) { perror("Problem with accept call\n"); exit(1); } printf("Got a connection from:\n"); printremoteinfo(sd); /* Go handle the connection */ tcp_talk(sd); close(sd); } return(0); }