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