mirror of
https://git.proxmox.com/git/mirror_frr
synced 2025-08-15 09:20:25 +00:00
lib: fix prefix2str return value and assert
Signed-off-by: Christian Franke <chris@opensourcerouting.org>
This commit is contained in:
parent
d987f2339d
commit
942e4486d8
33
lib/prefix.c
33
lib/prefix.c
@ -893,29 +893,22 @@ const char *
|
||||
prefix2str (union prefix46constptr pu, char *str, int size)
|
||||
{
|
||||
const struct prefix *p = pu.p;
|
||||
char buf[PREFIX2STR_BUFFER];
|
||||
|
||||
if (p->family == AF_ETHERNET) {
|
||||
int i;
|
||||
char *s = str;
|
||||
|
||||
assert(size > (3*ETHER_ADDR_LEN) + 1 /* slash */ + 3 /* plen */ );
|
||||
for (i = 0; i < ETHER_ADDR_LEN; ++i) {
|
||||
sprintf(s, "%02x", p->u.prefix_eth.octet[i]);
|
||||
if (i < (ETHER_ADDR_LEN - 1)) {
|
||||
*(s+2) = ':';
|
||||
s += 3;
|
||||
} else {
|
||||
s += 2;
|
||||
}
|
||||
if (p->family == AF_ETHERNET)
|
||||
{
|
||||
snprintf(str, size, "%02x:%02x:%02x:%02x:%02x:%02x/%d",
|
||||
p->u.prefix_eth.octet[0], p->u.prefix_eth.octet[1],
|
||||
p->u.prefix_eth.octet[2], p->u.prefix_eth.octet[3],
|
||||
p->u.prefix_eth.octet[4], p->u.prefix_eth.octet[5],
|
||||
p->prefixlen);
|
||||
}
|
||||
else
|
||||
{
|
||||
char buf[PREFIX2STR_BUFFER];
|
||||
inet_ntop(p->family, &p->u.prefix, buf, sizeof(buf));
|
||||
snprintf(str, size, "%s/%d", buf, p->prefixlen);
|
||||
}
|
||||
sprintf(s, "/%d", p->prefixlen);
|
||||
return 0;
|
||||
}
|
||||
|
||||
snprintf (str, size, "%s/%d",
|
||||
inet_ntop (p->family, &p->u.prefix, buf, PREFIX2STR_BUFFER),
|
||||
p->prefixlen);
|
||||
return str;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user