Chapter 07. Socket Options.

Slides:



Advertisements
Similar presentations
Multicasting© Dr. Ayman Abdel-Hamid, CS4254 Spring CS4254 Computer Network Architecture and Programming Dr. Ayman A. Abdel-Hamid Computer Science.
Advertisements

Socket Options. abstraction Introduction getsockopt and setsockopt function socket state Generic socket option IPv4 socket option ICMPv6 socket option.
Guide to TCP/IP, Third Edition
Chapter 12 Transport protocols. Outline 12.1 introduction 12.2 TCP/IP protocol suite.
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.
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.
Lecture 19 Advanced Sockets Programming CPE 401 / 601 Computer Network Systems slides are modified from Dave Hollinger.
MULTICAST USING UDP SOCKETS. PRELIMINARIES *CAST Unicast Communication is strictly from one sender to another specified receiver eg: TCP on LAN Broadcast.
Computer Networks Sockets.
Socket Programming.
Multimedia Networking Sockets. Outline Socket basics Socket details (TCP and UDP) Socket options Final notes.
TDC561 Network Programming Camelia Zlatea, PhD Week 8: Multicasting; Socket Options;
Sockets IMGD Outline Socket basics Socket details (TCP and UDP) Socket options Final notes.
Windows Sockets Purpose Windows Sockets 2 (Winsock) enables programmers to create advanced internet, intranet, and other network-capable applications to.
Multicasting Jari Kellokoski Introduction When a unicast address identifies a sigle IP interface Then a broadcast address identifies all IP.
Socket Options Jari Kellokoski. Introduction So far we have discovered some basic usage of socket With socket options we control sockets more suitable.
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 options A way for network applications to ‘tweak’ the processing done at lower-levels of the TCP/IP stack.
Socket option Getsockopt ou setsockopt fcntl ioctl.
Process-to-Process Delivery:
Broadcast and Multicast. Unicast Host 2Host 1 Broadcast Packet received by every host on network (including the sender!)
1 Introduction to Raw Sockets 2 IP address Port address MAC address TCP/IP Stack 67 Bootp DHCP OSPF protocol frame type UDP Port # TCP Port.
ECE 4110 – Internetwork Programming Client-Server Model.
University of Calgary – CPSC 441.  UDP stands for User Datagram Protocol.  A protocol for the Transport Layer in the protocol Stack.  Alternative to.
Chapter 17 Networking Dave Bremer Otago Polytechnic, N.Z. ©2008, Prentice Hall Operating Systems: Internals and Design Principles, 6/E William Stallings.
Sockets API Overview Sockets with UDP Sockets with TCP Fast Sockets (Fast UDP) IP Multicasting.
 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.
Network Programming Eddie Aronovich mail:
Broadcasting & Multicasting with UDP sockets Chap 20, 21.
Chaptere19 multicasting. contents multicast address multicasting versus broadcasting on a LAN multicasting on a WAN multicast socket option mcast_join.
Distributed Computing Systems Project 3 – Nutella: A P2P Streaming Movie System Due: Tuesday, April 15 th.
More on Socket API. More on Socket I/O Functions  Scatter read and gather write.
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.
Today’s topic –Broadcast and multicast –Send/receive broadcast and multicast packets.
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.
CS 6401 Introduction to Computer Networks 09/21/2010 Outline - UNIX sockets - A simple client-server program - Project 1 - LAN bridges and learning.
Advanced UNIX programming Fall 2002, lecture 16 Instructor: Ashok Srinivasan Acknowledgements: The syllabus and power point presentations are modified.
TELE 402 Lecture 8: Broadcast and Multicast 1 Overview Last Lecture –IPv6 This Lecture –Broadcast and multicast sockets –Source: Chapters 20&21 of Stevens’
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,
IP Configuration API. Network Interface Configuration NAIfconfigIsDeviceUp() NAIfconfigDeviceFromInterface() NAIfconfigBringDeviceUp() NAIfconfigSetIpAddress()
Distributed Computing Systems Project 3 – Nutella a P2P Streaming Movie System Due: Sunday, February 14 th.
McGraw-Hill Chapter 23 Process-to-Process Delivery: UDP, TCP Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display.
TCP/IP1 Address Resolution Protocol Internet uses IP address to recognize a computer. But IP address needs to be translated to physical address (NIC).
Broadcasting and Multicasting –An area that is not well standardized – systems from different vendors may behave differently when dealing with broadcast.
Department of Computer Science Southern Illinois University Edwardsville Spring, 2010 Dr. Hiroshi Fujinoki CS 547/490 Network.
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.
SOCKET PROGRAMMING Presented By : Divya Sharma.
Lecture Class 3 Advanced Socket Programming: Broadcast & Multicast Concepts.
IPv4 socket option Level => IPPROTO_IP
Socket Option.
Operating Systems Sockets ENCE 360.
學研計畫Training Course IP Multicasting
Process-to-Process Delivery:
Advanced Sockets Programming
Chapter 06. UDP Server/Client.
Process-to-Process Delivery: UDP, TCP
Socket options: a summary
Advanced UNIX programming
Presentation transcript:

