Pythonクライアントからリクエストを受信するC TCPソケットサーバーでバイトを読み取る問題に悩まされています。受信テンプレートとして次の構造体があります
struct ofp_connect {
uint16_t wildcards; /* identifies ports to use below */
uint16_t num_components;
uint8_t pad[4]; /* Align to 64 bits */
uint16_t in_port[0];
uint16_t out_port[0];
struct ofp_tdm_port in_tport[0];
struct ofp_tdm_port out_tport[0];
struct ofp_wave_port in_wport[0];
struct ofp_wave_port out_wport[0];
};
OFP_ASSERT(sizeof(struct ofp_connect) == 8);
最初の 2 つの 32 ビット フィールドは正しく読み取ることができますが、パッド フィールドの後の in_port[0] が間違っているようです。現在読み取られている方法は
uint16_t portwin, portwout, * wportIN;
wportIN = (uint16_t*)&cflow_mod->connect.in_port; //where cflow_mod is the main struct which encompasses connect struct template described above
memcpy(&portwin, wportIN, sizeof(portwin) );
DBG("inport:%d:\n", ntohs(portwin));
残念ながら、これは期待されるインポート番号を私に与えません。クライアントが正しいパケット形式を送信していることをwiresharkで確認できますが、入出力ポートの読み取り方法が間違っていると感じています。それとも、python がデータを送信する方法が原因ですか? どこで、なぜ間違っているのかについてアドバイスをいただけますか?前もって感謝します。