Magellan Linux

Annotation of /trunk/mkinitrd-magellan/busybox/networking/libiproute/ll_addr.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1123 - (hide annotations) (download)
Wed Aug 18 21:56:57 2010 UTC (13 years, 9 months ago) by niro
File MIME type: text/plain
File size: 1574 byte(s)
-updated to busybox-1.17.1
1 niro 532 /* vi: set sw=4 ts=4: */
2     /*
3     * ll_addr.c
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.
9     *
10     * Authors: Alexey Kuznetsov, <kuznet@ms2.inr.ac.ru>
11     */
12    
13     #include <net/if_arp.h>
14    
15 niro 816 #include "libbb.h"
16 niro 532 #include "rt_names.h"
17     #include "utils.h"
18    
19    
20 niro 984 const char* FAST_FUNC ll_addr_n2a(unsigned char *addr, int alen, int type, char *buf, int blen)
21 niro 532 {
22     int i;
23     int l;
24    
25 niro 1123 if (alen == 4
26     && (type == ARPHRD_TUNNEL || type == ARPHRD_SIT || type == ARPHRD_IPGRE)
27     ) {
28 niro 532 return inet_ntop(AF_INET, addr, buf, blen);
29     }
30     l = 0;
31 niro 984 for (i = 0; i < alen; i++) {
32     if (i == 0) {
33     snprintf(buf + l, blen, ":%02x"+1, addr[i]);
34 niro 532 blen -= 2;
35     l += 2;
36     } else {
37 niro 984 snprintf(buf + l, blen, ":%02x", addr[i]);
38 niro 532 blen -= 3;
39     l += 3;
40     }
41     }
42     return buf;
43     }
44    
45 niro 984 int FAST_FUNC ll_addr_a2n(unsigned char *lladdr, int len, char *arg)
46 niro 532 {
47 niro 984 int i;
48    
49 niro 532 if (strchr(arg, '.')) {
50     inet_prefix pfx;
51     if (get_addr_1(&pfx, arg, AF_INET)) {
52     bb_error_msg("\"%s\" is invalid lladdr", arg);
53     return -1;
54     }
55     if (len < 4) {
56     return -1;
57     }
58     memcpy(lladdr, pfx.data, 4);
59     return 4;
60 niro 984 }
61 niro 532
62 niro 984 for (i = 0; i < len; i++) {
63     int temp;
64     char *cp = strchr(arg, ':');
65     if (cp) {
66     *cp = 0;
67     cp++;
68 niro 532 }
69 niro 984 if (sscanf(arg, "%x", &temp) != 1 || (temp < 0 || temp > 255)) {
70     bb_error_msg("\"%s\" is invalid lladdr", arg);
71     return -1;
72     }
73     lladdr[i] = temp;
74     if (!cp) {
75     break;
76     }
77     arg = cp;
78 niro 532 }
79 niro 984 return i+1;
80 niro 532 }