udt-问题解决

来源:互联网 发布:淘宝被买家诈骗怎么办 编辑:程序博客网 时间:2024/05/16 15:35
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
原创粉丝点击
热门问题 老师的惩罚 人脸识别 我在镇武司摸鱼那些年 重生之率土为王 我在大康的咸鱼生活 盘龙之生命进化 天生仙种 凡人之先天五行 春回大明朝 姑娘不必设防,我是瞎子 美团没有健康证怎么办 健康证不给补办怎么办 南京怎么办健康证去哪里办 浙江横店健康证怎么办 办健康证查乙肝怎么办 餐饮健康证丢了怎么办 办健康证吃了东西怎么办 吃宵夜脸肿了怎么办 晚上不吃宵夜饿了怎么办 办健康证身份证丢了怎么办 宁波二院怎么办健康证 健康证和培训证怎么办 楼下烧煤炉呛人怎么办 衣服染了笔渍怎么办 济宁二院怎么办健康证 刚按揭车的想卖怎么办 房子已过户银行不放贷怎么办 办房贷信用逾期给拒了怎么办 二手房过户了房贷下不来怎么办 没有房证的房子买卖怎么办 老公失踪房产证要他签字怎么办 税务机关对长期欠税怎么办 离婚有贷款的房子怎么办 买房没过户房主反悔怎么办 房子过户卖方爱人去世怎么办 黄浦区学生社会实践护照掉了怎么办 北京医保卡坏了怎么办 去了越南的签证怎么办 护照签证到期还在国外怎么办 办护照预约满了怎么办 未满16岁怎么办护照 办理护照采集指纹录不上怎么办 办理护照时指纹没有怎么办 未满16岁的怎么办护照 身份证照得太丑怎么办 武汉江夏怎么办健康证 小孩偏胖肚子大怎么办 手机安全中心密码忘记了怎么办 进京证一年12次怎么办 青霉素和头孢都过敏怎么办 手汗孢疹肿胀怎么办能吃消炎药吗