udt-问题解决

阅读 25

02-25 12:00


Q:
when my client computers connect server, 1 or 2 computers always 
say "abort for security reasons". 
i cannot find any firewall in the computer,and other computer is right.
please do me a favor, what reason is it?
thanks for your help!

W:
The only reason to cause this error is that the client received a wrong response 
from the server. The response UDP packet may be changed or damaged somewhere in 
the middle.


解决:
之前的包头说明:key为随机的四子节秘钥

#pragma  pack(1) 
 struct UDPHead{
char  flag;  
short bodylen;
     char  key[4]; //now used 4 bytes
char  other[9];
 };
 #pragma  pack()



core.cpp

void CUDT::connect(const sockaddr* serv_addr)
 中
 int CHandShake::serialize(char* buf, int& size)



udt数据是head+data

int32_t m_iVersion;          // UDT version
 int32_t m_iType;             // UDT socket type 
 int32_t m_iISN;              // random initial sequence number
 int32_t m_iMSS;              // maximum segment size
 int32_t m_iFlightFlagSize;   // flow control window size
 int32_t m_iReqType;          // connection request type: 1: regular connection request, 0: rendezvous connection request, -1/-2: response
 int32_t m_iID; // socket ID
 int32_t m_iCookie; // cookie
 uint32_t m_piPeerIP[4]; // The IP address that the peer's UDP port is bound to


该函数中发送包之后会接收对方的数据包则调用

int CUDT::connect(const CPacket& response) throw (){
if ((1 != response.getFlag()) || (0 != response.getType()))
       return -1;}

就相当于A主动去connect B,而B用UDP发来个不符合要求的数据包,这样就冲突了,悲剧了。


因此前8字节最好别动,因为存在m_iType,所以改后的数据包为

#pragma  pack(1) 
 struct UDPHead{
char  flag;  
short bodylen;
char  other[9];
char  key[4];  //now used 4 bytes
 };
 #pragma  pack()

精彩评论(0)

0 0 举报