好了,我把整個結構在這裏,它的規範,在一些工業交換機實現的協議名爲OpenFlow的,所以結構是這樣的:填補了一個結構裏的數組場
struct ofp_packet_in {
struct ofp_header header;
uint32_t buffer_id; /* ID assigned by datapath. */
uint16_t total_len; /* Full length of frame. */
uint16_t in_port; /* Port on which frame was received. */
uint8_t reason; /* Reason packet is being sent (one of OFPR_*) */
uint8_t pad;
uint8_t data[0]; /* Ethernet frame, halfway through 32-bit word,
so the IP header is 32-bit aligned. The
amount of data is inferred from the length
field in the header. Because of padding,
offsetof(struct ofp_packet_in, data) ==
sizeof(struct ofp_packet_in) - 2. */
};
OFP_ASSERT(sizeof(struct ofp_packet_in) == 20);
現在我必須填寫最後一個字段中的一些數據,即 - uint8_t data[0]
,這些數據可以變化,並且信息從標題內的長度字段收集。我必須建立一個數據包,並且必須輸入數據。請看看。
請再次看到問題,編輯它。 – Abdullah 2012-02-04 10:35:40
我的答案適用於您更改的結構。用你需要的大小替換「+ 100」,並用'container-> data'來填充數據。 – Mat 2012-02-04 10:39:58
@ Mat,thnx mate。歡呼:) – Abdullah 2012-02-04 16:47:10