1
0
mirror of https://github.com/yarrick/iodine.git synced 2024-11-26 23:16:05 +03:00

change all printf to fprintf on stderr for #49

This commit is contained in:
Erik Ekman 2009-02-28 14:35:03 +00:00
parent cf2551cd8c
commit e7a1c784db
4 changed files with 111 additions and 111 deletions

View File

@ -115,7 +115,7 @@ open_dns(int localport, in_addr_t listen_ip)
addr.sin_addr.s_addr = listen_ip; addr.sin_addr.s_addr = listen_ip;
if ((fd = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP)) < 0) { if ((fd = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP)) < 0) {
printf("got fd %d\n", fd); fprintf(stderr, "got fd %d\n", fd);
err(1, "socket"); err(1, "socket");
} }
@ -133,7 +133,7 @@ open_dns(int localport, in_addr_t listen_ip)
if(bind(fd, (struct sockaddr*)&addr, sizeof(addr)) < 0) if(bind(fd, (struct sockaddr*)&addr, sizeof(addr)) < 0)
err(1, "bind"); err(1, "bind");
printf("Opened UDP socket\n"); fprintf(stderr, "Opened UDP socket\n");
return fd; return fd;
} }
@ -162,12 +162,12 @@ void
do_detach() do_detach()
{ {
#ifndef WINDOWS32 #ifndef WINDOWS32
printf("Detaching from terminal...\n"); fprintf(stderr, "Detaching from terminal...\n");
daemon(0, 0); daemon(0, 0);
umask(0); umask(0);
alarm(0); alarm(0);
#else #else
printf("Windows version does not support detaching\n"); fprintf(stderr, "Windows version does not support detaching\n");
#endif #endif
} }
@ -188,8 +188,8 @@ read_password(char *buf, size_t len)
int i; int i;
#endif #endif
printf("Enter password: "); fprintf(stderr, "Enter password: ");
fflush(stdout); fflush(stderr);
#ifndef WINDOWS32 #ifndef WINDOWS32
scanf("%79s", pwd); scanf("%79s", pwd);
#else #else
@ -204,7 +204,7 @@ read_password(char *buf, size_t len)
} }
} }
#endif #endif
printf("\n"); fprintf(stderr, "\n");
#ifndef WINDOWS32 #ifndef WINDOWS32
tcsetattr(0, TCSANOW, &old); tcsetattr(0, TCSANOW, &old);

View File

