So Sup Forums how do i create packets by hand?

So Sup Forums how do i create packets by hand?
I can use TCP and UDP to transfer data and what not, but how do i manually create, send and receive packets, including filling out all the info like receivers address, senders address, etc. manually?

I use C and debian btw if thats relevant

Other urls found in this thread:

beej.us/guide/bgnet/
twitter.com/SFWRedditGifs

You could capture a TCP packet in Wireshark and could view it as zeros and ones (that would be pretty much the physical level of how the packet travels on the cable) but i am not sure how could you define it entirely.

One of the problems would be that your network card and/or drivers would try to encapsulate your completed packets again i think which would fuck them up. (i am not sure about this one but it seems plausible)

What i mean is that you define an ethernet-->ip-->tcp-->http packet in software then your networking hardware would encapsulate it again like ethernet-->ip-->ethernet-->ip-->tcp-->http

>So Sup Forums how do i create packets by hand?
a packet is usually defined with a Struct in C

specifically, one with the packet's data itself at the very end, so it can hang off without affecting alignment.

Implement/copy a packet struct and fill it up with your headers and data.

Can you even go below the level of TCP/UDP packets from software? Wouldn't the IP and ethernet header stuff happen in drivers and/or hardware?

>TCP packet
>PACKET

packet is the PDU for the Internet layer. What you are referring to is a TCP SEGMENT. Yes, you actually can put ANY payload in an IP packet, not only TCP, UDP or ICMP. However most firewalls will drop this traffic as garbage.

It depends on how much layers are in control by the card.
Usually normal consumer cards provide layers 1 and 2, meaning that from 3 onwards is all done by kernel and software.
Some cards can offload TCP off the CPU (TOE) and the card itself will be in charge of layers 3 and 4 too, which means your kernel/application has to do very little (but can also see very little of what happens).

beej.us/guide/bgnet/
Now fuck off

But if i don't want to get my shit dropped as garbage then what is the deepest i can go? Writing the data field of a TCP segment/UDP datagram?

Would it be possible to capture a packet in wireshark to see how a valid packet looks like then get a microcontroller to send that sequence of ones and zeros into a UTP cable? Just to see how this stuff goes.

tfw i put some of those code examples into Dev-C++ and while they all compiled fine the command line disappeared immediately

This is correct, because the program is terminated when you leave the main function or call exit( int ).

Do you even know how to program?

You can see the binary representation of all PDUs in Wireshark. But why do you even want to send IP packets with arbitrary payloads? The network driver on the destination host can't assign the packet content to any application and will silently drop it.

Try scapy.

Wireshark can only see down to OSI layer 2. The physical layer is done by the network card and absolutely transparent to the system, this includes channel coding, error detection, electrical modulation, multiplexing, collision detection and avoiding and other stuff.

It would be a lie to say yes but when i do something trivial like printf-ing bullshit then the command line window stays.

Maybe you have a getchar() in your program.

Why do you even open a new command shell window? Just use a proper IDE like Eclipse and start your program from the inbuilt shell. Does your example program even write to the standard output?

>windows users learn how to program

You could use a non-autistic language

nemesis or scapy. i like scapy because it uses libpcap whereas nemesis uses libnet. some people like perl and cpan, but why.

It teaches TCP and UDP you faggot, where else do you think I learned those from?