]>
git.proxmox.com Git - mirror_iproute2.git/blob - lib/dnet_pton.c
1 /* SPDX-License-Identifier: GPL-2.0 */
5 #include <netinet/in.h>
9 static __inline__ u_int16_t
dn_htons(u_int16_t addr
)
17 return ((u_int16_t
)u
.byte
[0]) | (((u_int16_t
)u
.byte
[1]) << 8);
21 static int dnet_num(const char *src
, u_int16_t
* dst
)
27 while ((tmp
= *src
++) != 0) {
29 if ((tmp
< 0) || (tmp
> 9))
40 static int dnet_pton1(const char *src
, struct dn_naddr
*dna
)
47 pos
= dnet_num(src
, &area
);
48 if ((pos
== 0) || (area
> 63) || (*(src
+ pos
) != '.'))
50 pos
= dnet_num(src
+ pos
+ 1, &node
);
51 if ((pos
== 0) || (node
> 1023))
54 addr
= dn_htons((area
<< 10) | node
);
55 memcpy(dna
->a_addr
, &addr
, sizeof(addr
));
60 int dnet_pton(int af
, const char *src
, void *addr
)
67 err
= dnet_pton1(src
, (struct dn_naddr
*)addr
);