More on Socket API. More on Socket I/O Functions  Scatter read and gather write.

Slides:



Advertisements
Similar presentations
Socket Options. abstraction Introduction getsockopt and setsockopt function socket state Generic socket option IPv4 socket option ICMPv6 socket option.
Advertisements

I/O Models Satish Krishnan. I/O Models Blocking I/O Non-blocking I/O I/O Multiplexing Signal driven I/O Asynchronous I/O.
BZUPAGES.COM 1 User Datagram Protocol - UDP RFC 768, Protocol 17 Provides unreliable, connectionless on top of IP Minimal overhead, high performance –No.
Elementary TCP Sockets© Dr. Ayman Abdel-Hamid, CS4254 Spring CS4254 Computer Network Architecture and Programming Dr. Ayman A. Abdel-Hamid Computer.
Multicasting - Part II© Dr. Ayman Abdel-Hamid, CS4254 Spring CS4254 Computer Network Architecture and Programming Dr. Ayman A. Abdel-Hamid Computer.
Sockets CS 3516 – Computer Networks. Outline Socket basics Socket details (TCP and UDP) Socket options Final notes.
Distributed Computing Systems Sockets. Outline Socket basics Socket details (TCP and UDP) Socket options Final notes.
Domain Name System. DNS is a client/server protocol which provides Name to IP Address Resolution.
1 Internet Networking Spring 2006 Tutorial 8 DNS and DHCP as UDP applications.
Lecture 19 Advanced Sockets Programming CPE 401 / 601 Computer Network Systems slides are modified from Dave Hollinger.
Computer Networks Sockets.
Elementary TCP Sockets Chapter 4 UNIX Network Programming Vol. 1, Second Ed. Stevens.
Socket Programming.
Multimedia Networking Sockets. Outline Socket basics Socket details (TCP and UDP) Socket options Final notes.
1 Java Networking – Part I CS , Spring 2008/9.
CS3771 Today: network programming with sockets  Previous class: network structures, protocols  Next: network programming Sockets (low-level API) TODAY!
Socket Options Jari Kellokoski. Introduction So far we have discovered some basic usage of socket With socket options we control sockets more suitable.
1 Advanced Name and Address Conversions getaddrinfo, getnameinfo, gai_strerror, freeaddrinfo host_serv, tcp_connect, tcp_listen, udp_client, udp_connect,
Computer Networks Sockets. Outline F Socket basics F Socket details.
Computer Network Architecture and Programming
Operating Systems Sockets. Outline F Socket basics F TCP sockets F Socket details F Socket options F Final notes F Project 3.
Socket option Getsockopt ou setsockopt fcntl ioctl.
Domain Name System ( DNS )  DNS is the system that provides name to address mapping for the internet.
1 Spring Semester 2009, Dept. of Computer Science, Technion Internet Networking recitation #2 DNS and DHCP.
Process-to-Process Delivery:
ECE 4110 – Internetwork Programming Client-Server Model.
Socket Programming. Introduction Sockets are a protocol independent method of creating a connection between processes. Sockets can be either – Connection.
Chapter 17 Networking Dave Bremer Otago Polytechnic, N.Z. ©2008, Prentice Hall Operating Systems: Internals and Design Principles, 6/E William Stallings.
25.1 Chapter 25 Domain Name System Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display.
Chapter 17 Domain Name System
Domain Name System CH 25 Aseel Alturki
October 8, 2015 University of Tulsa - Center for Information Security Microsoft Windows 2000 DNS October 8, 2015.
TCP : Transmission Control Protocol Computer Network System Sirak Kaewjamnong.
 Wind River Systems, Inc Chapter - 13 Network Programming.
