#include
#include
#include
#include
#include
int main(int argc, char *argv[])
{
struct in_addr addr1,addr2;
unsigned long netaddr1,netaddr2;
if(argc != 3) //如果參數(shù)不正確
{
printf("請(qǐng)輸入正確的參數(shù).\n");
return 1; //退出
}
netaddr1 = inet_addr(argv[1]);
netaddr2 = inet_addr(argv[2]);
memcpy(&addr1, &netaddr1, 4);
memcpy(&addr2, &netaddr2, 4); //拷貝地址
printf("addr1 = %s : addr2 = %s\n", inet_ntoa(addr1), inet_ntoa(addr2)); //再次輸出兩個(gè)ip地址
//分別輸出IP地址
printf("%s\n", inet_ntoa(addr1));
printf("%s\n", inet_ntoa(addr2));
return 0;
}
分享名稱:[Linux網(wǎng)絡(luò)編程]IP地址轉(zhuǎn)換函數(shù)族--使用inet_ntoa函數(shù)
網(wǎng)站路徑:
http://weahome.cn/article/ijdpjs.html