Class A Addresses The 1st bit of a class A address is 0

Slides:



Advertisements
Similar presentations
Sockets: Network IPC Internet Socket UNIX Domain Socket.
Advertisements

Today’s topic: Basic TCP API –Socket –Bind –Listen –Connect –Accept –Read –Write –Close.
Networks: TCP/IP Socket Calls1 Elementary TCP Sockets Chapter 4 UNIX Network Programming Vol. 1, Second Ed. Stevens.
Tutorial 8 Socket Programming
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.
ISP – 9 th Recitation Socket programming – Client side.
1 Advanced Name and Address Conversions getaddrinfo, getnameinfo, gai_strerror, freeaddrinfo host_serv, tcp_connect, tcp_listen, udp_client, udp_connect,
1 Tutorial on Socket Programming Computer Networks - CSC 458 Department of Computer Science Yukun Zhu (Slides are mainly from Monia Ghobadi, and Amin Tootoonchian,
Sockets CIS 370 Fall 2009, UMassD. Introduction  Sockets provide a simple programming interface which is consistent for processes on the same machine.
Basic Socket Programming TCP/IP overview. TCP interface Reference: –UNIX Network Programming, by Richard Stevens. –UNIX man page.
TCP Socket Programming. r An abstract interface provided to the application programmer  File descriptor, allows apps to read/write to the network r Allows.
ECE 4110 – Internetwork Programming Client-Server Model.
Operating Systems Chapter 9 Distributed Communication.
Assignment 3 A Client/Server Application: Chatroom.
Network Programming Tutorial #9 CPSC 261. A socket is one end of a virtual communication channel Provides network connectivity to any other socket anywhere.
Client-Side Network Programming
CS345 Operating Systems Φροντιστήριο Άσκησης 2. Inter-process communication Exchange data among processes Methods –Signal –Pipe –Sockets.
Class A Addresses The 1 st bit of a class A address is 0 The 1 st byte has a value from (128.x.x.x would not be a class A) 127.x.x.x is reserved.
Week 13 - Wednesday.  What did we talk about last time?  Networking.
Sockets CIS 370 Lab 10 UMass Dartmouth. Introduction 4 Sockets provide a simple programming interface which is consistent for processes on the same machine.
Sirak Kaewjamnong Computer Network Systems
Server Sockets: A server socket listens on a given port Many different clients may be connecting to that port Ideally, you would like a separate file descriptor.
1 Computer Networks An Introduction to Computer Networks University of Tehran Dept. of EE and Computer Engineering By: Dr. Nasser Yazdani Lecture 3: Sockets.
Introduction to Socket
Socket Programming Tutorial Department of Computer Science Southern Illinois University Edwardsville Fall, 2015 Dr. Hiroshi Fujinoki
Socket Programming Lab 1 1CS Computer Networks.
TELE 402 Lecture 6: Name and address conversions 1 Overview Last Lecture –Socket Options and elementary UDP sockets This Lecture –Name and address conversions.
1 CS716 Advanced Computer Networks By A. Wahid Shaikh.
Intro to Socket Programming CS 360. Page 2 CS 360, WSU Vancouver Two views: Server vs. Client Servers LISTEN for a connection and respond when one is.
Introduction to Sockets
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.
Socket Programming. Computer Science, FSU2 Interprocess Communication Within a single system – Pipes, FIFOs – Message Queues – Semaphores, Shared Memory.
UNIX Sockets Outline UNIX sockets CS 640.
1 Spring Semester 2008, Dept. of Computer Science, Technion Internet Networking recitation #7 Socket Programming.
Chapter 11 Advanced Name and Address Conversion. Introduction gethostbyname, gethostbyaddr: protocol dependent getaddrinfo: –a function providing protocol.
Lecture 15 Socket Programming CPE 401 / 601 Computer Network Systems slides are modified from Dave Hollinger.
Lecture 3 TCP and UDP Sockets CPE 401 / 601 Computer Network Systems slides are modified from Dave Hollinger.
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.
CSE 333 – SECTION 8 Client-Side Network Programming.
CSCE 313 Network Socket MP8 DUE: FRI MAY 5, 2017
Week 13 - Wednesday CS222.
UNIX Sockets COS 461 Precept 1.
Advanced Computer Networks
Socket Programming (Cont.)
CS 105 “Tour of the Black Holes of Computing”
Week 13 - Friday CS222.
Socket Programming in C
Network Programming with Sockets
Socket Interface 1 Introduction 11 Socket address formats 2 API 12 13
Name and Address Conversions Part I
Transport layer API: Socket Programming
Client-side Networking CSE 333 Spring 2018
תקשורת ומחשוב תרגול 3-5 סוקטים ב-C.
Advanced Network Programming spring 2007
Socket Programming.
Advanced Sockets Programming
Client-side Networking CSE 333 Summer 2018
Network Programming: Part I CSCI 380: Operating Systems
Sockets Programming Socket to me!.
Sockets Programming Socket to me!.
Client-side Networking CSE 333 Winter 2019
Internet Networking recitation #8
Outline Communications in Distributed Systems Socket Programming
Sockets.
Today’s topic: Basic TCP API
CSI 4118 – UNIVERSITY OF OTTAWA
Client-side Networking CSE 333 Spring 2019
Presentation transcript:

Class A Addresses The 1st bit of a class A address is 0 The 1st byte has a value from 1-126. (128.x.x.x would not be a class A) 127.x.x.x is reserved for loopback (127.0.0.1 often used) x.255.255.255 is used from broadcast x. 0.0.0 is used as a ‘default’ router This allows 16,277,214 (224 -2) hosts per class A network. Only a few class A licenses are not shared. covers 50% of the entire address space 0 7 bits/1st byte 24 bits for host addresses/3 bytes

Class B Addresses The 1st 2 bits of a class B address is 10 Allows for 214 or 16,384 network licences, 216-2 hosts per network # 127.x.x.x is reserved for loopback (127.0.0.1 often used) 126 network numbers x.x.255.255 is used for broadcast x. x.0.0 is used as a ‘default’ router This allows 16,384 (214 -2) hosts per class A network Represents 25% of all available IP addresses 1st byte is from 128 to 191 10 14 bits 16 bits for host addresses/2 bytes

Class C Addresses The 1st 3 bits of a class C address is 110 Allows for 221 or 2,097,152 network licences, 254 hosts per network 127.x.x.x is reserved for loopback (127.0.0.1 often used) 126 network numbers x.x.x.255 is used for broadcast x. x.x.0 is used as a ‘default’ router Represents 12.5% of all available IP addresses first byte is 192-223 110 21 bits/3 bytes 8 bits

Class D Addresses The 1st 4 bits of a class B address is 1110 first byte is 192-223 Reserved by the Internet Address Number Authority (IANA) for broadcast purposes 1110 Addresses from 224.0.0.0 - 239.255.255.255

Class E Addresses The 1st 5 bits of a class B address is 11110 first byte is 240-255 Reserved for experimental use 1110 Addresses from 224.0.0.0 - 239.255.255.255

Sockets And Connections (exploring Beej’s client and server program)

Writing a Client in C gettaddrinfo(...) – name+port -> IP address inet_ntop(...) - only needed to display address socket(...) - create an fd for the socket connect(...) - open the socket recv(...) - receive bytes from the socket close(...) or shutdown(..) – close the socekt

getaddrinfo(name,service,hints,result) name: a string, ie: humber.ca service: a port# or service name, “80”, “http” hints: uses a sample addrinfo to suggest V4, V6... TCP, UDP – preferred choice of connection. hints.ai_family = AF_UNSPEC; hints.ai_socktype = SOCK_STREAM; results: starts a linked list of type addrinfo

struct addrinfo { int ai_flags; int ai_family; //AF_INET, AF_INET6, AF_UNIX // AF_LOCAL, AF_UNSPEC int ai_socktype; //SOCK_STREAM, SOCK_DGRAM int ai_protocol; size_t ai_addrlen; struct sockaddr *ai_addr; //different for V4, V6 char *ai_canonname; //not used? struct addinfo * ai_next; //it’s a linked list!jk }

A Generic Addresses struct sockaddr { sa_family_t sa_family; char sa_data[]; } struct sockaddr_in { //ipv4 address sa_family_t sa_family; //Always AF_INET in_port sin_port; //port: 16 bits struct inaddr sin_addr; //32 bit internet address } struct sockaddr_in6 { //ipv6 address* sa_family_t sa_family; //Always AF_INET6 in_port sin6_port; //port: 16 bits struct inaddr sin_addr; //32 bit internet address struct in6_addr sin6addr; //IPV6 address -128 bits. } *I’ve left out 2 fields which aren’t important. What’s relevant is that sockaddr_in and sockaddr_in6 are different sizes! How does that work???

if (genericAddress->sa_family==AF_INET) { Here’s a trick to handle both Note that the first field, sa_family, in all 3 is the same! struct sockaddr *generic_address; struct sockaddr_in *inet4_address; struct sockaddr_in6 *inet6_address; if (genericAddress->sa_family==AF_INET) { inet4_address=(struct sockaddr_in *) generic_address; code that is ipV4 specific } else { inet6_address=(struct sockaddr_in6 *) generic_address; code that is ipV6 specific }

pointer sockaddr_in sockaddr_in6

int socket(family,socketType,protocol) family: AF_INET, AF_INET6, AF_UNIX socketType: SOCK_STREAM, SOCK_DGRAM, SOCK_RAW, ... protocol - set to zero. Most socket types have only one protocol so we can ignore this

connect(fd,ipAddr,addrLength) The fd is the local end of the socket the ipAddr is either V4 or V6 – a string addrLength is the length of the string Fails if the service is not available. Not used with SOCK_DGRAM (connectionless)

recv(fd,buf,bufsize,flags) exactly like read – except for the flags unless socket is non-blocking it waits for input we don’t use flags in the 1st example MSG_DONTWAIT MSG_ERRQUEUE MSG_OOB MSG_PEEK

close(fd) Yes, it’s really simple!!!!

shutdown(fd, how) ‘how’ is either SHUT_RD, SHUT_WR, SHUT_RDWR SHUT_WR used to signal an EOF to the other end If we have multiple threads SHUT_RDWR decrements a count leaving the socket open

Writing a Server in C gettaddrinfo(...) - info about this machine socket(...) create a socket setsockopt(...) - define properties of the socket bind(...) listen(...) - wait for a connection – this blocks freeaddrinfo() - return the linked list’s memory sigaction (...) - reap any dead child processes accept(...) - accept the connection inet_ntop(...) - not req’d: display the connection fork a child to carry on the conversation send(...) (can also receive) close(....) - close the connection

getaddrinfo(NULL,service,&hints,&result) NULL - not needed service - port or service name as a string hints field .ai_flags is AI_PASSIVE – use this host ai_socktype - SOCK_STREAM ai_family - AF_UNSPEC - whatever. AF_INET, AF_INET6 Returns: a list of IP addresses, usually 1 or an error code – service may be in use

int socket(family,socketType,protocol) family: AF_INET, AF_INET6, AF_UNIX socketType: SOCK_STREAM, SOCK_DGRAM, SOCK_RAW, ... protocol - set to zero. Most socket types have only one protocol so we can ignore this

setsockopt(fd,level,optname,&value,len) Used to set socket characteristics fd – the socket id from call to socket() level – always SOL_SOCKET - it corresponds to the protocol, and we don’t have any optname: SO_REUSEADDR - set this to 1/true other options will come up later. For a list of options, see: man 7 socket value - settings for options may be different data structures – pass an address len

bind(fd,addressInfo,length) fd – the socket we just opened addressInfo - AF_type, port – we have to and will match the info in the call to socket length – size bind generates a name for the socket in the proc directory. In the client program, the call to socket only connects to an existing socket. ONLY THE SUPERUSER can use a port <1024 If the ip address is 0 (INADDR_ANY) then you can bind to any network card in the machine.

listen(fd,nItems) Sets up a queue for the socket of nItems. If a server is busy handling a connection it might miss the next request for one, even if we fork quickly. However if the average interarrival time is too high, no size may be big enough. This is to handle surges in requests, ie: when a class logs into a service all at once.

int accept(fd, &theirAddr, length) blocks/waits for a connection returns their addresss info and the bidirectional socket to talk to

send(fd,buffer,length, flags) send a message to the client

close(fd) Yes, it’s that simple Can also use shutdown(fd,how)

Other Management Tasks memset(&memoryBlock,val, nBytes) freeaddrinfo(serverInfo) sigemptyset(signalset) – clears all signal handlers sigaction(SIGHCHILD, handler,lastUse) - advanced version of signal(signum,handler) - it can be ignored. Use ps and kill -9 to terminate rogue children