diff options
Diffstat (limited to 'lib')
| -rw-r--r-- | lib/prefix.c | 29 | ||||
| -rw-r--r-- | lib/prefix.h | 12 |
2 files changed, 41 insertions, 0 deletions
diff --git a/lib/prefix.c b/lib/prefix.c index 52bb266f11..6b91969218 100644 --- a/lib/prefix.c +++ b/lib/prefix.c @@ -1359,6 +1359,35 @@ const char *prefix2str(union prefixconstptr pu, char *str, int size) return str; } +void prefix_mcast_inet4_dump(const char *onfail, struct in_addr addr, + char *buf, int buf_size) +{ + int save_errno = errno; + + if (addr.s_addr == INADDR_ANY) + strcpy(buf, "*"); + else { + if (!inet_ntop(AF_INET, &addr, buf, buf_size)) { + if (onfail) + snprintf(buf, buf_size, "%s", onfail); + } + } + + errno = save_errno; +} + +const char *prefix_sg2str(const struct prefix_sg *sg, char *sg_str) +{ + char src_str[INET_ADDRSTRLEN]; + char grp_str[INET_ADDRSTRLEN]; + + prefix_mcast_inet4_dump("<src?>", sg->src, src_str, sizeof(src_str)); + prefix_mcast_inet4_dump("<grp?>", sg->grp, grp_str, sizeof(grp_str)); + snprintf(sg_str, PREFIX_SG_STR_LEN, "(%s,%s)", src_str, grp_str); + + return sg_str; +} + struct prefix *prefix_new(void) { struct prefix *p; diff --git a/lib/prefix.h b/lib/prefix.h index a1c2086b8d..ffc973f6ea 100644 --- a/lib/prefix.h +++ b/lib/prefix.h @@ -321,6 +321,15 @@ union prefixconstptr { /* Maximum string length of the result of prefix2str */ #define PREFIX_STRLEN 80 +/* + * Longest possible length of a (S,G) string is 36 bytes + * 123.123.123.123 = 16 * 2 + * (,) = 3 + * NULL Character at end = 1 + * (123.123.123.123,123.123.123.123) + */ +#define PREFIX_SG_STR_LEN 36 + /* Max bit/byte length of IPv4 address. */ #define IPV4_MAX_BYTELEN 4 #define IPV4_MAX_BITLEN 32 @@ -394,6 +403,9 @@ extern int str2prefix(const char *, struct prefix *); #define PREFIX2STR_BUFFER PREFIX_STRLEN +extern void prefix_mcast_inet4_dump(const char *onfail, struct in_addr addr, + char *buf, int buf_size); +extern const char *prefix_sg2str(const struct prefix_sg *sg, char *str); extern const char *prefix2str(union prefixconstptr, char *, int); extern int prefix_match(const struct prefix *, const struct prefix *); extern int prefix_match_network_statement(const struct prefix *, |
