Project import
diff --git a/6tunnel.url b/6tunnel.url
new file mode 100644
index 0000000..558ad14
--- /dev/null
+++ b/6tunnel.url
@@ -0,0 +1 @@
+git@github.com:wojtekka/6tunnel.git
\ No newline at end of file
diff --git a/6tunnel.version b/6tunnel.version
new file mode 100644
index 0000000..1e4f4c3
--- /dev/null
+++ b/6tunnel.version
@@ -0,0 +1 @@
+2d3346169da8eb89088fc5ff4d5d13e2ad8ae9f6
\ No newline at end of file
diff --git a/6tunnel/6tunnel.1 b/6tunnel/6tunnel.1
new file mode 100644
index 0000000..4cf2a30
--- /dev/null
+++ b/6tunnel/6tunnel.1
@@ -0,0 +1,168 @@
+.\"
+.\" 6tunnel v0.11
+.\" (C) Copyright 2000-2005,2013 by Wojtek Kaniewski <wojtekka@toxygen.net>
+.\"
+.TH 6TUNNEL 1 "May 25, 2013"
+.SH NAME
+6tunnel \- tunnelling for application that don't speak IPv6
+.SH SYNOPSIS
+.B 6tunnel
+[
+.B \-146dhHfv
+] [
+.BI \-u
+.IR username
+] [
+.BI \-i
+.IR password
+] [
+.BI \-I
+.IR password
+] [
+.BI \-l
+.IR local\_host
+] [
+.BI \-L
+.IR limit
+] [
+.BI \-p
+.IR pid\_file
+] [
+.BI \-m
+.IR map\_file
+]
+.IR local\_port
+.IR remote\_host
+[
+.IR remote\_port
+]
+.SH DESCRIPTION
+.B 6tunnel
+allows you to use services provided by IPv6 hosts with IPv4-only
+applications and vice-versa. It can bind to any of your IPv4 (default) or
+IPv6 addresses and forward all data to IPv4 or IPv6 (default) host. For
+example
+.IP
+.BI 6tunnel "\ " \-1 "\ " 6668 "\ " irc6.net "\ " 6667
+.LP
+will be enough to connect to IPv6 irc server with
+.IP
+.BI irc "\ " foobar "\ " localhost:6668
+.LP
+If you don't wish to run
+.B 6tunnel
+every time you want to show your :c001: or :dead: IPv6 address on IRC,
+you can use
+.B \-i
+parameter, which makes
+.B 6tunnel
+ask your client for specified password. Just run
+.IP
+.BI 6tunnel "\ " \-i "\ " dupa.8 "\ " 31337 "\ " irc6.net "\ " 6667
+.LP
+and then type
+.IP
+.BI irc "\ " foobar "\ " localhost:31337:dupa.8
+.LP
+If your IRC server requires you to send password, specify it with
+.B \-I
+parameter -- after successful proxy authentication
+.B 6tunnel
+will send it to the server.
+
+.B 6tunnel
+can also be used as a tunnel for all other combinations of IPv4 and IPv6
+endpoints. If remote host doesn't have any IPv6 addresses,
+.B 6tunnel
+will use the IPv4 one. In other cases, use
+.B \-4
+parameter which makes IPv4 address the preffered one. For IPv6-to-any tunnels
+use
+.B \-6
+which makes
+.B 6tunnel
+bind to IPv6 address.
+.SH OPTIONS
+.TP
+.B \-1
+Exit after first connection.
+.TP
+.B \-4
+Preffer IPv4 endpoint if the machine has both address types.
+.TP
+.B \-6
+Listen on IPv6 address (IPv4 is default).
+.TP
+.B \-d
+Don't detach.
+.TP
+.B \-f
+Force tunneling even if remote host is not resolvable at the execution time.
+.TP
+.B \-h
+Print hex dump of every packet received or sent (hu-huh, Beavis, he said
+hex dump!)
+.TP
+.B \-H
+Don't ignore IPv4/IPv6 resolver hints. Original versions allowed only IPv4 to IPv6
+or IPv6 to IPv4 tunnels, so this option revert such behaviour.
+.TP
+.BI \-u "\ " username
+Change UID and GID after bind().
+.TP
+.BI \-i "\ " password
+Act as an IRC proxy and require user to authenticate.
+.TP
+.BI \-I "\ " password
+If you are using
+.B 6tunnel
+as an IRC proxy and the IRC server requires you to send password, place
+it right here.
+.TP
+.BI \-l "\ " local_host
+Listen on specified address (IPv4, or IPv6 if
+.B \-6
+used).
+.TP
+.BI \-L "\ " limit
+Limit simultaneous connections.
+.TP
+.BI \-p "\ " pid_file
+Write down pid to specified file.
+.TP
+.BI \-s "\ " source_host
+Connect to the remote host using specified source address.
+.TP
+.BI \-m "\ " map_file
+Binds to specified IPv6 addresses on basis of source IPv4 address. The file
+contains one mapping per line with IPv4 source address and corresponding IPv6
+address. Only listed hosts are allowed to connect. If you want to allow any
+host, add mapping for
+.BI default
+or
+.BI 0.0.0.0
+address. Example:
+.IP
+.nf
+.ta +3i
+192.168.0.2 3ffe:8010:18::1000:2
+192.168.0.3 3ffe:8010:18::1000:3
+.fi
+.TP
+.B \-v
+Be verbose and don't detach.
+.SH SIGNALS
+Sending SIGHUP forces map file reload.
+.SH THANKS
+#ipv6 crew, Lam.
+.SH BUGS
+Terrible man page. Hex dump doesn't include IRC proxy authentication.
+IRC proxy requires your client to send password first (don't worry ircii,
+EPIC, BitchX, mIRC and many more will work). No logging except debug output.
+.SH AUTHORS
+Wojtek Kaniewski (wojtekka@toxygen.net),
+Dariusz Jackowski (ascent@linux.pl),
+Ramunas Lukosevicus (lukoramu@parok.lt),
+Roland Stigge (stigge@antcom.de)
+.SH "SEE ALSO"
+.BR ssh (1)
diff --git a/6tunnel/6tunnel.c b/6tunnel/6tunnel.c
new file mode 100644
index 0000000..1d3e70c
--- /dev/null
+++ b/6tunnel/6tunnel.c
@@ -0,0 +1,812 @@
+/*
+ * 6tunnel v0.11
+ * (C) Copyright 2000-2005,2013 by Wojtek Kaniewski <wojtekka@toxygen.net>
+ *
+ * Contributions by:
+ * - Dariusz Jackowski <ascent@linux.pl>
+ * - Ramunas Lukosevicius <lukoramu@parok.lt>
+ * - Roland Stigge <stigge@antcom.de>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License Version 2 as
+ * published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <netdb.h>
+#include <string.h>
+#include <sys/types.h>
+#include <netinet/in.h>
+#include <sys/socket.h>
+#include <arpa/inet.h>
+#include <sys/wait.h>
+#include <fcntl.h>
+#include <signal.h>
+#include <errno.h>
+#include <ctype.h>
+#include <pwd.h>
+#include <time.h>
+
+#define debug(x...) do { \
+ if (verbose) \
+ printf(x); \
+} while(0)
+
+int verbose = 0, conn_count = 0;
+int remote_port, verbose, hexdump = 0;
+int remote_hint = AF_INET6;
+int local_hint = AF_INET;
+int hint_optional = 0;
+char *remote_host, *ircpass = NULL;
+char *ircsendpass = NULL, remote[128];
+char *pid_file = NULL;
+const char *source_host;
+
+typedef struct map {
+ char *ipv4;
+ char *ipv6;
+ struct map *next;
+} map_t;
+
+map_t *map_list = NULL;
+char *map_file = NULL;
+
+char *xmalloc(int size)
+{
+ char *tmp;
+
+ if (!(tmp = malloc(size))) {
+ perror("malloc");
+ exit(1);
+ }
+
+ return tmp;
+}
+
+char *xrealloc(char *ptr, int size)
+{
+ char *tmp;
+
+ if (!(tmp = realloc(ptr, size))) {
+ perror("realloc");
+ exit(1);
+ }
+
+ return tmp;
+}
+
+char *xstrdup(const char *str)
+{
+ char *tmp;
+
+ if (!(tmp = strdup(str))) {
+ perror("strdup");
+ exit(1);
+ }
+
+ return tmp;
+}
+
+struct sockaddr *resolve_host(const char *name, int hint)
+{
+ struct addrinfo *ai = NULL, hints;
+
+ memset(&hints, 0, sizeof(hints));
+ hints.ai_family = hint;
+
+ if (getaddrinfo(name, NULL, &hints, &ai) == 0 && ai != NULL) {
+ char *tmp;
+
+ tmp = xmalloc(ai->ai_addrlen);
+ memcpy(tmp, ai->ai_addr, ai->ai_addrlen);
+
+ freeaddrinfo(ai);
+
+ return (struct sockaddr*) tmp;
+ }
+
+ /* If hints are optional, try again without them. */
+ if (hint_optional && hint != 0) {
+ struct sockaddr *res;
+
+ res = resolve_host(name, 0);
+
+ if (res != NULL) {
+ debug("warning: %s resolved ignoring hints\n", name);
+ return res;
+ }
+ }
+
+ return NULL;
+}
+
+void print_hexdump(const char *buf, int len)
+{
+ int i, j;
+
+ for (i = 0; i < ((len / 16) + ((len % 16) ? 1 : 0)); i++) {
+ printf("%.4x: ", i * 16);
+
+ for (j = 0; j < 16; j++) {
+ if (i * 16 + j < len)
+ printf("%.2x ", buf[i*16+j]);
+ else
+ printf(" ");
+ if (j == 7)
+ printf(" ");
+ }
+
+ printf(" ");
+
+ for (j = 0; j < 16; j++) {
+ if (i * 16 + j < len) {
+ char ch = buf[i * 16 + j];
+
+ printf("%c", (isprint(ch)) ? ch : '.');
+ }
+ }
+
+ printf("\n");
+ }
+}
+
+const char *map_find(const char *ipv4)
+{
+ map_t *m;
+
+ for (m = map_list; m; m = m->next) {
+ if (!strcmp(m->ipv4, ipv4))
+ return m->ipv6;
+ }
+
+ for (m = map_list; m; m = m->next) {
+ if (!strcmp(m->ipv4, "0.0.0.0") || !strcmp(m->ipv4, "default"))
+ return m->ipv6;
+ }
+
+ return source_host;
+}
+
+void make_tunnel(int rsock, const char *remote)
+{
+ char buf[4096], *outbuf = NULL, *inbuf = NULL;
+ int sock = -1, outlen = 0, inlen = 0;
+ struct sockaddr *sa = NULL;
+ const char *source;
+
+ if (map_list) {
+ if (!(source = map_find(remote))) {
+ debug("<%d> connection from unmapped address (%s), disconnecting\n", rsock, remote);
+ goto cleanup;
+ }
+
+ debug("<%d> mapped to %s\n", rsock, source);
+ } else
+ source = source_host;
+
+ if (ircpass) {
+ int i, ret;
+
+ for (i = 0; i < sizeof(buf) - 1; i++) {
+ if ((ret = read(rsock, buf + i, 1)) < 1)
+ goto cleanup;
+ if (buf[i] == '\n')
+ break;
+ }
+
+ buf[i] = 0;
+
+ if (i > 0 && buf[i - 1] == '\r')
+ buf[i - 1] = 0;
+
+ if (i == 4095 || strncasecmp(buf, "PASS ", 5)) {
+ char *tmp;
+
+ debug("<%d> irc proxy auth failed - junk\n", rsock);
+
+ tmp = "ERROR :Closing link: Make your client send password first\r\n";
+ if (write(rsock, tmp, strlen(tmp)) != strlen(tmp)) {
+ // Do nothing. We're failing anyway.
+ }
+
+ goto cleanup;
+ }
+
+ if (strcmp(buf + 5, ircpass)) {
+ char *tmp;
+
+ debug("<%d> irc proxy auth failed - password incorrect\n", rsock);
+ tmp = ":6tunnel 464 * :Password incorrect\r\nERROR :Closing link: Password incorrect\r\n";
+ if (write(rsock, tmp, strlen(tmp)) != strlen(tmp)) {
+ // Do nothing. We're failing anyway.
+ }
+
+ goto cleanup;
+ }
+
+ debug("<%d> irc proxy auth succeded\n", rsock);
+ }
+
+ if (!(sa = resolve_host(remote_host, remote_hint))) {
+ debug("<%d> unable to resolve %s\n", rsock, remote_host);
+ goto cleanup;
+ }
+
+ if ((sock = socket(sa->sa_family, SOCK_STREAM, 0)) == -1) {
+ debug("<%d> unable to create socket (%s)\n", rsock, strerror(errno));
+ goto cleanup;
+ }
+
+ free(sa);
+ sa = NULL;
+
+ if (source) {
+ if (!(sa = resolve_host(source, local_hint))) {
+ debug("<%d> unable to resolve source host (%s)\n", rsock, source);
+ goto cleanup;
+ }
+
+ if (bind(sock, sa, (local_hint == AF_INET) ? sizeof(struct sockaddr_in) : sizeof(struct sockaddr_in6))) {
+ debug("<%d> unable to bind to source host (%s)\n", rsock, source);
+ goto cleanup;
+ }
+
+ free(sa);
+ sa = NULL;
+ }
+
+ sa = resolve_host(remote_host, remote_hint);
+
+ ((struct sockaddr_in*) sa)->sin_port = htons(remote_port);
+
+ if (connect(sock, sa, (sa->sa_family == AF_INET) ? sizeof(struct sockaddr_in) : sizeof(struct sockaddr_in6))) {
+ debug("<%d> connection refused (%s,%d)\n", rsock, remote_host, remote_port);
+ goto cleanup;
+ }
+
+ free(sa);
+ sa = NULL;
+
+ debug("<%d> connected to %s,%d\n", rsock, remote_host, remote_port);
+
+ if (ircsendpass) {
+ snprintf(buf, 4096, "PASS %s\r\n", ircsendpass);
+ if (write(sock, buf, strlen(buf)) != strlen(buf))
+ goto cleanup;
+ }
+
+ for (;;) {
+ fd_set rds, wds;
+ int ret, sent;
+
+ FD_ZERO(&rds);
+ FD_SET(sock, &rds);
+ FD_SET(rsock, &rds);
+
+ FD_ZERO(&wds);
+ if (outbuf && outlen)
+ FD_SET(rsock, &wds);
+ if (inbuf && inlen)
+ FD_SET(sock, &wds);
+
+ ret = select((sock > rsock) ? (sock + 1) : (rsock + 1), &rds, &wds, NULL, NULL);
+
+ if (FD_ISSET(rsock, &wds)) {
+ sent = write(rsock, outbuf, outlen);
+
+ if (sent < 1)
+ goto cleanup;
+
+ if (sent == outlen) {
+ free(outbuf);
+ outbuf = NULL;
+ outlen = 0;
+ } else {
+ memmove(outbuf, outbuf + sent, outlen - sent);
+ outlen -= sent;
+ }
+ }
+
+ if (FD_ISSET(sock, &wds)) {
+ sent = write(sock, inbuf, inlen);
+
+ if (sent < 1)
+ goto cleanup;
+
+ if (sent == inlen) {
+ free(inbuf);
+ inbuf = NULL;
+ inlen = 0;
+ } else {
+ memmove(inbuf, inbuf + sent, inlen - sent);
+ inlen -= sent;
+ }
+ }
+
+ if (FD_ISSET(sock, &rds)) {
+ if ((ret = read(sock, buf, 4096)) < 1)
+ goto cleanup;
+
+ if (hexdump) {
+ printf("<%d> recvfrom %s,%d\n", rsock, remote_host, remote_port);
+ print_hexdump(buf, ret);
+ }
+
+ sent = write(rsock, buf, ret);
+
+ if (sent < 1)
+ goto cleanup;
+
+ if (sent < ret) {
+ outbuf = xrealloc(outbuf, outlen + ret - sent);
+ memcpy(outbuf + outlen, buf + sent, ret - sent);
+ outlen = ret - sent;
+ }
+ }
+
+ if (FD_ISSET(rsock, &rds)) {
+ if ((ret = read(rsock, buf, 4096)) < 1)
+ goto cleanup;
+
+ if (hexdump) {
+ printf("<%d> sendto %s,%d\n", rsock, remote_host, remote_port);
+ print_hexdump(buf, ret);
+ }
+
+ sent = write(sock, buf, ret);
+
+ if (sent < 1)
+ goto cleanup;
+
+ if (sent < ret) {
+ inbuf = xrealloc(inbuf, inlen + ret - sent);
+ memcpy(inbuf + inlen, buf + sent, ret - sent);
+ inlen = ret - sent;
+ }
+ }
+ }
+
+
+cleanup:
+ if (sa)
+ free(sa);
+
+ close(rsock);
+
+ if (sock != -1)
+ close(sock);
+}
+
+void usage(const char *arg0)
+{
+ fprintf(stderr,
+
+"usage: %s [-146dvhH] [-s sourcehost] [-l localhost] [-i pass]\n"
+" [-I pass] [-L limit] [-A filename] [-p pidfile]\n"
+" [-m mapfile] localport remotehost [remoteport]\n"
+"\n"
+" -1 allow only one connection and quit\n"
+" -4 prefer IPv4 endpoints\n"
+" -6 bind to IPv6 address\n"
+" -d don't detach\n"
+" -f force tunneling (even if remotehost isn't resolvable)\n"
+" -h print hex dump of packets\n"
+" -H make IPv4/IPv6 resolver hints optional\n"
+" -i act like irc proxy and ask for password\n"
+" -I send specified password to the irc server\n"
+" -l bind to specified address\n"
+" -L limit simultanous connections\n"
+" -p write down pid to specified file\n"
+" -s connect using specified address\n"
+" -m read specified IPv4-to-IPv6 map file\n"
+" -v be verbose\n"
+"\n", arg0);
+}
+
+void clear_argv(char *argv)
+{
+ int x;
+
+ for (x = 0; x < strlen(argv); x++)
+ argv[x] = 'x';
+
+ return;
+}
+
+void map_destroy(void)
+{
+ map_t *m;
+
+ debug("map_destroy()\n");
+
+ for (m = map_list; m; ) {
+ map_t *n;
+
+ free(m->ipv4);
+ free(m->ipv6);
+ n = m;
+ m = m->next;
+ free(n);
+ }
+
+ map_list = NULL;
+}
+
+void map_read(void)
+{
+ char buf[256];
+ FILE *f;
+
+ if (!map_file)
+ return;
+
+ debug("reading map from %s\n", map_file);
+
+ if (!(f = fopen(map_file, "r"))) {
+ debug("unable to read map file, ignoring\n");
+ return;
+ }
+
+ while (fgets(buf, sizeof(buf), f)) {
+ char *p, *ipv4, *ipv6;
+ map_t *m;
+
+ for (p = buf; *p == ' ' || *p == '\t'; p++);
+
+ if (!*p)
+ continue;
+
+ ipv4 = p;
+
+ for (; *p && *p != ' ' && *p != '\t'; p++);
+
+ if (!*p)
+ continue;
+
+ *p = 0;
+ p++;
+
+ for (; *p == ' ' || *p == '\t'; p++);
+
+ if (!*p)
+ continue;
+
+ ipv6 = p;
+
+ for (; *p && *p != ' ' && *p != '\t' && *p != '\r' && *p != '\n'; p++);
+
+ *p = 0;
+
+ debug("[%s] mapped to [%s]\n", ipv4, ipv6);
+
+ m = (map_t*) xmalloc(sizeof(map_t));
+ m->ipv4 = xstrdup(ipv4);
+ m->ipv6 = xstrdup(ipv6);
+ m->next = map_list;
+ map_list = m;
+ }
+
+ fclose(f);
+}
+
+void sighup()
+{
+ map_destroy();
+ map_read();
+
+ signal(SIGHUP, sighup);
+}
+
+void sigchld()
+{
+ while (waitpid(-1, NULL, WNOHANG) > 0) {
+ debug("child process exited\n");
+ conn_count--;
+ }
+
+ signal(SIGCHLD, sigchld);
+}
+
+void sigterm()
+{
+ if (pid_file)
+ unlink(pid_file);
+
+ exit(0);
+}
+
+int main(int argc, char **argv)
+{
+ int force = 0, lsock, csock, one = 0, jeden = 1, local_port;
+ int detach = 1, sa_len, conn_limit = 0, optc;
+ char *username = NULL, *bind_host = NULL;
+ struct sockaddr *sa;
+ struct sockaddr_in laddr, caddr;
+ struct sockaddr_in6 laddr6;
+ unsigned int caddrlen = sizeof(caddr);
+ struct passwd *pw = NULL;
+
+ while ((optc = getopt(argc, argv, "1dv46fHs:l:I:i:hu:m:L:A:p:")) != -1) {
+ switch (optc) {
+ case '1':
+ one = 1;
+ break;
+ case 'd':
+ detach = 0;
+ break;
+ case 'v':
+ verbose = 1;
+ break;
+ case '4':
+ break;
+ case '6':
+ remote_hint = AF_INET;
+ local_hint = AF_INET6;
+ break;
+ case 's':
+ source_host = xstrdup(optarg);
+ break;
+ case 'l':
+ bind_host = xstrdup(optarg);
+ break;
+ case 'r':
+ force = 1;
+ break;
+ case 'i':
+ ircpass = xstrdup(optarg);
+ clear_argv(argv[optind - 1]);
+ break;
+ case 'I':
+ ircsendpass = xstrdup(optarg);
+ clear_argv(argv[optind - 1]);
+ break;
+ case 'h':
+ hexdump = 1;
+ break;
+ case 'u':
+ username = xstrdup(optarg);
+ break;
+ case 'm':
+ map_file = xstrdup(optarg);
+ break;
+ case 'L':
+ conn_limit = atoi(optarg);
+ break;
+ case 'p':
+ pid_file = xstrdup(optarg);
+ break;
+ case 'H':
+ hint_optional = 1;
+ break;
+ default:
+ return 1;
+ }
+ }
+
+ if (hexdump)
+ verbose = 1;
+
+ if (verbose)
+ detach = 0;
+
+ if (detach)
+ verbose = 0;
+
+ if (argc - optind < 2) {
+ usage(argv[0]);
+ exit(1);
+ }
+
+ if (username && !(pw = getpwnam(username))) {
+ fprintf(stderr, "%s: unknown user %s\n", argv[0], username);
+ exit(1);
+ }
+
+ if (map_file)
+ map_read();
+
+ local_port = atoi(argv[optind++]);
+ remote_host = argv[optind++];
+ remote_port = (argc == optind) ? local_port : atoi(argv[optind]);
+
+ debug("resolving %s\n", remote_host);
+
+ if (!(sa = resolve_host(remote_host, remote_hint)) && !force) {
+ fprintf(stderr, "%s: unable to resolve host %s\n", argv[0], remote_host);
+ exit(1);
+ }
+
+ free(sa);
+ sa = NULL;
+
+ if (bind_host) {
+ debug("resolving %s\n", bind_host);
+
+ if (!(sa = resolve_host(bind_host, local_hint))) {
+ fprintf(stderr, "%s: unable to resolve host %s\n", argv[0], remote_host);
+ exit(1);
+ }
+ }
+
+ debug("local: %s,%d; ", (bind_host) ? bind_host : "default", local_port);
+ debug("remote: %s,%d; ", remote_host, remote_port);
+
+ if (map_file)
+ debug("source: mapped\n");
+ else
+ debug("source: %s\n", (source_host) ? source_host : "default");
+
+ if (local_hint == AF_INET) {
+ lsock = socket(PF_INET, SOCK_STREAM, 0);
+
+ memset(&laddr, 0, (sa_len = sizeof(laddr)));
+ laddr.sin_family = AF_INET;
+ laddr.sin_port = htons(local_port);
+
+ if (sa) {
+ memcpy(&laddr.sin_addr, &((struct sockaddr_in*) sa)->sin_addr, sizeof(struct in_addr));
+ free(sa);
+ }
+
+ sa = (struct sockaddr*) &laddr;
+ } else {
+ lsock = socket(PF_INET6, SOCK_STREAM, 0);
+
+ memset(&laddr6, 0, (sa_len = sizeof(laddr6)));
+ laddr6.sin6_family = AF_INET6;
+ laddr6.sin6_port = htons(local_port);
+
+ if (sa) {
+ memcpy(&laddr6.sin6_addr, &((struct sockaddr_in6*) sa)->sin6_addr, sizeof(struct in6_addr));
+ free(sa);
+ }
+
+ sa = (struct sockaddr*) &laddr6;
+ }
+
+ if (setsockopt(lsock, SOL_SOCKET, SO_REUSEADDR, &jeden, sizeof(jeden)) == -1) {
+ perror("setsockopt");
+ exit(1);
+ }
+
+ // Reuse port wasn't working when only Weave set it.
+ if (setsockopt(lsock, SOL_SOCKET, SO_REUSEPORT, &jeden, sizeof(jeden)) == -1) {
+ perror("setsockopt");
+ exit(1);
+ }
+
+ if (bind(lsock, sa, sa_len)) {
+ perror("bind");
+ exit(1);
+ }
+
+ if (listen(lsock, 100)) {
+ perror("listen");
+ exit(1);
+ }
+
+ if (detach) {
+ int i, ret;
+
+ signal(SIGHUP, sighup);
+
+ for (i = 0; i < 3; i++)
+ close(i);
+
+ ret = fork();
+
+ if (ret == -1) {
+ perror("fork");
+ exit(1);
+ }
+
+ if (ret)
+ exit(0);
+ }
+
+ if (pid_file) {
+ FILE *f = fopen(pid_file, "w");
+
+ if (!f)
+ debug("warning: cannot write to pidfile (%s)\n", strerror(errno));
+ else {
+ fprintf(f, "%d", getpid());
+ fclose(f);
+ }
+ }
+
+ if (username && ((setgid(pw->pw_gid) == -1) || (setuid(pw->pw_uid) == -1))) {
+ perror("setuid/setgid");
+ exit(1);
+ }
+
+ setsid();
+ signal(SIGCHLD, sigchld);
+ signal(SIGTERM, sigterm);
+ signal(SIGINT, sigterm);
+ signal(SIGHUP, sighup);
+
+ for (;;) {
+ int ret;
+ fd_set rds;
+
+ FD_ZERO(&rds);
+ FD_SET(lsock, &rds);
+
+ if (select(lsock + 1, &rds, NULL, NULL, NULL) == -1) {
+ if (errno == EINTR)
+ continue;
+
+ perror("select");
+ break;
+ }
+
+ if ((csock = accept(lsock, (struct sockaddr*) &caddr, &caddrlen)) == -1) {
+ perror("accept");
+ break;
+ }
+
+ inet_ntop(caddr.sin_family, (caddr.sin_family == AF_INET) ?
+ &caddr.sin_addr :
+ (void*) &(((struct sockaddr_in6*)&caddr)->sin6_addr),
+ remote, sizeof(remote));
+
+ debug("<%d> connection from %s,%d", csock, remote, ntohs(caddr.sin_port));
+
+ if (conn_limit && (conn_count >= conn_limit)) {
+ debug(" -- rejected due to limit.\n");
+ shutdown(csock, 2);
+ close(csock);
+ continue;
+ }
+
+ if (conn_limit) {
+ conn_count++;
+ debug(" (no. %d)", conn_count);
+ }
+
+ fflush(stdout);
+
+ if ((ret = fork()) == -1) {
+ debug(" -- fork() failed.\n");
+ shutdown(csock, 2);
+ close(csock);
+ continue;
+ }
+
+ if (!ret) {
+ signal(SIGHUP, SIG_IGN);
+ close(lsock);
+ debug("\n");
+ make_tunnel(csock, remote);
+ debug("<%d> connection closed\n", csock);
+ exit(0);
+ }
+
+ close(csock);
+
+ if (one) {
+ shutdown(lsock, 2);
+ close(lsock);
+ exit(0);
+ }
+
+ }
+
+ close(lsock);
+
+ exit(1);
+}
+
+
diff --git a/6tunnel/COPYING b/6tunnel/COPYING
new file mode 100644
index 0000000..5b6e7c6
--- /dev/null
+++ b/6tunnel/COPYING
@@ -0,0 +1,340 @@
+ GNU GENERAL PUBLIC LICENSE
+ Version 2, June 1991
+
+ Copyright (C) 1989, 1991 Free Software Foundation, Inc.
+ 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ Everyone is permitted to copy and distribute verbatim copies
+ of this license document, but changing it is not allowed.
+
+ Preamble
+
+ The licenses for most software are designed to take away your
+freedom to share and change it. By contrast, the GNU General Public
+License is intended to guarantee your freedom to share and change free
+software--to make sure the software is free for all its users. This
+General Public License applies to most of the Free Software
+Foundation's software and to any other program whose authors commit to
+using it. (Some other Free Software Foundation software is covered by
+the GNU Library General Public License instead.) You can apply it to
+your programs, too.
+
+ When we speak of free software, we are referring to freedom, not
+price. Our General Public Licenses are designed to make sure that you
+have the freedom to distribute copies of free software (and charge for
+this service if you wish), that you receive source code or can get it
+if you want it, that you can change the software or use pieces of it
+in new free programs; and that you know you can do these things.
+
+ To protect your rights, we need to make restrictions that forbid
+anyone to deny you these rights or to ask you to surrender the rights.
+These restrictions translate to certain responsibilities for you if you
+distribute copies of the software, or if you modify it.
+
+ For example, if you distribute copies of such a program, whether
+gratis or for a fee, you must give the recipients all the rights that
+you have. You must make sure that they, too, receive or can get the
+source code. And you must show them these terms so they know their
+rights.
+
+ We protect your rights with two steps: (1) copyright the software, and
+(2) offer you this license which gives you legal permission to copy,
+distribute and/or modify the software.
+
+ Also, for each author's protection and ours, we want to make certain
+that everyone understands that there is no warranty for this free
+software. If the software is modified by someone else and passed on, we
+want its recipients to know that what they have is not the original, so
+that any problems introduced by others will not reflect on the original
+authors' reputations.
+
+ Finally, any free program is threatened constantly by software
+patents. We wish to avoid the danger that redistributors of a free
+program will individually obtain patent licenses, in effect making the
+program proprietary. To prevent this, we have made it clear that any
+patent must be licensed for everyone's free use or not licensed at all.
+
+ The precise terms and conditions for copying, distribution and
+modification follow.
+
+ GNU GENERAL PUBLIC LICENSE
+ TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
+
+ 0. This License applies to any program or other work which contains
+a notice placed by the copyright holder saying it may be distributed
+under the terms of this General Public License. The "Program", below,
+refers to any such program or work, and a "work based on the Program"
+means either the Program or any derivative work under copyright law:
+that is to say, a work containing the Program or a portion of it,
+either verbatim or with modifications and/or translated into another
+language. (Hereinafter, translation is included without limitation in
+the term "modification".) Each licensee is addressed as "you".
+
+Activities other than copying, distribution and modification are not
+covered by this License; they are outside its scope. The act of
+running the Program is not restricted, and the output from the Program
+is covered only if its contents constitute a work based on the
+Program (independent of having been made by running the Program).
+Whether that is true depends on what the Program does.
+
+ 1. You may copy and distribute verbatim copies of the Program's
+source code as you receive it, in any medium, provided that you
+conspicuously and appropriately publish on each copy an appropriate
+copyright notice and disclaimer of warranty; keep intact all the
+notices that refer to this License and to the absence of any warranty;
+and give any other recipients of the Program a copy of this License
+along with the Program.
+
+You may charge a fee for the physical act of transferring a copy, and
+you may at your option offer warranty protection in exchange for a fee.
+
+ 2. You may modify your copy or copies of the Program or any portion
+of it, thus forming a work based on the Program, and copy and
+distribute such modifications or work under the terms of Section 1
+above, provided that you also meet all of these conditions:
+
+ a) You must cause the modified files to carry prominent notices
+ stating that you changed the files and the date of any change.
+
+ b) You must cause any work that you distribute or publish, that in
+ whole or in part contains or is derived from the Program or any
+ part thereof, to be licensed as a whole at no charge to all third
+ parties under the terms of this License.
+
+ c) If the modified program normally reads commands interactively
+ when run, you must cause it, when started running for such
+ interactive use in the most ordinary way, to print or display an
+ announcement including an appropriate copyright notice and a
+ notice that there is no warranty (or else, saying that you provide
+ a warranty) and that users may redistribute the program under
+ these conditions, and telling the user how to view a copy of this
+ License. (Exception: if the Program itself is interactive but
+ does not normally print such an announcement, your work based on
+ the Program is not required to print an announcement.)
+
+These requirements apply to the modified work as a whole. If
+identifiable sections of that work are not derived from the Program,
+and can be reasonably considered independent and separate works in
+themselves, then this License, and its terms, do not apply to those
+sections when you distribute them as separate works. But when you
+distribute the same sections as part of a whole which is a work based
+on the Program, the distribution of the whole must be on the terms of
+this License, whose permissions for other licensees extend to the
+entire whole, and thus to each and every part regardless of who wrote it.
+
+Thus, it is not the intent of this section to claim rights or contest
+your rights to work written entirely by you; rather, the intent is to
+exercise the right to control the distribution of derivative or
+collective works based on the Program.
+
+In addition, mere aggregation of another work not based on the Program
+with the Program (or with a work based on the Program) on a volume of
+a storage or distribution medium does not bring the other work under
+the scope of this License.
+
+ 3. You may copy and distribute the Program (or a work based on it,
+under Section 2) in object code or executable form under the terms of
+Sections 1 and 2 above provided that you also do one of the following:
+
+ a) Accompany it with the complete corresponding machine-readable
+ source code, which must be distributed under the terms of Sections
+ 1 and 2 above on a medium customarily used for software interchange; or,
+
+ b) Accompany it with a written offer, valid for at least three
+ years, to give any third party, for a charge no more than your
+ cost of physically performing source distribution, a complete
+ machine-readable copy of the corresponding source code, to be
+ distributed under the terms of Sections 1 and 2 above on a medium
+ customarily used for software interchange; or,
+
+ c) Accompany it with the information you received as to the offer
+ to distribute corresponding source code. (This alternative is
+ allowed only for noncommercial distribution and only if you
+ received the program in object code or executable form with such
+ an offer, in accord with Subsection b above.)
+
+The source code for a work means the preferred form of the work for
+making modifications to it. For an executable work, complete source
+code means all the source code for all modules it contains, plus any
+associated interface definition files, plus the scripts used to
+control compilation and installation of the executable. However, as a
+special exception, the source code distributed need not include
+anything that is normally distributed (in either source or binary
+form) with the major components (compiler, kernel, and so on) of the
+operating system on which the executable runs, unless that component
+itself accompanies the executable.
+
+If distribution of executable or object code is made by offering
+access to copy from a designated place, then offering equivalent
+access to copy the source code from the same place counts as
+distribution of the source code, even though third parties are not
+compelled to copy the source along with the object code.
+
+ 4. You may not copy, modify, sublicense, or distribute the Program
+except as expressly provided under this License. Any attempt
+otherwise to copy, modify, sublicense or distribute the Program is
+void, and will automatically terminate your rights under this License.
+However, parties who have received copies, or rights, from you under
+this License will not have their licenses terminated so long as such
+parties remain in full compliance.
+
+ 5. You are not required to accept this License, since you have not
+signed it. However, nothing else grants you permission to modify or
+distribute the Program or its derivative works. These actions are
+prohibited by law if you do not accept this License. Therefore, by
+modifying or distributing the Program (or any work based on the
+Program), you indicate your acceptance of this License to do so, and
+all its terms and conditions for copying, distributing or modifying
+the Program or works based on it.
+
+ 6. Each time you redistribute the Program (or any work based on the
+Program), the recipient automatically receives a license from the
+original licensor to copy, distribute or modify the Program subject to
+these terms and conditions. You may not impose any further
+restrictions on the recipients' exercise of the rights granted herein.
+You are not responsible for enforcing compliance by third parties to
+this License.
+
+ 7. If, as a consequence of a court judgment or allegation of patent
+infringement or for any other reason (not limited to patent issues),
+conditions are imposed on you (whether by court order, agreement or
+otherwise) that contradict the conditions of this License, they do not
+excuse you from the conditions of this License. If you cannot
+distribute so as to satisfy simultaneously your obligations under this
+License and any other pertinent obligations, then as a consequence you
+may not distribute the Program at all. For example, if a patent
+license would not permit royalty-free redistribution of the Program by
+all those who receive copies directly or indirectly through you, then
+the only way you could satisfy both it and this License would be to
+refrain entirely from distribution of the Program.
+
+If any portion of this section is held invalid or unenforceable under
+any particular circumstance, the balance of the section is intended to
+apply and the section as a whole is intended to apply in other
+circumstances.
+
+It is not the purpose of this section to induce you to infringe any
+patents or other property right claims or to contest validity of any
+such claims; this section has the sole purpose of protecting the
+integrity of the free software distribution system, which is
+implemented by public license practices. Many people have made
+generous contributions to the wide range of software distributed
+through that system in reliance on consistent application of that
+system; it is up to the author/donor to decide if he or she is willing
+to distribute software through any other system and a licensee cannot
+impose that choice.
+
+This section is intended to make thoroughly clear what is believed to
+be a consequence of the rest of this License.
+
+ 8. If the distribution and/or use of the Program is restricted in
+certain countries either by patents or by copyrighted interfaces, the
+original copyright holder who places the Program under this License
+may add an explicit geographical distribution limitation excluding
+those countries, so that distribution is permitted only in or among
+countries not thus excluded. In such case, this License incorporates
+the limitation as if written in the body of this License.
+
+ 9. The Free Software Foundation may publish revised and/or new versions
+of the General Public License from time to time. Such new versions will
+be similar in spirit to the present version, but may differ in detail to
+address new problems or concerns.
+
+Each version is given a distinguishing version number. If the Program
+specifies a version number of this License which applies to it and "any
+later version", you have the option of following the terms and conditions
+either of that version or of any later version published by the Free
+Software Foundation. If the Program does not specify a version number of
+this License, you may choose any version ever published by the Free Software
+Foundation.
+
+ 10. If you wish to incorporate parts of the Program into other free
+programs whose distribution conditions are different, write to the author
+to ask for permission. For software which is copyrighted by the Free
+Software Foundation, write to the Free Software Foundation; we sometimes
+make exceptions for this. Our decision will be guided by the two goals
+of preserving the free status of all derivatives of our free software and
+of promoting the sharing and reuse of software generally.
+
+ NO WARRANTY
+
+ 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
+FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN
+OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
+PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
+OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
+MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS
+TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE
+PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
+REPAIR OR CORRECTION.
+
+ 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
+WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
+REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
+INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING
+OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED
+TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY
+YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER
+PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
+POSSIBILITY OF SUCH DAMAGES.
+
+ END OF TERMS AND CONDITIONS
+
+ How to Apply These Terms to Your New Programs
+
+ If you develop a new program, and you want it to be of the greatest
+possible use to the public, the best way to achieve this is to make it
+free software which everyone can redistribute and change under these terms.
+
+ To do so, attach the following notices to the program. It is safest
+to attach them to the start of each source file to most effectively
+convey the exclusion of warranty; and each file should have at least
+the "copyright" line and a pointer to where the full notice is found.
+
+ <one line to give the program's name and a brief idea of what it does.>
+ Copyright (C) <year> <name of author>
+
+ 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
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+
+
+Also add information on how to contact you by electronic and paper mail.
+
+If the program is interactive, make it output a short notice like this
+when it starts in an interactive mode:
+
+ Gnomovision version 69, Copyright (C) year name of author
+ Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
+ This is free software, and you are welcome to redistribute it
+ under certain conditions; type `show c' for details.
+
+The hypothetical commands `show w' and `show c' should show the appropriate
+parts of the General Public License. Of course, the commands you use may
+be called something other than `show w' and `show c'; they could even be
+mouse-clicks or menu items--whatever suits your program.
+
+You should also get your employer (if you work as a programmer) or your
+school, if any, to sign a "copyright disclaimer" for the program, if
+necessary. Here is a sample; alter the names:
+
+ Yoyodyne, Inc., hereby disclaims all copyright interest in the program
+ `Gnomovision' (which makes passes at compilers) written by James Hacker.
+
+ <signature of Ty Coon>, 1 April 1989
+ Ty Coon, President of Vice
+
+This General Public License does not permit incorporating your program into
+proprietary programs. If your program is a subroutine library, you may
+consider it more useful to permit linking proprietary applications with the
+library. If this is what you want to do, use the GNU Library General
+Public License instead of this License.
diff --git a/6tunnel/ChangeLog b/6tunnel/ChangeLog
new file mode 100644
index 0000000..1eedadb
--- /dev/null
+++ b/6tunnel/ChangeLog
@@ -0,0 +1,93 @@
+0.11 (2013-05-25)
+
+Changes by Wojtek Kaniewski <wojtekka@toxygen.net>:
+- changed license to GPL version 2. There was no license information before
+ which caused confusion. Code by Tomasz Lipski <lemur@irc.pl> and awayzzz
+ <awayzzz@digibel.org> had to be removed, because their e-mail addresses
+ were dead and googling for them gave no useful information. The missing
+ features have been rewritten from scratch. If any offending code is still
+ here, please let me know. I've done my best, but I haven't used any
+ version control 5 years ago,
+- changed e-mail address,
+- ignore IPv4/IPv6 address hints when option -H is present.
+
+Changes by Ramunas Lukosevicius <lukoramu@parok.lt>
+- fixed source mapping bug,
+- SIGHUP reloads map file.
+
+Changes by Roland Stigge <stigge@antcom.de>
+- fix an error in the "hints" handling of the host resolver which confused
+ local/source and remote hint (AF_INET/AF_INET6).
+
+0.10 (2003-06-12)
+
+Changes by Wojtek Kaniewski <wojtekka@irc.pl>:
+- major code cleanup,
+- select() before accept(), so 6tunnel won't hang on sys_socketcall.
+- fixed losing data under heavy load, when write() didn't send all
+ data. unsent data is stored in a buffer,
+- autoconf,
+- supports pid file (idea by misio <monster@qm.pl>).
+
+0.09 (2001-10-18)
+
+Changes by Wojtek Kaniewski <wojtekka@irc.pl>:
+- included patch from OpenBSD port by Patroklos Argyroudis <argp@bsd.gr>.
+- fixing the fix - patch by awayzzz <awayzzz@digibel.org>.
+
+0.08 (2001-10-13)
+
+Changes by Dariusz Jackowski <ascent@linux.pl>:
+- modified IPv4 to IPv6 mapping -- better memory managing.
+
+Changes by Wojtek Kaniewski <wojtekka@irc.pl>:
+- some memory leaks fixed thanks to Sorrow The Prince <s0tp@libero.it>.
+- fixed dos condition thanks to awayzzz <awayzzz@digibel.org>.
+
+0.07 (2000-11-19)
+
+Changes by Tomasz Lipski <lemur@irc.pl>:
+- added IPv4 to IPv6 mapping table for binding to different IPv6 addresses,
+- fixed multiple connections handling for BSD,
+- fixed manpage installation path.
+
+Changes by Wojtek Kaniewski <wojtekka@irc.pl>:
+- fixed some typos,
+- connection limit (-L),
+- changes installation prefix from /usr to /usr/local.
+
+0.06 (2000-09-11)
+
+Changes by Wojtek Kaniewski <wojtekka@irc.pl>:
+- added -u, quick patch.
+
+0.05 (2000-06-25)
+
+Changes by Wojtek Kaniewski <wojtekka@irc.pl>:
+- added shadowing of args which store -i or -I passwords,
+- added changelog (huh, that was the most difficult part ;)),
+- fixed Makefile to compile propertly on BSD with native IPv6 support
+ (FreeBSD 4.0 for example).
+
+0.04 (2000-02-24)
+
+Changes by Wojtek Kaniewski <wojtekka@irc.pl>:
+- added irc proxy,
+- added hexdump of forwaded packets.
+
+0.03 (2000-02-01)
+
+Changes by Wojtek Kaniewski <wojtekka@irc.pl>:
+- added listening on IPv4 address,
+- added man page,
+- almost complete rewrite.
+
+0.02 (2000-01-13)
+
+Changes by Wojtek Kaniewski <wojtekka@irc.pl>:
+- added detaching, verbose mode.
+
+0.01 (2000-01-12)
+
+Initial release.
+
diff --git a/6tunnel/Makefile.am b/6tunnel/Makefile.am
new file mode 100644
index 0000000..c24cb9d
--- /dev/null
+++ b/6tunnel/Makefile.am
@@ -0,0 +1,7 @@
+
+bin_PROGRAMS = 6tunnel
+
+6tunnel_SOURCES = 6tunnel.c
+
+
+
diff --git a/6tunnel/TODO b/6tunnel/TODO
new file mode 100644
index 0000000..90eb215
--- /dev/null
+++ b/6tunnel/TODO
@@ -0,0 +1,2 @@
+Resolve all names after startup -- Simonas Kareiva <simonas@vusa.lt>
+UDP tunneling -- Nuno Amorim <na.amorim@gmail.com>
diff --git a/6tunnel/autogen.sh b/6tunnel/autogen.sh
new file mode 100755
index 0000000..4a37ee1
--- /dev/null
+++ b/6tunnel/autogen.sh
@@ -0,0 +1,3 @@
+#!/bin/sh
+autoreconf --install
+test x$NOCONFIGURE = x && ./configure
diff --git a/6tunnel/configure.ac b/6tunnel/configure.ac
new file mode 100644
index 0000000..94fea49
--- /dev/null
+++ b/6tunnel/configure.ac
@@ -0,0 +1,36 @@
+AC_INIT([6tunnel],[0.10],[])
+AM_INIT_AUTOMAKE([foreign silent-rules subdir-objects tar-pax])
+AC_PROG_CC
+AC_PROG_INSTALL
+AC_PROG_MAKE_SET
+AC_PATH_PROG(STRIP, strip, :)
+
+test -d /usr/local/v6/lib && LIBS="$LIBS -L/usr/local/v6/lib"
+test -d /usr/inet6/lib && LIBS="$LIBS -L/usr/inet6/lib"
+test -d /usr/local/inet6/lib && LIBS="$LIBS -L/usr/local/inet6/lib"
+
+AC_CHECK_LIB(nsl, t_accept, LIBS="$LIBS -lnsl")
+AC_CHECK_LIB(socket, socket, LIBS="$LIBS -lsocket")
+AC_CHECK_LIB(inet6, main, LIBS="$LIBS -linet6")
+
+AC_STDC_HEADERS
+AC_HAVE_HEADERS(sys/socket.h netinet/in.h arpa/inet.h netdb.h, , AC_MSG_ERROR([Socket related headers missing.]))
+AC_CHECK_FUNCS(getaddrinfo, , AC_MSG_ERROR([Your system doesn't support IPv6.]))
+
+AC_MSG_CHECKING([for AF_INET6])
+AC_TRY_COMPILE([#include <netinet/in.h>], [int x = AF_INET6;], [
+ AC_MSG_RESULT(yes)
+], [
+ AC_MSG_RESULT(no)
+ AC_MSG_ERROR([Your system doesn't support IPv6.])
+])
+
+AC_SUBST(VERSION)
+VERSION=`grep '6tunnel v' 6tunnel.c | sed 's/.*v//'`
+
+AC_CONFIG_FILES([
+ Makefile
+])
+
+AC_OUTPUT
+
diff --git a/6tunnel/contrib/cron.sh b/6tunnel/contrib/cron.sh
new file mode 100755
index 0000000..57865af
--- /dev/null
+++ b/6tunnel/contrib/cron.sh
@@ -0,0 +1,48 @@
+#!/bin/sh
+#
+# This is a script for use in crontab.
+#
+# To check for your 6tunnel every 10 minutes,
+# put this line in your crontab:
+# 0,10,20,30,40,50 * * * * /home/yourdir/6tunnel/cron.sh >/dev/null 2>&1
+#
+
+### CONFIG ###
+
+# Path to 6tunnel
+T6PATH="/home/misio/6tunnel"
+
+# Real 6tunnel file name
+T6BIN="6tunnel"
+
+# Start options
+T6OPTIONS="-4 -s very.nice.host.pl -i secretpass 19999 poznan.irc.pl 6666"
+
+# Name of pidfile
+T6PIDFILE="6tunnel.pid"
+
+### CODE ###
+
+cd $T6PATH
+if test -r $T6PATH/$T6PIDFILE; then
+ MYPID=$(cat $T6PATH/$T6PIDFILE)
+ if $(kill -CHLD $MYPID >/dev/null 2>&1)
+ then
+ exit 0
+ fi
+ echo ""
+ echo "erasing old PID file"
+ rm -f $T6PATH/$T6PIDFILE
+fi
+
+echo ""
+echo "6tunnel not running, restarting..."
+echo ""
+
+if test -x $T6BIN ;then
+ $T6PATH/$T6BIN -p $T6PIDFILE $T6OPTIONS
+ exit 0
+fi
+
+echo "error restarting 6tunnel"
+
diff --git a/6tunnel/install-sh b/6tunnel/install-sh
new file mode 100755
index 0000000..e9de238
--- /dev/null
+++ b/6tunnel/install-sh
@@ -0,0 +1,251 @@
+#!/bin/sh
+#
+# install - install a program, script, or datafile
+# This comes from X11R5 (mit/util/scripts/install.sh).
+#
+# Copyright 1991 by the Massachusetts Institute of Technology
+#
+# Permission to use, copy, modify, distribute, and sell this software and its
+# documentation for any purpose is hereby granted without fee, provided that
+# the above copyright notice appear in all copies and that both that
+# copyright notice and this permission notice appear in supporting
+# documentation, and that the name of M.I.T. not be used in advertising or
+# publicity pertaining to distribution of the software without specific,
+# written prior permission. M.I.T. makes no representations about the
+# suitability of this software for any purpose. It is provided "as is"
+# without express or implied warranty.
+#
+# Calling this script install-sh is preferred over install.sh, to prevent
+# `make' implicit rules from creating a file called install from it
+# when there is no Makefile.
+#
+# This script is compatible with the BSD install script, but was written
+# from scratch. It can only install one file at a time, a restriction
+# shared with many OS's install programs.
+
+
+# set DOITPROG to echo to test this script
+
+# Don't use :- since 4.3BSD and earlier shells don't like it.
+doit="${DOITPROG-}"
+
+
+# put in absolute paths if you don't have them in your path; or use env. vars.
+
+mvprog="${MVPROG-mv}"
+cpprog="${CPPROG-cp}"
+chmodprog="${CHMODPROG-chmod}"
+chownprog="${CHOWNPROG-chown}"
+chgrpprog="${CHGRPPROG-chgrp}"
+stripprog="${STRIPPROG-strip}"
+rmprog="${RMPROG-rm}"
+mkdirprog="${MKDIRPROG-mkdir}"
+
+transformbasename=""
+transform_arg=""
+instcmd="$mvprog"
+chmodcmd="$chmodprog 0755"
+chowncmd=""
+chgrpcmd=""
+stripcmd=""
+rmcmd="$rmprog -f"
+mvcmd="$mvprog"
+src=""
+dst=""
+dir_arg=""
+
+while [ x"$1" != x ]; do
+ case $1 in
+ -c) instcmd="$cpprog"
+ shift
+ continue;;
+
+ -d) dir_arg=true
+ shift
+ continue;;
+
+ -m) chmodcmd="$chmodprog $2"
+ shift
+ shift
+ continue;;
+
+ -o) chowncmd="$chownprog $2"
+ shift
+ shift
+ continue;;
+
+ -g) chgrpcmd="$chgrpprog $2"
+ shift
+ shift
+ continue;;
+
+ -s) stripcmd="$stripprog"
+ shift
+ continue;;
+
+ -t=*) transformarg=`echo $1 | sed 's/-t=//'`
+ shift
+ continue;;
+
+ -b=*) transformbasename=`echo $1 | sed 's/-b=//'`
+ shift
+ continue;;
+
+ *) if [ x"$src" = x ]
+ then
+ src=$1
+ else
+ # this colon is to work around a 386BSD /bin/sh bug
+ :
+ dst=$1
+ fi
+ shift
+ continue;;
+ esac
+done
+
+if [ x"$src" = x ]
+then
+ echo "install: no input file specified"
+ exit 1
+else
+ true
+fi
+
+if [ x"$dir_arg" != x ]; then
+ dst=$src
+ src=""
+
+ if [ -d $dst ]; then
+ instcmd=:
+ chmodcmd=""
+ else
+ instcmd=mkdir
+ fi
+else
+
+# Waiting for this to be detected by the "$instcmd $src $dsttmp" command
+# might cause directories to be created, which would be especially bad
+# if $src (and thus $dsttmp) contains '*'.
+
+ if [ -f $src -o -d $src ]
+ then
+ true
+ else
+ echo "install: $src does not exist"
+ exit 1
+ fi
+
+ if [ x"$dst" = x ]
+ then
+ echo "install: no destination specified"
+ exit 1
+ else
+ true
+ fi
+
+# If destination is a directory, append the input filename; if your system
+# does not like double slashes in filenames, you may need to add some logic
+
+ if [ -d $dst ]
+ then
+ dst="$dst"/`basename $src`
+ else
+ true
+ fi
+fi
+
+## this sed command emulates the dirname command
+dstdir=`echo $dst | sed -e 's,[^/]*$,,;s,/$,,;s,^$,.,'`
+
+# Make sure that the destination directory exists.
+# this part is taken from Noah Friedman's mkinstalldirs script
+
+# Skip lots of stat calls in the usual case.
+if [ ! -d "$dstdir" ]; then
+defaultIFS='
+'
+IFS="${IFS-${defaultIFS}}"
+
+oIFS="${IFS}"
+# Some sh's can't handle IFS=/ for some reason.
+IFS='%'
+set - `echo ${dstdir} | sed -e 's@/@%@g' -e 's@^%@/@'`
+IFS="${oIFS}"
+
+pathcomp=''
+
+while [ $# -ne 0 ] ; do
+ pathcomp="${pathcomp}${1}"
+ shift
+
+ if [ ! -d "${pathcomp}" ] ;
+ then
+ $mkdirprog "${pathcomp}"
+ else
+ true
+ fi
+
+ pathcomp="${pathcomp}/"
+done
+fi
+
+if [ x"$dir_arg" != x ]
+then
+ $doit $instcmd $dst &&
+
+ if [ x"$chowncmd" != x ]; then $doit $chowncmd $dst; else true ; fi &&
+ if [ x"$chgrpcmd" != x ]; then $doit $chgrpcmd $dst; else true ; fi &&
+ if [ x"$stripcmd" != x ]; then $doit $stripcmd $dst; else true ; fi &&
+ if [ x"$chmodcmd" != x ]; then $doit $chmodcmd $dst; else true ; fi
+else
+
+# If we're going to rename the final executable, determine the name now.
+
+ if [ x"$transformarg" = x ]
+ then
+ dstfile=`basename $dst`
+ else
+ dstfile=`basename $dst $transformbasename |
+ sed $transformarg`$transformbasename
+ fi
+
+# don't allow the sed command to completely eliminate the filename
+
+ if [ x"$dstfile" = x ]
+ then
+ dstfile=`basename $dst`
+ else
+ true
+ fi
+
+# Make a temp file name in the proper directory.
+
+ dsttmp=$dstdir/#inst.$$#
+
+# Move or copy the file name to the temp name
+
+ $doit $instcmd $src $dsttmp &&
+
+ trap "rm -f ${dsttmp}" 0 &&
+
+# and set any options; do chmod last to preserve setuid bits
+
+# If any of these fail, we abort the whole thing. If we want to
+# ignore errors from any of these, just make sure not to ignore
+# errors from the above "$doit $instcmd $src $dsttmp" command.
+
+ if [ x"$chowncmd" != x ]; then $doit $chowncmd $dsttmp; else true;fi &&
+ if [ x"$chgrpcmd" != x ]; then $doit $chgrpcmd $dsttmp; else true;fi &&
+ if [ x"$stripcmd" != x ]; then $doit $stripcmd $dsttmp; else true;fi &&
+ if [ x"$chmodcmd" != x ]; then $doit $chmodcmd $dsttmp; else true;fi &&
+
+# Now rename the file to the real destination.
+
+ $doit $rmcmd -f $dstdir/$dstfile &&
+ $doit $mvcmd $dsttmp $dstdir/$dstfile
+
+fi &&
+
+
+exit 0
diff --git a/Makefile b/Makefile
new file mode 100644
index 0000000..8544bc8
--- /dev/null
+++ b/Makefile
@@ -0,0 +1,95 @@
+#
+# Copyright (c) 2015 Nest, Inc.
+# All rights reserved.
+#
+# This document is the property of Nest. It is considered
+# confidential and proprietary information.
+#
+# This document may not be reproduced or transmitted in any form,
+# in whole or in part, without the express written permission of
+# Nest.
+#
+# Description: This file is the makefile for the 6tunnel, a utility
+# to forward TCP connections between ipv6 and ipv4
+#
+
+
+include pre.mak
+
+PackageName := 6tunnel
+
+PackageSourceDir := $(PackageName)
+
+PackageBuildMakefile = $(call GenerateBuildPaths,Makefile)
+
+CleanPaths += $(PackageLicenseFile)
+
+SOURCEDIRS = $(PackageSourceDir)
+$(PackageSourceDir)_RULE_TARGET = $(BuildDirectory)/configure
+
+all: $(PackageDefaultGoal)
+
+# Generate the package license contents.
+
+$(PackageSourceDir)/COPYING: $(BuildDirectory)/source
+
+$(PackageLicenseFile): $(PackageSourceDir)/COPYING
+ $(copy-result)
+
+# Extract the source from the archive and apply patches, if any.
+
+$(PackageSourceDir): $(PackageArchive)
+ $(expand-and-patch-package)
+
+# Prepare the sources.
+
+$(BuildDirectory)/source: | $(PackageSourceDir)
+ $(Verbose)touch $@
+
+# Patch the sources, if necessary.
+
+$(BuildDirectory)/patch: $(BuildDirectory)/source
+ $(Verbose)touch $@
+
+# Generate the package build makefile.
+
+# Configure the source for building.
+
+$(BuildDirectory)/configure: $(BuildDirectory)/source | $(PackageSourceDir) $(BuildDirectory) $(ResultDirectory)
+ $(Verbose)pushd $(PackageSourceDir) && autoreconf --install && popd && cd $(BuildDirectory) && \
+ $(CURDIR)/$(PackageSourceDir)/configure \
+ CC="$(CC)" AR=$(AR) RANLIB=$(RANLIB) STRIP=$(STRIP) \
+ INSTALL="$(INSTALL) $(INSTALLFLAGS)" \
+ --build=$(HostTuple) \
+ --host=$(TargetTuple) \
+ --prefix=/usr \
+ --sysconfdir=/etc \
+ --localstatedir=/var
+ $(Verbose)touch $@
+
+# Build the source.
+#
+# We have to unset MAKEFLAGS since they confuse the package build otherwise.
+
+$(BuildDirectory)/build: $(BuildDirectory)/configure | $(PackageSourceDir)
+ $(Verbose)unset MAKEFLAGS && \
+ $(MAKE) $(JOBSFLAG) -C $(BuildDirectory) all
+ $(Verbose)touch $@
+
+# Stage the build to a temporary installation area.
+#
+# We have to unset MAKEFLAGS since they confuse the package build otherwise.
+
+$(BuildDirectory)/stage: $(BuildDirectory)/build | $(ResultDirectory)
+ $(Verbose)unset MAKEFLAGS && \
+ $(MAKE) $(JOBSFLAG) -C $(BuildDirectory) DESTDIR=$(ResultDirectory) install
+ $(Verbose)touch $@
+
+.PHONY: stage
+stage: $(BuildDirectory)/stage
+
+clean:
+ $(Verbose)$(RM) $(RMFLAGS) -r $(BuildDirectory)
+ $(Verbose)$(RM) $(RMFLAGS) -r $(ResultDirectory)
+
+include post.mak