Sfoglia il codice sorgente

port to compile with MSVC

ambrop7 13 anni fa
parent
commit
a21e23fe8a
83 ha cambiato i file con 1069 aggiunte e 639 eliminazioni
  1. 10 6
      CMakeLists.txt
  2. 4 8
      base/BLog.c
  3. 1 0
      base/BLog.h
  4. 1 1
      blog_generator/blog.php
  5. 20 6
      bproto/BProto.h
  6. 1 1
      client/DPRelay.c
  7. 1 1
      client/DataProto.c
  8. 3 3
      client/FragmentProtoAssembler.c
  9. 3 3
      client/FrameDecider.c
  10. 3 3
      client/PasswordListener.c
  11. 1 1
      client/SPProtoDecoder.c
  12. 1 1
      client/SPProtoEncoder.c
  13. 1 1
      client/SimpleStreamBuffer.c
  14. 1 1
      client/StreamPeerIO.c
  15. 48 41
      client/client.c
  16. 3 3
      examples/bavl_test.c
  17. 2 2
      examples/bencryption_bench.c
  18. 2 2
      examples/bheap_test.c
  19. 8 5
      examples/predicate_test.c
  20. 3 3
      examples/savl_test.c
  21. 1 1
      examples/stdin_input.c
  22. 7 6
      examples/substring_test.c
  23. 10 0
      fix_flex.php
  24. 5 1
      flooder/flooder.c
  25. 1 1
      flow/LineBuffer.c
  26. 1 1
      flow/PacketBuffer.c
  27. 1 1
      flow/PacketProtoDecoder.c
  28. 1 1
      flow/RouteBuffer.c
  29. 1 1
      flow/SinglePacketBuffer.c
  30. 2 0
      generate_files
  31. 110 109
      generated/bison_BPredicate.c
  32. 27 7
      generated/bison_BPredicate.h
  33. 125 125
      generated/blog_channels_list.h
  34. 32 40
      generated/flex_BPredicate.c
  35. 4 4
      generated/flex_BPredicate.h
  36. 18 7
      lwip/custom/arch/cc.h
  37. 2 2
      lwip/src/include/netif/etharp.h
  38. 1 1
      misc/balloc.h
  39. 1 1
      misc/debugcounter.h
  40. 5 1
      misc/ethernet_proto.h
  41. 20 6
      misc/igmp_proto.h
  42. 8 3
      misc/ipv4_proto.h
  43. 51 0
      misc/packed.h
  44. 1 1
      misc/parse_number.h
  45. 98 0
      misc/print_macros.h
  46. 23 7
      misc/socks_proto.h
  47. 86 0
      misc/strdup.h
  48. 4 2
      misc/udp_proto.h
  49. 1 1
      ncd/NCDRequestClient.c
  50. 1 1
      ncd/modules/sys_request_server.c
  51. 2 2
      nspr_support/BSSLConnection.c
  52. 2 2
      predicate/BPredicate.c
  53. 5 7
      predicate/BPredicate.l
  54. 6 6
      predicate/BPredicate.y
  55. 2 0
      predicate/BPredicate_parser.h
  56. 7 2
      protocol/dataproto.h
  57. 4 1
      protocol/fragmentproto.h
  58. 5 1
      protocol/packetproto.h
  59. 29 9
      protocol/scproto.h
  60. 4 1
      protocol/spproto.h
  61. 4 1
      protocol/udpgw_proto.h
  62. 1 1
      security/OTPCalculator.c
  63. 2 2
      security/OTPChecker.c
  64. 23 21
      server/server.c
  65. 16 4
      server_connection/ServerConnection.c
  66. 1 1
      server_connection/ServerConnection.h
  67. 1 1
      socksclient/BSocksClient.c
  68. 31 18
      socksclient/BSocksClient.h
  69. 9 5
      system/BAddr.h
  70. 23 19
      system/BConnection.h
  71. 9 9
      system/BConnection_win.c
  72. 6 7
      system/BDatagram_win.c
  73. 1 1
      system/BInputProcess.c
  74. 1 1
      system/BSignal.c
  75. 1 1
      system/BTime.c
  76. 2 2
      tests/bproto_test.c
  77. 6 8
      tun2socks/tun2socks.c
  78. 20 16
      tuntap/BTap.c
  79. 64 55
      tuntap/tapwin32-funcs.c
  80. 2 2
      tuntap/tapwin32-funcs.h
  81. 5 5
      udpgw/udpgw.c
  82. 1 1
      udpgw_client/UdpGwClient.c
  83. 9 4
      udpgw_client/UdpGwClient.h

+ 10 - 6
CMakeLists.txt

@@ -107,18 +107,22 @@ if (NOT (SIZE_SIZE GREATER INT_SIZE OR SIZE_SIZE EQUAL INT_SIZE))
     message(FATAL_ERROR "size_t must be greater or equal than int")
 endif ()
 
-add_definitions(-std=gnu99 -Werror=implicit-function-declaration -Wno-unused-value -Wno-parentheses -Wno-switch-enum -Wno-switch -Wredundant-decls)
+if (MSVC)
+    add_definitions(/TP -D_CRT_SECURE_NO_WARNINGS /wd4065 /wd4018 /wd4533 /wd4244 /wd4102)
+else ()
+    add_definitions(-std=gnu99 -Werror=implicit-function-declaration -Wno-unused-value -Wno-parentheses -Wno-switch-enum -Wno-switch -Wredundant-decls)
+endif ()
 
 # platform-specific stuff
 if (WIN32)
     add_definitions(-DBADVPN_USE_WINAPI -D_WIN32_WINNT=0x600 -DWIN32_LEAN_AND_MEAN)
 
     set(CMAKE_REQUIRED_DEFINITIONS "-D_WIN32_WINNT=0x600")
-    check_symbol_exists(WSAID_WSASENDMSG "mswsock.h" HAVE_MSW_1)
-    check_symbol_exists(WSAID_WSARECVMSG "mswsock.h" HAVE_MSW_2)
-    check_symbol_exists(WSAID_ACCEPTEX "mswsock.h" HAVE_MSW_3)
-    check_symbol_exists(WSAID_GETACCEPTEXSOCKADDRS "mswsock.h" HAVE_MSW_4)
-    check_symbol_exists(WSAID_CONNECTEX "mswsock.h" HAVE_MSW_5)
+    check_symbol_exists(WSAID_WSASENDMSG "winsock2.h;mswsock.h" HAVE_MSW_1)
+    check_symbol_exists(WSAID_WSARECVMSG "winsock2.h;mswsock.h" HAVE_MSW_2)
+    check_symbol_exists(WSAID_ACCEPTEX "winsock2.h;mswsock.h" HAVE_MSW_3)
+    check_symbol_exists(WSAID_GETACCEPTEXSOCKADDRS "winsock2.h;mswsock.h" HAVE_MSW_4)
+    check_symbol_exists(WSAID_CONNECTEX "winsock2.h;mswsock.h" HAVE_MSW_5)
     set(CMAKE_REQUIRED_DEFINITIONS "")
     if (NOT (HAVE_MSW_1 AND HAVE_MSW_2 AND HAVE_MSW_3 AND HAVE_MSW_4 AND HAVE_MSW_5))
         add_definitions(-DBADVPN_USE_SHIPPED_MSWSOCK)

+ 4 - 8
base/BLog.c

@@ -28,6 +28,7 @@
  */
 
 #include <stdio.h>
+#include <stddef.h>
 
 #include "BLog.h"
 
@@ -37,17 +38,12 @@ struct _BLog_channel blog_channel_list[] = {
 
 struct _BLog_global blog_global = {
     #ifndef NDEBUG
-    .initialized = 0,
+    0
     #endif
 };
 
-static char *level_names[] = {
-    [BLOG_ERROR] = "ERROR",
-    [BLOG_WARNING] = "WARNING",
-    [BLOG_NOTICE] = "NOTICE",
-    [BLOG_INFO] = "INFO",
-    [BLOG_DEBUG] = "DEBUG",
-};
+// keep in sync with level numbers in BLog.h!
+static char *level_names[] = { NULL, "ERROR", "WARNING", "NOTICE", "INFO", "DEBUG" };
 
 static void stdout_log (int channel, int level, const char *msg)
 {

+ 1 - 0
base/BLog.h

@@ -42,6 +42,7 @@
 // auto-generated channel numbers and number of channels
 #include <generated/blog_channels_defines.h>
 
+// keep in sync with level names in BLog.c!
 #define BLOG_ERROR 1
 #define BLOG_WARNING 2
 #define BLOG_NOTICE 3

+ 1 - 1
blog_generator/blog.php

@@ -95,7 +95,7 @@ EOD;
 EOD;
 
     $channels_list .= <<<EOD
-{.name = "{$ch_name[1]}", .loglevel = {$ch_priority[1]}},
+{"{$ch_name[1]}", {$ch_priority[1]}},
 
 EOD;
 

+ 20 - 6
bproto/BProto.h

@@ -36,6 +36,8 @@
 
 #include <stdint.h>
 
+#include <misc/packed.h>
+
 #define BPROTO_TYPE_UINT8 1
 #define BPROTO_TYPE_UINT16 2
 #define BPROTO_TYPE_UINT32 3
@@ -43,29 +45,41 @@
 #define BPROTO_TYPE_DATA 5
 #define BPROTO_TYPE_CONSTDATA 6
 
+B_START_PACKED
 struct BProto_header_s {
     uint16_t id;
     uint16_t type;
-} __attribute__((packed));
+} B_PACKED;
+B_END_PACKED
 
+B_START_PACKED
 struct BProto_uint8_s {
     uint8_t v;
-} __attribute__((packed));
+} B_PACKED;
+B_END_PACKED
 
+B_START_PACKED
 struct BProto_uint16_s {
     uint16_t v;
-} __attribute__((packed));
+} B_PACKED;
+B_END_PACKED
 
+B_START_PACKED
 struct BProto_uint32_s {
     uint32_t v;
-} __attribute__((packed));
+} B_PACKED;
+B_END_PACKED
 
+B_START_PACKED
 struct BProto_uint64_s {
     uint64_t v;
-} __attribute__((packed));
+} B_PACKED;
+B_END_PACKED
 
+B_START_PACKED
 struct BProto_data_header_s {
     uint32_t len;
-} __attribute__((packed));
+} B_PACKED;
+B_END_PACKED
 
 #endif

+ 1 - 1
client/DPRelay.c

