mirror of
https://github.com/yarrick/iodine.git
synced 2024-11-23 18:15:13 +00: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
|
||||
open_dns(const char *domain, int localport)
|
||||
open_dns(const char *domain, int localport, in_addr_t listen_ip)
|
||||
{
|
||||
int fd;
|
||||
int flag;
|
||||
@ -67,9 +67,9 @@ open_dns(const char *domain, int localport)
|
||||
bzero(&addr, sizeof(addr));
|
||||
addr.sin_family = AF_INET;
|
||||
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) {
|
||||
warn("socket");
|
||||
return -1;
|
||||
|
2
dns.h
2
dns.h
@ -17,7 +17,7 @@
|
||||
#ifndef _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*);
|
||||
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)
|
||||
goto cleanup1;
|
||||
if ((dns_fd = open_dns(argv[1], 0)) == -1)
|
||||
if ((dns_fd = open_dns(argv[1], 0, INADDR_ANY)) == -1)
|
||||
goto cleanup2;
|
||||
if (dns_settarget(argv[0]) == -1)
|
||||
goto cleanup2;
|
||||
|
19
iodined.c
19
iodined.c
@ -163,7 +163,7 @@ extern char *__progname;
|
||||
|
||||
static void
|
||||
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);
|
||||
exit(2);
|
||||
}
|
||||
@ -171,7 +171,7 @@ usage() {
|
||||
static void
|
||||
help() {
|
||||
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);
|
||||
printf(" -v to print version info 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(" -d device to set tunnel device name\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("topdomain is the FQDN that is delegated to this server.\n");
|
||||
exit(0);
|
||||
@ -205,19 +206,21 @@ main(int argc, char **argv)
|
||||
int foreground;
|
||||
int mtu;
|
||||
struct passwd *pw;
|
||||
in_addr_t listen_ip;
|
||||
|
||||
username = NULL;
|
||||
newroot = NULL;
|
||||
device = NULL;
|
||||
foreground = 0;
|
||||
mtu = 1024;
|
||||
listen_ip = INADDR_ANY;
|
||||
|
||||
packetbuf.len = 0;
|
||||
packetbuf.offset = 0;
|
||||
outpacket.len = 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) {
|
||||
case 'v':
|
||||
version();
|
||||
@ -240,6 +243,9 @@ main(int argc, char **argv)
|
||||
case 'm':
|
||||
mtu = atoi(optarg);
|
||||
break;
|
||||
case 'l':
|
||||
listen_ip = inet_addr(optarg);
|
||||
break;
|
||||
default:
|
||||
usage();
|
||||
break;
|
||||
@ -270,11 +276,16 @@ main(int argc, char **argv)
|
||||
usage();
|
||||
}
|
||||
|
||||
if (listen_ip == INADDR_NONE) {
|
||||
printf("Bad IP address to listen on.\n");
|
||||
usage();
|
||||
}
|
||||
|
||||
if ((tun_fd = open_tun(device)) == -1)
|
||||
goto cleanup0;
|
||||
if (tun_setip(argv[0]) != 0 || tun_setmtu(mtu) != 0)
|
||||
goto cleanup1;
|
||||
if ((dnsd_fd = open_dns(argv[1], 53)) == -1)
|
||||
if ((dnsd_fd = open_dns(argv[1], 53, listen_ip)) == -1)
|
||||
goto cleanup2;
|
||||
|
||||
my_ip = inet_addr(argv[0]);
|
||||
|
Loading…
Reference in New Issue
Block a user