More on Socket API. How to Place Timeouts on Sockets (1)  Using SIGALRM signal Connection timeout 기간의 축소 Response timeout advio/dgclitimeo3.clib/connect_timeo.c.
Chapter 2 Applications and Layered Architectures Sockets.
The Socket Interface Chapter 22. Introduction This chapter reviews one example of an Application Program Interface (API) which is the interface between.
1 Kyung Hee University Chapter 18 Domain Name System.
7.9 TCP Socket Options 7.10 SCTP Socket Options 7.11 fcntl Function 7.12 Summary 報告者 : 梁凱鈞.
Name and Address Conversions Chap 11. Domain Name System  A lookup mechanism for translating objects into other objects  A globally distributed, loosely.
TELE 402 Lecture 10: Unix domain … 1 Overview Last Lecture –Daemon processes and advanced I/O functions This Lecture –Unix domain protocols and non-blocking.
Netprog: Advanced Sockets Programming1 Advanced Sockets Programming Ref: Chapter 7,11,21,22.
Advanced Sockets API-II Vinayak Jagtap
CPSC 441 TUTORIAL – FEB 13, 2012 TA: RUITNG ZHOU UDP REVIEW.
1 Socket Options Ref: Chapter 7. 2 Socket Options Various attributes that are used to determine the behavior of sockets.Various attributes that are used.
Socket options: a summary –Tcp options, ip options and general socket options can be examined and sometimes modified. getsockopt, setsockopt routines Some.
TELE 402 Lecture 6: Name and address conversions 1 Overview Last Lecture –Socket Options and elementary UDP sockets This Lecture –Name and address conversions.
Today’s topic: UDP Reliable communication over UDP.
Discussion of MIF API draft-liu-mif-api-extension-04 IETF 80 March 28, 2011 Dapeng Liu.
1 Socket Options getsockopt and setsockopt functions Check options and obtain default values Generic socket options IPv4 socket options IPv6 socket options.
ECE 4110 – Internetwork Programming
CMPT 471 Networking II Network Programming © Janice Regan,
CSCI 330 UNIX and Network Programming Unit XIV: User Datagram Protocol.
TCP/IP Protocol Suite 1 Chapter 17 Upon completion you will be able to: Domain Name System: DNS Understand how the DNS is organized Know the domains in.
Chapter 11 Advanced Name and Address Conversion. Introduction gethostbyname, gethostbyaddr: protocol dependent getaddrinfo: –a function providing protocol.
Internet Naming Service: DNS* Chapter 5. The Name Space The name space is the structure of the DNS database –An inverted tree with the root node at the.
TCP/IP1 Address Resolution Protocol Internet uses IP address to recognize a computer. But IP address needs to be translated to physical address (NIC).
Basics of the Domain Name System (DNS) By : AMMY- DRISS Mohamed Amine KADDARI Zakaria MAHMOUDI Soufiane Oujda Med I University National College of Applied.
Client/Server Design Issues Based on Java Network Programming and Distributed Computing, Chapter 6 Also Online Java Tutorial, Sun.
Socket Option.
Name and Address Conversions Part I
Network Programming CSC- 341
Process-to-Process Delivery:
Chapter 07. Socket Options.
Advanced Network Programming spring 2007
Advanced Sockets Programming
Chapter 11 Name and Address Conversions (Part II)
Process-to-Process Delivery: UDP, TCP
Socket options: a summary
Advanced UNIX programming
Presentation transcript:

More on Socket API

More on Socket I/O Functions  Scatter read and gather write

More Advanced Socket I/O Functions

Ancillary data - cmsghdr Structure

Socket I/O Summary

Socket and Standard I/O  Buffering in Standard I/O library  fully buffered: all stream except for terminal devices  line buffered : terminal devices  unbuffered: stderr  Caution  Socket 에 standard I/O functions(fgets, fputs) 를 쓰면 fully buffered 됨

Name and Address Conversions

Domain Name System  A lookup mechanism for translating objects into other objects  A globally distributed, loosely coherent, scalable, reliable, dynamic database  Comprised of three components  Name space  Servers making that name space available  Resolvers (clients) which query the servers about the name space

Domain Name Space  DNS's distributed database is indexed by domain names.  Each domain name is essentially just a path in a large inverted tree, called the domain name space.

Domain, Delegation, Zone

Name Server Architecture Master server Zone transfer Zone data file From disk Authoritative Data (primary master and slave zones) Agent (looks up queries on behalf of resolvers) Cache Data (responses from other name servers) Name Server Process

