TDC561 Network Programming Camelia Zlatea, PhD Week 5: Client/Server Programming Aspects  Client side:

Slides:



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

Sockets: Network IPC Internet Socket UNIX Domain Socket.
Taekyung Kim 0x410 ~ 0x International Standards Organization (ISO) is a multinational body dedicated to worldwide agreement on international.
Programming with UDP – I Covered Subjects: IPv4 Socket Address Structure Byte Ordering Functions Address Access/Conversion Functions Functions: 1.socket()
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.
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.
Netprog: daemons and inetd1 Daemons & inetd Refs: Chapter 13.
Networks: TCP/IP Socket Calls1 Elementary TCP Sockets Chapter 4 UNIX Network Programming Vol. 1, Second Ed. Stevens.
Elementary TCP Sockets Chapter 4 UNIX Network Programming Vol. 1, Second Ed. Stevens.
Quick Overview. 2 ISO/OSI Reference Model Application Application Presentation Presentation Session Session Transport Transport Network Network Data Link.
Socket Programming.
Multimedia Networking Sockets. Outline Socket basics Socket details (TCP and UDP) Socket options Final notes.
Tutorial 8 Socket Programming
Programming with Berkeley Sockets Presented by Chris GauthierDickey Written by Daniel Stutzbach (I think!) for CIS 432/532 Useful References: ● man pages.
UDP: User Datagram Protocol. UDP: User Datagram Protocol [RFC 768] r “bare bones”, “best effort” transport protocol r connectionless: m no handshaking.
CS 311 – Lecture 18 Outline IPC via Sockets – Server side socket() bind() accept() listen() – Client side connect() Lecture 181CS Operating Systems.
SOCKETS Lecture #3. The Socket Interface Funded by ARPA (Advanced Research Projects Agency) in Developed at UC Berkeley Objective: to transport.
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.
1 Tutorial on Socket Programming Computer Networks - CSC 458 Department of Computer Science Yukun Zhu (Slides are mainly from Monia Ghobadi, and Amin Tootoonchian,
UNIX Sockets COS 461 Precept 1.
Server Design Discuss Design issues for Servers Review Server Creation in Linux.
ECE 4110 – Internetwork Programming Client-Server Model.
1 Networking (Stack and Sockets API). 2 Topic Overview Introduction –Protocol Models –Linux Kernel Support TCP/IP Sockets –Usage –Attributes –Example.
TCP/IP Protocol Stack IP Device Drivers TCPUDP Application Sockets (Gate to network) TCP: –Establish connection –Maintain connection during the communication.
Assignment 3 A Client/Server Application: Chatroom.
Netprog: DNS and name lookups1 Address Conversion Functions and The Domain Name System Refs: Chapter 9 RFC 1034 RFC 1035.
Socket Programming. Introduction Sockets are a protocol independent method of creating a connection between processes. Sockets can be either – Connection.
Client-Side Network Programming
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.
ICOM 6115©Manuel Rodriguez-Martinez ICOM 6115 – Computer Networks and the WWW Manuel Rodriguez-Martinez, Ph.D. Lecture 26.
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:
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.
UNIX Sockets COS 461 Precept 1. Socket and Process Communication The interface that the OS provides to its networking subsystem application layer transport.
Introduction to Socket
1 Daemons & inetd Refs: Chapter Daemons A daemon is a process that: –runs in the background –not associated with any terminal Unix systems typically.
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.
2: Application Layer1 Chapter 2: Application layer r 2.1 Principles of network applications r 2.2 Web and HTTP r 2.3 FTP r 2.4 Electronic Mail  SMTP,
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,
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.
1 Spring Semester 2008, Dept. of Computer Science, Technion Internet Networking recitation #7 Socket Programming.
Netprog: Client/Server Issues1 Issues in Client/Server Programming Refs: Chapter 27.
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.
Socket Programming(1/2). Outline  1. Introduction to Network Programming  2. Network Architecture – Client/Server Model  3. TCP Socket Programming.
1 Socket Interface. 2 Basic Sockets API Review Socket Library TCPUDP IP EthernetPPP ARP DHCP, Mail, WWW, TELNET, FTP... Network cardCom Layer 4 / Transport.
1 Issues in Client/Server Refs: Chapter 27 Case Studies RFCs.
Socket Option.
UNIX Sockets COS 461 Precept 1.
Transport layer API: Socket Programming
Chapter 07. Socket Options.
Advanced Network Programming spring 2007
Advanced Sockets Programming
Issues in Client/Server Programming
Daemons & inetd Refs: Chapter 12.
Sockets Programming Socket to me!.
Sockets Programming Socket to me!.
Internet Networking recitation #8
Presentation transcript:

TDC561 Network Programming Camelia Zlatea, PhD Week 5: Client/Server Programming Aspects  Client side: Identifying the Server; Specifying a local IP address; TCP client design, UDP client design.  Server Side: Daemon, inetd. Socket Options ( discussion will continue in a next lecture )

Network Programming (TDC561)Page 2 Winter 2003 References  Douglas Comer, David Stevens, Internetworking with TCP/IP : Client-Server Programming, Volume III (BSD Unix and ANSI C), 2nd edition, 1996 (ISBN X) –Chap. 6, 14 (partial)  W. Richard Stevens, Network Programming : Networking API: Sockets and XTI, Volume 1, 2nd edition, 1998 (ISBN X) –Chap. 7,11,12, 21,22

Network Programming (TDC561)Page 3 Winter 2003 Aspects of Client/Server Programming  Client-side aspects: –Identifying the Server. »Looking up an IP address. »Looking up a well known port name. –Specifying a local IP address. –TCP client design. –UDP client design.  Server-side aspects: –daemons –inetd

Network Programming (TDC561)Page 4 Winter 2003 Identifying the Server  Need an IP address, protocol and port. –often use host names instead of IP addresses. –usually the protocol (UDP vs. TCP) is not specified by the user. –often the port is not specified by the user.  Options: –hard-coded into the client program. –require that the user identify the server. –read from a configuration file. –use a separate network service to lookup the identity of the server.

Network Programming (TDC561)Page 5 Winter 2003 Byte Ordering  Different computer architectures use different byte ordering to represent/store multi-byte values (such as 16-bit/32-bit integers)  16 bit integer: Low Byte High Byte Low Byte Address A Address A+1 Little-Endian (Intel) Big-Endian (RISC-Sparc)

Network Programming (TDC561)Page 6 Winter 2003 Byte Order and Networking  Suppose a Big Endian machine sends a 16 bit integer with the value 2:  A Little Endian machine will understand the number as 512:  How do two machines with different byte-orders communicate? –Using network byte-order –Network byte-order = big-endian order

Network Programming (TDC561)Page 7 Winter 2003 Network Byte Order  Conversion of application-level data is left up to the presentation layer.  Lower level layers communicate using a fixed byte order called network byte order for all control data.  TCP/IP mandates that big-endian byte ordering be used for transmitting protocol information  All values stored in a sockaddr_in must be in network byte order. –sin_port a TCP/IP port number. –sin_addr an IP address.

Network Programming (TDC561)Page 8 Winter 2003 Network Byte Order Functions  Several functions are provided to allow conversion between host and network byte ordering,  Conversion macros ( ) –to translate 32-bit numbers (i.e. IP addresses): »unsigned long htonl(unsigned long hostlong); »unsigned long ntohl(unsigned long netlong); –to translate 16-bit numbers (i.e. Port numbers): »unsigned short htons(unsigned short hostshort); »unsigned short ntohs(unsigned short netshort);

Network Programming (TDC561)Page 9 Winter 2003 Services and Ports  Identifying of the server –Many services are available via “well known” addresses (names). –There is a mapping of service names to port numbers: struct *servent getservbyname( char *service, char *protocol ); servent->s_port is the port number in network byte order.  Specifying a Local Address –When a client creates and binds a socket it must specify a local port and an IP address. »A client ask the kernel to assign the local IP address: haddr->sin_addr.s_addr= htonl(INADDR_ANY); »Typically a randomly port available is assigned with: haddr->port = htons(0);

Network Programming (TDC561)Page 10 Winter 2003 Example: Identifying the Server /* Initialize the server structure */ server.sin_addr.s_addr = INADDR_ANY; server.sin_family = AF_INET; /* Get the service port associated with this process usually in some /etc/ config file such as /etc/services */ servent_p = getservbyname ( PMSERVICE, “tcp” ); server.sin_port = servent_p->s_port;  Option: read from a configuration file.

Network Programming (TDC561)Page 11 Winter 2003 DNS library functions : gethostbyname #include struct hostent *gethostbyname( const char *hostname); struct hostent { char *h_name; char **h_aliases; int h_addrtype; int h_length; char **h_addr_list; };

Network Programming (TDC561)Page 12 Winter 2003 hostent h_name h_aliases h_addrtype h_length h_addr_list Official Name alias 1 alias 2 null (IP address 1) (IP address 2) null #define h_addr h_addr_list[0] h_addr_list[0] h_addr_list[1] All the IP addresses returned via the hostent are in network byte order

Network Programming (TDC561)Page 13 Winter 2003 DNS library functions : gethostbyname  On error gethostbyname return null.  gethostbyname sets the global variable h_errno to indicate the exact error: –HOST_NOT_FOUND –TRY_AGAIN –NO_RECOVERY –NO_DATA –NO_ADDRESS

Network Programming (TDC561)Page 14 Winter 2003 Getting host IP address: char **h_addr_list; h = gethostbyname(“hawk.depaul.edu"); memcpy(&sockaddr.sin_addr, h->h_addr_list[0], sizeof(struct in_addr));

Network Programming (TDC561)Page 15 Winter 2003 DNS library functions : gethostbyaddr struct hostent *gethostbyaddr( const char *addr size_t len, int family);

Network Programming (TDC561)Page 16 Winter 2003 Other DNS library functions  Shell Command uname –n –get hostname of local host –uname –a prints all info local host  getservbyname –get port number for a named service  getservbyaddr –get name for service associated with a port number

Network Programming (TDC561)Page 17 Winter 2003 Name/Address Conversion  Protocol dependent DNS library functions –gethostbyname –gethostbyaddr  Posix protocol independent functions –getaddrinfo() –getnameinfo() –getaddrinfo()and getnameinfo() functions provide name/address conversions as part of the sockets library. –designed to support writing code that can run on many protocols (IPv4, IPv6)

Network Programming (TDC561)Page 18 Winter 2003 POSIX: getaddrinfo() int getaddrinfo( const char *hostname, const char *service, const struct addrinfo* hints, struct addrinfo **result);  hostname is a hostname or an address string (dotted decimal string for IP).  service is a service name or a decimal port number string.  getaddrinfo() –provides the combined functionality of gethostbyname() and getservbyname()

Network Programming (TDC561)Page 19 Winter 2003 POSIX: getaddrinfo() struct addrinfo { intai_flags; intai_family; intai_socktype; intai_protocol; size_tai_addrlen; char *canonname; structsockaddr *ai_addr; structaddrinfo *ai_next; }; used by socket() used by: bind()connect()sendto()  result is returned with the address of a pointer to an addrinfo structure that is the head of a linked list.

Network Programming (TDC561)Page 20 Winter 2003 POSIX: getnameinfo() int getnameinfo( const struct sockaddr *sockaddr, socklen_t addrlen char *host, size_t hostlen, char *serv, size_t servlen, int flags); getnameinfo() looks up a hostname and a service name given a sockaddr

Network Programming (TDC561)Page 21 Winter 2003 TCP Client Design  Identify and establish server address (IP and port).  Allocate a socket.  Request OS to use any valid local port and IP address  Call connect()  Communicate with server (read,write).  Close the connection.

Network Programming (TDC561)Page 22 Winter 2003 Stream Socket Transaction (TCP Connection) socket() connect() bind() listen() accept() socket() write() read() close() read() write() read()close() 3-way handshake EOF data Client Server

Network Programming (TDC561)Page 23 Winter 2003 Closing a TCP socket  Many TCP based application protocols support multiple requests and/or variable length requests over a single TCP connection. – How does the server known when the client is done ? –When it is safe to close the socket?

Network Programming (TDC561)Page 24 Winter 2003 Partial Close  One solution is for the client to shut down only it’s writing end of the socket.  The shutdown() system call provides this function. shutdown( int s, int direction); –direction can be 0 to close the reading end or 1 to close the writing end. –shutdown sends info to the other process

Network Programming (TDC561)Page 25 Winter 2003 TCP Sockets Programming  Typical issues : –reads don’t correspond to writes. –synchronization (including close())  TCP Reads: –Each call to read() on a TCP socket returns any available data (up to a maximum). –TCP buffers data at both ends of the connection.

Network Programming (TDC561)Page 26 Winter 2003 UDP Client Design  Identify and establish the server address (IP and port).  Allocate a socket.  Request OS to use any valid local port and IP address  Communicate with server (send, recv)  Close the socket.

Network Programming (TDC561)Page 27 Winter 2003 Datagram Socket Transaction (UDP Connection) socket() bind() socket() sendto() recvfrom() close() recvfrom() sendto() data Client Server

Network Programming (TDC561)Page 28 Winter 2003 Datagram Sockets  Connectionless sockets, i.e., C/S addresses are passed along with each message sent from one process to another  Peer-to-Peer Communication  Provides an interface to the UDP datagram services  Handles network transmission as independent packets  Provides no guarantees, although it does include a checksum  Does not detect duplicates  Does not determine sequence –ie information can be lost, wrong order or duplicated

Network Programming (TDC561)Page 29 Winter 2003 Daemons  Most servers run as a daemon process  Typical UNIX daemons: –Web server (httpd) –Mail server (sendmail) –SuperServer (inetd) –System logging (syslogd) –Print server (lpd) –router process (routed, gated)

Network Programming (TDC561)Page 30 Winter 2003 Daemon Process  A daemon is a process that: –runs in the background –not associated with any terminal »output doesn't end up in another session. »ignore SIGINT (such as terminal generated signals - ^C –since is not associated with any terminal uses »file system »central logging facility –daemons should close all unnecessary descriptors »often including stdin, stdout, stderr. –daemons often change working directory.  A background process –Parent process fork() and then the parent exit().  A way to disassociate a process from a terminal. –Call setsid() and then fork() again.

Network Programming (TDC561)Page 31 Winter 2003 Daemon Process Init – Example #include int daemon_init(void) { pid_tpid; if ( (pid = fork()) < 0) return(-1); else if (pid != 0) exit(0);/* parent is gone */ /* child continues */ setsid();/* become session leader */ system(“cd /");/* change working directory */ umask(0);/* clear our file mode creation mask */ close(0); close(1); close(2); /* stdin, stdout, stderr */ return(0); }

Network Programming (TDC561)Page 32 Winter 2003  CPU utilization –There can be many servers running as daemons -and idle most of the time.  Memory utilization –Most daemons/servers are suspended most of the time, but still occupy space in the process table.  A solution: Superserver or inetd ( Internet services daemon ) Performance issues with daemons processes

Network Programming (TDC561)Page 33 Winter 2003 inetd  the SuperServer is named inetd.  inetd daemon creates multiple sockets and waits for (multiple) incoming requests.  inetd typically uses select to watch multiple sockets for input.  when a request arrives, inetd will fork and the child process handles the client.  inetd child process closes all unnecessary sockets.  inetd child dup ’s the client socket to descriptors 0,1 and 2 ( stdin, stdout, stderr ).  inetd child exec ’s the real server program, which handles the request and exits.

Network Programming (TDC561)Page 34 Winter 2003 inetd based servers  Servers that are started by inetd assume that the socket holding the request is already established (descriptors 0,1 or 2).  TCP servers started by inetd don’t call accept, so they must call getpeername if they need to know the address of the client.  inetd reads a configuration file that lists all the services it should handle. –/etc/inetd.conf  inetd creates a socket for each listed service, and adds the socket to a fd_set given to select().

Network Programming (TDC561)Page 35 Winter 2003 getpeername #include int getpeername(int s, struct sockaddr *name, socklen_t *namelen);  getpeername() returns the name of the peer connected to socket s.

Network Programming (TDC561)Page 36 Winter 2003 inetd service specification  For each service, inetd needs to know: –the socket type and transport protocol –wait/nowait flag. –login name the process should run as. –pathname of real server program. –command line arguments to server program.  Servers that are expected to deal with frequent requests are typically not run from inetd –mail, web, NFS.

Network Programming (TDC561)Page 37 Winter 2003 # Syntax for socket-based Internet services: # # comments start with # echo stream tcp nowait root internal echo dgram udp wait root internal chargen stream tcp nowait root internal chargen dgram udp wait root internal ftp stream tcp nowait root /usr/sbin/ftpd ftpd -l telnet stream tcp nowait root /usr/sbin/telnetd telnetd finger stream tcp nowait root /usr/sbin/fingerd fingerd # Authentication auth stream tcp nowait nobody /usr/sbin/in.identd in.identd -l -e - o # TFTP tftp dgram udpwait root /usr/sbin/tftpd tftpd -s /tftpboot Example /etc/inetd.conf

Network Programming (TDC561)Page 38 Winter 2003 wait/nowait  WAIT specifies that inetd should not look for new clients for the service until the child (the real server) has terminated.  TCP servers usually specify nowait - this means inetd can start multiple copies of the TCP server program - providing concurrency  Most UDP services run with inetd told to wait until the child server has died.

Topic Socket Options (discussion will continue in a next lecture)

Network Programming (TDC561)Page 40 Winter 2003 Socket Options  Various attributes that are used to determine the behavior of sockets.  Setting options tells the OS/Protocol Stack the behavior we want.  Support for generic options (apply to all sockets) and protocol specific options.

Network Programming (TDC561)Page 41 Winter 2003 Option types  Many socket options are Boolean flags indicating whether some feature is enabled (1) or disabled (0).  Other options are associated with more complex types including int, timeval, in_addr, sockaddr, etc.

Network Programming (TDC561)Page 42 Winter 2003 Read-Only Socket Options  Some options are readable only (we can’t set the value).

Network Programming (TDC561)Page 43 Winter 2003 Setting and Getting option values #include getsockopt() gets the current value of a socket option. setsockopt() is used to set the value of a socket option.

Network Programming (TDC561)Page 44 Winter 2003 int getsockopt( int sockfd, int level, int optname, void *opval, socklen_t *optlen); level specifies whether the option is a general option or a protocol specific option (what level of code should interpret the option). getsockopt()

Network Programming (TDC561)Page 45 Winter 2003 int setsockopt( int sockfd, int level, int optname, const void *opval, socklen_t optlen); setsockopt()

Network Programming (TDC561)Page 46 Winter 2003 General Options  Protocol independent options.  Handled by the generic socket system code.  Some general options are supported only by specific types of sockets (SOCK_DGRAM, SOCK_STREAM).

Network Programming (TDC561)Page 47 Winter 2003 Some Generic Options SO_BROADCAST SO_DONTROUTE SO_ERROR SO_KEEPALIVE SO_LINGER SO_RCVBUF,SO_SNDBUF SO_REUSEADDR

Network Programming (TDC561)Page 48 Winter 2003 SO_BROADCAST  Boolean option: enables/disables sending of broadcast messages.  Underlying data layer must support broadcasting  Applies only to SOCK_DGRAM sockets.  Prevents applications from inadvertently sending broadcasts (OS looks for this flag when broadcast address is specified).

Network Programming (TDC561)Page 49 Winter 2003 SO_DONTROUTE  Boolean option: enables bypassing of normal routing.  Used by routing daemons.

Network Programming (TDC561)Page 50 Winter 2003 SO_ERROR  Integer value option.  The value is an error indicator value (similar to errno).  Readable only  Reading (by calling getsockopt() ) clears any pending error.

Network Programming (TDC561)Page 51 Winter 2003 SO_KEEPALIVE  Boolean option: enabled means that STREAM sockets should send a probe to peer if no data flow for a “long time”.  Used by TCP - allows a process to determine whether peer process/host has crashed.  Consider what would happen to an open telnet connection without keepalive.

Network Programming (TDC561)Page 52 Winter 2003 SO_LINGER Value is of type: struct linger { int l_onoff; /* 0 = off */ int l_linger; /* time in seconds */ };  Used to control whether and how long a call to close will wait for pending ACKS.  connection-oriented sockets only.

Network Programming (TDC561)Page 53 Winter 2003 SO_LINGER usage  By default, calling close() on a TCP socket will return immediately.  The closing process has no way of knowing whether or not the peer received all data.  Setting SO_LINGER means the closing process can determine that the peer machine has received the data (but not that the data has been read() !).

Network Programming (TDC561)Page 54 Winter 2003 shutdown() vs SO_LINGER  How you can use shutdown() to find out when the peer process has read all the sent data [see R.Stevens, 7.5]

Network Programming (TDC561)Page 55 Winter 2003 FIN SN=X FIN SN=X Client Server ACK=X+1 ACK=Y FIN SN=Y FIN SN=Y 3... TCP Connection Termination write close close returns Data queued By TCP Application Reads queued data and FIN close

Network Programming (TDC561)Page 56 Winter 2003 FIN SN=X FIN SN=X Client Server ACK=X+1 ACK=Y FIN SN=Y FIN SN=Y 3... TCP Connection Termination close w/ SO_LINGER write close close returns Data queued By TCP App. Reads queued data and FIN close

Network Programming (TDC561)Page 57 Winter 2003 FIN SN=X FIN SN=X Client Server ACK=X+1 ACK=Y FIN SN=Y FIN SN=Y 3... TCP Connection Termination w/ shutdown write shutdown WRITE read blocks read returns 0 Data queued By TCP App. Reads queued data and FIN close

Network Programming (TDC561)Page 58 Winter 2003 SO_RCVBUF and SO_SNDBUF  Integer values options - change the receive and send buffer sizes.  Can be used with STREAM and DGRAM sockets.  With TCP, this option effects the window size used for flow control - must be established before connection is made.

Network Programming (TDC561)Page 59 Winter 2003 SO_REUSEADDR  Boolean option: enables binding to an address (port) that is already in use.  Used by servers that are transient - allows binding a passive socket to a port currently in use (with active sockets) by other processes. (see example from lecture 4 – Performance Management server)  Can be used to establish separate servers for the same service on different interfaces (or different IP addresses on the same interface).  Virtual Web Servers can work this way.

Network Programming (TDC561)Page 60 Winter 2003 IP Options (IPv4)  IP_HDRINCL: used on raw IP sockets when we want to build the IP header ourselves.  IP_TOS: allows us to set the “Type-of-service” field in an IP header.  IP_TTL: allows us to set the “Time-to-live” field in an IP header.

Network Programming (TDC561)Page 61 Winter 2003 TCP socket options  TCP_KEEPALIVE: set the idle time used when SO_KEEPALIVE is enabled.  TCP_MAXSEG: set the maximum segment size sent by a TCP socket.

Network Programming (TDC561)Page 62 Winter 2003 TCP socket options  TCP_NODELAY: can disable TCP’s Nagle algorithm that delays sending small packets if there is unACK’d data pending.  TCP_NODELAY also disables delayed ACKS (TCP ACKs are cumulative).