From f3f6ece4fcff14d9e9a1ef0f2726a1bedadb36f2 Mon Sep 17 00:00:00 2001 From: Max Lv Date: Mon, 26 Jan 2015 14:25:39 +0800 Subject: [PATCH] clean up --- src/server.c | 9 ++------- src/udprelay.c | 15 +++++---------- 2 files changed, 7 insertions(+), 17 deletions(-) diff --git a/src/server.c b/src/server.c index 376d90b1..252bb376 100644 --- a/src/server.c +++ b/src/server.c @@ -197,7 +197,6 @@ int create_and_bind(const char *host, const char *port) rp = ipv4v6bindall; /* Take first IPV6 address available */ break; } - ipv4v6bindall = ipv4v6bindall->ai_next; /* Get next address info, if any */ } } @@ -208,16 +207,12 @@ int create_and_bind(const char *host, const char *port) continue; } - int opt = 1; - if (rp->ai_family == AF_INET6) { - int ipv6only = 0; - if (host) { - ipv6only = 1; - } + int ipv6only = host ? 1 : 0; setsockopt(listen_sock, IPPROTO_IPV6, IPV6_V6ONLY, &ipv6only, sizeof(ipv6only)); } + int opt = 1; setsockopt(listen_sock, SOL_SOCKET, SO_REUSEADDR, &opt, sizeof(opt)); #ifdef SO_NOSIGPIPE setsockopt(listen_sock, SOL_SOCKET, SO_NOSIGPIPE, &opt, sizeof(opt)); diff --git a/src/udprelay.c b/src/udprelay.c index 98763b82..eb77ff49 100644 --- a/src/udprelay.c +++ b/src/udprelay.c @@ -321,7 +321,7 @@ int create_server_socket(const char *host, const char *port) hints.ai_socktype = SOCK_DGRAM; /* We want a UDP socket */ hints.ai_flags = AI_ALL | AI_V4MAPPED | AI_PASSIVE | AI_ADDRCONFIG; /* For wildcard IP address */ hints.ai_protocol = IPPROTO_UDP; - + s = getaddrinfo(host, port, &hints, &result); if (s != 0) { LOGE("[udp] getaddrinfo: %s", gai_strerror(s)); @@ -345,27 +345,22 @@ int create_server_socket(const char *host, const char *port) rp = ipv4v6bindall; /* Take first IPV6 address available */ break; } - ipv4v6bindall = ipv4v6bindall->ai_next; /* Get next address info, if any */ } } - + for (/*rp = result*/; rp != NULL; rp = rp->ai_next) { server_sock = socket(rp->ai_family, rp->ai_socktype, rp->ai_protocol); if (server_sock == -1) { continue; } - int opt = 1; - if (rp->ai_family == AF_INET6) { - int ipv6only = 0; - if (host) { - ipv6only = 1; - } + int ipv6only = host ? 1 : 0; setsockopt(server_sock, IPPROTO_IPV6, IPV6_V6ONLY, &ipv6only, sizeof(ipv6only)); } - + + int opt = 1; setsockopt(server_sock, SOL_SOCKET, SO_REUSEADDR, &opt, sizeof(opt)); #ifdef SO_NOSIGPIPE set_nosigpipe(server_sock);