176 ULONG size; |
176 ULONG size; |
177 DWORD ret; |
177 DWORD ret; |
178 int count; |
178 int count; |
179 netif *netifP; |
179 netif *netifP; |
180 DWORD i; |
180 DWORD i; |
181 int lo=0, eth=0, tr=0, fddi=0, ppp=0, sl=0, wlan=0, net=0; |
181 int lo=0, eth=0, tr=0, fddi=0, ppp=0, sl=0, wlan=0, net=0, wlen=0; |
182 |
182 |
183 /* |
183 /* |
184 * Ask the IP Helper library to enumerate the adapters |
184 * Ask the IP Helper library to enumerate the adapters |
185 */ |
185 */ |
186 size = sizeof(MIB_IFTABLE); |
186 size = sizeof(MIB_IFTABLE); |
258 * Allocate a netif structure and space for the name and |
258 * Allocate a netif structure and space for the name and |
259 * display name (description in this case). |
259 * display name (description in this case). |
260 */ |
260 */ |
261 curr = (netif *)calloc(1, sizeof(netif)); |
261 curr = (netif *)calloc(1, sizeof(netif)); |
262 if (curr != NULL) { |
262 if (curr != NULL) { |
|
263 wlen = MultiByteToWideChar(CP_OEMCP, 0, ifrowP->bDescr, |
|
264 ifrowP->dwDescrLen, NULL, 0); |
|
265 if(wlen == 0) { |
|
266 // MultiByteToWideChar should not fail |
|
267 // But in rare case it fails, we allow 'char' to be displayed |
|
268 curr->displayName = (char *)malloc(ifrowP->dwDescrLen + 1); |
|
269 } else { |
|
270 curr->displayName = (wchar_t *)malloc(wlen*(sizeof(wchar_t))+1); |
|
271 } |
|
272 |
263 curr->name = (char *)malloc(strlen(dev_name) + 1); |
273 curr->name = (char *)malloc(strlen(dev_name) + 1); |
264 curr->displayName = (char *)malloc(ifrowP->dwDescrLen + 1); |
|
265 |
274 |
266 if (curr->name == NULL || curr->displayName == NULL) { |
275 if (curr->name == NULL || curr->displayName == NULL) { |
267 if (curr->name) free(curr->name); |
276 if (curr->name) free(curr->name); |
268 if (curr->displayName) free(curr->displayName); |
277 if (curr->displayName) free(curr->displayName); |
269 curr = NULL; |
278 curr = NULL; |
280 * Populate the interface. Note that we need to convert the |
289 * Populate the interface. Note that we need to convert the |
281 * index into its "friendly" value as otherwise we will expose |
290 * index into its "friendly" value as otherwise we will expose |
282 * 32-bit numbers as index values. |
291 * 32-bit numbers as index values. |
283 */ |
292 */ |
284 strcpy(curr->name, dev_name); |
293 strcpy(curr->name, dev_name); |
285 strncpy(curr->displayName, ifrowP->bDescr, ifrowP->dwDescrLen); |
294 if (wlen == 0) { |
286 curr->displayName[ifrowP->dwDescrLen] = '\0'; |
295 // display char type in case of MultiByteToWideChar failure |
|
296 strncpy(curr->displayName, ifrowP->bDescr, ifrowP->dwDescrLen); |
|
297 curr->displayName[ifrowP->dwDescrLen] = '\0'; |
|
298 } else { |
|
299 // call MultiByteToWideChar again to fill curr->displayName |
|
300 // it should not fail, because we have called it once before |
|
301 if (MultiByteToWideChar(CP_OEMCP, 0, ifrowP->bDescr, |
|
302 ifrowP->dwDescrLen, curr->displayName, wlen) == 0) { |
|
303 JNU_ThrowByName(env, "java/lang/Error", |
|
304 "Cannot get multibyte char for interface display name"); |
|
305 free_netif(netifP); |
|
306 free(tableP); |
|
307 free(curr->name); |
|
308 free(curr->displayName); |
|
309 free(curr); |
|
310 return -1; |
|
311 } else { |
|
312 curr->displayName[wlen*(sizeof(wchar_t))] = '\0'; |
|
313 curr->dNameIsUnicode = TRUE; |
|
314 } |
|
315 } |
|
316 |
287 curr->dwIndex = ifrowP->dwIndex; |
317 curr->dwIndex = ifrowP->dwIndex; |
288 curr->ifType = ifrowP->dwType; |
318 curr->ifType = ifrowP->dwType; |
289 curr->index = GetFriendlyIfIndex(ifrowP->dwIndex); |
319 curr->index = GetFriendlyIfIndex(ifrowP->dwIndex); |
290 |
320 |
291 /* |
321 /* |