1 Socket Options getsockopt and setsockopt functions Check options and obtain default values Generic socket options IPv4 socket options IPv6 socket options.

Slides:



Advertisements
Similar presentations
Review: Name/Address conversion: –What does the domain name system do? –Which system calls use the domain name system? –How does it work? –How does getservbyname.
Advertisements

Florida State UniversityCOP Advanced Unix Programming Raw Sockets Datalink Access Chapters 25, 26.
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.
Out-of-Band Data© Dr. Ayman Abdel-Hamid, CS4254 Spring CS4254 Computer Network Architecture and Programming Dr. Ayman A. Abdel-Hamid Computer Science.
Netprog Advanced Sockets Programming1 Advanced Sockets Programming Ref: Chapter 7,11,21,22.
Transmission Control Protocol (TCP) Basics
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.
CSCE 515: Computer Network Programming Chin-Tser Huang University of South Carolina.
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.
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.
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
1 Application Presentation Session Transport Network Datalink Physical OSI model Application IPv4, IPv6 Device Driver Hardware TCPUDP Internet.
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.
Network Layer4-1 Network layer r transport segment from sending to receiving host r on sending side encapsulates segments into datagrams r on rcving side,
Network Layer4-1 Network layer r transport segment from sending to receiving host r on sending side encapsulates segments into datagrams r on rcving side,
Socket option Getsockopt ou setsockopt fcntl ioctl.
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.
IT1352-NETWORK PROGRAMMING AND MANAGEMENT
Signal-Driven I/O Concepts and steps for using signal-driven I/O
More on Socket API. How to Place Timeouts on Sockets (1)  Using SIGALRM signal Connection timeout 기간의 축소 Response timeout advio/dgclitimeo3.clib/connect_timeo.c.
Nonblocking I/O Blocking vs. non-blocking I/O Nonblocking input, output, accept, and connect Readings –UNP Ch16 1.
CS4550 Computer Networks II IP : internet protocol, part 2 : packet formats, routing, routing tables, ICMP read feit chapter 6.
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.
Network Programming Eddie Aronovich mail:
7.9 TCP Socket Options 7.10 SCTP Socket Options 7.11 fcntl Function 7.12 Summary 報告者 : 梁凱鈞.
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.
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.
Understanding IPv6 Slide: 1 Lesson 12 IPv6 Mobility.
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.
TELE 402 Lecture 8: Broadcast and Multicast 1 Overview Last Lecture –IPv6 This Lecture –Broadcast and multicast sockets –Source: Chapters 20&21 of Stevens’
CMPT 471 Networking II Network Programming © Janice Regan,
1 CSE 5346 Spring Network Simulator Project.
Net7: IP 協定 Internet Protocol 授課教師:雲林科技大學 張慶龍 老師.
Ioctl Operations. ioctl Function Interface Configuration  Netstat, ifconfig command 에서 사용.
Computer Networking Project II question/answer session October 18, 2001.
Chapter 3 TCP and IP 1 Chapter 3 TCP and IP. Chapter 3 TCP and IP 2 Introduction Transmission Control Protocol (TCP) User Datagram Protocol (UDP) Internet.
IP Fragmentation. Network layer transport segment from sending to receiving host on sending side encapsulates segments into datagrams on rcving side,
IP Internet Protocol. IP TCP UDP ICMPIGMP ARP PPP Ethernet.
Client/Server Design Issues Based on Java Network Programming and Distributed Computing, Chapter 6 Also Online Java Tutorial, Sun.
IPv4 socket option Level => IPPROTO_IP
Socket Option.
Operating Systems Sockets ENCE 360.
學研計畫Training Course IP Multicasting
Network Programming CSC- 341
Chapter 07. Socket Options.
Advanced Sockets Programming
Socket options: a summary
Advanced UNIX programming
Presentation transcript:

1 Socket Options getsockopt and setsockopt functions Check options and obtain default values Generic socket options IPv4 socket options IPv6 socket options TCP socket options fcntl function Summary

2 getsockopt and setsockopt Functions #include int getsockopt (int sockfd, int level, int optname, void *optval, socklen_t *optlen ); int setsockopt (int sockfd, int level, int optname, const void *optval, socklen_t optlen ); Both return: 0 if OK, -1 if error Types of options: flag and value Levels: Generic -- SOL_SOCKET IP -- IPPROTO_IP ICMPv6 -- IPPROTO_OCMPV6 IPv6 --IPPROTO_IPV6 TCP --IPPROTO_TCP

3 Check Options and Obtain Default Values Program declaration: –declare union of possible option values –define printing function prototypes –define sock_opt structure, initialize sock_opt[ ] array Check and print options: –create TCP socket, go through all options –call getsockopt –print option’s default value

4 Declaration for Socket Options (see figure 7.2) Program to Check and Print Socket Options (see figure 7.3 and 7.4)

