Thread: WinSock error 10049

  1. #1
    Registered User
    Join Date
    Nov 2008
    Posts
    127

    WinSock error 10049

    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?

  2. #2
    Registered User
    Join Date
    Dec 2007
    Posts
    2,675
    From here:

    Limitations on Raw Sockets

    On Windows 7, Windows Server 2008 R2, Windows Vista, and Windows XP with Service Pack 2 (SP2), the ability to send traffic over raw sockets has been restricted in several ways:

    * TCP data cannot be sent over raw sockets.
    * UDP datagrams with an invalid source address cannot be sent over raw sockets. The IP source address for any outgoing UDP datagram must exist on a network interface or the datagram is dropped. This change was made to limit the ability of malicious code to create distributed denial-of-service attacks and limits the ability to send spoofed packets (TCP/IP packets with a forged source IP address).
    * A call to the bind function with a raw socket is not allowed.

    These above restrictions do not apply to Windows Server 2008 , Windows Server 2003, or to versions of the operating system earlier than Windows XP with SP2.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Winsock issues
    By tjpanda in forum Windows Programming
    Replies: 3
    Last Post: 12-04-2008, 08:32 AM
  2. Winsock Messaging Program
    By Morgul in forum Windows Programming
    Replies: 13
    Last Post: 04-25-2005, 04:00 PM
  3. Winsock - Where do i start?
    By Brain Cell in forum Networking/Device Communication
    Replies: 5
    Last Post: 02-14-2005, 01:39 PM
  4. Where do I initialize Winsock and catch messages for it?
    By Lithorien in forum Windows Programming
    Replies: 10
    Last Post: 12-30-2004, 12:11 PM
  5. winsock
    By pode in forum Networking/Device Communication
    Replies: 2
    Last Post: 09-26-2003, 12:45 AM