|
1 --- libnet-1.1.2.1/src/libnet_link_dlpi.c.orig Thu Jul 14 14:55:07 2011 |
|
2 +++ libnet-1.1.2.1/src/libnet_link_dlpi.c Thu Jul 14 14:55:27 2011 |
|
3 @@ -123,6 +123,9 @@ |
|
4 int8_t dname2[100]; |
|
5 #endif |
|
6 |
|
7 + int8_t dev_net_dname[200]; |
|
8 + uint32_t dev_str_len; |
|
9 + |
|
10 if (l == NULL) |
|
11 { |
|
12 return (-1); |
|
13 @@ -130,21 +133,23 @@ |
|
14 |
|
15 /* |
|
16 * Determine device and ppa |
|
17 + * ppa is the last numeric token in the datalink name |
|
18 */ |
|
19 - cp = strpbrk(l->device, "0123456789"); |
|
20 - if (cp == NULL) |
|
21 - { |
|
22 + |
|
23 + eos = l->device; |
|
24 + ppa = -1; |
|
25 + do { |
|
26 + cp = strpbrk(eos, "0123456789"); |
|
27 + if (cp != NULL) { |
|
28 + ppa = strtol(cp, &eos, 10); |
|
29 + } |
|
30 + } while (*eos != '\0' && cp != NULL); |
|
31 + |
|
32 + if (ppa == -1) { |
|
33 snprintf(l->err_buf, LIBNET_ERRBUF_SIZE, |
|
34 - "%s(): %s is missing unit number\n", __func__, l->device); |
|
35 - goto bad; |
|
36 + "%s(): %s is missing unit number\n", __func__, l->device); |
|
37 + goto bad; |
|
38 } |
|
39 - ppa = strtol(cp, &eos, 10); |
|
40 - if (*eos != '\0') |
|
41 - { |
|
42 - snprintf(l->err_buf, LIBNET_ERRBUF_SIZE, |
|
43 - "%s(): %s bad unit number\n", __func__, l->device); |
|
44 - goto bad; |
|
45 - } |
|
46 |
|
47 if (*(l->device) == '/') |
|
48 { |
|
49 @@ -157,6 +162,7 @@ |
|
50 sprintf(dname, "%s/%s", DLPI_DEV_PREFIX, l->device); |
|
51 } |
|
52 #ifdef HAVE_DEV_DLPI |
|
53 + |
|
54 /* |
|
55 * Map network device to /dev/dlpi unit |
|
56 */ |
|
57 @@ -179,6 +185,7 @@ |
|
58 goto bad; |
|
59 } |
|
60 #else |
|
61 + |
|
62 /* |
|
63 * Try device without unit number |
|
64 */ |
|
65 @@ -186,6 +193,40 @@ |
|
66 cp = strchr(dname, *cp); |
|
67 *cp = '\0'; |
|
68 |
|
69 + /* |
|
70 + * First try the /dev/net vanity device name: |
|
71 + * /dev/net/<original_with_num> (DLPI style 1), |
|
72 + * and then fallback to the original device name. |
|
73 + */ |
|
74 + dev_str_len = strlen("/dev/"); |
|
75 + memset(dev_net_dname, 0, sizeof(dev_net_dname)); |
|
76 + |
|
77 + if(strlen(dname2) > dev_str_len) { |
|
78 + snprintf(dev_net_dname, sizeof(dev_net_dname), |
|
79 + "/dev/net/%s", dname2+dev_str_len); |
|
80 + } |
|
81 + |
|
82 + l->fd = open(dev_net_dname, O_RDWR); |
|
83 + |
|
84 + if(l->fd == -1) { |
|
85 + goto old_style_open; |
|
86 + } |
|
87 + |
|
88 + cp = dev_net_dname; |
|
89 + while(*cp && !isdigit((int)*cp)) { |
|
90 + cp++; |
|
91 + } |
|
92 + if(*cp) { |
|
93 + ppa = atoi(cp); |
|
94 + } else { |
|
95 + ppa = 0; |
|
96 + } |
|
97 + |
|
98 + goto opened_device; |
|
99 + |
|
100 + /* If opening device via /dev/net fails */ |
|
101 + old_style_open: |
|
102 + |
|
103 l->fd = open(dname, O_RDWR); |
|
104 if (l->fd == -1) |
|
105 { |
|
106 @@ -223,6 +264,9 @@ |
|
107 ppa = 0; |
|
108 } |
|
109 #endif |
|
110 + |
|
111 + opened_device: |
|
112 + |
|
113 /* |
|
114 * Attach if "style 2" provider |
|
115 */ |