5 Generic Socket Options SO_BROADCAST: permit sending of broadcast datagram, only on broadcast links SO_DEBUG: enable debug tracing of packets sent or received by TCP socket, trpt program to examine the kernel circular buffer SO_DONTROUTE: bypass routing table lookup, used by routing daemons (routed and gated) in case the routing table is incorrect SO_ERROR: get pending error and clear SO_KEEPALIVE: test if TCP connection still alive periodically (2 hours, changed by TCP_KEEPALIVE)

6 Generic Socket Options (Cont.) SO_LINGER: linger on TCP close if data in socket send buffer, linger structure passed SO_OOBINLINE: leave received out-of-band data inline in the normal input queue SO_RCVBUF/SO_SNDBUF: socket receive / send buffer size, TCP default: , UDP default: 40000/9000 SO_RCVLOWAT/SO_SNDLOWAT: receive / send buffer low water mark for select to return

7 Generic Socket Options (Cont.) SO_RCVTIMEO/SO_SNDTIMEO: receive / send timeout for socket read/write SO_REUSEADDR/SO_REUSEPORT: allow local address reuse for TCP server restart, IP alias, UDP duplicate binding for multicasting SO_TYPE: get socket type, SOCK_STREAM or SOCK_DGRAM SO_USELOOPBACK: routing socket gets copy of what it sends

8 IPv4 Socket Options IP_HDRINCL: IP header included with data, e.g. traceroute builds own IP header on a raw socket IP_OPTIONS: specify socket options like source route, timestamp, record route, etc. IP_RECVSTADDR: return destination IP address of a received UDP datagram by recvmsg IP_RECVIF: return received interface index for a received UDP datagram by recvmsg

9 IP Socket Options (Cont.) IP_TOS: set IP TOS field of outgoing packets for TCP/UDP socket, TOS: IPTOS_LOWDELAY / THROUGHPUT, RELIABILITY / LOWCOST IP_TTL: set and fetch the default TTL for outgoing packets, 64 for TCP/UDP sockets, 255 for raw sockets, used in traceroute IP_MULTICAST_IF, IP_MULTICAST_TTL, IP_MULTICAST_LOOP,IP_ADD_MEMBERSHIP IP_DROP_MEMBERSHIP

10 IPv6 Socket Options ICMP6_FILTER: fetch and set icmp6_filter structure specifying message types to pass IPV6_ADDFORM: change address format of socket between IPv4 and IPv6 IPV6_CHECKSUM: offset of checksum field for raw socket IPV6_DSTOPTS: return destination options of received datagram by recvmsg IPV6_HOPLIMIT: return hop limit of received datagrams by recvmsg

11 IPv6 Socket Options (Cont.) IPV6_HOPOPS: return hop-by-hop options of received datagrams by recvmsg IPV6_NEXTHOP: specify next hop address as a socket address structure for a datagram IPV6_PKTINFO: return packet info, dest IPv6 and arriving interface, of received datagrams

12 IPv6 Socket Options (Cont.) IPV6_PKTOPTIONS: specify socket options of TCP socket IPV6_RTHDR: receive source route IPV6_UNICAST_HOPS: ~ IP_TTL IPV6_MULTICAST_IF/HOPS/LOOP, IPV6_ADD/DROP_MEMBERSHIP

13 TCP Socket Options TCP_KEEPALIVE: seconds between probes TCP_MAXRT: TCP max retx time TCP_MAXSEG: TCP max segment size TCP_NODELAY: disable Nagle algorithm, to reduce the number of small packets TCP_STDURG: interpretation of TCP’s urgent pointer, used with out-of-band data

14 fcntl Function #include int fcntl (int fd, int cmd,... /* int arg */ ); returns: depends on cmd if OK, -1 on error Two flags that affect a socket: (fetch by F_GETFL, set by F_SETFL) O_NONBLOCK (nonblocking I/O) O_ASYNC (signal-driven I/O notification) To set a flag : fetch, OR/AND~, set int flags; if ( (flags = fcntl (fd, F_GETFL, 0) ) < 0) error_sys (“F_GETFL error”); flags |= O_NONBLOCK; /* turn on */ ( or flags &= ~O_NONBLOCK; /* turn off */ ) if (fcntl(fd, F_SETFL, flags) < 0) error_sys (“F_SETFL error”);

15 fcntl Function (Cont.) Two signals, SIGIO and SIGURG, are sent to the socket owner (process ID or process group ID) if the socket is assigned an owner by F_SETOWN command. fcntl commands to set or get socket owner: F_SETOWN, F_GETOWN

16 Summary Commonly used socket options: SO_KEEPALIVE, SO_RCVBUF, SO_SNDBUF, SO_REUSEADDR SO_REUSEADDR set in TCP server before calling bind SO_LINGER gives more control over when close returns and forces RST to be sent SO_RCVBUF/SO_SNDBUF for bulk data transfer across long fat pipes