4 Copyright (C) 2006-2009 Jonathan Zarate
13 static int check_addr(const char *addr
, int max
)
18 if ((addr
== NULL
) || (addr
[0] == 0)) return 0;
22 if ((!isalnum(c
)) && (c
!= '.') && (c
!= '-') && (c
!= ':')) return 0; //Give IPv6 address a chance
25 return((p
- addr
) <= max
);
28 void wo_trace(char *url
)
33 addr
= webcgi_get("addr");
34 if (!check_addr(addr
, 64)) return;
36 killall("traceroute", SIGTERM
);
38 web_puts("\ntracedata = '");
39 sprintf(cmd
, "traceroute -I -m %u -w %u %s", atoi(webcgi_safeget("hops", "0")), atoi(webcgi_safeget("wait", "0")), addr
);
40 web_pipecmd(cmd
, WOF_JAVASCRIPT
);
44 void wo_ping(char *url
)
49 addr
= webcgi_get("addr");
50 if (!check_addr(addr
, 64)) return;
52 killall("ping", SIGTERM
);
54 web_puts("\npingdata = '");
55 sprintf(cmd
, "ping -c %d -s %d %s", atoi(webcgi_safeget("count", "0")), atoi(webcgi_safeget("size", "0")), addr
);
56 web_pipecmd(cmd
, WOF_JAVASCRIPT
);
64 int main(int argc, char **argv)
76 if ((f = popen("traceroute -I 192.168.0.1", "r")) == NULL) {
80 // 2 192.168.0.1 (192.168.0.1) 1.908 ms 1.812 ms 1.688 ms
82 while (fgets(s, sizeof(s), f)) {
85 if (regcomp(&re, "^ +[0-9]+ +(.+?) +\\((.+?)\\) +(.+?) ms +(.+?) ms +(.+?) ms", REG_EXTENDED) != 0) {
86 printf("error: regcomp\n");
89 if ((regexec(&re, s, sizeof(rm) / sizeof(rm[0]), rm, 0) == 0) && (re.re_nsub == 5)) {
91 for (i = 1; i < 6; ++i) {
93 printf("'%s'%c", s + rm[i].rm_so, (i == 5) ? ' ' : ',');
96 // printf("%d = %d = [%s]\n", i, rm[i].rm_so, s + rm[i].rm_so);
100 // sscanf(s, "%d %s (%s) %s ms", &n, domain, ip, min);
101 // printf("[%s] %s %s\n", ip, domain, min);