Skip to content

Instantly share code, notes, and snippets.

@hrs113355
Created August 25, 2008 00:37
Show Gist options
  • Save hrs113355/7016 to your computer and use it in GitHub Desktop.
Save hrs113355/7016 to your computer and use it in GitHub Desktop.
char *
fqdn2ip(host)
char *host;
{
unsigned long sum;
unsigned long base[4]={16777216,65536,256,1};
int i, ip[4];
if (!strcmp(host, "localhost"))
return "127.0.0.1";
sum = dns_a(host);
for (i=0; i<=3; i++)
{
ip[i] = sum / base[i];
sum -= base[i]*ip[i];
}
sprintf(ipaddr, "%d.%d.%d.%d\0", ip[3], ip[2], ip[1], ip[0]);
return (ipaddr);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment