diff options
Diffstat (limited to 'lib/prefix.c')
-rw-r--r-- | lib/prefix.c | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/lib/prefix.c b/lib/prefix.c index d3e8a612e..4e9d41836 100644 --- a/lib/prefix.c +++ b/lib/prefix.c @@ -1374,10 +1374,36 @@ static ssize_t printfrr_ia(struct fbuf *buf, struct printfrr_eargs *ea, { const struct ipaddr *ipa = ptr; char cbuf[INET6_ADDRSTRLEN]; + bool use_star = false; + + if (ea->fmt[0] == 's') { + use_star = true; + ea->fmt++; + } if (!ipa) return bputs(buf, "(null)"); + if (use_star) { + struct in_addr zero4 = {}; + struct in6_addr zero6 = {}; + + switch (ipa->ipa_type) { + case IPADDR_V4: + if (!memcmp(&ipa->ip.addr, &zero4, sizeof(zero4))) + return bputch(buf, '*'); + break; + + case IPADDR_V6: + if (!memcmp(&ipa->ip.addr, &zero6, sizeof(zero6))) + return bputch(buf, '*'); + break; + + default: + break; + } + } + ipaddr2str(ipa, cbuf, sizeof(cbuf)); return bputs(buf, cbuf); } @@ -1387,10 +1413,20 @@ static ssize_t printfrr_i4(struct fbuf *buf, struct printfrr_eargs *ea, const void *ptr) { char cbuf[INET_ADDRSTRLEN]; + bool use_star = false; + struct in_addr zero = {}; + + if (ea->fmt[0] == 's') { + use_star = true; + ea->fmt++; + } if (!ptr) return bputs(buf, "(null)"); + if (use_star && !memcmp(ptr, &zero, sizeof(zero))) + return bputch(buf, '*'); + inet_ntop(AF_INET, ptr, cbuf, sizeof(cbuf)); return bputs(buf, cbuf); } @@ -1400,10 +1436,20 @@ static ssize_t printfrr_i6(struct fbuf *buf, struct printfrr_eargs *ea, const void *ptr) { char cbuf[INET6_ADDRSTRLEN]; + bool use_star = false; + struct in6_addr zero = {}; + + if (ea->fmt[0] == 's') { + use_star = true; + ea->fmt++; + } if (!ptr) return bputs(buf, "(null)"); + if (use_star && !memcmp(ptr, &zero, sizeof(zero))) + return bputch(buf, '*'); + inet_ntop(AF_INET6, ptr, cbuf, sizeof(cbuf)); return bputs(buf, cbuf); } |