From ce225e0b100c6334e8e17aaa45a15f8010c084cf Mon Sep 17 00:00:00 2001 From: Roger Wolff Date: Sun, 10 Feb 2002 00:00:00 +0000 Subject: [PATCH] mtr v0.46 - Included patch to be able to specify outgoing interface address. source: ftp://ftp.bitwizard.nl/mtr/mtr-0.46.tar.gz --- AUTHORS | 2 +- ChangeLog | 3 +++ NEWS | 3 +++ configure.in | 2 +- dns.c | 7 ++++++- mtr.8 | 13 +++++++++++++ mtr.c | 36 ++++++++++++++++++++++++++++++++++-- 7 files changed, 61 insertions(+), 5 deletions(-) diff --git a/AUTHORS b/AUTHORS index f03cc5b..981965e 100644 --- a/AUTHORS +++ b/AUTHORS @@ -36,7 +36,7 @@ Robert Sparks (rjsparks@nostrum.com) David Stone (stone@AsIf.com) Greg Stark (gsstark@mit.edu) - Andrew Brown (codewarrior@daemon.org ?) + Andrew Brown (atatat@atatdot.net) Marc Bejarano (marc.bejarano@openwave.com) and anyone who has slipped through the cracks of my mail file. diff --git a/ChangeLog b/ChangeLog index b19c0af..0c91c59 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,6 @@ +2002-02-09 bodq + * Added --address option to bind to given IP addess + 2001-04-15 root * Added this file so that automake won't complain. diff --git a/NEWS b/NEWS index f18afb9..43b825f 100644 --- a/NEWS +++ b/NEWS @@ -1,5 +1,8 @@ WHAT'S NEW? + v0.45 Included patch to be able to specify outgoing interface + address. + v0.45 People are pressuring me to release new versions with their changes. That's fine. Now this version just adds dynamic switching between numeric / dns names, and some minor diff --git a/configure.in b/configure.in index 1682e99..06bfb44 100644 --- a/configure.in +++ b/configure.in @@ -1,5 +1,5 @@ AC_INIT(mtr.c) -AM_INIT_AUTOMAKE(mtr, 0.45) +AM_INIT_AUTOMAKE(mtr, 0.46) AC_SUBST(GTK_OBJ) AC_SUBST(CURSES_OBJ) diff --git a/dns.c b/dns.c index b93fa0d..fdcb069 100644 --- a/dns.c +++ b/dns.c @@ -982,7 +982,7 @@ void parserespacket(byte *s,int l){ restell("Resolver error: Specified rdata length exceeds packet size."); return; } - if (datatype == qdatatype){ + if (datatype == qdatatype || datatype == T_CNAME){ if (debug){ sprintf(tempstring,"Resolver: TTL: %s",strtdiff(sendstring,ttl)); restell(tempstring); @@ -1014,6 +1014,7 @@ void parserespacket(byte *s,int l){ } break; case T_PTR: + case T_CNAME: *namestring = '\0'; r = dn_expand(s,s + l,c,namestring,MAXDNAME); if (r == -1){ @@ -1029,6 +1030,10 @@ void parserespacket(byte *s,int l){ failrp(rp); return; } + if (datatype == T_CNAME){ + strcpy(stackstring,namestring); + break; + } if (!rp->hostname){ rp->hostname = (char *)statmalloc(strlen(namestring) + 1); if (!rp->hostname){ diff --git a/mtr.8 b/mtr.8 index d9f416c..91d87df 100644 --- a/mtr.8 +++ b/mtr.8 @@ -38,6 +38,9 @@ mtr \- a network diagnostic tool .B \-\-gtk\c ] [\c +.B \-\-address\ IP.ADD.RE.SS\c +] +[\c .B \-\-interval\ SECONDS\c ] [\c @@ -182,6 +185,16 @@ to use the raw output format. This format is better suited for archival of the measurement results. It could be parsed to be presented into any of the other display methods. +.TP +.B \-a\ IP.ADD.RE.SS +.TP +.B \-\-address\ IP.ADD.RE.SS +.br +Use this option to bind outgoing packets' socket to specific interface, +so that any packet will be sent through this interface. NOTE that this +option doesn't apply to DNS requests (which could be and could not be +what you want). + .TP .B \-i\ SECONDS .TP diff --git a/mtr.c b/mtr.c index 8ad4f0e..5f53549 100644 --- a/mtr.c +++ b/mtr.c @@ -44,6 +44,7 @@ int PrintHelp = 0; int MaxPing = 16; float WaitTime = 1.0; char *Hostname = NULL; +char *InterfaceAddress = NULL; char LocalHostname[128]; int dns = 1; int packetsize = MINPACKET; @@ -61,13 +62,14 @@ void parse_arg(int argc, char **argv) { { "psize", 1, 0, 'p' }, { "no-dns", 0, 0, 'n' }, { "split", 0, 0, 's' }, /* BL */ + { "address", 1, 0, 'a' }, { "raw", 0, 0, 'l' }, { 0, 0, 0, 0 } }; opt = 0; while(1) { - opt = getopt_long(argc, argv, "hvrc:tgklnsi:p:", long_options, NULL); + opt = getopt_long(argc, argv, "a:hvrc:tgklnsi:p:", long_options, NULL); if(opt == -1) break; @@ -90,6 +92,9 @@ void parse_arg(int argc, char **argv) { case 't': DisplayMode = DisplayCurses; break; + case 'a': + InterfaceAddress = optarg; + break; case 'g': DisplayMode = DisplayGTK; break; @@ -184,7 +189,7 @@ int main(int argc, char **argv) { if(PrintHelp) { printf("usage: %s [-hvrctglsni] [--help] [--version] [--report]\n" "\t\t[--report-cycles=COUNT] [--curses] [--gtk]\n" - "\t\t[--raw] [--split] [--no-dns]\n" /* BL */ + "\t\t[--raw] [--split] [--no-dns] [--address interface]\n" /* BL */ "\t\t[--psize=bytes/-p=bytes]\n" /* ok */ "\t\t[--interval=SECONDS] HOSTNAME [PACKETSIZE]\n", argv[0]); exit(0); @@ -201,6 +206,33 @@ int main(int argc, char **argv) { } + if(InterfaceAddress) { /* Mostly borrowed from ping(1) code */ + struct sockaddr_in source; + int i1, i2, i3, i4; + char dummy; + extern int sendsock; /* from net.c:115 */ + + source.sin_family = AF_INET; + source.sin_port = 0; + + if(sscanf(InterfaceAddress, "%u.%u.%u.%u%c", &i1, &i2, &i3, &i4, &dummy) != 4) { + printf("mtr: bad interface address: %s\n", InterfaceAddress); + exit(1); + } else { + unsigned char*ptr; + ptr = (unsigned char*)&source.sin_addr; + ptr[0] = i1; + ptr[1] = i2; + ptr[2] = i3; + ptr[3] = i4; + } + + if(bind(sendsock, (struct sockaddr*)&source, sizeof(source)) == -1) { + perror("mtr: failed to bind to interface"); + exit(1); + } + } + host = gethostbyname(Hostname); if(host == NULL) { #ifndef NO_HERROR -- 2.47.2