@@ -44,7 +44,7 @@ static struct DPRelay_flow * create_flow (DPRelaySource *src, DPRelaySink *sink,
     ASSERT(num_packets > 0)
     
     // allocate structure
-    struct DPRelay_flow *flow = malloc(sizeof(*flow));
+    struct DPRelay_flow *flow = (struct DPRelay_flow *)malloc(sizeof(*flow));
     if (!flow) {
         BLog(BLOG_ERROR, "relay flow %d->%d: malloc failed", (int)src->source_id, (int)sink->dest_id);
         goto fail0;

+ 1 - 1
client/DataProto.c

@@ -407,7 +407,7 @@ int DataProtoFlow_Init (DataProtoFlow *o, DataProtoSource *source, peerid_t sour
     o->sink_desired = NULL;
     
     // allocate buffer structure
-    struct DataProtoFlow_buffer *b = malloc(sizeof(*b));
+    struct DataProtoFlow_buffer *b = (struct DataProtoFlow_buffer *)malloc(sizeof(*b));
     if (!b) {
         BLog(BLOG_ERROR, "malloc failed");
         goto fail0;

+ 3 - 3
client/FragmentProtoAssembler.c

@@ -396,17 +396,17 @@ int FragmentProtoAssembler_Init (FragmentProtoAssembler *o, int input_mtu, Packe
     o->time_tolerance = num_frames;
     
     // allocate frames
-    if (!(o->frames_entries = BAllocArray(num_frames, sizeof(o->frames_entries[0])))) {
+    if (!(o->frames_entries = (struct FragmentProtoAssembler_frame *)BAllocArray(num_frames, sizeof(o->frames_entries[0])))) {
         goto fail1;
     }
     
     // allocate chunks
-    if (!(o->frames_chunks = BAllocArray2(num_frames, o->num_chunks, sizeof(o->frames_chunks[0])))) {
+    if (!(o->frames_chunks = (struct FragmentProtoAssembler_chunk *)BAllocArray2(num_frames, o->num_chunks, sizeof(o->frames_chunks[0])))) {
         goto fail2;
     }
     
     // allocate buffers
-    if (!(o->frames_buffer = BAllocArray(num_frames, o->output_mtu))) {
+    if (!(o->frames_buffer = (uint8_t *)BAllocArray(num_frames, o->output_mtu))) {
         goto fail3;
     }
     

+ 3 - 3
client/FrameDecider.c

@@ -29,7 +29,6 @@
 
 #include <string.h>
 #include <stddef.h>
-#include <inttypes.h>
 
 #include <misc/debug.h>
 #include <misc/offset.h>
@@ -39,6 +38,7 @@
 #include <misc/igmp_proto.h>
 #include <misc/byteorder.h>
 #include <misc/compare.h>
+#include <misc/print_macros.h>
 
 #include <client/FrameDecider.h>
 
@@ -553,13 +553,13 @@ int FrameDeciderPeer_Init (FrameDeciderPeer *o, FrameDecider *d, void *user, BLo
     o->logfunc = logfunc;
     
     // allocate MAC entries
-    if (!(o->mac_entries = BAllocArray(d->max_peer_macs, sizeof(struct _FrameDecider_mac_entry)))) {
+    if (!(o->mac_entries = (struct _FrameDecider_mac_entry *)BAllocArray(d->max_peer_macs, sizeof(struct _FrameDecider_mac_entry)))) {
         PeerLog(o, BLOG_ERROR, "failed to allocate MAC entries");
         goto fail0;
     }
     
     // allocate group entries
-    if (!(o->group_entries = BAllocArray(d->max_peer_groups, sizeof(struct _FrameDecider_group_entry)))) {
+    if (!(o->group_entries = (struct _FrameDecider_group_entry *)BAllocArray(d->max_peer_groups, sizeof(struct _FrameDecider_group_entry)))) {
         PeerLog(o, BLOG_ERROR, "failed to allocate group entries");
         goto fail1;
     }

+ 3 - 3
client/PasswordListener.c

@@ -99,13 +99,13 @@ void listener_handler (PasswordListener *l)
     LinkedList2_Append(&l->clients_used, &client->list_node);
     
     // allocate sslsocket structure
-    if (!(client->sock = malloc(sizeof(*client->sock)))) {
+    if (!(client->sock = (sslsocket *)malloc(sizeof(*client->sock)))) {
         BLog(BLOG_ERROR, "malloc failedt");
         goto fail0;
     }
     
     // accept connection
-    if (!BConnection_Init(&client->sock->con, BCONNECTION_SOURCE_LISTENER(&l->listener, NULL), l->bsys, client, (BConnection_handler)client_connection_handler)) {
+    if (!BConnection_Init(&client->sock->con, BConnection_source_listener(&l->listener, NULL), l->bsys, client, (BConnection_handler)client_connection_handler)) {
         BLog(BLOG_ERROR, "BConnection_Init failed");
         goto fail1;
     }
@@ -257,7 +257,7 @@ int PasswordListener_Init (PasswordListener *l, BReactor *bsys, BAddr listen_add
     l->ssl = ssl;
     
     // allocate client entries
-    if (!(l->clients_data = BAllocArray(max_clients, sizeof(struct PasswordListenerClient)))) {
+    if (!(l->clients_data = (struct PasswordListenerClient *)BAllocArray(max_clients, sizeof(struct PasswordListenerClient)))) {
         BLog(BLOG_ERROR, "BAllocArray failed");
         goto fail0;
     }

+ 1 - 1
client/SPProtoDecoder.c

@@ -260,7 +260,7 @@ int SPProtoDecoder_Init (SPProtoDecoder *o, PacketPassInterface *output, struct
     // allocate plaintext buffer
     if (SPPROTO_HAVE_ENCRYPTION(o->sp_params)) {
         int buf_size = balign_up((SPPROTO_HEADER_LEN(o->sp_params) + o->output_mtu + 1), o->enc_block_size);
-        if (!(o->buf = malloc(buf_size))) {
+        if (!(o->buf = (uint8_t *)malloc(buf_size))) {
             goto fail0;
         }
     }

+ 1 - 1
client/SPProtoEncoder.c

@@ -303,7 +303,7 @@ int SPProtoEncoder_Init (SPProtoEncoder *o, PacketRecvInterface *input, struct s
     // allocate plaintext buffer
     if (SPPROTO_HAVE_ENCRYPTION(o->sp_params)) {
         int buf_size = balign_up((SPPROTO_HEADER_LEN(o->sp_params) + o->input_mtu + 1), o->enc_block_size);
-        if (!(o->buf = malloc(buf_size))) {
+        if (!(o->buf = (uint8_t *)malloc(buf_size))) {
             goto fail1;
         }
     }

+ 1 - 1
client/SimpleStreamBuffer.c

@@ -84,7 +84,7 @@ int SimpleStreamBuffer_Init (SimpleStreamBuffer *o, int buf_size, BPendingGroup
     StreamRecvInterface_Init(&o->output, (StreamRecvInterface_handler_recv)output_handler_recv, o, pg);
     
     // allocate buffer
-    if (!(o->buf = BAlloc(buf_size))) {
+    if (!(o->buf = (uint8_t *)BAlloc(buf_size))) {
         goto fail1;
     }
     

+ 1 - 1
client/StreamPeerIO.c

@@ -93,7 +93,7 @@ void connector_handler (StreamPeerIO *pio, int is_error)
     }
     
     // init connection
-    if (!BConnection_Init(&pio->connect.sock.con, BCONNECTION_SOURCE_CONNECTOR(&pio->connect.connector), pio->reactor, pio, (BConnection_handler)connection_handler)) {
+    if (!BConnection_Init(&pio->connect.sock.con, BConnection_source_connector(&pio->connect.connector), pio->reactor, pio, (BConnection_handler)connection_handler)) {
         PeerLog(pio, BLOG_ERROR, "BConnection_Init failed");
         goto fail0;
     }

+ 48 - 41
client/client.c

@@ -27,7 +27,7 @@
  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
-#include <inttypes.h>
+#include <stdint.h>
 #include <stdlib.h>
 #include <string.h>
 #include <limits.h>
@@ -71,10 +71,17 @@
 #define LOGGER_STDOUT 1
 #define LOGGER_SYSLOG 2
 
-// declares and initializes a pointer x to y
-#define POINTER(x, y) typeof (y) *(x) = &(y);
-
 // command-line options
+struct ext_addr_option  {
+    char *addr;
+    char *scope;
+};
+struct bind_addr_option {
+    char *addr;
+    int num_ports;
+    int num_ext_addrs;
+    struct ext_addr_option ext_addrs[MAX_EXT_ADDRS];
+};
 struct {
     int help;
     int version;
@@ -95,15 +102,7 @@ struct {
     int num_scopes;
     char *scopes[MAX_SCOPES];
     int num_bind_addrs;
-    struct {
-        char *addr;
-        int num_ports;
-        int num_ext_addrs;
-        struct {
-            char *addr;
-            char *scope;
-        } ext_addrs[MAX_EXT_ADDRS];
-    } bind_addrs[MAX_BIND_ADDRS];
+    struct bind_addr_option bind_addrs[MAX_BIND_ADDRS];
     int transport_mode;
     int encryption_mode;
     int hash_mode;
@@ -123,17 +122,19 @@ struct {
 } options;
 
 // bind addresses
-int num_bind_addrs;
-struct {
+struct ext_addr {
+    int server_reported_port;
+    BAddr addr; // if server_reported_port>=0, defined only after hello received
+    char scope[64];
+};
+struct bind_addr {
     BAddr addr;
     int num_ports;
     int num_ext_addrs;
-    struct {
-        int server_reported_port;
-        BAddr addr; // if server_reported_port>=0, defined only after hello received
-        char scope[64];
-    } ext_addrs[MAX_EXT_ADDRS];
-} bind_addrs[MAX_BIND_ADDRS];
+    struct ext_addr ext_addrs[MAX_EXT_ADDRS];
+};
+int num_bind_addrs;
+struct bind_addr bind_addrs[MAX_BIND_ADDRS];
 
 // TCP listeners
 PasswordListener listeners[MAX_BIND_ADDRS];
@@ -498,7 +499,7 @@ int main (int argc, char *argv[])
     int num_listeners = 0;
     if (options.transport_mode == TRANSPORT_MODE_TCP) {
         while (num_listeners < num_bind_addrs) {
-            POINTER(addr, bind_addrs[num_listeners])
+            struct bind_addr *addr = &bind_addrs[num_listeners];
             if (!PasswordListener_Init(&listeners[num_listeners], &ss, addr->addr, TCP_MAX_PASSWORD_LISTENER_CLIENTS, options.peer_ssl, client_cert, client_key)) {
                 BLog(BLOG_ERROR, "PasswordListener_Init failed");
                 goto fail8;
@@ -887,7 +888,7 @@ int parse_arguments (int argc, char *argv[])
                 fprintf(stderr, "%s: too many\n", arg);
                 return 0;
             }
-            POINTER(addr, options.bind_addrs[options.num_bind_addrs])
+            struct bind_addr_option *addr = &options.bind_addrs[options.num_bind_addrs];
             addr->addr = argv[i + 1];
             addr->num_ports = -1;
             addr->num_ext_addrs = 0;
@@ -903,7 +904,7 @@ int parse_arguments (int argc, char *argv[])
                 fprintf(stderr, "%s: must folow --bind-addr\n", arg);
                 return 0;
             }
-            POINTER(addr, options.bind_addrs[options.num_bind_addrs - 1])
+            struct bind_addr_option *addr = &options.bind_addrs[options.num_bind_addrs - 1];
             if ((addr->num_ports = atoi(argv[i + 1])) < 0) {
                 fprintf(stderr, "%s: wrong argument\n", arg);
                 return 0;
@@ -919,12 +920,12 @@ int parse_arguments (int argc, char *argv[])
                 fprintf(stderr, "%s: must folow --bind-addr\n", arg);
                 return 0;
             }
-            POINTER(addr, options.bind_addrs[options.num_bind_addrs - 1])
+            struct bind_addr_option *addr = &options.bind_addrs[options.num_bind_addrs - 1];
             if (addr->num_ext_addrs == MAX_EXT_ADDRS) {
                 fprintf(stderr, "%s: too many\n", arg);
                 return 0;
             }
-            POINTER(eaddr, addr->ext_addrs[addr->num_ext_addrs])
+            struct ext_addr_option *eaddr = &addr->ext_addrs[addr->num_ext_addrs];
             eaddr->addr = argv[i + 1];
             eaddr->scope = argv[i + 2];
             addr->num_ext_addrs++;
@@ -1185,14 +1186,18 @@ int process_arguments (void)
     
     // override server name if requested
     if (options.server_name) {
-        snprintf(server_name, sizeof(server_name), "%s", options.server_name);
+        if (strlen(options.server_name) >= sizeof(server_name)) {
+            BLog(BLOG_ERROR, "server name: too long");
+            return 0;
+        }
+        strcpy(server_name, options.server_name);
     }
     
     // resolve bind addresses and external addresses
     num_bind_addrs = 0;
     for (int i = 0; i < options.num_bind_addrs; i++) {
-        POINTER(addr, options.bind_addrs[i])
-        POINTER(out, bind_addrs[num_bind_addrs])
+        struct bind_addr_option *addr = &options.bind_addrs[i];
+        struct bind_addr *out = &bind_addrs[num_bind_addrs];
         
         // read addr
         if (!BAddr_Parse(&out->addr, addr->addr, NULL, 0)) {
@@ -1216,8 +1221,8 @@ int process_arguments (void)
         // read ext addrs
         out->num_ext_addrs = 0;
         for (int j = 0; j < addr->num_ext_addrs; j++) {
-            POINTER(eaddr, addr->ext_addrs[j])
-            POINTER(eout, out->ext_addrs[out->num_ext_addrs])
+            struct ext_addr_option *eaddr = &addr->ext_addrs[j];
+            struct ext_addr *eout = &out->ext_addrs[out->num_ext_addrs];
             
             // read addr
             if (string_begins_with(eaddr->addr, "{server_reported}:")) {
@@ -1239,7 +1244,11 @@ int process_arguments (void)
             }
             
             // read scope
-            snprintf(eout->scope, sizeof(eout->scope), "%s", eaddr->scope);
+            if (strlen(eaddr->scope) >= sizeof(eout->scope)) {
+                BLog(BLOG_ERROR, "ext addr: too long");
+                return 0;
+            }
+            strcpy(eout->scope, eaddr->scope);
             
             out->num_ext_addrs++;
         }
@@ -1277,7 +1286,7 @@ void peer_add (peerid_t id, int flags, const uint8_t *cert, int cert_len)
     ASSERT(cert_len <= SCID_NEWCLIENT_MAX_CERT_LEN)
     
     // allocate structure
-    struct peer_data *peer = malloc(sizeof(*peer));
+    struct peer_data *peer = (struct peer_data *)malloc(sizeof(*peer));
     if (!peer) {
         BLog(BLOG_ERROR, "peer %d: failed to allocate memory", (int)id);
         goto fail0;
@@ -1307,7 +1316,7 @@ void peer_add (peerid_t id, int flags, const uint8_t *cert, int cert_len)
         // copy the certificate and append it a good load of zero bytes,
         // hopefully preventing the crappy CERT_DecodeCertFromPackage from crashing
         // by reading past the of its input
-        uint8_t *certbuf = malloc(cert_len + 100);
+        uint8_t *certbuf = (uint8_t *)malloc(cert_len + 100);
         if (!certbuf) {
             peer_log(peer, BLOG_ERROR, "malloc failed");
             goto fail1;
@@ -2247,8 +2256,6 @@ void peer_bind (struct peer_data *peer)
     ASSERT(peer->binding_addrpos >= 0)
     ASSERT(peer->binding_addrpos <= num_bind_addrs)
     
-    int res;
-    
     while (peer->binding_addrpos < num_bind_addrs) {
         // if there are no external addresses, skip bind address
         if (bind_addrs[peer->binding_addrpos].num_ext_addrs == 0) {
@@ -2301,7 +2308,7 @@ void peer_bind_one_address (struct peer_data *peer, int addr_index, int *cont)
     
     if (options.transport_mode == TRANSPORT_MODE_UDP) {
         // get addr
-        POINTER(addr, bind_addrs[addr_index]);
+        struct bind_addr *addr = &bind_addrs[addr_index];
         
         // try binding to all ports in the range
         int port_add;
@@ -2458,7 +2465,7 @@ void peer_send_conectinfo (struct peer_data *peer, int addr_index, int port_adju
     ASSERT(bind_addrs[addr_index].num_ext_addrs > 0)
     
     // get address
-    POINTER(bind_addr, bind_addrs[addr_index]);
+    struct bind_addr *bind_addr = &bind_addrs[addr_index];
     
     // remember encryption key size
     int key_size;
@@ -2682,9 +2689,9 @@ void server_handler_ready (void *user, peerid_t param_my_id, uint32_t ext_ip)
     
     // store server reported addresses
     for (int i = 0; i < num_bind_addrs; i++) {
-        POINTER(addr, bind_addrs[i]);
+        struct bind_addr *addr = &bind_addrs[i];
         for (int j = 0; j < addr->num_ext_addrs; j++) {
-            POINTER(eaddr, addr->ext_addrs[j]);
+            struct ext_addr *eaddr = &addr->ext_addrs[j];
             if (eaddr->server_reported_port >= 0) {
                 if (ext_ip == 0) {
                     BLog(BLOG_ERROR, "server did not provide our address");
@@ -2840,7 +2847,7 @@ struct server_flow * server_flow_init (void)
     ASSERT(server_ready)
     
     // allocate structure
-    struct server_flow *flow = malloc(sizeof(*flow));
+    struct server_flow *flow = (struct server_flow *)malloc(sizeof(*flow));
     if (!flow) {
         BLog(BLOG_ERROR, "malloc failed");
         goto fail0;

+ 3 - 3
examples/bavl_test.c

@@ -63,13 +63,13 @@ int main (int argc, char **argv)
         return 1;
     }
     
-    struct mynode *nodes = BAllocArray(num_nodes, sizeof(*nodes));
+    struct mynode *nodes = (struct mynode *)BAllocArray(num_nodes, sizeof(*nodes));
     ASSERT_FORCE(nodes)
     
-    int *values_ins = BAllocArray(num_nodes, sizeof(int));
+    int *values_ins = (int *)BAllocArray(num_nodes, sizeof(int));
     ASSERT_FORCE(values_ins)
     
-    int *values = BAllocArray(num_random_delete, sizeof(int));
+    int *values = (int *)BAllocArray(num_random_delete, sizeof(int));
     ASSERT_FORCE(values)
     
     BAVL avl;

+ 2 - 2
examples/bencryption_bench.c

@@ -108,13 +108,13 @@ int main (int argc, char **argv)
     
     printf("unit size %d\n", unit_size);
     
-    uint8_t *buf1 = BAlloc(unit_size);
+    uint8_t *buf1 = (uint8_t *)BAlloc(unit_size);
     if (!buf1) {
         printf("BAlloc failed");
         goto fail0;
     }
     
-    uint8_t *buf2 = BAlloc(unit_size);
+    uint8_t *buf2 = (uint8_t *)BAlloc(unit_size);
     if (!buf2) {
         printf("BAlloc failed");
         goto fail1;

+ 2 - 2
examples/bheap_test.c

@@ -80,10 +80,10 @@ int main (int argc, char **argv)
         return 1;
     }
     
-    struct mynode *nodes = BAllocArray(num_nodes, sizeof(*nodes));
+    struct mynode *nodes = (struct mynode *)BAllocArray(num_nodes, sizeof(*nodes));
     ASSERT_FORCE(nodes)
     
-    int *values = BAllocArray(num_random_delete, sizeof(int));
+    int *values = (int *)BAllocArray(num_random_delete, sizeof(int));
     ASSERT_FORCE(values)
     
     BHeap heap;

+ 8 - 5
examples/predicate_test.c

@@ -55,8 +55,8 @@ static int func_conj (void *user, void **args)
 
 static int func_strcmp (void *user, void **args)
 {
-    char *arg1 = args[0];
-    char *arg2 = args[1];
+    char *arg1 = (char *)args[0];
+    char *arg2 = (char *)args[1];
     
     return (!strcmp(arg1, arg2));
 }
@@ -86,12 +86,15 @@ int main (int argc, char **argv)
     // init functions
     BPredicateFunction f_hello;
     BPredicateFunction_Init(&f_hello, &pr, "hello", NULL, 0, func_hello, NULL);
+    int arr1[] = {PREDICATE_TYPE_BOOL};
     BPredicateFunction f_neg;
-    BPredicateFunction_Init(&f_neg, &pr, "neg", (int []){PREDICATE_TYPE_BOOL}, 1, func_neg, NULL);
+    BPredicateFunction_Init(&f_neg, &pr, "neg", arr1, 1, func_neg, NULL);
+    int arr2[] = {PREDICATE_TYPE_BOOL, PREDICATE_TYPE_BOOL};
     BPredicateFunction f_conj;
-    BPredicateFunction_Init(&f_conj, &pr, "conj", (int []){PREDICATE_TYPE_BOOL, PREDICATE_TYPE_BOOL}, 2, func_conj, NULL);
+    BPredicateFunction_Init(&f_conj, &pr, "conj", arr2, 2, func_conj, NULL);
+    int arr3[] = {PREDICATE_TYPE_STRING, PREDICATE_TYPE_STRING};
     BPredicateFunction f_strcmp;
-    BPredicateFunction_Init(&f_strcmp, &pr, "strcmp", (int []){PREDICATE_TYPE_STRING, PREDICATE_TYPE_STRING}, 2, func_strcmp, NULL);
+    BPredicateFunction_Init(&f_strcmp, &pr, "strcmp", arr3, 2, func_strcmp, NULL);
     BPredicateFunction f_error;
     BPredicateFunction_Init(&f_error, &pr, "error", NULL, 0, func_error, NULL);
     

+ 3 - 3
examples/savl_test.c

@@ -66,13 +66,13 @@ int main (int argc, char **argv)
         return 1;
     }
     
-    struct mynode *nodes = BAllocArray(num_nodes, sizeof(*nodes));
+    struct mynode *nodes = (struct mynode *)BAllocArray(num_nodes, sizeof(*nodes));
     ASSERT_FORCE(nodes)
     
-    int *values_ins = BAllocArray(num_nodes, sizeof(int));
+    int *values_ins = (int *)BAllocArray(num_nodes, sizeof(int));
     ASSERT_FORCE(values_ins)
     
-    int *values = BAllocArray(num_random_delete, sizeof(int));
+    int *values = (int *)BAllocArray(num_random_delete, sizeof(int));
     ASSERT_FORCE(values)
     
     MyTree tree;

+ 1 - 1
examples/stdin_input.c

@@ -107,7 +107,7 @@ int main ()
     }
     
     // init BConnection object backed by the stdin fd
-    if (!BConnection_Init(&pipe_con, BCONNECTION_SOURCE_PIPE(0), &reactor, NULL, connection_handler)) {
+    if (!BConnection_Init(&pipe_con, BConnection_source_pipe(0), &reactor, NULL, connection_handler)) {
         fprintf(stderr, "BConnection_Init failed\n");
         goto fail3;
     }

+ 7 - 6
examples/substring_test.c

@@ -1,11 +1,12 @@
 #include <stdlib.h>
 #include <string.h>
-#include <inttypes.h>
+#include <stdio.h>
 #include <time.h>
 
 #include <misc/substring.h>
 #include <misc/debug.h>
 #include <misc/balloc.h>
+#include <misc/print_macros.h>
 
 static int find_substring_slow (const char *str, size_t str_len, const char *sub, size_t sub_len, size_t *out_pos)
 {
@@ -48,10 +49,10 @@ static void test_tables (int len, int count)
     ASSERT(len > 0)
     ASSERT(count >= 0)
     
-    char *word = BAllocSize(bsize_fromint(len));
+    char *word = (char *)BAllocSize(bsize_fromint(len));
     ASSERT_FORCE(word)
     
-    size_t *table = BAllocSize(bsize_mul(bsize_fromint(len), bsize_fromsize(sizeof(table[0]))));
+    size_t *table = (size_t *)BAllocSize(bsize_mul(bsize_fromint(len), bsize_fromsize(sizeof(table[0]))));
     ASSERT_FORCE(table)
     
     for (int i = 0; i < count; i++) {
@@ -82,13 +83,13 @@ static void test_substring (int word_len, int text_len, int word_count, int text
     assert(word_count >= 0);
     assert(text_count >= 0);
     
-    char *word = BAllocSize(bsize_fromint(word_len));
+    char *word = (char *)BAllocSize(bsize_fromint(word_len));
     ASSERT_FORCE(word)
     
-    size_t *table = BAllocSize(bsize_mul(bsize_fromint(word_len), bsize_fromsize(sizeof(table[0]))));
+    size_t *table = (size_t *)BAllocSize(bsize_mul(bsize_fromint(word_len), bsize_fromsize(sizeof(table[0]))));
     ASSERT_FORCE(table)
     
-    char *text = BAllocSize(bsize_fromint(text_len));
+    char *text = (char *)BAllocSize(bsize_fromint(text_len));
     ASSERT_FORCE(text)
     
     for (int i = 0; i < word_count; i++) {

+ 10 - 0
fix_flex.php

@@ -0,0 +1,10 @@
+<?php
+
+$filename = $argv[1];
+$contents = file_get_contents($filename);
+if ($contents === FALSE) exit(1);
+$search = array("<inttypes.h>", "#if defined (__STDC_VERSION__) && __STDC_VERSION__ >= 199901L");
+$replace = array("<stdint.h>", "#if 1");
+$contents = str_replace($search, $replace, $contents);
+$res = file_put_contents($filename, $contents);
+if ($res === FALSE) exit(1);

+ 5 - 1
flooder/flooder.c

@@ -553,7 +553,11 @@ int resolve_arguments (void)
     
     // override server name if requested
     if (options.server_name) {
-        snprintf(server_name, sizeof(server_name), "%s", options.server_name);
+        if (strlen(options.server_name) >= sizeof(server_name)) {
+            BLog(BLOG_ERROR, "server name: too long");
+            return 0;
+        }
+        strcpy(server_name, options.server_name);
     }
     
     return 1;

+ 1 - 1
flow/LineBuffer.c

@@ -116,7 +116,7 @@ int LineBuffer_Init (LineBuffer *o, StreamRecvInterface *input, PacketPassInterf
     o->buf_used = 0;
     
     // allocate buffer
-    if (!(o->buf = malloc(o->buf_size))) {
+    if (!(o->buf = (uint8_t *)malloc(o->buf_size))) {
         BLog(BLOG_ERROR, "malloc failed");
         goto fail0;
     }

+ 1 - 1
flow/PacketBuffer.c

@@ -104,7 +104,7 @@ int PacketBuffer_Init (PacketBuffer *buf, PacketRecvInterface *input, PacketPass
     if (num_blocks < 0) {
         goto fail0;
     }
-    if (!(buf->buf_data = BAllocArray(num_blocks, sizeof(buf->buf_data[0])))) {
+    if (!(buf->buf_data = (struct ChunkBuffer2_block *)BAllocArray(num_blocks, sizeof(buf->buf_data[0])))) {
         goto fail0;
     }
     

+ 1 - 1
flow/PacketProtoDecoder.c

@@ -149,7 +149,7 @@ int PacketProtoDecoder_Init (PacketProtoDecoder *enc, StreamRecvInterface *input
     enc->buf_used = 0;
     
     // allocate buffer
-    if (!(enc->buf = malloc(enc->buf_size))) {
+    if (!(enc->buf = (uint8_t *)malloc(enc->buf_size))) {
         goto fail0;
     }
     

+ 1 - 1
flow/RouteBuffer.c

@@ -42,7 +42,7 @@ static struct RouteBuffer_packet * alloc_packet (int mtu)
     }
     
     // allocate memory
-    struct RouteBuffer_packet *p = malloc(sizeof(*p) + mtu);
+    struct RouteBuffer_packet *p = (struct RouteBuffer_packet *)malloc(sizeof(*p) + mtu);
     if (!p) {
         return NULL;
     }

+ 1 - 1
flow/SinglePacketBuffer.c

@@ -63,7 +63,7 @@ int SinglePacketBuffer_Init (SinglePacketBuffer *o, PacketRecvInterface *input,
     PacketPassInterface_Sender_Init(o->output, (PacketPassInterface_handler_done)output_handler_done, o);
     
     // init buffer
-    if (!(o->buf = BAlloc(PacketRecvInterface_GetMTU(o->input)))) {
+    if (!(o->buf = (uint8_t *)BAlloc(PacketRecvInterface_GetMTU(o->input)))) {
         goto fail1;
     }
     

+ 2 - 0
generate_files

@@ -18,6 +18,8 @@ function do_flex() {
     local input="$1"
     local name="$2"
     "${FLEX_CMD[@]}" -o "${OUT_DIR}/flex_${name}.c" --header-file="${OUT_DIR}/flex_${name}.h" "${input}"
+    "${PHP_CMD[@]}" fix_flex.php "${OUT_DIR}/flex_${name}.c"
+    "${PHP_CMD[@]}" fix_flex.php "${OUT_DIR}/flex_${name}.h"
 }
 
 function do_bison() {

+ 110 - 109
generated/bison_BPredicate.c

@@ -1,4 +1,4 @@
-/* A Bison parser, made by GNU Bison 2.5.1.  */
+/* A Bison parser, made by GNU Bison 2.6.  */
 
 /* Bison implementation for Yacc-like parsers in C
    
@@ -44,7 +44,7 @@
 #define YYBISON 1
 
 /* Bison version.  */
-#define YYBISON_VERSION "2.5.1"
+#define YYBISON_VERSION "2.6"
 
 /* Skeleton name.  */
 #define YYSKELETON_NAME "yacc.c"
@@ -58,14 +58,12 @@
 /* Pull parsers.  */
 #define YYPULL 1
 
-/* Using locations.  */
-#define YYLSP_NEEDED 1
 
 
 
 /* Copy the first part of user declarations.  */
 
-/* Line 268 of yacc.c  */
+/* Line 336 of yacc.c  */
 #line 34 "predicate/BPredicate.y"
 
 
@@ -78,7 +76,7 @@
 
 static struct predicate_node * make_constant (int val)
 {
-    struct predicate_node *n = malloc(sizeof(*n));
+    struct predicate_node *n = (struct predicate_node *)malloc(sizeof(*n));
     if (!n) {
         return NULL;
     }
@@ -95,7 +93,7 @@ static struct predicate_node * make_negation (struct predicate_node *op)
         goto fail;
     }
 
-    struct predicate_node *n = malloc(sizeof(*n));
+    struct predicate_node *n = (struct predicate_node *)malloc(sizeof(*n));
     if (!n) {
         goto fail;
     }
@@ -118,7 +116,7 @@ static struct predicate_node * make_conjunction (struct predicate_node *op1, str
         goto fail;
     }
 
-    struct predicate_node *n = malloc(sizeof(*n));
+    struct predicate_node *n = (struct predicate_node *)malloc(sizeof(*n));
     if (!n) {
         goto fail;
     }
@@ -145,7 +143,7 @@ static struct predicate_node * make_disjunction (struct predicate_node *op1, str
         goto fail;
     }
 
-    struct predicate_node *n = malloc(sizeof(*n));
+    struct predicate_node *n = (struct predicate_node *)malloc(sizeof(*n));
     if (!n) {
         goto fail;
     }
@@ -172,7 +170,7 @@ static struct predicate_node * make_function (char *name, struct arguments_node
         goto fail;
     }
 
-    struct predicate_node *n = malloc(sizeof(*n));
+    struct predicate_node *n = (struct predicate_node *)malloc(sizeof(*n));
     if (!n) {
         goto fail;
     }
@@ -199,7 +197,7 @@ static struct arguments_node * make_arguments (struct arguments_arg arg, struct
         goto fail;
     }
 
-    struct arguments_node *n = malloc(sizeof(*n));
+    struct arguments_node *n = (struct arguments_node *)malloc(sizeof(*n));
     if (!n) {
         goto fail;
     }
@@ -255,8 +253,8 @@ fail:
 
 
 
-/* Line 268 of yacc.c  */
-#line 260 "generated//bison_BPredicate.c"
+/* Line 336 of yacc.c  */
+#line 258 "generated//bison_BPredicate.c"
 
 # ifndef YY_NULL
 #  if defined __cplusplus && 201103L <= __cplusplus
@@ -266,11 +264,6 @@ fail:
 #  endif
 # endif
 
-/* Enabling traces.  */
-#ifndef YYDEBUG
-# define YYDEBUG 0
-#endif
-
 /* Enabling verbose error messages.  */
 #ifdef YYERROR_VERBOSE
 # undef YYERROR_VERBOSE
@@ -279,11 +272,17 @@ fail:
 # define YYERROR_VERBOSE 0
 #endif
 
-/* Enabling the token table.  */
-#ifndef YYTOKEN_TABLE
-# define YYTOKEN_TABLE 0
+/* In a future release of Bison, this section will be replaced
+   by #include "bison_BPredicate.h".  */
+#ifndef YY_GENERATED_BISON_BPREDICATE_H
+# define YY_GENERATED_BISON_BPREDICATE_H
+/* Enabling traces.  */
+#ifndef YYDEBUG
+# define YYDEBUG 0
+#endif
+#if YYDEBUG
+extern int yydebug;
 #endif
-
 
 /* Tokens.  */
 #ifndef YYTOKENTYPE
@@ -307,12 +306,11 @@ fail:
 #endif
 
 
-
 #if ! defined YYSTYPE && ! defined YYSTYPE_IS_DECLARED
 typedef union YYSTYPE
 {
 
-/* Line 295 of yacc.c  */
+/* Line 350 of yacc.c  */
 #line 227 "predicate/BPredicate.y"
 
     char *text;
@@ -323,8 +321,8 @@ typedef union YYSTYPE
 
 
 
-/* Line 295 of yacc.c  */
-#line 328 "generated//bison_BPredicate.c"
+/* Line 350 of yacc.c  */
+#line 326 "generated//bison_BPredicate.c"
 } YYSTYPE;
 # define YYSTYPE_IS_TRIVIAL 1
 # define yystype YYSTYPE /* obsolescent; will be withdrawn */
@@ -345,11 +343,27 @@ typedef struct YYLTYPE
 #endif
 
 
+#ifdef YYPARSE_PARAM
+#if defined __STDC__ || defined __cplusplus
+int yyparse (void *YYPARSE_PARAM);
+#else
+int yyparse ();
+#endif
+#else /* ! YYPARSE_PARAM */
+#if defined __STDC__ || defined __cplusplus
+int yyparse (void *scanner, struct predicate_node **result);
+#else
+int yyparse ();
+#endif
+#endif /* ! YYPARSE_PARAM */
+
+#endif /* !YY_GENERATED_BISON_BPREDICATE_H  */
+
 /* Copy the second part of user declarations.  */
 
 
-/* Line 345 of yacc.c  */
-#line 353 "generated//bison_BPredicate.c"
+/* Line 353 of yacc.c  */
+#line 367 "generated//bison_BPredicate.c"
 
 #ifdef short
 # undef short
@@ -651,7 +665,7 @@ static const yytype_uint16 yyrline[] =
 };
 #endif
 
-#if YYDEBUG || YYERROR_VERBOSE || YYTOKEN_TABLE
+#if YYDEBUG || YYERROR_VERBOSE || 0
 /* YYTNAME[SYMBOL-NUM] -- String name of the symbol SYMBOL-NUM.
    First, the terminals, then, starting at YYNTOKENS, nonterminals.  */
 static const char *const yytname[] =
@@ -810,32 +824,33 @@ while (YYID (0))
 #define YYTERROR	1
 #define YYERRCODE	256
 
-
 /* YYLLOC_DEFAULT -- Set CURRENT to span from RHS[1] to RHS[N].
    If N is 0, then set CURRENT to the empty location which ends
    the previous symbol: RHS[0] (always defined).  */
 
-#define YYRHSLOC(Rhs, K) ((Rhs)[K])
 #ifndef YYLLOC_DEFAULT
-# define YYLLOC_DEFAULT(Current, Rhs, N)				\
-    do									\
-      if (YYID (N))                                                    \
-	{								\
-	  (Current).first_line   = YYRHSLOC (Rhs, 1).first_line;	\
-	  (Current).first_column = YYRHSLOC (Rhs, 1).first_column;	\
-	  (Current).last_line    = YYRHSLOC (Rhs, N).last_line;		\
-	  (Current).last_column  = YYRHSLOC (Rhs, N).last_column;	\
-	}								\
-      else								\
-	{								\
-	  (Current).first_line   = (Current).last_line   =		\
-	    YYRHSLOC (Rhs, 0).last_line;				\
-	  (Current).first_column = (Current).last_column =		\
-	    YYRHSLOC (Rhs, 0).last_column;				\
-	}								\
+# define YYLLOC_DEFAULT(Current, Rhs, N)                                \
+    do                                                                  \
+      if (YYID (N))                                                     \
+        {                                                               \
+          (Current).first_line   = YYRHSLOC (Rhs, 1).first_line;        \
+          (Current).first_column = YYRHSLOC (Rhs, 1).first_column;      \
+          (Current).last_line    = YYRHSLOC (Rhs, N).last_line;         \
+          (Current).last_column  = YYRHSLOC (Rhs, N).last_column;       \
+        }                                                               \
+      else                                                              \
+        {                                                               \
+          (Current).first_line   = (Current).last_line   =              \
+            YYRHSLOC (Rhs, 0).last_line;                                \
+          (Current).first_column = (Current).last_column =              \
+            YYRHSLOC (Rhs, 0).last_column;                              \
+        }                                                               \
     while (YYID (0))
 #endif
 
+#define YYRHSLOC(Rhs, K) ((Rhs)[K])
+
+
 
 /* YY_LOCATION_PRINT -- Print the location on the stream.
    This macro was not mandated originally: define only if we know
@@ -1329,29 +1344,29 @@ yydestruct (yymsg, yytype, yyvaluep, yylocationp, scanner, result)
     {
       case 3: /* "STRING" */
 
-/* Line 1395 of yacc.c  */
+/* Line 1381 of yacc.c  */
 #line 240 "predicate/BPredicate.y"
 	{
     free((yyvaluep->text));
 };
 
-/* Line 1395 of yacc.c  */
-#line 1340 "generated//bison_BPredicate.c"
+/* Line 1381 of yacc.c  */
+#line 1355 "generated//bison_BPredicate.c"
 	break;
       case 4: /* "NAME" */
 
-/* Line 1395 of yacc.c  */
+/* Line 1381 of yacc.c  */
 #line 240 "predicate/BPredicate.y"
 	{
     free((yyvaluep->text));
 };
 
-/* Line 1395 of yacc.c  */
-#line 1351 "generated//bison_BPredicate.c"
+/* Line 1381 of yacc.c  */
+#line 1366 "generated//bison_BPredicate.c"
 	break;
       case 17: /* "predicate" */
 
-/* Line 1395 of yacc.c  */
+/* Line 1381 of yacc.c  */
 #line 250 "predicate/BPredicate.y"
 	{
     if ((yyvaluep->node)) {
@@ -1359,12 +1374,12 @@ yydestruct (yymsg, yytype, yyvaluep, yylocationp, scanner, result)
     }
 };
 
-/* Line 1395 of yacc.c  */
-#line 1364 "generated//bison_BPredicate.c"
+/* Line 1381 of yacc.c  */
+#line 1379 "generated//bison_BPredicate.c"
 	break;
       case 18: /* "constant" */
 
-/* Line 1395 of yacc.c  */
+/* Line 1381 of yacc.c  */
 #line 250 "predicate/BPredicate.y"
 	{
     if ((yyvaluep->node)) {
@@ -1372,12 +1387,12 @@ yydestruct (yymsg, yytype, yyvaluep, yylocationp, scanner, result)
     }
 };
 
-/* Line 1395 of yacc.c  */
-#line 1377 "generated//bison_BPredicate.c"
+/* Line 1381 of yacc.c  */
+#line 1392 "generated//bison_BPredicate.c"
 	break;
       case 19: /* "parentheses" */
 
-/* Line 1395 of yacc.c  */
+/* Line 1381 of yacc.c  */
 #line 250 "predicate/BPredicate.y"
 	{
     if ((yyvaluep->node)) {
@@ -1385,12 +1400,12 @@ yydestruct (yymsg, yytype, yyvaluep, yylocationp, scanner, result)
     }
 };
 
-/* Line 1395 of yacc.c  */
-#line 1390 "generated//bison_BPredicate.c"
+/* Line 1381 of yacc.c  */
+#line 1405 "generated//bison_BPredicate.c"
 	break;
       case 20: /* "neg" */
 
-/* Line 1395 of yacc.c  */
+/* Line 1381 of yacc.c  */
 #line 250 "predicate/BPredicate.y"
 	{
     if ((yyvaluep->node)) {
@@ -1398,12 +1413,12 @@ yydestruct (yymsg, yytype, yyvaluep, yylocationp, scanner, result)
     }
 };
 
-/* Line 1395 of yacc.c  */
-#line 1403 "generated//bison_BPredicate.c"
+/* Line 1381 of yacc.c  */
+#line 1418 "generated//bison_BPredicate.c"
 	break;
       case 21: /* "conjunct" */
 
-/* Line 1395 of yacc.c  */
+/* Line 1381 of yacc.c  */
 #line 250 "predicate/BPredicate.y"
 	{
     if ((yyvaluep->node)) {
@@ -1411,12 +1426,12 @@ yydestruct (yymsg, yytype, yyvaluep, yylocationp, scanner, result)
     }
 };
 
-/* Line 1395 of yacc.c  */
-#line 1416 "generated//bison_BPredicate.c"
+/* Line 1381 of yacc.c  */
+#line 1431 "generated//bison_BPredicate.c"
 	break;
       case 22: /* "disjunct" */
 
-/* Line 1395 of yacc.c  */
+/* Line 1381 of yacc.c  */
 #line 250 "predicate/BPredicate.y"
 	{
     if ((yyvaluep->node)) {
@@ -1424,12 +1439,12 @@ yydestruct (yymsg, yytype, yyvaluep, yylocationp, scanner, result)
     }
 };
 
-/* Line 1395 of yacc.c  */
-#line 1429 "generated//bison_BPredicate.c"
+/* Line 1381 of yacc.c  */
+#line 1444 "generated//bison_BPredicate.c"
 	break;
       case 23: /* "function" */
 
-/* Line 1395 of yacc.c  */
+/* Line 1381 of yacc.c  */
 #line 250 "predicate/BPredicate.y"
 	{
     if ((yyvaluep->node)) {
@@ -1437,12 +1452,12 @@ yydestruct (yymsg, yytype, yyvaluep, yylocationp, scanner, result)
     }
 };
 
-/* Line 1395 of yacc.c  */
-#line 1442 "generated//bison_BPredicate.c"
+/* Line 1381 of yacc.c  */
+#line 1457 "generated//bison_BPredicate.c"
 	break;
       case 24: /* "arguments" */
 
-/* Line 1395 of yacc.c  */
+/* Line 1381 of yacc.c  */
 #line 257 "predicate/BPredicate.y"
 	{
     if ((yyvaluep->arg_node)) {
@@ -1450,19 +1465,19 @@ yydestruct (yymsg, yytype, yyvaluep, yylocationp, scanner, result)
     }
 };
 
-/* Line 1395 of yacc.c  */
-#line 1455 "generated//bison_BPredicate.c"
+/* Line 1381 of yacc.c  */
+#line 1470 "generated//bison_BPredicate.c"
 	break;
       case 25: /* "argument" */
 
-/* Line 1395 of yacc.c  */
+/* Line 1381 of yacc.c  */
 #line 264 "predicate/BPredicate.y"
 	{
     free_argument((yyvaluep->arg_arg));
 };
 
-/* Line 1395 of yacc.c  */
-#line 1466 "generated//bison_BPredicate.c"
+/* Line 1381 of yacc.c  */
+#line 1481 "generated//bison_BPredicate.c"
 	break;
 
       default:
@@ -1471,20 +1486,6 @@ yydestruct (yymsg, yytype, yyvaluep, yylocationp, scanner, result)
 }
 
 
-/* Prevent warnings from -Wmissing-prototypes.  */
-#ifdef YYPARSE_PARAM
-#if defined __STDC__ || defined __cplusplus
-int yyparse (void *YYPARSE_PARAM);
-#else
-int yyparse ();
-#endif
-#else /* ! YYPARSE_PARAM */
-#if defined __STDC__ || defined __cplusplus
-int yyparse (void *scanner, struct predicate_node **result);
-#else
-int yyparse ();
-#endif
-#endif /* ! YYPARSE_PARAM */
 
 
 /*----------.
@@ -1791,7 +1792,7 @@ yyreduce:
     {
         case 2:
 
-/* Line 1810 of yacc.c  */
+/* Line 1788 of yacc.c  */
 #line 276 "predicate/BPredicate.y"
     {
         *result = (yyvsp[(1) - (1)].node);
@@ -1800,7 +1801,7 @@ yyreduce:
 
   case 9:
 
-/* Line 1810 of yacc.c  */
+/* Line 1788 of yacc.c  */
 #line 284 "predicate/BPredicate.y"
     {
         (yyval.node) = make_constant(1);
@@ -1809,7 +1810,7 @@ yyreduce:
 
   case 10:
 
-/* Line 1810 of yacc.c  */
+/* Line 1788 of yacc.c  */
 #line 288 "predicate/BPredicate.y"
     {
         (yyval.node) = make_constant(0);
@@ -1818,7 +1819,7 @@ yyreduce:
 
   case 11:
 
-/* Line 1810 of yacc.c  */
+/* Line 1788 of yacc.c  */
 #line 294 "predicate/BPredicate.y"
     {
         (yyval.node) = (yyvsp[(2) - (3)].node);
@@ -1827,7 +1828,7 @@ yyreduce:
 
   case 12:
 
-/* Line 1810 of yacc.c  */
+/* Line 1788 of yacc.c  */
 #line 300 "predicate/BPredicate.y"
     {
         (yyval.node) = make_negation((yyvsp[(2) - (2)].node));
@@ -1836,7 +1837,7 @@ yyreduce:
 
   case 13:
 
-/* Line 1810 of yacc.c  */
+/* Line 1788 of yacc.c  */
 #line 306 "predicate/BPredicate.y"
     {
         (yyval.node) = make_conjunction((yyvsp[(1) - (3)].node), (yyvsp[(3) - (3)].node));
@@ -1845,7 +1846,7 @@ yyreduce:
 
   case 14:
 
-/* Line 1810 of yacc.c  */
+/* Line 1788 of yacc.c  */
 #line 312 "predicate/BPredicate.y"
     {
         (yyval.node) = make_disjunction((yyvsp[(1) - (3)].node), (yyvsp[(3) - (3)].node));
@@ -1854,7 +1855,7 @@ yyreduce:
 
   case 15:
 
-/* Line 1810 of yacc.c  */
+/* Line 1788 of yacc.c  */
 #line 318 "predicate/BPredicate.y"
     {
         (yyval.node) = make_function((yyvsp[(1) - (3)].text), NULL, 0);
@@ -1863,7 +1864,7 @@ yyreduce:
 
   case 16:
 
-/* Line 1810 of yacc.c  */
+/* Line 1788 of yacc.c  */
 #line 322 "predicate/BPredicate.y"
     {
         (yyval.node) = make_function((yyvsp[(1) - (4)].text), (yyvsp[(3) - (4)].arg_node), 1);
@@ -1872,7 +1873,7 @@ yyreduce:
 
   case 17:
 
-/* Line 1810 of yacc.c  */
+/* Line 1788 of yacc.c  */
 #line 328 "predicate/BPredicate.y"
     {
         (yyval.arg_node) = make_arguments((yyvsp[(1) - (1)].arg_arg), NULL, 0);
@@ -1881,7 +1882,7 @@ yyreduce:
 
   case 18:
 
-/* Line 1810 of yacc.c  */
+/* Line 1788 of yacc.c  */
 #line 332 "predicate/BPredicate.y"
     {
         (yyval.arg_node) = make_arguments((yyvsp[(1) - (3)].arg_arg), (yyvsp[(3) - (3)].arg_node), 1);
@@ -1890,7 +1891,7 @@ yyreduce:
 
   case 19:
 
-/* Line 1810 of yacc.c  */
+/* Line 1788 of yacc.c  */
 #line 338 "predicate/BPredicate.y"
     {
         (yyval.arg_arg) = make_argument_predicate((yyvsp[(1) - (1)].node));
@@ -1899,7 +1900,7 @@ yyreduce:
 
   case 20:
 
-/* Line 1810 of yacc.c  */
+/* Line 1788 of yacc.c  */
 #line 342 "predicate/BPredicate.y"
     {
         (yyval.arg_arg) = make_argument_string((yyvsp[(1) - (1)].text));
@@ -1908,8 +1909,8 @@ yyreduce:
 
 
 
-/* Line 1810 of yacc.c  */
-#line 1913 "generated//bison_BPredicate.c"
+/* Line 1788 of yacc.c  */
+#line 1914 "generated//bison_BPredicate.c"
       default: break;
     }
   /* User semantic actions sometimes alter yychar, and that requires

+ 27 - 7
generated/bison_BPredicate.h

@@ -1,4 +1,4 @@
-/* A Bison parser, made by GNU Bison 2.5.1.  */
+/* A Bison parser, made by GNU Bison 2.6.  */
 
 /* Bison interface for Yacc-like parsers in C
    
@@ -30,6 +30,15 @@
    This special exception was added by the Free Software Foundation in
    version 2.2 of Bison.  */
 
+#ifndef YY_GENERATED_BISON_BPREDICATE_H
+# define YY_GENERATED_BISON_BPREDICATE_H
+/* Enabling traces.  */
+#ifndef YYDEBUG
+# define YYDEBUG 0
+#endif
+#if YYDEBUG
+extern int yydebug;
+#endif
 
 /* Tokens.  */
 #ifndef YYTOKENTYPE
@@ -53,12 +62,11 @@
 #endif
 
 
-
 #if ! defined YYSTYPE && ! defined YYSTYPE_IS_DECLARED
 typedef union YYSTYPE
 {
 
-/* Line 2072 of yacc.c  */
+/* Line 2050 of yacc.c  */
 #line 227 "predicate/BPredicate.y"
 
     char *text;
@@ -69,16 +77,14 @@ typedef union YYSTYPE
 
 
 
-/* Line 2072 of yacc.c  */
-#line 74 "generated//bison_BPredicate.h"
+/* Line 2050 of yacc.c  */
+#line 82 "generated//bison_BPredicate.h"
 } YYSTYPE;
 # define YYSTYPE_IS_TRIVIAL 1
 # define yystype YYSTYPE /* obsolescent; will be withdrawn */
 # define YYSTYPE_IS_DECLARED 1
 #endif
 
-
-
 #if ! defined YYLTYPE && ! defined YYLTYPE_IS_DECLARED
 typedef struct YYLTYPE
 {
@@ -93,4 +99,18 @@ typedef struct YYLTYPE
 #endif
 
 
+#ifdef YYPARSE_PARAM
+#if defined __STDC__ || defined __cplusplus
+int yyparse (void *YYPARSE_PARAM);
+#else
+int yyparse ();
+#endif
+#else /* ! YYPARSE_PARAM */
+#if defined __STDC__ || defined __cplusplus
+int yyparse (void *scanner, struct predicate_node **result);
+#else
+int yyparse ();
+#endif
+#endif /* ! YYPARSE_PARAM */
 
+#endif /* !YY_GENERATED_BISON_BPREDICATE_H  */

+ 125 - 125
generated/blog_channels_list.h

@@ -1,125 +1,125 @@
-{.name = "server", .loglevel = 4},
-{.name = "client", .loglevel = 4},
-{.name = "flooder", .loglevel = 4},
-{.name = "tun2socks", .loglevel = 4},
-{.name = "ncd", .loglevel = 4},
-{.name = "ncd_var", .loglevel = 4},
-{.name = "ncd_list", .loglevel = 4},
-{.name = "ncd_depend", .loglevel = 4},
-{.name = "ncd_multidepend", .loglevel = 4},
-{.name = "ncd_dynamic_depend", .loglevel = 4},
-{.name = "ncd_concat", .loglevel = 4},
-{.name = "ncd_concatv", .loglevel = 4},
-{.name = "ncd_if", .loglevel = 4},
-{.name = "ncd_strcmp", .loglevel = 4},
-{.name = "ncd_regex_match", .loglevel = 4},
-{.name = "ncd_logical", .loglevel = 4},
-{.name = "ncd_sleep", .loglevel = 4},
-{.name = "ncd_print", .loglevel = 4},
-{.name = "ncd_blocker", .loglevel = 4},
-{.name = "ncd_ip_in_network", .loglevel = 4},
-{.name = "ncd_run", .loglevel = 4},
-{.name = "ncd_runonce", .loglevel = 4},
-{.name = "ncd_daemon", .loglevel = 4},
-{.name = "ncd_spawn", .loglevel = 4},
-{.name = "ncd_call", .loglevel = 4},
-{.name = "ncd_imperative", .loglevel = 4},
-{.name = "ncd_ref", .loglevel = 4},
-{.name = "ncd_index", .loglevel = 4},
-{.name = "ncd_alias", .loglevel = 4},
-{.name = "ncd_process_manager", .loglevel = 4},
-{.name = "ncd_ondemand", .loglevel = 4},
-{.name = "ncd_foreach", .loglevel = 4},
-{.name = "ncd_choose", .loglevel = 4},
-{.name = "ncd_net_backend_waitdevice", .loglevel = 4},
-{.name = "ncd_net_backend_waitlink", .loglevel = 4},
-{.name = "ncd_net_backend_badvpn", .loglevel = 4},
-{.name = "ncd_net_backend_wpa_supplicant", .loglevel = 4},
-{.name = "ncd_net_backend_rfkill", .loglevel = 4},
-{.name = "ncd_net_up", .loglevel = 4},
-{.name = "ncd_net_dns", .loglevel = 4},
-{.name = "ncd_net_iptables", .loglevel = 4},
-{.name = "ncd_net_ipv4_addr", .loglevel = 4},
-{.name = "ncd_net_ipv4_route", .loglevel = 4},
-{.name = "ncd_net_ipv4_dhcp", .loglevel = 4},
-{.name = "ncd_net_ipv4_arp_probe", .loglevel = 4},
-{.name = "ncd_net_watch_interfaces", .loglevel = 4},
-{.name = "ncd_sys_watch_input", .loglevel = 4},
-{.name = "ncd_sys_watch_usb", .loglevel = 4},
-{.name = "ncd_sys_evdev", .loglevel = 4},
-{.name = "ncd_sys_watch_directory", .loglevel = 4},
-{.name = "StreamPeerIO", .loglevel = 4},
-{.name = "DatagramPeerIO", .loglevel = 4},
-{.name = "BReactor", .loglevel = 3},
-{.name = "BSignal", .loglevel = 3},
-{.name = "FragmentProtoAssembler", .loglevel = 4},
-{.name = "BPredicate", .loglevel = 3},
-{.name = "ServerConnection", .loglevel = 4},
-{.name = "Listener", .loglevel = 4},
-{.name = "DataProto", .loglevel = 4},
-{.name = "FrameDecider", .loglevel = 4},
-{.name = "BSocksClient", .loglevel = 4},
-{.name = "BDHCPClientCore", .loglevel = 4},
-{.name = "BDHCPClient", .loglevel = 4},
-{.name = "NCDIfConfig", .loglevel = 4},
-{.name = "BUnixSignal", .loglevel = 4},
-{.name = "BProcess", .loglevel = 4},
-{.name = "PRStreamSink", .loglevel = 4},
-{.name = "PRStreamSource", .loglevel = 4},
-{.name = "PacketProtoDecoder", .loglevel = 4},
-{.name = "DPRelay", .loglevel = 4},
-{.name = "BThreadWork", .loglevel = 4},
-{.name = "DPReceive", .loglevel = 4},
-{.name = "BInputProcess", .loglevel = 4},
-{.name = "NCDUdevMonitorParser", .loglevel = 4},
-{.name = "NCDUdevMonitor", .loglevel = 4},
-{.name = "NCDUdevCache", .loglevel = 4},
-{.name = "NCDUdevManager", .loglevel = 4},
-{.name = "BTime", .loglevel = 4},
-{.name = "BEncryption", .loglevel = 4},
-{.name = "SPProtoDecoder", .loglevel = 4},
-{.name = "LineBuffer", .loglevel = 4},
-{.name = "BTap", .loglevel = 4},
-{.name = "lwip", .loglevel = 4},
-{.name = "NCDConfigTokenizer", .loglevel = 4},
-{.name = "NCDConfigParser", .loglevel = 4},
-{.name = "NCDValueParser", .loglevel = 4},
-{.name = "nsskey", .loglevel = 4},
-{.name = "addr", .loglevel = 4},
-{.name = "PasswordListener", .loglevel = 4},
-{.name = "NCDInterfaceMonitor", .loglevel = 4},
-{.name = "NCDRfkillMonitor", .loglevel = 4},
-{.name = "udpgw", .loglevel = 4},
-{.name = "UdpGwClient", .loglevel = 4},
-{.name = "SocksUdpGwClient", .loglevel = 4},
-{.name = "BNetwork", .loglevel = 4},
-{.name = "BConnection", .loglevel = 4},
-{.name = "BSSLConnection", .loglevel = 4},
-{.name = "BDatagram", .loglevel = 4},
-{.name = "PeerChat", .loglevel = 4},
-{.name = "BArpProbe", .loglevel = 4},
-{.name = "NCDModuleIndex", .loglevel = 4},
-{.name = "NCDModuleProcess", .loglevel = 4},
-{.name = "NCDValueGenerator", .loglevel = 4},
-{.name = "ncd_from_string", .loglevel = 4},
-{.name = "ncd_to_string", .loglevel = 4},
-{.name = "ncd_value", .loglevel = 4},
-{.name = "ncd_try", .loglevel = 4},
-{.name = "ncd_sys_request_server", .loglevel = 4},
-{.name = "NCDRequest", .loglevel = 4},
-{.name = "ncd_net_ipv6_wait_dynamic_addr", .loglevel = 4},
-{.name = "NCDRequestClient", .loglevel = 4},
-{.name = "ncd_request", .loglevel = 4},
-{.name = "ncd_sys_request_client", .loglevel = 4},
-{.name = "ncd_exit", .loglevel = 4},
-{.name = "ncd_getargs", .loglevel = 4},
-{.name = "ncd_arithmetic", .loglevel = 4},
-{.name = "ncd_parse", .loglevel = 4},
-{.name = "ncd_valuemetic", .loglevel = 4},
-{.name = "ncd_file", .loglevel = 4},
-{.name = "ncd_netmask", .loglevel = 4},
-{.name = "ncd_implode", .loglevel = 4},
-{.name = "ncd_call2", .loglevel = 4},
-{.name = "ncd_assert", .loglevel = 4},
-{.name = "ncd_reboot", .loglevel = 4},
-{.name = "ncd_explode", .loglevel = 4},
+{"server", 4},
+{"client", 4},
+{"flooder", 4},
+{"tun2socks", 4},
+{"ncd", 4},
+{"ncd_var", 4},
+{"ncd_list", 4},
+{"ncd_depend", 4},
+{"ncd_multidepend", 4},
+{"ncd_dynamic_depend", 4},
+{"ncd_concat", 4},
+{"ncd_concatv", 4},
+{"ncd_if", 4},
+{"ncd_strcmp", 4},
+{"ncd_regex_match", 4},
+{"ncd_logical", 4},
+{"ncd_sleep", 4},
+{"ncd_print", 4},
+{"ncd_blocker", 4},
+{"ncd_ip_in_network", 4},
+{"ncd_run", 4},
+{"ncd_runonce", 4},
+{"ncd_daemon", 4},
+{"ncd_spawn", 4},
+{"ncd_call", 4},
+{"ncd_imperative", 4},
+{"ncd_ref", 4},
+{"ncd_index", 4},
+{"ncd_alias", 4},
+{"ncd_process_manager", 4},
+{"ncd_ondemand", 4},
+{"ncd_foreach", 4},
+{"ncd_choose", 4},
+{"ncd_net_backend_waitdevice", 4},
+{"ncd_net_backend_waitlink", 4},
+{"ncd_net_backend_badvpn", 4},
+{"ncd_net_backend_wpa_supplicant", 4},
+{"ncd_net_backend_rfkill", 4},
+{"ncd_net_up", 4},
+{"ncd_net_dns", 4},
+{"ncd_net_iptables", 4},
+{"ncd_net_ipv4_addr", 4},
+{"ncd_net_ipv4_route", 4},
+{"ncd_net_ipv4_dhcp", 4},
+{"ncd_net_ipv4_arp_probe", 4},
+{"ncd_net_watch_interfaces", 4},
+{"ncd_sys_watch_input", 4},
+{"ncd_sys_watch_usb", 4},
+{"ncd_sys_evdev", 4},
+{"ncd_sys_watch_directory", 4},
+{"StreamPeerIO", 4},
+{"DatagramPeerIO", 4},
+{"BReactor", 3},
+{"BSignal", 3},
+{"FragmentProtoAssembler", 4},
+{"BPredicate", 3},
+{"ServerConnection", 4},
+{"Listener", 4},
+{"DataProto", 4},
+{"FrameDecider", 4},
+{"BSocksClient", 4},
+{"BDHCPClientCore", 4},
+{"BDHCPClient", 4},
+{"NCDIfConfig", 4},
+{"BUnixSignal", 4},
+{"BProcess", 4},
+{"PRStreamSink", 4},
+{"PRStreamSource", 4},
+{"PacketProtoDecoder", 4},
+{"DPRelay", 4},
+{"BThreadWork", 4},
+{"DPReceive", 4},
+{"BInputProcess", 4},
+{"NCDUdevMonitorParser", 4},
+{"NCDUdevMonitor", 4},
+{"NCDUdevCache", 4},
+{"NCDUdevManager", 4},
+{"BTime", 4},
+{"BEncryption", 4},
+{"SPProtoDecoder", 4},
+{"LineBuffer", 4},
+{"BTap", 4},
+{"lwip", 4},
+{"NCDConfigTokenizer", 4},
+{"NCDConfigParser", 4},
+{"NCDValueParser", 4},
+{"nsskey", 4},
+{"addr", 4},
+{"PasswordListener", 4},
+{"NCDInterfaceMonitor", 4},
+{"NCDRfkillMonitor", 4},
+{"udpgw", 4},
+{"UdpGwClient", 4},
+{"SocksUdpGwClient", 4},
+{"BNetwork", 4},
+{"BConnection", 4},
+{"BSSLConnection", 4},
+{"BDatagram", 4},
+{"PeerChat", 4},
+{"BArpProbe", 4},
+{"NCDModuleIndex", 4},
+{"NCDModuleProcess", 4},
+{"NCDValueGenerator", 4},
+{"ncd_from_string", 4},
+{"ncd_to_string", 4},
+{"ncd_value", 4},
+{"ncd_try", 4},
+{"ncd_sys_request_server", 4},
+{"NCDRequest", 4},
+{"ncd_net_ipv6_wait_dynamic_addr", 4},
+{"NCDRequestClient", 4},
+{"ncd_request", 4},
+{"ncd_sys_request_client", 4},
+{"ncd_exit", 4},
+{"ncd_getargs", 4},
+{"ncd_arithmetic", 4},
+{"ncd_parse", 4},
+{"ncd_valuemetic", 4},
+{"ncd_file", 4},
+{"ncd_netmask", 4},
+{"ncd_implode", 4},
+{"ncd_call2", 4},
+{"ncd_assert", 4},
+{"ncd_reboot", 4},
+{"ncd_explode", 4},

+ 32 - 40
generated/flex_BPredicate.c

@@ -29,9 +29,9 @@
 #ifndef FLEXINT_H
 #define FLEXINT_H
 
-/* C99 systems have <inttypes.h>. Non-C99 systems may or may not. */
+/* C99 systems have <stdint.h>. Non-C99 systems may or may not. */
 
-#if defined (__STDC_VERSION__) && __STDC_VERSION__ >= 199901L
+#if 1
 
 /* C99 says to define __STDC_LIMIT_MACROS before including stdint.h,
  * if you want the limit (max/min) macros for int types. 
@@ -40,7 +40,7 @@
 #define __STDC_LIMIT_MACROS 1
 #endif
 
-#include <inttypes.h>
+#include <stdint.h>
 typedef int8_t flex_int8_t;
 typedef uint8_t flex_uint8_t;
 typedef int16_t flex_int16_t;
@@ -502,13 +502,12 @@ static yyconst flex_int16_t yy_chk[70] =
 
 #include <generated/bison_BPredicate.h>
 
-#define YY_EXTRA_TYPE LexMemoryBufferInput *
-
 #define YY_INPUT(buffer, res, max_size) \
-    int bytes_read = LexMemoryBufferInput_Read(yyget_extra(yyscanner), buffer, max_size); \
+    int bytes_read = LexMemoryBufferInput_Read((LexMemoryBufferInput *)yyget_extra(yyscanner), buffer, max_size); \
     res = (bytes_read == 0 ? YY_NULL : bytes_read);
 
-#line 512 "generated//flex_BPredicate.c"
+#define YY_NO_UNISTD_H 1
+#line 511 "generated//flex_BPredicate.c"
 
 #define INITIAL 0
 
@@ -760,9 +759,9 @@ YY_DECL
 	register int yy_act;
     struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
 
-#line 54 "predicate/BPredicate.l"
+#line 52 "predicate/BPredicate.l"
 
-#line 766 "generated//flex_BPredicate.c"
+#line 765 "generated//flex_BPredicate.c"
 
     yylval = yylval_param;
 
@@ -825,16 +824,12 @@ yy_match:
 			yy_current_state = yy_nxt[yy_base[yy_current_state] + (unsigned int) yy_c];
 			++yy_cp;
 			}
-		while ( yy_base[yy_current_state] != 47 );
+		while ( yy_current_state != 33 );
+		yy_cp = yyg->yy_last_accepting_cpos;
+		yy_current_state = yyg->yy_last_accepting_state;
 
 yy_find_action:
 		yy_act = yy_accept[yy_current_state];
-		if ( yy_act == 0 )
-			{ /* have to back up */
-			yy_cp = yyg->yy_last_accepting_cpos;
-			yy_current_state = yyg->yy_last_accepting_state;
-			yy_act = yy_accept[yy_current_state];
-			}
 
 		YY_DO_BEFORE_ACTION;
 
@@ -851,50 +846,50 @@ do_action:	/* This label is used only to access EOF actions. */
 
 case 1:
 YY_RULE_SETUP
-#line 55 "predicate/BPredicate.l"
+#line 53 "predicate/BPredicate.l"
 return SPAR;
 	YY_BREAK
 case 2:
 YY_RULE_SETUP
-#line 56 "predicate/BPredicate.l"
+#line 54 "predicate/BPredicate.l"
 return EPAR;
 	YY_BREAK
 case 3:
 YY_RULE_SETUP
-#line 57 "predicate/BPredicate.l"
+#line 55 "predicate/BPredicate.l"
 return COMMA;
 	YY_BREAK
 case 4:
 YY_RULE_SETUP
-#line 58 "predicate/BPredicate.l"
+#line 56 "predicate/BPredicate.l"
 return AND;
 	YY_BREAK
 case 5:
 YY_RULE_SETUP
-#line 59 "predicate/BPredicate.l"
+#line 57 "predicate/BPredicate.l"
 return OR;
 	YY_BREAK
 case 6:
 YY_RULE_SETUP
-#line 60 "predicate/BPredicate.l"
+#line 58 "predicate/BPredicate.l"
 return NOT;
 	YY_BREAK
 case 7:
 YY_RULE_SETUP
-#line 61 "predicate/BPredicate.l"
+#line 59 "predicate/BPredicate.l"
 return CONSTANT_TRUE;
 	YY_BREAK
 case 8:
 YY_RULE_SETUP
-#line 62 "predicate/BPredicate.l"
+#line 60 "predicate/BPredicate.l"
 return CONSTANT_FALSE;
 	YY_BREAK
 case 9:
 YY_RULE_SETUP
-#line 63 "predicate/BPredicate.l"
+#line 61 "predicate/BPredicate.l"
 {
                     int l = strlen(yytext);
-                    char *p = malloc(l + 1);
+                    char *p = (char *)malloc(l + 1);
                     if (p) {
                         memcpy(p, yytext, l);
                         p[l] = '\0';
@@ -906,10 +901,10 @@ YY_RULE_SETUP
 case 10:
 /* rule 10 can match eol */
 YY_RULE_SETUP
-#line 73 "predicate/BPredicate.l"
+#line 71 "predicate/BPredicate.l"
 {
                     int l = strlen(yytext);
-                    char *p = malloc(l - 1);
+                    char *p = (char *)malloc(l - 1);
                     if (p) {
                         memcpy(p, yytext + 1, l - 2);
                         p[l - 2] = '\0';
@@ -921,20 +916,20 @@ YY_RULE_SETUP
 case 11:
 /* rule 11 can match eol */
 YY_RULE_SETUP
-#line 83 "predicate/BPredicate.l"
+#line 81 "predicate/BPredicate.l"
 ;
 	YY_BREAK
 case 12:
 YY_RULE_SETUP
-#line 84 "predicate/BPredicate.l"
-LexMemoryBufferInput_SetError(yyget_extra(yyscanner)); return 0; // remember failure and report EOF
+#line 82 "predicate/BPredicate.l"
+LexMemoryBufferInput_SetError((LexMemoryBufferInput *)yyget_extra(yyscanner)); return 0; // remember failure and report EOF
 	YY_BREAK
 case 13:
 YY_RULE_SETUP
-#line 85 "predicate/BPredicate.l"
+#line 83 "predicate/BPredicate.l"
 ECHO;
 	YY_BREAK
-#line 938 "generated//flex_BPredicate.c"
+#line 933 "generated//flex_BPredicate.c"
 case YY_STATE_EOF(INITIAL):
 	yyterminate();
 
@@ -1001,7 +996,8 @@ case YY_STATE_EOF(INITIAL):
 
 			else
 				{
-				yy_cp = yyg->yy_c_buf_p;
+				yy_cp = yyg->yy_last_accepting_cpos;
+				yy_current_state = yyg->yy_last_accepting_state;
 				goto yy_find_action;
 				}
 			}
@@ -1493,10 +1489,6 @@ static void yy_load_buffer_state  (yyscan_t yyscanner)
 	yyfree((void *) b ,yyscanner );
 }
 
-#ifndef __cplusplus
-extern int isatty (int );
-#endif /* __cplusplus */
-    
 /* Initializes or reinitializes a buffer.
  * This function is sometimes called more than once on the same buffer,
  * such as during a yyrestart() or at EOF.
@@ -1521,7 +1513,7 @@ extern int isatty (int );
         b->yy_bs_column = 0;
     }
 
-        b->yy_is_interactive = file ? (isatty( fileno(file) ) > 0) : 0;
+        b->yy_is_interactive = 0;
     
 	errno = oerrno;
 }
@@ -2153,7 +2145,7 @@ void yyfree (void * ptr , yyscan_t yyscanner)
 
 #define YYTABLES_NAME "yytables"
 
-#line 85 "predicate/BPredicate.l"
+#line 83 "predicate/BPredicate.l"
 
 
 

+ 4 - 4
generated/flex_BPredicate.h

@@ -33,9 +33,9 @@
 #ifndef FLEXINT_H
 #define FLEXINT_H
 
-/* C99 systems have <inttypes.h>. Non-C99 systems may or may not. */
+/* C99 systems have <stdint.h>. Non-C99 systems may or may not. */
 
-#if defined (__STDC_VERSION__) && __STDC_VERSION__ >= 199901L
+#if 1
 
 /* C99 says to define __STDC_LIMIT_MACROS before including stdint.h,
  * if you want the limit (max/min) macros for int types. 
@@ -44,7 +44,7 @@
 #define __STDC_LIMIT_MACROS 1
 #endif
 
-#include <inttypes.h>
+#include <stdint.h>
 typedef int8_t flex_int8_t;
 typedef uint8_t flex_uint8_t;
 typedef int16_t flex_int16_t;
@@ -351,7 +351,7 @@ extern int yylex \
 #undef YY_DECL
 #endif
 
-#line 85 "predicate/BPredicate.l"
+#line 83 "predicate/BPredicate.l"
 
 
 #line 358 "generated//flex_BPredicate.h"

+ 18 - 7
lwip/custom/arch/cc.h

@@ -30,13 +30,16 @@
 #ifndef LWIP_CUSTOM_CC_H
 #define LWIP_CUSTOM_CC_H
 
-#include <inttypes.h>
 #include <stdlib.h>
 #include <stdio.h>
 #include <errno.h>
+#include <stdint.h>
 
 #include <misc/debug.h>
 #include <misc/byteorder.h>
+#include <misc/packed.h>
+#include <misc/print_macros.h>
+#include <misc/byteorder.h>
 #include <base/BLog.h>
 
 #define u8_t uint8_t
@@ -47,7 +50,9 @@
 #define s32_t int32_t
 #define mem_ptr_t uintptr_t
 
-#define PACK_STRUCT_STRUCT __attribute__((packed))
+#define PACK_STRUCT_BEGIN B_START_PACKED
+#define PACK_STRUCT_END B_END_PACKED
+#define PACK_STRUCT_STRUCT B_PACKED
 
 #define LWIP_PLATFORM_DIAG(x) { if (BLog_WouldLog(BLOG_CHANNEL_lwip, BLOG_INFO)) { BLog_Append x; BLog_Finish(BLOG_CHANNEL_lwip, BLOG_INFO); } }
 #define LWIP_PLATFORM_ASSERT(x) { fprintf(stderr, "%s: lwip assertion failure: %s\n", __FUNCTION__, (x)); abort(); }
@@ -65,14 +70,20 @@
 #define LWIP_PLATFORM_HTONL(x) hton32(x)
 
 // for BYTE_ORDER
-#ifdef BADVPN_USE_WINAPI
+#if defined(BADVPN_USE_WINAPI) && !defined(_MSC_VER)
     #include <sys/param.h>
-#endif
-#ifdef BADVPN_LINUX
+#elif defined(BADVPN_LINUX)
     #include <endian.h>
-#endif
-#ifdef BADVPN_FREEBSD
+#elif defined(BADVPN_FREEBSD)
     #include <machine/endian.h>
+#else
+    #define LITTLE_ENDIAN 1234
+    #define BIG_ENDIAN 4321
+    #if defined(BADVPN_LITTLE_ENDIAN)
+        #define BYTE_ORDER LITTLE_ENDIAN
+    #else
+        #define BYTE_ORDER BIG_ENDIAN
+    #endif
 #endif
 
 #endif

+ 2 - 2
lwip/src/include/netif/etharp.h

@@ -212,10 +212,10 @@ err_t ethernet_input(struct pbuf *p, struct netif *netif);
 
 extern const struct eth_addr ethbroadcast, ethzero;
 
-#endif /* LWIP_ARP || LWIP_ETHERNET */
-
 #ifdef __cplusplus
 }
 #endif
 
+#endif /* LWIP_ARP || LWIP_ETHERNET */
+
 #endif /* __NETIF_ARP_H__ */

+ 1 - 1
misc/balloc.h

@@ -35,7 +35,7 @@
 #define BADVPN_MISC_BALLOC_H
 
 #include <stddef.h>
-#include <inttypes.h>
+#include <stdint.h>
 #include <stdlib.h>
 
 #include <misc/debug.h>

+ 1 - 1
misc/debugcounter.h

@@ -48,7 +48,7 @@ typedef struct {
 } DebugCounter;
 
 #ifndef NDEBUG
-#define DEBUGCOUNTER_STATIC { .c = 0 }
+#define DEBUGCOUNTER_STATIC { 0 }
 #else
 #define DEBUGCOUNTER_STATIC {}
 #endif

+ 5 - 1
misc/ethernet_proto.h

@@ -36,13 +36,17 @@
 
 #include <stdint.h>
 
+#include <misc/packed.h>
+
 #define ETHERTYPE_IPV4 0x0800
 #define ETHERTYPE_ARP 0x0806
 
+B_START_PACKED
 struct ethernet_header {
     uint8_t dest[6];
     uint8_t source[6];
     uint16_t type;
-} __attribute__((packed));
+} B_PACKED;
+B_END_PACKED
 
 #endif

+ 20 - 6
misc/igmp_proto.h

@@ -36,6 +36,8 @@
 
 #include <stdint.h>
 
+#include <misc/packed.h>
+
 #define IGMP_TYPE_MEMBERSHIP_QUERY 0x11
 #define IGMP_TYPE_V1_MEMBERSHIP_REPORT 0x12
 #define IGMP_TYPE_V2_MEMBERSHIP_REPORT 0x16
@@ -47,37 +49,49 @@
 #define IGMP_RECORD_TYPE_CHANGE_TO_INCLUDE_MODE 3
 #define IGMP_RECORD_TYPE_CHANGE_TO_EXCLUDE_MODE 4
 
+B_START_PACKED
 struct igmp_source {
     uint32_t addr;
-} __attribute__((packed));
+} B_PACKED;
+B_END_PACKED
 
+B_START_PACKED
 struct igmp_base {
     uint8_t type;
     uint8_t max_resp_code;
     uint16_t checksum;
-} __attribute__((packed));
+} B_PACKED;
+B_END_PACKED
 
+B_START_PACKED
 struct igmp_v3_query_extra {
     uint32_t group;
     uint8_t reserved4_suppress1_qrv3;
     uint8_t qqic;
     uint16_t number_of_sources;
-} __attribute__((packed));
+} B_PACKED;
+B_END_PACKED
 
+B_START_PACKED
 struct igmp_v3_report_extra {
     uint16_t reserved;
     uint16_t number_of_group_records;
-} __attribute__((packed));
+} B_PACKED;
+B_END_PACKED
 
+B_START_PACKED
 struct igmp_v3_report_record {
     uint8_t type;
     uint8_t aux_data_len;
     uint16_t number_of_sources;
     uint32_t group;
-} __attribute__((packed));
+} B_PACKED;
+B_END_PACKED
 
+B_START_PACKED
 struct igmp_v2_extra {
     uint32_t group;
-} __attribute__((packed));
+} B_PACKED;
+B_END_PACKED
 
 #endif

+ 8 - 3
misc/ipv4_proto.h

@@ -38,10 +38,12 @@
 
 #include <misc/debug.h>
 #include <misc/byteorder.h>
+#include <misc/packed.h>
 
 #define IPV4_PROTOCOL_IGMP 2
 #define IPV4_PROTOCOL_UDP 17
 
+B_START_PACKED
 struct ipv4_header {
     uint8_t version4_ihl4;
     uint8_t ds;
@@ -57,22 +59,25 @@ struct ipv4_header {
     uint32_t source_address;
     //
     uint32_t destination_address;
-} __attribute__((packed));
+} B_PACKED;
+B_END_PACKED
 
 #define IPV4_GET_VERSION(_header) (((_header).version4_ihl4&0xF0)>>4)
 #define IPV4_GET_IHL(_header) (((_header).version4_ihl4&0x0F)>>0)
 
 #define IPV4_MAKE_VERSION_IHL(size) (((size)/4) + (4 << 4))
 
+B_START_PACKED
 struct ipv4_short {
     uint16_t v;
-} __attribute__((packed));
+} B_PACKED;
+B_END_PACKED
 
 static uint16_t ipv4_checksum (uint8_t *ip_hdr, uint16_t len)
 {
     ASSERT(len % 2 == 0)
     
-    struct ipv4_short *s = (void *)ip_hdr;
+    struct ipv4_short *s = (struct ipv4_short *)ip_hdr;
     
     uint32_t t = 0;
     

+ 51 - 0
misc/packed.h

@@ -0,0 +1,51 @@
+/**
+ * @file packed.h
+ * @author Ambroz Bizjak <ambrop7@gmail.com>
+ * 
+ * @section LICENSE
+ * 
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of the author nor the
+ *    names of its contributors may be used to endorse or promote products
+ *    derived from this software without specific prior written permission.
+ * 
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
+ * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ * 
+ * @section DESCRIPTION
+ * 
+ * Structure packing macros.
+ */
+
+#ifndef BADVPN_PACKED_H
+#define BADVPN_PACKED_H
+
+#ifdef _MSC_VER
+
+#define B_START_PACKED __pragma(pack(push, 1))
+#define B_END_PACKED __pragma(pack(pop))
+#define B_PACKED
+
+#else
+
+#define B_START_PACKED
+#define B_END_PACKED
+#define B_PACKED __attribute__((packed))
+
+#endif
+
+#endif

+ 1 - 1
misc/parse_number.h

@@ -34,7 +34,7 @@
 #ifndef BADVPN_MISC_PARSE_NUMBER_H
 #define BADVPN_MISC_PARSE_NUMBER_H
 
-#include <inttypes.h>
+#include <stdint.h>
 #include <string.h>
 #include <stddef.h>
 

+ 98 - 0
misc/print_macros.h

@@ -0,0 +1,98 @@
+/**
+ * @file print_macros.h
+ * @author Ambroz Bizjak <ambrop7@gmail.com>
+ * 
+ * @section LICENSE
+ * 
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of the author nor the
+ *    names of its contributors may be used to endorse or promote products
+ *    derived from this software without specific prior written permission.
+ * 
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
+ * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ * 
+ * @section DESCRIPTION
+ * 
+ * Format macros for printf() for non-standard compilers.
+ */
+
+#ifndef BADVPN_PRINT_MACROS
+#define BADVPN_PRINT_MACROS
+
+#ifdef _MSC_VER
+
+// size_t
+#define PRIsz "Iu"
+
+// signed exact width (intN_t)
+#define PRId8 "d"
+#define PRIi8 "i"
+#define PRId16 "d"
+#define PRIi16 "i"
+#define PRId32 "I32d"
+#define PRIi32 "I32i"
+#define PRId64 "I64d"
+#define PRIi64 "I64i"
+
+// unsigned exact width (uintN_t)
+#define PRIo8 "o"
+#define PRIu8 "u"
+#define PRIx8 "x"
+#define PRIX8 "X"
+#define PRIo16 "o"
+#define PRIu16 "u"
+#define PRIx16 "x"
+#define PRIX16 "X"
+#define PRIo32 "I32o"
+#define PRIu32 "I32u"
+#define PRIx32 "I32x"
+#define PRIX32 "I32X"
+#define PRIo64 "I64o"
+#define PRIu64 "I64u"
+#define PRIx64 "I64x"
+#define PRIX64 "I64X"
+
+// signed maximum width (intmax_t)
+#define PRIdMAX "I64d"
+#define PRIiMAX "I64i"
+
+// unsigned maximum width (uintmax_t)
+#define PRIoMAX "I64o"
+#define PRIuMAX "I64u"
+#define PRIxMAX "I64x"
+#define PRIXMAX "I64X"
+
+// signed pointer (intptr_t)
+#define PRIdPTR "Id"
+#define PRIiPTR "Ii"
+
+// unsigned pointer (uintptr_t)
+#define PRIoPTR "Io"
+#define PRIuPTR "Iu"
+#define PRIxPTR "Ix"
+#define PRIXPTR "IX"
+
+#else
+
+#include <inttypes.h>
+
+#define PRIsz "zu"
+
+#endif
+
+#endif

+ 23 - 7
misc/socks_proto.h

@@ -36,6 +36,8 @@
 
 #include <stdint.h>
 
+#include <misc/packed.h>
+
 #define SOCKS_VERSION 0x05
 
 #define SOCKS_METHOD_NO_AUTHENTICATION_REQUIRED 0x00
@@ -61,42 +63,56 @@
 #define SOCKS_REP_COMMAND_NOT_SUPPORTED 0x07
 #define SOCKS_REP_ADDRESS_TYPE_NOT_SUPPORTED 0x08
 
+B_START_PACKED
 struct socks_client_hello_header {
     uint8_t ver;
     uint8_t nmethods;
-} __attribute__((packed));
+} B_PACKED;
+B_END_PACKED
 
+B_START_PACKED
 struct socks_client_hello_method {
     uint8_t method;
-} __attribute__((packed));
+} B_PACKED;
+B_END_PACKED
 
+B_START_PACKED
 struct socks_server_hello {
     uint8_t ver;
     uint8_t method;
-} __attribute__((packed));
+} B_PACKED;
+B_END_PACKED
 
+B_START_PACKED
 struct socks_request_header {
     uint8_t ver;
     uint8_t cmd;
     uint8_t rsv;
     uint8_t atyp;
-} __attribute__((packed));
+} B_PACKED;
+B_END_PACKED
 
+B_START_PACKED
 struct socks_reply_header {
     uint8_t ver;
     uint8_t rep;
     uint8_t rsv;
     uint8_t atyp;
-} __attribute__((packed));
+} B_PACKED;
+B_END_PACKED
 
+B_START_PACKED
 struct socks_addr_ipv4 {
     uint32_t addr;
     uint16_t port;
-} __attribute__((packed));
+} B_PACKED;
+B_END_PACKED
 
+B_START_PACKED
 struct socks_addr_ipv6 {
     uint8_t addr[16];
     uint16_t port;
-} __attribute__((packed));    
+} B_PACKED;    
+B_END_PACKED
 
 #endif

+ 86 - 0
misc/strdup.h

@@ -0,0 +1,86 @@
+/**
+ * @file strdup.h
+ * @author Ambroz Bizjak <ambrop7@gmail.com>
+ * 
+ * @section LICENSE
+ * 
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of the author nor the
+ *    names of its contributors may be used to endorse or promote products
+ *    derived from this software without specific prior written permission.
+ * 
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
+ * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ * 
+ * @section DESCRIPTION
+ * 
+ * Allocate memory for a string and copy it there.
+ */
+
+#ifndef BADVPN_STRDUP_H
+#define BADVPN_STRDUP_H
+
+#include <string.h>
+#include <stdlib.h>
+#include <limits.h>
+
+#include <misc/debug.h>
+
+/**
+ * Allocate and copy a null-terminated string.
+ */
+static char * b_strdup (const char *str)
+{
+    ASSERT(str)
+    
+    size_t len = strlen(str);
+    
+    char *s = (char *)malloc(len + 1);
+    if (!s) {
+        return NULL;
+    }
+    
+    memcpy(s, str, len + 1);
+    
+    return s;
+}
+
+/**
+ * Allocate memory for a null-terminated string and use the
+ * given data as its contents. A null terminator is appended
+ * after the specified data.
+ */
+static char * b_strdup_bin (const char *str, size_t len)
+{
+    ASSERT(str)
+    
+    if (len == SIZE_MAX) {
+        return NULL;
+    }
+    
+    char *s = (char *)malloc(len + 1);
+    if (!s) {
+        return NULL;
+    }
+    
+    memcpy(s, str, len);
+    s[len] = '\0';
+    
+    return s;
+}
+
+#endif

+ 4 - 2
misc/udp_proto.h

@@ -40,18 +40,20 @@
 #include <misc/byteorder.h>
 #include <misc/ipv4_proto.h>
 
+B_START_PACKED
 struct udp_header {
     uint16_t source_port;
     uint16_t dest_port;
     uint16_t length;
     uint16_t checksum;
-} __attribute__((packed));
+} B_PACKED;
+B_END_PACKED
 
 static uint32_t udp_checksum_summer (uint8_t *data, uint16_t len)
 {
     ASSERT(len % 2 == 0)
     
-    struct ipv4_short *s = (void *)data;
+    struct ipv4_short *s = (struct ipv4_short *)data;
     
     uint32_t t = 0;
     

+ 1 - 1
ncd/NCDRequestClient.c

@@ -115,7 +115,7 @@ static void connector_handler (NCDRequestClient *o, int is_error)
     BPendingGroup *pg = BReactor_PendingGroup(o->reactor);
     
     // init connection
-    if (!BConnection_Init(&o->con, BCONNECTION_SOURCE_CONNECTOR(&o->connector), o->reactor, o, (BConnection_handler)connection_handler)) {
+    if (!BConnection_Init(&o->con, BConnection_source_connector(&o->connector), o->reactor, o, (BConnection_handler)connection_handler)) {
         BLog(BLOG_ERROR, "BConnection_Init failed");
         goto fail0;
     }

+ 1 - 1
ncd/modules/sys_request_server.c

@@ -188,7 +188,7 @@ static void listener_handler (struct instance *o)
     
     LinkedList0_Prepend(&o->connections_list, &c->connections_list_node);
     
-    if (!BConnection_Init(&c->con, BCONNECTION_SOURCE_LISTENER(&o->listener, &c->addr), reactor, c, (BConnection_handler)connection_con_handler)) {
+    if (!BConnection_Init(&c->con, BConnection_source_listener(&o->listener, &c->addr), reactor, c, (BConnection_handler)connection_con_handler)) {
         ModuleLog(o->i, BLOG_ERROR, "BConnection_Init failed");
         goto fail1;
     }

+ 2 - 2
nspr_support/BSSLConnection.c

@@ -30,10 +30,10 @@
 #include <prerror.h>
 #include <ssl.h>
 
-#include <inttypes.h>
 #include <string.h>
 #include <stdlib.h>
 
+#include <misc/print_macros.h>
 #include <base/BLog.h>
 
 #include "BSSLConnection.h"
@@ -548,7 +548,7 @@ int BSSLConnection_MakeBackend (PRFileDesc *prfd, StreamPassInterface *send_if,
     ASSERT(bprconnection_initialized)
     
     // allocate backend
-    struct BSSLConnection_backend *b = malloc(sizeof(*b));
+    struct BSSLConnection_backend *b = (struct BSSLConnection_backend *)malloc(sizeof(*b));
     if (!b) {
         BLog(BLOG_ERROR, "malloc failed");
         return 0;

+ 2 - 2
predicate/BPredicate.c

@@ -230,14 +230,14 @@ void BPredicate_Free (BPredicate *p)
     DebugObject_Free(&p->d_obj);
     
     // free tree
-    free_predicate_node(p->root);
+    free_predicate_node((struct predicate_node *)p->root);
 }
 
 int BPredicate_Eval (BPredicate *p)
 {
     ASSERT(!p->in_function)
     
-    if (!eval_predicate_node(p, p->root)) {
+    if (!eval_predicate_node(p, (struct predicate_node *)p->root)) {
         return -1;
     }
     

+ 5 - 7
predicate/BPredicate.l

@@ -41,15 +41,13 @@
 
 #include <generated/bison_BPredicate.h>
 
-#define YY_EXTRA_TYPE LexMemoryBufferInput *
-
 #define YY_INPUT(buffer, res, max_size) \
-    int bytes_read = LexMemoryBufferInput_Read(yyget_extra(yyscanner), buffer, max_size); \
+    int bytes_read = LexMemoryBufferInput_Read((LexMemoryBufferInput *)yyget_extra(yyscanner), buffer, max_size); \
     res = (bytes_read == 0 ? YY_NULL : bytes_read);
 
 %}
 
-%option reentrant stack noyywrap bison-bridge bison-locations
+%option reentrant stack noyywrap bison-bridge bison-locations never-interactive nounistd
 
 %%
 \(              return SPAR;
@@ -62,7 +60,7 @@ true            return CONSTANT_TRUE;
 false           return CONSTANT_FALSE;
 [a-zA-Z0-9_]+   {
                     int l = strlen(yytext);
-                    char *p = malloc(l + 1);
+                    char *p = (char *)malloc(l + 1);
                     if (p) {
                         memcpy(p, yytext, l);
                         p[l] = '\0';
@@ -72,7 +70,7 @@ false           return CONSTANT_FALSE;
                 }
 \"[^\"]*\"      {
                     int l = strlen(yytext);
-                    char *p = malloc(l - 1);
+                    char *p = (char *)malloc(l - 1);
                     if (p) {
                         memcpy(p, yytext + 1, l - 2);
                         p[l - 2] = '\0';
@@ -81,5 +79,5 @@ false           return CONSTANT_FALSE;
                     return STRING;
                 }
 [ \t\n]+        ;
-.               LexMemoryBufferInput_SetError(yyget_extra(yyscanner)); return 0; // remember failure and report EOF
+.               LexMemoryBufferInput_SetError((LexMemoryBufferInput *)yyget_extra(yyscanner)); return 0; // remember failure and report EOF
 %%

+ 6 - 6
predicate/BPredicate.y

@@ -42,7 +42,7 @@
 
 static struct predicate_node * make_constant (int val)
 {
-    struct predicate_node *n = malloc(sizeof(*n));
+    struct predicate_node *n = (struct predicate_node *)malloc(sizeof(*n));
     if (!n) {
         return NULL;
     }
@@ -59,7 +59,7 @@ static struct predicate_node * make_negation (struct predicate_node *op)
         goto fail;
     }
 
-    struct predicate_node *n = malloc(sizeof(*n));
+    struct predicate_node *n = (struct predicate_node *)malloc(sizeof(*n));
     if (!n) {
         goto fail;
     }
@@ -82,7 +82,7 @@ static struct predicate_node * make_conjunction (struct predicate_node *op1, str
         goto fail;
     }
 
-    struct predicate_node *n = malloc(sizeof(*n));
+    struct predicate_node *n = (struct predicate_node *)malloc(sizeof(*n));
     if (!n) {
         goto fail;
     }
@@ -109,7 +109,7 @@ static struct predicate_node * make_disjunction (struct predicate_node *op1, str
         goto fail;
     }
 
-    struct predicate_node *n = malloc(sizeof(*n));
+    struct predicate_node *n = (struct predicate_node *)malloc(sizeof(*n));
     if (!n) {
         goto fail;
     }
@@ -136,7 +136,7 @@ static struct predicate_node * make_function (char *name, struct arguments_node
         goto fail;
     }
 
-    struct predicate_node *n = malloc(sizeof(*n));
+    struct predicate_node *n = (struct predicate_node *)malloc(sizeof(*n));
     if (!n) {
         goto fail;
     }
@@ -163,7 +163,7 @@ static struct arguments_node * make_arguments (struct arguments_arg arg, struct
         goto fail;
     }
 
-    struct arguments_node *n = malloc(sizeof(*n));
+    struct arguments_node *n = (struct arguments_node *)malloc(sizeof(*n));
     if (!n) {
         goto fail;
     }

+ 2 - 0
predicate/BPredicate_parser.h

@@ -34,6 +34,8 @@
 #ifndef BADVPN_PREDICATE_BPREDICATE_PARSER_H
 #define BADVPN_PREDICATE_BPREDICATE_PARSER_H
 
+#define YY_NO_UNISTD_H
+
 #include <predicate/BPredicate_internal.h>
 
 #include <generated/bison_BPredicate.h>

+ 7 - 2
protocol/dataproto.h

@@ -44,6 +44,7 @@
 #include <stdint.h>
 
 #include <protocol/scproto.h>
+#include <misc/packed.h>
 
 #define DATAPROTO_MAX_PEER_IDS 1
 
@@ -52,6 +53,7 @@
 /**
  * DataProto header.
  */
+B_START_PACKED
 struct dataproto_header {
     /**
      * Bitwise OR of flags. Possible flags:
@@ -71,15 +73,18 @@ struct dataproto_header {
      * Must be <=DATAPROTO_MAX_PEER_IDS.
      */
     peerid_t num_peer_ids;
-} __attribute__((packed));
+} B_PACKED;
+B_END_PACKED
 
 /**
  * Structure for a destination peer ID in DataProto.
  * Wraps a single peerid_t in a packed struct for easy access.
  */
+B_START_PACKED
 struct dataproto_peer_id {
     peerid_t id;
-} __attribute__((packed));
+} B_PACKED;
+B_END_PACKED
 
 #define DATAPROTO_MAX_OVERHEAD (sizeof(struct dataproto_header) + DATAPROTO_MAX_PEER_IDS * sizeof(struct dataproto_peer_id))
 

+ 4 - 1
protocol/fragmentproto.h

@@ -45,12 +45,14 @@
 #include <stdint.h>
 
 #include <misc/balign.h>
+#include <misc/packed.h>
 
 typedef uint16_t fragmentproto_frameid;
 
 /**
  * FragmentProto chunk header.
  */
+B_START_PACKED
 struct fragmentproto_chunk_header {
     /**
      * Identifier of the frame this chunk belongs to.
@@ -74,7 +76,8 @@ struct fragmentproto_chunk_header {
      * the total length of the frame is chunk_start + chunk_len.
      */
     uint8_t is_last;
-} __attribute__((packed));
+} B_PACKED;
+B_END_PACKED
 
 /**
  * Calculates how many chunks are needed at most for encoding one frame of the

+ 5 - 1
protocol/packetproto.h

@@ -45,17 +45,21 @@
 #include <stdint.h>
 #include <limits.h>
 
+#include <misc/packed.h>
+
 /**
  * PacketProto packet header.
  * Wraps a single uint16_t in a packed struct for easy access.
  */
+B_START_PACKED
 struct packetproto_header
 {
     /**
      * Length of the packet payload that follows.
      */
     uint16_t len;
-} __attribute__((packed));
+} B_PACKED;
+B_END_PACKED
 
 #define PACKETPROTO_ENCLEN(_len) (sizeof(struct packetproto_header) + (_len))
 

+ 29 - 9
protocol/scproto.h

@@ -86,6 +86,8 @@
 
 #include <stdint.h>
 
+#include <misc/packed.h>
+
 #define SC_VERSION 29
 #define SC_OLDVERSION_NOSSL 27
 #define SC_OLDVERSION_BROKENCERT 26
@@ -96,12 +98,14 @@
  * SCProto packet header.
  * Follows up to SC_MAX_PAYLOAD bytes of payload.
  */
+B_START_PACKED
 struct sc_header {
     /**
      * Message type.
      */
     uint8_t type;
-} __attribute__((packed));
+} B_PACKED;
+B_END_PACKED
 
 #define SC_MAX_PAYLOAD 2000
 #define SC_MAX_ENC (sizeof(struct sc_header) + SC_MAX_PAYLOAD)
@@ -122,17 +126,20 @@ typedef uint16_t peerid_t;
  * "clienthello" client packet payload.
  * Packet type is SCID_CLIENTHELLO.
  */
+B_START_PACKED
 struct sc_client_hello {
     /**
      * Protocol version the client is using.
      */
     uint16_t version;
-} __attribute__((packed));
+} B_PACKED;
+B_END_PACKED
 
 /**
  * "serverhello" server packet payload.
  * Packet type is SCID_SERVERHELLO.
  */
+B_START_PACKED
 struct sc_server_hello {
     /**
      * Flags. Not used yet.
@@ -149,7 +156,8 @@ struct sc_server_hello {
      * (network byte order). Zero if not applicable.
      */
     uint32_t clientAddr;
-} __attribute__((packed));
+} B_PACKED;
+B_END_PACKED
 
 /**
  * "newclient" server packet payload.
@@ -157,6 +165,7 @@ struct sc_server_hello {
  * If the server is using TLS, follows up to SCID_NEWCLIENT_MAX_CERT_LEN
  * bytes of the new client's certificate (encoded in DER).
  */
+B_START_PACKED
 struct sc_server_newclient {
     /**
      * ID of the new peer.
@@ -173,7 +182,8 @@ struct sc_server_newclient {
      *     SSL must be used to talk to this peer through messages.
      */
     uint16_t flags;
-} __attribute__((packed));
+} B_PACKED;
+B_END_PACKED
 
 #define SCID_NEWCLIENT_FLAG_RELAY_SERVER 1
 #define SCID_NEWCLIENT_FLAG_RELAY_CLIENT 2
@@ -185,36 +195,42 @@ struct sc_server_newclient {
  * "endclient" server packet payload.
  * Packet type is SCID_ENDCLIENT.
  */
+B_START_PACKED
 struct sc_server_endclient {
     /**
      * ID of the removed peer.
      */
     peerid_t id;
-} __attribute__((packed));
+} B_PACKED;
+B_END_PACKED
 
 /**
  * "outmsg" client packet header.
  * Packet type is SCID_OUTMSG.
  * Follows up to SC_MAX_MSGLEN bytes of message payload.
  */
+B_START_PACKED
 struct sc_client_outmsg {
     /**
      * ID of the destionation peer.
      */
     peerid_t clientid;
-} __attribute__((packed));
+} B_PACKED;
+B_END_PACKED
 
 /**
  * "inmsg" server packet payload.
  * Packet type is SCID_INMSG.
  * Follows up to SC_MAX_MSGLEN bytes of message payload.
  */
+B_START_PACKED
 struct sc_server_inmsg {
     /**
      * ID of the source peer.
      */
     peerid_t clientid;
-} __attribute__((packed));
+} B_PACKED;
+B_END_PACKED
 
 #define _SC_MAX_OUTMSGLEN (SC_MAX_PAYLOAD - sizeof(struct sc_client_outmsg))
 #define _SC_MAX_INMSGLEN (SC_MAX_PAYLOAD - sizeof(struct sc_server_inmsg))
@@ -225,22 +241,26 @@ struct sc_server_inmsg {
  * "resetpeer" client packet header.
  * Packet type is SCID_RESETPEER.
  */
+B_START_PACKED
 struct sc_client_resetpeer {
     /**
      * ID of the peer to reset.
      */
     peerid_t clientid;
-} __attribute__((packed));
+} B_PACKED;
+B_END_PACKED
 
 /**
  * "acceptpeer" client packet payload.
  * Packet type is SCID_ACCEPTPEER.
  */
+B_START_PACKED
 struct sc_client_acceptpeer {
     /**
      * ID of the peer to accept.
      */
     peerid_t clientid;
-} __attribute__((packed));
+} B_PACKED;
+B_END_PACKED
 
 #endif

+ 4 - 1
protocol/spproto.h

@@ -62,6 +62,7 @@
 
 #include <misc/debug.h>
 #include <misc/balign.h>
+#include <misc/packed.h>
 #include <security/BHash.h>
 #include <security/BEncryption.h>
 #include <security/OTPCalculator.h>
@@ -113,10 +114,12 @@ struct spproto_security_params {
 
 #define SPPROTO_HAVE_OTP(_params) ((_params).otp_mode != SPPROTO_OTP_MODE_NONE)
 
+B_START_PACKED
 struct spproto_otpdata {
     uint16_t seed_id;
     otp_t otp;
-} __attribute__((packed));
+} B_PACKED;
+B_END_PACKED
 
 #define SPPROTO_HEADER_OTPDATA_OFF(_params) 0
 #define SPPROTO_HEADER_OTPDATA_LEN(_params) (SPPROTO_HAVE_OTP(_params) ? sizeof(struct spproto_otpdata) : 0)

+ 4 - 1
protocol/udpgw_proto.h

@@ -37,16 +37,19 @@
 #include <stdint.h>
 
 #include <misc/bsize.h>
+#include <misc/packed.h>
 
 #define UDPGW_CLIENT_FLAG_KEEPALIVE (1 << 0)
 #define UDPGW_CLIENT_FLAG_REBIND (1 << 1)
 
+B_START_PACKED
 struct udpgw_header {
     uint8_t flags;
     uint16_t conid;
     uint32_t addr_ip;
     uint16_t addr_port;
-} __attribute__((packed));
+} B_PACKED;
+B_END_PACKED
 
 static int udpgw_compute_mtu (int dgram_mtu)
 {

+ 1 - 1
security/OTPCalculator.c

@@ -52,7 +52,7 @@ int OTPCalculator_Init (OTPCalculator *calc, int num_otps, int cipher)
     calc->num_blocks = bdivide_up(calc->num_otps * sizeof(otp_t), calc->block_size);
     
     // allocate buffer
-    if (!(calc->data = BAllocArray(calc->num_blocks, calc->block_size))) {
+    if (!(calc->data = (otp_t *)BAllocArray(calc->num_blocks, calc->block_size))) {
         goto fail0;
     }
     

+ 2 - 2
security/OTPChecker.c

@@ -179,12 +179,12 @@ int OTPChecker_Init (OTPChecker *mc, int num_otps, int cipher, int num_tables, B
     }
     
     // allocate tables
-    if (!(mc->tables = BAllocArray(mc->num_tables, sizeof(mc->tables[0])))) {
+    if (!(mc->tables = (struct OTPChecker_table *)BAllocArray(mc->num_tables, sizeof(mc->tables[0])))) {
         goto fail1;
     }
     
     // allocate entries
-    if (!(mc->entries = BAllocArray2(mc->num_tables, mc->num_entries, sizeof(mc->entries[0])))) {
+    if (!(mc->entries = (struct OTPChecker_entry *)BAllocArray2(mc->num_tables, mc->num_entries, sizeof(mc->entries[0])))) {
         goto fail2;
     }
     

+ 23 - 21
server/server.c

@@ -27,7 +27,7 @@
  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
-#include <inttypes.h>
+#include <stdint.h>
 #include <stdlib.h>
 #include <string.h>
 #include <stddef.h>
@@ -393,10 +393,11 @@ int main (int argc, char *argv[])
         }
         
         // init functions
-        BPredicateFunction_Init(&comm_predicate_func_p1name, &comm_predicate, "p1name", (int []){PREDICATE_TYPE_STRING}, 1, comm_predicate_func_p1name_cb, NULL);
-        BPredicateFunction_Init(&comm_predicate_func_p2name, &comm_predicate, "p2name", (int []){PREDICATE_TYPE_STRING}, 1, comm_predicate_func_p2name_cb, NULL);
-        BPredicateFunction_Init(&comm_predicate_func_p1addr, &comm_predicate, "p1addr", (int []){PREDICATE_TYPE_STRING}, 1, comm_predicate_func_p1addr_cb, NULL);
-        BPredicateFunction_Init(&comm_predicate_func_p2addr, &comm_predicate, "p2addr", (int []){PREDICATE_TYPE_STRING}, 1, comm_predicate_func_p2addr_cb, NULL);
+        int args[] = {PREDICATE_TYPE_STRING};
+        BPredicateFunction_Init(&comm_predicate_func_p1name, &comm_predicate, "p1name", args, 1, comm_predicate_func_p1name_cb, NULL);
+        BPredicateFunction_Init(&comm_predicate_func_p2name, &comm_predicate, "p2name", args, 1, comm_predicate_func_p2name_cb, NULL);
+        BPredicateFunction_Init(&comm_predicate_func_p1addr, &comm_predicate, "p1addr", args, 1, comm_predicate_func_p1addr_cb, NULL);
+        BPredicateFunction_Init(&comm_predicate_func_p2addr, &comm_predicate, "p2addr", args, 1, comm_predicate_func_p2addr_cb, NULL);
     }
     
     // init relay predicate
@@ -408,10 +409,11 @@ int main (int argc, char *argv[])
         }
         
         // init functions
-        BPredicateFunction_Init(&relay_predicate_func_pname, &relay_predicate, "pname", (int []){PREDICATE_TYPE_STRING}, 1, relay_predicate_func_pname_cb, NULL);
-        BPredicateFunction_Init(&relay_predicate_func_rname, &relay_predicate, "rname", (int []){PREDICATE_TYPE_STRING}, 1, relay_predicate_func_rname_cb, NULL);
-        BPredicateFunction_Init(&relay_predicate_func_paddr, &relay_predicate, "paddr", (int []){PREDICATE_TYPE_STRING}, 1, relay_predicate_func_paddr_cb, NULL);
-        BPredicateFunction_Init(&relay_predicate_func_raddr, &relay_predicate, "raddr", (int []){PREDICATE_TYPE_STRING}, 1, relay_predicate_func_raddr_cb, NULL);
+        int args[] = {PREDICATE_TYPE_STRING};
+        BPredicateFunction_Init(&relay_predicate_func_pname, &relay_predicate, "pname", args, 1, relay_predicate_func_pname_cb, NULL);
+        BPredicateFunction_Init(&relay_predicate_func_rname, &relay_predicate, "rname", args, 1, relay_predicate_func_rname_cb, NULL);
+        BPredicateFunction_Init(&relay_predicate_func_paddr, &relay_predicate, "paddr", args, 1, relay_predicate_func_paddr_cb, NULL);
+        BPredicateFunction_Init(&relay_predicate_func_raddr, &relay_predicate, "raddr", args, 1, relay_predicate_func_raddr_cb, NULL);
     }
     
     // init time
@@ -830,14 +832,14 @@ void listener_handler (BListener *listener)
     }
     
     // allocate the client structure
-    struct client_data *client = malloc(sizeof(*client));
+    struct client_data *client = (struct client_data *)malloc(sizeof(*client));
     if (!client) {
         BLog(BLOG_ERROR, "failed to allocate client");
         goto fail0;
     }
     
     // accept connection
-    if (!BConnection_Init(&client->con, BCONNECTION_SOURCE_LISTENER(listener, &client->addr), &ss, client, (BConnection_handler)client_connection_handler)) {
+    if (!BConnection_Init(&client->con, BConnection_source_listener(listener, &client->addr), &ss, client, (BConnection_handler)client_connection_handler)) {
         BLog(BLOG_ERROR, "BConnection_Init failed");
         goto fail1;
     }
@@ -1691,7 +1693,7 @@ struct peer_flow * peer_flow_create (struct client_data *src_client, struct clie
     ASSERT(!find_flow(src_client, dest_client->id))
     
     // allocate flow structure
-    struct peer_flow *flow = malloc(sizeof(*flow));
+    struct peer_flow *flow = (struct peer_flow *)malloc(sizeof(*flow));
     if (!flow) {
         BLog(BLOG_ERROR, "malloc failed");
         goto fail0;
@@ -2026,21 +2028,21 @@ int clients_allowed (struct client_data *client1, struct client_data *client2)
 
 int comm_predicate_func_p1name_cb (void *user, void **args)
 {
-    char *arg = args[0];
+    char *arg = (char *)args[0];
     
     return (!strcmp(arg, comm_predicate_p1name));
 }
 
 int comm_predicate_func_p2name_cb (void *user, void **args)
 {
-    char *arg = args[0];
+    char *arg = (char *)args[0];
     
     return (!strcmp(arg, comm_predicate_p2name));
 }
 
 int comm_predicate_func_p1addr_cb (void *user, void **args)
 {
-    char *arg = args[0];
+    char *arg = (char *)args[0];
     
     BIPAddr addr;
     if (!BIPAddr_Resolve(&addr, arg, 1)) {
@@ -2053,7 +2055,7 @@ int comm_predicate_func_p1addr_cb (void *user, void **args)
 
 int comm_predicate_func_p2addr_cb (void *user, void **args)
 {
-    char *arg = args[0];
+    char *arg = (char *)args[0];
     
     BIPAddr addr;
     if (!BIPAddr_Resolve(&addr, arg, 1)) {
@@ -2087,21 +2089,21 @@ int relay_allowed (struct client_data *client, struct client_data *relay)
 
 int relay_predicate_func_pname_cb (void *user, void **args)
 {
-    char *arg = args[0];
+    char *arg = (char *)args[0];
     
     return (!strcmp(arg, relay_predicate_pname));
 }
 
 int relay_predicate_func_rname_cb (void *user, void **args)
 {
-    char *arg = args[0];
+    char *arg = (char *)args[0];
     
     return (!strcmp(arg, relay_predicate_rname));
 }
 
 int relay_predicate_func_paddr_cb (void *user, void **args)
 {
-    char *arg = args[0];
+    char *arg = (char *)args[0];
     
     BIPAddr addr;
     if (!BIPAddr_Resolve(&addr, arg, 1)) {
@@ -2114,7 +2116,7 @@ int relay_predicate_func_paddr_cb (void *user, void **args)
 
 int relay_predicate_func_raddr_cb (void *user, void **args)
 {
-    char *arg = args[0];
+    char *arg = (char *)args[0];
     
     BIPAddr addr;
     if (!BIPAddr_Resolve(&addr, arg, 1)) {
@@ -2138,7 +2140,7 @@ struct peer_know * create_know (struct client_data *from, struct client_data *to
     ASSERT(!to->dying)
     
     // allocate structure
-    struct peer_know *k = malloc(sizeof(*k));
+    struct peer_know *k = (struct peer_know *)malloc(sizeof(*k));
     if (!k) {
         return NULL;
     }

+ 16 - 4
server_connection/ServerConnection.c

@@ -30,6 +30,7 @@
 #include <stdio.h>
 
 #include <misc/debug.h>
+#include <misc/strdup.h>
 #include <base/BLog.h>
 
 #include <server_connection/ServerConnection.h>
@@ -75,7 +76,7 @@ void connector_handler (ServerConnection *o, int is_error)
     BLog(BLOG_NOTICE, "connected");
     
     // init connection
-    if (!BConnection_Init(&o->con, BCONNECTION_SOURCE_CONNECTOR(&o->connector), o->reactor, o, (BConnection_handler)connection_handler)) {
+    if (!BConnection_Init(&o->con, BConnection_source_connector(&o->connector), o->reactor, o, (BConnection_handler)connection_handler)) {
         BLog(BLOG_ERROR, "BConnection_Init failed");
         goto fail0;
     }
@@ -493,6 +494,7 @@ int ServerConnection_Init (
     ASSERT(keepalive_interval > 0)
     ASSERT(buffer_size > 0)
     ASSERT(have_ssl == 0 || have_ssl == 1)
+    ASSERT(!have_ssl || server_name)
     
     // init arguments
     o->reactor = reactor;
@@ -502,7 +504,6 @@ int ServerConnection_Init (
     if (have_ssl) {
         o->client_cert = client_cert;
         o->client_key = client_key;
-        snprintf(o->server_name, sizeof(o->server_name), "%s", server_name);
     }
     o->user = user;
     o->handler_error = handler_error;
@@ -511,15 +512,21 @@ int ServerConnection_Init (
     o->handler_endclient = handler_endclient;
     o->handler_message = handler_message;
     
+    o->server_name = NULL;
+    if (have_ssl && !(o->server_name = b_strdup(server_name))) {
+        BLog(BLOG_ERROR, "malloc failed");
+        goto fail0;
+    }
+    
     if (!BConnection_AddressSupported(addr)) {
         BLog(BLOG_ERROR, "BConnection_AddressSupported failed");
-        goto fail0;
+        goto fail1;
     }
     
     // init connector
     if (!BConnector_Init(&o->connector, addr, o->reactor, o, (BConnector_handler)connector_handler)) {
         BLog(BLOG_ERROR, "BConnector_Init failed");
-        goto fail0;
+        goto fail1;
     }
     
     // init newclient job
@@ -532,6 +539,8 @@ int ServerConnection_Init (
     DebugObject_Init(&o->d_obj);
     return 1;
     
+fail1:
+    free(o->server_name);
 fail0:
     return 0;
 }
@@ -587,6 +596,9 @@ void ServerConnection_Free (ServerConnection *o)
     
     // free connector
     BConnector_Free(&o->connector);
+    
+    // free server name
+    free(o->server_name);
 }
 
 PacketPassInterface * ServerConnection_GetSendInterface (ServerConnection *o)

+ 1 - 1
server_connection/ServerConnection.h

@@ -136,7 +136,7 @@ typedef struct {
     SECKEYPrivateKey *client_key;
     
     // server name if using SSL
-    char server_name[256];
+    char *server_name;
     
     // handlers
     void *user;

+ 1 - 1
socksclient/BSocksClient.c

@@ -131,7 +131,7 @@ void connector_handler (BSocksClient* o, int is_error)
     }
     
     // init connection
-    if (!BConnection_Init(&o->con, BCONNECTION_SOURCE_CONNECTOR(&o->connector), o->reactor, o, (BConnection_handler)connection_handler)) {
+    if (!BConnection_Init(&o->con, BConnection_source_connector(&o->connector), o->reactor, o, (BConnection_handler)connection_handler)) {
         BLog(BLOG_ERROR, "BConnection_Init failed");
         goto fail0;
     }

+ 31 - 18
socksclient/BSocksClient.h

@@ -39,6 +39,7 @@
 #include <misc/debug.h>
 #include <misc/debugerror.h>
 #include <misc/socks_proto.h>
+#include <misc/packed.h>
 #include <base/DebugObject.h>
 #include <system/BConnection.h>
 #include <flow/PacketStreamSender.h>
@@ -61,6 +62,33 @@
  */
 typedef void (*BSocksClient_handler) (void *user, int event);
 
+B_START_PACKED
+struct BSocksClient__client_hello {
+    struct socks_client_hello_header header;
+    struct socks_client_hello_method method;
+} B_PACKED;
+B_END_PACKED
+
+B_START_PACKED
+struct BSocksClient__request {
+    struct socks_request_header header;
+    union {
+        struct socks_addr_ipv4 ipv4;
+        struct socks_addr_ipv6 ipv6;
+    } addr;
+} B_PACKED;
+B_END_PACKED
+
+B_START_PACKED
+struct BSocksClient__reply {
+    struct socks_reply_header header;
+    union {
+        struct socks_addr_ipv4 ipv4;
+        struct socks_addr_ipv6 ipv6;
+    } addr;
+} B_PACKED;
+B_END_PACKED
+
 typedef struct {
     BAddr dest_addr;
     BSocksClient_handler handler;
@@ -75,25 +103,10 @@ typedef struct {
             PacketStreamSender send_sender;
             StreamRecvInterface *recv_if;
             union {
-                struct {
-                    struct socks_client_hello_header header;
-                    struct socks_client_hello_method method;
-                } __attribute__((packed)) client_hello;
+                struct BSocksClient__client_hello client_hello;
                 struct socks_server_hello server_hello;
-                struct {
-                    struct socks_request_header header;
-                    union {
-                        struct socks_addr_ipv4 ipv4;
-                        struct socks_addr_ipv6 ipv6;
-                    } addr;
-                } __attribute__((packed)) request;
-                struct {
-                    struct socks_reply_header header;
-                    union {
-                        struct socks_addr_ipv4 ipv4;
-                        struct socks_addr_ipv6 ipv6;
-                    } addr;
-                } __attribute__((packed)) reply;
+                struct BSocksClient__request request;
+                struct BSocksClient__reply reply;
             } msg;
             uint8_t *recv_dest;
             int recv_len;

+ 9 - 5
system/BAddr.h

@@ -39,7 +39,6 @@
 #include <stdlib.h>
 #include <string.h>
 #include <stdio.h>
-#include <inttypes.h>
 
 #ifdef BADVPN_USE_WINAPI
 #include <ws2tcpip.h>
@@ -52,6 +51,8 @@
 
 #include <misc/byteorder.h>
 #include <misc/debug.h>
+#include <misc/print_macros.h>
+#include <misc/packed.h>
 
 #define BADDR_TYPE_NONE 0
 #define BADDR_TYPE_IPV4 1
@@ -421,10 +422,12 @@ void BAddr_SetPort (BAddr *addr, uint16_t port)
     }
 }
 
+B_START_PACKED
 struct _BAddr_ipv6_addr
 {
     uint16_t addr[8];
-} __attribute__((packed));
+} B_PACKED;
+B_END_PACKED
 
 void BIPAddr_Print (BIPAddr *addr, char *out)
 {
@@ -574,8 +577,6 @@ void BAddr_Print (BAddr *addr, char *out)
 
 int BAddr_Parse2 (BAddr *addr, char *str, char *name, int name_len, int noresolve)
 {
-    BAddr result;
-    
     int len = strlen(str);
     if (len < 1 || len > 1000) {
         return 0;
@@ -684,7 +685,10 @@ int BAddr_Parse2 (BAddr *addr, char *str, char *name, int name_len, int noresolv
     freeaddrinfo(addrs);
     
     if (name) {
-        snprintf(name, name_len, "%s", addr_str);
+        if (strlen(addr_str) >= name_len) {
+            return 0;
+        }
+        strcpy(name, addr_str);
     }
     
     return 1;

+ 23 - 19
system/BConnection.h

@@ -191,29 +191,33 @@ struct BConnection_source {
     } u;
 };
 
-#define BCONNECTION_SOURCE_LISTENER(_listener, _out_addr) \
-    ((struct BConnection_source){ \
-        .type = BCONNECTION_SOURCE_TYPE_LISTENER, \
-        .u.listener.listener = (_listener), \
-        .u.listener.out_addr = (_out_addr) \
-    })
-
-#define BCONNECTION_SOURCE_CONNECTOR(_connector) \
-    ((struct BConnection_source){ \
-        .type = BCONNECTION_SOURCE_TYPE_CONNECTOR, \
-        .u.connector.connector = (_connector) \
-    })
+static struct BConnection_source BConnection_source_listener (BListener *listener, BAddr *out_addr)
+{
+    struct BConnection_source s;
+    s.type = BCONNECTION_SOURCE_TYPE_LISTENER;
+    s.u.listener.listener = listener;
+    s.u.listener.out_addr = out_addr;
+    return s;
+}
+
+static struct BConnection_source BConnection_source_connector (BConnector *connector)
+{
+    struct BConnection_source s;
+    s.type = BCONNECTION_SOURCE_TYPE_CONNECTOR;
+    s.u.connector.connector = connector;
+    return s;
+}
 
 #ifndef BADVPN_USE_WINAPI
-#define BCONNECTION_SOURCE_PIPE(_pipefd) \
-    ((struct BConnection_source){ \
-        .type = BCONNECTION_SOURCE_TYPE_PIPE, \
-        .u.pipe.pipefd = (_pipefd) \
-    })
+static struct BConnection_source BConnection_source_pipe (int pipefd)
+{
+    struct BConnection_source s;
+    s.type = BCONNECTION_SOURCE_TYPE_PIPE;
+    s.u.pipe.pipefd;
+    return s;
+}
 #endif
 
-
-
 struct BConnection_s;
 
 /**

+ 9 - 9
system/BConnection_win.c

@@ -103,7 +103,8 @@ static void addr_any_to_sys (struct sys_addr *out, int family)
             out->addr.ipv6.sin6_family = AF_INET6;
             out->addr.ipv6.sin6_port = 0;
             out->addr.ipv6.sin6_flowinfo = 0;
-            out->addr.ipv6.sin6_addr = (struct in6_addr)IN6ADDR_ANY_INIT;
+            struct in6_addr any = IN6ADDR_ANY_INIT;
+            out->addr.ipv6.sin6_addr = any;
             out->addr.ipv6.sin6_scope_id = 0;
         } break;
         
@@ -317,7 +318,7 @@ static void connection_send_iface_handler_send (BConnection *o, uint8_t *data, i
     }
     
     WSABUF buf;
-    buf.buf = data;
+    buf.buf = (char *)data;
     buf.len = data_len;
     
     memset(&o->send.olap.olap, 0, sizeof(o->send.olap.olap));
@@ -350,7 +351,7 @@ static void connection_recv_iface_handler_recv (BConnection *o, uint8_t *data, i
     }
     
     WSABUF buf;
-    buf.buf = data;
+    buf.buf = (char *)data;
     buf.len = data_len;
     
     memset(&o->recv.olap.olap, 0, sizeof(o->recv.olap.olap));
@@ -484,19 +485,18 @@ int BListener_Init (BListener *o, BAddr addr, BReactor *reactor, void *user,
         goto fail1;
     }
     
-    GUID guid;
     DWORD out_bytes;
     
     // obtain AcceptEx
-    guid = (GUID)WSAID_ACCEPTEX;
-    if (WSAIoctl(o->sock, SIO_GET_EXTENSION_FUNCTION_POINTER, &guid, sizeof(guid), &o->fnAcceptEx, sizeof(o->fnAcceptEx), &out_bytes, NULL, NULL) != 0) {
+    GUID guid1 = WSAID_ACCEPTEX;
+    if (WSAIoctl(o->sock, SIO_GET_EXTENSION_FUNCTION_POINTER, &guid1, sizeof(guid1), &o->fnAcceptEx, sizeof(o->fnAcceptEx), &out_bytes, NULL, NULL) != 0) {
         BLog(BLOG_ERROR, "faild to obtain AcceptEx");
         goto fail1;
     }
     
     // obtain GetAcceptExSockaddrs
-    guid = (GUID)WSAID_GETACCEPTEXSOCKADDRS;
-    if (WSAIoctl(o->sock, SIO_GET_EXTENSION_FUNCTION_POINTER, &guid, sizeof(guid), &o->fnGetAcceptExSockaddrs, sizeof(o->fnGetAcceptExSockaddrs), &out_bytes, NULL, NULL) != 0) {
+    GUID guid2 = WSAID_GETACCEPTEXSOCKADDRS;
+    if (WSAIoctl(o->sock, SIO_GET_EXTENSION_FUNCTION_POINTER, &guid2, sizeof(guid2), &o->fnGetAcceptExSockaddrs, sizeof(o->fnGetAcceptExSockaddrs), &out_bytes, NULL, NULL) != 0) {
         BLog(BLOG_ERROR, "faild to obtain GetAcceptExSockaddrs");
         goto fail1;
     }
@@ -781,7 +781,7 @@ int BConnection_SetSendBuffer (BConnection *o, int buf_size)
 {
     DebugObject_Access(&o->d_obj);
     
-    if (setsockopt(o->sock, SOL_SOCKET, SO_SNDBUF, (void *)&buf_size, sizeof(buf_size)) < 0) {
+    if (setsockopt(o->sock, SOL_SOCKET, SO_SNDBUF, (char *)&buf_size, sizeof(buf_size)) < 0) {
         BLog(BLOG_ERROR, "setsockopt failed");
         return 0;
     }

+ 6 - 7
system/BDatagram_win.c

@@ -184,7 +184,7 @@ static void start_send (BDatagram *o)
     addr_socket_to_sys(&o->send.sysaddr, o->send.remote_addr);
     
     WSABUF buf;
-    buf.buf = o->send.data;
+    buf.buf = (char *)o->send.data;
     buf.len = (o->send.data_len > ULONG_MAX ? ULONG_MAX : o->send.data_len);
     
     memset(&o->send.olap.olap, 0, sizeof(o->send.olap.olap));
@@ -260,7 +260,7 @@ static void start_recv (BDatagram *o)
     ASSERT(o->recv.started)
     
     WSABUF buf;
-    buf.buf = o->recv.data;
+    buf.buf = (char *)o->recv.data;
     buf.len = (o->recv.mtu > ULONG_MAX ? ULONG_MAX : o->recv.mtu);
     
     memset(&o->recv.olap.olap, 0, sizeof(o->recv.olap.olap));
@@ -499,18 +499,17 @@ int BDatagram_Init (BDatagram *o, int family, BReactor *reactor, void *user,
         goto fail0;
     }
     
-    GUID guid;
     DWORD out_bytes;
     
     // obtain WSASendMsg
-    guid = (GUID)WSAID_WSASENDMSG;
-    if (WSAIoctl(o->sock, SIO_GET_EXTENSION_FUNCTION_POINTER, &guid, sizeof(guid), &o->fnWSASendMsg, sizeof(o->fnWSASendMsg), &out_bytes, NULL, NULL) != 0) {
+    GUID guid1 = WSAID_WSASENDMSG;
+    if (WSAIoctl(o->sock, SIO_GET_EXTENSION_FUNCTION_POINTER, &guid1, sizeof(guid1), &o->fnWSASendMsg, sizeof(o->fnWSASendMsg), &out_bytes, NULL, NULL) != 0) {
         o->fnWSASendMsg = NULL;
     }
     
     // obtain WSARecvMsg
-    guid = (GUID)WSAID_WSARECVMSG;
-    if (WSAIoctl(o->sock, SIO_GET_EXTENSION_FUNCTION_POINTER, &guid, sizeof(guid), &o->fnWSARecvMsg, sizeof(o->fnWSARecvMsg), &out_bytes, NULL, NULL) != 0) {
+    GUID guid2 = WSAID_WSARECVMSG;
+    if (WSAIoctl(o->sock, SIO_GET_EXTENSION_FUNCTION_POINTER, &guid2, sizeof(guid2), &o->fnWSARecvMsg, sizeof(o->fnWSARecvMsg), &out_bytes, NULL, NULL) != 0) {
         BLog(BLOG_ERROR, "failed to obtain WSARecvMsg");
         o->fnWSARecvMsg = NULL;
     }

+ 1 - 1
system/BInputProcess.c

@@ -105,7 +105,7 @@ int BInputProcess_Init (BInputProcess *o, BReactor *reactor, BProcessManager *ma
     }
     
     // init pipe connection
-    if (!BConnection_Init(&o->pipe_con, BCONNECTION_SOURCE_PIPE(pipefds[0]), o->reactor, o, (BConnection_handler)connection_handler)) {
+    if (!BConnection_Init(&o->pipe_con, BConnection_source_pipe(pipefds[0]), o->reactor, o, (BConnection_handler)connection_handler)) {
         BLog(BLOG_ERROR, "BConnection_Init failed");
         goto fail1;
     }

+ 1 - 1
system/BSignal.c

@@ -55,7 +55,7 @@ struct {
     BUnixSignal signal;
     #endif
 } bsignal_global = {
-    .initialized = 0,
+    0
 };
 
 #ifdef BADVPN_USE_WINAPI

+ 1 - 1
system/BTime.c

@@ -31,6 +31,6 @@
 
 struct _BTime_global btime_global = {
     #ifndef NDEBUG
-    .initialized = 0,
+    0
     #endif
 };

+ 2 - 2
tests/bproto_test.c

@@ -1,5 +1,5 @@
 #include <string.h>
-#include <inttypes.h>
+#include <stdint.h>
 #include <stdio.h>
 
 #include <misc/debug.h>
@@ -21,7 +21,7 @@ int main ()
     
     int len = msg1_SIZEa + msg1_SIZEc + msg1_SIZEd + msg1_SIZEd + msg1_SIZEe + msg1_SIZEf(strlen(f)) + msg1_SIZEg;
     
-    uint8_t *msg = BAlloc(len);
+    uint8_t *msg = (uint8_t *)BAlloc(len);
     ASSERT_FORCE(msg)
     msg1Writer writer;
     msg1Writer_Init(&writer, msg);

+ 6 - 8
tun2socks/tun2socks.c

@@ -337,7 +337,7 @@ int main (int argc, char **argv)
     BPending_Set(&lwip_init_job);
     
     // init device write buffer
-    if (!(device_write_buf = BAlloc(BTap_GetMTU(&device)))) {
+    if (!(device_write_buf = (uint8_t *)BAlloc(BTap_GetMTU(&device)))) {
         BLog(BLOG_ERROR, "BAlloc failed");
         goto fail5;
     }
@@ -703,8 +703,6 @@ void lwip_init_job_hadler (void *unused)
     // NOTE: the device may fail during this, but there's no harm in not checking
     // for that at every step
     
-    int res;
-    
     // init lwip
     lwip_init();
     
@@ -917,7 +915,7 @@ err_t netif_output_func (struct netif *netif, struct pbuf *p, ip_addr_t *ipaddr)
         }
         
         SYNC_FROMHERE
-        BTap_Send(&device, p->payload, p->len);
+        BTap_Send(&device, (uint8_t *)p->payload, p->len);
         SYNC_COMMIT
     } else {
         int len = 0;
@@ -966,7 +964,7 @@ err_t listener_accept_func (void *arg, struct tcp_pcb *newpcb, err_t err)
     tcp_accepted(listener);
     
     // allocate client structure
-    struct tcp_client *client = malloc(sizeof(*client));
+    struct tcp_client *client = (struct tcp_client *)malloc(sizeof(*client));
     if (!client) {
         BLog(BLOG_ERROR, "listener accept: malloc failed");
         return ERR_MEM;
@@ -1183,7 +1181,7 @@ void client_dealloc (struct tcp_client *client)
 
 void client_err_func (void *arg, err_t err)
 {
-    struct tcp_client *client = arg;
+    struct tcp_client *client = (struct tcp_client *)arg;
     ASSERT(!client->client_closed)
     
     client_log(client, BLOG_INFO, "client error (%d)", (int)err);
@@ -1194,7 +1192,7 @@ void client_err_func (void *arg, err_t err)
 
 err_t client_recv_func (void *arg, struct tcp_pcb *tpcb, struct pbuf *p, err_t err)
 {
-    struct tcp_client *client = arg;
+    struct tcp_client *client = (struct tcp_client *)arg;
     ASSERT(!client->client_closed)
     ASSERT(err == ERR_OK) // checked in lwIP source. Otherwise, I've no idea what should
                           // be done with the pbuf in case of an error.
@@ -1436,7 +1434,7 @@ int client_socks_recv_send_out (struct tcp_client *client)
 
 err_t client_sent_func (void *arg, struct tcp_pcb *tpcb, u16_t len)
 {
-    struct tcp_client *client = arg;
+    struct tcp_client *client = (struct tcp_client *)arg;
     
     ASSERT(!client->client_closed)
     ASSERT(client->socks_up)

+ 20 - 16
tuntap/BTap.c

@@ -198,24 +198,22 @@ int BTap_Init (BTap *o, BReactor *reactor, char *devname, BTap_handler_error han
     
     if (!devname) {
         BLog(BLOG_ERROR, "no device specification provided");
-        return 0;
+        goto fail0;
     }
     
-    int devname_len = strlen(devname);
-    
-    char device_component_id[devname_len + 1];
-    char device_name[devname_len + 1];
+    char *device_component_id;
+    char *device_name;
     uint32_t tun_addrs[3];
     
     if (tun) {
-        if (!tapwin32_parse_tun_spec(devname, device_component_id, device_name, tun_addrs)) {
+        if (!tapwin32_parse_tun_spec(devname, &device_component_id, &device_name, tun_addrs)) {
             BLog(BLOG_ERROR, "failed to parse TUN device specification");
-            return 0;
+            goto fail0;
         }
     } else {
-        if (!tapwin32_parse_tap_spec(devname, device_component_id, device_name)) {
+        if (!tapwin32_parse_tap_spec(devname, &device_component_id, &device_name)) {
             BLog(BLOG_ERROR, "failed to parse TAP device specification");
-            return 0;
+            goto fail0;
         }
     }
     
@@ -227,7 +225,7 @@ int BTap_Init (BTap *o, BReactor *reactor, char *devname, BTap_handler_error han
     
     if (!tapwin32_find_device(device_component_id, device_name, &device_path)) {
         BLog(BLOG_ERROR, "Could not find device");
-        goto fail0;
+        goto fail1;
     }
     
     // open device
@@ -237,7 +235,7 @@ int BTap_Init (BTap *o, BReactor *reactor, char *devname, BTap_handler_error han
     o->device = CreateFile(device_path, GENERIC_READ | GENERIC_WRITE, 0, 0, OPEN_EXISTING, FILE_ATTRIBUTE_SYSTEM|FILE_FLAG_OVERLAPPED, 0);
     if (o->device == INVALID_HANDLE_VALUE) {
         BLog(BLOG_ERROR, "CreateFile failed");
-        goto fail0;
+        goto fail1;
     }
     
     // set TUN if needed
@@ -247,7 +245,7 @@ int BTap_Init (BTap *o, BReactor *reactor, char *devname, BTap_handler_error han
     if (tun) {
         if (!DeviceIoControl(o->device, TAP_IOCTL_CONFIG_TUN, tun_addrs, sizeof(tun_addrs), tun_addrs, sizeof(tun_addrs), &len, NULL)) {
             BLog(BLOG_ERROR, "DeviceIoControl(TAP_IOCTL_CONFIG_TUN) failed");
-            goto fail1;
+            goto fail2;
         }
     }
     
@@ -257,7 +255,7 @@ int BTap_Init (BTap *o, BReactor *reactor, char *devname, BTap_handler_error han
     
     if (!DeviceIoControl(o->device, TAP_IOCTL_GET_MTU, NULL, 0, &umtu, sizeof(umtu), &len, NULL)) {
         BLog(BLOG_ERROR, "DeviceIoControl(TAP_IOCTL_GET_MTU) failed");
-        goto fail1;
+        goto fail2;
     }
     
     if (tun) {
@@ -271,7 +269,7 @@ int BTap_Init (BTap *o, BReactor *reactor, char *devname, BTap_handler_error han
     ULONG upstatus = TRUE;
     if (!DeviceIoControl(o->device, TAP_IOCTL_SET_MEDIA_STATUS, &upstatus, sizeof(upstatus), &upstatus, sizeof(upstatus), &len, NULL)) {
         BLog(BLOG_ERROR, "DeviceIoControl(TAP_IOCTL_SET_MEDIA_STATUS) failed");
-        goto fail1;
+        goto fail2;
     }
     
     BLog(BLOG_INFO, "Device opened");
@@ -280,7 +278,7 @@ int BTap_Init (BTap *o, BReactor *reactor, char *devname, BTap_handler_error han
     
     if (!CreateIoCompletionPort(o->device, BReactor_GetIOCPHandle(o->reactor), 0, 0)) {
         BLog(BLOG_ERROR, "CreateIoCompletionPort failed");
-        goto fail1;
+        goto fail2;
     }
     
     // init send olap
@@ -289,10 +287,16 @@ int BTap_Init (BTap *o, BReactor *reactor, char *devname, BTap_handler_error han
     // init recv olap
     BReactorIOCPOverlapped_Init(&o->recv_olap, o->reactor, o, (BReactorIOCPOverlapped_handler)recv_olap_handler);
     
+    free(device_name);
+    free(device_component_id);
+    
     goto success;
     
-fail1:
+fail2:
     ASSERT_FORCE(CloseHandle(o->device))
+fail1:
+    free(device_name);
+    free(device_component_id);
 fail0:
     return 0;
     

+ 64 - 55
tuntap/tapwin32-funcs.c

@@ -33,97 +33,96 @@
 #include <string.h>
 
 #include <misc/debug.h>
+#include <misc/ipaddr.h>
+#include <misc/maxalign.h>
+#include <misc/strdup.h>
 
 #include "wintap-common.h"
 
 #include <tuntap/tapwin32-funcs.h>
 
-static int split_spec (char *name, char *sep, char *out_fields[], int num_fields)
+static int split_spec (char *name, char *sep, char **out_fields[], int num_fields)
 {
     ASSERT(num_fields > 0)
     ASSERT(strlen(sep) > 0)
     
     size_t seplen = strlen(sep);
     
-    int i;
-    for (i = 0; i < num_fields - 1; i++) {
+    int i = 0;
+    while (i < num_fields - 1) {
         char *s = strstr(name, sep);
         if (!s) {
             DEBUG("missing separator number %d", (i + 1));
-            return 0;
+            goto fail;
         }
         
-        int flen = s - name;
-        memcpy(out_fields[i], name, flen);
-        out_fields[i][flen] = '\0';
+        if (!(*out_fields[i] = b_strdup_bin(name, s - name))) {
+            DEBUG("b_strdup_bin failed");
+            goto fail;
+        }
         
         name = s + seplen;
+        i++;
     }
     
-    int flen = strlen(name);
-    memcpy(out_fields[i], name, flen);
-    out_fields[i][flen] = '\0';
-    
-    return 1;
-}
-
-static int parse_ipv4_addr (char *name, uint8_t out_addr[4])
-{
-    if (strlen(name) > 15) {
-        return 0;
+    if (!(*out_fields[i] = b_strdup(name))) {
+        DEBUG("b_strdup_bin failed");
+        goto fail;
     }
     
-    char (nums[4])[16];
-    
-    char *out_fields[] = { nums[0], nums[1], nums[2], nums[3] };
+    return 1;
     
-    if (!split_spec(name, ".", out_fields, 4)) {
-        return 0;
+fail:
+    while (i-- > 0) {
+        free(*out_fields[i]);
     }
-    
-    for (int i = 0; i < 4; i++) {
-        if (strlen(nums[i]) > 3) {
-            return 0;
-        }
-        
-        int num = atoi(nums[i]);
-        
-        if (!(num >= 0 && num < 256)) {
-            return 0;
-        }
-        
-        out_addr[i] = num;
-    }
-    
-    return 1;
+    return 0;
 }
 
-int tapwin32_parse_tap_spec (char *name, char *out_component_id, char *out_human_name)
+int tapwin32_parse_tap_spec (char *name, char **out_component_id, char **out_human_name)
 {
-    char *out_fields[] = { out_component_id, out_human_name };
+    char **out_fields[2];
+    out_fields[0] = out_component_id;
+    out_fields[1] = out_human_name;
     
     return split_spec(name, ":", out_fields, 2);
 }
 
-int tapwin32_parse_tun_spec (char *name, char *out_component_id, char *out_human_name, uint32_t out_addrs[3])
+int tapwin32_parse_tun_spec (char *name, char **out_component_id, char **out_human_name, uint32_t out_addrs[3])
 {
-    int namelen = strlen(name);
+    char *addr_strs[3];
     
-    char (addr_strs[3])[namelen + 1];
-    
-    char *out_fields[] = { out_component_id, out_human_name, addr_strs[0], addr_strs[1], addr_strs[2] };
+    char **out_fields[5];
+    out_fields[0] = out_component_id;
+    out_fields[1] = out_human_name;
+    out_fields[2] = &addr_strs[0];
+    out_fields[3] = &addr_strs[1];
+    out_fields[4] = &addr_strs[2];
     
     if (!split_spec(name, ":", out_fields, 5)) {
-        return 0;
+        goto fail0;
     }
     
     for (int i = 0; i < 3; i++) {
-        if (!parse_ipv4_addr(addr_strs[i], (uint8_t *)(out_addrs + i))) {
-            return 0;
+        if (!ipaddr_parse_ipv4_addr(addr_strs[i], &out_addrs[i])) {
+            goto fail1;
         }
     }
     
+    free(addr_strs[0]);
+    free(addr_strs[1]);
+    free(addr_strs[2]);
+    
     return 1;
+    
+fail1:
+    free(*out_component_id);
+    free(*out_human_name);
+    free(addr_strs[0]);
+    free(addr_strs[1]);
+    free(addr_strs[2]);
+fail0:
+    return 0;
 }
 
 int tapwin32_find_device (char *device_component_id, char *device_name, char (*device_path)[TAPWIN32_MAX_REG_SIZE])
@@ -138,6 +137,7 @@ int tapwin32_find_device (char *device_component_id, char *device_name, char (*d
     
     char net_cfg_instance_id[TAPWIN32_MAX_REG_SIZE];
     int found = 0;
+    int pres;
     
     DWORD i;
     for (i = 0;; i++) {
@@ -151,7 +151,10 @@ int tapwin32_find_device (char *device_component_id, char *device_name, char (*d
         }
         
         char unit_string[TAPWIN32_MAX_REG_SIZE];
-        snprintf(unit_string, sizeof(unit_string), "%s\\%s", ADAPTER_KEY, key_name);
+        pres = _snprintf(unit_string, sizeof(unit_string), "%s\\%s", ADAPTER_KEY, key_name);
+        if (pres < 0 || pres == sizeof(unit_string)) {
+            continue;
+        }
         HKEY unit_key;
         if (RegOpenKeyEx(HKEY_LOCAL_MACHINE, unit_string, 0, KEY_READ, &unit_key) != ERROR_SUCCESS) {
             continue;
@@ -159,13 +162,13 @@ int tapwin32_find_device (char *device_component_id, char *device_name, char (*d
         
         char component_id[TAPWIN32_MAX_REG_SIZE];
         len = sizeof(component_id);
-        if (RegQueryValueEx(unit_key, "ComponentId", NULL, &type, component_id, &len) != ERROR_SUCCESS || type != REG_SZ) {
+        if (RegQueryValueEx(unit_key, "ComponentId", NULL, &type, (LPBYTE)component_id, &len) != ERROR_SUCCESS || type != REG_SZ) {
             ASSERT_FORCE(RegCloseKey(unit_key) == ERROR_SUCCESS)
             continue;
         }
         
         len = sizeof(net_cfg_instance_id);
-        if (RegQueryValueEx(unit_key, "NetCfgInstanceId", NULL, &type, net_cfg_instance_id, &len) != ERROR_SUCCESS || type != REG_SZ) {
+        if (RegQueryValueEx(unit_key, "NetCfgInstanceId", NULL, &type, (LPBYTE)net_cfg_instance_id, &len) != ERROR_SUCCESS || type != REG_SZ) {
             ASSERT_FORCE(RegCloseKey(unit_key) == ERROR_SUCCESS)
             continue;
         }
@@ -182,7 +185,10 @@ int tapwin32_find_device (char *device_component_id, char *device_name, char (*d
             
             // open connection key
             char conn_string[TAPWIN32_MAX_REG_SIZE];
-            snprintf(conn_string, sizeof(conn_string), "%s\\%s\\Connection", NETWORK_CONNECTIONS_KEY, net_cfg_instance_id);
+            pres = _snprintf(conn_string, sizeof(conn_string), "%s\\%s\\Connection", NETWORK_CONNECTIONS_KEY, net_cfg_instance_id);
+            if (pres < 0 || pres == sizeof(conn_string)) {
+                continue;
+            }
             HKEY conn_key;
             if (RegOpenKeyEx(HKEY_LOCAL_MACHINE, conn_string, 0, KEY_READ, &conn_key) != ERROR_SUCCESS) {
                 continue;
@@ -191,7 +197,7 @@ int tapwin32_find_device (char *device_component_id, char *device_name, char (*d
             // read name
             char name[TAPWIN32_MAX_REG_SIZE];
             len = sizeof(name);
-            if (RegQueryValueEx(conn_key, "Name", NULL, &type, name, &len) != ERROR_SUCCESS || type != REG_SZ) {
+            if (RegQueryValueEx(conn_key, "Name", NULL, &type, (LPBYTE)name, &len) != ERROR_SUCCESS || type != REG_SZ) {
                 ASSERT_FORCE(RegCloseKey(conn_key) == ERROR_SUCCESS)
                 continue;
             }
@@ -212,7 +218,10 @@ int tapwin32_find_device (char *device_component_id, char *device_name, char (*d
         return 0;
     }
     
-    snprintf(*device_path, sizeof(*device_path), "\\\\.\\Global\\%s.tap", net_cfg_instance_id);
+    pres = _snprintf(*device_path, sizeof(*device_path), "\\\\.\\Global\\%s.tap", net_cfg_instance_id);
+    if (pres < 0 || pres == sizeof(*device_path)) {
+        return 0;
+    }
     
     return 1;
 }

+ 2 - 2
tuntap/tapwin32-funcs.h

@@ -35,8 +35,8 @@
 
 #define TAPWIN32_MAX_REG_SIZE 256
 
-int tapwin32_parse_tap_spec (char *name, char *out_component_id, char *out_human_name);
-int tapwin32_parse_tun_spec (char *name, char *out_component_id, char *out_human_name, uint32_t out_addrs[3]);
+int tapwin32_parse_tap_spec (char *name, char **out_component_id, char **out_human_name);
+int tapwin32_parse_tun_spec (char *name, char **out_component_id, char **out_human_name, uint32_t out_addrs[3]);
 int tapwin32_find_device (char *device_component_id, char *device_name, char (*device_path)[TAPWIN32_MAX_REG_SIZE]);
 
 #endif

+ 5 - 5
udpgw/udpgw.c

@@ -27,7 +27,6 @@
  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
-#include <inttypes.h>
 #include <stdio.h>
 #include <string.h>
 #include <stdarg.h>
@@ -44,6 +43,7 @@
 #include <misc/open_standard_streams.h>
 #include <misc/balloc.h>
 #include <misc/compare.h>
+#include <misc/print_macros.h>
 #include <structure/LinkedList1.h>
 #include <structure/BAVL.h>
 #include <base/BLog.h>
@@ -586,14 +586,14 @@ void listener_handler (BListener *listener)
     }
     
     // allocate structure
-    struct client *client = malloc(sizeof(*client));
+    struct client *client = (struct client *)malloc(sizeof(*client));
     if (!client) {
         BLog(BLOG_ERROR, "malloc failed");
         goto fail0;
     }
     
     // accept client
-    if (!BConnection_Init(&client->con, BCONNECTION_SOURCE_LISTENER(listener, &client->addr), &ss, client, (BConnection_handler)client_connection_handler)) {
+    if (!BConnection_Init(&client->con, BConnection_source_listener(listener, &client->addr), &ss, client, (BConnection_handler)client_connection_handler)) {
         BLog(BLOG_ERROR, "BConnection_Init failed");
         goto fail1;
     }
@@ -832,7 +832,7 @@ uint8_t * build_port_usage_array_and_find_least_used_connection (BAddr remote_ad
     ASSERT(remote_addr.type == BADDR_TYPE_IPV4)
     
     // allocate port usage array
-    uint8_t *port_usage = BAllocSize(bsize_fromint(options.local_udp_num_ports));
+    uint8_t *port_usage = (uint8_t *)BAllocSize(bsize_fromint(options.local_udp_num_ports));
     if (!port_usage) {
         return NULL;
     }
@@ -890,7 +890,7 @@ void connection_init (struct client *client, uint16_t conid, BAddr addr, const u
     ASSERT(data_len <= options.udp_mtu)
     
     // allocate structure
-    struct connection *con = malloc(sizeof(*con));
+    struct connection *con = (struct connection *)malloc(sizeof(*con));
     if (!con) {
         client_log(client, BLOG_ERROR, "malloc failed");
         goto fail0;

+ 1 - 1
udpgw_client/UdpGwClient.c

@@ -235,7 +235,7 @@ static void connection_init (UdpGwClient *o, struct UdpGwClient_conaddr conaddr,
     ASSERT(data_len <= o->udp_mtu)
     
     // allocate structure
-    struct UdpGwClient_connection *con = malloc(sizeof(*con));
+    struct UdpGwClient_connection *con = (struct UdpGwClient_connection *)malloc(sizeof(*con));
     if (!con) {
         BLog(BLOG_ERROR, "malloc failed");
         goto fail0;

+ 9 - 4
udpgw_client/UdpGwClient.h

@@ -34,6 +34,7 @@
 
 #include <protocol/udpgw_proto.h>
 #include <misc/debug.h>
+#include <misc/packed.h>
 #include <structure/BAVL.h>
 #include <structure/LinkedList1.h>
 #include <base/DebugObject.h>
@@ -49,6 +50,13 @@
 typedef void (*UdpGwClient_handler_servererror) (void *user);
 typedef void (*UdpGwClient_handler_received) (void *user, BAddr local_addr, BAddr remote_addr, const uint8_t *data, int data_len);
 
+B_START_PACKED
+struct UdpGwClient__keepalive_packet {
+    struct packetproto_header pp;
+    struct udpgw_header udpgw;
+} B_PACKED;
+B_END_PACKED
+
 typedef struct {
     int udp_mtu;
     int max_connections;
@@ -68,10 +76,7 @@ typedef struct {
     PacketPassFairQueue send_queue;
     PacketPassInactivityMonitor send_monitor;
     PacketPassConnector send_connector;
-    struct {
-        struct packetproto_header pp;
-        struct udpgw_header udpgw;
-    } __attribute__((packed)) keepalive_packet;
+    struct UdpGwClient__keepalive_packet keepalive_packet;
     PacketPassInterface *keepalive_if;
     PacketPassFairQueueFlow keepalive_qflow;
     int keepalive_sending;