请大家帮我简单分析下下面的语句。
这个是P2P的例子
SERVER端:
//20120602 支持两个客户端运行在同一个NAT后 if (sender.sin_addr.S_un.S_addr == remote.sin_addr.s_addr) { stP2PMessage trans1; trans1.iMessageType = P2PSAMENAT; sendto(PrimaryUDP,(const char*)&trans1, sizeof(trans1), 0, (const sockaddr *)&sender, sizeof(sender)); stP2PMessage trans2; trans2.iMessageType = P2PSAMENAT; sendto(PrimaryUDP,(const char*)&trans2, sizeof(trans2), 0, (const sockaddr *)&remote, sizeof(remote)); printf("this is same nat\n"); break; }
case P2PSAMENAT://20120602 发送内部IP来更新IP { printf("same nat, please send agian\n"); stMessage trans1; trans1.iMessageType = P2PSAMENAT; trans1.nIpAddress = ntohl(GetLocalIp()); strncpy(trans1.message.loginmember.userName, UserName, 10); sendto(PrimaryUDP, (const char *)&trans1, sizeof(trans1), 0, (const sockaddr*)&remote, sizeof(remote)); bSameNatACK = true; break; }//-------------------------------------------------unsigned long GetLocalIp(void){ char szHostName[128]; if (gethostname(szHostName, 128) == 0) { struct hostent* pHost; pHost = gethostbyname(szHostName); in_addr tmp = *(struct in_addr *)pHost->h_addr_list[0]; return tmp.S_un.S_addr; } return 0;}