4 Copyright (C) 2006-2009 Jonathan Zarate
12 static int check_addr(const char *addr
, int max
)
17 if ((addr
== NULL
) || (addr
[0] == 0)) return 0;
21 if ((!isalnum(c
)) && (c
!= '.') && (c
!= '-') && (c
!= ':')) return 0; //Give IPv6 addresses a chance
24 return((p
- addr
) <= max
);
27 void wo_trace(char *url
)
32 addr
= webcgi_get("addr");
33 if (!check_addr(addr
, 64)) return;
35 killall("traceroute", SIGTERM
);
37 web_puts("\ntracedata = '");
38 sprintf(cmd
, "traceroute -I -m %u -w %u %s", atoi(webcgi_safeget("hops", "0")), atoi(webcgi_safeget("wait", "0")), addr
);
39 web_pipecmd(cmd
, WOF_JAVASCRIPT
);
43 void wo_ping(char *url
)
48 addr
= webcgi_get("addr");
49 if (!check_addr(addr
, 64)) return;
51 killall("ping", SIGTERM
);
53 web_puts("\npingdata = '");
54 sprintf(cmd
, "ping -c %d -s %d %s", atoi(webcgi_safeget("count", "0")), atoi(webcgi_safeget("size", "0")), addr
);
55 web_pipecmd(cmd
, WOF_JAVASCRIPT
);
63 int main(int argc, char **argv)
75 if ((f = popen("traceroute -I 192.168.0.1", "r")) == NULL) {
79 // 2 192.168.0.1 (192.168.0.1) 1.908 ms 1.812 ms 1.688 ms
81 while (fgets(s, sizeof(s), f)) {
84 if (regcomp(&re, "^ +[0-9]+ +(.+?) +\\((.+?)\\) +(.+?) ms +(.+?) ms +(.+?) ms", REG_EXTENDED) != 0) {
85 printf("error: regcomp\n");
88 if ((regexec(&re, s, sizeof(rm) / sizeof(rm[0]), rm, 0) == 0) && (re.re_nsub == 5)) {
90 for (i = 1; i < 6; ++i) {
92 printf("'%s'%c", s + rm[i].rm_so, (i == 5) ? ' ' : ',');
95 // printf("%d = %d = [%s]\n", i, rm[i].rm_so, s + rm[i].rm_so);
99 // sscanf(s, "%d %s (%s) %s ms", &n, domain, ip, min);
100 // printf("[%s] %s %s\n", ip, domain, min);