Chapter 07. Socket Options

Understanding and practice of various socket options Goal Understanding and practice of various socket options

Socket programming model Overview (1/7) Socket programming model application TCP IP UDP IrDA Bluetooth ... socket Socket code Protocol implementation code

Two types of socket option Overview (2/7) socket options Changing the basic operation of socket call Two types of socket option ① handling in socket code socket option is analyzed and proceeded in socket code ② handling in protocol implementation code socket option is analyzed and proceeded in protocol implementation code

Socket option setting Overview (3/7) int setsockopt ( SOCKET s, int level, int optname, const char* optval, int optlen ) ; success: 0, fail: SOCKET_ERROR

Socket option getting Overview (4/7) int getsockopt ( SOCKET s, int level, int optname, char* optval, int* optlen ) ; success: 0, fail: SOCKET_ERROR

Socket option - SOL_SOCKET Overview (5/7) Socket option - SOL_SOCKET optname SO_BROADCAST SO_DONTROUTE SO_KEEPALIVE SO_LINGER SO_SNDBUF SO_RCVBUF SO_SNDTIMEO SO_RCVTIMEO SO_REUSEADDR optval type BOOL struct linger{} int get set  description permit sending broadcast datagram No routing table reference in data transfer Checking connection status periodically Changing closesocket() property Setting socket send/receive buffer size Setting timeout for send(), recv() and so on Reuse of Local address(IP address, port number)

Socket option - IPPROTO_IP Overview (6/7) Socket option - IPPROTO_IP optname IP_HDRINCL IP_TTL IP_MULTICAST_IF IP_MULTICAST_TTL IP_MULTICAST_LOOP IP_ADD_MEMBERSHIP IP_DROP_MEMBERSHIP optval type BOOL int IN_ADDR{} struct ip_mreq{} get set    description Including IP header in data sending Changing IP packet TTL(time-to-live) Setting interface to send multicast packet Changing TTL of multicast packet Setting of loop-back of multicast packet Join and leave multicast group

Socket option - IPPROTO_TCP Overview (7/7) Socket option - IPPROTO_TCP optname optval type get set description TCP_NODELAY BOOL  Stop Nagle algorithm in TCP

It is supported only for datagram sockets. Its default value is off. SO_BROADCAST option Enables or disables the ability of a process to send broadcast messages. It is supported only for datagram sockets. Its default value is off.

SO_DONTROUTE option usage used by routing daemon to make sure a packet goes through a certain interface Code example BOOL optval = TRUE; if(setsockopt(listen_sock, SOL_SOCKET, SO_DONTROUTE, (char *)&optval, sizeof(optval)) == SOCKET_ERROR) { err_quit("setsockopt()"); }

SO_KEEPALIVE option If set, this option is used for detecting peer host crashes. If this option is set and no data has been exchanged for 2 hours, then TCP sends keepalive probe to the peer. Cases: Peer responds with ACK. Another probe will be sent only after 2 hours of inactivity. Peer responds with RST (has crashed and rebooted). Error is set to ECONNRESET and the socket is closed. No response. 8 more probes are sent after which the socket’s pending error is set to ETIMEDOUT and the socket is closed. Code example BOOL optval = TRUE; if(setsockopt(listen_sock, SOL_SOCKET, SO_KEEPALIVE, (char *)&optval, sizeof(optval)) == SOCKET_ERROR) { err_quit("setsockopt()"); }

l_onoff=0 : defualt behaviour SO_LINGER option This option specifies how the close function operates for connection-oriented protocols struct linger { int l_onoff; /* Linger active */ int l_linger; /* How long to linger for */ }; l_onoff=0 : defualt behaviour l_onoff=1, l_linger=val : close returns only after val seconds, if socket is blocking l_onoff=1, l_linger=0 : RST sent on close

