mirror of
https://github.com/yarrick/iodine.git
synced 2024-11-23 00:29:20 +02:00
Added support for choosing ip to listen on for DNS
This commit is contained in:
parent
fdb56f8e97
commit
4c0032c04c
6
dns.c
6
dns.c
|
@ -58,7 +58,7 @@ uint16_t pingid;
|
||||||
|
|
||||||
|
|
||||||
int
|
int
|
||||||
open_dns(const char *domain, int localport)
|
open_dns(const char *domain, int localport, in_addr_t listen_ip)
|
||||||
{
|
{
|
||||||
int fd;
|
int fd;
|
||||||
int flag;
|
int flag;
|
||||||
|
@ -67,9 +67,9 @@ open_dns(const char *domain, int localport)
|
||||||
bzero(&addr, sizeof(addr));
|
bzero(&addr, sizeof(addr));
|
||||||
addr.sin_family = AF_INET;
|
addr.sin_family = AF_INET;
|
||||||
addr.sin_port = htons(localport);
|
addr.sin_port = htons(localport);
|
||||||
addr.sin_addr.s_addr = htonl(INADDR_ANY);
|
addr.sin_addr.s_addr = listen_ip; // This is already network byte order, inet_addr() or constant INADDR_ANY (==0)
|
||||||
|
|
||||||
fd = socket(AF_INET, SOCK_DGRAM, 0);
|
fd = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP);
|
||||||
if(fd < 0) {
|
if(fd < 0) {
|
||||||
warn("socket");
|
warn("socket");
|
||||||
return -1;
|
return -1;
|
||||||
|
|
2
dns.h
2
dns.h
|
@ -17,7 +17,7 @@
|
||||||
#ifndef _DNS_H_
|
#ifndef _DNS_H_
|
||||||
#define _DNS_H_
|
#define _DNS_H_
|
||||||
|
|
||||||
int open_dns(const char *, int);
|
int open_dns(const char *, int, in_addr_t);
|
||||||
int dns_settarget(const char*);
|
int dns_settarget(const char*);
|
||||||
void close_dns(int);
|
void close_dns(int);
|
||||||
|
|
||||||
|
|
2
iodine.c
2
iodine.c
|
@ -255,7 +255,7 @@ main(int argc, char **argv)
|
||||||
|
|
||||||
if ((tun_fd = open_tun(device)) == -1)
|
if ((tun_fd = open_tun(device)) == -1)
|
||||||
goto cleanup1;
|
goto cleanup1;
|
||||||
if ((dns_fd = open_dns(argv[1], 0)) == -1)
|
if ((dns_fd = open_dns(argv[1], 0, INADDR_ANY)) == -1)
|
||||||
goto cleanup2;
|
goto cleanup2;
|
||||||
if (dns_settarget(argv[0]) == -1)
|
if (dns_settarget(argv[0]) == -1)
|
||||||
goto cleanup2;
|
goto cleanup2;
|
||||||
|
|
19
iodined.c
19
iodined.c
|
@ -163,7 +163,7 @@ extern char *__progname;
|
||||||
|
|
||||||
static void
|
static void
|
||||||
usage() {
|
usage() {
|
||||||
printf("Usage: %s [-v] [-h] [-f] [-u user] [-t chrootdir] [-d device] [-m mtu] "
|
printf("Usage: %s [-v] [-h] [-f] [-u user] [-t chrootdir] [-d device] [-m mtu] [-l ip address to listen on] "
|
||||||
"tunnel_ip topdomain\n", __progname);
|
"tunnel_ip topdomain\n", __progname);
|
||||||
exit(2);
|
exit(2);
|
||||||
}
|
}
|
||||||
|
@ -171,7 +171,7 @@ usage() {
|
||||||
static void
|
static void
|
||||||
help() {
|
help() {
|
||||||
printf("iodine IP over DNS tunneling server\n");
|
printf("iodine IP over DNS tunneling server\n");
|
||||||
printf("Usage: %s [-v] [-h] [-f] [-u user] [-t chrootdir] [-d device] [-m mtu] "
|
printf("Usage: %s [-v] [-h] [-f] [-u user] [-t chrootdir] [-d device] [-m mtu] [-l ip address to listen on] "
|
||||||
"tunnel_ip topdomain\n", __progname);
|
"tunnel_ip topdomain\n", __progname);
|
||||||
printf(" -v to print version info and exit\n");
|
printf(" -v to print version info and exit\n");
|
||||||
printf(" -h to print this help and exit\n");
|
printf(" -h to print this help and exit\n");
|
||||||
|
@ -180,6 +180,7 @@ help() {
|
||||||
printf(" -t dir to chroot to directory dir\n");
|
printf(" -t dir to chroot to directory dir\n");
|
||||||
printf(" -d device to set tunnel device name\n");
|
printf(" -d device to set tunnel device name\n");
|
||||||
printf(" -m mtu to set tunnel device mtu\n");
|
printf(" -m mtu to set tunnel device mtu\n");
|
||||||
|
printf(" -l ip address to listen on for incoming dns traffic (default 0.0.0.0)\n");
|
||||||
printf("tunnel_ip is the IP number of the local tunnel interface.\n");
|
printf("tunnel_ip is the IP number of the local tunnel interface.\n");
|
||||||
printf("topdomain is the FQDN that is delegated to this server.\n");
|
printf("topdomain is the FQDN that is delegated to this server.\n");
|
||||||
exit(0);
|
exit(0);
|
||||||
|
@ -205,19 +206,21 @@ main(int argc, char **argv)
|
||||||
int foreground;
|
int foreground;
|
||||||
int mtu;
|
int mtu;
|
||||||
struct passwd *pw;
|
struct passwd *pw;
|
||||||
|
in_addr_t listen_ip;
|
||||||
|
|
||||||
username = NULL;
|
username = NULL;
|
||||||
newroot = NULL;
|
newroot = NULL;
|
||||||
device = NULL;
|
device = NULL;
|
||||||
foreground = 0;
|
foreground = 0;
|
||||||
mtu = 1024;
|
mtu = 1024;
|
||||||
|
listen_ip = INADDR_ANY;
|
||||||
|
|
||||||
packetbuf.len = 0;
|
packetbuf.len = 0;
|
||||||
packetbuf.offset = 0;
|
packetbuf.offset = 0;
|
||||||
outpacket.len = 0;
|
outpacket.len = 0;
|
||||||
q.id = 0;
|
q.id = 0;
|
||||||
|
|
||||||
while ((choice = getopt(argc, argv, "vfhu:t:d:m:")) != -1) {
|
while ((choice = getopt(argc, argv, "vfhu:t:d:m:l:")) != -1) {
|
||||||
switch(choice) {
|
switch(choice) {
|
||||||
case 'v':
|
case 'v':
|
||||||
version();
|
version();
|
||||||
|
@ -240,6 +243,9 @@ main(int argc, char **argv)
|
||||||
case 'm':
|
case 'm':
|
||||||
mtu = atoi(optarg);
|
mtu = atoi(optarg);
|
||||||
break;
|
break;
|
||||||
|
case 'l':
|
||||||
|
listen_ip = inet_addr(optarg);
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
usage();
|
usage();
|
||||||
break;
|
break;
|
||||||
|
@ -270,11 +276,16 @@ main(int argc, char **argv)
|
||||||
usage();
|
usage();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (listen_ip == INADDR_NONE) {
|
||||||
|
printf("Bad IP address to listen on.\n");
|
||||||
|
usage();
|
||||||
|
}
|
||||||
|
|
||||||
if ((tun_fd = open_tun(device)) == -1)
|
if ((tun_fd = open_tun(device)) == -1)
|
||||||
goto cleanup0;
|
goto cleanup0;
|
||||||
if (tun_setip(argv[0]) != 0 || tun_setmtu(mtu) != 0)
|
if (tun_setip(argv[0]) != 0 || tun_setmtu(mtu) != 0)
|
||||||
goto cleanup1;
|
goto cleanup1;
|
||||||
if ((dnsd_fd = open_dns(argv[1], 53)) == -1)
|
if ((dnsd_fd = open_dns(argv[1], 53, listen_ip)) == -1)
|
||||||
goto cleanup2;
|
goto cleanup2;
|
||||||
|
|
||||||
my_ip = inet_addr(argv[0]);
|
my_ip = inet_addr(argv[0]);
|
||||||
|
|
Loading…
Reference in New Issue