locked
getaddrinfo, GetAddrInfoW and UTF8 string for pNodeName RRS feed

  • Question

  • I am trying to retrieve the IP of a machine with a non-ASCII name using the mentioned functions, I have noticed the following -

    1. GetAddrInfoW - When I try to pass the wide char version of the machine name to this function, name resolution works properly.
    2. getaddrinfo - When I try to pass the UTF8 version of the machine name (properly null terminated), name resolution does not work

    Please note the msdn link for GetAddrInfoW mentions that finally the UTF8 version goes on the wire. Then I dont understand

    • Why does the getaddrinfo function not work, when I am sending the same UTF8 buffer parameter for pNodeName that is sent on the wire when GetAddrInfoW is called?
    • I noticed that on the wire getaddrinfo does not send the same buffer, it sends a slightly modifed version, what are the modifications for?

    Any help will be appreciated?

    [Let me know if I need to post this in some other forum]


    • Edited by Nishchal A Thursday, March 29, 2012 3:32 PM
    Thursday, March 29, 2012 2:55 PM

Answers

  • On 3/29/2012 10:55 AM, Nishchal A wrote:

    I am trying to retrieve the IP of a machine with a non-ASCII name using the mentioned functions, I have noticed the following -

    1. GetAddrInfoW - When I try to pass the wide char version of the machine name to this function, name resolution works properly.
    2. getaddrinfo - When I try to pass the UTF8 version of the machine name (properly null terminated), name resolution does not work

    Windows API doesn't do anything in UTF-8. If the name is representable in current system code page (CP_ACP), getaddrinfo might have a chance. But generally, wide versions of API functions (those that take UTF-16, usuarlly in the form of WCHAR*) are your best bet.

    Please note the msdn link for
    GetAddrInfoW<http://msdn.microsoft.com/en-us/library/windows/desktop/ms738519(v=vs.85).aspx>mentions
    that finally the UTF8 version goes on the wire.

    That doesn't really matter. I doubt getaddrinfo sends its parameter directly onto the wire. I wouldn't be surprised if getaddrinfo converts its parameter from CP_ACP to Unicode (that is, UTF-16), then calls GetAddrInfoW.

    * I noticed that the getaddrinfo does not send the same buffer and sends a slightly modifed version, what are the modifications for?

    Modified in what way?


    Igor Tandetnik

    • Proposed as answer by Helen Zhao Tuesday, April 3, 2012 5:34 AM
    • Marked as answer by Helen Zhao Monday, April 9, 2012 2:03 AM
    Thursday, March 29, 2012 3:41 PM