SO_SNDBUF, SO_RCVBUF option usage send and receive buffer size Code example int optval; int optlen = sizeof(optval); if(getsockopt(listen_sock, SOL_SOCKET, SO_RCVBUF, (char *)&optval, &optlen) == SOCKET_ERROR) err_quit("getsockopt()"); printf(“receive buffer size = %d bytes \n", optval); optval *= 2; if(setsockopt(listen_sock, SOL_SOCKET, SO_RCVBUF, (char *)&optval, sizeof(optval)) == SOCKET_ERROR) err_quit("setsockopt()");

SO_SNDTIMEO, SO_RCVTIMEO option Usage Setting timeout for send(), recv(), sendto(), recvfrom(), etc Code example int optval = 3000; if(setsockopt(sock, SOL_SOCKET, SO_RCVTIMEO, (char *)&optval, sizeof(optval)) == SOCKET_ERROR) { err_quit("setsockopt()"); }

SO_REUSEADDR option It allows a listening server to restart and bind its well known port even if previously established connections exist. It 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. It allows a single process to bind the same port to multiple sockets, as long as each bind specifies a different local IP address. It allows completely duplicate bindings only for UDP sockets (broadcasting and multicasting).

Multicast address Features multicasting (1/3) Multicast address Features Join and leave a multicast group , all group members are equal A member have to join a multicast group to receive multicast data A member don’t have to join a multicast group to send multicast data 28 bit Multicast group ID 1

Multicast data transfer (1) multicasting (2/3) Multicast data transfer (1) A B Multicast group A B Multicast group

Multicast data transfer (2) multicasting (3/3) Multicast data transfer (2) MulticastSender.cpp, Multicastreceiver.cpp A B C Multicast group

Socket options setsockopt() getsockopt() API support IP_MULTICAST_LOOP yes IP_MULTICAST_TTL IP_MULTICAST_IF IP_ADD_MEMBERSHIP no IP_DROP_MEMBERSHIP Vinayak Jagtap, IP Broadcasting and Multicasting

IP_MULTICAST_IF option (1/2) Usage Specify the interface for outgoing multicast datagrams sent on this socket Code example IN_ADDR localaddr; localaddr.s_addr = inet_addr("147.46.114.70"); if(setsockopt(sock, IPPROTO_IP, IP_MULTICAST_IF, (char *)&localaddr, sizeof(localaddr)) == SOCKET_ERROR) { err_quit("setsockopt()"); }

IP_MULTICAST_IF option (2/2) Option setting result application 147.46.114.70 147.46.115.38

IP_MULTICAST_TTL option Usage Set the IPv4 TTL parameter (if not specified, default=1) Code example // multicast TTL setting int ttl = 2; retval = setsockopt(sock, IPPROTO_IP, IP_MULTICAST_TTL, (char *)&ttl, sizeof(ttl)); if(retval == SOCKET_ERROR) err_quit("setsockopt()");

IP_MULTICAST_LOOP option Usage Enable or disable local loopback (default is enabled) Code example BOOL optval = FALSE; // no receiving the data sent if(setsockopt(sock, IPPROTO_IP, IP_MULTICAST_LOOP, (char *)&optval, sizeof(optval)) == SOCKET_ERROR) { err_quit("setsockopt()"); }

IP_ADD_MEMBERSHIP, IP_DROP_MEMBERSHIP option (1/3) Usage Join/leave a multicast group on a specified local interface Option value #include <ws2tcpip.h> struct ip_mreq { struct in_addr imr_multiaddr; /* IP multicast address of group */ struct in_addr imr_interface; /* local IP address of interface */ };

IP_ADD_MEMBERSHIP, IP_DROP_MEMBERSHIP option (2/3) Code example struct ip_mreq mreq; mreq.imr_multiaddr.s_addr = inet_addr("235.7.8.9"); mreq.imr_interface.s_addr = inet_addr("147.46.114.70"); if(setsockopt(sock, IPPROTO_IP, IP_ADD_MEMBERSHIP, (char *)&mreq, sizeof(mreq)) == SOCKET_ERROR) { err_quit("setsockopt()"); }

IP_ADD_MEMBERSHIP, IP_DROP_MEMBERSHIP option (3/3) Option setting result application 147.46.114.70 147.46.115.38

TCP_NODELAY option (1/2) usage Used to enable/disable Nagle’s algorithm in TCP Nagle algorithm ① send the data when the size of the sending data becomes to MSS(maximum segment size) ② wait for the ACK of the previous data when the sending data size is less that. Once ACK is arrived, data is sent to peer side BOOL optval = TRUE; // Stop Nagle algorithm if(setsockopt(sock, IPPROTO_TCP, TCP_NODELAY, (char *)&optval, sizeof(optval)) == SOCKET_ERROR) { err_quit("setsockopt()"); }