请教!!!!!

cainiaodonggua 2003-11-21 11:52:42
//初始化SOCKET
WSADATA wsaData;
int iRet = WSAStartup(MAKEWORD(2,1), &wsaData);
if ( iRet != 0 )
{
printf( "WSAStartup Error:%d\n", GetLastError() );
exit( 0 );
}
int nRemoteAddr = inet_addr( argv[1] );
remoteHostent= (struct hostent*)malloc( sizeof(struct hostent ));
struct in_addr sa;
for ( int i = 0; i < numberOfHost; i ++ )
{
//获取远程机器名
sa.s_addr = nRemoteAddr;
printf( "\nIpAddress : %s\n", inet_ntoa( sa ) );
remoteHostent = gethostbyaddr( (char*)&nRemoteAddr,4, AF_INET );
函数WSAStartup(MAKEWORD(2,1), &wsaData)是如何理解的?
函数gethostbyaddr( (char*)&nRemoteAddr,4, AF_INET )又是如何理解的?
...全文
61 1 打赏 收藏 转发到动态 举报
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
Wolf0403 2003-11-22
  • 打赏
  • 举报
回复
幸亏这里是 CSDN。。。呵呵,在别的论坛你会挨骂的

The WSAStartup function initiates use of WS2_32.DLL by a process.

int WSAStartup(
WORD wVersionRequested,
LPWSADATA lpWSAData
);

Parameters
wVersionRequested
[in] Highest version of Windows Sockets support that the caller can use. The high-order byte specifies the minor version (revision) number; the low-order byte specifies the major version number.
lpWSAData
[out] Pointer to the WSADATA data structure that is to receive details of the Windows Sockets implementation.


The gethostbyaddr function retrieves the host information corresponding to a network address.

Note The gethostbyaddr function has been deprecated by the introduction of the getnameinfo function. Developers creating Windows Sockets 2 applications are urged to use the getnameinfo function instead of the gethostbyaddr function. See Remarks.


struct HOSTENT* FAR gethostbyaddr(
const char* addr,
int len,
int type
);

Parameters
addr
[in] Pointer to an address in network byte order.
len
[in] Length of the address, in bytes.
type
[in] Type of the address, such as the AF_INET address family type (defined as TCP, UDP, and other associated Internet protocols). Address family types and their corresponding values are defined in the Winsock2.h header file.
Return Values

24,854

社区成员

发帖
与我相关
我的任务
社区描述
C/C++ 工具平台和程序库
社区管理员
  • 工具平台和程序库社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