mirror of
https://codeberg.org/scip/udpxd.git
synced 2025-12-16 03:20:58 +01:00
tab => spc, year++
This commit is contained in:
2
Makefile
2
Makefile
@@ -1,7 +1,7 @@
|
||||
#
|
||||
# This file is part of udpxd.
|
||||
#
|
||||
# Copyright (C) 2015 T.v.Dein.
|
||||
# Copyright (C) 2015-2016 T.v.Dein.
|
||||
#
|
||||
# This program is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
|
||||
4
client.c
4
client.c
@@ -1,7 +1,7 @@
|
||||
/*
|
||||
This file is part of udpxd.
|
||||
|
||||
Copyright (C) 2015 T.v.Dein.
|
||||
Copyright (C) 2015-2016 T.v.Dein.
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
@@ -74,7 +74,7 @@ void client_clean(int asap) {
|
||||
diff = now - current->lastseen;
|
||||
if(diff >= MAXAGE || asap) {
|
||||
verbose("closing socket %s:%d for client %s:%d (aged out after %d seconds)\n",
|
||||
current->src->ip, current->src->port, current->dst->ip, current->dst->port, MAXAGE);
|
||||
current->src->ip, current->src->port, current->dst->ip, current->dst->port, MAXAGE);
|
||||
client_close(current);
|
||||
}
|
||||
}
|
||||
|
||||
2
client.h
2
client.h
@@ -1,7 +1,7 @@
|
||||
/*
|
||||
This file is part of udpxd.
|
||||
|
||||
Copyright (C) 2015 T.v.Dein.
|
||||
Copyright (C) 2015-2016 T.v.Dein.
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
|
||||
14
host.c
14
host.c
@@ -1,7 +1,7 @@
|
||||
/*
|
||||
This file is part of udpxd.
|
||||
|
||||
Copyright (C) 2015 T.v.Dein.
|
||||
Copyright (C) 2015-2016 T.v.Dein.
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
@@ -43,20 +43,20 @@ host_t *get_host(char *ip, int port, struct sockaddr_in *v4, struct sockaddr_in6
|
||||
|
||||
unsigned int scope = get_v6_scope(ip);
|
||||
if (is_linklocal((struct in6_addr*)&tmp->sin6_addr))
|
||||
tmp->sin6_scope_id = scope;
|
||||
tmp->sin6_scope_id = scope;
|
||||
else
|
||||
tmp->sin6_scope_id = 0;
|
||||
tmp->sin6_scope_id = 0;
|
||||
|
||||
host->is_v6 = 1;
|
||||
host->sock = (struct sockaddr*)tmp;
|
||||
host->size = sizeof(struct sockaddr_in6);
|
||||
if(tmp->sin6_scope_id != 0) {
|
||||
host->ip = malloc(INET6_ADDRSTRLEN + 9); /* plus [ % ] \0 , scope*/
|
||||
sprintf(host->ip, "[%s%%%d]", ip, scope);
|
||||
host->ip = malloc(INET6_ADDRSTRLEN + 9); /* plus [ % ] \0 , scope*/
|
||||
sprintf(host->ip, "[%s%%%d]", ip, scope);
|
||||
}
|
||||
else {
|
||||
host->ip = malloc(INET6_ADDRSTRLEN + 3); /* plus [ ] \0 */
|
||||
sprintf(host->ip, "[%s]", ip);
|
||||
host->ip = malloc(INET6_ADDRSTRLEN + 3); /* plus [ ] \0 */
|
||||
sprintf(host->ip, "[%s]", ip);
|
||||
}
|
||||
}
|
||||
else {
|
||||
|
||||
2
host.h
2
host.h
@@ -1,7 +1,7 @@
|
||||
/*
|
||||
This file is part of udpxd.
|
||||
|
||||
Copyright (C) 2015 T.v.Dein.
|
||||
Copyright (C) 2015-2016 T.v.Dein.
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
|
||||
6
log.c
6
log.c
@@ -1,7 +1,7 @@
|
||||
/*
|
||||
This file is part of udpxd.
|
||||
|
||||
Copyright (C) 2015 T.v.Dein.
|
||||
Copyright (C) 2015-2016 T.v.Dein.
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
@@ -33,10 +33,10 @@ void verbose(const char * fmt, ...) {
|
||||
va_end(ap);
|
||||
|
||||
if(FORKED) {
|
||||
syslog(LOG_INFO, "%s", msg);
|
||||
syslog(LOG_INFO, "%s", msg);
|
||||
}
|
||||
else {
|
||||
fprintf(stderr, "%s", msg);
|
||||
fprintf(stderr, "%s", msg);
|
||||
}
|
||||
}
|
||||
else {
|
||||
|
||||
2
log.h
2
log.h
@@ -1,7 +1,7 @@
|
||||
/*
|
||||
This file is part of udpxd.
|
||||
|
||||
Copyright (C) 2015 T.v.Dein.
|
||||
Copyright (C) 2015-2016 T.v.Dein.
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
|
||||
82
net.c
82
net.c
@@ -1,7 +1,7 @@
|
||||
/*
|
||||
This file is part of udpxd.
|
||||
|
||||
Copyright (C) 2015 T.v.Dein.
|
||||
Copyright (C) 2015-2016 T.v.Dein.
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
@@ -34,7 +34,7 @@ int fill_set(fd_set *fds) {
|
||||
client_iter(clients, current) {
|
||||
if (current->socket < (int)FD_SETSIZE) {
|
||||
if (current->socket > max)
|
||||
max = current->socket;
|
||||
max = current->socket;
|
||||
FD_SET(current->socket, fds);
|
||||
}
|
||||
else {
|
||||
@@ -104,12 +104,12 @@ int daemonize(char *pidfile) {
|
||||
if (pid > 0) {
|
||||
/* leave parent */
|
||||
if((fd = fopen(pidfile, "w")) == NULL) {
|
||||
perror("failed to write pidfile");
|
||||
return -1;
|
||||
perror("failed to write pidfile");
|
||||
return -1;
|
||||
}
|
||||
else {
|
||||
fprintf(fd, "%d\n", pid);
|
||||
fclose(fd);
|
||||
fprintf(fd, "%d\n", pid);
|
||||
fclose(fd);
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
@@ -186,7 +186,7 @@ int drop_privileges(char *user, char *chrootdir) {
|
||||
}
|
||||
|
||||
int start_listener (char *inip, char *inpt, char *srcip, char *dstip,
|
||||
char *dstpt, char *pidfile, char *chrootdir, char *user) {
|
||||
char *dstpt, char *pidfile, char *chrootdir, char *user) {
|
||||
host_t *listen_h, *dst_h, *bind_h;
|
||||
|
||||
int dm = daemonize(pidfile);
|
||||
@@ -224,7 +224,7 @@ int start_listener (char *inip, char *inpt, char *srcip, char *dstip,
|
||||
|
||||
if(VERBOSE) {
|
||||
verbose("Listening on %s:%s, forwarding to %s:%s",
|
||||
listen_h->ip, inpt, dst_h->ip, dstpt);
|
||||
listen_h->ip, inpt, dst_h->ip, dstpt);
|
||||
if(srcip != NULL)
|
||||
verbose(", binding to %s\n", bind_h->ip);
|
||||
else
|
||||
@@ -266,7 +266,7 @@ void handle_inside(int inside, host_t *listen_h, host_t *bind_h, host_t *dst_h)
|
||||
src = malloc(size);
|
||||
|
||||
len = recvfrom( inside, buffer, sizeof( buffer ), 0,
|
||||
(struct sockaddr*)src, (socklen_t *)&size );
|
||||
(struct sockaddr*)src, (socklen_t *)&size );
|
||||
|
||||
if(listen_h->is_v6)
|
||||
src_h = get_host(NULL, 0, NULL, (struct sockaddr_in6 *)src);
|
||||
@@ -281,49 +281,49 @@ void handle_inside(int inside, host_t *listen_h, host_t *bind_h, host_t *dst_h)
|
||||
if(client != NULL) {
|
||||
/* yes, we know it, send req out via existing bind socket */
|
||||
verbose("Client %s:%d is known, forwarding %d bytes to %s:%d ",
|
||||
src_h->ip, src_h->port, len, dst_h->ip, dst_h->port);
|
||||
src_h->ip, src_h->port, len, dst_h->ip, dst_h->port);
|
||||
verb_prbind(bind_h);
|
||||
|
||||
if(sendto(client->socket, buffer, len, 0, (struct sockaddr*)dst_h->sock, dst_h->size) < 0) {
|
||||
fprintf(stderr, "unable to forward to %s:%d\n", dst_h->ip, dst_h->port);
|
||||
perror(NULL);
|
||||
fprintf(stderr, "unable to forward to %s:%d\n", dst_h->ip, dst_h->port);
|
||||
perror(NULL);
|
||||
}
|
||||
else {
|
||||
client_seen(client);
|
||||
client_seen(client);
|
||||
}
|
||||
}
|
||||
else {
|
||||
/* unknown client, open new out socket */
|
||||
verbose("Client %s:%d is unknown, forwarding %d bytes to %s:%d ",
|
||||
src_h->ip, src_h->port, len, dst_h->ip, dst_h->port);
|
||||
verb_prbind(bind_h);
|
||||
verbose("Client %s:%d is unknown, forwarding %d bytes to %s:%d ",
|
||||
src_h->ip, src_h->port, len, dst_h->ip, dst_h->port);
|
||||
verb_prbind(bind_h);
|
||||
|
||||
output = bindsocket(bind_h);
|
||||
|
||||
/* send req out */
|
||||
if(sendto(output, buffer, len, 0, (struct sockaddr*)dst_h->sock, dst_h->size) < 0) {
|
||||
fprintf(stderr, "unable to forward to %s:%d\n", dst_h->ip, dst_h->port);
|
||||
perror(NULL);
|
||||
fprintf(stderr, "unable to forward to %s:%d\n", dst_h->ip, dst_h->port);
|
||||
perror(NULL);
|
||||
}
|
||||
else {
|
||||
size = listen_h->size;
|
||||
host_t *ret_h;
|
||||
if(listen_h->is_v6) {
|
||||
struct sockaddr_in6 *ret = malloc(size);
|
||||
getsockname(output, (struct sockaddr*)ret, (socklen_t *)&size);
|
||||
ret_h = get_host(NULL, 0, NULL, ret);
|
||||
free(ret);
|
||||
client = client_new(output, src_h, ret_h);
|
||||
}
|
||||
else {
|
||||
struct sockaddr_in *ret = malloc(size);
|
||||
getsockname(output, (struct sockaddr*)ret, (socklen_t *)&size);
|
||||
ret_h = get_host(NULL, 0, ret, NULL);
|
||||
free(ret);
|
||||
client = client_new(output, src_h, ret_h);
|
||||
}
|
||||
|
||||
client_add(client);
|
||||
size = listen_h->size;
|
||||
host_t *ret_h;
|
||||
if(listen_h->is_v6) {
|
||||
struct sockaddr_in6 *ret = malloc(size);
|
||||
getsockname(output, (struct sockaddr*)ret, (socklen_t *)&size);
|
||||
ret_h = get_host(NULL, 0, NULL, ret);
|
||||
free(ret);
|
||||
client = client_new(output, src_h, ret_h);
|
||||
}
|
||||
else {
|
||||
struct sockaddr_in *ret = malloc(size);
|
||||
getsockname(output, (struct sockaddr*)ret, (socklen_t *)&size);
|
||||
ret_h = get_host(NULL, 0, ret, NULL);
|
||||
free(ret);
|
||||
client = client_new(output, src_h, ret_h);
|
||||
}
|
||||
|
||||
client_add(client);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -349,9 +349,9 @@ void handle_outside(int inside, int outside, host_t *outside_h) {
|
||||
/* yes, we know it */
|
||||
/* FIXME: check src vs. client->src ? */
|
||||
if(sendto(inside, buffer, len, 0,
|
||||
(struct sockaddr*)client->src->sock, client->src->size) < 0) {
|
||||
perror("unable to send back to client"); /* FIXME: add src+port */
|
||||
client_close(client);
|
||||
(struct sockaddr*)client->src->sock, client->src->size) < 0) {
|
||||
perror("unable to send back to client"); /* FIXME: add src+port */
|
||||
client_close(client);
|
||||
}
|
||||
}
|
||||
else {
|
||||
@@ -388,8 +388,8 @@ int main_loop(int listensocket, host_t *listen_h, host_t *bind_h, host_t *dst_h)
|
||||
select(max + 1, &fds, NULL, NULL, NULL);
|
||||
|
||||
if (FD_ISSET(listensocket, &fds)) {
|
||||
/* incoming client on the inside, get src, bind output fd, add to list
|
||||
if known, otherwise just handle it */
|
||||
/* incoming client on the inside, get src, bind output fd, add
|
||||
to list if known, otherwise just handle it */
|
||||
handle_inside(listensocket, listen_h, bind_h, dst_h);
|
||||
}
|
||||
else {
|
||||
|
||||
2
net.h
2
net.h
@@ -1,7 +1,7 @@
|
||||
/*
|
||||
This file is part of udpxd.
|
||||
|
||||
Copyright (C) 2015 T.v.Dein.
|
||||
Copyright (C) 2015-2016 T.v.Dein.
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
|
||||
4
udpxd.1
4
udpxd.1
@@ -124,7 +124,7 @@
|
||||
.\" ========================================================================
|
||||
.\"
|
||||
.IX Title "UDPXD 1"
|
||||
.TH UDPXD 1 "2015-04-27" "perl v5.14.2" "User Contributed Perl Documentation"
|
||||
.TH UDPXD 1 "2015-2016-04-27" "perl v5.14.2" "User Contributed Perl Documentation"
|
||||
.\" For nroff, turn off justification. Always turn off hyphenation; it makes
|
||||
.\" way too many mistakes in technical documents.
|
||||
.if n .ad l
|
||||
@@ -280,7 +280,7 @@ or to submit a patch, please open an issue on github:
|
||||
.IX Header "LICENSE"
|
||||
This software is licensed under the \s-1GNU\s0 \s-1GENERAL\s0 \s-1PUBLIC\s0 \s-1LICENSE\s0 version 3.
|
||||
.PP
|
||||
Copyright (c) 2015 by T. v. Dein.
|
||||
Copyright (c) 2015-2016 by T. v. Dein.
|
||||
.PP
|
||||
This software uses \fButhash\fR (bundled), which is
|
||||
Copyright (c) 2003\-2013 by Troy D. Hanson.
|
||||
|
||||
48
udpxd.c
48
udpxd.c
@@ -1,7 +1,7 @@
|
||||
/*
|
||||
This file is part of udpxd.
|
||||
|
||||
Copyright (C) 2015 T.v.Dein.
|
||||
Copyright (C) 2015-2016 T.v.Dein.
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
@@ -71,8 +71,8 @@ int parse_ip(char *src, char *ip, char *pt) {
|
||||
}
|
||||
else {
|
||||
if(atoi(ptr) > 65535) {
|
||||
fprintf(stderr, "maximum port number possible: 65535!\n");
|
||||
return 1;
|
||||
fprintf(stderr, "maximum port number possible: 65535!\n");
|
||||
return 1;
|
||||
}
|
||||
strncpy(pt, ptr, strlen(ptr)+1);
|
||||
}
|
||||
@@ -89,21 +89,21 @@ int parse_ip(char *src, char *ip, char *pt) {
|
||||
|
||||
void usage() {
|
||||
fprintf(stderr,
|
||||
"Usage: udpxd [-lbdfpvhV]\n\n"
|
||||
"Options:\n"
|
||||
"--listen -l <ip:port> listen for incoming requests\n"
|
||||
"--bind -b <ip> bind ip used for outgoing requests\n"
|
||||
"--to -t <ip:port> destination to forward requests to\n"
|
||||
"--daemon -d daemon mode, fork into background\n"
|
||||
"--pidfile -p <file> pidfile, default: /var/run/udpxd.pid\n"
|
||||
"--user -u <user> run as user (only in daemon mode)\n"
|
||||
"--chroot -c <path> chroot to <path> (only in daemon mode)\n"
|
||||
"--help -h -? print help message\n"
|
||||
"--version -V print program version\n"
|
||||
"--verbose -v enable verbose logging\n\n"
|
||||
"Options -l and -t are mandatory.\n\n"
|
||||
"This is udpxd version %s.\n", UDPXD_VERSION
|
||||
);
|
||||
"Usage: udpxd [-lbdfpvhV]\n\n"
|
||||
"Options:\n"
|
||||
"--listen -l <ip:port> listen for incoming requests\n"
|
||||
"--bind -b <ip> bind ip used for outgoing requests\n"
|
||||
"--to -t <ip:port> destination to forward requests to\n"
|
||||
"--daemon -d daemon mode, fork into background\n"
|
||||
"--pidfile -p <file> pidfile, default: /var/run/udpxd.pid\n"
|
||||
"--user -u <user> run as user (only in daemon mode)\n"
|
||||
"--chroot -c <path> chroot to <path> (only in daemon mode)\n"
|
||||
"--help -h -? print help message\n"
|
||||
"--version -V print program version\n"
|
||||
"--verbose -v enable verbose logging\n\n"
|
||||
"Options -l and -t are mandatory.\n\n"
|
||||
"This is udpxd version %s.\n", UDPXD_VERSION
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -163,22 +163,22 @@ int main ( int argc, char* argv[] ) {
|
||||
inip = malloc(INET6_ADDRSTRLEN+1);
|
||||
inpt = malloc(6);
|
||||
if (parse_ip(optarg, inip, inpt) != 0) {
|
||||
fprintf(stderr, "Parameter -l has the format <ip-address:port>!\n");
|
||||
err = 1;
|
||||
fprintf(stderr, "Parameter -l has the format <ip-address:port>!\n");
|
||||
err = 1;
|
||||
}
|
||||
break;
|
||||
case 't':
|
||||
dstip = malloc(INET6_ADDRSTRLEN+1);
|
||||
dstpt = malloc(6);
|
||||
if (parse_ip(optarg, dstip, dstpt) != 0) {
|
||||
fprintf(stderr, "Parameter -d has the format <ip-address:port>!\n");
|
||||
err = 1;
|
||||
fprintf(stderr, "Parameter -d has the format <ip-address:port>!\n");
|
||||
err = 1;
|
||||
}
|
||||
break;
|
||||
case 'b':
|
||||
if(strlen(optarg) > INET6_ADDRSTRLEN) {
|
||||
fprintf(stderr, "Bind ip address is too long!\n");
|
||||
err = 1;
|
||||
fprintf(stderr, "Bind ip address is too long!\n");
|
||||
err = 1;
|
||||
}
|
||||
srcip = malloc(INET6_ADDRSTRLEN+1);
|
||||
strncpy(srcip, optarg, strlen(optarg));
|
||||
|
||||
2
udpxd.h
2
udpxd.h
@@ -1,7 +1,7 @@
|
||||
/*
|
||||
This file is part of udpxd.
|
||||
|
||||
Copyright (C) 2015 T.v.Dein.
|
||||
Copyright (C) 2015-2016 T.v.Dein.
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
|
||||
@@ -140,7 +140,7 @@ L<https://github.com/TLINDEN/udpxd/issues>.
|
||||
|
||||
This software is licensed under the GNU GENERAL PUBLIC LICENSE version 3.
|
||||
|
||||
Copyright (c) 2015 by T. v. Dein.
|
||||
Copyright (c) 2015-2016 by T. v. Dein.
|
||||
|
||||
This software uses B<uthash> (bundled), which is
|
||||
Copyright (c) 2003-2013 by Troy D. Hanson.
|
||||
|
||||
Reference in New Issue
Block a user