簡體   English   中英

來自getaddrinfo&inet_ntop的虛假IP地址

[英]Bogus IP Address from getaddrinfo & inet_ntop

我一直在使用getaddrinfo查找基本套接字命令的套接字地址。 最近,它返回給我的地址是偽造的IP地址,我發現使用inet_ntop。 我已經嘗試了我的代碼,以及Beej指南中提供的代碼,它們都產生了相同的結果。 這是代碼:

struct addrinfo hints, *info;
int status;

memset(&hints, 0, sizeof hints);

hints.ai_family = AF_INET;
hints.ai_socktype = SOCK_STREAM;

if(status = getaddrinfo(address, port, &hints, &info)) {
    fprintf(stderr, "getaddrinfo: %s\n", gai_strerror(status));
}

char ip4[INET_ADDRSTRLEN];
inet_ntop(AF_INET, info->ai_addr, ip4, INET_ADDRSTRLEN);

std::cout<<ip4<<std::endl;

無論我使用什么地址,它總是給我一張表格的IP

16.2.xy

其中256 * x + y等於端口號。 有沒有人見過這種情況,或者任何人都可以猜到為什么它會給我這個?

你不應該過世嗎?

((sockaddr_in const *)info->ai_addr)->sin_addr

inet_ntop

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM