/* COMP2303 Week 9 ** ** Address Handling Example 2 Code ** Code will be commented in class */ #include #include #include #include int main(int argc, char* argv[]) { struct in_addr a; uint32_t hostAddress; /* IP address is 216.109.125.70 */ /* U = unsigned */ /* hostAddress is host byte ordered rep. of IP address */ hostAddress = (216<<24) + (109U<<16) + (125U<<8) + 70; /* Convert to network byte ordered */ a.s_addr = htonl(hostAddress); /* inet_ntoa() converts to ASCII text */ printf("IP address (hex): %08x, String: %s\n", hostAddress, inet_ntoa(a)); return 0; }