Raw Sockets What are Raw Sockets Allows you
- Slides: 29
Raw Sockets
What are Raw Sockets? • Allows you to bypass the TCP/UDP layers. • Send/receive your own packets, with your own headers. • You need to do all protocol processing at user-level.
Typical Uses • ICMP messages – ping generates ICMP echo requests and received ICMP echo replies. • Routing protocols – gated implements OSPF routing protocol. – Uses IP packets with protocol ID 89 – not supported by kernel. • Hacking – Generating your own TCP/UDP packets with spoofed headers
Raw socket creation • Only root can open a raw socket. sockfd = socket(AF_INET, SOCK_RAW, proto) where proto is IPPROTO_RAW, IPPROTO_ICMP etc.
Raw socket output • As usual – sendto(), sendmsg() etc. • IP_HDRINCL option – Specifies whether the process or the kernel builds the IP header. /* allow process to build IP header */ int on=1; setsockopt( sockfd, IPPROTO_IP, IP_HDRINCL, &on, sizeof(on))
Raw socket input • Normally using recvfrom() • Conditions for a packet to match raw socket – If protocol parameter was specified, only packets with that protocol value are delivered. – If bind() was called on raw socket, only packets destined to bound IP address are delivered. – If connect() was called, only packets from connected address are delivered.
Which protocol types are delivered? • TCP and UDP never reach raw sockets – Kernel IP stack handles these – Linux implementation is an exception. • All ICMP except – ICMP echo request – Timestamp request – Mask request • All IGMP • All other protocols that kernel doesn't understand – Such as OSPF
Exercise Write a simple “Hello” exchange program using raw sockets that implements your own protocol on top of IP.
Java Reference Book “Thinking in Java” by Bruce Eckel Book is online at http: //www. mindview. net/books/TIJ
Levels of abstraction Object oriented languages (C++, Java) Abstracting the problem as object interactions Imperative languages (C, FORTRAN, ALGOL) Abstracting the machine model Assembly language Low-level machine details Machine
Object • An object has – State (internal data) – Behavior (methods that operate on data) – Identity (object can be addressed uniquely)
Objects… • Class defines properties of a set of similar objects. – Think of it as type of the object • Protection boundaries define what object state is visible to others. • Inheritance allows a new class to inherit properties of an earlier class without re-defining them. • Interface defines what requests others can make to a particular object
Parent class Interface Child classes
Primitive Data types • • boolean - false char - ‘u 0000’ (null) byte - (byte)0 short - (short)0 int - 0 long - 0 L float - 0. 0 f double -0. 0 d
Creating a class Circle { public : Circle(int x, int y, float r) {…} void draw(){…} Methods void erase(){…} void move(){…} private : int x_; Fields int y_; float radius_; }
Creating an object Circle c = new Circle(10, 20, 5); c. draw(); c. move(); c. erase();
Inheritance abstract class Shape { public : Shape(int x, int y) { x_ = x; y_ = y; } abstract void draw(); abstract void erase(); abstract void move(); protected : int x_; int y_; }
Inheritance… class Circle extends Shape { Circle(int x, int y, float r){ super(x, y); radius_ = r; } void draw() {…} void erase(){…} void move(){…} protected : float radius_; }
Inheritance… class Square extends Shape { Square(int x, int y, float w){ super(x, y); width_ = r; } void draw() {…} void erase(){…} void move(){…} protected : float width_; }
void do. Stuff(Shape s) { s. erase(); //. . . s. draw(); } Circle c = new Circle(); Square s = new Square(); Line l = new Line(); do. Stuff(c); do. Stuff(s); do. Stuff(l);
Interfaces interface Draw. Object { // automatically public void draw(); void erase(); void move(); // Compile-time constant: int SOME_CONST = 5; // static & final }
class Shape { public : Shape(int x, int y) { x_ = x; y_ = y; } protected : int x_; int y_; }
class Circle extends Shape implements Draw. Object { Circle(int x, int y, float r){ super(x, y); radius_ = r; } void draw() {…} void erase(){…} void move(){…} protected : float radius_; }
class Square extends Shape implements Draw. Object { Square(int x, int y, float w){ super(x, y); width_ = r; } void draw() {…} void erase(){…} void move(){…} protected : float width_; }
static members • static fields or methods have one instance across all object instances class X { static int i = 0; …… } x 1 = new X(); x 2 = new X(); x 1. i++; x 2. i++; System. out. println(“Result = “ + x 2. i); Result = 2
final member/class • final class X { … } Final classes cannot be extended. • class X { final int m(); } Final methods cannot be overridden. • int mthd(final My. Class mc) {…} – Final arguments cannot be modified. • final int MY_CONST = 10; – Final fields/references are constants
Things you should learn from TIJ • Packaging your classes - Chapter 5 • Java I/O system - Chapter 11 • Error handling with exceptions - Chapter 10 • Applets - Chapter 14
Using Standard Java Packages java import java. lang. *; public class Hello. Date { public static void main(String[] args) { System. out. println("Hello, it's: "); System. out. println(new Date()); } }
Some other packages… • • • java. net java. rmi java. io java. applet java. awt java. math
- Insidan region jh
- Linux raw sockets
- What are raw sockets
- Bullets smacking the belly out of the air
- Spoken word poetry allows you to be anyone you want to be
- Office technology allows you to
- Ssrange in cobol example
- Silver sockets of the tabernacle
- Tcp ip sockets in c
- Tcp/ip sockets in java: practical guide for programmers
- Functions of a steering system
- Sockets direct protocol
- Berkeley sockets
- Reliable datagram sockets
- Elementary udp sockets
- Sockets and threads
- Cleanroom 380v sockets
- What is socket
- Tanenbaum linux
- Secure sockets
- Tcp/ip sockets in c
- Datacenter fabric
- Berkeley sockets
- Rain
- Agree or disagree questions about life
- If you think you can you can poem
- Tell me what you eat and i shall tell you what you are
- Wherever you lead i will follow
- The first trial of a controlled experiment allows
- It allows rapid entry of text by experienced users.