Magellan Linux

Annotation of /trunk/net-tools/patches/net-tools-1.60-get_name.patch

Parent Directory Parent Directory | Revision Log Revision Log


Revision 153 - (hide annotations) (download)
Tue May 8 20:52:56 2007 UTC (17 years ago) by niro
File size: 1608 byte(s)
-import

1 niro 153 diff -Nrup net-tools-1.60.orig/lib/interface.c net-tools-1.60/lib/interface.c
2     --- net-tools-1.60.orig/lib/interface.c 2004-08-12 05:54:09.000000000 -0400
3     +++ net-tools-1.60/lib/interface.c 2004-08-12 06:03:20.000000000 -0400
4     @@ -203,28 +203,34 @@ out:
5    
6     static char *get_name(char *name, char *p)
7     {
8     - while (isspace(*p))
9     - p++;
10     - while (*p) {
11     - if (isspace(*p))
12     - break;
13     - if (*p == ':') { /* could be an alias */
14     - char *dot = p, *dotname = name;
15     - *name++ = *p++;
16     - while (isdigit(*p))
17     - *name++ = *p++;
18     - if (*p != ':') { /* it wasn't, backup */
19     - p = dot;
20     - name = dotname;
21     - }
22     - if (*p == '\0')
23     - return NULL;
24     - p++;
25     - break;
26     + /* Extract <name>[:<alias>] from nul-terminated p where p matches
27     + <name>[:<alias>]: after leading whitespace.
28     + If match is not made, set name empty and return unchanged p */
29     + int namestart=0, nameend=0, aliasend;
30     + while (isspace(p[namestart]))
31     + namestart++;
32     + nameend=namestart;
33     + while (p[nameend] && p[nameend]!=':' && !isspace(p[nameend]))
34     + nameend++;
35     + if (p[nameend]==':') {
36     + aliasend=nameend+1;
37     + while (p[aliasend] && isdigit(p[aliasend]))
38     + aliasend++;
39     + if (p[aliasend]==':') {
40     + nameend=aliasend;
41     + }
42     + if ((nameend-namestart)<IFNAMSIZ) {
43     + memcpy(name,&p[namestart],nameend-namestart);
44     + name[nameend-namestart]='\0';
45     + p=&p[nameend+1];
46     + } else {
47     + /* Interface name too large */
48     + name[0]='\0';
49     }
50     - *name++ = *p++;
51     + } else {
52     + /* first ':' not found - return empty */
53     + name[0]='\0';
54     }
55     - *name++ = '\0';
56     return p;
57     }
58