/* Generic TCP client that reads from standard input and forwards to a TCP socket. Also sends to stdout anything received from the socket. This is an IPv6 client, although by changing only the call to tcp_connect you can change it to an IPv4 client. command line parameters identify the TCP server. Uses many functions defined in common.c */ #include /* standard C i/o facilities */ #include /* needed for atoi() */ #include /* Unix System Calls */ #include /* system data type definitions */ #include /* socket specific definitions */ #include /* INET constants and stuff */ #include /* IP address conversion stuff */ #include /* Name lookups (gethostbyname) */ #include #include "common.h" /* =============================================================== The following must passed in on the command line: name or address of the server (argv[1]) port number or service name of the server (argv[2]) getaddrinfo is given both values, and it can handle hostnames, dotted-decimal IPv4 addresses and IPv6 addresses (colon seperated HEX digits). */ int main( int argc, char **argv ) { int sk; /* first - check to make sure there are 2 command line parameters (argc=3 since the program name is argv[0]) */ if (argc!=3) { printf("Usage: client \n"); exit(0); } sk = tcp_connect(argv[1],argv[2],PF_INET6); printf("Connected!\n"); /* print information about the server (uses getnameinfo) */ printremoteinfo(sk); /* Go handle the connection */ tcp_talk(sk); close(sk); return(0); }