Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why can't I send this IP packet?

I'm trying to send an IP packet using c#.

    destAddress = IPAddress.Parse("192.168.0.198"),
    destPort = 80;

    // Create a raw socket to send this packet
    rawSocket = new Socket(AddressFamily.InterNetwork, SocketType.Raw, ProtocolType.IP);

    // Bind the socket to the interface specified
    IPEndPoint iep = new IPEndPoint(IPAddress.Parse("192.168.0.140"),0);
    rawSocket.Bind(iep);

    // Set the HeaderIncluded option since we include the IP header
    rawSocket.SetSocketOption( socketLevel, SocketOptionName.HeaderIncluded, 1 );

    // Send the packet!
    int rc = rawSocket.SendTo(builtPacket, new IPEndPoint(destAddress, destPort));
    Console.WriteLine("sent {0} bytes to {1}", rc, destAddress.ToString());

The content of builtPacket is shown below. It's an IP packet containing a TCP SYN packet (That's what I think I created anyway).

45 00 00 28 00 00 00 00 02 06 36 6E C0 A8 00 8C

C0 A8 00 C6 14 1E 00 50 00 00 00 00 00 00 00 00

05 02 FF FF E6 4F 00 00

The output is:

sent 40 bytes to 192.168.0.198

The problem is I don't see anything in the Wireshark trace. It's like the data is not getting far enough down the stack for Wireshark to see it? If I use a browser to connect to 192.168.0.198, Wireshark shows all the packets, but shows nothing when I try to send a packet using the above code and data.

My config:

  • I am running as admin so it's not a permissions problem.

  • Windows7 ( Not running in a VM)

  • Wireless connection only (IP config reports its IP as 192.168.0.140)

What am I doing wrong?

I'm sure Occam's Razor applies here, but I've been looking at this for hours and can't figure out what's wrong.

like image 595
TonyM Avatar asked May 11 '12 09:05

TonyM


People also ask

What is in an IP packet?

Each IP packet contains both a header (20 or 24 bytes long) and data (variable length). The header includes the IP addresses of the source and destination, plus other fields that help to route the packet. The data is the actual content, such as a string of letters or part of a webpage.

What is IP packet delivery?

All IP packets sent to the MN are delivered to the COA, not directly to the IP address of the MN. Packet delivery toward the mobile node is done using a tunnel. To be more precise, the COA marks the endpoint of the tunnel, i.e. the address where packets exit the tunnel.

What is the difference between an IP address and an IP packet?

What is the difference between an IP address and an IP Packet? An IP address is a sequence of numbers used to identify a device on an IP network. An IP packet contains an IP address AND the data intended for the machine identified by the IP address.

Can IP handle corrupt packets?

The Internet Protocol (IP) describes how to split messages into multiple IP packets and route packets to their destination by hopping from router to router. IP does not handle all the consequences of packets, however.


1 Answers

This question, backed up by MSDN, claims that Windows no longer (XP SP 2 through 7) allows transmission of TCP data using raw sockets.

like image 107
anton.burger Avatar answered Nov 01 '22 00:11

anton.burger