locked
Alternatives for inet_addr() method and ntohl() method in winrt

    Question

  • Hi,

    I am portin of win32 code to winrt, I could not find an alternative for  inet_addr()  method and ntohl() method in winrt.
    Please suggest some alternatives for these methods.

    Thanks,

    AKEV


    • Edited by AKEV Wednesday, November 21, 2012 11:46 AM
    Wednesday, November 21, 2012 11:45 AM

Answers

  • In winsock, ntohl()/htonl()  function just reverse the byte order. So you can implement it easily by changing byte order.

    http://social.msdn.microsoft.com/Forums/en-US/winappswithnativecode/thread/56b86d20-e7cd-4493-aa5b-e7bec729e8a6

    In winsock, inet_addr function converts a string containing an IPv4 dotted-decimal address into an unsigned long value. In performing different socket operation this unsigned long value is used.

    As HostName class can take both dotted-decimal and domain name, it is unnecessary to have such a function like inet_addr.

    As you mention, you are porting legacy code so you need to implement it manually. You can do it by segregating four octets and then performing some bit-wise operation.

    • Marked as answer by AKEV Thursday, November 22, 2012 6:29 AM
    Wednesday, November 21, 2012 3:04 PM