- 论坛徽章:
- 1
|
哪位有对emule协议进行分析的,麻烦查看下这个数据表有什么错误。
给服务器发送登入包的时候,服务器没有反馈任何信息,在大约10秒后服务器强制断开
附件中是协议说明
以下是完整的测试代码
在linux下的
#include <arpa/inet.h>
#include <string.h>
#include <iostream>
using namespace std;
typedef unsigned char Byte;
typedef struct Msg_Header Msg_Header;
struct Msg_Header{
Byte Protocol;
int Size;
Byte Type;
};
typedef struct Msg_Login Msg_Login;
struct Msg_Login{
Msg_Header Header;
Byte UserHash[16];
int ClientID;
short TCPPort;
int TagCount;
Byte NameTag[10];
Byte VersionTag[8];
Byte PortTag[8];
Byte FlagsTag[8];
};
Byte UserHash[16] = {
0xD1,0x1A,0xC3,0x2E,0xF6,0x1B,0xA1,0x72,
0xED,0x1F,0x9B,0x3F,0x30,0x7F,0xA3,0x5E};
void Login(int fd)
{
Msg_Login msg;
bzero(&msg, sizeof(Msg_Login));
Msg_Header *pHeader = &msg.Header;
pHeader->Protocol = 0xE3;
pHeader->Size = sizeof(Msg_Login) - 6;
pHeader->Type = 0x01;
memcpy(msg.UserHash, UserHash, sizeof(UserHash));
msg.ClientID = 0;
msg.TCPPort = 4006;
msg.TagCount = 10;
strcpy((char*)msg.NameTag, "tear");
msg.VersionTag[7] = 0x3c;
msg.PortTag[7] = 0x0f;
msg.FlagsTag[7] = 0x01;
int nRet = send(fd, &msg, sizeof(Msg_Login), 0);
if(nRet != sizeof(Msg_Login)){
printf("send error\n");
}
}
int Connect(char *host, int port)
{
//服务器描述
struct sockaddr_in ServerAddr;
bzero(&ServerAddr,sizeof(ServerAddr));
ServerAddr.sin_family = AF_INET;
ServerAddr.sin_addr.s_addr = inet_addr(host);
ServerAddr.sin_port = htons(port);
int ClientFd = socket(AF_INET,SOCK_STREAM,0);
if(ClientFd<=0)
{
return ClientFd;
}
int nRet;
nRet = connect(ClientFd,(sockaddr *)&ServerAddr,sizeof(ServerAddr));
if(nRet != 0)
{
cout<<"connect fail"<<endl;
return -1;
}
return ClientFd;
}
int main()
{
int bRet;
int fd = Connect("172.168.0.56", 4661);
if(fd <= 0){
return 0;
}
Login(fd);
char buff[1024];
bzero(buff, sizeof(buff));
int nRet = recv(fd, buff, sizeof(buff), 0);
printf("%d : %s\n", nRet, buff);
return 0;
}
|
|