]>
git.proxmox.com Git - mirror_iproute2.git/blob - lib/ll_addr.c
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation; either version
7 * 2 of the License, or (at your option) any later version.
9 * Authors: Alexey Kuznetsov, <kuznet@ms2.inr.ac.ru>
17 #include <sys/ioctl.h>
18 #include <sys/socket.h>
19 #include <netinet/in.h>
20 #include <arpa/inet.h>
23 #include <linux/netdevice.h>
24 #include <linux/if_arp.h>
25 #include <linux/sockios.h>
31 const char *ll_addr_n2a(const unsigned char *addr
, int alen
, int type
, char *buf
, int blen
)
37 (type
== ARPHRD_TUNNEL
|| type
== ARPHRD_SIT
|| type
== ARPHRD_IPGRE
)) {
38 return inet_ntop(AF_INET
, addr
, buf
, blen
);
40 if (alen
== 16 && type
== ARPHRD_TUNNEL6
) {
41 return inet_ntop(AF_INET6
, addr
, buf
, blen
);
43 snprintf(buf
, blen
, "%02x", addr
[0]);
44 for (i
= 1, l
= 2; i
< alen
&& l
< blen
; i
++, l
+= 3)
45 snprintf(buf
+ l
, blen
- l
, ":%02x", addr
[i
]);
49 /*NB: lladdr is char * (rather than u8 *) because sa_data is char * (1003.1g) */
50 int ll_addr_a2n(char *lladdr
, int len
, const char *arg
)
52 if (strchr(arg
, '.')) {
54 if (get_addr_1(&pfx
, arg
, AF_INET
)) {
55 fprintf(stderr
, "\"%s\" is invalid lladdr.\n", arg
);
60 memcpy(lladdr
, pfx
.data
, 4);
65 for (i
=0; i
<len
; i
++) {
67 char *cp
= strchr(arg
, ':');
72 if (sscanf(arg
, "%x", &temp
) != 1) {
73 fprintf(stderr
, "\"%s\" is invalid lladdr.\n", arg
);
76 if (temp
< 0 || temp
> 255) {
77 fprintf(stderr
, "\"%s\" is invalid lladdr.\n", arg
);