我利用winapi函数inet_ntoa将无符号长十进制数转换为IP地址。我正在反向获取IP地址。我使用网站 http://www.allredroster.com/iptodec.htm来获取十进制相当于输入的IP地址。
for ex decimal equivalent of 206.117.16.66 is 3463778370
如果我使用函数 inet_ntoa 取回 ip,它给出的 ip 为66.16.117.206。下面是相同的代码,请让我知道正确的方法。
#include<stdio.h>
#include<WinSock2.h>
#pragma comment(lib, "Ws2_32.lib")
int main()
{
ULONG ipdec=0;
struct in_addr ipadr;
char ip[50];
printf("\n Enter the ip address in decimal equivalent of ip address : ");
scanf_s("%ld",&ipdec);
ipadr.S_un.S_addr=ipdec;
strcpy_s(ip,inet_ntoa(ipadr));
printf("\n The ip address in dotted format is : %s \n" ,ip);
}