我已經利用winapi函數inet_ntoa將無符號長整數轉換爲IP地址。我用相反的IP地址獲取IP地址。我使用網站http://www.allredroster.com/iptodec.htm來獲取輸入IP的十進制等效值地址。十進制到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);
}
明智的回答你們每個人,感謝您清除概念。+ 1 upvote for each one.Thanks。 –