Chapter 3 Sockets Introduction

Slides:



Advertisements
Similar presentations
Ipv4 Socket Address Structure struct in_addr { in_addr_t s_addr; /* 32-bit IPv4 address */ /* network byte ordered */ }; struct sockaddr_in { uint8_t sin_len;
Advertisements

Sockets: Network IPC Internet Socket UNIX Domain Socket.
Today’s topic: Basic TCP API –Socket –Bind –Listen –Connect –Accept –Read –Write –Close.
Sockets CS 3516 – Computer Networks. Outline Socket basics Socket details (TCP and UDP) Socket options Final notes.
Elementary TCP Sockets Computer Networks Computer Networks Term B10 UNIX Network Programming Vol. 1, Second Ed. Stevens Chapter 4.
Networks: TCP/IP Socket Calls1 Elementary TCP Sockets Chapter 4 UNIX Network Programming Vol. 1, Second Ed. Stevens.
Multimedia Networking Sockets. Outline Socket basics Socket details (TCP and UDP) Socket options Final notes.
CSCE 515: Computer Network Programming Socket Wenyuan Xu Department of Computer Science and Engineering.
Sockets Programming Introduction © Dr. Ayman Abdel-Hamid, CS4254 Spring CS4254 Computer Network Architecture and Programming Dr. Ayman A. Abdel-Hamid.
LANMAR for IPv6 Jason Chen Teresa Breyer Yeng-Zhong Lee.
Tutorial 8 Socket Programming
#include DatatypeDescription int8_t uint8_t int16_t uint16_t int32_t uint32_t Signed 8-bit integer Unsigned 8-bit integer Signed 16-bit integer Unsigned.
CS 311 – Lecture 18 Outline IPC via Sockets – Server side socket() bind() accept() listen() – Client side connect() Lecture 181CS Operating Systems.
Socket Addresses. Domains Internet domains –familiar with these Unix domains –for processes communicating on the same hosts –not sure of widespread use.
Winsock programming.  TCP/IP UDP TCP  Winsock #include wsock32.lib.
Unix Network Programming Part 2: Elementary Sockets Jani Peusaari.
Lecture 10 Overview. Network API Application Programming Interface – Services that provide the interface between application and protocol software often.
1 Tutorial on Socket Programming Computer Networks - CSC 458 Department of Computer Science Yukun Zhu (Slides are mainly from Monia Ghobadi, and Amin Tootoonchian,
Basic Socket Programming TCP/IP overview. TCP interface Reference: –UNIX Network Programming, by Richard Stevens. –UNIX man page.
UNIX Socket Programming CS 6378
TCP Socket Programming. r An abstract interface provided to the application programmer  File descriptor, allows apps to read/write to the network r Allows.
ECE453 – Introduction to Computer Networks Lecture 15 – Transport Layer (II)
Client-Side Network Programming
Zhu Reference: Daniel Spangenberger Computer Networks, Fall 2007 PPT-4 Socket Programming.
CS345 Operating Systems Φροντιστήριο Άσκησης 2. Inter-process communication Exchange data among processes Methods –Signal –Pipe –Sockets.
Introduction to Socket Programming Advisor: Quincy Wu Speaker: Kuan-Ta Lu Date: Nov. 25, 2010.
1 CMPT 471 Networking II Transport Layer Network Programming © Janice Regan, 2013.
Outline Socket programming with Windows OSSocket programming with Windows OS C++ UDPSocket classC++ UDPSocket class Socket programming with Windows OSSocket.
TELE202 Lecture 15 Socket programming 1 Lecturer Dr Z. Huang Overview ¥Last Lecture »TCP/UDP (2) »Source: chapter 17 ¥This Lecture »Socket programming.
Lecture 15 Overview.
Elementary TCP Sockets UNIX Network Programming Vol. 1, Second Ed. Stevens Chapter 4.
Introduction to Socket
Socket Programming Lab 1 1CS Computer Networks.
1 Sockets Programming Socket to me!. 2 Network Application Programming Interface (API) The services provided by the operating system that provide the.
Socket address structures Byte ordering IP address conversion
Sockets Introduction Socket address structures Value-result arguments
Introduction to Sockets
Socket Programming(2/2) 1. Outline  1. Introduction to Network Programming  2. Network Architecture – Client/Server Model  3. TCP Socket Programming.
Read() recv() connection establishment Server (connection-oriented protocol) blocks until connection from client Client socket() bind() listen() accept()
CSCI 330 UNIX and Network Programming Unit XIV: User Datagram Protocol.
In unistd.h : int gethostname(char * name, int maxlen) Purpose : Find the computer's name.
1 Spring Semester 2008, Dept. of Computer Science, Technion Internet Networking recitation #7 Socket Programming.
Advanced UNIX programming Fall 2002 Instructor: Ashok Srinivasan Lecture 17 Acknowledgements: The syllabus and power point presentations are modified versions.
Lecture 15 Socket Programming CPE 401 / 601 Computer Network Systems slides are modified from Dave Hollinger.
Socket Programming(1/2). Outline  1. Introduction to Network Programming  2. Network Architecture – Client/Server Model  3. TCP Socket Programming.
CSE 333 – SECTION 8 Client-Side Network Programming.
CS 3214 Computer Systems.
Read: Chapters 1,2, 3, 4 Communications Client Server Ex: TCP/IP
CS 3214 Computer Systems Lecture 22 Godmar Back.
Socket Programming (Cont.)
Network Programming CSC- 341
Network Programming with Sockets
Socket Interface 1 Introduction 11 Socket address formats 2 API 12 13
Transport layer API: Socket Programming
תקשורת ומחשוב תרגול 3-5 סוקטים ב-C.
Introduction to Socket Programming
Lecture 2 Socket Programming
IP Addresses, DNS CSE 333 Summer 2018
IP Addresses, DNS CSE 333 Autumn 2018
Refs: Chapter 10, Appendix A
IP Addresses, DNS CSE 333 Winter 2019
Socket Programming(1/2)
Sockets Programming Socket to me!.
Sockets Programming Socket to me!.
Internet Networking recitation #8
in unistd.h: int gethostname(char * name, int maxlen)
Outline Communications in Distributed Systems Socket Programming
Sockets.
Today’s topic: Basic TCP API
CSI 4118 – UNIVERSITY OF OTTAWA
Presentation transcript:

Chapter 3 Sockets Introduction By They Yu Shu

Outline Socket Address Structures Value-Result Arguments Byte Ordering Functions Byte Manipulation Functions Address Conversion

Socket Address Structure In socket programming, IP address and Port value are used to identify the end-points of the TCP/IP communication. Socket Address Structure is a data structure to hold Address Family IP address Port Value And ….

IPv4 Socket Address Structure struct in_addr { in_addr_t s_addr; /* 32-bit IPv4 address */ /* network byte ordered */ }; struct sockaddr_in { uint8_t sin_len; /* length of structure */ sa_family_t sin_family; /* 16 bit address family*/ /*AF_INET*/ in_port_t sin_port; /* 16-bit TCP or UDP port number */ struct in_addr sin_addr; /* 32-bit IPv4 address */ char sin_zero[8]; /* unused (to keep sockaddr_in > 16 bytes in size) */

Address Family Number Number Description Reference ------ ---------------------------------------------------- --------- 0 Reserved 1 IP (IP version 4) 2 IP6 (IP version 6) 3 NSAP 4 HDLC (8-bit multidrop) 5 BBN 1822 6 802 (includes all 802 media plus Ethernet "canonical format") 7 E.163 8 E.164 (SMDS, Frame Relay, ATM) 9 F.69 (Telex) 10 X.121 (X.25, Frame Relay) 11 IPX 12 Appletalk 13 Decnet IV 14 Banyan Vines 15 E.164 with NSAP format subaddress [UNI-3.1] [Malis] 16 DNS (Domain Name System) 17 Distinguished Name [Lynn] 18 AS Number [Lynn] 19 XTP over IP version 4 [Saul] 20 XTP over IP version 6 [Saul] 21 XTP native mode XTP [Saul] 22 Fibre Channel World-Wide Port Name [Bakke] 23 Fibre Channel World-Wide Node Name [Bakke] 24 GWID [Hegde] 25 AFI for L2VPN information [RFC4761] 65535 Reserved

Socket Functions IPv4 Socket Address Structure IPv6 Socket others Socket Address Structure Socket Functions: Bind() Connect() Send() Recv() …. Example: int bind(int, struct sockaddr *, socklen_t );

Generic Socket Address Structure struct sockaddr { uint8_t sa_len; sa_family_t sa_family; /* address family: AF_xxx value */ char sa_data[14]; /* protocol-specific address */ };

Using Generic Socket Address Structure struct sockaddr_in serv; /* IPv4 socket address structure */ /* fill in serv{} */ bind(sockfd, (struct sockaddr *) &serv, sizeof(serv));

IPv6 Socket Address Structure struct in6_addr { uint8_t s6_addr[16]; /* 128-bit IPv6 address */ /* network byte ordered */ }; struct sockaddr_in6 { uint8_t sin6_len; /* length of this struct (28) */ sa_family_t sin6_family; /* AF_INET6 */ in_port_t sin6_port; /* transport layer port# */ uint32_t sin6_flowinfo; /* flow information, undefined */ struct in6_addr sin6_addr; /* IPv6 address */ uint32_t sin6_scope_id; /* set of interfaces for a scope */

New Generic Socket Address Structure struct sockaddr_storage { uint8_t ss_len; /* length of this struct (implementation dependent) */ sa_family_t ss_family; /* address family: AF_xxx value */ ….. };

Value-Result Arguments Arguments used for both value passing and result returning purpose. Process to Kernel: bind(),connect(),sendto() Example: struct sockaddr_in serv; /* fill in serv{} */ connect (sockfd, (sockaddr *) &serv, sizeof(serv) ); Kernel to Process accept(), recvfrom(), getsockname(), and getpeername() struct sockaddr_un cli; /* Unix domain */ socklen_t len; len = sizeof(cli); /* len is a value */ getpeername(unixfd, (sockaddr *) &cli, &len); /* len may have changed */

Byte Ordering Functions

#include <netinet/in.h> uint16_t htons(uint16_t host16bitvalue) ; uint32_t htonl(uint32_t host32bitvalue) uint16_t ntohs(uint16_t net16bitvalue) ; uint32_t ntohl(uint32_t net32bitvalue) ;

Byte Manipulation Functions

Address Conversion Functions to convert 32 bit IPv4 network address to Ascii string 0x01020304 => “1.2.3.4” inet_aton(), net_ntoa()

Address Conversion Functions to convert 32 bit IPv4/IPv6 network address to Ascii string inet_pton(), inet_ntop()

End