#include #include #include #include #include #include #include #define HPDRC "hpdrc.cs.fiu.edu" #define TIME_PORT "13" #define BUF_SIZE 1024 int main( ) { struct addrinfo hints, *res; int sd; char buf[ BUF_SIZE ]; int bytesRead; memset( &hints, 0, sizeof( hints ) ); hints.ai_family = AF_INET; hints.ai_socktype = SOCK_STREAM; if( getaddrinfo( HPDRC, TIME_PORT, &hints, &res ) ) { fprintf( stderr, "Error invoking getaddrinfo\n" ); return 2; } sd = socket( res->ai_family, res->ai_socktype, res->ai_protocol ); if( sd < 0 ) { fprintf( stderr, "Error creating socket\n" ); return 3; } if( connect( sd, res->ai_addr, res->ai_addrlen ) < 0 ) { fprintf( stderr, "Error connecting\n" ); return 4; } freeaddrinfo( res ); // free the linked list bytesRead = recv( sd, buf, BUF_SIZE, 0 ); if( bytesRead < 0 ) { fprintf( stderr, "Error creating socket\n" ); return 5; } write( 1, buf, bytesRead ); close( sd ); return 0; }