Using Connect and Bind on a Raw socket

Bind and connect API can be used on a RAW socket connection. However, it is normally not performed. The below snippets from the book “Unix Network Programming” describes the bind and connect operation as below:

“bind can be called on the RAW socket, but this is rare. This function sets only the local address: There is no concept of a port number with a raw socket. With regard to output, calling bind sets the source IP address that will be used for datagrams sent on the raw socket (but only if the IP_HDRINCL socket option is not set).

connect can be called on the raw socket, but this is rare. This function sets only the foreign address: Again, there is no concept of a port number with a raw socket. With regard to output, calling connect lets us call write or send instead of sendto, since the destination IP address is already specified.”

The next couple of articles will illustrate an example RAW socket implementation for TCP as the protocol. Since, the protocol is TCP, the TCP header has to be generated by the application itself. In the example, we keep re-sending the same TCP packet.

Raw Socket Example with Connect and Bind API – setup

 

Comments

  1. Pingback: Analysis of RAW socket IPPROTO_UDP code | Hitch Hiker's Guide to Learning

  2. Pingback: Raw Socket Example with Connect and Bind API – (UDP example) | Hitch Hiker's Guide to Learning

Leave a Reply

Your email address will not be published. Required fields are marked *