diff --git a/.gitignore b/.gitignore index 3a3cff5..097adc5 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,5 @@ .vscode -ciadpi.exe \ No newline at end of file +ciadpi.exe +ciadpi +*.o +compile_flags.txt diff --git a/conev.c b/conev.c index 5831919..6387775 100644 --- a/conev.c +++ b/conev.c @@ -1,4 +1,4 @@ -#define CONEV_H + #include "conev.h" #include diff --git a/conev.h b/conev.h index 6df99a1..eed9079 100644 --- a/conev.h +++ b/conev.h @@ -1,4 +1,6 @@ -#pragma once +#ifndef CONEV_H +#define CONEV_H + #include #ifndef __linux__ @@ -107,3 +109,5 @@ void destroy_pool(struct poolhd *pool); struct eval *next_event(struct poolhd *pool, int *offs, int *type); int mod_etype(struct poolhd *pool, struct eval *val, int type); + +#endif diff --git a/desync.c b/desync.c index 1b0fbb9..a87496a 100644 --- a/desync.c +++ b/desync.c @@ -1,5 +1,7 @@ #define _GNU_SOURCE +#include "desync.h" + #include #include @@ -16,7 +18,6 @@ #include #include - #include #ifdef MFD_CLOEXEC #include @@ -391,12 +392,12 @@ ssize_t desync(int sfd, char *buffer, size_t bfsize, type = IS_HTTP; } if (len && host) { - LOG(LOG_S, "host: %.*s (%ld)\n", + LOG(LOG_S, "host: %.*s (%zd)\n", len, host, host - buffer); } // modify packet if (type == IS_HTTP && dp.mod_http) { - LOG(LOG_S, "modify HTTP: n=%ld\n", n); + LOG(LOG_S, "modify HTTP: n=%zd\n", n); if (mod_http(buffer, n, dp.mod_http)) { LOG(LOG_E, "mod http error\n"); return -1; @@ -420,10 +421,10 @@ ssize_t desync(int sfd, char *buffer, size_t bfsize, } if (!part_tls(buffer + lp, bfsize - lp, n - lp, pos - lp)) { - LOG(LOG_E, "tlsrec error: pos=%ld, n=%ld\n", pos, n); + LOG(LOG_E, "tlsrec error: pos=%ld, n=%zd\n", pos, n); break; } - LOG(LOG_S, "tlsrec: pos=%ld, n=%ld\n", pos, n); + LOG(LOG_S, "tlsrec: pos=%ld, n=%zd\n", pos, n); n += 5; lp = pos + 5; } @@ -462,7 +463,7 @@ ssize_t desync(int sfd, char *buffer, size_t bfsize, continue; } else if (pos <= 0 || pos >= n || pos <= lp) { - LOG(LOG_E, "split cancel: pos=%ld-%ld, n=%ld\n", lp, pos, n); + LOG(LOG_E, "split cancel: pos=%ld-%ld, n=%zd\n", lp, pos, n); break; } // send part @@ -494,7 +495,7 @@ ssize_t desync(int sfd, char *buffer, size_t bfsize, default: return -1; } - LOG(LOG_S, "split: pos=%ld-%ld (%ld), m: %s\n", lp, pos, s, demode_str[part.m]); + LOG(LOG_S, "split: pos=%ld-%ld (%zd), m: %s\n", lp, pos, s, demode_str[part.m]); if (s < 0) { if (get_e() == EAGAIN) { @@ -503,14 +504,14 @@ ssize_t desync(int sfd, char *buffer, size_t bfsize, return -1; } else if (s != (pos - lp)) { - LOG(LOG_E, "%ld != %ld\n", s, pos - lp); + LOG(LOG_E, "%zd != %ld\n", s, pos - lp); return lp + s; } lp = pos; } // send all/rest if (lp < n) { - LOG((lp ? LOG_S : LOG_L), "send: pos=%ld-%ld\n", lp, n); + LOG((lp ? LOG_S : LOG_L), "send: pos=%ld-%zd\n", lp, n); if (send(sfd, buffer + lp, n - lp, 0) < 0) { if (get_e() == EAGAIN) { return lp; diff --git a/desync.h b/desync.h index db0632a..a1a67db 100644 --- a/desync.h +++ b/desync.h @@ -1,3 +1,15 @@ +#ifndef DESYNC_H +#define DESYNC_H + +#include +#include + +#ifdef _WIN32 + #include +#else + #include +#endif + ssize_t desync(int sfd, char *buffer, size_t bfsize, ssize_t n, ssize_t offset, struct sockaddr *dst, int dp_c); ssize_t desync_udp(int sfd, char *buffer, size_t bfsize, ssize_t n, struct sockaddr *dst, int dp_c); @@ -9,4 +21,6 @@ struct tcpi { uint32_t unacked; uint32_t rrr[29]; uint32_t notsent_bytes; -}; \ No newline at end of file +}; + +#endif diff --git a/error.h b/error.h index 0352f7a..9eddcee 100644 --- a/error.h +++ b/error.h @@ -1,3 +1,6 @@ +#ifndef CIADPI_ERROR_H +#define CIADPI_ERROR_H + #include #include @@ -18,7 +21,7 @@ #ifdef _WIN32 #define uniperror(str) \ - fprintf(stderr, "%s: %d\n", str, GetLastError()) + fprintf(stderr, "%s: %ld\n", str, GetLastError()) #else #ifdef ANDROID_APP #define uniperror(str) \ @@ -72,3 +75,5 @@ static inline const int unie(int e) inet_ntop(AF_INET, &dst.in.sin_addr, ADDR_STR, sizeof(ADDR_STR)); \ else \ inet_ntop(AF_INET6, &dst.in6.sin6_addr, ADDR_STR, sizeof(ADDR_STR)); + +#endif diff --git a/extend.c b/extend.c index b91edf1..d5d6d59 100644 --- a/extend.c +++ b/extend.c @@ -1,3 +1,6 @@ + +#include "extend.h" + #ifdef _WIN32 #include diff --git a/extend.h b/extend.h index d861966..8a6ab8f 100644 --- a/extend.h +++ b/extend.h @@ -1,3 +1,11 @@ +#ifndef EXTEND_H +#define EXTEND_H + +#include + +#include "conev.h" +#include "proxy.h" + int connect_hook(struct poolhd *pool, struct eval *val, struct sockaddr_ina *dst, int next); @@ -14,4 +22,6 @@ ssize_t udp_hook(struct eval *val, int protect(int conn_fd, const char *path); #else #define protect(fd, path) 0 -#endif \ No newline at end of file +#endif + +#endif diff --git a/mpool.c b/mpool.c index bcc0792..9d4fd42 100644 --- a/mpool.c +++ b/mpool.c @@ -1,7 +1,9 @@ + +#include "mpool.h" + #include #include -#include "mpool.h" static inline int scmp(const struct elem *p, const struct elem *q) diff --git a/mpool.h b/mpool.h index 8f5d47d..c209dc0 100644 --- a/mpool.h +++ b/mpool.h @@ -1,3 +1,6 @@ +#ifndef MPOOL_H +#define MPOOL_H + #include #include #include "kavl.h" @@ -24,3 +27,5 @@ struct elem *mem_add(struct mphdr *hdr, char *str, int len); void mem_delete(struct mphdr *hdr, char *str, int len); void mem_destroy(struct mphdr *hdr); + +#endif diff --git a/packets.c b/packets.c index 540ba86..ebe4d39 100644 --- a/packets.c +++ b/packets.c @@ -1,6 +1,7 @@ #define _GNU_SOURCE -#include +#include "packets.h" + #include #include #include diff --git a/packets.h b/packets.h index 5ef44c4..2c04449 100644 --- a/packets.h +++ b/packets.h @@ -1,3 +1,6 @@ +#ifndef PACKETS_H +#define PACKETS_H + #include #include #include @@ -43,3 +46,6 @@ int part_tls(char *buffer, size_t bsize, ssize_t n, long pos); //bool is_dns_req(char *buffer, size_t n); //bool is_quic_initial(char *buffer, size_t bsize); + + +#endif diff --git a/params.h b/params.h index 825950c..a8ff74b 100644 --- a/params.h +++ b/params.h @@ -1,3 +1,6 @@ +#ifndef PARAMS_H +#define PARAMS_H + #include #include @@ -107,4 +110,6 @@ extern struct packet fake_http; extern struct packet oob_data; extern struct packet fake_udp; -extern char ip_option[1]; \ No newline at end of file +extern char ip_option[1]; + +#endif diff --git a/proxy.c b/proxy.c index de5ad7a..c938857 100644 --- a/proxy.c +++ b/proxy.c @@ -1,6 +1,8 @@ #define _GNU_SOURCE #define EID_STR +#include "proxy.h" + #include #include #include @@ -8,7 +10,6 @@ #include #include -#include "proxy.h" #include "params.h" #include "conev.h" #include "extend.h" @@ -57,7 +58,8 @@ void map_fix(struct sockaddr_ina *addr, char f6) else if (!ipv6m->o64 && !ipv6m->o16 && ipv6m->t16 == 0xffff && !f6) { addr->sa.sa_family = AF_INET; - addr->in.sin_addr = *(struct in_addr *)(&ipv6m->o32); + const struct in_addr *sin_addr_ptr = (struct in_addr *) &ipv6m->o32; + addr->in.sin_addr = *sin_addr_ptr; } } @@ -617,7 +619,7 @@ int on_tunnel(struct poolhd *pool, struct eval *val, } sn = 0; } - LOG(LOG_S, "send: %ld != %ld (fd: %d)\n", sn, n, pair->fd); + LOG(LOG_S, "send: %zd != %zd (fd: %d)\n", sn, n, pair->fd); assert(!(val->buff.size || val->buff.offset)); val->buff.size = n - sn; @@ -738,7 +740,7 @@ static inline int on_request(struct poolhd *pool, struct eval *val, return 0; } if (n < S_SIZE_MIN) { - LOG(LOG_E, "ss: request to small (%ld)\n", n); + LOG(LOG_E, "ss: request to small (%zd)\n", n); return -1; } struct s5_req *r = (struct s5_req *)buffer; @@ -780,7 +782,7 @@ static inline int on_request(struct poolhd *pool, struct eval *val, error = connect_hook(pool, val, &dst, EV_CONNECT); } else { - LOG(LOG_E, "ss: invalid version: 0x%x (%lu)\n", *buffer, n); + LOG(LOG_E, "ss: invalid version: 0x%x (%zd)\n", *buffer, n); return -1; } if (error) { diff --git a/proxy.h b/proxy.h index b9db0a8..43e5756 100644 --- a/proxy.h +++ b/proxy.h @@ -1,3 +1,6 @@ +#ifndef PROXY_H +#define PROXY_H + #include #ifdef _WIN32 @@ -111,3 +114,5 @@ int listen_socket(struct sockaddr_ina *srv); int event_loop(int srvfd); int run(struct sockaddr_ina *srv); + +#endif diff --git a/win_service.c b/win_service.c index 0bfd7a4..8645f45 100644 --- a/win_service.c +++ b/win_service.c @@ -1,4 +1,6 @@ + #include "win_service.h" + #include #define SERVICE_NAME "ByeDPI" @@ -76,4 +78,4 @@ int register_winsvc(int argc, char *argv[]) svc_argv = argv; return StartServiceCtrlDispatcher(ServiceTable); -} \ No newline at end of file +} diff --git a/win_service.h b/win_service.h index 6c15d5d..65b797a 100644 --- a/win_service.h +++ b/win_service.h @@ -1 +1,7 @@ -int register_winsvc(int argc, char *argv[]); \ No newline at end of file +#ifndef WIN_SERVICE_H +#define WIN_SERVICE_H + +int register_winsvc(int argc, char *argv[]); + + +#endif