Implement cross-platform structure packing
This commit is contained in:
		
							parent
							
								
									3350140196
								
							
						
					
					
						commit
						1ad489620e
					
				| 
						 | 
					@ -41,7 +41,7 @@ namespace uvg_rtp {
 | 
				
			||||||
            RTCP_FT_APP  = 204  /* Application-specific message */
 | 
					            RTCP_FT_APP  = 204  /* Application-specific message */
 | 
				
			||||||
        };
 | 
					        };
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        PACKED_STRUCT(rtp_header) {
 | 
					        PACK(struct rtp_header {
 | 
				
			||||||
            uint8_t version:2;
 | 
					            uint8_t version:2;
 | 
				
			||||||
            uint8_t padding:1;
 | 
					            uint8_t padding:1;
 | 
				
			||||||
            uint8_t ext:1;
 | 
					            uint8_t ext:1;
 | 
				
			||||||
| 
						 | 
					@ -51,13 +51,13 @@ namespace uvg_rtp {
 | 
				
			||||||
            uint16_t seq;
 | 
					            uint16_t seq;
 | 
				
			||||||
            uint32_t timestamp;
 | 
					            uint32_t timestamp;
 | 
				
			||||||
            uint32_t ssrc;
 | 
					            uint32_t ssrc;
 | 
				
			||||||
        };
 | 
					        });
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        PACKED_STRUCT(ext_header) {
 | 
					        PACK(struct ext_header {
 | 
				
			||||||
            uint16_t type;
 | 
					            uint16_t type;
 | 
				
			||||||
            uint16_t len;
 | 
					            uint16_t len;
 | 
				
			||||||
            uint8_t *data;
 | 
					            uint8_t *data;
 | 
				
			||||||
        };
 | 
					        });
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        struct rtp_frame {
 | 
					        struct rtp_frame {
 | 
				
			||||||
            struct rtp_header header;
 | 
					            struct rtp_header header;
 | 
				
			||||||
| 
						 | 
					@ -150,14 +150,14 @@ namespace uvg_rtp {
 | 
				
			||||||
            uint8_t *payload;
 | 
					            uint8_t *payload;
 | 
				
			||||||
        };
 | 
					        };
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        PACKED_STRUCT(zrtp_frame) {
 | 
					        PACK(struct zrtp_frame {
 | 
				
			||||||
            uint8_t version:4;
 | 
					            uint8_t version:4;
 | 
				
			||||||
            uint16_t unused:12;
 | 
					            uint16_t unused:12;
 | 
				
			||||||
            uint16_t seq;
 | 
					            uint16_t seq;
 | 
				
			||||||
            uint32_t magic;
 | 
					            uint32_t magic;
 | 
				
			||||||
            uint32_t ssrc;
 | 
					            uint32_t ssrc;
 | 
				
			||||||
            uint8_t payload[1];
 | 
					            uint8_t payload[1];
 | 
				
			||||||
        };
 | 
					        });
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        /* Allocate an RTP frame
 | 
					        /* Allocate an RTP frame
 | 
				
			||||||
         *
 | 
					         *
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -18,13 +18,11 @@
 | 
				
			||||||
typedef SSIZE_T ssize_t;
 | 
					typedef SSIZE_T ssize_t;
 | 
				
			||||||
#endif
 | 
					#endif
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/* https://stackoverflow.com/questions/1537964/visual-c-equivalent-of-gccs-attribute-packed  */
 | 
				
			||||||
#if defined(__MINGW32__) || defined(__MINGW64__) || defined(__linux__)
 | 
					#if defined(__MINGW32__) || defined(__MINGW64__) || defined(__linux__)
 | 
				
			||||||
#define PACKED_STRUCT(name) \
 | 
					#define PACK(__Declaration__) __Declaration__ __attribute__((__packed__))
 | 
				
			||||||
    struct __attribute__((packed)) name
 | 
					 | 
				
			||||||
#else
 | 
					#else
 | 
				
			||||||
//#warning "structures are not packed!"
 | 
					#define PACK(__Declaration__) __pragma(pack(push, 1)) __Declaration__ __pragma(pack(pop))
 | 
				
			||||||
#define PACKED_STRUCT(name) struct name
 | 
					 | 
				
			||||||
#endif
 | 
					#endif
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#ifdef _WIN32
 | 
					#ifdef _WIN32
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -14,7 +14,7 @@ namespace uvg_rtp {
 | 
				
			||||||
    namespace zrtp_msg {
 | 
					    namespace zrtp_msg {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        /* DH Commit Message */
 | 
					        /* DH Commit Message */
 | 
				
			||||||
        PACKED_STRUCT(zrtp_commit) {
 | 
					        PACK(struct zrtp_commit {
 | 
				
			||||||
            zrtp_msg msg_start;
 | 
					            zrtp_msg msg_start;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            uint32_t hash[8];
 | 
					            uint32_t hash[8];
 | 
				
			||||||
| 
						 | 
					@ -28,7 +28,7 @@ namespace uvg_rtp {
 | 
				
			||||||
            uint32_t hvi[8];
 | 
					            uint32_t hvi[8];
 | 
				
			||||||
            uint32_t mac[2];
 | 
					            uint32_t mac[2];
 | 
				
			||||||
            uint32_t crc;
 | 
					            uint32_t crc;
 | 
				
			||||||
        };
 | 
					        });
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        class commit {
 | 
					        class commit {
 | 
				
			||||||
            public:
 | 
					            public:
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -11,10 +11,10 @@ namespace uvg_rtp {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    namespace zrtp_msg {
 | 
					    namespace zrtp_msg {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        PACKED_STRUCT(zrtp_confack) {
 | 
					        PACK(struct zrtp_confack {
 | 
				
			||||||
            zrtp_msg msg_start;
 | 
					            zrtp_msg msg_start;
 | 
				
			||||||
            uint32_t crc;
 | 
					            uint32_t crc;
 | 
				
			||||||
        };
 | 
					        });
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        class confack {
 | 
					        class confack {
 | 
				
			||||||
            public:
 | 
					            public:
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -11,7 +11,7 @@ namespace uvg_rtp {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    namespace zrtp_msg {
 | 
					    namespace zrtp_msg {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        PACKED_STRUCT(zrtp_confirm) {
 | 
					        PACK(struct zrtp_confirm {
 | 
				
			||||||
            zrtp_msg msg_start;
 | 
					            zrtp_msg msg_start;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            uint8_t confirm_mac[8];
 | 
					            uint8_t confirm_mac[8];
 | 
				
			||||||
| 
						 | 
					@ -32,7 +32,7 @@ namespace uvg_rtp {
 | 
				
			||||||
            /* encrypted portion ends */
 | 
					            /* encrypted portion ends */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            uint32_t crc;
 | 
					            uint32_t crc;
 | 
				
			||||||
        };
 | 
					        });
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        class confirm {
 | 
					        class confirm {
 | 
				
			||||||
            public:
 | 
					            public:
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -11,20 +11,20 @@ namespace uvg_rtp {
 | 
				
			||||||
        struct zrtp_hello;
 | 
					        struct zrtp_hello;
 | 
				
			||||||
        struct zrtp_dh;
 | 
					        struct zrtp_dh;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        PACKED_STRUCT(zrtp_header) {
 | 
					        PACK(struct zrtp_header {
 | 
				
			||||||
            uint8_t version:4;
 | 
					            uint8_t version:4;
 | 
				
			||||||
            uint16_t unused:12;
 | 
					            uint16_t unused:12;
 | 
				
			||||||
            uint16_t seq;
 | 
					            uint16_t seq;
 | 
				
			||||||
            uint32_t magic;
 | 
					            uint32_t magic;
 | 
				
			||||||
            uint32_t ssrc;
 | 
					            uint32_t ssrc;
 | 
				
			||||||
        };
 | 
					        });
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        PACKED_STRUCT(zrtp_msg) {
 | 
					        PACK(struct zrtp_msg {
 | 
				
			||||||
            struct zrtp_header header;
 | 
					            struct zrtp_header header;
 | 
				
			||||||
            uint16_t magic;
 | 
					            uint16_t magic;
 | 
				
			||||||
            uint16_t length;
 | 
					            uint16_t length;
 | 
				
			||||||
            uint64_t msgblock;
 | 
					            uint64_t msgblock;
 | 
				
			||||||
        };
 | 
					        });
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        enum ZRTP_FRAME_TYPE {
 | 
					        enum ZRTP_FRAME_TYPE {
 | 
				
			||||||
            ZRTP_FT_HELLO     =  1,
 | 
					            ZRTP_FT_HELLO     =  1,
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -13,7 +13,7 @@ namespace uvg_rtp {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    namespace zrtp_msg {
 | 
					    namespace zrtp_msg {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        PACKED_STRUCT(zrtp_dh) {
 | 
					        PACK(struct zrtp_dh {
 | 
				
			||||||
            zrtp_msg msg_start;
 | 
					            zrtp_msg msg_start;
 | 
				
			||||||
            uint32_t hash[8];
 | 
					            uint32_t hash[8];
 | 
				
			||||||
            uint8_t rs1_id[8];
 | 
					            uint8_t rs1_id[8];
 | 
				
			||||||
| 
						 | 
					@ -23,7 +23,7 @@ namespace uvg_rtp {
 | 
				
			||||||
            uint8_t pk[384];
 | 
					            uint8_t pk[384];
 | 
				
			||||||
            uint8_t mac[8];
 | 
					            uint8_t mac[8];
 | 
				
			||||||
            uint32_t crc;
 | 
					            uint32_t crc;
 | 
				
			||||||
        };
 | 
					        });
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        class dh_key_exchange {
 | 
					        class dh_key_exchange {
 | 
				
			||||||
            public:
 | 
					            public:
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -10,11 +10,11 @@ namespace uvg_rtp {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    namespace zrtp_msg {
 | 
					    namespace zrtp_msg {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        PACKED_STRUCT(zrtp_error) {
 | 
					        PACK(struct zrtp_error {
 | 
				
			||||||
            zrtp_msg msg_start;
 | 
					            zrtp_msg msg_start;
 | 
				
			||||||
            uint32_t error;
 | 
					            uint32_t error;
 | 
				
			||||||
            uint32_t crc;
 | 
					            uint32_t crc;
 | 
				
			||||||
        };
 | 
					        });
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        class error {
 | 
					        class error {
 | 
				
			||||||
            public:
 | 
					            public:
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -14,7 +14,7 @@ namespace uvg_rtp {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    namespace zrtp_msg {
 | 
					    namespace zrtp_msg {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        PACKED_STRUCT(zrtp_hello) {
 | 
					        PACK(struct zrtp_hello {
 | 
				
			||||||
            zrtp_msg msg_start;
 | 
					            zrtp_msg msg_start;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            uint32_t version;
 | 
					            uint32_t version;
 | 
				
			||||||
| 
						 | 
					@ -35,7 +35,7 @@ namespace uvg_rtp {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            uint64_t mac;
 | 
					            uint64_t mac;
 | 
				
			||||||
            uint32_t crc;
 | 
					            uint32_t crc;
 | 
				
			||||||
        };
 | 
					        });
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        class hello {
 | 
					        class hello {
 | 
				
			||||||
            public:
 | 
					            public:
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -10,10 +10,10 @@ namespace uvg_rtp {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    namespace zrtp_msg {
 | 
					    namespace zrtp_msg {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        PACKED_STRUCT(zrtp_hello_ack) {
 | 
					        PACK(struct zrtp_hello_ack {
 | 
				
			||||||
            zrtp_msg msg_start;
 | 
					            zrtp_msg msg_start;
 | 
				
			||||||
            uint32_t crc;
 | 
					            uint32_t crc;
 | 
				
			||||||
        };
 | 
					        });
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        class hello_ack {
 | 
					        class hello_ack {
 | 
				
			||||||
            public:
 | 
					            public:
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in New Issue