如何将数据包缓冲区解析为struct

时间:2019-12-19 16:08:08

标签: c++ struct arduino

我对netbios信息有疑问,我认为我的解析不正确,有人可以帮助我做到这一点吗?非常感谢。

我收到多个IP,我想将它们存储到我的结构中

这是我的结构:

typedef struct PACK({
  uint16_t id;
  uint8_t flags1;
  uint8_t flags2;
  uint16_t qcount;
  uint16_t acount;
  uint16_t nscount;
  uint16_t adcount;
  uint8_t name_len;
  char name[NBNS_MAX_HOSTNAME_LEN + 1];
  uint16_t type;
  uint16_t clas;
  uint32_t ttl;
  uint16_t data_len;
  struct {                <------------ HERE I DID ANOTHER STRUCT FOR MULTIPLE IP (LOOK BELOW)
    uint16_t flags;
    uint32_t addr;
  } addrs[];
}) nbns_answer_t;

这是我在Wireshark中的包裹:

Wireshark packet

这是我的解析:

nbns_answer_t* data = (nbns_answer_t*) response;

当我这样做时,我没有所有的ip(或者我对它们的处理不好吗?):

if (!(memcmp(data->name, "FDENEBFCFECNEEEFEDELFDCACACACACA", sizeof(data->name)))) {
        if (data->acount >= 1) {   
          for (int i = 0; i < sizeof(addrs[]); i++) {
            Serial.printf("\n%x", data->addrs[i].addr); <------------------
          }

我明白了:

138
a8c00000
0
0
138

谢谢!

0 个答案:

没有答案