1 Introduction to Raw Sockets 2 IP address Port address MAC address TCP/IP Stack 67 Bootp DHCP 176 2 OSPF 89 53 protocol frame type UDP Port # TCP Port.

Slides:



Advertisements
Similar presentations
Florida State UniversityCOP Advanced Unix Programming Raw Sockets Datalink Access Chapters 25, 26.
Advertisements

Taekyung Kim 0x410 ~ 0x International Standards Organization (ISO) is a multinational body dedicated to worldwide agreement on international.
Internet Control Protocols Savera Tanwir. Internet Control Protocols ICMP ARP RARP DHCP.
TELE 402 Lecture 11: Advanced UDP… 1 by Dr Z. Huang Overview Last Lecture –Nonblocking I/O and ioctl operations –Source: Chapter 16 & 17 of Stevens’ book.
CSE551: Computer Network Review r Network Layers r TCP/UDP r IP.
Raw Sockets CS-480b Dick Steflik Raw Sockets Raw Sockets let you program at just above the network (IP) layer You could program at the IP level using.
CSCE 515: Computer Network Programming Chin-Tser Huang University of South Carolina.
Elementary TCP Sockets Chapter 4 UNIX Network Programming Vol. 1, Second Ed. Stevens.
The Network Layer Chapter 5. The IP Protocol The IPv4 (Internet Protocol) header.
Socket Programming.
Chapter 5 The Network Layer.
CSCE 515: Computer Network Programming Chin-Tser Huang University of South Carolina.
Additional API functions and data-structures A look at how some information from lower-layers of the TCP/IP protocol stack could be accessed.
Shivkumar Kalyanaraman Rensselaer Polytechnic Institute 1 Internet Control Message Protocol (ICMP) Shivkumar Kalyanaraman Rensselaer Polytechnic Institute.
1 Application Presentation Session Transport Network Datalink Physical OSI model Application IPv4, IPv6 Device Driver Hardware TCPUDP Internet.
Internet Command Message Protocol (ICMP) CS-431 Dick Steflik.
1 Internet Control Message Protocol (ICMP) RIZWAN REHMAN CCS, DU.
1 CMPT 471 Networking II ICMP © Janice Regan, 2012.
4: Network Layer4a-1 IP datagram format ver length 32 bits data (variable length, typically a TCP or UDP segment) 16-bit identifier Internet checksum time.
Internet Control Message Protocol ICMP. ICMP has two major purposes: –To report erroneous conditions –To diagnose network problems ICMP has two major.
Petrozavodsk State University, Alex Moschevikin, 2003NET TECHNOLOGIES Internet Control Message Protocol ICMP author -- J. Postel, September The purpose.
Network Layer4-1 NAT: Network Address Translation local network (e.g., home network) /24 rest of.
© Janice Regan, CMPT 128, CMPT 371 Data Communications and Networking Network Layer ICMP and fragmentation.
Elementary UDP Sockets© Dr. Ayman Abdel-Hamid, CS4254 Spring CS4254 Computer Network Architecture and Programming Dr. Ayman A. Abdel-Hamid Computer.
Raw Sockets.
ECE 4110 – Internetwork Programming Client-Server Model.
Jan 29, 2008CS573: Network Protocols and Standards1 NAT, DHCP Autonomous System Network Protocols and Standards Winter
IT1352-NETWORK PROGRAMMING AND MANAGEMENT
ICMP : Internet Control Message Protocol. Introduction ICMP is often considered part of the IP layer. It communicates error messages and other conditions.
LWIP TCP/IP Stack 김백규.
© Jörg Liebeherr (modified by M. Veeraraghavan) 1 ICMP: A helper protocol to IP The Internet Control Message Protocol (ICMP) is the protocol used for error.
1 Internet Control Message Protocol (ICMP) Used to send error and control messages. It is a necessary part of the TCP/IP suite. It is above the IP module.
Internet Protocols. Address Resolution IP Addresses are not recognized by hardware. If we know the IP address of a host, how do we find out the hardware.
Advanced Sockets API-II Vinayak Jagtap
CPSC 441 TUTORIAL – FEB 13, 2012 TA: RUITNG ZHOU UDP REVIEW.
DoS Suite and Raw Socket Programming Group 16 Thomas Losier Paul Obame Group 16 Thomas Losier Paul Obame.
Transport Layer3-1 Chapter 4: Network Layer r 4. 1 Introduction r 4.2 Virtual circuit and datagram networks r 4.3 What’s inside a router r 4.4 IP: Internet.
TELE 402 Lecture 9: Daemon … 1 by Dr Z. Huang Overview Last Lecture –Broadcast and multicast This Lecture –Daemon processes and advanced I/O functions.
TELE 402 Lecture 12: Signal-Driven I/O & Raw Socket 1 Overview Last Lecture –Advanced UDP sockets and threads –Source: Chapters 22&26 of Stevens’ book.
Advanced UNIX programming Fall 2002, lecture 16 Instructor: Ashok Srinivasan Acknowledgements: The syllabus and power point presentations are modified.
Today’s topic: UDP Reliable communication over UDP.
1 Socket Options getsockopt and setsockopt functions Check options and obtain default values Generic socket options IPv4 socket options IPv6 socket options.
CMPT 471 Networking II Network Programming © Janice Regan,
UNIX Network Programming1 Chapter 13. Advanced I / O Functions.
© Jörg Liebeherr (modified by M. Veeraraghavan) 1 ICMP The PING Tool Traceroute program IGMP.
TCP/IP Illustrated, Volume 1: The Protocols Chapter 6. ICMP: Internet Control Message Protocol ( 월 ) 김 철 환
UDP : User Datagram Protocol 백 일 우
Lecture 21: Network Primer 7/9/2003 CSCE 590 Summer 2003.
Packet Switch Network Server client IP Ether IPTCPData.
1 Socket Interface. 2 Client-Server Architecture The client is the one who speaks first Typical client-server situations  Client and server on the same.
1 Socket Interface. 2 Basic Sockets API Review Socket Library TCPUDP IP EthernetPPP ARP DHCP, Mail, WWW, TELNET, FTP... Network cardCom Layer 4 / Transport.
4: Network Layer4-1 Chapter 4: Network Layer r 4. 1 Introduction r 4.2 Virtual circuit and datagram networks r 4.3 What’s inside a router r 4.4 IP: Internet.
SOCKET PROGRAMMING Presented By : Divya Sharma.
Internet Control Message Protocol (ICMP)
Internet Control Message Protocol (ICMP)
Dr. Richard Spillman Fall 2006
Internet Control Message Protocol (ICMP)
Internet Control Message Protocol
8 Network Layer Part V Computer Networks Tutun Juhana
Byungchul Park ICMP & ICMPv DPNM Lab. Byungchul Park
Internet Control Message Protocol (ICMP)
Internet Control Message Protocol (ICMP)
Internet Control Message Protocol (ICMP)
Internet Control Message Protocol (ICMP)
Internet Control Message Protocol (ICMP)
User Datagram Protocol (UDP)
Advanced I/O Functions
46 to 1500 bytes TYPE CODE CHECKSUM IDENTIFIER SEQUENCE NUMBER OPTIONAL DATA ICMP Echo message.
Socket Programming with UDP
32 bit destination IP address
Presentation transcript:

