Skip to content

Instantly share code, notes, and snippets.

@hausdorff
Last active January 1, 2016 11:59
Show Gist options
  • Save hausdorff/8141382 to your computer and use it in GitHub Desktop.
Save hausdorff/8141382 to your computer and use it in GitHub Desktop.
#include <arpa/inet.h>
#include <netinet/in.h>
#include <stdio.h>
#include <stdlib.h>
void convert_both_ways();
int main(int argc, char **argv)
{
/* convert integer address to dotted decimal,
then convert it back*/
convert_both_ways();
exit(0);
}
void convert_both_ways()
{
char *dotted;
struct in_addr address;
address.s_addr = 0x8002c2f2;
dotted = inet_ntoa(address);
printf("Converting address 0x%x to dotted-decimal: %s\n"
, address.s_addr, dotted);
printf("Converting dotted-decimal %s to address: 0x%x\n"
, dotted, address.s_addr);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment