From 2eb56c0a4c9a83e753ce20dc77dcdbc569f5235e Mon Sep 17 00:00:00 2001 From: Neels Hofmeyr Date: Thu, 26 Dec 2019 14:14:27 +0100 Subject: abisip-find -l: sort by IP Change-Id: I1a4b0686c2787d17ead2251d0a2adeb3bc0d485b --- src/ipaccess/abisip-find.c | 27 +++++++++++++++++++++++---- 1 file changed, 23 insertions(+), 4 deletions(-) diff --git a/src/ipaccess/abisip-find.c b/src/ipaccess/abisip-find.c index df866f0bf..e5e12810c 100644 --- a/src/ipaccess/abisip-find.c +++ b/src/ipaccess/abisip-find.c @@ -267,14 +267,33 @@ static char *parse_response(void *ctx, unsigned char *buf, int len) if (cmdline_opts.format_json) out = talloc_asprintf_append(out,"{ "); + // write IP first, to sort by IP + cur = buf; while (cur < buf + len) { t_len = *cur++; t_tag = *cur++; - if (cmdline_opts.format_json) - out = talloc_asprintf_append(out, "\"%s\": \"%s\", ", idtag_name(t_tag), cur); - else - out = talloc_asprintf_append(out, "%s='%s' ", idtag_name(t_tag), cur); + if (t_tag == IPAC_IDTAG_IPADDR) { + if (cmdline_opts.format_json) + out = talloc_asprintf_append(out, "\"%s\": \"%s\", ", idtag_name(t_tag), cur); + else + out = talloc_asprintf_append(out, "%s='%s' ", idtag_name(t_tag), cur); + } + + cur += t_len; + } + + cur = buf; + while (cur < buf + len) { + t_len = *cur++; + t_tag = *cur++; + + if (t_tag != IPAC_IDTAG_IPADDR) { + if (cmdline_opts.format_json) + out = talloc_asprintf_append(out, "\"%s\": \"%s\", ", idtag_name(t_tag), cur); + else + out = talloc_asprintf_append(out, "%s='%s' ", idtag_name(t_tag), cur); + } cur += t_len; } -- cgit v1.2.3