/* * File: client.c * Modified by: [TODO: Fill this in!] * Description: Sends a string over a TCP socket */ #include #include #include #include #include #include #include #include #include #include int main(int argc, char * argv[]) { char hostbuffer[256]={}; char *IPbuffer=NULL; struct hostent *host_entry=NULL; int hostname; /* Get the hostname of this machine */ //hostname = TODO FILL THIS IN, using gethostname() function with the string hostbuffer printf("Hostname: %s\n", hostbuffer); /* To get the IP address of this machine */ //host_entry = TODO FILL THIS IN, using gethostbyname() function with the hostbuffer string. /* Get the IP address out of the host_entry struct */ /* This code should "just work" if gethostname() and gethostbyname() above are working */ if (host_entry!=NULL) { IPbuffer = inet_ntoa(*((struct in_addr*) host_entry->h_addr_list[0])); } printf("Host IP: %s\n", IPbuffer); return 0; }