Allow bind port and listen port to be the same if listenip doesnt include localhost. Also remove newlines from warnx

This commit is contained in:
Erik Ekman 2009-07-16 08:44:04 +00:00 committed by Erik Ekman
parent d5acb508bc
commit a62ae8e562

View file

@ -1172,43 +1172,50 @@ main(int argc, char **argv)
my_ip = inet_addr(argv[0]); my_ip = inet_addr(argv[0]);
if (my_ip == INADDR_NONE) { if (my_ip == INADDR_NONE) {
warnx("Bad IP address to use inside tunnel.\n"); warnx("Bad IP address to use inside tunnel.");
usage(); usage();
} }
topdomain = strdup(argv[1]); topdomain = strdup(argv[1]);
if(strlen(topdomain) <= 128) { if(strlen(topdomain) <= 128) {
if(check_topdomain(topdomain)) { if(check_topdomain(topdomain)) {
warnx("Topdomain contains invalid characters.\n"); warnx("Topdomain contains invalid characters.");
usage(); usage();
} }
} else { } else {
warnx("Use a topdomain max 128 chars long.\n"); warnx("Use a topdomain max 128 chars long.");
usage(); usage();
} }
if (username != NULL) { if (username != NULL) {
#ifndef WINDOWS32 #ifndef WINDOWS32
if ((pw = getpwnam(username)) == NULL) { if ((pw = getpwnam(username)) == NULL) {
warnx("User %s does not exist!\n", username); warnx("User %s does not exist!", username);
usage(); usage();
} }
#endif #endif
} }
if (mtu <= 0) { if (mtu <= 0) {
warnx("Bad MTU given.\n"); warnx("Bad MTU given.");
usage(); usage();
} }
if(port < 1 || port > 65535) { if(port < 1 || port > 65535) {
warnx("Bad port number given.\n"); warnx("Bad port number given.");
usage(); usage();
} }
if(bind_enable) { if(bind_enable) {
if (bind_port < 1 || bind_port > 65535 || bind_port == port) { if (bind_port < 1 || bind_port > 65535) {
warnx("Bad DNS server port number given.\n"); warnx("Bad DNS server port number given.");
usage();
/* NOTREACHED */
}
/* Avoid forwarding loops */
if (bind_port == port && (listen_ip == INADDR_ANY || listen_ip == htonl(0x7f000001L))) {
warnx("Forward port is same as listen port (%d), will create a loop!", bind_port);
fprintf(stderr, "Use -l to set listen ip to avoid this.\n");
usage(); usage();
/* NOTREACHED */ /* NOTREACHED */
} }
@ -1228,16 +1235,16 @@ main(int argc, char **argv)
} }
if (listen_ip == INADDR_NONE) { if (listen_ip == INADDR_NONE) {
warnx("Bad IP address to listen on.\n"); warnx("Bad IP address to listen on.");
usage(); usage();
} }
if (ns_ip == INADDR_NONE) { if (ns_ip == INADDR_NONE) {
warnx("Bad IP address to return as nameserver.\n"); warnx("Bad IP address to return as nameserver.");
usage(); usage();
} }
if (netmask > 30 || netmask < 8) { if (netmask > 30 || netmask < 8) {
warnx("Bad netmask (%d bits). Use 8-30 bits.\n", netmask); warnx("Bad netmask (%d bits). Use 8-30 bits.", netmask);
usage(); usage();
} }