Browse Source

refactor: handle clang warnings

master
dnomd343 3 years ago
parent
commit
26df75a952
  1. 3
      src/dns.c
  2. 5
      src/network.c
  3. 6
      src/process.c

3
src/dns.c

@ -81,8 +81,7 @@ char** ipv6_dns_resolve(char *domain) { // DNS解析IPv6地址
char* dns_resolve(char *domain) { // DNS解析 返回首个IP地址 IPv4优先
int num = 0;
char **result = init_dns_result();
result = ipv4_dns_resolve(domain); // IPv4解析
char **result = ipv4_dns_resolve(domain); // IPv4解析
while(result[num++] != NULL); // num - 1 为IPv4地址数
if (num - 1 != 0) { // 存在IPv4解析
char *tmp = strcpy((char*)malloc(strlen(result[0]) + 1), result[0]);

5
src/network.c

@ -49,7 +49,7 @@ int get_random_num(int range_start, int range_end) { // create a random number i
struct timeval tp;
gettimeofday(&tp, NULL);
srand(tp.tv_usec);
return range_start + (rand() % (range_end - range_start + 1));
return range_start + (rand() % (range_end - range_start + 1)); // NOLINT (randomness is enough for us)
}
int check_port_available(unsigned int port, int is_udp, int is_ipv6) { // test a port is available or not
@ -291,8 +291,7 @@ void proxy(char *server_ip, int server_port, char *listen_ip, int listen_port) {
pthread_t tid;
long recv_len;
char recv_buffer[BUFFER_SIZE]; // 接收缓冲区
int ipv4_client_fd = -1;
int ipv6_client_fd = -1;
int ipv4_client_fd, ipv6_client_fd;
struct sockaddr_in ipv4_client_addr;
struct sockaddr_in6 ipv6_client_addr;
socklen_t ipv4_client_addr_len = sizeof(ipv4_client_addr);

6
src/process.c

@ -1,4 +1,6 @@
#ifndef _GNU_SOURCE
#define _GNU_SOURCE
#endif
#include <glib.h>
#include <stdio.h>
#include <unistd.h>
@ -217,9 +219,9 @@ void start_bootstrap(char *ss_type, int is_udp_proxy) { // start shadowsocks and
printf("[Shadowsocks Bootstrap] Skip UDP Proxy.\n");
} else { // udp proxy
if (!strcmp(ss_type, "sslocal")) { // local mode
proxy(remote_ip, atoi(SS_REMOTE_PORT), SS_LOCAL_HOST, atoi(SS_LOCAL_PORT));
proxy(remote_ip, atoi(SS_REMOTE_PORT), SS_LOCAL_HOST, atoi(SS_LOCAL_PORT)); // NOLINT
} else { // server mode
proxy(SS_LOCAL_HOST, atoi(SS_LOCAL_PORT), remote_ip, atoi(SS_REMOTE_PORT));
proxy(SS_LOCAL_HOST, atoi(SS_LOCAL_PORT), remote_ip, atoi(SS_REMOTE_PORT)); // NOLINT
}
}
} else {

Loading…
Cancel
Save