I am trying to do raw sockets on Windows 7. In runtime when I do
Code:
// Initialize Winsock
iResult = WSAStartup(MAKEWORD(2,2), &wsaData);
if (iResult != 0) {
printf("WSAStartup failed: %d\n", iResult);
return 1;
}
// Create a SOCKET for connecting to server
sd = WSASocket(AF_INET, SOCK_RAW, IPPROTO_TCP, 0, 0, 0);
if (sd == INVALID_SOCKET) {
printf("Error at socket(): %ld\n", WSAGetLastError());
WSACleanup();
return 1;
}
int val = 1;
if (setsockopt(sd, IPPROTO_IP, IP_HDRINCL, (const char*)&val,
sizeof(val)) == SOCKET_ERROR) {
printf("IP_HDRINCL setsockopt failed: %ld\n", WSAGetLastError());
return 1;
}
I get "IP_HDRINCL setsockopt failed: 10049". 10049 is documented as Cannot assign requested address. I'm not trying to bind, so it's odd that this is my error num. What could be causing this error?