/* decip.c * Despite the name, it converts to more than decimal. * UziMonkey (uzimonkey@gmail.com) */ #include #include #include #include int main (int argc, char *argv[]) { struct hostent *he; unsigned char *ucip; unsigned long *ulip; if (argv[1][0] != '-') he = gethostbyname (argv[1]); else he = gethostbyname (argv[2]); if (he == NULL) printf ("Could not resolve hostname.\n"); ucip = (unsigned char *)((struct in_addr *)he->h_addr); ulip = (unsigned long *)((struct in_addr *)he->h_addr); printf ("%d.%d.%d.%d is ", ucip[0], ucip[1], ucip[2], ucip[3]); if (argv[1][0] != '-' || !strcmp (argv[1], "--dotted-decimal")) { printf ("%u.%u.%u.%u\n", ucip[0], ucip[1], ucip[2], ucip[3]); } else if (!strcmp (argv[1], "--decimal")) { printf ("%u\n", ntohl(*ulip)); } else if (!strcmp (argv[1], "--dotted-octal")) { printf ("0%03o.0%03o.0%03o.0%03o\n", ucip[0], ucip[1], ucip[2], ucip[3]); } else if (!strcmp (argv[1], "--octal")) { printf ("0%o\n", ntohl(*ulip)); } else if (!strcmp (argv[1], "--dotted-hex")) { printf ("%x.%x.%x.%x\n", ucip[0], ucip[1], ucip[2], ucip[3]); } else if (!strcmp (argv[1], "--hex")) { printf ("%x\n", ntohl(*ulip)); } return 0; }