1 Introduction to Raw Sockets

2 IP address Port address MAC address TCP/IP Stack 67 Bootp DHCP OSPF protocol frame type UDP Port # TCP Port # 1 EGP

3 What can raw sockets do? r Bypass TCP/UDP layers r Read and write ICMP and IGMP packets m ping, traceroute, multicast daemon r Read and write IP datagrams with an IP protocol field not processed by the kernel m OSPF m user process versus kernel r Send and receive your own IP packets with your own IP header using the IP_HDRINCL socket option m can build and send TCP and UDP packets m testing, hacking m only superuser can create raw socket though r You need to do all protocol processing at user-level

4 User TCP ICMP UDP stack TCP stack 6 17 UDP 6 TCP 1 ICMP 2 IGMP 89 OSPF TCP port TCP port 17 UDP port RAW User UDP ICMP (ping, etc) RAW IGMP echo timestamp

5 Creating a Raw Socket r Can we use bind() with raw sockets? m rare, no concept of port r Can we use connect() with raw sockets? m rare, only foreign ip address int sockfd; sockfd = socket(AF_INET, SOCK_RAW, protocol); const int on = 1; setsockopt (sockfd, IPPROTO_IP, IP_HDRINCL, &on, sizeof(on); IPPROTO_ICMP IPPROTO_IGMP

6 Raw Socket Output  Sending raw socket packets by sendto or sendmsg  If IP_HDRINCL option not set ( i.e. header is not included ), the starting address of the data in sendto() specifies the first byte following the IP header  If IP_HDRINCL option set, the starting address of data in sendto() specifies the first byte of the IP header. r IP Header fields modified on sending by IP_HDRINCL m IP Checksum Always filled in. m Source Address Filled in when zero. m Packet Id Filled in when zero. m Total Length Always filled in.  Example: see Steven’s code under ping/send_v4.c, ping/send_v6.c

7 Raw Socket Input r Received TCP/UDP packets are NEVER passed to raw sockets. If needed, link layer is the place.  Receiving raw packets by recvfrom() or recvmsg() m Most ICMP packets are passed to all matching ICMP raw sockets except a few exceptions ICMP echo request, timestamp request m All IGMP packets are passed to all matching raw sockets m All IP datagrams with a protocol field not processed by the kernel (e.g. OSPF) are passed to all matching raw sockets r The entire datagram, including the IP header, is passed to the raw socket. Fragments are assembled first.  Example: steven’s code in ping/readloop.c and ping/proc_v4.c

8 Scatter read and gather write Vectored IO  Send and receive from one or more buffers with a single function call #include readv(int fd, const struct iovec *iov, int iovcnt); writev(int fd, const struct iovec *iov, int iovcnt); struct iovec { void *iov_base; /* addr. Of buffer */ size_t iov_len; /* size of buffer */ }

9 sendmsg and recvmsg most general of all the IO functions recvmsg(int sock, struct msghdr *msg, int flags); sendmsg(int sock, struct msghdr *msg, int flags); struct msghdr { void *msg_name; /* address if socket is unconnected */ socklen_t msg_namelen; /* size of above */ struct iovec *msg_iov; int msg_iovlen; void *msg_control; /* ancillary data */ socklen_t msg_controllen; int msg_flags; /* returned status by recvmsg */ } MSG_TRUNC MSG_CTRUNC. MSG_EOR (end of record) MSG_OOB scatter gather read/write buffer MSG_PEEK MSG_WAITALL

10 ICMP Format subtype

11 Ping Program r Create a raw socket to send/receive ICMP echo request and echo reply packets r Install SIGALRM handler to process output m Sending echo request packets every t seconds m Build ICMP packets (type, code, checksum, id, seq, sending timestamp as optional data) r Enter an infinite loop processing input m Use recvmsg() to read from the network m Parse the message and retrieve the ICMP packet m Print ICMP packet information, e.g., peer IP address, round- trip time r Source code: Steven’s under ping/

12 Traceroute program r Create a UDP socket and bind source port m To send probe packets with increasing TTL m For each TTL value, use timer to send a probe every three seconds, and send 3 probes in total r Create a raw socket to receive ICMP packets m If timeout, printing “ *” m If ICMP “port unreachable”, then terminate m If ICMP “TTL expired”, then printing hostname of the router and round trip time to the router r Source code: Steven’s traceroute/

Limitations r Loss of Reliability r No ports r Non Standard Communications r No automatic ICMP r No Raw TCP or UDP r Must have root (or administrator) privilege

When to use r When you need to control the IP header m applications like Ping and Traceroute m not all fields can be set using the IP APIs m Network Address Translation Firewalls r When your application requires optimum network speed m one level above the Link Layer m if you need reliability, you must build it into your application

Windows and Raw Sockets r WinSock 2.0 allows windows programmers to build advanced applications m Firewalls Network Address Translation Packet Filtering SYN Flood protection m Security IPSec support VPN Clients m Network Administration Packet Sniffers/Analyzers Pathway Analyzers (ping and traceroute)