Tag: host

通过sockaddr_in gethostname等将主机转换为ip

我需要帮助将hostname转换为ip并插入sockaddr_in-> sin_addr才能分配给char。 例如我输入:localhost,它给了我127.0.0.1 我找到了代码,但我不知道为什么它给了我错误的数字 //— #include #include #include #include #include #include #include #include #include #include #include #include #include //— ///CZY WPISANO HOST struct in_addr inaddr; inaddr.s_addr = inet_addr(argv[1]); if( inaddr.s_addr == INADDR_NONE) //if sHost is name and not IP { struct hostent* phostent = gethostbyname( argv[1]); if( phostent == 0) bail(“gethostbyname()”); if( sizeof(inaddr) != phostent->h_length) […]