CAPWAP プロトコル用のクライアント C コードを作成しようとしています。ビット フィールド構造を使用して CAPWAP ヘッダーを実装してみました。しかし、sendto() を使用してソケット経由でこの構造体を送信した後、wireshark を使用してパケットを盗聴すると、その間にいくつかの余分なビットが追加されていることがわかります。これがどこから来たのか、私には手がかりがありません。助けを求めています。前もって感謝します。
構造体の最後のいくつかのメンバーにコメントを付けて、4バイトで整列させようとしました。それでも問題は解決しません。
元のヘッダーです
struct cw_header
{
unsigned preamble : 8;
unsigned hlen : 5;
unsigned rid : 5;
unsigned wbid : 5;
unsigned t : 1;
unsigned f : 1;
unsigned l : 1;
unsigned w : 1;
unsigned m : 1;
unsigned k : 1;
unsigned flags : 3;
unsigned fragment_id : 16;
unsigned fragment_offset : 13;
unsigned reserved : 3;
uint32_t mac_length : 8;
uint32_t mac_addr[6];
uint32_t padding : 8;
};
これらにコメントしてみました
//uint32_t mac_length : 8;
//uint32_t mac_addr[6];
//uint32_t padding : 8;
これは、構造体が取り込まれる場所です
struct cw_header create_cw_header()
{
struct cw_header cw_header;
cw_header.preamble = 0;
cw_header.hlen = 1;
cw_header.rid = 1;
cw_header.wbid = 1;
cw_header.t = 0;
cw_header.f = 0;
cw_header.l = 1;
cw_header.w = 0;
cw_header.m = 1;
cw_header.k = 0;
cw_header.flags = 0;
cw_header.fragment_id = 0; ;
cw_header.fragment_offset = 0;
cw_header.reserved = 0;
cw_header.mac_length = 6;
get_mac_address(cw_header.mac_addr);
cw_header.padding = 0;
return cw_header;
};
最初の 32 ビットの Wireshark の出力を次に示します。
0000 0000 0010 0001 0000 0100 0000 1010
期待される結果 : ビットは構造体に記載されている順序である必要があります エラー : 余分なビットが構造体メンバー間に追加されます