locked
WSAStringToAddressA returns -1 for both IPV4 and IPV6 RRS feed

  • Question

  • Hi all

    i am trying to convert a numeric string to sockaddr structure, but these APIs always return -1 for both IPV4 and IPV6

    char *ipaddr = "10.112.45.43";
    sockaddr addr;
    memset(&addr,0,sizeof(sockaddr));
    addr.sa_family = AF_INET;
    int len = sizeof(sockaddr);
    int ret = ::WSAStringToAddressA(ipaddr,AF_INET,NULL,&addr,&len); (returns -1)

     

    char *ipaddr = "fe80::95b:b49c:40cd:b737%10";
    sockaddr_in6 addr;
    memset(&addr,0,sizeof(sockaddr_in6));
    addr.sa_family = AF_INET6;
    int len = sizeof(sockaddr_in6);
    int ret = ::WSAStringToAddressA(ipaddr,AF_INET6,NULL,&addr,&len); (returns -1)

    can anyone of you tell me what is wrong wiht my code.

     

    regards

    pradish

     

     

     

    Thursday, May 20, 2010 1:54 PM

All replies

  • You should call WSAGetLastError(); to figure out what happened.

    My guess based on your code is that you did not initialize Winsock  (WSAGetLastError() will return WSANOTINITIALISED).  Prior to using WinSock calls in your code call WSAStartup().

    Hope this helps


    Dusty Harper [MSFT]
    Microsoft Corporation
    ------------------------------------------------------------
    This posting is provided "AS IS", with NO warranties and confers NO rights
    ------------------------------------------------------------
    Monday, June 14, 2010 7:35 PM