USHORT GetSocketLocalPort(SOCKET s)
{
sockaddr Addr;
sockaddr_in *lpSa;
int addr_len = sizeof(Addr);
USHORT dwRet = 0;
if (getsockname(s, &Addr, &addr_len) == NO_ERROR)
{
if (Addr.sa_family == AF_INET)
{
lpSa = (sockaddr_in *)&Addr;
dwRet = ntohs(lpSa->sin_port);
}
}
return dwRet;
}
获取连接方信息的函数是getpeername