dev/c/masync_server/int2ip.c

36 lines
578 B
C
Raw Normal View History

#include <stdio.h>
#include <errno.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <netdb.h>
2011-05-02 12:11:12 +04:00
static const char *int2ip(unsigned int ip)
{
static char s[16];
2011-05-02 12:11:12 +04:00
sprintf(s, "%d.%d.%d.%d", ip >> 24, ip << 8 >> 24, ip << 16 >> 24, ip << 24 >> 24);
return s;
}
2011-05-02 12:11:12 +04:00
int main(int argc, char *argv[])
{
if (argc < 2) {
perror("need hex ip address");
exit(1);
}
unsigned int ip = 0;
2011-05-02 12:11:12 +04:00
sscanf(argv[1], "%X", &ip);
2011-05-02 12:11:12 +04:00
printf("%s\n", int2ip(ip));
return 0;
}