Implement cross-platform structure packing

This commit is contained in:
Aaro Altonen 2020-10-01 10:12:01 +03:00
parent 3350140196
commit 1ad489620e
10 changed files with 27 additions and 29 deletions

View File

@ -41,7 +41,7 @@ namespace uvg_rtp {
RTCP_FT_APP = 204 /* Application-specific message */
};
PACKED_STRUCT(rtp_header) {
PACK(struct rtp_header {
uint8_t version:2;
uint8_t padding:1;
uint8_t ext:1;
@ -51,13 +51,13 @@ namespace uvg_rtp {
uint16_t seq;
uint32_t timestamp;
uint32_t ssrc;
};
});
PACKED_STRUCT(ext_header) {
PACK(struct ext_header {
uint16_t type;
uint16_t len;
uint8_t *data;
};
});
struct rtp_frame {
struct rtp_header header;
@ -150,14 +150,14 @@ namespace uvg_rtp {
uint8_t *payload;
};
PACKED_STRUCT(zrtp_frame) {
PACK(struct zrtp_frame {
uint8_t version:4;
uint16_t unused:12;
uint16_t seq;
uint32_t magic;
uint32_t ssrc;
uint8_t payload[1];
};
});
/* Allocate an RTP frame
*

View File

@ -18,13 +18,11 @@
typedef SSIZE_T ssize_t;
#endif
/* https://stackoverflow.com/questions/1537964/visual-c-equivalent-of-gccs-attribute-packed */
#if defined(__MINGW32__) || defined(__MINGW64__) || defined(__linux__)
#define PACKED_STRUCT(name) \
struct __attribute__((packed)) name
#define PACK(__Declaration__) __Declaration__ __attribute__((__packed__))
#else
//#warning "structures are not packed!"
#define PACKED_STRUCT(name) struct name
#define PACK(__Declaration__) __pragma(pack(push, 1)) __Declaration__ __pragma(pack(pop))
#endif
#ifdef _WIN32

View File

@ -14,7 +14,7 @@ namespace uvg_rtp {
namespace zrtp_msg {
/* DH Commit Message */
PACKED_STRUCT(zrtp_commit) {
PACK(struct zrtp_commit {
zrtp_msg msg_start;
uint32_t hash[8];
@ -28,7 +28,7 @@ namespace uvg_rtp {
uint32_t hvi[8];
uint32_t mac[2];
uint32_t crc;
};
});
class commit {
public:

View File

@ -11,10 +11,10 @@ namespace uvg_rtp {
namespace zrtp_msg {
PACKED_STRUCT(zrtp_confack) {
PACK(struct zrtp_confack {
zrtp_msg msg_start;
uint32_t crc;
};
});
class confack {
public:

View File

@ -11,7 +11,7 @@ namespace uvg_rtp {
namespace zrtp_msg {
PACKED_STRUCT(zrtp_confirm) {
PACK(struct zrtp_confirm {
zrtp_msg msg_start;
uint8_t confirm_mac[8];
@ -32,7 +32,7 @@ namespace uvg_rtp {
/* encrypted portion ends */
uint32_t crc;
};
});
class confirm {
public:

View File

@ -11,20 +11,20 @@ namespace uvg_rtp {
struct zrtp_hello;
struct zrtp_dh;
PACKED_STRUCT(zrtp_header) {
PACK(struct zrtp_header {
uint8_t version:4;
uint16_t unused:12;
uint16_t seq;
uint32_t magic;
uint32_t ssrc;
};
});
PACKED_STRUCT(zrtp_msg) {
PACK(struct zrtp_msg {
struct zrtp_header header;
uint16_t magic;
uint16_t length;
uint64_t msgblock;
};
});
enum ZRTP_FRAME_TYPE {
ZRTP_FT_HELLO = 1,

View File

@ -13,7 +13,7 @@ namespace uvg_rtp {
namespace zrtp_msg {
PACKED_STRUCT(zrtp_dh) {
PACK(struct zrtp_dh {
zrtp_msg msg_start;
uint32_t hash[8];
uint8_t rs1_id[8];
@ -23,7 +23,7 @@ namespace uvg_rtp {
uint8_t pk[384];
uint8_t mac[8];
uint32_t crc;
};
});
class dh_key_exchange {
public:

View File

@ -10,11 +10,11 @@ namespace uvg_rtp {
namespace zrtp_msg {
PACKED_STRUCT(zrtp_error) {
PACK(struct zrtp_error {
zrtp_msg msg_start;
uint32_t error;
uint32_t crc;
};
});
class error {
public:

View File

@ -14,7 +14,7 @@ namespace uvg_rtp {
namespace zrtp_msg {
PACKED_STRUCT(zrtp_hello) {
PACK(struct zrtp_hello {
zrtp_msg msg_start;
uint32_t version;
@ -35,7 +35,7 @@ namespace uvg_rtp {
uint64_t mac;
uint32_t crc;
};
});
class hello {
public:

View File

@ -10,10 +10,10 @@ namespace uvg_rtp {
namespace zrtp_msg {
PACKED_STRUCT(zrtp_hello_ack) {
PACK(struct zrtp_hello_ack {
zrtp_msg msg_start;
uint32_t crc;
};
});
class hello_ack {
public: