8 #include <netinet/in.h> 9 #include <netlink/netlink-compat.h> 10 #include <netlink-private/route/mpls.h> 11 #include <linux-private/linux/mpls.h> 13 static const char *mpls_ntop1(
const struct mpls_label *addr,
14 char *buf,
size_t buflen)
16 size_t destlen = buflen;
21 uint32_t entry = ntohl(addr[count++].entry);
22 uint32_t label = (entry & MPLS_LS_LABEL_MASK) >> MPLS_LS_LABEL_SHIFT;
23 int len = snprintf(dest, destlen,
"%u", label);
29 if (entry & MPLS_LS_S_MASK)
45 const char *mpls_ntop(
int af,
const void *addr,
char *buf,
size_t buflen)
50 return mpls_ntop1((
struct mpls_label *)addr, buf, buflen);
57 static int mpls_pton1(
const char *name,
struct mpls_label *addr,
58 unsigned int maxlabels)
63 for (count = 0; count < maxlabels; count++) {
66 label = strtoul(name, &endp, 0);
68 if (label >= (1 << 20))
74 addr->entry = htonl(label << MPLS_LS_LABEL_SHIFT);
76 addr->entry |= htonl(1 << MPLS_LS_S_SHIFT);
77 return (count + 1) *
sizeof(
struct mpls_label);
92 int mpls_pton(
int af,
const char *src,
void *addr,
size_t alen)
94 unsigned int maxlabels = alen /
sizeof(
struct mpls_label);
100 err = mpls_pton1(src, (
struct mpls_label *)addr, maxlabels);
103 errno = EAFNOSUPPORT;