Application Layer 1
Raw Sockets and ICMP Raw Sockets and ICMP
Srinidhi Varadarajan
11/4/2002 2
Topics Topics
Raw sockets Internet Control Message Protocol
(ICMP)
Code Examples
– Ping – Traceroute
11/4/2002 3
Raw Sockets Raw Sockets
Usually, sockets are used to build
applications on top of a transport protocol
– Stream sockets (TCP) – Datagram sockets (UDP)
Some applications need to access a lower
layer protocol
– Control protocols built on IP rather than UDP
- r TCP, such as ICMP and IGMP
– Experimental transport protocols
A “raw” socket allows direct access to IP
– Used to build applications on top of the network layer
11/4/2002 4
Creating a Raw Socket Creating a Raw Socket
Standard socket() call used to create a raw
socket
– Family is AF_INET, as for TCP or UDP – Socket type is SOCK_RAW instead of SOCK_STREAM or SOCK_DGRAM – Socket protocol needs to be specified, e.g. IPPROTO_ICMP (often left at 0 for UDP or TCP sockets) socket(AF_INET, SOCK_RAW, IPPROTO_ICMP)
11/4/2002 5
Socket Types Socket Types
Stream socket SOCK_STREAM 1 Datagram socket SOCK_DGRAM 2 Raw protocol interface SOCK_RAW 3 Reliably delivered message SOCK_RDM 4 Sequenced packet stream SOCK_SEQPACKET 5
11/4/2002 6
Protocols Protocols
IP (dummy) IPPROTO_IP ICMP IPPROTO_ICMP 1 IGMP IPPROTO_IGMP 2 Gateway IPPROTO_GGP 3 TCP IPPROTO_TCP 6 PUP IPPROTO_PUP 12 UDP IPPROTO_UDP 17 XND IDP IPPROTO_IDP 22 Net Disk IPPROTO_ND 77 Raw IP IPPROTO_RAW 255 IP (dummy) IPPROTO_IP ICMP IPPROTO_ICMP 1 IGMP IPPROTO_IGMP 2 Gateway IPPROTO_GGP 3 TCP IPPROTO_TCP 6 PUP IPPROTO_PUP 12 UDP IPPROTO_UDP 17 XND IDP IPPROTO_IDP 22 Net Disk IPPROTO_ND 77 Raw IP IPPROTO_RAW 255
Protocol values
– Used to define the Protocol field in the IP header