The POSIX Socket API



Similar documents
Tutorial on Socket Programming

ELEN 602: Computer Communications and Networking. Socket Programming Basics

ICT SEcurity BASICS. Course: Software Defined Radio. Angelo Liguori. SP4TE lab.

UNIX Sockets. COS 461 Precept 1

Unix Network Programming

Socket Programming in C/C++

Computer Networks Network architecture

Socket Programming. Kameswari Chebrolu Dept. of Electrical Engineering, IIT Kanpur

Programmation Systèmes Cours 9 UNIX Domain Sockets

Implementing Network Software

Lab 4: Socket Programming: netcat part

NS3 Lab 1 TCP/IP Network Programming in C

Introduction to Socket Programming Part I : TCP Clients, Servers; Host information

Generalised Socket Addresses for Unix Squeak

IT304 Experiment 2 To understand the concept of IPC, Pipes, Signals, Multi-Threading and Multiprocessing in the context of networking.

Networks. Inter-process Communication. Pipes. Inter-process Communication

Operating Systems Design 16. Networking: Sockets

INTRODUCTION UNIX NETWORK PROGRAMMING Vol 1, Third Edition by Richard Stevens

Socket Programming. Srinidhi Varadarajan

Introduction to Socket programming using C

Socket Programming. Request. Reply. Figure 1. Client-Server paradigm

Network Programming with Sockets. Process Management in UNIX

VMCI Sockets Programming Guide VMware ESX/ESXi 4.x VMware Workstation 7.x VMware Server 2.0

Overview. Socket Programming. Using Ports to Identify Services. UNIX Socket API. Knowing What Port Number To Use. Socket: End Point of Communication

TCP/IP - Socket Programming

Porting applications & DNS issues. socket interface extensions for IPv6. Eva M. Castro. ecastro@dit.upm.es. dit. Porting applications & DNS issues UPM

Linux Kernel Architecture

University of Amsterdam

Firewall Implementation

Network Programming TDC 561

Application Architecture

Limi Kalita / (IJCSIT) International Journal of Computer Science and Information Technologies, Vol. 5 (3), 2014, Socket Programming

Computer Networks. Chapter 5 Transport Protocols

Programming with TCP/IP Best Practices

Chapter 11. User Datagram Protocol (UDP)

Computer Networks - Xarxes de Computadors

Session NM059. TCP/IP Programming on VMS. Geoff Bryant Process Software

IP Subnetting and Addressing

Concurrent Server Design Alternatives

Direct Sockets. Christian Leber Lehrstuhl Rechnerarchitektur Universität Mannheim

Transport Layer. Chapter 3.4. Think about

Socket = an interface connection between two (dissimilar) pipes. OS provides this API to connect applications to networks. home.comcast.

Writing Client/Server Programs in C Using Sockets (A Tutorial) Part I. Session Greg Granger grgran@sas. sas.com. SAS/C & C++ Support

SSC - Communication and Networking Java Socket Programming (II)

BSD Sockets Interface Programmer s Guide

What is CSG150 about? Fundamentals of Computer Networking. Course Outline. Lecture 1 Outline. Guevara Noubir noubir@ccs.neu.

Communication Networks. Introduction & Socket Programming Yuval Rochman

Overview of TCP/IP. TCP/IP and Internet

CS 213, Fall 2000 Lab Assignment L5: Logging Web Proxy Assigned: Nov. 28, Due: Mon. Dec. 11, 11:59PM

Computer Networks/DV2 Lab

Implementing and testing tftp

DESIGN AND IMPLEMENT AND ONLINE EXERCISE FOR TEACHING AND DEVELOPMENT OF A SERVER USING SOCKET PROGRAMMING IN C

Question: 3 When using Application Intelligence, Server Time may be defined as.

Network-Oriented Software Development. Course: CSc4360/CSc6360 Instructor: Dr. Beyah Sessions: M-W, 3:00 4:40pm Lecture 2

SMTP-32 Library. Simple Mail Transfer Protocol Dynamic Link Library for Microsoft Windows. Version 5.2

Application Layer. CMPT Application Layer 1. Required Reading: Chapter 2 of the text book. Outline of Chapter 2

Network layer: Overview. Network layer functions IP Routing and forwarding

sys socketcall: Network systems calls on Linux

Network Programming. Writing network and internet applications.

Dissertation Title: SOCKS5-based Firewall Support For UDP-based Application. Author: Fung, King Pong

IP addressing and forwarding Network layer

Chapter 25 Domain Name System Copyright The McGraw-Hill Companies, Inc. Permission required for reproduction or display.

File Transfer Protocol (FTP) Chuan-Ming Liu Computer Science and Information Engineering National Taipei University of Technology Fall 2007, TAIWAN

Objectives of Lecture. Network Architecture. Protocols. Contents

