From 726a1b7dd70939c5ded978760bc554ad59cbfbdd Mon Sep 17 00:00:00 2001 From: Max Lv Date: Thu, 22 Jan 2015 09:12:19 +0800 Subject: [PATCH] clean up --- .uncrustify.cfg | 2 +- src/local.c | 10 +++++----- src/netutils.c | 3 ++- src/redir.c | 2 +- src/server.c | 40 +++++++++++++++++++++------------------- src/tunnel.c | 2 +- 6 files changed, 31 insertions(+), 28 deletions(-) diff --git a/.uncrustify.cfg b/.uncrustify.cfg index 589e53b5..233e06d2 100644 --- a/.uncrustify.cfg +++ b/.uncrustify.cfg @@ -2,7 +2,7 @@ # based on uncrustify config file for the linux kernel # -code_width = 80 +code_width = 120 indent_case_brace = 4 indent_columns = 4 indent_label = 2 # pos: absolute col, neg: relative column diff --git a/src/local.c b/src/local.c index 522ac40e..551a6579 100644 --- a/src/local.c +++ b/src/local.c @@ -796,7 +796,7 @@ static void close_and_free_server(EV_P_ struct server *server) } static struct remote * connect_to_remote(struct listen_ctx *listener, - struct sockaddr *addr) + struct sockaddr *addr) { struct sockaddr *remote_addr; @@ -1070,7 +1070,7 @@ int main(int argc, char **argv) for (i = 0; i < remote_num; i++) { char *host = remote_addr[i].host; char *port = remote_addr[i].port == NULL ? remote_port : - remote_addr[i].port; + remote_addr[i].port; struct sockaddr_storage *storage = malloc(sizeof(struct sockaddr_storage)); memset(storage, 0, sizeof(struct sockaddr_storage)); if (get_sockaddr(host, port, storage) == -1) { @@ -1091,7 +1091,7 @@ int main(int argc, char **argv) if (udprelay) { LOGI("udprelay enabled"); init_udprelay(local_addr, local_port, listen_ctx.remote_addr[0], - get_sockaddr_len(listen_ctx.remote_addr[0]), m, listen_ctx.timeout, iface); + get_sockaddr_len(listen_ctx.remote_addr[0]), m, listen_ctx.timeout, iface); } // setuid @@ -1220,8 +1220,8 @@ int start_ss_local_server(profile_t profile) if (udprelay) { LOGI("udprelay enabled"); init_udprelay(local_addr, local_port_str, listen_ctx.remote_addr[0], - get_sockaddr_len(listen_ctx.remote_addr[0]), m, - listen_ctx.timeout, NULL); + get_sockaddr_len(listen_ctx.remote_addr[0]), m, + listen_ctx.timeout, NULL); } // Init connections diff --git a/src/netutils.c b/src/netutils.c index d73738b8..d787dce4 100644 --- a/src/netutils.c +++ b/src/netutils.c @@ -38,7 +38,8 @@ #include "netutils.h" #include "utils.h" -int get_sockaddr_len(struct sockaddr *addr) { +int get_sockaddr_len(struct sockaddr *addr) +{ if (addr->sa_family == AF_INET) { return sizeof(struct sockaddr_in); } else if (addr->sa_family == AF_INET6) { diff --git a/src/redir.c b/src/redir.c index c18f0a20..e8dd3f60 100644 --- a/src/redir.c +++ b/src/redir.c @@ -726,7 +726,7 @@ int main(int argc, char **argv) for (int i = 0; i < remote_num; i++) { char *host = remote_addr[i].host; char *port = remote_addr[i].port == NULL ? remote_port : - remote_addr[i].port; + remote_addr[i].port; struct sockaddr_storage *storage = malloc(sizeof(struct sockaddr_storage)); memset(storage, 0, sizeof(struct sockaddr_storage)); if (get_sockaddr(host, port, storage) == -1) { diff --git a/src/server.c b/src/server.c index 6ab60371..eeec1c51 100644 --- a/src/server.c +++ b/src/server.c @@ -151,9 +151,9 @@ int create_and_bind(const char *host, const char *port) int s, listen_sock; memset(&hints, 0, sizeof(struct addrinfo)); - hints.ai_family = AF_UNSPEC; /* Return IPv4 and IPv6 choices */ - hints.ai_socktype = SOCK_STREAM; /* We want a TCP socket */ - hints.ai_flags = AI_ALL|AI_V4MAPPED|AI_PASSIVE|AI_ADDRCONFIG; /* For wildcard IP address */ + hints.ai_family = AF_UNSPEC; /* Return IPv4 and IPv6 choices */ + hints.ai_socktype = SOCK_STREAM; /* We want a TCP socket */ + hints.ai_flags = AI_ALL | AI_V4MAPPED | AI_PASSIVE | AI_ADDRCONFIG; /* For wildcard IP address */ hints.ai_protocol = IPPROTO_TCP; s = getaddrinfo(host, port, &hints, &result); @@ -165,24 +165,24 @@ int create_and_bind(const char *host, const char *port) rp = result; /* - On Linux, with net.ipv6.bindv6only = 0 (the default), getaddrinfo(NULL) with - AI_PASSIVE returns 0.0.0.0 and :: (in this order). AI_PASSIVE was meant to - return a list of addresses to listen on, but it is impossible to listen on - 0.0.0.0 and :: at the same time, if :: implies dualstack mode. - */ + On Linux, with net.ipv6.bindv6only = 0 (the default), getaddrinfo(NULL) with + AI_PASSIVE returns 0.0.0.0 and :: (in this order). AI_PASSIVE was meant to + return a list of addresses to listen on, but it is impossible to listen on + 0.0.0.0 and :: at the same time, if :: implies dualstack mode. + */ if (!host) { ipv4v6bindall = result; - + /* Loop over all address infos found until a IPV6 address is found. */ while (ipv4v6bindall) { if (ipv4v6bindall->ai_family == AF_INET6) { - rp = ipv4v6bindall; /* Take first IPV6 address available */ - break; + rp = ipv4v6bindall; /* Take first IPV6 address available */ + break; } - ipv4v6bindall= ipv4v6bindall->ai_next; /* Get next address info, if any */ - } - } + ipv4v6bindall = ipv4v6bindall->ai_next; /* Get next address info, if any */ + } + } for (/*rp = result*/; rp != NULL; rp = rp->ai_next) { listen_sock = socket(rp->ai_family, rp->ai_socktype, rp->ai_protocol); @@ -194,10 +194,12 @@ int create_and_bind(const char *host, const char *port) if (rp->ai_family == AF_INET6) { int ipv6only = 0; - if (host) ipv6only = 1; + if (host) { + ipv6only = 1; + } setsockopt(listen_sock, IPPROTO_IPV6, IPV6_V6ONLY, &ipv6only, sizeof(ipv6only)); } - + setsockopt(listen_sock, SOL_SOCKET, SO_REUSEADDR, &opt, sizeof(opt)); #ifdef SO_NOSIGPIPE setsockopt(listen_sock, SOL_SOCKET, SO_NOSIGPIPE, &opt, sizeof(opt)); @@ -1132,9 +1134,9 @@ int main(int argc, char **argv) } } - if (server_num == 0) { - server_host[server_num++]=NULL; - } + if (server_num == 0) { + server_host[server_num++] = NULL; + } if (server_num == 0 || server_port == NULL || password == NULL) { usage(); diff --git a/src/tunnel.c b/src/tunnel.c index 0e301fa1..3899dc5e 100644 --- a/src/tunnel.c +++ b/src/tunnel.c @@ -792,7 +792,7 @@ int main(int argc, char **argv) for (i = 0; i < remote_num; i++) { char *host = remote_addr[i].host; char *port = remote_addr[i].port == NULL ? remote_port : - remote_addr[i].port; + remote_addr[i].port; struct sockaddr_storage *storage = malloc(sizeof(struct sockaddr_storage)); memset(storage, 0, sizeof(struct sockaddr_storage)); if (get_sockaddr(host, port, storage) == -1) {