请教

zhongbing79 2003-08-23 11:40:52
请问获得Socket指针以后,可以得到客户端的端口和IP吗?如何得到,请执教。
...全文
35 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
windbells 2003-08-23
  • 打赏
  • 举报
回复
getpeername
The getpeername function retrieves the name of the peer to which a socket is connected.

int getpeername(
SOCKET s,
struct sockaddr FAR *name,
int FAR *namelen
);
Parameters
s
[in] Descriptor identifying a connected socket.
name
[out] The SOCKADDR structure that receives the name of the peer.
namelen
[in, out] Pointer to the size of the name structure.
zhouyong0371 2003-08-23
  • 打赏
  • 举报
回复
iAddrSize = sizeof(client);
sClient = accept(sListen, (struct sockaddr *)&client,
&iAddrSize);
if (sClient == INVALID_SOCKET)
{
break;
}

char ip[16]; //对方的IP
strcpy(ip,inet_ntoa(client.sin_addr));

18,356

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC 网络编程
c++c语言开发语言 技术论坛(原bbs)
社区管理员
  • 网络编程
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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