Project 1: Implement a simple hosts framework using UNIX TCP Sockets to demonstrate the concept of Mobile Agents

CSE 127: Computer Security. Network Security. Kirill Levchenko

Simple Network Management Protocol

Jean Parrend 1/6 SNMP. Content. 1. Introduction...1

TCP/IP Fundamentals. OSI Seven Layer Model & Seminar Outline

Network packet capture in Linux kernelspace

Packet Sniffing and Spoofing Lab

Chapter 3. Internet Applications and Network Programming

UNIX. Sockets. mgr inż. Marcin Borkowski

Networks class CS144 Introduction to Computer Networking Goal: Teach the concepts underlying networks Prerequisites:

Writing a C-based Client/Server

3.5. cmsg Developer s Guide. Data Acquisition Group JEFFERSON LAB. Version

Network layer" 1DT066! Distributed Information Systems!! Chapter 4" Network Layer!! goals: "

µtasker Document FTP Client

Networking Test 4 Study Guide

ICS 351: Today's plan. IP addresses Network Address Translation Dynamic Host Configuration Protocol Small Office / Home Office configuration

Basic Networking Concepts. 1. Introduction 2. Protocols 3. Protocol Layers 4. Network Interconnection/Internet

ICOM : Computer Networks Chapter 6: The Transport Layer. By Dr Yi Qian Department of Electronic and Computer Engineering Fall 2006 UPRM

Unix System Administration

Overview. Securing TCP/IP. Introduction to TCP/IP (cont d) Introduction to TCP/IP

TFTP Usage and Design. Diskless Workstation Booting 1. TFTP Usage and Design (cont.) CSCE 515: Computer Network Programming TFTP + Errors

Networks: IP and TCP. Internet Protocol

Solution of Exercise Sheet 5

The Java Sound Internet Phone

Single Pass Load Balancing with Session Persistence in IPv6 Network. C. J. (Charlie) Liu Network Operations Charter Communications

Linux Networking Stack

8.2 The Internet Protocol

Slide 1 Introduction cnds@napier 1 Lecture 6 (Network Layer)

A Client Server Transaction. Introduction to Computer Systems /18 243, fall th Lecture, Nov. 3 rd

Transcription:

The POSIX Giovanni Agosta Piattaforme Software per la Rete Modulo 2 G. Agosta The POSIX

Outline Sockets & TCP Connections 1 Sockets & TCP Connections 2 3 4 G. Agosta The POSIX

TCP Connections Preliminaries TCP Application Interfaces Loosely specified Multiple implementations (Berkeley Sockets, System V TLI) Finally, POSIX socket API POSIX Sockets API (Mostly) Unix networking interface abstraction Bidirection communication device Allows many different underlying protocols (not just TCP) Also abstracts inter process communication (IPC) G. Agosta The POSIX

Socket Concepts Communication style Data is sent in packets Communications style determines packet handling and addressing Communication styles Connection (Stream and sequential sockets) In-order delivery Automatic request for retrasmission of lost/reordered packets Reliably Delivered Messages No in-order delivery guarantee Automatic request for retrasmission of lost packets Datagram No in-order delivery guarantee Actually, no delivery guaranty at all Raw G. Agosta The POSIX

Socket Concepts Namespaces & Protocols Namespaces Define how socket addresses are written Local namespace Socket addresses are filenames Internet namespace Socket addresses are IP addresses plus port numbers Port numbers allow multiple sockets on the same host Protocols Specify the underlying protocol for transmitting data IP protocol family IP version 6 UNIX local communication Many others (Appletalk, G. Agosta Novell The IPX, POSIXIRDA, Bluetooth...)

Socket Concepts Protocol-Style Combinations Protocol Style SOCK STREAM SOCK DGRAM SOCK RAW SOCK RDM SOCK SEQPACKET PF LOCAL PF INET TCP UDP IPv4 PF INET6 TCP UDP IPv6 PF NETLINK PF X25 PF APPLETALK PF PACKET Valid combination, with no special name G. Agosta The POSIX

Socket Representation and System Calls Representation File descriptors are employed to represent sockets Once communication is established, POSIX I/O calls are used System Calls socket Creates a socket close Destroys a socket connect Creates a connection between two sockets bind Labels a server socket with an address listen Configures a socket to accept conditions accept Accepts a connection and creates a new socket for the connection G. Agosta The POSIX

socket Sockets & TCP Connections Prototype #include <sys/socket.h> int socket(int domain, int type, int protocol) Operation Creates a socket (data structure in the file table) Takes three parameters domain Socket domain (protocol family, e.g., PF LOCAL, PF INET) type Socket type (communication style) protocol Protocol (generally implicit) Returns a file descriptor (positive integer) if successful, -1 otherwise G. Agosta The POSIX

close Sockets & TCP Connections Prototype #include <unistd.h> int close(int f) Operation Closes the socket Actually, since it is a file descriptor, this is just the usual close call Returns 0 if successful G. Agosta The POSIX

