From: Baptiste Jonglez Date: Thu, 9 Jun 2016 18:18:22 +0000 (+0100) Subject: Fix wrap-around bug when displaying IP info (-y option) X-Git-Tag: v0.87~7^2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=refs%2Fpull%2F118%2Fhead;p=thirdparty%2Fmtr.git Fix wrap-around bug when displaying IP info (-y option) Some IP prefixes have an allocation date, but some don't. For instance: $ dig +short 49.60.231.80.origin.asn.cymru.com TXT "6453 | 80.231.0.0/16 | EU | ripencc | 2002-03-20" $ dig +short 186.83.219.195.origin.asn.cymru.com TXT "6453 | 195.219.0.0/16 | EU | ripencc |" In the latter case, the parsing code would miss the last (empty) field and wrap around to the AS number, producing an inconsistent output (see below). While we're at it, also make the parsing logic easier to understand... Before this patch: $ mtr --report -y 4 nic.co.jp Start: Thu Jun 9 19:13:50 2016 HOST: gilead Loss% Snt Last Avg Best Wrst StDev 1. 2004-04-05 gatwick.net.cl.ca 0.0% 10 2.0 4.7 2.0 7.1 1.9 2. 786 cl-wgb.route-west 0.0% 10 0.6 11.3 0.6 104.7 32.8 3. 786 d-we.c-ce.net.cam 0.0% 10 0.7 0.6 0.5 0.8 0.0 4. 786 c-ce.b-ec.net.cam 0.0% 10 0.7 6.9 0.3 52.6 16.2 5. 786 ae1.cambab-rbr1.e 0.0% 10 0.3 0.5 0.3 0.7 0.0 6. 786 146.97.65.118 0.0% 10 0.7 0.6 0.5 0.8 0.0 7. 786 146.97.38.17 0.0% 10 3.5 9.3 3.5 17.9 6.2 8. 786 ae29.londtn-sbr1. 0.0% 10 3.7 4.0 3.5 6.6 0.9 9. 2002-03-20 ix-ae-11-0.tcore1 0.0% 10 3.8 5.0 3.5 16.8 4.1 10. 6453 195.219.83.186 0.0% 10 4.3 4.4 3.9 5.6 0.3 11. 2914 ae-4.r22.londen03 0.0% 10 7.7 8.8 3.9 25.5 6.9 12. 2914 ae-6.r21.sngpsi05 0.0% 10 185.4 185.8 174.4 226.5 14.9 13. 2914 ae-20.r31.tokyjp0 0.0% 10 249.9 250.0 249.8 250.4 0.0 14. 2914 ae-21.r00.tokyjp0 0.0% 10 265.9 265.9 265.6 266.1 0.0 15. 2000-09-29 ae-0.gmo.tokyjp05 0.0% 10 253.7 252.5 244.7 257.5 4.4 16. ??? ??? 100.0 10 0.0 0.0 0.0 0.0 0.0 17. 7506 g-o-p-4ee-a01-1-e 0.0% 10 250.3 250.3 250.2 250.5 0.0 18. 7506 unused-157-7-041- 0.0% 10 257.0 256.9 256.7 257.2 0.0 19. 7506 157-7-107-115.vir 0.0% 10 258.6 258.4 258.2 258.6 0.0 After this patch: $ mtr --report -y 4 nic.co.jp Start: Thu Jun 9 19:12:30 2016 HOST: gilead Loss% Snt Last Avg Best Wrst StDev 1. 2004-04-05 gatwick.net.cl.ca 0.0% 10 3.6 7.3 1.2 18.1 5.9 2. cl-wgb.route-west 0.0% 10 0.6 0.8 0.5 1.3 0.0 3. d-we.c-ce.net.cam 0.0% 10 0.5 0.7 0.5 1.0 0.0 4. c-ce.b-ec.net.cam 0.0% 10 0.4 1.6 0.3 9.1 2.6 5. ae1.cambab-rbr1.e 0.0% 10 0.4 0.5 0.3 0.7 0.0 6. 146.97.65.118 0.0% 10 0.5 1.1 0.5 5.0 1.3 7. 146.97.38.17 0.0% 10 3.7 8.4 3.4 51.9 15.3 8. ae29.londtn-sbr1. 0.0% 10 3.7 9.0 3.5 54.8 16.1 9. 2002-03-20 ix-ae-11-0.tcore1 0.0% 10 5.5 4.1 3.5 6.0 0.8 10. 195.219.83.186 0.0% 10 4.0 4.2 3.9 4.6 0.0 11. ae-4.r22.londen03 0.0% 10 3.8 9.5 3.8 33.6 11.6 12. ae-6.r21.sngpsi05 20.0% 10 185.8 181.0 179.5 185.8 2.1 13. ae-20.r31.tokyjp0 0.0% 10 249.9 249.7 249.5 249.9 0.0 14. ae-21.r00.tokyjp0 0.0% 10 266.1 266.0 265.7 266.4 0.0 15. 2000-09-29 ae-0.gmo.tokyjp05 0.0% 10 243.8 243.8 243.4 244.4 0.0 16. ??? ??? 100.0 10 0.0 0.0 0.0 0.0 0.0 17. g-o-p-4ee-a01-1-e 0.0% 10 246.1 246.2 245.7 247.4 0.0 18. unused-157-7-041- 0.0% 10 257.3 258.0 256.9 260.9 1.2 19. 157-7-107-115.vir 0.0% 10 258.3 258.4 258.2 258.8 0.0 --- diff --git a/asn.c b/asn.c index 628f504..62880dc 100644 --- a/asn.c +++ b/asn.c @@ -173,15 +173,19 @@ char* split_txtrec(char *txtrec) { } } - char* prev = (*items)[0] = trimsep(txtrec); + char* prev = txtrec; char* next; int i = 0, j; while ((next = strchr(prev, ITEMSEP)) && (i < ITEMSMAX)) { - *next++ = '\0'; - (*items)[i++] = trimsep(prev); - (*items)[i] = prev = trimsep(next); + *next = '\0'; + next++; + (*items)[i] = trimsep(prev); + prev = next; + i++; } + (*items)[i] = trimsep(prev); + if (i < ITEMSMAX) i++; for (j = i; j <= ITEMSMAX; j++)