{
const struct prefix *p = pu.p;
char buf[PREFIX2STR_BUFFER];
+ int byte, tmp, a, b;
+ bool z = false;
+ size_t l;
switch (p->family) {
case AF_INET:
case AF_INET6:
- snprintf(str, size, "%s/%d", inet_ntop(p->family, &p->u.prefix,
- buf, PREFIX2STR_BUFFER),
- p->prefixlen);
+ inet_ntop(p->family, &p->u.prefix, buf, sizeof(buf));
+ l = strlen(buf);
+ buf[l++] = '/';
+ byte = p->prefixlen;
+ if ((tmp = p->prefixlen - 100) >= 0) {
+ buf[l++] = '1';
+ z = true;
+ byte = tmp;
+ }
+ b = byte % 10;
+ a = byte / 10;
+ if (a || z)
+ buf[l++] = '0' + a;
+ buf[l++] = '0' + b;
+ buf[l] = '\0';
+ strlcpy(str, buf, size);
break;
case AF_ETHERNET:
break;
case AF_FLOWSPEC:
- sprintf(str, "FS prefix");
+ strlcpy(str, "FS prefix", size);
break;
default:
- sprintf(str, "UNK prefix");
+ strlcpy(str, "UNK prefix", size);
break;
}
tests/lib/test_memory \
tests/lib/test_nexthop_iter \
tests/lib/test_ntop \
+ tests/lib/test_prefix2str \
tests/lib/test_printfrr \
tests/lib/test_privs \
tests/lib/test_ringbuf \
tests_lib_test_ntop_CPPFLAGS = $(TESTS_CPPFLAGS)
tests_lib_test_ntop_LDADD = # none
tests_lib_test_ntop_SOURCES = tests/lib/test_ntop.c tests/helpers/c/prng.c
+tests_lib_test_prefix2str_CFLAGS = $(TESTS_CFLAGS)
+tests_lib_test_prefix2str_CPPFLAGS = $(TESTS_CPPFLAGS)
+tests_lib_test_prefix2str_LDADD = $(ALL_TESTS_LDADD)
+tests_lib_test_prefix2str_SOURCES = tests/lib/test_prefix2str.c tests/helpers/c/prng.c
tests_lib_test_printfrr_CFLAGS = $(TESTS_CFLAGS)
tests_lib_test_printfrr_CPPFLAGS = $(TESTS_CPPFLAGS)
tests_lib_test_printfrr_LDADD = $(ALL_TESTS_LDADD)
tests/lib/test_atomlist.py \
tests/lib/test_nexthop_iter.py \
tests/lib/test_ntop.py \
+ tests/lib/test_prefix2str.py \
tests/lib/test_printfrr.py \
tests/lib/test_ringbuf.py \
tests/lib/test_srcdest_table.py \