connect Sockets & TCP Connections Prototype #include <sys/socket.h> int connect(int sockfd, const struct sockaddr *serv addr, socklen t addrlen); Operation Connects the socked sockfd to the specified (remote) address addrlen is an integer (size of the sockaddr structure) Connectionless sockets can use connect multiple times, to change the associated address G. Agosta The POSIX

bind Sockets & TCP Connections Prototype #include <sys/socket.h> int bind(int sockfd, const struct sockaddr *addr, socklen t addrlen); Operation Assigns a local address to the socket Necessary to make a socket visible outside the process The sockaddr structure depends on the address family Returns 0 if successful, -1 otherwise G. Agosta The POSIX

listen Sockets & TCP Connections Prototype #include <sys/socket.h> int listen(int sockfd, int backlog); Operation Marks the socket as passive The socket must use the SOCK STREAM or SOCK SEQPACKET styles It will then be used to accept incoming connections backlog is the maximum length of the pending connections queue Returns 0 if successful, -1 otherwise G. Agosta The POSIX

accept Sockets & TCP Connections Prototype #include <sys/socket.h> int accept(int sockfd, struct sockaddr *addr, socklen t *addrlen); Operation Used in passive connection-based sockets addr is filled with the peer socket address addrlen initially contains the size of addr in memory, replaced with the actual size Returns the file descriptor (positive integer) for the accepted socket if successful, -1 otherwise G. Agosta The POSIX

Socket Address Generic data structure Rationale Addresses differ for the various protocols Different structures must be used Sockets are rather old (1982), and a non-ansi C workaround was used instead of void The sockaddr structure s t r u c t sockaddr { s a f a m i l y t s a f a m i l y ; / AF xxx / char s a d a t a [ 1 4 ] ; / a d d r e s s / } G. Agosta The POSIX

Socket Address Data types for sockaddr structures Type Description Header int8 t signed 8 bit integer sys/texttts.h uint8 t unsigned 8 bit integer sys/texttts.h int16 t signed 16 bit integer sys/texttts.h uint16 t unsigned 16 bit integer sys/texttts.h int32 t signed 32 bit integer sys/texttts.h uint32 t unsigned 32 bit integer sys/texttts.h sa family t address family sys/socket.h socklen t address struct length (uint32 t) sys/socket.h in addr t IPv4 address (uint32 t) netinet/in.h in port t TCP or UDP port (uint16 t) netinet/in.h G. Agosta The POSIX

Local Sockets Using Sockets as IPC Why? Provide communication between programs/processes Use the same socket abstraction How to use local/unix sockets Namespace: PF LOCAL or PF UNIX Use the struct sockaddr un The filename must be up to 108 bytes The actual length is computed using SUN LEN G. Agosta The POSIX

Local/UNIX Socket Address The sockaddr structures #define UNIX PATH MAX 108 s t r u c t s o c k a d d r u n { / AF UNIX / s a f a m i l y t s u n f a m i l y ; / pathname / char s u n p a t h [ UNIX PATH MAX ] ; } ; Values sun family = AF LOCAL or sun family = AF UNIX sun path must be a file pathname G. Agosta The POSIX

Generalities Sockets & TCP Connections Connection-based socket Two sockets are involved, with different roles One socket (server) accept the connection The other socket (client) establishes the connection The client needs to know the server in advance, but not vice versa G. Agosta The POSIX

TCP Connections Three Way Handshake client TCP TCP server (blocks) socket connect CLOSED CLOSED socket bind listen active open SYN_SENT SYN j passive open accept (blocks) LISTEN SYN_RCVD SYN k, ACK j+1 (return) connect ESTABLISHED ACK k+1 ESTABLISHED accept (return) G. Agosta The POSIX

IPv4 Socket Address The sockaddr structures s t r u c t s o c k a d d r i n { / a d d r e s s f a m i l y : AF INET / s a f a m i l y t s i n f a m i l y ; / p o r t i n network byte o r d e r ( big e n d i a n ) / i n p o r t t s i n p o r t ; / i n t e r n e t a d d r e s s / s t r u c t i n a d d r s i n a d d r ; } ; / I n t e r n e t a d d r e s s. / s t r u c t i n a d d r { / a d d r e s s i n network byte o r d e r / i n a d d r t s a d d r ; } ; G. Agosta The POSIX

TCP Connections Well-known ports TCP (and UDP) define well-known ports Well-known ports are assigned numbers from 0 to 1023 The remaiing ports are divided in registered (up to 49151) and dynamic (up to 65535) In Linux and BSD, well-known ports are reserved to processes with administration rights (only root can start the ssh server, e.g.) Also, ports 1024 4999 and 61000 65535 are used as ephemeral ports (i.e., for client sockets) G. Agosta The POSIX