PNP: TTCP

TTCP: Test TCP

https://en.wikipedia.org/wiki/Ttcp

協議

struct SessionMessage
{
  int32_t number;
  int32_t length;
} __attribute__ ((__packed__));

struct PayloadMessage
{
  int32_t length;
  char data[0];
}

Code

https://github.com/huntinux/pnp/blob/master/ttcp/ttcp.cc

其他知識

__attribute__((packed))

http://stackoverflow.com/questions/1756811/does-gccs-attribute-packed-retain-the-original-ordering

在使用struct描述網絡包的時候,使用“__attribute__(packed)”能保證struct中的member之間沒有gap:

struct packet {
    uint8_t x;
    uint32_t y;
} __attribute__((packed)); // sizeof 爲 5


struct packet {
    uint8_t x;
    uint32_t y;
} ;                        // sizeof 爲 8
發佈了195 篇原創文章 · 獲贊 64 · 訪問量 50萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章