From 2b92b57bedbfc5bada5a530ef8cea2e2422e7590 Mon Sep 17 00:00:00 2001 From: Max Lv Date: Thu, 27 Feb 2014 08:11:16 +0800 Subject: [PATCH] fix the ambiguous type defination --- src/include.h | 2 +- src/jconf.c | 4 ++-- src/jconf.h | 8 ++++---- src/json.c | 22 +++++++++++----------- src/local.c | 24 ++++++++++++------------ src/local.h | 2 +- src/tunnel.c | 28 ++++++++++++++-------------- src/tunnel.h | 4 ++-- src/udprelay.c | 2 +- src/udprelay.h | 2 +- 10 files changed, 49 insertions(+), 49 deletions(-) diff --git a/src/include.h b/src/include.h index 9c8ed5c7..bd6ddfa4 100644 --- a/src/include.h +++ b/src/include.h @@ -5,7 +5,7 @@ int udprelay_init(const char *server_host, const char *server_port, #ifdef UDPRELAY_LOCAL const char *remote_host, const char *remote_port, #ifdef UDPRELAY_TUNNEL - const addr_t tunnel_addr, + const ss_addr_t tunnel_addr, #endif #endif #ifdef UDPRELAY_REMOTE diff --git a/src/jconf.c b/src/jconf.c index dbe5352e..44bb482d 100644 --- a/src/jconf.c +++ b/src/jconf.c @@ -35,7 +35,7 @@ static char *to_string(const json_value *value) return 0; } -void free_addr(addr_t *addr) +void free_addr(ss_addr_t *addr) { free(addr->host); free(addr->port); @@ -43,7 +43,7 @@ void free_addr(addr_t *addr) addr->port = NULL; } -void parse_addr(const char *str, addr_t *addr) +void parse_addr(const char *str, ss_addr_t *addr) { int ret = -1, n = 0; char *pch; diff --git a/src/jconf.h b/src/jconf.h index 2bfc8c78..189f08dc 100644 --- a/src/jconf.h +++ b/src/jconf.h @@ -10,12 +10,12 @@ typedef struct { char *host; char *port; -} addr_t; +} ss_addr_t; typedef struct { int remote_num; - addr_t remote_addr[MAX_REMOTE_NUM]; + ss_addr_t remote_addr[MAX_REMOTE_NUM]; char *remote_port; char *local_addr; char *local_port; @@ -25,7 +25,7 @@ typedef struct } jconf_t; jconf_t *read_jconf(const char* file); -void parse_addr(const char *str, addr_t *addr); -void free_addr(addr_t *addr); +void parse_addr(const char *str, ss_addr_t *addr); +void free_addr(ss_addr_t *addr); #endif // _JCONF_H diff --git a/src/json.c b/src/json.c index 8ce02059..5ab52c5b 100644 --- a/src/json.c +++ b/src/json.c @@ -50,7 +50,7 @@ typedef unsigned short json_uchar; static unsigned char hex_value (json_char c) { - if (isdigit(c)) + if (isdigit((uint8_t)c)) return c - '0'; switch (c) { @@ -193,7 +193,7 @@ static const long flag_next = 1 << 0, flag_reproc = 1 << 1, flag_need_comma = 1 << 2, - flag_seek_value = 1 << 3, + flag_seek_value = 1 << 3, flag_escaped = 1 << 4, flag_string = 1 << 5, flag_need_colon = 1 << 6, @@ -263,7 +263,7 @@ json_value * json_parse_ex (json_settings * settings, for (i = json ;; ++ i) { json_char b = (i == end ? 0 : *i); - + if (flags & flag_string) { if (!b) @@ -287,7 +287,7 @@ json_value * json_parse_ex (json_settings * settings, case 't': string_add ('\t'); break; case 'u': - if (end - i < 4 || + if (end - i < 4 || (uc_b1 = hex_value (*++ i)) == 0xFF || (uc_b2 = hex_value (*++ i)) == 0xFF || (uc_b3 = hex_value (*++ i)) == 0xFF || (uc_b4 = hex_value (*++ i)) == 0xFF) { @@ -363,7 +363,7 @@ json_value * json_parse_ex (json_settings * settings, if (state.first_pass) (*(json_char **) &top->u.object.values) += string_length + 1; else - { + { top->u.object.values [top->u.object.length].name = (json_char *) top->_reserved.object_mem; @@ -576,14 +576,14 @@ json_value * json_parse_ex (json_settings * settings, default: - if (isdigit (b) || b == '-') + if (isdigit ((uint8_t)b) || b == '-') { if (!new_value (&state, &top, &root, &alloc, json_integer)) goto e_alloc_failure; if (!state.first_pass) { - while (isdigit (b) || b == '+' || b == '-' + while (isdigit ((uint8_t)b) || b == '+' || b == '-' || b == 'e' || b == 'E' || b == '.') { if ( (++ i) == end) @@ -628,7 +628,7 @@ json_value * json_parse_ex (json_settings * settings, switch (top->type) { case json_object: - + switch (b) { whitespace: @@ -648,7 +648,7 @@ json_value * json_parse_ex (json_settings * settings, string_length = 0; break; - + case '}': flags = (flags & ~ flag_need_comma) | flag_next; @@ -673,7 +673,7 @@ json_value * json_parse_ex (json_settings * settings, case json_integer: case json_double: - if (isdigit (b)) + if (isdigit ((uint8_t)b)) { ++ num_digits; @@ -804,7 +804,7 @@ json_value * json_parse_ex (json_settings * settings, if (top->parent->type == json_array) flags |= flag_seek_value; - + if (!state.first_pass) { json_value * parent = top->parent; diff --git a/src/local.c b/src/local.c index b08612da..fff3f2af 100644 --- a/src/local.c +++ b/src/local.c @@ -251,16 +251,16 @@ static void server_recv_cb (EV_P_ ev_io *w, int revents) } else { - char *addr_to_send = malloc(BUF_SIZE); + char *ss_addr_to_send = malloc(BUF_SIZE); ssize_t addr_len = 0; - addr_to_send[addr_len++] = request->atyp; + ss_addr_to_send[addr_len++] = request->atyp; // get remote addr and port if (request->atyp == 1) { // IP V4 size_t in_addr_len = sizeof(struct in_addr); - memcpy(addr_to_send + addr_len, remote->buf + 4, in_addr_len + 2); + memcpy(ss_addr_to_send + addr_len, remote->buf + 4, in_addr_len + 2); addr_len += in_addr_len + 2; if (verbose) @@ -277,8 +277,8 @@ static void server_recv_cb (EV_P_ ev_io *w, int revents) { // Domain name uint8_t name_len = *(uint8_t *)(remote->buf + 4); - addr_to_send[addr_len++] = name_len; - memcpy(addr_to_send + addr_len, remote->buf + 4 + 1, name_len + 2); + ss_addr_to_send[addr_len++] = name_len; + memcpy(ss_addr_to_send + addr_len, remote->buf + 4 + 1, name_len + 2); addr_len += name_len + 2; if (verbose) @@ -295,7 +295,7 @@ static void server_recv_cb (EV_P_ ev_io *w, int revents) { // IP V6 size_t in6_addr_len = sizeof(struct in6_addr); - memcpy(addr_to_send + addr_len, remote->buf + 4, in6_addr_len + 2); + memcpy(ss_addr_to_send + addr_len, remote->buf + 4, in6_addr_len + 2); addr_len += in6_addr_len + 2; if (verbose) @@ -316,16 +316,16 @@ static void server_recv_cb (EV_P_ ev_io *w, int revents) return; } - addr_to_send = ss_encrypt(BUF_SIZE, addr_to_send, &addr_len, server->e_ctx); - if (addr_to_send == NULL) + ss_addr_to_send = ss_encrypt(BUF_SIZE, ss_addr_to_send, &addr_len, server->e_ctx); + if (ss_addr_to_send == NULL) { LOGE("invalid password or cipher"); close_and_free_remote(EV_A_ remote); close_and_free_server(EV_A_ server); return; } - int s = send(remote->fd, addr_to_send, addr_len, 0); - free(addr_to_send); + int s = send(remote->fd, ss_addr_to_send, addr_len, 0); + free(ss_addr_to_send); if (s < addr_len) { @@ -807,7 +807,7 @@ int main (int argc, char **argv) char *iface = NULL; int remote_num = 0; - addr_t remote_addr[MAX_REMOTE_NUM]; + ss_addr_t remote_addr[MAX_REMOTE_NUM]; char *remote_port = NULL; opterr = 0; @@ -928,7 +928,7 @@ int main (int argc, char **argv) // Setup proxy context struct listen_ctx listen_ctx; listen_ctx.remote_num = remote_num; - listen_ctx.remote_addr = malloc(sizeof(addr_t) * remote_num); + listen_ctx.remote_addr = malloc(sizeof(ss_addr_t) * remote_num); while (remote_num > 0) { int index = --remote_num; diff --git a/src/local.h b/src/local.h index 35596115..70b5d883 100644 --- a/src/local.h +++ b/src/local.h @@ -10,7 +10,7 @@ struct listen_ctx { ev_io io; - addr_t *remote_addr; + ss_addr_t *remote_addr; char *iface; int remote_num; int method; diff --git a/src/tunnel.c b/src/tunnel.c index dfbf835e..d5ccb208 100644 --- a/src/tunnel.c +++ b/src/tunnel.c @@ -385,19 +385,19 @@ static void remote_send_cb (EV_P_ ev_io *w, int revents) ev_timer_stop(EV_A_ &remote_send_ctx->watcher); // send destaddr - char *addr_to_send = malloc(BUF_SIZE); + char *ss_addr_to_send = malloc(BUF_SIZE); ssize_t addr_len = 0; struct sockaddr *sa = &server->destaddr; - addr_to_send[addr_len++] = 1; - + ss_addr_to_send[addr_len++] = 1; + if (sa->sa_family == AF_INET) { // handle IPv4 struct sockaddr_in *sin = (struct sockaddr_in *)sa; size_t in_addr_len = sizeof(struct in_addr); - memcpy(addr_to_send + addr_len, &sin->sin_addr, in_addr_len); + memcpy(ss_addr_to_send + addr_len, &sin->sin_addr, in_addr_len); addr_len += in_addr_len; - memcpy(addr_to_send + addr_len, &sin->sin_port, 2); + memcpy(ss_addr_to_send + addr_len, &sin->sin_port, 2); addr_len += 2; } else if (sa->sa_family == AF_INET6) @@ -405,9 +405,9 @@ static void remote_send_cb (EV_P_ ev_io *w, int revents) // handle IPv6 struct sockaddr_in6 *sin6 = (struct sockaddr_in6 *)sa; size_t in6_addr_len = sizeof(struct in6_addr); - memcpy(addr_to_send + addr_len, &sin6->sin6_addr, in6_addr_len); + memcpy(ss_addr_to_send + addr_len, &sin6->sin6_addr, in6_addr_len); addr_len += in6_addr_len; - memcpy(addr_to_send + addr_len, &sin6->sin6_port, 2); + memcpy(ss_addr_to_send + addr_len, &sin6->sin6_port, 2); addr_len += 2; } else @@ -418,8 +418,8 @@ static void remote_send_cb (EV_P_ ev_io *w, int revents) return; } - addr_to_send = ss_encrypt(BUF_SIZE, addr_to_send, &addr_len, server->e_ctx); - if (addr_to_send == NULL) + ss_addr_to_send = ss_encrypt(BUF_SIZE, ss_addr_to_send, &addr_len, server->e_ctx); + if (ss_addr_to_send == NULL) { LOGE("invalid password or cipher"); close_and_free_remote(EV_A_ remote); @@ -427,8 +427,8 @@ static void remote_send_cb (EV_P_ ev_io *w, int revents) return; } - int s = send(remote->fd, addr_to_send, addr_len, 0); - free(addr_to_send); + int s = send(remote->fd, ss_addr_to_send, addr_len, 0); + free(ss_addr_to_send); if (s < addr_len) { @@ -714,10 +714,10 @@ int main (int argc, char **argv) char *iface = NULL; int remote_num = 0; - addr_t remote_addr[MAX_REMOTE_NUM]; + ss_addr_t remote_addr[MAX_REMOTE_NUM]; char *remote_port = NULL; - addr_t tunnel_addr = {.host = NULL, .port = NULL}; + ss_addr_t tunnel_addr = {.host = NULL, .port = NULL}; char *tunnel_addr_str = NULL; opterr = 0; @@ -845,7 +845,7 @@ int main (int argc, char **argv) struct listen_ctx listen_ctx; listen_ctx.tunnel_addr = tunnel_addr; listen_ctx.remote_num = remote_num; - listen_ctx.remote_addr = malloc(sizeof(addr_t) * remote_num); + listen_ctx.remote_addr = malloc(sizeof(ss_addr_t) * remote_num); while (remote_num > 0) { int index = --remote_num; diff --git a/src/tunnel.h b/src/tunnel.h index bd0f6d48..bfa648b8 100644 --- a/src/tunnel.h +++ b/src/tunnel.h @@ -10,8 +10,8 @@ struct listen_ctx { ev_io io; - addr_t tunnel_addr; - addr_t *remote_addr; + ss_addr_t tunnel_addr; + ss_addr_t *remote_addr; char *iface; int remote_num; int method; diff --git a/src/udprelay.c b/src/udprelay.c index 7d249926..e06a0a6b 100644 --- a/src/udprelay.c +++ b/src/udprelay.c @@ -833,7 +833,7 @@ int udprelay_init(const char *server_host, const char *server_port, #ifdef UDPRELAY_LOCAL const char *remote_host, const char *remote_port, #ifdef UDPRELAY_TUNNEL - const addr_t tunnel_addr, + const ss_addr_t tunnel_addr, #endif #endif #ifdef UDPRELAY_REMOTE diff --git a/src/udprelay.h b/src/udprelay.h index 8a42b3dd..40915f85 100644 --- a/src/udprelay.h +++ b/src/udprelay.h @@ -33,7 +33,7 @@ struct server_ctx const char *remote_host; const char *remote_port; #ifdef UDPRELAY_TUNNEL - addr_t tunnel_addr; + ss_addr_t tunnel_addr; #endif #endif };