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!