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 <sys/ioctl.h>
20 #include <netinet/in.h>
21 #include <arpa/inet.h>
24 #include <linux/netdevice.h>
25 #include <linux/if_arp.h>
26 #include <linux/sockios.h>
31 const char *ll_addr_n2a(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);
41 for (i=0; i<alen; i++) {
43 snprintf(buf+l, blen, "%02x", addr[i]);
47 snprintf(buf+l, blen, ":%02x", addr[i]);
55 int ll_addr_a2n(unsigned char *lladdr, int len, char *arg)
57 if (strchr(arg, '.')) {
59 if (get_addr_1(&pfx, arg, AF_INET)) {
60 error_msg("\"%s\" is invalid lladdr.", arg);
66 memcpy(lladdr, pfx.data, 4);
71 for (i=0; i<len; i++) {
73 char *cp = strchr(arg, ':');
78 if (sscanf(arg, "%x", &temp) != 1) {
79 error_msg("\"%s\" is invalid lladdr.", arg);
82 if (temp < 0 || temp > 255) {
83 error_msg("\"%s\" is invalid lladdr.", arg);