]>
git.proxmox.com Git - mirror_iproute2.git/blob - lib/mpls_pton.c
1 /* SPDX-License-Identifier: GPL-2.0 */
6 #include <netinet/in.h>
7 #include <linux/mpls.h>
12 static int mpls_pton1(const char *name
, struct mpls_label
*addr
,
13 unsigned int maxlabels
)
18 for (count
= 0; count
< maxlabels
; count
++) {
21 label
= strtoul(name
, &endp
, 0);
22 /* Fail when the label value is out or range */
23 if (label
>= (1 << 20))
26 if (endp
== name
) /* no digits */
29 addr
->entry
= htonl(label
<< MPLS_LS_LABEL_SHIFT
);
31 addr
->entry
|= htonl(1 << MPLS_LS_S_SHIFT
);
35 /* Bad character in the address */
42 /* The address was too long */
43 fprintf(stderr
, "Error: too many labels.\n");
47 int mpls_pton(int af
, const char *src
, void *addr
, size_t alen
)
49 unsigned int maxlabels
= alen
/ sizeof(struct mpls_label
);
55 err
= mpls_pton1(src
, (struct mpls_label
*)addr
, maxlabels
);