![if !IE]> <![endif]>
Raw sockets, are those that bypass the TCP and IP layers and pass the ICMPv4, (Internet Control Message Protocol), IGMPv4 ()Internet Group Management Protocol – used with multicasting) and ICMPv6 packets directly to the link layers.
This allows the application to build ICMP and IGMP entirely as user processes instead of putting more code into the kernel. Examples are route discovery daemon which processes router advertisement and router solicitation are built this way.
With raw sockets a process can read and write IPv4 datagram with IPv4 protocol filed ( an 8 bit filed in IPv4 packet) that is not processed by the kernel. Most kernels process datagrams containing values of 1 (ICMP), 2 (IGMP), 6 (TCP), and 17 (UDP). But values like 89 (OSPF) routing protocol does not use TCP or UDP but uses IP directly by setting the protocol field to 89.
With raw sockets, a process can build its own IPv4 header using the IP_HDRINCL socket option
We learn the raw socket creation, input and the output and developing few programs that work with IPv4 and IPv6.
RAW SOCKET CREATION
1. To create raw sockets, the second argument in socket function SOCK_RAW. And the third argument is nonzero (normally) as shown below:
Sockfd = socket (AF_INET, SOCK_RAW, protocol);
In this the protocol is th one of the constants defined by IPPROTO_XXX which is done by including <netinet/in.h> header. For example IPPROO_ICMP. Only super user can create raw socket.
2. The IP-HDRINCL socket option can be set to: const int ON =1;
if (setsocketopt(sockfd, IPPROTO_IP, IP_HDRINCL, &ON, soze0f(ON)) <0) error
3. Bind may not be called on raw sockets. If called, it sets the local IP address and not the port number as there is no concept of port number with raw sockets. With regard to output, calling bind sets the IP address that will be used for datagrams sent on the raw socket (only if IP_HDRINCL socket option is not set). If bind is not called, the kernel sets the source IP address of the outgoing interface.
4. connect can be call on the raw socket but this is also rare. This function sets only the foreign address and again there is no concept of port number. With regard to output, calling connect lets us call write or send instead of sendto, since the destination IP address is already specified.
Raw Socket Output:
The output of raw socket is governed by the following rules:
• Normal output is performed by calling sendto or sendmsg and specifying the destination IP address. IN case the socket has been connected, write and send functions can be used.
• If the IP_HDRINCL option is not set, the IP header will be built by the kernal and it will be prepend it to the data.
• If IP_HDRINCL is set, the header format will remain the same and the process builds the entire IP header except the IPv4 identification field which is set to 0 by the kernel
• The kernel fragments the raw packets that exceed the outgoing interface.
• All fields in the protocol headers sent or received on a raw IPv6 sockets are in network byte order.
• There ae no option fields in IPv6 format. Almost all fields in an IPv6 header and all extension headers (Optional header that follow have their own length field. There is a separate fragmentation header.) are available to the application through socket options.
• Checksum are handled differently.
Copyright © 2018-2023 BrainKart.com; All Rights Reserved. Developed by Therithal info, Chennai.