Skip to content

Commit 7bc8d18

Browse files
authored
Merge into the main branch (#4)
* 整理include * 增加编译信息 * 递增版本号 --------- Co-authored-by: bytesharky <fish@doffish.com>
1 parent bcd0f1b commit 7bc8d18

19 files changed

Lines changed: 182 additions & 95 deletions

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
.vscode/
22
.VSCodeCounter/
3+
.vs/

include/config.h

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
#ifndef CONFIG_H
22
#define CONFIG_H
3-
#include <stddef.h>
4-
#include "helper.h"
3+
#include <stddef.h> // for size_t
54

6-
#define VERSION "1.1.0"
5+
#define VERSION "1.1.1"
76
#define LISTEN_PORT_ENV "LISTEN_PORT"
87
#define FORWARD_DNS_ENV "FORWARD_DNS"
98
#define GATEWAY_ENV "GATEWAY_NAME"
@@ -34,7 +33,7 @@ extern char container_name[256];
3433
extern char gateway_name[64];
3534
extern char suffix_domain[64];
3635

37-
void init_config_env();
36+
void init_config_env(void);
3837
void init_config_argc(int argc, char *argv[]);
3938
int* str2int(const char *nptr);
4039
void read_env(const char *env_name, const char *default_val, char *dest, size_t dest_size);

include/dns.h

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,22 @@
11
#ifndef DNS_H
22
#define DNS_H
3+
#include <stdint.h> // for uint8_t
4+
#include <sys/socket.h> // for socklen_t, ssize_t
5+
// #include <ldns/packet.h> // for ldns_pkt
6+
// #include <ldns/rdata.h> // for ldns_rdf
7+
// #include <ldns/resolver.h> // for ldns_resolver
38
#include <ldns/ldns.h>
4-
#include <netinet/in.h>
5-
#include <sys/socket.h>
6-
#include <arpa/inet.h>
9+
10+
struct sockaddr_in;
711

812
#define QUEUE_SIZE 1024
913

10-
int test_forward_dns();
14+
int test_forward_dns(void);
1115
int is_match_suffix(const char *name);
16+
void strip_dot(char *name);
1217
void strip_suffix(char *name);
13-
ldns_resolver* create_fresh_resolver();
18+
ldns_resolver* create_fresh_resolver(void);
1419
ldns_pkt* modify_query_domain(ldns_pkt *original_pkt, ldns_rdf *new_domain);
15-
void process_dns_query(int sockfd, const char *buf, ssize_t len,
20+
void process_dns_query(int sockfd, const uint8_t *buf, ssize_t len,
1621
struct sockaddr_in *client, socklen_t client_len);
1722
#endif

include/gateway.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
#ifndef GATEWAY_H
22
#define GATEWAY_H
3+
#include <netinet/in.h> // for in_addr
4+
// #include <ldns/packet.h> // for ldns_pkt
5+
// #include <ldns/rr.h> // for ldns_rr
36
#include <ldns/ldns.h>
4-
#include <netinet/in.h>
57

68
extern struct in_addr gateway_addr;
79

810
int is_gateway_domain(const char *name);
9-
int resolve_gateway_ip();
11+
int resolve_gateway_ip(void);
1012
ldns_pkt* handle_gateway_query(ldns_pkt *query_pkt, ldns_rr *qrr,
1113
struct in_addr client_addr);
1214

include/helper.h

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,31 @@ typedef enum {
1717
OPT_VERSION
1818
} OptionType;
1919

20+
#if defined(__linux__)
21+
#define OS_NAME "Linux"
22+
#elif defined(__APPLE__)
23+
#define OS_NAME "macOS"
24+
#elif defined(_WIN32) || defined(_WIN64)
25+
#define OS_NAME "Windows"
26+
#else
27+
#define OS_NAME "Unknown"
28+
#endif
29+
30+
#if defined(__x86_64__)
31+
#define ARCH_NAME "x86_64"
32+
#elif defined(__i386__)
33+
#define ARCH_NAME "i386"
34+
#elif defined(__aarch64__)
35+
#define ARCH_NAME "ARM64"
36+
#elif defined(__arm__)
37+
#define ARCH_NAME "ARM32"
38+
#elif defined(__riscv)
39+
#define ARCH_NAME "RISC-V"
40+
#else
41+
#define ARCH_NAME "Unknown"
42+
#endif
43+
44+
void print_version(void);
2045
void print_help(const char *progname);
2146
OptionType get_option_type(const char* arg);
22-
#endif
47+
#endif

include/logging.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#ifndef LOGGING_H
22
#define LOGGING_H
3-
#include <stdarg.h>
3+
4+
#include <stdio.h> // for va_list
45

56
typedef enum {
67
LOG_DEBUG = 0,

include/loop_marker.h

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
#ifndef LOOP_MARKER_H
22
#define LOOP_MARKER_H
3-
#include <ldns/ldns.h>
4-
#include <ldns/edns.h>
5-
#include <arpa/inet.h>
3+
4+
#include <stdint.h> // for uint16_t
5+
// #include <ldns/packet.h> // for ldns_pkt
6+
#include <ldns/ldns.h>
67

78
#define MY_OPTION_CODE 65001
89
#define HOP_COUNT_DATA_LEN 2

include/queue.h

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
#ifndef QUEUE_H
22
#define QUEUE_H
3-
#include <pthread.h>
4-
#include <netinet/in.h>
5-
#include <sys/socket.h>
3+
#include <netinet/in.h> // for sockaddr_in
4+
#include <pthread.h> // for pthread_cond_t, pthread_mutex_t
5+
#include <stdint.h> // for uint8_t
6+
#include <sys/socket.h> // for size_t, socklen_t
67

78
#define BUF_SIZE 4096
89
#define QUEUE_SIZE 1024
@@ -20,5 +21,5 @@ extern pthread_mutex_t q_mutex;
2021
extern pthread_cond_t q_cond;
2122

2223
void enqueue_request(dns_request_t *req);
23-
int dequeue_request(dns_request_t *req);
24+
void dequeue_request(dns_request_t *req);
2425
#endif

include/sigterm.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#ifndef SIGNAL_H
22
#define SIGNAL_H
3-
#include <signal.h>
3+
#include <signal.h> // for sig_atomic_t
44

55
extern volatile sig_atomic_t stop;
66

src/config.c

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
1-
#include <stdio.h>
2-
#include <stdlib.h>
3-
#include <string.h>
4-
#include <errno.h>
5-
#include <limits.h>
6-
#include "logging.h"
71
#include "config.h"
2+
#include "helper.h" // for print_help, get_option_type, OPT_CONTAINER, OPT...
3+
#include "logging.h" // for log_msg, LOG_FATAL, parse_log_level, log_level
4+
#include <errno.h> // for errno, ERANGE
5+
#include <limits.h> // for INT_MAX, INT_MIN, LONG_MAX, LONG_MIN
6+
#include <stdio.h> // for fprintf, printf, stderr
7+
#include <stdlib.h> // for exit, free, getenv, malloc, strtol
8+
#include <string.h> // for strncpy, memmove, strlen
89

910
int max_hops = MAX_HOPS_DEFAULT;
1011
int num_workers = NUM_WORKERS_DEFAULT;
@@ -17,7 +18,7 @@ char gateway_name[64] = {0};
1718
char suffix_domain[64] = {0};
1819

1920
// 初始化配置(环境变量)
20-
void init_config_env() {
21+
void init_config_env(void) {
2122

2223
// 从环境变量读取
2324
log_level = parse_log_level(getenv(LOG_LEVEL_ENV), LOG_INFO);
@@ -203,7 +204,7 @@ void init_config_argc(int argc, char *argv[]) {
203204
print_help(argv[0]);
204205
exit(0);
205206
case OPT_VERSION:
206-
printf("version: %s\n", VERSION);
207+
print_version();
207208
exit(0);
208209
case OPT_UNKNOWN:
209210
fprintf(stderr, "Error: Unknown option '%s'\n", argv[i]);

0 commit comments

Comments
 (0)