为什么我构造的COM_BINLOG_DUMP包被mysql忽略了?

问题描述

这是我的 C++ 代码

bool slave::request_dump(){
    int binlog_filename_len=binlog_filename.length();
    ssize_t         res;
    struct _COM_binlog_DUMP
    {
        unsigned char cmd;
        unsigned char binlog_pos[4];
        unsigned char flags[2];
        unsigned char serverid[4];
    } COM_binlog_DUMP;
    MysqL_PACKET_HEADER  mph = { 0 };
    mph.plen = 11 + binlog_filename_len;
    mph.psid = 0; 
    COM_binlog_DUMP.cmd = 0x12;
    memcpy(COM_binlog_DUMP.serverid,&serverid,sizeof(COM_binlog_DUMP.serverid));
    COM_binlog_DUMP.flags[0] = 0x00;
    COM_binlog_DUMP.flags[1] = 0x00;
    memcpy(COM_binlog_DUMP.binlog_pos,&binlog_pos,sizeof(COM_binlog_DUMP.binlog_pos));
    
    unsigned char packet[sizeof(mph)+sizeof(COM_binlog_DUMP)+binlog_filename_len];
    memcpy(packet,&mph,sizeof(mph));
    memcpy(packet+sizeof(mph),&COM_binlog_DUMP,sizeof(COM_binlog_DUMP));
    memcpy(packet+sizeof(mph)+sizeof(COM_binlog_DUMP),binlog_filename.c_str(),binlog_filename_len);
    
    res = write(this->MysqL.net.fd,packet,sizeof(packet));
    
    if ( res == (15 + binlog_filename_len) ) {
        return 1;
    } else {
        return 0;
    }
}

这是我从wireshark得到的信息。 数据包被MysqL拒绝并确定为忽略的未知记录。

0000   00 0c 29 93 09 eb 00 0c 29 d7 b0 64 08 00 45 00   ..).....)..d..E.
0010   00 53 5d f3 40 00 40 06 e6 56 c0 a8 3a 87 c0 a8   .S].@.@..V..:...
0020   3a 83 96 c0 0c ea 7b 30 17 d7 4a 9d 54 84 80 18   :.....{0..J.T...
0030   01 f5 de fa 00 00 01 01 08 0a f3 e8 cd 78 a4 2d   .............x.-
0040   ee b8 1b 00 00 00 12 9a 00 00 00 00 00 e7 03 00   ................
0050   00 6d 79 73 71 6c 2d 62 69 6e 2e 30 30 30 30 30   .MysqL-bin.00000
0060   33                                                3

有人可以帮我吗?提前致谢。

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)