diff --git a/Makefile b/Makefile index 046b87a..8b76081 100644 --- a/Makefile +++ b/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 diff --git a/client.c b/client.c index b7342ab..b5983d7 100644 --- a/client.c +++ b/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); } } diff --git a/client.h b/client.h index e7eb815..eb2f7b6 100644 --- a/client.h +++ b/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 diff --git a/host.c b/host.c index 91a89f4..d152c80 100644 --- a/host.c +++ b/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 { diff --git a/host.h b/host.h index 4722a50..6a63a92 100644 --- a/host.h +++ b/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 diff --git a/log.c b/log.c index 3ca0dc8..58042e5 100644 --- a/log.c +++ b/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 { diff --git a/log.h b/log.h index 29b68f0..134f0a9 100644 --- a/log.h +++ b/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 diff --git a/net.c b/net.c index 557ab66..313ef6d 100644 --- a/net.c +++ b/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 { diff --git a/net.h b/net.h index 2e9821e..25156f7 100644 --- a/net.h +++ b/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 diff --git a/udpxd.1 b/udpxd.1 index 4c3dc4f..c3b5be4 100644 --- a/udpxd.1 +++ b/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. diff --git a/udpxd.c b/udpxd.c index 68cbbf9..3df9d49 100644 --- a/udpxd.c +++ b/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 listen for incoming requests\n" - "--bind -b bind ip used for outgoing requests\n" - "--to -t destination to forward requests to\n" - "--daemon -d daemon mode, fork into background\n" - "--pidfile -p pidfile, default: /var/run/udpxd.pid\n" - "--user -u run as user (only in daemon mode)\n" - "--chroot -c chroot to (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 listen for incoming requests\n" + "--bind -b bind ip used for outgoing requests\n" + "--to -t destination to forward requests to\n" + "--daemon -d daemon mode, fork into background\n" + "--pidfile -p pidfile, default: /var/run/udpxd.pid\n" + "--user -u run as user (only in daemon mode)\n" + "--chroot -c chroot to (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 !\n"); - err = 1; + fprintf(stderr, "Parameter -l has the format !\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 !\n"); - err = 1; + fprintf(stderr, "Parameter -d has the format !\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)); diff --git a/udpxd.h b/udpxd.h index 344bf8f..e850004 100644 --- a/udpxd.h +++ b/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 diff --git a/udpxd.pod b/udpxd.pod index 71936a4..78b711d 100644 --- a/udpxd.pod +++ b/udpxd.pod @@ -140,7 +140,7 @@ L. 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 (bundled), which is Copyright (c) 2003-2013 by Troy D. Hanson.