none
connect函数连接ipv6地址返回10049错误 RRS feed

  • 问题

  • struct sockaddr_in6 svaddr;
    if((svsk=socket(AF_INET6,SOCK_STREAM,0))<0){
        printf("soket error:%d\n",GetLastError());
        return;
    }
    svaddr.sin6_family=AF_INET6;
    svaddr.sin6_port=htons(MYPORT);
    inet_pton(AF_INET6,ipaddr,&(svaddr.sin6_addr));
    if(connect(svsk,(struct sockaddr *)&svaddr,sizeof(svaddr))<0){
        printf("connect error:%d\n",GetLastError());
        return;
    }

    这是部分代码 首先所给的地址肯定没问题,服务端程序也没问题,同样的代码在linux下运行良好

    但是在vs2010下面编译运行是connect出错,错误是10049

    2012年6月16日 15:02

全部回复

  • WSAEADDRNOTAVAIL
    10049

    Cannot assign requested address.

    The requested address is not valid in its context. This normally results from an attempt to bindto an address that is not valid for the local computer. This can also result from connectsendto,WSAConnectWSAJoinLeaf, or WSASendTo when the remote address or port is not valid for a remote computer (for example, address or port 0).

    还有,你该用WSAGetLastError


    0xDEADBEEF

    2012年6月17日 13:58
    版主
  • 拜托,我肯定知道10049 的含义,我的意思是为什么出这个错误
    2012年6月17日 14:02
  •  
    Cannot assign requested address.
    The requested address is not valid in its context. This normally results from an attempt to bindto an address that is not valid for the local computer. This can also result from connect, sendto,WSAConnect, WSAJoinLeaf, or WSASendTo when the remote address or port is not valid for a remote computer (for example, address or port 0).


    拜托,上面不是说有相关的原因吗?

     


    Please mark this reply as answer if it helps you! Thanks for your cooperation! Good Luck to you.

    2012年6月19日 7:27
  • 请问你仔细看过我问题的描述吗?
    2012年6月19日 7:35