|
1 --- net-snmp-5.4.1/agent/mibgroup/kernel_sunos5.c Tue Apr 24 14:13:10 2012 |
|
2 +++ kernel_sunos5.c.latest Tue Apr 24 14:11:58 2012 |
|
3 @@ -1045,18 +1045,21 @@ |
|
4 static int |
|
5 _dlpi_open(const char *devname) |
|
6 { |
|
7 - char *devstr; |
|
8 + char devstr[255], devstrcpy[255]; |
|
9 int fd = -1; |
|
10 int ppa = -1; |
|
11 + int ret = -1; |
|
12 |
|
13 DEBUGMSGTL(("kernel_sunos5", "_dlpi_open called\n")); |
|
14 |
|
15 if (devname == NULL) |
|
16 - return (-1); |
|
17 + return (-1); |
|
18 + |
|
19 + ret = snprintf(devstr, sizeof(devstr), "/dev/%s", devname); |
|
20 |
|
21 - if ((devstr = malloc(5 + strlen(devname) + 1)) == NULL) |
|
22 - return (-1); |
|
23 - (void) sprintf(devstr, "/dev/%s", devname); |
|
24 + if(ret < 0 || ret > sizeof(devstr) - 1) |
|
25 + return -1; |
|
26 + |
|
27 DEBUGMSGTL(("kernel_sunos5:dlpi", "devstr(%s)\n", devstr)); |
|
28 /* |
|
29 * First try opening the device using style 1, if the device does not |
|
30 @@ -1067,13 +1070,49 @@ |
|
31 DEBUGMSGTL(("kernel_sunos5:dlpi", "style1 open(%s)\n", devstr)); |
|
32 if ((fd = open(devstr, O_RDWR | O_NONBLOCK)) < 0) { |
|
33 DEBUGMSGTL(("kernel_sunos5:dlpi", "style1 open failed\n")); |
|
34 - if (_dlpi_parse_devname(devstr, &ppa) == 0) { |
|
35 - DEBUGMSGTL(("kernel_sunos5:dlpi", "style2 parse: %s, %d\n", |
|
36 - devstr, ppa)); |
|
37 - /* try style 2 */ |
|
38 - DEBUGMSGTL(("kernel_sunos5:dlpi", "style2 open(%s)\n", devstr)); |
|
39 + fd = -1; |
|
40 + } else { |
|
41 + DEBUGMSGTL(("kernel_sunos5:dlpi", "style1 open succeeded\n")); |
|
42 + } |
|
43 |
|
44 - if ((fd = open(devstr, O_RDWR | O_NONBLOCK)) != -1) { |
|
45 + /* Creating a copy of the devname incase style 3 open |
|
46 + * is required |
|
47 + */ |
|
48 + ret = strlcpy(devstrcpy, devstr, sizeof(devstrcpy)); |
|
49 + |
|
50 + if(ret > sizeof(devstrcpy) - 1) |
|
51 + return -1; |
|
52 + |
|
53 + DEBUGMSGTL(("kernel_sunos5:dlpi", "devstrcpy(%s)\n", devstrcpy)); |
|
54 + |
|
55 + |
|
56 + if (fd == -1 ) { |
|
57 + ret = snprintf(devstr, sizeof(devstr), "/dev/net/%s", devname); |
|
58 + |
|
59 + if(ret < 0 || ret > sizeof(devstr) - 1) |
|
60 + return -1; |
|
61 + |
|
62 + DEBUGMSGTL(("kernel_sunos5:dlpi", "devstr(%s)\n", devstr)); |
|
63 + |
|
64 + /* try style 2 */ |
|
65 + |
|
66 + if ((fd = open(devstr, O_RDWR | O_NONBLOCK)) < 0) { |
|
67 + DEBUGMSGTL(("kernel_sunos5:dlpi", "style2 open failed\n")); |
|
68 + fd = -1; |
|
69 + } else { |
|
70 + DEBUGMSGTL(("kernel_sunos5:dlpi", "style2 open succeeded\n")); |
|
71 + } |
|
72 + } |
|
73 + |
|
74 + |
|
75 + if (fd == -1 ) { |
|
76 + if (_dlpi_parse_devname(devstrcpy, &ppa) == 0) { |
|
77 + DEBUGMSGTL(("kernel_sunos5:dlpi", "style3 parse: %s, %d\n", |
|
78 + devstrcpy, ppa)); |
|
79 + /* try style 3 */ |
|
80 + DEBUGMSGTL(("kernel_sunos5:dlpi", "style3 open(%s)\n", devstrcpy)); |
|
81 + |
|
82 + if ((fd = open(devstrcpy, O_RDWR | O_NONBLOCK)) != -1) { |
|
83 if (_dlpi_attach(fd, ppa) == 0) { |
|
84 DEBUGMSGTL(("kernel_sunos5:dlpi", "attached\n")); |
|
85 } else { |
|
86 @@ -1082,16 +1121,11 @@ |
|
87 fd = -1; |
|
88 } |
|
89 } else { |
|
90 - DEBUGMSGTL(("kernel_sunos5:dlpi", "style2 open failed\n")); |
|
91 + DEBUGMSGTL(("kernel_sunos5:dlpi", "style3 open failed\n")); |
|
92 } |
|
93 } |
|
94 - } else { |
|
95 - DEBUGMSGTL(("kernel_sunos5:dlpi", "style1 open succeeded\n")); |
|
96 } |
|
97 |
|
98 - /* clean up */ |
|
99 - free(devstr); |
|
100 - |
|
101 return (fd); |
|
102 } |
|
103 |
|
104 @@ -1106,7 +1140,9 @@ |
|
105 struct strbuf ctlbuf; |
|
106 char buf[MAX(DL_PHYS_ADDR_ACK_SIZE+64, DL_ERROR_ACK_SIZE)]; |
|
107 int flag = 0; |
|
108 - |
|
109 + struct pollfd pfd; |
|
110 + int timeout = 100; |
|
111 + |
|
112 DEBUGMSGTL(("kernel_sunos5:dlpi", "_dlpi_get_phys_address\n")); |
|
113 |
|
114 paddr_req.dl_primitive = DL_PHYS_ADDR_REQ; |
|
115 @@ -1119,7 +1155,22 @@ |
|
116 ctlbuf.maxlen = sizeof(buf); |
|
117 ctlbuf.len = 0; |
|
118 ctlbuf.buf = buf; |
|
119 - if (getmsg(fd, &ctlbuf, NULL, &flag) < 0) |
|
120 + |
|
121 + pfd.fd = fd; |
|
122 + pfd.events = POLLIN | POLLPRI; |
|
123 + |
|
124 + switch (poll(&pfd, 1, timeout)) { |
|
125 + default: |
|
126 + if (pfd.revents & POLLHUP) |
|
127 + return (-1); |
|
128 + break; |
|
129 + case 0: |
|
130 + return (-1); |
|
131 + case -1: |
|
132 + return (-1); |
|
133 + } |
|
134 + |
|
135 + if (getmsg(fd, &ctlbuf, NULL, &flag) < 0) |
|
136 return (-1); |
|
137 |
|
138 if (ctlbuf.len < sizeof(uint32_t)) |
|
139 @@ -1161,6 +1212,8 @@ |
|
140 struct strbuf ctlbuf; |
|
141 char buf[MAX(DL_INFO_ACK_SIZE, DL_ERROR_ACK_SIZE)]; |
|
142 int flag = 0; |
|
143 + struct pollfd pfd; |
|
144 + int timeout = 100; |
|
145 |
|
146 DEBUGMSGTL(("kernel_sunos5:dlpi", "_dlpi_get_iftype\n")); |
|
147 |
|
148 @@ -1175,7 +1228,22 @@ |
|
149 ctlbuf.maxlen = sizeof(buf); |
|
150 ctlbuf.len = 0; |
|
151 ctlbuf.buf = buf; |
|
152 - if (getmsg(fd, &ctlbuf, NULL, &flag) < 0) { |
|
153 + |
|
154 + pfd.fd = fd; |
|
155 + pfd.events = POLLIN | POLLPRI; |
|
156 + |
|
157 + switch (poll(&pfd, 1, timeout)) { |
|
158 + default: |
|
159 + if (pfd.revents & POLLHUP) |
|
160 + return (-1); |
|
161 + break; |
|
162 + case 0: |
|
163 + return (-1); |
|
164 + case -1: |
|
165 + return (-1); |
|
166 + } |
|
167 + |
|
168 + if (getmsg(fd, &ctlbuf, NULL, &flag) < 0) { |
|
169 DEBUGMSGTL(("kernel_sunos5:dlpi", "getmsg failed: %d\n", errno)); |
|
170 return (-1); |
|
171 } |