Important Notice: Our web hosting provider recently started charging us for additional visits, which was unexpected. In response, we're seeking donations. Depending on the situation, we may explore different monetization options for our Community and Expert Contributors. It's crucial to provide more returns for their expertise and offer more Expert Validated Answers or AI Validated Answers. Learn more about our hosting issue here.

How do I send a TCP/IP packet through a raw socket?

IP packet raw send socket TCP
0
Posted

How do I send a TCP/IP packet through a raw socket?

0

Depending on what you want to send, you initially open a socket and give it its type. sockd = socket(AF_INET,SOCK_RAW,); You can choose from any protocol including IPPROTO_RAW. The protocol number goes into the IP header verbatim. IPPROTO_RAW places 0 in the IP header. Most systems have a socket option IP_HDRINCL which allows you to include your own IP header along with the rest of the packet. If your system doesn’t have this option, you may or may not be able to include your own IP header. If it is available, you should use it as such: char on = 1; setsockopt(sockd,IPPROTO_IP,IP_HDRINCL,&on,sizeof(on)); Of course, if you don’t want to include an IP header, you can always specify a protocol in the creation of the socket and slip your transport level header under it. You then build the packet and use a normal sendto().

Related Questions

What is your question?

*Sadly, we had to bring back ads too. Hopefully more targeted.

Experts123