|||
struct sockaddr addr;
struct sockaddr_in* addr_v4;
int addr_len = sizeof(addr);
//获取local ip and port
ZeroMemory(&addr, sizeof(addr));
if (0 == getsockname(s, &addr, &addr_len))
{
if (addr.sa_family == AF_INET)
{
addr_v4 = (sockaddr_in*)&addr;
cMonitorInf.nSourceIP = addr_v4->sin_addr.S_un.S_addr;
cMonitorInf.nSourcePort = ntohs(addr_v4->sin_port);
}
}
//获取remote ip and port
ZeroMemory(&addr, sizeof(addr));
if (0 == getpeername(s, &addr, &addr_len))
{
if (addr.sa_family == AF_INET)
{
addr_v4 = (sockaddr_in*)&addr;
cMonitorInf.nDesIP = addr_v4->sin_addr.S_un.S_addr;
cMonitorInf.nDesPort = ntohs(addr_v4->sin_port);
}
}
Archiver|手机版|科学网 ( 京ICP备07017567号-12 )
GMT+8, 2024-8-25 07:25
Powered by ScienceNet.cn
Copyright © 2007- 中国科学报社