The gethostbyname function resolves the string returned by a successful call to gethostname.
gethostname
The Windows Sockets gethostname function returns the standard host name for the local machine.int gethostname(
char FAR *name,
int namelen
);
Parameters
name
[out] Pointer to a buffer that receives the local host name.
namelen (*****************注意这里*****************)
[in] Length of the buffer.
gethostname
The Windows Sockets gethostname function returns the standard host name for the local machine.int gethostname(
char FAR *name,
int namelen
);
Parameters
name
[out] Pointer to a buffer that receives the local host name.
namelen (*****************注意这里*****************)
[in] Length of the buffer.
我上面贴了,使用的方法。
如果你想对http://www.csdn.net/expert/topic/771/771757.xml?temp=.7499658这样的url获得ip,恐怕不行,除非是www.csdn.net这样的
const char FAR *name//使用gethostname第1个参数返回的内容作为参数
);
int gethostname(
char FAR *name,
int namelen
);
Parameters
name
[out] Pointer to a buffer that receives the local host name.
namelen (*****************注意这里*****************)
[in] Length of the buffer.
if(WSAStartup(MAKEWORD(2,2),&data)!=0)
{
//initial failed!
return;
}
...
...
用FormatMessage()讲错误代码转换成语言表述的错误类型
然后察看这个错误类型代表的意思
gethostname(......);
WSAClean();