From 6b83b07e9950f40884a49159b4b113921bd2a653 Mon Sep 17 00:00:00 2001 From: Aaro Altonen Date: Mon, 17 Jun 2019 12:01:23 +0300 Subject: [PATCH] Add PACKED_STRUCT macro We must use packed structures because the structs we're sending must not be padded at all --- src/frame.hh | 10 +++++----- src/util.hh | 13 +++++++++++++ 2 files changed, 18 insertions(+), 5 deletions(-) diff --git a/src/frame.hh b/src/frame.hh index 587c301..fdaa21e 100644 --- a/src/frame.hh +++ b/src/frame.hh @@ -46,7 +46,7 @@ namespace kvz_rtp { rtp_type_t type; }; - struct rtcp_header { + PACKED_STRUCT(rtcp_header) { uint8_t version:2; uint8_t padding:1; uint8_t report_cnt:5; @@ -54,7 +54,7 @@ namespace kvz_rtp { uint16_t length; }; - struct rtcp_sender_info { + PACKED_STRUCT(rtcp_sender_info) { uint32_t ntp_msw; uint32_t ntp_lsw; uint32_t rtp_timestamp; @@ -62,7 +62,7 @@ namespace kvz_rtp { uint32_t byte_count; }; - struct rtcp_report_block { + PACKED_STRUCT(rtcp_report_block) { uint32_t ssrc; uint8_t fraction_lost; uint32_t cumulative_pkt_lost:24; @@ -72,13 +72,13 @@ namespace kvz_rtp { uint32_t delay_since_last_sr; }; - struct rtcp_sender_frame { + PACKED_STRUCT(rtcp_sender_frame) { struct rtcp_header header; struct rtcp_sender_info s_info; struct rtcp_report_block blocks[0]; }; - struct rtcp_receiver_frame { + PACKED_STRUCT(rtcp_receiver_frame) { struct rtcp_header header; struct rtcp_report_block blocks[0]; }; diff --git a/src/util.hh b/src/util.hh index 5862e90..9a58a40 100644 --- a/src/util.hh +++ b/src/util.hh @@ -4,6 +4,19 @@ #include #include +#ifdef _WIN32 + +/* TODO: make sure this works on windows too! */ + +#define PACKED_STRUCT_WIN(name) \ + __pragma(pack(push, 1)) \ + struct name \ + __pragma(pack(pop)) +#else +#define PACKED_STRUCT(name) \ + struct __attribute__((packed)) name +#endif + const int MAX_PACKET = 65536; const int MAX_PAYLOAD = 1000;