English 中文(简体)
Bind(a)一皮没有Pipv6地址
原标题:Bind() api fails with ipv6 address
  • 时间:2012-01-16 04:55:09
  •  标签:
  • ipv6

it works when iam trying to bind to my auto-config link local address. but when i try to bind to some manually assigned IPv6 address bind() fails with 10049 error. here is the code

bool StartServer()
{
  const char *Ip = " fe80::216:76ff:fe12:2661%4";
  SHORT nIPFamily = -1;
  int dSock;
  union 
 {
   struct sockaddr_in  saddr4;
   struct sockaddr_in6  saddr6;
 }ServerIP;

午餐会(和;ServerIP,0,sizeof(ServerIP);

 if(strstr(Ip,":"))
 {
   UCHAR MyIp[16];
   USHORT ScopeId = 0;
   ServerIP.saddr6.sin6_family = nIPFamily = AF_INET6;
   ServerIP.saddr6.sin6_port = htons( nPort );
   StringToAddress( Ip, MyIp ); //common function to convert string to address (16byte)
   memcpy( ServerIP.saddr6.sin6_addr.u.Byte, MyIp,16 );
   sscanf(strstr(Ip,"%")+1,"%d",&ScopeId);
   ServerIP.saddr6.sin6_scope_id = ScopeId;
   nAddLen = sizeof(sockaddr_in6);
   psockaddr = &ServerIP.saddr6;
 }

 if ((dSock = socket(nIPFamily, SOCK_STREAM, 0)) < 0)
 {
   AfxMessageBox("Failed to create server socket");
   return -1;
 }
 if (bind (dSock, (sockaddr*)psockaddr, nAddLen) < 0)
 {
   char errmsg[128];
   sprintf(errmsg,"Bind Failed with error %d",WSAGetlastError());
   AfxMessageBox(errmsg);
   return -1;
 }

请提出咨询意见。 超过2天,我 st!

问题回答

只有在使用全球预测时,才有链接-当地地址的使用范围,而不是增加。





相关问题
Force python mechanize/urllib2 to only use A requests?

Here is a related question but I could not figure out how to apply the answer to mechanize/urllib2: how to force python httplib library to use only A requests Basically, given this simple code: #!/...

Comparison operations on ipv6 address using C++

As IPV6 address has 16 bytes and their is no data type to store it in c++, i wanted to store the IPV6 address, and do some comparisions between to IPv6 address, please let me know how to do it

How do you determine equality between two IPv6 addresses?

I have an application that allows administrators to specify valid IP addresses from which web service requests can be made. I simply take the configured IP addresses and compare them against the ...

getaddrinfo() returning only ::1 as IPV6 address,

I m using getaddrinfo() to return all assigned IP addresses (both IPv4 and IPv6) for my local machine. I see that on XP, getaddrinfo() only returns ::1 ( I installed the IPV6 stack on 2 XP machine ...

How to initialize struct in6_addr?

I do know one method to do this, const struct in6_addr naddr6 = { { 0x3f, 0xfe, 0x05, 0x01, 0x00, 0x08, 0x00, 0x00, 0x02, 0x60, 0x97, 0xff, ...

热门标签