static int tracepair_isdiff(const tracepair_t *pair) { scamper_trace_t *a = pair->traces[0]; scamper_trace_t *b = pair->traces[1]; scamper_trace_t *x = NULL; int i, hopc; if(a->hop_count < b->hop_count) hopc = a->hop_count; else hopc = b->hop_count; for(i=0; i<hopc; i++) { if(a->hops[i] == NULL || b->hops[i] == NULL) continue; if(scamper_addr_cmp(a->hops[i]->hop_addr, b->hops[i]->hop_addr) != 0) return 1; } if(hopc < a->hop_count) x = a; else if(hopc < b->hop_count) x = b; if(x != NULL) { for(i=hopc; i<x->hop_count; i++) if(x->hops[i] != NULL) return 1; } return 0; }
static int tx_nd_cmp(const void *va, const void *vb) { const scamper_task_sig_t *a = ((const s2t_t *)va)->sig; const scamper_task_sig_t *b = ((const s2t_t *)vb)->sig; assert(a->sig_type == SCAMPER_TASK_SIG_TYPE_TX_ND); assert(b->sig_type == SCAMPER_TASK_SIG_TYPE_TX_ND); return scamper_addr_cmp(a->sig_tx_nd_ip, b->sig_tx_nd_ip); }
static int firewall_rule_cmp(const scamper_firewall_rule_t *a, const scamper_firewall_rule_t *b) { int i; assert(a->type == SCAMPER_FIREWALL_RULE_TYPE_5TUPLE); assert(b->type == SCAMPER_FIREWALL_RULE_TYPE_5TUPLE); if(a->type < b->type) return -1; if(a->type > b->type) return 1; if(a->type == SCAMPER_FIREWALL_RULE_TYPE_5TUPLE) { if(a->sfw_5tuple_proto < b->sfw_5tuple_proto) return -1; if(a->sfw_5tuple_proto > b->sfw_5tuple_proto) return 1; if(a->sfw_5tuple_sport < b->sfw_5tuple_sport) return -1; if(a->sfw_5tuple_sport > b->sfw_5tuple_sport) return 1; if(a->sfw_5tuple_dport < b->sfw_5tuple_dport) return -1; if(a->sfw_5tuple_dport > b->sfw_5tuple_dport) return 1; if((i = scamper_addr_cmp(a->sfw_5tuple_src, b->sfw_5tuple_src)) != 0) return i; if(a->sfw_5tuple_dst == NULL && b->sfw_5tuple_dst == NULL) return 0; if(a->sfw_5tuple_dst != NULL && b->sfw_5tuple_dst == NULL) return -1; if(a->sfw_5tuple_dst == NULL && b->sfw_5tuple_dst != NULL) return 1; return scamper_addr_cmp(a->sfw_5tuple_dst, b->sfw_5tuple_dst); } return 0; }
static void sniff_check(scamper_dl_rec_t *dl) { scamper_task_sig_t *sig; s2t_t *s2t; dlist_node_t *n; scamper_addr_t src; uint16_t id; if(dlist_count(sniff) <= 0) return; if(SCAMPER_DL_IS_ICMP_ECHO_REPLY(dl)) id = dl->dl_icmp_id; else if(SCAMPER_DL_IS_ICMP_Q_ICMP_ECHO(dl)) id = dl->dl_icmp_icmp_id; else return; if(SCAMPER_DL_IS_IPV4(dl)) src.type = SCAMPER_ADDR_TYPE_IPV4; else if(SCAMPER_DL_IS_IPV6(dl)) src.type = SCAMPER_ADDR_TYPE_IPV6; else return; src.addr = dl->dl_ip_dst; for(n = dlist_head_node(sniff); n != NULL; n = dlist_node_next(n)) { s2t = dlist_node_item(n); sig = s2t->sig; if(sig->sig_sniff_icmp_id != id) continue; if(scamper_addr_cmp(sig->sig_sniff_src, &src) != 0) continue; if(s2t->task->funcs->handle_dl != NULL) s2t->task->funcs->handle_dl(s2t->task, dl); } return; }
static void tracepair_dump(const tracepair_t *pair) { scamper_trace_t *trace; struct tm *tm; time_t tt; uint8_t min_ttl; uint8_t max_ttl; int i, k; size_t w, ws[2]; char fs[32], a[256], b[256]; /* there needs to be two traces for a pairwise comparison */ if(pair->tracec != 2) return; /* print the header of the traceroute */ trace = pair->traces[0]; for(i=1; i<pair->tracec; i++) if(scamper_addr_cmp(trace->dst, pair->traces[i]->dst) != 0) break; w = 0; string_concat(a, sizeof(a), &w, "traceroute "); if(i == pair->tracec) string_concat(a, sizeof(a), &w, "from %s ", scamper_addr_tostr(trace->src, b, sizeof(b))); string_concat(a, sizeof(a), &w, "to %s", scamper_addr_tostr(trace->dst, b, sizeof(b))); if(options & OPT_NAMES && addr_toname(trace->dst, b, sizeof(b)) != NULL) string_concat(a, sizeof(a), &w, " (%s)", b); printf("%s\n", a); max_ttl = 0; min_ttl = 0; for(k=0; k<pair->tracec; k++) { trace = pair->traces[k]; if(max_ttl < trace->hop_count) max_ttl = trace->hop_count; if(min_ttl == 0 || min_ttl > trace->firsthop) min_ttl = trace->firsthop; } for(k=0; k<pair->tracec; k++) { ws[k] = 8; trace = pair->traces[0]; for(i=0; i<trace->hop_count; i++) { w = sizeof(a); hop_tostr(trace, i, a, &w); if(w > ws[k]) ws[k] = w; } } snprintf(fs, sizeof(fs), " %%-%ds %%-%ds\n", (int)ws[0], (int)ws[1]); tt = pair->traces[0]->start.tv_sec; tm = localtime(&tt); snprintf(a, sizeof(a), "%02d:%02d:%02d",tm->tm_hour,tm->tm_min,tm->tm_sec); tt = pair->traces[1]->start.tv_sec; tm = localtime(&tt); snprintf(b, sizeof(b), "%02d:%02d:%02d",tm->tm_hour,tm->tm_min,tm->tm_sec); printf(fs, a, b); snprintf(fs, sizeof(fs), "%%2d %%-%ds %%-%ds\n", (int)ws[0], (int)ws[1]); for(i=min_ttl-1; i<max_ttl; i++) { ws[0] = sizeof(a); ws[1] = sizeof(b); printf(fs, i+1, hop_tostr(pair->traces[0], i, a, &ws[0]), hop_tostr(pair->traces[1], i, b, &ws[1])); } return; }
static int match_dst(const scamper_trace_t *a, const scamper_trace_t *b) { return scamper_addr_cmp(a->dst, b->dst); }
static int addr2mac_cmp(const addr2mac_t *a, const addr2mac_t *b) { if(a->ifindex < b->ifindex) return -1; if(a->ifindex > b->ifindex) return 1; return scamper_addr_cmp(a->ip, b->ip); }