locked
IPv6 Address binding problem in Windows2000 with IPv6 Preview patch RRS feed

  • Question

  •  

    Hi,

     

    I have enabled IPv6 on two Windows2000 machines by installing IPv6 Preview Technology(Microsoft's IPv6 patch for windows2000). Then I connected these two machines via cross cable & ping6 is working between these two

    machines with IPv6 Linklocal addresses.

    I am unable bind IPv6 address in IPv6 enabled Win32 Server.c program using Visual Studio 2003 editor.

    The PROBLEM is if i invoke win32 bind() function by passing IPv6 address then its throwing 10049 error.

    Error is: WSAEADDRNOTAVAIL (10049) Cannot assign requested address.

    But the address is valid & ping6 is working with that same address.

     

    Please let me know how can I bind the ipv6 socket structure with IPv6-link local address?

     

    Please find my IPv6 Server.c program & correct me.

    -------------------------------------------------------------

    #define DEFAULT_BUFLEN 512

    #define DEFAULT_PORT  "27015"

    #define IPV6_ADDR_STR   "fe80::211:43ff:fe13Big Smile18b"

    #define IPV6_LOOPBACKADDR_STR "::1"

     

    int __cdecl main(void)

    {

    WSADATA wsaData;

    SOCKET ListenSocket = INVALID_SOCKET,

    ClientSocket = INVALID_SOCKET;

    struct addrinfo *result = NULL,

    hints;

    char recvbuf[DEFAULT_BUFLEN];

    int iResult, iSendResult;

    int recvbuflen = DEFAULT_BUFLEN;

    struct sockaddr_in6 sock6;

    // Initialize Winsock

    iResult = WSAStartup(MAKEWORD(2,2), &wsaData);

    if (iResult != 0) {

    printf("WSAStartup failed: %d\n", iResult);

    return 1;

    }

    ZeroMemory(&hints, sizeof(hints));

    hints.ai_family = PF_INET6;

    hints.ai_socktype = SOCK_STREAM;

    hints.ai_protocol = IPPROTO_TCP;

    hints.ai_flags = AI_NUMERICHOST | AI_PASSIVE;

    hints.ai_addrlen = sizeof(struct sockaddr);

    // Resolve the server address and port

    iResult = getaddrinfo(IPV6_ADDR_STR, DEFAULT_PORT, &hints, &result);

    if ( iResult != 0 ) {

    printf("getaddrinfo failed: %d\n", iResult);

    WSACleanup();

    return 1;

    }

    // Create a SOCKET for connecting to server

    ListenSocket = socket(result->ai_family, result->ai_socktype, result->ai_protocol);

    if (ListenSocket == INVALID_SOCKET) {

    printf("socket failed: %ld\n", WSAGetLastError());

    freeaddrinfo(result);

    WSACleanup();

    return 1;

    }

    iResult = bind( ListenSocket, result->ai_addr, (int)result->ai_addrlen);

    printf ("\n\nWSAGetLastError(): [%d]\n\n", WSAGetLastError());

    if (iResult == SOCKET_ERROR) {

    printf("bind failed: %d\n", WSAGetLastError());

    freeaddrinfo(result);

    closesocket(ListenSocket);

    WSACleanup();

    return 1;

    }

    .........and so on...

     

    Please correct this program ? suggest me.

     

    Regards,

    Mohan

     

     

    Friday, March 7, 2008 4:54 AM