Authoritative Data Resolver Query Response Authoritative Data (primary master and slave zones) Agent (looks up queries on behalf of resolvers) Cache Data (responses from other name servers) Name Server Process

Using Other Name Servers Arbitrary name server Response Resolver Query Authoritative Data (primary master and slave zones) Agent (looks up queries on behalf of resolvers) Cache Data (responses from other name servers) Name Server Process Response

Cached Data Query Response Authoritative Data (primary master and slave zones) Agent (looks up queries on behalf of resolvers) Cache Data (responses from other name servers) Name Server Process Resolver

Name Resolution  A DNS query has three parameters:  A domain name (e.g., ice.hufs.ac.kr),  Remember, every node has a domain name!  A class (e.g., IN), and  A type (e.g., A)  DNS message format Additional Authority Answer Question Header : the question for the name server : RRs answering the question : RRs pointing toward an authority : RRs holding additional information

Mapping Addresses to Names

Resource Records  주요 RRs  SOA Record (Start Of Authority): 해당 도메인에 대해 네임서버가 인증 (authoritative) 된 자료를 갖고 있음을 의미  NS(Name Server) Record: 해당 도메인에 대한 delegation 하는 네임서버를 지시  A Record: 도메인에 IPv4 주소를 mapping  AAAA Record: 도메인에 IPv6 주소를 mapping  CNAME Record: 도메인에 대한 또 다른 이름 설정  MX(Mail eXchanger) Record: 해당 호스트의 메일 라우팅 경로를 조정  PTR(Pointer) Record: IP 주소를 domain name 으로 reverse mapping 해 주며, Reverse Zone 파일에서 사용 NAME (Dynamic) TYPE(2 Byte) CLASS(2 Byte) TTL(4 Byte) RDLENGTH(2 Byte) RDATA(Dynamic)

Name and Address Conversion Functions  Domain name  IPv4 address  IPv4 address  domain name  gethostbyname/gethostbyaddr are not reentrant !! static struct hostent host; /* result stored here */ struct hostent * gethostbyname(const char *hostname) { /* call DNS functions for A or AAAA query */ /* fill in host structure */ return(&host); }

Service Name Conversion Functions  Service name  port ( See /etc/services )  Port  service name

Example: name/daytimetcpcli1.c Network-related information

New Name/Address Conversion Function (1)  hostname : hostname or address string  service : service name or decimal port number string  result : addrinfo data structure is dynamically allocated  Re-entrant, thread-safe, and protocol independent functions (support IPv4, IPv6)

New Name/Address Conversion Function (2)  hints : NULL or pointer to addrinfo data structure  The following member can be set by caller  ai_flag /* AI_PASSIVE for server, AI_CANNONNAME */  ai_family/* AF_xxx */  ai_socktype/* SOCK_xxx */  ai_protocol/* 0 or IPPROTO_xxx for IPv4 and IPv6 */  Example

getaddrinfo Actions and Results

UNP Library Functions #include “unp.h” struct addrinfo *host_serv(const char *hostname, const char *service, int family, int socktype); Returns: pointer to addrinfo structure if OK, NULL on error int tcp_connect(const char *hostname, const char *service); int tcp_listen(const char *hostname, const char *service, socklen_t *lenptr); Both returns: connected socket descriptor if OK, no return on error int udp_client(const char *hostname, const char *service, void **saptr, socklen_t *lenp); Returns: unconnected socket descriptor if OK, no return on error saptr : address of a pointer to a socket address structure that stores destination IP addr/port # for future calls to sendto int udp_connect(const char *hostname, const char *service); Returns: connected socket descriptor if OK, no return on error int udp_server(const char *hostname, const char *service, socklen_t *lenptr); Rerurns: unconnected socket descriptor if OK, no return on error

tcp_connect and tcp_listen Functions

Protocol-indep Daytime TCP Client/Server names/daytimetcpsrv1.cnames/daytimetcpcli.c

Protocol-indep Daytime UDP Client/Server names/daytimeudpsrv2.c names/daytimeudpcli1.c

getnameinfo Function  If the caller does not want to return host ( serv ) string, specify hostlen ( servlen ) of 0  flags

Socket Options

getsockopt and setsockopt Functions

