kiranvizru / psutil

Automatically exported from code.google.com/p/psutil
Other
0 stars 0 forks source link

Not listing NICs with unicode name in windows. #446

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1. Rename any NIC's connection to something with unicode characters, like 
"Połączenie lokalne" - default name in Polish version of Windows
2. Simply try get stats

What is the expected output?
Stats for every NIC

What do you see instead?
Stats only for NICs named without any unicode characters

What version of psutil are you using? What Python version?
Problem occurs both on Python 2.3.7 and 3.3, x86

On what operating system? Is it 32bit or 64bit version?
Windows 7 Pro x64 SP1

Please provide any additional information below.

Original issue reported on code.google.com by lukasgu...@gmail.com on 28 Nov 2013 at 6:12

GoogleCodeExporter commented 9 years ago
I tried to look into this but so far I wasn't able to find any solution as the 
way we're retrieving the NIC name is the one recommended by the official 
Windows documentation.

For posterity, problem is here:
https://code.google.com/p/psutil/source/browse/psutil/_psutil_mswindows.c?name=r
elease-1.2.1#2258

Original comment by g.rodola on 2 Dec 2013 at 7:42

GoogleCodeExporter commented 9 years ago
Also, another note: on my Windows 7 box the NIC gets listed but its name is 
truncated after encountering the first unicode character (whereas you state it 
is not listed at all - are you sure about that?).

Original comment by g.rodola on 2 Dec 2013 at 7:44

GoogleCodeExporter commented 9 years ago
Yup, I'm sure. Maybe try re-encode the string or add an option to strip unicode 
characters?
In my case NICs with unicode characters simply doesn't appear in the returned 
list, they aren't counted into overall stats too.

Original comment by lukasgu...@gmail.com on 7 Dec 2013 at 2:46

GoogleCodeExporter commented 9 years ago
Does ipconfig /all show the NIC?

Original comment by g.rodola on 7 Dec 2013 at 2:47

GoogleCodeExporter commented 9 years ago
Yes, of course.

Original comment by lukasgu...@gmail.com on 7 Dec 2013 at 2:49

GoogleCodeExporter commented 9 years ago
Any progress?

Original comment by lukasgu...@gmail.com on 31 Jan 2014 at 10:59

GoogleCodeExporter commented 9 years ago
No, sorry. I'm also pretty swamped lately because of a new job so I won't have 
time to dedicate to this issue (and psutil in general to be entirely honest).

Original comment by g.rodola on 1 Feb 2014 at 1:24

GoogleCodeExporter commented 9 years ago
Issue 491 has been merged into this issue.

Original comment by g.rodola on 31 Mar 2014 at 4:55

GoogleCodeExporter commented 9 years ago
The problem is here: 
https://code.google.com/p/psutil/source/browse/psutil/_psutil_mswindows.c?name=r
elease-1.2.1#2260

The Py_BuildValue able to decode only the UNICODE characters.
I made the following path to replace these characters with "_".

    while (pCurrAddresses) {
        py_nic_name = NULL;
        py_nic_info = NULL;
>   int i;
        ...
        sprintf(ifname, "%ws", pCurrAddresses->FriendlyName);
>   for (i=0; i<100; i++) {
>     if ( *(ifname+i) < 0 || *(ifname+i) > 256 ) {
>        // Replace the NON UNICODE character
>        *(ifname+i)='_';
>     }
>     if (*(ifname+i) == '\0') {
>       // end of friendly name
>       break;
>     }
>   }
        py_nic_name = Py_BuildValue("s", ifname);

@g.rodola: can you put this patch into the next release?

Original comment by szigeti....@gmail.com on 17 Apr 2014 at 12:59

GoogleCodeExporter commented 9 years ago
Issue 500 has been merged into this issue.

Original comment by g.rodola on 29 Apr 2014 at 5:40

GoogleCodeExporter commented 9 years ago
Despite this is a dirty hack I couldn't find any better solution so I committed 
your patch as of revision f5bbb4efc031.
Thanks.

Original comment by g.rodola on 29 Apr 2014 at 7:16

GoogleCodeExporter commented 9 years ago

Original comment by g.rodola on 13 May 2014 at 2:42