From 15dfb6f10d650582f52efb8148c641d21d9549a8 Mon Sep 17 00:00:00 2001 From: Max Lv Date: Thu, 29 Dec 2016 16:00:50 +0800 Subject: [PATCH] Refine the alignment again --- src/obfs_tls.c | 13 +++++-------- src/obfs_tls.h | 14 +++++++------- src/socks5.h | 8 ++++---- src/utils.h | 2 +- 4 files changed, 17 insertions(+), 20 deletions(-) diff --git a/src/obfs_tls.c b/src/obfs_tls.c index 0b3c27e0..b723ba42 100644 --- a/src/obfs_tls.c +++ b/src/obfs_tls.c @@ -67,7 +67,7 @@ tls_ext_server_name_template = { .ext_len = 0, .server_name_list_len = 0, .server_name_type = 0, - .server_name_len = 0 + .server_name_len = 0, // char server_name[server_name_len]; }; @@ -102,7 +102,7 @@ tls_ext_others_template = { .encrypt_then_mac_ext_len = 0, .extended_master_secret_type = CT_HTONS(0x0017), - .extended_master_secret_ext_len = 0 + .extended_master_secret_ext_len = 0, }; static const struct tls_server_hello @@ -136,7 +136,7 @@ tls_server_hello_template = { .ec_point_formats_ext_type = CT_HTONS(0x000B), .ec_point_formats_ext_len = CT_HTONS(2), .ec_point_formats_len = 1, - .ec_point_formats = { 0 } + .ec_point_formats = { 0 }, }; static const struct tls_change_cipher_spec @@ -144,20 +144,19 @@ tls_change_cipher_spec_template = { .content_type = 0x14, .version = CT_HTONS(0x0303), .len = CT_HTONS(1), - .msg = 0x01 + .msg = 0x01, }; static const struct tls_encrypted_handshake tls_encrypted_handshake_template = { .content_type = 0x16, .version = CT_HTONS(0x0303), - .len = 0 + .len = 0, // char msg[len]; }; const char tls_data_header[3] = {0x17, 0x03, 0x03}; - static int obfs_tls_request(buffer_t *, size_t, obfs_t *); static int obfs_tls_response(buffer_t *, size_t, obfs_t *); static int deobfs_tls_request(buffer_t *, size_t, obfs_t *); @@ -247,7 +246,6 @@ deobfs_app_data(buffer_t *buf, size_t idx, obfs_t *obfs) static int obfs_tls_request(buffer_t *buf, size_t cap, obfs_t *obfs) { - if (obfs == NULL || obfs->obfs_stage < 0) return 0; static buffer_t tmp = { 0, 0, 0, NULL }; @@ -489,7 +487,6 @@ deobfs_tls_response(buffer_t *buf, size_t cap, obfs_t *obfs) } - return 0; } diff --git a/src/obfs_tls.h b/src/obfs_tls.h index 943a8fbf..29f6f2a6 100644 --- a/src/obfs_tls.h +++ b/src/obfs_tls.h @@ -44,7 +44,7 @@ struct tls_client_hello { char comp_methods_len; char comp_methods[1]; short ext_len; -} __attribute__((packed)); +} __attribute__((packed, aligned(1))); struct tls_ext_server_name { short ext_type; @@ -53,13 +53,13 @@ struct tls_ext_server_name { char server_name_type; short server_name_len; // char server_name[server_name_len]; -} __attribute__((packed)); +} __attribute__((packed, aligned(1))); struct tls_ext_session_ticket { short session_ticket_type; short session_ticket_ext_len; // char session_ticket[session_ticket_ext_len]; -} __attribute__((packed)); +} __attribute__((packed, aligned(1))); struct tls_ext_others { short ec_point_formats_ext_type; @@ -82,7 +82,7 @@ struct tls_ext_others { short extended_master_secret_type; short extended_master_secret_ext_len; -} __attribute__((packed)); +} __attribute__((packed, aligned(1))); struct tls_server_hello { char content_type; @@ -113,21 +113,21 @@ struct tls_server_hello { short ec_point_formats_ext_len; char ec_point_formats_len; char ec_point_formats[1]; -} __attribute__((packed)); +} __attribute__((packed, aligned(1))); struct tls_change_cipher_spec { char content_type; short version; short len; char msg; -} __attribute__((packed)); +} __attribute__((packed, aligned(1))); struct tls_encrypted_handshake { char content_type; short version; short len; // char msg[len]; -} __attribute__((packed)); +} __attribute__((packed, aligned(1))); typedef struct frame { short idx; diff --git a/src/socks5.h b/src/socks5.h index 984c09e2..538830eb 100644 --- a/src/socks5.h +++ b/src/socks5.h @@ -34,25 +34,25 @@ struct method_select_request { char ver; char nmethods; char methods[255]; -} __attribute__((packed)); +} __attribute__((packed, aligned(1))); struct method_select_response { char ver; char method; -} __attribute__((packed)); +} __attribute__((packed, aligned(1))); struct socks5_request { char ver; char cmd; char rsv; char atyp; -} __attribute__((packed)); +} __attribute__((packed, aligned(1))); struct socks5_response { char ver; char rep; char rsv; char atyp; -} __attribute__((packed)); +} __attribute__((packed, aligned(1))); #endif // _SOCKS5_H diff --git a/src/utils.h b/src/utils.h index 7c768f5f..654ab959 100644 --- a/src/utils.h +++ b/src/utils.h @@ -229,7 +229,7 @@ void *ss_realloc(void *ptr, size_t new_size); ptr = NULL; \ } while (0) -#ifdef WORDS_BIGENDIAN +#if _BYTE_ORDER == _BIG_ENDIAN #define CT_HTONS(n) (n) #define CT_NTOHS(n) (n)