Socket Option.

Slides:



Advertisements
Similar presentations
Introduction to Sockets Jan Why do we need sockets? Provides an abstraction for interprocess communication.
Advertisements

Nonblocking I/O Blocking vs. non-blocking I/O
Multicasting© Dr. Ayman Abdel-Hamid, CS4254 Spring CS4254 Computer Network Architecture and Programming Dr. Ayman A. Abdel-Hamid Computer Science.
Socket Options. abstraction Introduction getsockopt and setsockopt function socket state Generic socket option IPv4 socket option ICMPv6 socket option.
© Janice Regan, CMPT 128, CMPT 371 Data Communications and Networking Socket Programming 0.
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.
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.
Networks: TCP/IP Socket Calls1 Elementary TCP Sockets Chapter 4 UNIX Network Programming Vol. 1, Second Ed. Stevens.
Computer Networks Sockets.
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.
Sockets IMGD Outline Socket basics Socket details (TCP and UDP) Socket options Final notes.
Socket Options Jari Kellokoski. Introduction So far we have discovered some basic usage of socket With socket options we control sockets more suitable.
1 Nonblocking I/O Nonblocking reads and writes Buffers enabling overlapped nonblocking I/O Nonblocking connect.
1 I/O Multiplexing Computer Network Programming. 2 Input from multiple sources Process keyboard sockets file A process may have multiple sources of input.
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.
Sockets CIS 370 Fall 2009, UMassD. Introduction  Sockets provide a simple programming interface which is consistent for processes on the same machine.
Elementary UDP Sockets© Dr. Ayman Abdel-Hamid, CS4254 Spring CS4254 Computer Network Architecture and Programming Dr. Ayman A. Abdel-Hamid Computer.
ECE 4110 – Internetwork Programming Client-Server Model.
Elementary TCP Sockets
IT1352-NETWORK PROGRAMMING AND MANAGEMENT
Socket Options –Four functions define the API for ‘get’ and ‘setting’ socket options. We will cover those aspects which address generic, IPv4, TCP UDP.
 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.
Review: How to create a TCP end point? What is the right format for sin_port and sin_addr in the sockaddr_in data structure? How many different ways we.
Chapter 2 Applications and Layered Architectures Sockets.
More on Socket API. More on Socket I/O Functions  Scatter read and gather write.
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
I/O Multiplexing. TCP Echo Client: I/O operation is sequential !! tcpcliserv/tcpcli01.c: lib/str_cli.c: TCP Client TCP Server stdin stdout fgets fputs.
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.
I/O Multiplexing. What is I/O multiplexing? When an application needs to handle multiple I/O descriptors at the same time –E.g. file and socket descriptors,
TELE 402 Lecture 12: Signal-Driven I/O & Raw Socket 1 Overview Last Lecture –Advanced UDP sockets and threads –Source: Chapters 22&26 of Stevens’ book.
Today’s topic: UDP Reliable communication over UDP.
1 Socket Options getsockopt and setsockopt functions Check options and obtain default values Generic socket options IPv4 socket options IPv6 socket options.
CMPT 471 Networking II Network Programming © Janice Regan,
I/O Multiplexing Chap 6. I/O Models  Blocking I/O Model  Nonblocking I/O Model  I/O Multiplexing Model  Signal Driven I/O Model  Asynchronous I/O.
1 TCP Sockets Programming Creating a passive mode (server) socket.Creating a passive mode (server) socket. Establishing an application-level connection.Establishing.
Ioctl Operations. ioctl Function Interface Configuration  Netstat, ifconfig command 에서 사용.
Lecture 3 TCP and UDP Sockets CPE 401 / 601 Computer Network Systems slides are modified from Dave Hollinger.
Client/Server Design Issues Based on Java Network Programming and Distributed Computing, Chapter 6 Also Online Java Tutorial, Sun.
1 Socket Interface. 2 Basic Sockets API Review Socket Library TCPUDP IP EthernetPPP ARP DHCP, Mail, WWW, TELNET, FTP... Network cardCom Layer 4 / Transport.
Sockets API Developing Applications using the Sockets API.
Netprog: TCP Sockets1 TCP Sockets Programming Creating a passive mode (server) socket.Creating a passive mode (server) socket. Establishing an application-level.
SOCKET PROGRAMMING Presented By : Divya Sharma.
IPv4 socket option Level => IPPROTO_IP
Operating Systems Sockets ENCE 360.
Sockets and Beginning Network Programming
Elementary UDP Sockets
Socket Programming in C
CHAPTER 8 ELEMENTARY UDP SOCKETS
Network Programming CSC- 341
UNIX Sockets Outline Homework #1 posted by end of day
Network Programming CSC- 341
UDP Sockets Programming
Chapter 07. Socket Options.
TCP Sockets Programming
Advanced Network Programming spring 2007
Advanced Sockets Programming
Socket options: a summary
Transport Layer 9/22/2019.
Advanced UNIX programming
Presentation transcript:

