Skip to content

Commit

Permalink
Merge pull request #47 from dartvader316/fix-headers
Browse files Browse the repository at this point in the history
Fix headers and format
  • Loading branch information
hufrea authored Aug 11, 2024
2 parents 084921e + b49d0ed commit 99e2d9b
Show file tree
Hide file tree
Showing 17 changed files with 99 additions and 25 deletions.
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@
.vscode
ciadpi.exe
ciadpi.exe
ciadpi
*.o
compile_flags.txt
2 changes: 1 addition & 1 deletion conev.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#define CONEV_H

#include "conev.h"

#include <stdlib.h>
Expand Down
6 changes: 5 additions & 1 deletion conev.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
#pragma once
#ifndef CONEV_H
#define CONEV_H

#include <stdint.h>

#ifndef __linux__
Expand Down Expand Up @@ -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
19 changes: 10 additions & 9 deletions desync.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#define _GNU_SOURCE

#include "desync.h"

#include <stdio.h>
#include <string.h>

Expand All @@ -16,7 +18,6 @@
#include <sys/sendfile.h>
#include <fcntl.h>

#include <desync.h>

#ifdef MFD_CLOEXEC
#include <sys/syscall.h>
Expand Down Expand Up @@ -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;
Expand All @@ -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;
}
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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) {
Expand All @@ -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;
Expand Down
16 changes: 15 additions & 1 deletion desync.h
Original file line number Diff line number Diff line change
@@ -1,3 +1,15 @@
#ifndef DESYNC_H
#define DESYNC_H

#include <stdint.h>
#include <stddef.h>

#ifdef _WIN32
#include <winsock2.h>
#else
#include <sys/socket.h>
#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);
Expand All @@ -9,4 +21,6 @@ struct tcpi {
uint32_t unacked;
uint32_t rrr[29];
uint32_t notsent_bytes;
};
};

#endif
7 changes: 6 additions & 1 deletion error.h
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
#ifndef CIADPI_ERROR_H
#define CIADPI_ERROR_H

#include <stdio.h>
#include <errno.h>

Expand All @@ -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) \
Expand Down Expand Up @@ -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
3 changes: 3 additions & 0 deletions extend.c
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@

#include "extend.h"

#ifdef _WIN32
#include <ws2tcpip.h>

Expand Down
12 changes: 11 additions & 1 deletion extend.h
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
#ifndef EXTEND_H
#define EXTEND_H

#include <stddef.h>

#include "conev.h"
#include "proxy.h"

int connect_hook(struct poolhd *pool, struct eval *val,
struct sockaddr_ina *dst, int next);

Expand All @@ -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
#endif

#endif
4 changes: 3 additions & 1 deletion mpool.c
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@

#include "mpool.h"

#include <stdlib.h>
#include <string.h>

#include "mpool.h"


static inline int scmp(const struct elem *p, const struct elem *q)
Expand Down
5 changes: 5 additions & 0 deletions mpool.h
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
#ifndef MPOOL_H
#define MPOOL_H

#include <stdbool.h>
#include <time.h>
#include "kavl.h"
Expand All @@ -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
3 changes: 2 additions & 1 deletion packets.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#define _GNU_SOURCE

#include <packets.h>
#include "packets.h"

#include <ctype.h>
#include <stdio.h>
#include <stdlib.h>
Expand Down
6 changes: 6 additions & 0 deletions packets.h
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
#ifndef PACKETS_H
#define PACKETS_H

#include <stdint.h>
#include <stdlib.h>
#include <stdbool.h>
Expand Down Expand Up @@ -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
7 changes: 6 additions & 1 deletion params.h
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
#ifndef PARAMS_H
#define PARAMS_H

#include <stdint.h>
#include <stdio.h>

Expand Down Expand Up @@ -107,4 +110,6 @@ extern struct packet fake_http;
extern struct packet oob_data;
extern struct packet fake_udp;

extern char ip_option[1];
extern char ip_option[1];

#endif
12 changes: 7 additions & 5 deletions proxy.c
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
#define _GNU_SOURCE
#define EID_STR

#include "proxy.h"

#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <signal.h>
#include <assert.h>

#include "proxy.h"
#include "params.h"
#include "conev.h"
#include "extend.h"
Expand Down Expand Up @@ -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;
}
}

Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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) {
Expand Down
5 changes: 5 additions & 0 deletions proxy.h
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
#ifndef PROXY_H
#define PROXY_H

#include <stdint.h>

#ifdef _WIN32
Expand Down Expand Up @@ -111,3 +114,5 @@ int listen_socket(struct sockaddr_ina *srv);
int event_loop(int srvfd);

int run(struct sockaddr_ina *srv);

#endif
4 changes: 3 additions & 1 deletion win_service.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@

#include "win_service.h"

#include <windows.h>

#define SERVICE_NAME "ByeDPI"
Expand Down Expand Up @@ -76,4 +78,4 @@ int register_winsvc(int argc, char *argv[])
svc_argv = argv;

return StartServiceCtrlDispatcher(ServiceTable);
}
}
8 changes: 7 additions & 1 deletion win_service.h
Original file line number Diff line number Diff line change
@@ -1 +1,7 @@
int register_winsvc(int argc, char *argv[]);
#ifndef WIN_SERVICE_H
#define WIN_SERVICE_H

int register_winsvc(int argc, char *argv[]);


#endif

0 comments on commit 99e2d9b

Please sign in to comment.