C++根据SOCKET获取套接字IP、Port等信息的代码

如下资料是关于C++根据SOCKET获取套接字IP、Port等信息的内容。

bool GetAddressBySocket(SOCKET m_socket,SOCKADDR_IN &m_address)
{
memset(&m_address, 0, sizeof(m_address));
int nAddrLen = sizeof(m_address);

{
    printf("Get IP address by socket failed!n");
    return false;
}
 
cout<<"IP: "<<::inet_ntoa(m_address.sin_addr)<<"  PORT: "<<ntohs(m_address.sin_port)<<endl;
return true;

}

上一篇:27. 多道技术与socketserver实现并发


下一篇:C++根据SOCKET获取套接字IP、Port等信息的代码