@ -539,7 +539,7 @@ handshake_version(int dns_fd, int *seed)
*seed = payload; *seed = payload;
userid = in[8]; userid = in[8];
printf("Version ok, both using protocol v 0x%08x. You are user #%d\n", VERSION, userid); fprintf(stderr, "Version ok, both using protocol v 0x%08x. You are user #%d\n", VERSION, userid);
return 0; return 0;
} else if (strncmp("VNAK", in, 4) == 0) { } else if (strncmp("VNAK", in, 4) == 0) {
warnx("You use protocol v 0x%08x, server uses v 0x%08x. Giving up", warnx("You use protocol v 0x%08x, server uses v 0x%08x. Giving up",
@ -553,7 +553,7 @@ handshake_version(int dns_fd, int *seed)
warnx("did not receive proper login challenge"); warnx("did not receive proper login challenge");
} }
printf("Retrying version check...\n"); fprintf(stderr, "Retrying version check...\n");
} }
warnx("couldn't connect to server"); warnx("couldn't connect to server");
return 1; return 1;
@ -597,7 +597,7 @@ handshake_login(int dns_fd, int seed)
if (read > 0) { if (read > 0) {
int netmask; int netmask;
if (strncmp("LNAK", in, 4) == 0) { if (strncmp("LNAK", in, 4) == 0) {
printf("Bad password\n"); fprintf(stderr, "Bad password\n");
return 1; return 1;
} else if (sscanf(in, "%64[^-]-%64[^-]-%d-%d", } else if (sscanf(in, "%64[^-]-%64[^-]-%d-%d",
server, client, &mtu, &netmask) == 4) { server, client, &mtu, &netmask) == 4) {
@ -611,12 +611,12 @@ handshake_login(int dns_fd, int seed)
warnx("Received handshake with bad data"); warnx("Received handshake with bad data");
} }
} else { } else {
printf("Received bad handshake\n"); fprintf(stderr, "Received bad handshake\n");
} }
} }
} }
printf("Retrying login...\n"); fprintf(stderr, "Retrying login...\n");
} }
warnx("couldn't login to server"); warnx("couldn't login to server");
return 1; return 1;
@ -650,7 +650,7 @@ handshake_case_check(int dns_fd)
if (read > 0) { if (read > 0) {
if (in[0] == 'z' || in[0] == 'Z') { if (in[0] == 'z' || in[0] == 'Z') {
if (read < (27 * 2)) { if (read < (27 * 2)) {
printf("Received short case check reply. Will use base32 encoder\n"); fprintf(stderr, "Received short case check reply. Will use base32 encoder\n");
return; return;
} else { } else {
int k; int k;
@ -666,18 +666,18 @@ handshake_case_check(int dns_fd)
return; return;
} }
} else { } else {
printf("Received bad case check reply\n"); fprintf(stderr, "Received bad case check reply\n");
} }
} else { } else {
printf("Got error on case check, will use base32\n"); fprintf(stderr, "Got error on case check, will use base32\n");
return; return;
} }
} }
printf("Retrying case check...\n"); fprintf(stderr, "Retrying case check...\n");
} }
printf("No reply on case check, continuing\n"); fprintf(stderr, "No reply on case check, continuing\n");
} }
static void static void
@ -691,7 +691,7 @@ handshake_switch_codec(int dns_fd)
int read; int read;
dataenc = get_base64_encoder(); dataenc = get_base64_encoder();
printf("Switching to %s codec\n", dataenc->name); fprintf(stderr, "Switching to %s codec\n", dataenc->name);
/* Send to server that this user will use base64 from now on */ /* Send to server that this user will use base64 from now on */
for (i=0; running && i<5 ;i++) { for (i=0; running && i<5 ;i++) {
int bits; int bits;
@ -712,26 +712,26 @@ handshake_switch_codec(int dns_fd)
if (read > 0) { if (read > 0) {
if (strncmp("BADLEN", in, 6) == 0) { if (strncmp("BADLEN", in, 6) == 0) {
printf("Server got bad message length. "); fprintf(stderr, "Server got bad message length. ");
goto codec_revert; goto codec_revert;
} else if (strncmp("BADIP", in, 5) == 0) { } else if (strncmp("BADIP", in, 5) == 0) {
printf("Server rejected sender IP address. "); fprintf(stderr, "Server rejected sender IP address. ");
goto codec_revert; goto codec_revert;
} else if (strncmp("BADCODEC", in, 8) == 0) { } else if (strncmp("BADCODEC", in, 8) == 0) {
printf("Server rejected the selected codec. "); fprintf(stderr, "Server rejected the selected codec. ");
goto codec_revert; goto codec_revert;
} }
in[read] = 0; /* zero terminate */ in[read] = 0; /* zero terminate */
printf("Server switched to codec %s\n", in); fprintf(stderr, "Server switched to codec %s\n", in);
return; return;
} }
} }
printf("Retrying codec switch...\n"); fprintf(stderr, "Retrying codec switch...\n");
} }
printf("No reply from server on codec switch. "); fprintf(stderr, "No reply from server on codec switch. ");
codec_revert: codec_revert:
printf("Falling back to base32\n"); fprintf(stderr, "Falling back to base32\n");
dataenc = get_base32_encoder(); dataenc = get_base32_encoder();
} }
@ -749,7 +749,7 @@ handshake_autoprobe_fragsize(int dns_fd)
int max_fragsize = 0; int max_fragsize = 0;
max_fragsize = 0; max_fragsize = 0;
printf("Autoprobing max downstream fragment size... (skip with -m fragsize)\n"); fprintf(stderr, "Autoprobing max downstream fragment size... (skip with -m fragsize)\n");
while (running && range > 0 && (range >= 8 || !max_fragsize)) { while (running && range > 0 && (range >= 8 || !max_fragsize)) {
for (i=0; running && i<3 ;i++) { for (i=0; running && i<3 ;i++) {
tv.tv_sec = 1; tv.tv_sec = 1;
@ -769,8 +769,8 @@ handshake_autoprobe_fragsize(int dns_fd)
int acked_fragsize = ((in[0] & 0xff) << 8) | (in[1] & 0xff); int acked_fragsize = ((in[0] & 0xff) << 8) | (in[1] & 0xff);
if (acked_fragsize == proposed_fragsize) { if (acked_fragsize == proposed_fragsize) {
if (read == proposed_fragsize) { if (read == proposed_fragsize) {
printf("%d ok.. ", acked_fragsize); fprintf(stderr, "%d ok.. ", acked_fragsize);
fflush(stdout); fflush(stderr);
max_fragsize = acked_fragsize; max_fragsize = acked_fragsize;
range >>= 1; range >>= 1;
proposed_fragsize += range; proposed_fragsize += range;
@ -780,30 +780,30 @@ handshake_autoprobe_fragsize(int dns_fd)
} }
} }
if (strncmp("BADIP", in, 5) == 0) { if (strncmp("BADIP", in, 5) == 0) {
printf("got BADIP.. "); fprintf(stderr, "got BADIP.. ");
fflush(stdout); fflush(stderr);
} }
} }
} }
} }
badlen: badlen:
printf("%d not ok.. ", proposed_fragsize); fprintf(stderr, "%d not ok.. ", proposed_fragsize);
fflush(stdout); fflush(stderr);
range >>= 1; range >>= 1;
proposed_fragsize -= range; proposed_fragsize -= range;
} }
if (!running) { if (!running) {
printf("\n"); fprintf(stderr, "\n");
warnx("stopped while autodetecting fragment size (Try probing manually with -m)"); warnx("stopped while autodetecting fragment size (Try probing manually with -m)");
return 0; return 0;
} }
if (range == 0) { if (range == 0) {
/* Tried all the way down to 2 and found no good size */ /* Tried all the way down to 2 and found no good size */
printf("\n"); fprintf(stderr, "\n");
warnx("found no accepted fragment size. (Try probing manually with -m)"); warnx("found no accepted fragment size. (Try probing manually with -m)");
return 0; return 0;
} }
printf("will use %d\n", max_fragsize); fprintf(stderr, "will use %d\n", max_fragsize);
return max_fragsize; return max_fragsize;
} }
@ -817,7 +817,7 @@ handshake_set_fragsize(int dns_fd, int fragsize)
int r; int r;
int read; int read;
printf("Setting downstream fragment size to max %d...\n", fragsize); fprintf(stderr, "Setting downstream fragment size to max %d...\n", fragsize);
for (i=0; running && i<5 ;i++) { for (i=0; running && i<5 ;i++) {
tv.tv_sec = i + 1; tv.tv_sec = i + 1;
tv.tv_usec = 0; tv.tv_usec = 0;
@ -836,10 +836,10 @@ handshake_set_fragsize(int dns_fd, int fragsize)
int accepted_fragsize; int accepted_fragsize;
if (strncmp("BADFRAG", in, 7) == 0) { if (strncmp("BADFRAG", in, 7) == 0) {
printf("Server rejected fragsize. Keeping default."); fprintf(stderr, "Server rejected fragsize. Keeping default.");
return; return;
} else if (strncmp("BADIP", in, 5) == 0) { } else if (strncmp("BADIP", in, 5) == 0) {
printf("Server rejected sender IP address.\n"); fprintf(stderr, "Server rejected sender IP address.\n");
return; return;
} }
@ -847,9 +847,9 @@ handshake_set_fragsize(int dns_fd, int fragsize)
return; return;
} }
} }
printf("Retrying set fragsize...\n"); fprintf(stderr, "Retrying set fragsize...\n");
} }
printf("No reply from server when setting fragsize. Keeping default.\n"); fprintf(stderr, "No reply from server when setting fragsize. Keeping default.\n");
} }
static int static int
@ -954,7 +954,7 @@ static void
usage() { usage() {
extern char *__progname; extern char *__progname;
printf("Usage: %s [-v] [-h] [-f] [-u user] [-t chrootdir] [-d device] " fprintf(stderr, "Usage: %s [-v] [-h] [-f] [-u user] [-t chrootdir] [-d device] "
"[-P password] [-m maxfragsize] [nameserver] topdomain\n", __progname); "[-P password] [-m maxfragsize] [nameserver] topdomain\n", __progname);
exit(2); exit(2);
} }
@ -963,19 +963,19 @@ static void
help() { help() {
extern char *__progname; extern char *__progname;
printf("iodine IP over DNS tunneling client\n"); fprintf(stderr, "iodine IP over DNS tunneling client\n");
printf("Usage: %s [-v] [-h] [-f] [-u user] [-t chrootdir] [-d device] " fprintf(stderr, "Usage: %s [-v] [-h] [-f] [-u user] [-t chrootdir] [-d device] "
"[-P password] [-m maxfragsize] [nameserver] topdomain\n", __progname); "[-P password] [-m maxfragsize] [nameserver] topdomain\n", __progname);
printf(" -v to print version info and exit\n"); fprintf(stderr, " -v to print version info and exit\n");
printf(" -h to print this help and exit\n"); fprintf(stderr, " -h to print this help and exit\n");
printf(" -f to keep running in foreground\n"); fprintf(stderr, " -f to keep running in foreground\n");
printf(" -u name to drop privileges and run as user 'name'\n"); fprintf(stderr, " -u name to drop privileges and run as user 'name'\n");
printf(" -t dir to chroot to directory dir\n"); fprintf(stderr, " -t dir to chroot to directory dir\n");
printf(" -d device to set tunnel device name\n"); fprintf(stderr, " -d device to set tunnel device name\n");
printf(" -P password used for authentication (max 32 chars will be used)\n"); fprintf(stderr, " -P password used for authentication (max 32 chars will be used)\n");
printf(" -m maxfragsize, to limit size of downstream packets\n"); fprintf(stderr, " -m maxfragsize, to limit size of downstream packets\n");
printf("nameserver is the IP number of the relaying nameserver, if absent /etc/resolv.conf is used\n"); fprintf(stderr, "nameserver is the IP number of the relaying nameserver, if absent /etc/resolv.conf is used\n");
printf("topdomain is the FQDN that is delegated to the tunnel endpoint.\n"); fprintf(stderr, "topdomain is the FQDN that is delegated to the tunnel endpoint.\n");
exit(0); exit(0);
} }
@ -986,8 +986,8 @@ version() {
svnver = "$Rev$ from $Date$"; svnver = "$Rev$ from $Date$";
printf("iodine IP over DNS tunneling client\n"); fprintf(stderr, "iodine IP over DNS tunneling client\n");
printf("SVN version: %s\n", svnver); fprintf(stderr, "SVN version: %s\n", svnver);
exit(0); exit(0);
} }
@ -1139,7 +1139,7 @@ main(int argc, char **argv)
if(handshake(dns_fd, autodetect_frag_size, max_downstream_frag_size)) if(handshake(dns_fd, autodetect_frag_size, max_downstream_frag_size))
goto cleanup2; goto cleanup2;
printf("Sending queries for %s to %s\n", topdomain, nameserv_addr); fprintf(stderr, "Sending queries for %s to %s\n", topdomain, nameserv_addr);
if (foreground == 0) if (foreground == 0)
do_detach(); do_detach();

