#include <strings.h>
#include <unistd.h>
-#ifdef HAVE_NCURSES
#include <ctype.h>
#include <stdlib.h>
#include <string.h>
# error No curses header file available
#endif
+/* This go-around is needed only when compiling with antique version of curses.
+ getmaxyx is part of Technical Standard X/Open Curses Issue 4, Version 2 (1996).
+ http://pubs.opengroup.org/onlinepubs/9693989999/toc.pdf see page 106 */
#ifndef getmaxyx
# define getmaxyx(win,y,x) ((y) = (win)->_maxy + 1, (x) = (win)->_maxx + 1)
#endif
#include "display.h"
#include "utils.h"
-#endif
-
#include <time.h>
attroff(A_BOLD);
mvprintw(1, 0, "%s (%s)", ctl->LocalHostname, net_localaddr());
- /*
- printw("(tos=0x%X ", tos);
- printw("psize=%d ", packetsize );
- printw("bitpattern=0x%02X)", (unsigned char)(abs(ctl->bitpattern)));
- if( cpacketsize > 0 ){
- printw("psize=%d ", cpacketsize);
- } else {
- printw("psize=rand(%d,%d) ",MINPACKET, -cpacketsize);
- }
- if( ctl->bitpattern>=0 ){
- printw("bitpattern=0x%02X)", (unsigned char)(ctl->bitpattern));
- } else {
- printw("bitpattern=rand(0x00-FF))");
- }
- */
t = time(NULL);
mvprintw(1, maxx-25, iso_time(&t));
printw("\n");
{
struct dns_results *t;
- //printf ("Looking for: %s\n", strlongip (ctl, ip));
for (t=results;t;t=t->next) {
- //printf ("comparing: %s\n", strlongip (ctl, &t->ip));
if (addrcmp ( (void *)ip, (void*) &t->ip, ctl->af) == 0)
return t;
}
static int todns[2], fromdns[2];
FILE *fromdnsfp;
-#if 0
-static void handle_sigchld(int sig) {
- while (waitpid((pid_t)(-1), 0, WNOHANG) > 0) {}
-}
-#endif
-
extern void dns_open(struct mtr_ctl *ctl)
{
int pid;
}
fflush (stdout);
pid = fork ();
- //pid = 1;
if (pid < 0) {
error(EXIT_FAILURE, errno, "can't fork for DNS process");
}
if (pid == 0) {
char buf[2048];
int i;
- FILE *infp; //, *outfp;
+ FILE *infp;
// Automatically reap children.
if (signal(SIGCHLD, SIG_IGN) == SIG_ERR) {
error(EXIT_FAILURE, errno, "signal");
}
-#if 0
- // No longer necessary: we close all of them below.
- // The child: We're going to handle the DNS requests here.
- close (todns[1]); // close the pipe ends we don't need.
- close (fromdns[0]);
-#endif
// Close all unneccessary FDs.
// for debugging and error reporting, keep std-in/out/err.
for (i=3;i<fromdns[1];i++) {
close (i);
}
infp = fdopen (todns[0],"r");
- //outfp = fdopen (fromdns[1],"w");
while (fgets (buf, sizeof (buf), infp)) {
ip_t host;
buf[strlen(buf)-1] = 0; // chomp newline.
longipstr (buf, &host, ctl->af);
- //printf ("resolving %s (%d)\n", strlongip (ctl, &host), ctl->af);
set_sockaddr_ip (ctl, &sa, &host);
salen = (ctl->af == AF_INET)?sizeof(struct sockaddr_in):
sizeof(struct sockaddr_in6);
hostname, sizeof (hostname), NULL, 0, 0);
if (rv == 0) {
sprintf (result, "%s %s\n", strlongip (ctl, &host), hostname);
- //printf ("resolved: %s -> %s (%d)\n", strlongip (ctl, &host), hostname, rv);
rv = write (fromdns[1], result, strlen (result));
if (rv < 0)
error (0, errno, "write DNS lookup result");
return strlongip (ctl, ip);
} else {
r = xmalloc (sizeof (struct dns_results));
- //r->ip = *ip;
memcpy (&r->ip, ip, sizeof (r->ip));
r->name = NULL;
r->next = results;
results = r;
-
- //printf ("lookup: %s\n", strlongip (ctl, ip));
-
snprintf (buf, sizeof(buf), "%s\n", strlongip (ctl, ip));
rv = write (todns[1], buf, strlen (buf));
if (rv < 0)
return t;
}
-
-#if 0
-extern char *strlongip(struct mtr_ctl *ctl, ip_t * ip)
-{
-#ifdef ENABLE_IPV6
- static char addrstr[INET6_ADDRSTRLEN];
-
- return (char *) inet_ntop( ctl->af, ip, addrstr, sizeof addrstr );
-#else
- return inet_ntoa( *ip );
-#endif
-}
-#endif
-
-
// XXX check if necessary/exported.
/* Resolve an IP address to a hostname. */
#ifdef ENABLE_IPV6
extern int dns_waitfd6(void);
extern void dns_ack6(void);
-#ifdef NEED_RES_STATE_EXT
-/* __res_state_ext is missing on many (most?) BSD systems */
-struct __res_state_ext {
- union res_sockaddr_union nsaddrs[MAXNS];
- struct sort_list {
- int af;
- union {
- struct in_addr ina;
- struct in6_addr in6a;
- } addr, mask;
- } sort_list[MAXRESOLVSORT];
- char nsuffix[64];
- char nsuffix2[64];
-};
-#endif
#endif
extern char *dns_lookup(struct mtr_ctl *ctl, ip_t * address);
0.0);
Button = gtk_spin_button_new(Adjustment, 0.5, 2);
gtk_spin_button_set_numeric(GTK_SPIN_BUTTON(Button), TRUE);
- /* gtk_spin_button_set_snap_to_ticks(GTK_SPIN_BUTTON(Button), FALSE); */
- /* gtk_spin_button_set_set_update_policy(GTK_SPIN_BUTTON(Button),
- GTK_UPDATE_IF_VALID); */
gtk_box_pack_end(GTK_BOX(Toolbar), Button, FALSE, FALSE, 0);
ctl->gtk_data = Button;
g_signal_connect(GTK_OBJECT(Adjustment), "value_changed",
while (names != NULL) {
ctl.Hostname = names->name;
- // if (Hostname == NULL) Hostname = "localhost"; // no longer necessary.
if (gethostname(ctl.LocalHostname, sizeof(ctl.LocalHostname))) {
xstrncpy(ctl.LocalHostname, "UNKNOWNHOST", sizeof(ctl.LocalHostname));
}
int avg; /* average: addByMin */
int gmean; /* geometric mean: addByMin */
int jitter; /* current jitter, defined as t1-t0 addByMin */
-/*int jbest;*/ /* min jitter, of cause it is 0, not needed */
int javg; /* avg jitter */
int jworst; /* max jitter */
int jinta; /* estimated variance,? rfc1889's "Interarrival Jitter" */
static struct nethost host[MaxHost];
static struct sequence sequence[MaxSequence];
-static struct timeval reset = { 0, 0 };
static int sendsock4;
static int sendsock4_icmp;
error(EXIT_FAILURE, errno, "getsockname()");
}
- // opt = 1;
flags = fcntl(s, F_GETFL, 0);
if (flags < 0) {
display_clear(ctl);
host[index].jitter = host[index].jworst = host[index].jinta= 0;
}
- /* some time best can be too good to be true, experienced
- * at least in linux 2.4.x.
- * safe guard 1) best[index]>=best[index-1] if index>0
- * 2) best >= average-20,000 usec (good number?)
- if (index > 0) {
- if (totusec < host[index].best &&
- totusec>= host[index-1].best) host[index].best = totusec;
- } else {
- if(totusec < host[index].best) host[index].best = totusec;
- }
- */
if (totusec < host[index].best ) host[index].best = totusec;
if (totusec > host[index].worst) host[index].worst = totusec;
int max;
max = 0;
- /* for(at = 0; at < MaxHost-2; at++) { */
for(at = 0; at < ctl->maxTTL-1; at++) {
if ( addrcmp( (void *) &(host[at].addr),
(void *) remoteaddress, ctl->af ) == 0 ) {
}
}
- /* printf ("cpacketsize = %d, packetsize = %d\n", cpacketsize, packetsize); */
-
net_send_query(ctl, batch_at);
for (i=ctl->fstTTL-1;i<batch_at;i++) {
If the line proves necessary, it should at least NOT trigger that line
when host[i].addr == 0 */
if ( ( addrcmp( (void *) &(host[i].addr),
- (void *) remoteaddress, ctl->af ) == 0 )
- /* || (host[i].addr == host[batch_at].addr) */)
+ (void *) remoteaddress, ctl->af ) == 0 ))
n_unknown = MaxHost; /* Make sure we drop into "we should restart" */
}
len = sizeof name_struct;
getsockname (recvsock, name, &len);
sockaddrtop( name, localaddr, sizeof localaddr );
-#if 0
- printf ("got localaddr: %s\n", localaddr);
-#endif
return 0;
}
}
}
- gettimeofday(&reset, NULL);
}
static int net_set_interfaceaddress_udp(struct mtr_ctl *ctl)
#include "dns.h"
-#if 0
-static char *addr_to_str(struct mtr_ctl *ctl, ip_t addr)
-{
- static char buf[20];
-
- sprintf (buf, "%s", strlongip(ctl, &addr ));
- return buf;
-}
-#endif
-
// Log an echo request, or a "ping"
extern void raw_rawxmit (int host, int seq)
{
static double dnsinterval;
static struct timeval intervaltime;
-#define GRACETIME (ctl->GraceTime * 1000*1000)
-
extern void select_loop(struct mtr_ctl *ctl){
fd_set readfd;
fd_set writefd;
if (graceperiod) {
dt = (thistime.tv_usec - startgrace.tv_usec) +
1000000 * (thistime.tv_sec - startgrace.tv_sec);
- if (dt > GRACETIME)
+ if ((ctl->GraceTime * 1000 * 1000) < dt)
return;
}