/* ECE435: tespip.c * Change IP address to internal representation * Work at APPLICATION level * Compile using : gcc -o testip testip.c * Usage: testip 192.168.0.9 */ #include #include #include #include #include #include #include #include #include #define PORT 3500 int main (int argc, char *argv[]) { struct hostent *he; struct sockaddr_in their_addr; // connector's address information if (argc != 2) { fprintf(stderr,"usage: testip hostname\n"); exit(1); } if ((he=gethostbyname(argv[1])) == NULL) { // get the host info perror("gethostbyname"); exit(1); } their_addr.sin_family = AF_INET; // host byte order their_addr.sin_port = htons(PORT); // short, network byte order their_addr.sin_addr = *((struct in_addr *)he->h_addr); memset(&(their_addr.sin_zero), '\0', 8); // zero the rest of the struct printf("IP address : %s\n", argv[1]); printf("IP network number : %lu\n", their_addr.sin_addr.s_addr); exit(1); }