View File

@ -238,7 +238,7 @@ send_chunk(int dns_fd, int userid) {
((users[userid].outpacket.fragment & 15) << 1) | (last & 1); ((users[userid].outpacket.fragment & 15) << 1) | (last & 1);
if (debug >= 1) { if (debug >= 1) {
printf("OUT pkt seq# %d, frag %d (last=%d), offset %d, fragsize %d, total %d, to user %d\n", fprintf(stderr, "OUT pkt seq# %d, frag %d (last=%d), offset %d, fragsize %d, total %d, to user %d\n",
users[userid].outpacket.seqno & 7, users[userid].outpacket.fragment & 15, users[userid].outpacket.seqno & 7, users[userid].outpacket.fragment & 15,
last, users[userid].outpacket.offset, datalen, users[userid].outpacket.len, userid); last, users[userid].outpacket.offset, datalen, users[userid].outpacket.len, userid);
} }
@ -482,7 +482,7 @@ handle_null_request(int tun_fd, int dns_fd, struct query *q, int domain_len)
} }
if (debug >= 1) { if (debug >= 1) {
printf("PING pkt from user %d\n", userid); fprintf(stderr, "PING pkt from user %d\n", userid);
} }
if (users[userid].q.id != 0) { if (users[userid].q.id != 0) {
@ -532,7 +532,7 @@ handle_null_request(int tun_fd, int dns_fd, struct query *q, int domain_len)
up_frag <= users[userid].inpacket.fragment) { up_frag <= users[userid].inpacket.fragment) {
/* Got repeated old packet, skip it */ /* Got repeated old packet, skip it */
if (debug >= 1) { if (debug >= 1) {
printf("IN pkt seq# %d, frag %d, dropped duplicate\n", fprintf(stderr, "IN pkt seq# %d, frag %d, dropped duplicate\n",
up_seq, up_frag); up_seq, up_frag);
} }
/* Update seqno and maybe send immediate response packet */ /* Update seqno and maybe send immediate response packet */
@ -557,7 +557,7 @@ handle_null_request(int tun_fd, int dns_fd, struct query *q, int domain_len)
users[userid].inpacket.offset += read; users[userid].inpacket.offset += read;
if (debug >= 1) { if (debug >= 1) {
printf("IN pkt seq# %d, frag %d (last=%d), fragsize %d, total %d, from user %d\n", fprintf(stderr, "IN pkt seq# %d, frag %d (last=%d), fragsize %d, total %d, from user %d\n",
up_seq, up_frag, lastfrag, read, users[userid].inpacket.len, userid); up_seq, up_frag, lastfrag, read, users[userid].inpacket.len, userid);
} }
@ -583,7 +583,7 @@ handle_null_request(int tun_fd, int dns_fd, struct query *q, int domain_len)
} }
} }
} else { } else {
printf("Discarded data, uncompress() result: %d\n", ret); fprintf(stderr, "Discarded data, uncompress() result: %d\n", ret);
} }
users[userid].inpacket.len = users[userid].inpacket.offset = 0; users[userid].inpacket.len = users[userid].inpacket.offset = 0;
} }
@ -608,7 +608,7 @@ handle_ns_request(int dns_fd, struct query *q)
if (debug >= 2) { if (debug >= 2) {
struct sockaddr_in *tempin; struct sockaddr_in *tempin;
tempin = (struct sockaddr_in *) &(q->from); tempin = (struct sockaddr_in *) &(q->from);
printf("TX: client %s, type %d, name %s, %d bytes NS reply\n", fprintf(stderr, "TX: client %s, type %d, name %s, %d bytes NS reply\n",
inet_ntoa(tempin->sin_addr), q->type, q->name, len); inet_ntoa(tempin->sin_addr), q->type, q->name, len);
} }
if (sendto(dns_fd, buf, len, 0, (struct sockaddr*)&q->from, q->fromlen) <= 0) { if (sendto(dns_fd, buf, len, 0, (struct sockaddr*)&q->from, q->fromlen) <= 0) {
@ -639,7 +639,7 @@ forward_query(int bind_fd, struct query *q)
myaddr->sin_port = htons(bind_port); myaddr->sin_port = htons(bind_port);
if (debug >= 2) { if (debug >= 2) {
printf("TX: NS reply \n"); fprintf(stderr, "TX: NS reply \n");
} }
if (sendto(bind_fd, buf, len, 0, (struct sockaddr*)&q->from, q->fromlen) <= 0) { if (sendto(bind_fd, buf, len, 0, (struct sockaddr*)&q->from, q->fromlen) <= 0) {
@ -667,20 +667,20 @@ tunnel_bind(int bind_fd, int dns_fd)
id = dns_get_id(packet, r); id = dns_get_id(packet, r);
if (debug >= 2) { if (debug >= 2) {
printf("RX: Got response on query %u from DNS\n", (id & 0xFFFF)); fprintf(stderr, "RX: Got response on query %u from DNS\n", (id & 0xFFFF));
} }
/* Get sockaddr from id */ /* Get sockaddr from id */
fw_query_get(id, &query); fw_query_get(id, &query);
if (!query && debug >= 2) { if (!query && debug >= 2) {
printf("Lost sender of id %u, dropping reply\n", (id & 0xFFFF)); fprintf(stderr, "Lost sender of id %u, dropping reply\n", (id & 0xFFFF));
return 0; return 0;
} }
if (debug >= 2) { if (debug >= 2) {
struct sockaddr_in *in; struct sockaddr_in *in;
in = (struct sockaddr_in *) &(query->addr); in = (struct sockaddr_in *) &(query->addr);
printf("TX: client %s id %u, %d bytes\n", fprintf(stderr, "TX: client %s id %u, %d bytes\n",
inet_ntoa(in->sin_addr), (id & 0xffff), r); inet_ntoa(in->sin_addr), (id & 0xffff), r);
} }
@ -707,7 +707,7 @@ tunnel_dns(int tun_fd, int dns_fd, int bind_fd)
if (debug >= 2) { if (debug >= 2) {
struct sockaddr_in *tempin; struct sockaddr_in *tempin;
tempin = (struct sockaddr_in *) &(q.from); tempin = (struct sockaddr_in *) &(q.from);
printf("RX: client %s, type %d, name %s\n", fprintf(stderr, "RX: client %s, type %d, name %s\n",
inet_ntoa(tempin->sin_addr), q.type, q.name); inet_ntoa(tempin->sin_addr), q.type, q.name);
} }
@ -878,7 +878,7 @@ write_dns(int fd, struct query *q, char *data, int datalen)
if (debug >= 2) { if (debug >= 2) {
struct sockaddr_in *tempin; struct sockaddr_in *tempin;
tempin = (struct sockaddr_in *) &(q->from); tempin = (struct sockaddr_in *) &(q->from);
printf("TX: client %s, type %d, name %s, %d bytes data\n", fprintf(stderr, "TX: client %s, type %d, name %s, %d bytes data\n",
inet_ntoa(tempin->sin_addr), q->type, q->name, datalen); inet_ntoa(tempin->sin_addr), q->type, q->name, datalen);
} }
@ -889,7 +889,7 @@ static void
usage() { usage() {
extern char *__progname; extern char *__progname;
printf("Usage: %s [-v] [-h] [-c] [-s] [-f] [-D] [-u user] " fprintf(stderr, "Usage: %s [-v] [-h] [-c] [-s] [-f] [-D] [-u user] "
"[-t chrootdir] [-d device] [-m mtu] " "[-t chrootdir] [-d device] [-m mtu] "
"[-l ip address to listen on] [-p port] [-n external ip] [-b dnsport] [-P password]" "[-l ip address to listen on] [-p port] [-n external ip] [-b dnsport] [-P password]"
" tunnel_ip[/netmask] topdomain\n", __progname); " tunnel_ip[/netmask] topdomain\n", __progname);
@ -900,31 +900,31 @@ static void
help() { help() {
extern char *__progname; extern char *__progname;
printf("iodine IP over DNS tunneling server\n"); fprintf(stderr, "iodine IP over DNS tunneling server\n");
printf("Usage: %s [-v] [-h] [-c] [-s] [-f] [-D] [-u user] " fprintf(stderr, "Usage: %s [-v] [-h] [-c] [-s] [-f] [-D] [-u user] "
"[-t chrootdir] [-d device] [-m mtu] " "[-t chrootdir] [-d device] [-m mtu] "
"[-l ip address to listen on] [-p port] [-n external ip] [-b dnsport] [-P password]" "[-l ip address to listen on] [-p port] [-n external ip] [-b dnsport] [-P password]"
" tunnel_ip[/netmask] topdomain\n", __progname); " tunnel_ip[/netmask] topdomain\n", __progname);
printf(" -v to print version info and exit\n"); fprintf(stderr, " -v to print version info and exit\n");
printf(" -h to print this help and exit\n"); fprintf(stderr, " -h to print this help and exit\n");
printf(" -c to disable check of client IP/port on each request\n"); fprintf(stderr, " -c to disable check of client IP/port on each request\n");
printf(" -s to skip creating and configuring the tun device, " fprintf(stderr, " -s to skip creating and configuring the tun device, "
"which then has to be created manually\n"); "which then has to be created manually\n");
printf(" -f to keep running in foreground\n"); fprintf(stderr, " -f to keep running in foreground\n");
printf(" -D to increase debug level\n"); fprintf(stderr, " -D to increase debug level\n");
printf(" -u name to drop privileges and run as user 'name'\n"); fprintf(stderr, " -u name to drop privileges and run as user 'name'\n");
printf(" -t dir to chroot to directory dir\n"); fprintf(stderr, " -t dir to chroot to directory dir\n");
printf(" -d device to set tunnel device name\n"); fprintf(stderr, " -d device to set tunnel device name\n");
printf(" -m mtu to set tunnel device mtu\n"); fprintf(stderr, " -m mtu to set tunnel device mtu\n");
printf(" -l ip address to listen on for incoming dns traffic " fprintf(stderr, " -l ip address to listen on for incoming dns traffic "
"(default 0.0.0.0)\n"); "(default 0.0.0.0)\n");
printf(" -p port to listen on for incoming dns traffic (default 53)\n"); fprintf(stderr, " -p port to listen on for incoming dns traffic (default 53)\n");
printf(" -n ip to respond with to NS queries\n"); fprintf(stderr, " -n ip to respond with to NS queries\n");
printf(" -b port to forward normal DNS queries to (on localhost)\n"); fprintf(stderr, " -b port to forward normal DNS queries to (on localhost)\n");
printf(" -P password used for authentication (max 32 chars will be used)\n"); fprintf(stderr, " -P password used for authentication (max 32 chars will be used)\n");
printf("tunnel_ip is the IP number of the local tunnel interface.\n"); fprintf(stderr, "tunnel_ip is the IP number of the local tunnel interface.\n");
printf(" /netmask sets the size of the tunnel network.\n"); fprintf(stderr, " /netmask sets the size of the tunnel network.\n");
printf("topdomain is the FQDN that is delegated to this server.\n"); fprintf(stderr, "topdomain is the FQDN that is delegated to this server.\n");
exit(0); exit(0);
} }
@ -932,8 +932,8 @@ static void
version() { version() {
char *svnver; char *svnver;
svnver = "$Rev$ from $Date$"; svnver = "$Rev$ from $Date$";
printf("iodine IP over DNS tunneling server\n"); fprintf(stderr, "iodine IP over DNS tunneling server\n");
printf("SVN version: %s\n", svnver); fprintf(stderr, "SVN version: %s\n", svnver);
exit(0); exit(0);
} }
@ -1112,18 +1112,18 @@ main(int argc, char **argv)
usage(); usage();
/* NOTREACHED */ /* NOTREACHED */
} }
printf("Requests for domains outside of %s will be forwarded to port %d\n", fprintf(stderr, "Requests for domains outside of %s will be forwarded to port %d\n",
topdomain, bind_port); topdomain, bind_port);
} }
if (port != 53) { if (port != 53) {
printf("ALERT! Other dns servers expect you to run on port 53.\n"); fprintf(stderr, "ALERT! Other dns servers expect you to run on port 53.\n");
printf("You must manually forward port 53 to port %d for things to work.\n", port); fprintf(stderr, "You must manually forward port 53 to port %d for things to work.\n", port);
} }
if (debug) { if (debug) {
printf("Debug level %d enabled, will stay in foreground.\n", debug); fprintf(stderr, "Debug level %d enabled, will stay in foreground.\n", debug);
printf("Add more -D switches to set higher debug level.\n"); fprintf(stderr, "Add more -D switches to set higher debug level.\n");
foreground = 1; foreground = 1;
} }
@ -1160,10 +1160,10 @@ main(int argc, char **argv)
created_users = init_users(my_ip, netmask); created_users = init_users(my_ip, netmask);
if (created_users < USERS) { if (created_users < USERS) {
printf("Limiting to %d simultaneous users because of netmask /%d\n", fprintf(stderr, "Limiting to %d simultaneous users because of netmask /%d\n",
created_users, netmask); created_users, netmask);
} }
printf("Listening to dns for domain %s\n", topdomain); fprintf(stderr, "Listening to dns for domain %s\n", topdomain);
if (foreground == 0) if (foreground == 0)
do_detach(); do_detach();

View File

@ -85,7 +85,7 @@ open_tun(const char *tun_device)
if_name[sizeof(if_name)-1] = '\0'; if_name[sizeof(if_name)-1] = '\0';
if (ioctl(tun_fd, TUNSETIFF, (void *) &ifreq) != -1) { if (ioctl(tun_fd, TUNSETIFF, (void *) &ifreq) != -1) {
printf("Opened %s\n", ifreq.ifr_name); fprintf(stderr, "Opened %s\n", ifreq.ifr_name);
return tun_fd; return tun_fd;
} }
@ -98,7 +98,7 @@ open_tun(const char *tun_device)
snprintf(ifreq.ifr_name, IFNAMSIZ, "dns%d", i); snprintf(ifreq.ifr_name, IFNAMSIZ, "dns%d", i);
if (ioctl(tun_fd, TUNSETIFF, (void *) &ifreq) != -1) { if (ioctl(tun_fd, TUNSETIFF, (void *) &ifreq) != -1) {
printf("Opened %s\n", ifreq.ifr_name); fprintf(stderr, "Opened %s\n", ifreq.ifr_name);
snprintf(if_name, sizeof(if_name), "dns%d", i); snprintf(if_name, sizeof(if_name), "dns%d", i);
return tun_fd; return tun_fd;
} }
@ -133,14 +133,14 @@ open_tun(const char *tun_device)
return -1; return -1;
} }
printf("Opened %s\n", tun_name); fprintf(stderr, "Opened %s\n", tun_name);
return tun_fd; return tun_fd;
} else { } else {
for (i = 0; i < TUN_MAX_TRY; i++) { for (i = 0; i < TUN_MAX_TRY; i++) {
snprintf(tun_name, sizeof(tun_name), "/dev/tun%d", i); snprintf(tun_name, sizeof(tun_name), "/dev/tun%d", i);
if ((tun_fd = open(tun_name, O_RDWR)) >= 0) { if ((tun_fd = open(tun_name, O_RDWR)) >= 0) {
printf("Opened %s\n", tun_name); fprintf(stderr, "Opened %s\n", tun_name);
snprintf(if_name, sizeof(if_name), "tun%d", i); snprintf(if_name, sizeof(if_name), "tun%d", i);
return tun_fd; return tun_fd;
} }
@ -270,7 +270,7 @@ open_tun(const char *tun_device)
} }
snprintf(tapfile, sizeof(tapfile), "%s%s.tap", TAP_DEVICE_SPACE, adapter); snprintf(tapfile, sizeof(tapfile), "%s%s.tap", TAP_DEVICE_SPACE, adapter);
printf("Opening device %s\n", tapfile); fprintf(stderr, "Opening device %s\n", tapfile);
dev_handle = CreateFile(tapfile, GENERIC_WRITE | GENERIC_READ, 0, 0, OPEN_EXISTING, FILE_ATTRIBUTE_SYSTEM | FILE_FLAG_OVERLAPPED, NULL); dev_handle = CreateFile(tapfile, GENERIC_WRITE | GENERIC_READ, 0, 0, OPEN_EXISTING, FILE_ATTRIBUTE_SYSTEM | FILE_FLAG_OVERLAPPED, NULL);
if (dev_handle == INVALID_HANDLE_VALUE) { if (dev_handle == INVALID_HANDLE_VALUE) {
return -1; return -1;
@ -394,7 +394,7 @@ tun_setip(const char *ip, int netbits)
net.s_addr = htonl(netmask); net.s_addr = htonl(netmask);
if (inet_addr(ip) == INADDR_NONE) { if (inet_addr(ip) == INADDR_NONE) {
printf("Invalid IP: %s!\n", ip); fprintf(stderr, "Invalid IP: %s!\n", ip);
return 1; return 1;
} }
#ifndef WINDOWS32 #ifndef WINDOWS32
@ -405,7 +405,7 @@ tun_setip(const char *ip, int netbits)
ip, ip,
inet_ntoa(net)); inet_ntoa(net));
printf("Setting IP of %s to %s\n", if_name, ip); fprintf(stderr, "Setting IP of %s to %s\n", if_name, ip);
#ifndef LINUX #ifndef LINUX
r = system(cmdline); r = system(cmdline);
if(r != 0) { if(r != 0) {
@ -415,18 +415,18 @@ tun_setip(const char *ip, int netbits)
"/sbin/route add %s/%d %s", "/sbin/route add %s/%d %s",
ip, netbits, ip); ip, netbits, ip);
} }
printf("Adding route %s/%d to %s\n", ip, netbits, ip); fprintf(stderr, "Adding route %s/%d to %s\n", ip, netbits, ip);
#endif #endif
return system(cmdline); return system(cmdline);
#else /* WINDOWS32 */ #else /* WINDOWS32 */
/* Set device as connected */ /* Set device as connected */
printf("Enabling interface '%s'\n", if_name); fprintf(stderr, "Enabling interface '%s'\n", if_name);
status = 1; status = 1;
r = DeviceIoControl(dev_handle, TAP_IOCTL_SET_MEDIA_STATUS, &status, r = DeviceIoControl(dev_handle, TAP_IOCTL_SET_MEDIA_STATUS, &status,
sizeof(status), &status, sizeof(status), &len, NULL); sizeof(status), &status, sizeof(status), &len, NULL);
if (!r) { if (!r) {
printf("Failed to enable interface\n"); fprintf(stderr, "Failed to enable interface\n");
return -1; return -1;
} }
@ -442,12 +442,12 @@ tun_setip(const char *ip, int netbits)
r = DeviceIoControl(dev_handle, TAP_IOCTL_CONFIG_TUN, &ipdata, r = DeviceIoControl(dev_handle, TAP_IOCTL_CONFIG_TUN, &ipdata,
sizeof(ipdata), &ipdata, sizeof(ipdata), &len, NULL); sizeof(ipdata), &ipdata, sizeof(ipdata), &len, NULL);
if (!r) { if (!r) {
printf("Failed to set interface in TUN mode\n"); fprintf(stderr, "Failed to set interface in TUN mode\n");
return -1; return -1;
} }
/* use netsh to set ip address */ /* use netsh to set ip address */
printf("Setting IP of interface '%s' to %s (can take a few seconds)...\n", if_name, ip); fprintf(stderr, "Setting IP of interface '%s' to %s (can take a few seconds)...\n", if_name, ip);
snprintf(cmdline, sizeof(cmdline), "netsh interface ip set address \"%s\" static %s %s", snprintf(cmdline, sizeof(cmdline), "netsh interface ip set address \"%s\" static %s %s",
if_name, ip, inet_ntoa(net)); if_name, ip, inet_ntoa(net));
return system(cmdline); return system(cmdline);
@ -466,7 +466,7 @@ tun_setmtu(const unsigned mtu)
if_name, if_name,
mtu); mtu);
printf("Setting MTU of %s to %u\n", if_name, mtu); fprintf(stderr, "Setting MTU of %s to %u\n", if_name, mtu);
return system(cmdline); return system(cmdline);
} else { } else {
warn("MTU out of range: %u\n", mtu); warn("MTU out of range: %u\n", mtu);