Browse Source

fix the ambiguous type defination

pull/51/head
Max Lv 10 years ago
parent
commit
2b92b57bed
10 changed files with 49 additions and 49 deletions
  1. 2
      src/include.h
  2. 4
      src/jconf.c
  3. 8
      src/jconf.h
  4. 22
      src/json.c
  5. 24
      src/local.c
  6. 2
      src/local.h
  7. 28
      src/tunnel.c
  8. 4
      src/tunnel.h
  9. 2
      src/udprelay.c
  10. 2
      src/udprelay.h

2
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

4
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;

8
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

22
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;

24
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;

2
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;

28
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;

4
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;

2
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

2
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
};

Loading…
Cancel
Save