The select system call is used in multiplexed I/O. The select system call blocks on a set of File descriptors (FD) until one of the FDs is ready for read/write. The select system call is provided below FIG Courtesy : The Linux Programming Interface – Michael Kerrisk The parameters of the API are explained below. […]
Select and Poll API
The Select and Poll API provide a means to perform multiplexed I/O on sockets from an application. In Linux, all opened sockets are file descriptors. If a particular application wishes to read from or write into multiple file descriptors, the program has to wait on the different file descriptors to know when data can be […]
IPv6 Socket Code Example
All the previous examples of socket programming in this website have been based on IPv4. In this code example, we see a stream IPv6 socket connection. The code for IPv6 is very similar to the IPv4 connection with minor changes in socket structure. For the interested reader, the IPv4 Socket example for stream sockets is […]
Raw Socket Code – IP_HDRINCL Code example
The previous code example (provided here) showed the usage of IPPROTO_RAW. In the current example, the protocol field is kept as IPPROTO_UDP (or any L4 protocol). However, the setsockopt API is used to set the IP_HDRINCL flag. The setting of this flag will again stop the kernel from adding the IP header and the onus […]
Raw Socket Code – IPPROTO_RAW example
We have not seen the usage of IPPROTO_RAW as a protocol in all of the previous articles. The current article provides a code example for IPPROTO_RAW as the protocol field in the socket API. If IPPROTO_RAW is used, then the IP header needs to be formulated by the application. The sample code fills in a […]
Raw Socket Communication with Data Link Layer – code example
The Raw socket can be used to send and receive data from the L2 layer directly. To achieve this, a suitable socket protocol type needs to be sent out. we will use ETH_P_ARP for the ARP L2 protocol. The sample code only transmits a single ARP packet. An interested reader can add the receive code […]
Raw Socket Communication with Data Link Layer
In the previous examples, we used the TCP and UDP protocols and added the TCP/UDP headers in the sample application. The IP header was added by the linux kernel since we had not set the IP_HDRINCL flag via setsockopt API or used IPPROTO_RAW for the protocol in the socket API. However, Raw Sockets can be […]
Analysis of Raw socket code with connect and Bind API
The code examples and setup are provided at the links below Raw socket code setup Raw socket code example with connect and bind API – TCP Raw socket code example with connect and bind API – UDP The TCP/UDP headers are added by the application. The output of the TCP and UDP code is provided […]
Raw Socket Example with Connect and Bind API – (UDP example)
The below code provides an example UDP code for a raw socket. The code setup and raw socket basics for the the sample code can be found at the links below Raw Socket Example with Connect and Bind API – setup Using Connect and Bind API with a Raw socket The UDP header is added […]
Raw Socket Example with Connect and Bind API
For the below code, to understand the setup requirements, once can check the link below Raw Socket Example with Connect and Bind API – setup The below code creates the TCP header and basically resends the same TCP packet over and over again in a “while 1” loop. Run the server side code first and […]