원본의 IP를 찾으려고하는데 작동하지 않습니다.gethostbyname()이 작동하지 않습니다.
void getSourceIp(struct hostent *sourceHost, struct ip *ipStruct)
{
char sourceName[100];
if (gethostname(sourceName,sizeof(sourceName)) < 0)
{
perror("Error in function gethostname().\n");
exit(EXIT_FAILURE);
}
if ((sourceHost = gethostbyname(sourceName)) == NULL)
{
std::cout << "The source " << sourceName << " is unknown.\n";
exit(EXIT_FAILURE);
}
ipStruct->ip_src = (*(struct in_addr *) sourceHost->h_addr_list);
std::cout << "IP Address: " << inet_ntoa(ipStruct->ip_src);
}
주요 기능 : 내가 얻을 출력은
int main(int argc, char *argv[])
{
struct hostent *sourceHostent = NULL;
struct hostent *destinationHostent = NULL;
struct ip *ip = NULL;
getSourceIp(sourceHostent,ip);
return 0;
}
"소스 맥북 알 수 없습니다."
"gethostbyname() not working"- 아마도 그렇 겠지만 기대치가 그 행동과 일치하지 않습니다. –
무엇을 의미합니까? @ H2CO3 – Teodora
죄송합니다. 내 의견을 마치고 깜빡 ...>. <바보 같이. –