mirror of
https://github.com/hufrea/byedpi.git
synced 2024-12-22 06:15:14 +00:00
Move LOG to error.h
This commit is contained in:
parent
e12be5db14
commit
90ca8aca01
6
conev.c
6
conev.c
@ -19,7 +19,7 @@ struct poolhd *init_pool(int count)
|
||||
#ifndef NOEPOLL
|
||||
int efd = epoll_create(count);
|
||||
if (efd < 0) {
|
||||
perror("epoll_create");
|
||||
uniperror("epoll_create");
|
||||
free(pool);
|
||||
return 0;
|
||||
}
|
||||
@ -149,7 +149,7 @@ struct eval *next_event(struct poolhd *pool, int *offs, int *type)
|
||||
if (i < 0) {
|
||||
i = (epoll_wait(pool->efd, pool->pevents, pool->max, -1) - 1);
|
||||
if (i < 0) {
|
||||
perror("epoll_wait");
|
||||
uniperror("epoll_wait");
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
@ -171,7 +171,7 @@ int mod_etype(struct poolhd *pool, struct eval *val, int type, char add)
|
||||
val->events = ev.events;
|
||||
int s = epoll_ctl(pool->efd, EPOLL_CTL_MOD, val->fd, &ev);
|
||||
if (s)
|
||||
perror("epoll_ctl");
|
||||
uniperror("epoll_ctl");
|
||||
return s;
|
||||
}
|
||||
|
||||
|
10
desync.c
10
desync.c
@ -75,7 +75,7 @@ int fake_attack(int sfd, char *buffer,
|
||||
|
||||
int ffd = memfd_create("name", O_RDWR);
|
||||
if (ffd < 0) {
|
||||
perror("memfd_create");
|
||||
uniperror("memfd_create");
|
||||
return -1;
|
||||
}
|
||||
char *p = 0;
|
||||
@ -83,12 +83,12 @@ int fake_attack(int sfd, char *buffer,
|
||||
|
||||
while (status) {
|
||||
if (ftruncate(ffd, pos) < 0) {
|
||||
perror("ftruncate");
|
||||
uniperror("ftruncate");
|
||||
break;
|
||||
}
|
||||
p = mmap(0, pos, PROT_WRITE, MAP_SHARED, ffd, 0);
|
||||
if (p == MAP_FAILED) {
|
||||
perror("mmap");
|
||||
uniperror("mmap");
|
||||
p = 0;
|
||||
break;
|
||||
}
|
||||
@ -163,6 +163,7 @@ int desync(int sfd, char *buffer, size_t bfsize,
|
||||
}
|
||||
|
||||
if (type == IS_HTTP && params.mod_http) {
|
||||
LOG(LOG_S, "modify HTTP: n=%ld\n", n);
|
||||
if (mod_http(buffer, n, params.mod_http)) {
|
||||
fprintf(stderr, "mod http error\n");
|
||||
return -1;
|
||||
@ -176,6 +177,7 @@ int desync(int sfd, char *buffer, size_t bfsize,
|
||||
else if (o < 0) {
|
||||
o += n;
|
||||
}
|
||||
LOG(LOG_S, "tlsrec: pos=%d, n=%ld\n", o, n);
|
||||
n = part_tls(buffer, bfsize, n, o);
|
||||
}
|
||||
|
||||
@ -188,7 +190,7 @@ int desync(int sfd, char *buffer, size_t bfsize,
|
||||
else if (pos < 0) {
|
||||
pos += n;
|
||||
}
|
||||
LOG(LOG_L, "split pos: %d, n: %ld\n", pos, n);
|
||||
LOG(LOG_L, "split-pos=%d, n=%ld\n", pos, n);
|
||||
|
||||
if (params.custom_ttl) {
|
||||
if (setttl(sfd, params.def_ttl, fa) < 0) {
|
||||
|
34
error.h
34
error.h
@ -2,7 +2,10 @@
|
||||
#include <errno.h>
|
||||
|
||||
#ifdef _WIN32
|
||||
#include <winsock2.h>
|
||||
#include <winsock2.h>
|
||||
#endif
|
||||
#ifdef ANDROID_APP
|
||||
#include <android/log.h>
|
||||
#endif
|
||||
|
||||
#ifdef _WIN32
|
||||
@ -14,11 +17,17 @@
|
||||
#endif
|
||||
|
||||
#ifdef _WIN32
|
||||
#define uniperror(str) \
|
||||
fprintf(stderr, "%s: %d\n", str, WSAGetLastError())
|
||||
#define uniperror(str) \
|
||||
fprintf(stderr, "%s: %d\n", str, WSAGetLastError())
|
||||
#else
|
||||
#define uniperror(str) \
|
||||
perror(str)
|
||||
#ifdef ANDROID_APP
|
||||
#define uniperror(str) \
|
||||
__android_log_print(ANDROID_LOG_ERROR, "proxy",
|
||||
"%s: %s\n", str, strerror(errno))
|
||||
#else
|
||||
#define uniperror(str) \
|
||||
perror(str)
|
||||
#endif
|
||||
#endif
|
||||
|
||||
inline const int unie(int e)
|
||||
@ -39,3 +48,18 @@ inline const int unie(int e)
|
||||
#endif
|
||||
return e;
|
||||
}
|
||||
|
||||
#ifdef ANDROID_APP
|
||||
#define LOG_E ANDROID_LOG_ERROR
|
||||
#define LOG_S ANDROID_LOG_DEBUG
|
||||
#define LOG_L ANDROID_LOG_VERBOSE
|
||||
#define LOG(s, str, ...) \
|
||||
__android_log_print(s, "proxy", str, ##__VA_ARGS__)
|
||||
#else
|
||||
#define LOG_E -1
|
||||
#define LOG_S 1
|
||||
#define LOG_L 2
|
||||
#define LOG(s, str, ...) \
|
||||
if (params.debug >= s) \
|
||||
fprintf(stderr, str, ##__VA_ARGS__)
|
||||
#endif
|
16
params.h
16
params.h
@ -5,9 +5,6 @@
|
||||
#else
|
||||
#include <arpa/inet.h>
|
||||
#endif
|
||||
#if __ANDROID_NDK__
|
||||
#include <android/log.h>
|
||||
#endif
|
||||
|
||||
enum demode {
|
||||
DESYNC_NONE,
|
||||
@ -46,16 +43,3 @@ struct packet {
|
||||
};
|
||||
extern struct packet fake_tls;
|
||||
extern struct packet fake_http;
|
||||
|
||||
#if __ANDROID_NDK__
|
||||
#define LOG_S ANDROID_LOG_DEBUG
|
||||
#define LOG_L ANDROID_LOG_VERBOSE
|
||||
#define LOG(s, str, ...) \
|
||||
__android_log_print(s, "proxy", str, ##__VA_ARGS__)
|
||||
#else
|
||||
#define LOG_S 1
|
||||
#define LOG_L 2
|
||||
#define LOG(s, str, ...) \
|
||||
if (params.debug >= s) printf(str, ##__VA_ARGS__)
|
||||
#endif
|
||||
|
||||
|
24
proxy.c
24
proxy.c
@ -81,7 +81,7 @@ static inline int nb_socket(int domain, int type)
|
||||
#else
|
||||
#ifndef __linux__
|
||||
if (fcntl(fd, F_SETFL, O_NONBLOCK) < 0) {
|
||||
perror("fcntl");
|
||||
uniperror("fcntl");
|
||||
close(fd);
|
||||
return -1;
|
||||
}
|
||||
@ -202,7 +202,7 @@ int s4_get_addr(char *buff, size_t n,
|
||||
return -1;
|
||||
}
|
||||
if (resolve(id_end + 1, len, dst)) {
|
||||
fprintf(stderr, "not resolved: %.*s\n", len, id_end + 1);
|
||||
LOG(LOG_E, "not resolved: %.*s\n", len, id_end + 1);
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
@ -224,11 +224,11 @@ int s5_get_addr(char *buffer, ssize_t n,
|
||||
(r->atp == S_ATP_ID ? r->id.len + S_SIZE_ID :
|
||||
(r->atp == S_ATP_I6 ? S_SIZE_I6 : 0)));
|
||||
if (n < o) {
|
||||
fprintf(stderr, "ss: bad request\n");
|
||||
LOG(LOG_E, "ss: bad request\n");
|
||||
return S_ER_GEN;
|
||||
}
|
||||
if (r->cmd != S_CMD_CONN) {
|
||||
fprintf(stderr, "ss: unsupported cmd: 0x%x\n", r->cmd);
|
||||
LOG(LOG_E, "ss: unsupported cmd: 0x%x\n", r->cmd);
|
||||
return S_ER_CMD;
|
||||
}
|
||||
switch (r->atp) {
|
||||
@ -243,7 +243,7 @@ int s5_get_addr(char *buffer, ssize_t n,
|
||||
}
|
||||
if (r->id.len < 3 ||
|
||||
resolve(r->id.domain, r->id.len, addr)) {
|
||||
fprintf(stderr, "not resolved: %.*s\n", r->id.len, r->id.domain);
|
||||
LOG(LOG_E, "not resolved: %.*s\n", r->id.len, r->id.domain);
|
||||
return S_ER_HOST;
|
||||
}
|
||||
break;
|
||||
@ -272,7 +272,7 @@ int create_conn(struct poolhd *pool,
|
||||
map_fix(&addr, 0);
|
||||
}
|
||||
if (addr.sa.sa_family != params.baddr.sin6_family) {
|
||||
fprintf(stderr, "different addresses family\n");
|
||||
LOG(LOG_E, "different addresses family\n");
|
||||
return -1;
|
||||
}
|
||||
int sfd = nb_socket(addr.sa.sa_family, SOCK_STREAM);
|
||||
@ -350,7 +350,7 @@ static inline int on_request(struct poolhd *pool, struct eval *val,
|
||||
return 0;
|
||||
}
|
||||
if (n < S_SIZE_MIN) {
|
||||
fprintf(stderr, "ss: request to small\n");
|
||||
LOG(LOG_E, "ss: request to small\n");
|
||||
return -1;
|
||||
}
|
||||
int s5e = s5_get_addr(buffer, n, &dst);
|
||||
@ -377,7 +377,7 @@ static inline int on_request(struct poolhd *pool, struct eval *val,
|
||||
}
|
||||
}
|
||||
else {
|
||||
fprintf(stderr, "ss: invalid version: 0x%x (%lu)\n", *buffer, n);
|
||||
LOG(LOG_E, "ss: invalid version: 0x%x (%lu)\n", *buffer, n);
|
||||
return -1;
|
||||
}
|
||||
val->type = EV_IGNORE;
|
||||
@ -411,7 +411,7 @@ static inline int on_accept(struct poolhd *pool, struct eval *val)
|
||||
uniperror("ioctlsocket");
|
||||
#else
|
||||
if (fcntl(c, F_SETFL, O_NONBLOCK) < 0) {
|
||||
perror("fcntl");
|
||||
uniperror("fcntl");
|
||||
#endif
|
||||
close(c);
|
||||
continue;
|
||||
@ -603,11 +603,11 @@ int big_loop(int srvfd)
|
||||
continue;
|
||||
|
||||
default:
|
||||
fprintf(stderr, "???\n");
|
||||
LOG(LOG_E, "???\n");
|
||||
NOT_EXIT = 0;
|
||||
}
|
||||
}
|
||||
fprintf(stderr, "exit\n");
|
||||
LOG(LOG_E, "exit\n");
|
||||
free(buffer);
|
||||
destroy_pool(pool);
|
||||
return 0;
|
||||
@ -618,7 +618,7 @@ int listener(struct sockaddr_ina srv)
|
||||
{
|
||||
#ifdef SIGPIPE
|
||||
if (signal(SIGPIPE, SIG_IGN))
|
||||
perror("signal SIGPIPE!");
|
||||
uniperror("signal SIGPIPE!");
|
||||
#endif
|
||||
signal(SIGINT, on_cancel);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user