问题描述
我试图让使用IPv6和UDP在C客户机/服务器程序。当程序绑定插座它返回WSAError 10049.我知道,这是与ADRESS名称的问题,但看不出什么问题。我希望有人可以提供帮助。
结构体sockaddr_in6服务器,客户端;
SOCKET袜子;
字符缓冲区[BUFFERSIZE]
LPTSTR recvBuff [1024];
DWORD recvBuffLen = 1024UL;
INT LEN = sizeof的(客户端);WORD wVersionRequested;
WSADATA WSADATA;
wVersionRequested = MAKEWORD(1,1);
调用WSAStartup(wVersionRequested,&安培; WSADATA);袜子=插座(AF_INET6,SOCK_DGRAM,0);
如果(袜子℃,)
错误(Fehler BEIM Anlegen DES套接字);server.sin6_family = AF_INET6;
server.sin6_port = htons(6000);
server.sin6_addr = IN6ADDR_ANY;如果(绑定(袜子,(结构sockaddr *)及服务器的sizeof(服务器))== -1)
错误(Fehler BEIM binden DES套接字);
出现此错误,当你试图命名本地套接字(指定本地地址和端口号)与绑定
,以无效本地计算机。地址
您应该使用 PF_INET
在这里,而不是 AF_INET
。它们具有相同的价值,但你不指定地址族 AF
在这里,你指定一个协议族 PF
。这仅仅是一个风格的建议。
我会建议 memset的
零以下数组,结构:
结构体sockaddr_in6服务器,客户端;
SOCKET袜子;
字符缓冲区[BUFFERSIZE]
LPTSTR recvBuff [1024];
I try to make a client/server program in C with IPv6 and UDP. When the program binds the socket it return the WSAError 10049. I know that this is a problem with the adress name but don't see whats the problem. I hope someone can help.
struct sockaddr_in6 server, client;
SOCKET sock;
char buffer[BUFFERSIZE];
LPTSTR recvBuff[1024];
DWORD recvBuffLen = 1024UL;
int len = sizeof(client);
WORD wVersionRequested;
WSADATA wsaData;
wVersionRequested = MAKEWORD(1,1);
WSAStartup(wVersionRequested, &wsaData);
sock = socket(AF_INET6, SOCK_DGRAM, 0);
if (sock < 0)
error("Fehler beim Anlegen des Sockets");
server.sin6_family = AF_INET6;
server.sin6_port = htons(6000);
server.sin6_addr = in6addr_any;
if (bind(sock, (struct sockaddr *) &server, sizeof(server)) == -1)
error("Fehler beim binden des Sockets");
This error occurs when you are trying to name the local socket (assign local address and port number) with bind
, to an address that is not valid for the local computer.
You should use PF_INET
here instead of AF_INET
. They have the same value, but you're not specifying an address family AF
here, you're specifying a protocol family PF
. This is just a style recommendation.
I would suggest to memset
zero the below arrays,structures:
struct sockaddr_in6 server, client;
SOCKET sock;
char buffer[BUFFERSIZE];
LPTSTR recvBuff[1024];
这篇关于bind()的失败与Windows套接字错误10049的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!