1 /* vi: set sw=4 ts=4: */
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License
7 * as published by the Free Software Foundation; either version
8 * 2 of the License, or (at your option) any later version.
10 * Authors: Alexey Kuznetsov, <kuznet@ms2.inr.ac.ru>
13 #include <net/if_arp.h>
20 const char *ll_addr_n2a(unsigned char *addr, int alen, int type, char *buf, int blen)
26 (type == ARPHRD_TUNNEL || type == ARPHRD_SIT || type == ARPHRD_IPGRE)) {
27 return inet_ntop(AF_INET, addr, buf, blen);
30 for (i=0; i<alen; i++) {
32 snprintf(buf+l, blen, ":%02x"+1, addr[i]);
36 snprintf(buf+l, blen, ":%02x", addr[i]);
44 int ll_addr_a2n(unsigned char *lladdr, int len, char *arg)
46 if (strchr(arg, '.')) {
48 if (get_addr_1(&pfx, arg, AF_INET)) {
49 bb_error_msg("\"%s\" is invalid lladdr", arg);
55 memcpy(lladdr, pfx.data, 4);
60 for (i=0; i<len; i++) {
62 char *cp = strchr(arg, ':');
67 if (sscanf(arg, "%x", &temp) != 1) {
68 bb_error_msg("\"%s\" is invalid lladdr", arg);
71 if (temp < 0 || temp > 255) {
72 bb_error_msg("\"%s\" is invalid lladdr", arg);