Generic Socket Options(1)  SO_BROADCAST  Enable the ability of the process to send broadcast messages  Application must set this option before broadcasting  SO_DEBUG  Kernel keeps track of detailed information about all the packets sent or received by TCP for the socket  SO_DONTROUTE  Bypass the normal routing mechanism  The packet is directed to the appropriate local interface. If the local interface cannot be determined (i.e. destination is not on the same network), ENETUNREACH is returned.  SO_ERROR  Get the value of pending error  Socket 에 error 가 발생하면, so_error (pending error) 에 먼저 setting 하고 나서 errno 에 setting 함

Generic Socket Options(2)  SO_KEEPALIVE  Enforce TCP to send a keepalive probe automatically to the peer if no data has been exchanged for 2 hours (to detect if the peer host crashes)  Peer’s response is either  ACK: everything is OK (application is not notified)  RST: the peer host has crashed and rebooted. Socket’s pending error = ECONNRESET and socket is closed  No response: send 8 additional probes, 75 sec apart (totally, 11mim and 15sec). Listen the peer’s response. Still no response  ETIMEOUT and socket is closed Receives ICMP error, EHOSTUNREACH or …  To shorten probe period  Use TCP_KEEPALIVE option (Not all implementation support this option). But, this will affect all sockets on the host.  Or, implement your own heartbeat mechanism.

Generic Socket Options(3)  SO_LINGER: linger when the socket is closed  Data type for option value  If l_onoff = 0, default close(). i.e. return immediately, but the remaining data is delivered to the peer  else  linger when the socket is closed  If l_linger==0, TCP aborts the connection. i.e. TCP discards any data still remaining in the socket send buffer and sends an RST to the peer.  else linger when the socket is closed. Any data still remaining in the socket send buffer is sent. But, if linger time expires, return EWOULDBLOCK and any remaining data is discarded.

Generic Socket Options(4)  SO_OOBINLINE  OOB data will be placed in the normal input queue  SO_RCVBUF and SO_SNDBUF  Set or get socket send buffer size / socket receive buffer size  TCP:  advertise receive buffer(window) to the peer  sliding window mechanism(flow control)  buffer size  3 * MSS  UDP: typical send buffer size  9000, receive buffer size  40,000,  If data received > available receive buffer, datagram is discarded  Capacity of full-duplex pipe (bandwidth-delay product)  bandwidth * RTT (<= 64KB)  SO_RCVLOWAT, SO_SNDLOWAT: socket low water mark  data in socket receive buffer >= SO_RCVLOWAT  readable  available space in socket send buffer >= SO_SNDLOWAT  writable  SO_RCVLOWAT = 1, SO_SNDLOWAT = 2048 by default  SO_RCVTIMEO, SO_SNDTIMEO: socket time out for receiving and sending message

Generic Socket Options(6)  SO_REUSEADDR: reuse the established port  Allows a listening server to start and bind its well- known port even if previously established connections exist that use this port  Allows multiple instances of the same server to be started on the same port as long as each instance binds a different local IP address  hosting multiple HTTP servers using IP alias technique  Allows a single process to bind the same port to multiple socket as long as each bind specifies a different local IP address  Allows completely duplicate bindings when same IP address and port are already bound to another socket.  Used with multicasting to allow the same application to be run multiple times on the same host when the SO_REUSEPORT option is not supported

TCP Socket Options  TCP_KEEPALIVE: specifies the idle time in seconds for the connection before TCP starts sending keepalive probes  7200 sec (2 hours), default  Effective only when SO_KEEPALIVE socket option is enabled  TCP_MAXSEG: fetch or set MSS for TCP connection  TCP_NODELAY  e.g) rlogin, telnet  Nagle algorithm / delayed algorithm disabled  TCP’s Nagle algorithm  No small packet( < MSS ) will not be sent until the existing data is ACKed  TCP’s delayed ACK algorithm  piggyback: TCP sends an ACK after some small amount of time( 50 ~ 200msec)

Nagle Algorithm Enabled/Disabled  Nagle Algorithm Enabled  No small packet( < MSS ) will not be sent until the existing data is ACKed  Nagle Algorithm Disabled