Socket Option

abstraction Introduction getsockopt and setsockopt function socket state Generic socket option

Introduction Three ways to get and set the socket option that affect a socket getsockopt , setsockopt function=>IPv4 and IPv6 multicasting options fcntl function =>nonblocking I/O, signal driven I/O ioctl function =>chapter16

getsockopt and setsockopt function #include <sys/socket.h> int getsockopt(int sockfd, , int level, int optname, void *optval, socklent_t *optlen); int setsockopt(int sockfd, int level , int optname, const void *optval, socklent_t optlen); sockfd => open socket descriptor level => code in the system to interprete the option(generic, IPv4, IPv6, TCP) optval => pointer to a variable from which the new value of option is fetched by setsockopt, or into which the current value of the option is stored by setsockopt. optlen => the size of the option variable.

socket state We must set that option for the listening socket => because connected socket is not returned to a server by accept until the three way handshake is completed by the TCP layer.

Generic socket option SO_BROCAST =>enable or disable the ability of the process to send broadcast message.(only datagram socket : Ethernet, token ring..) :chapter18 SO_DEBUG =>kernel keep track of detailed information about all packets sent or received by TCP(only supported by TCP) SO_DONTROUTE=>outgoing packets are to bypass the normal routing mechanisms of the underlying protocol. SO_ERROR=>when error occurs on a socket, the protocol module in a Berkeley-derived kernel sets a variable named so_error for that socket. Process can obtain the value of so_error by fetching the SO_ERROR socket option

SO_KEEPALIVE SO_KEEPALIVE=>wait 2hours, and then TCP automatically sends a keepalive probe to the peer. Peer response ACK(everything OK) RST(peer crashed and rebooted):ECONNRESET no response:ETIMEOUT =>socket closed example: Rlogin, Telnet…

SO_LINGER SO_LINGER =>specify how the close function operates for a connection-oriented protocol(default:close returns immediately) struct linger{ int l_onoff; /* 0 = off, nonzero = on */ int l_linger; /*linger time : second*/ }; l_onoff = 0 : turn off , l_linger is ignored l_onoff = nonzero and l_linger is 0:TCP abort the connection, discard any remaining data in send buffer. l_onoff = nonzero and l_linger is nonzero : process wait until remained data sending, or until linger time expired. If socket has been set nonblocking it will not wait for the close to complete, even if linger time is nonzero.

SO_LINGER client server write data Data queued by TCP Close FIN close returns FIN Ack of data and FIN Application reads queued data and FIN close FIN Ack of data and FIN Default operation of close:it returns immediately

SO_LINGER client server write data Data queued by TCP Close FIN Ack of data and FIN close returns Application reads queued data and FIN close FIN Ack of data and FIN Close with SO_LINGER socket option set and l_linger a positive value

SO_LINGER client server write data Data queued by TCP Shutdown FIN read block FIN Ack of data and FIN Application reads queued data and FIN close FIN read returns 0 Ack of data and FIN Using shutdown to know that peer has received our data

An way to know that the peer application has read the data use an application-level ack or application ACK client char ack; Write(sockfd, data, nbytes); // data from client to server n=Read(sockfd, &ack, 1); // wait for application-level ack server nbytes=Read(sockfd, buff, sizeof(buff)); //data from client //server verifies it received the correct amount of data from // the client Write(sockfd, “”, 1);//server’s ACK back to client

SO_RCVBUF , SO_SNDBUF let us change the default send-buffer, receive-buffer size. Default TCP send and receive buffer size : 4096bytes 8192-61440 bytes Default UDP buffer size : 9000bytes, 40000 bytes SO_RCVBUF option must be setting before connection established. TCP socket buffer size should be at least three times the MSSs

SO_RCVLOWAT , SO_SNDLOWAT Every socket has a receive low-water mark and send low-water mark.(used by select function) Receive low-water mark: the amount of data that must be in the socket receive buffer for select to return “readable”. Default receive low-water mark : 1 for TCP and UDP Send low-water mark: the amount of available space that must exist in the socket send buffer for select to return “writable” Default send low-water mark : 2048 for TCP UDP send buffer never change because dose not keep a copy of send datagram.

SO_RCVTIMEO, SO_SNDTIMEO allow us to place a timeout on socket receives and sends. Default disabled

SO_REUSEADDR, SO_REUSEPORT Allow a listening server to start and bind its well known port even if previously established connection exist that use this port as their local port. Allow multiple instance of the same server to be started on the same port, as long as each instance binds a different local IP address. Allow a single process to bind the same port to multiple sockets, as long as each bind specifies a different local IP address. Allow completely duplicate bindings : multicasting

SO_TYPE Return the socket type. Returned value is such as SOCK_STREAM, SOCK_DGRAM...

SO_USELOOPBACK This option applies only to sockets in the routing domain(AF_ROUTE). The socket receives a copy of everything sent on the socket.