char buf[BUFSIZ];
if (p->family == AF_INET) {
- len = vty_out(vty, "%s",
- inet_ntop(p->family, &p->u.prefix, buf, BUFSIZ));
- destination = ntohl(p->u.prefix4.s_addr);
-
- if ((IN_CLASSC(destination) && p->prefixlen == 24)
- || (IN_CLASSB(destination) && p->prefixlen == 16)
- || (IN_CLASSA(destination) && p->prefixlen == 8)
- || p->u.prefix4.s_addr == 0) {
- /* When mask is natural, mask is not displayed. */
- } else
- len += vty_out(vty, "/%d", p->prefixlen);
+ if (!json) {
+ len = vty_out(vty, "%s",
+ inet_ntop(p->family, &p->u.prefix, buf,
+ BUFSIZ));
+ destination = ntohl(p->u.prefix4.s_addr);
+
+ if ((IN_CLASSC(destination) && p->prefixlen == 24)
+ || (IN_CLASSB(destination) && p->prefixlen == 16)
+ || (IN_CLASSA(destination) && p->prefixlen == 8)
+ || p->u.prefix4.s_addr == 0) {
+ /* When mask is natural, mask is not displayed. */
+ } else
+ len += vty_out(vty, "/%d", p->prefixlen);
+ } else {
+ json_object_string_add(json, "prefix",
+ inet_ntop(p->family,
+ &p->u.prefix, buf,
+ BUFSIZ));
+ json_object_int_add(json, "prefixLen", p->prefixlen);
+ }
} else if (p->family == AF_ETHERNET) {
prefix2str(p, buf, PREFIX_STRLEN);
len = vty_out(vty, "%s", buf);
len = vty_out(vty, "%s", buf);
#endif
} else {
- len = vty_out(vty, "%s/%d",
- inet_ntop(p->family, &p->u.prefix, buf, BUFSIZ),
- p->prefixlen);
+ if (!json)
+ len = vty_out(vty, "%s/%d",
+ inet_ntop(p->family, &p->u.prefix, buf,
+ BUFSIZ),
+ p->prefixlen);
}
if (!json) {