SlideShare uma empresa Scribd logo
1 de 45
Chapter 7
Socket Option
abstraction

•   Introduction
•   getsockopt and setsockopt function
•   socket state
•   Generic socket option
•   IPv4 socket option
•   ICMPv6 socket option
•   IPv6 socket option
•   TCP 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
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.
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=>
• When the keep-alive option is set for a TCP socket and no
  data has been exchanged across the socket in either
  direction for two hours, TCP automatically sends a keep-
  alive probe to the peer.
• 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

       Close                                         Data queued by TCP
                              FIN
close returns
                      Ack of data and FIN

                                                     Application reads queued
                                                     data and FIN
                              FIN                    close

                          Ack of data and FIN



 Default operation of close:it returns immediately
SO_LINGER

             client                             server

     write                    data

      Close                                          Data queued by TCP
                              FIN

                      Ack of data and FIN
close returns
                                                     Application reads queued
                                                     data and FIN
                              FIN                    close

                          Ack of data and FIN



Close with SO_LINGER socket option set and l_linger a positive value
SO_LINGER

              client                             server

      write                    data

Shutdown                                              Data queued by TCP
                               FIN
read block
                       Ack of data and FIN

                                                      Application reads queued
                                                      data and FIN
                               FIN                    close
read returns 0
                           Ack of data and FIN



  Using shutdown to know that peer has received our data
• A 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.
IPv4 socket option
• Level => IPPROTO_IP
• IP_HDRINCL => If this option is set for a raw IP
  socket, we must build our IP header for all the
  datagrams that we send on the raw socket.(chapter
  26)
When this option is set, we build a complete IP header, with the following exception:

•   IP always calculates and stores the IP header checksum.
•   If we set the IP identification field to 0, the kernel will set the field.
•   If the source IP address is INADDR_ANY, IP sets it to the primary IP address of
    the outgoing interface.
•   Setting IP options is implementation-dependent. Some implementations take any
    IP options that were set using the IP_OPTIONS socket option and append these to
    the header that we build, while others require our header to also contain any
    desired IP options.
•   Some fields must be in host byte order, and some in network byte order. This is
    implementation-dependent, which makes writing raw packets with IP_HDRINCL
    not as portable as we'd like.
• IP_OPTIONS=>allows us to set IP option in IPv4
  header.(chapter 24)
• IP_RECVDSTADDR=>This socket option causes
  the destination IP address of a received UDP
  datagram to be returned as additional data by
  recvmsg.(chapter20)
IP_RECVIF
• Cause the index of the interface on which a UDP
  datagram is received to be returned as ancillary
  data by recvmsg.(chapter20)
IP_TOS
• lets us set the type-of-service(TOS) field in IP
  header for a TCP or UDP socket.
• If we call getsockopt for this option, the current
  value that would be placed into the TOS(type of
  service) field in the IP header is returned.(figure
  A.1)
IP_TTL
• We can set and fetch the default TTL(time to live
  field)for unicast.
• With this option, we can set and fetch the default
  TTL that the system will use for unicast packets
  sent on a given socket. (The multicast TTL is set
  using the IP_MULTICAST_TTL socket option)
ICMPv6 socket option
• This socket option is processed by ICMPv6 and
  has a level of IPPROTO_ICMPV6.
• ICMP6_FILTER =>lets us fetch and set an
  icmp6_filter structure that specifies which of the
  256possible ICMPv6 message types are passed to
  the process on a raw socket.(chapter 25)
IPv6 socket option
• This socket option is processed by IPv6 and have
  a level of IPPROTO_IPV6.
• IPV6_ADDRFORM=>allow a socket to be
  converted from IPv4 to IPv6 or vice versa.
  (chapter 10)
• IPV6_CHECKSUM=>specifies the byte offset
  into the user data of where the checksum field is
  located.
IPV6_DSTOPTS
• Specifies that any received IPv6 destination
  options are to be returned as ancillary data by
  recvmsg.
IPV6_HOPLIMIT
• Setting this option specifies that the received hop
  limit field be returned as ancillary data by
  recvmsg.(chapter 20)
• Default off.
IPV6_HOPOPTS
• Setting this option specifies that any received
  IPv6 hop-by-hop option are to be returned as
  ancillary data by recvmsg.(chapter 24)
IPV6_NEXTHOP
• This is not a socket option but the type of an
  ancillary data object that can be specified to
  sendmsg. This object specifies the next-hop
  address for a datagram as a socket address
  structure.(chapter20)
IPV6_PKTINFO
• Setting this option specifies that the following
  two pieces of infoemation about a received IPv6
  datagram are to be returned as ancillary data by
  recvmsg:the destination IPv6 address and the
  arriving interface index.(chapter 20)
IPV6_PKTOPTIONS
• Most of the IPv6 socket options assume a UDP
  socket with the information being passed between
  the kernel and the application using ancillary data
  with recvmsg and sendmsg.
• A TCP socket fetch and store these values using
  IPV6_ PKTOPTIONS socket option.
IPV6_RTHDR
• Setting this option specifies that a received IPv6
  routing header is to be returned as ancillary data
  by recvmsg.(chapter 24)
• Default off
IPV6_UNICAST_HOPS
• This is similar to the IPv4 IP_TTL.
• Specifies the default hop limit for outgoing
  datagram sent on the socket, while fetching the
  socket option returns the value for the hop limit
  that the kernel will use for the socket.
TCP socket option
• There are five socket option for TCP, but three
  are new with Posix.1g and not widely supported.
• Specify the level as IPPROTO_TCP.
TCP_KEEPALIVE
• This is new with Posix.1g
• It specifies the idle time in second for the
  connection before TCP starts sending keepalive
  probe.
• Default 2hours
• this option is effective only when the
  SO_KEEPALIVE socket option enabled.
TCP_MAXRT
• This is new with Posix.1g.
• It specifies the amount of time in seconds before a
  connection is broken once TCP starts
  retransmitting data.
  – 0 : use default
  – -1:retransmit forever
  – positive value:rounded up to next transmission time
TCP_MAXSEG
• This allows us to fetch or set the maximum
  segment size(MSS) for TCP connection.
TCP_NODELAY
• This option disables TCP’s Nagle algorithm.
  (default this algorithm enabled)
• purpose of the Nagle algorithm.
  ==>prevent a connection from having multiple
  small packets outstanding at any time.
• Small packet => any packet smaller than MSS.
Nagle algorithm
• Default enabled.
• Reduce the number of small packet on the WAN.
• If given connection has outstanding data , then no
  small packet data will be sent on connection until
  the existing data is acknowledged.
Nagle algorithm disabled
    Nagle algorithm disabled
h        0
e      250
l      500
l      750
o    1000
!    1250
     1500
     1500
    1750
    2000
Nagle algorithm enabled

h            h
         0
e      250
l      500
                  el
l      750
o    1000
!    1250
                 lo
     1500
     1500
    1750
                  !
    2000
    2250
    2500
Np unit iv ii
Np unit iv ii

Mais conteúdo relacionado

Mais procurados

Waterfall Model (Software Engineering)
Waterfall Model (Software Engineering)  Waterfall Model (Software Engineering)
Waterfall Model (Software Engineering) MuhammadTalha436
 
Tutorial ns 3-tutorial-slides
Tutorial ns 3-tutorial-slidesTutorial ns 3-tutorial-slides
Tutorial ns 3-tutorial-slidesVinayagam D
 
Java rmi example program with code
Java rmi example program with codeJava rmi example program with code
Java rmi example program with codekamal kotecha
 
MULTIPLE CHOICE QUESTIONS WITH ANSWERS ON NETWORK MANAGEMENT SYSTEMS
MULTIPLE CHOICE QUESTIONS WITH ANSWERS ON NETWORK MANAGEMENT SYSTEMSMULTIPLE CHOICE QUESTIONS WITH ANSWERS ON NETWORK MANAGEMENT SYSTEMS
MULTIPLE CHOICE QUESTIONS WITH ANSWERS ON NETWORK MANAGEMENT SYSTEMSvtunotesbysree
 
Resource Monitoring and management
Resource Monitoring and management  Resource Monitoring and management
Resource Monitoring and management Duressa Teshome
 
TFTP - Trivial File Transfer Protocol
TFTP - Trivial File Transfer ProtocolTFTP - Trivial File Transfer Protocol
TFTP - Trivial File Transfer ProtocolPeter R. Egli
 
Operating system 18 process creation and termination
Operating system 18 process creation and terminationOperating system 18 process creation and termination
Operating system 18 process creation and terminationVaibhav Khanna
 
13 DHCP Configuration in Linux
13 DHCP Configuration in Linux13 DHCP Configuration in Linux
13 DHCP Configuration in LinuxHameda Hurmat
 
TCP - IP Presentation
TCP - IP PresentationTCP - IP Presentation
TCP - IP PresentationHarish Chand
 
Improving of software processes
Improving of software processesImproving of software processes
Improving of software processesREHMAT ULLAH
 

Mais procurados (20)

ICMPV4
ICMPV4ICMPV4
ICMPV4
 
Cooja simple programs.ppt
Cooja simple programs.pptCooja simple programs.ppt
Cooja simple programs.ppt
 
Flow Control
Flow ControlFlow Control
Flow Control
 
Waterfall Model (Software Engineering)
Waterfall Model (Software Engineering)  Waterfall Model (Software Engineering)
Waterfall Model (Software Engineering)
 
Transport layer protocols : Simple Protocol , Stop and Wait Protocol , Go-Bac...
Transport layer protocols : Simple Protocol , Stop and Wait Protocol , Go-Bac...Transport layer protocols : Simple Protocol , Stop and Wait Protocol , Go-Bac...
Transport layer protocols : Simple Protocol , Stop and Wait Protocol , Go-Bac...
 
Tutorial ns 3-tutorial-slides
Tutorial ns 3-tutorial-slidesTutorial ns 3-tutorial-slides
Tutorial ns 3-tutorial-slides
 
Np unit2
Np unit2Np unit2
Np unit2
 
Java rmi example program with code
Java rmi example program with codeJava rmi example program with code
Java rmi example program with code
 
MULTIPLE CHOICE QUESTIONS WITH ANSWERS ON NETWORK MANAGEMENT SYSTEMS
MULTIPLE CHOICE QUESTIONS WITH ANSWERS ON NETWORK MANAGEMENT SYSTEMSMULTIPLE CHOICE QUESTIONS WITH ANSWERS ON NETWORK MANAGEMENT SYSTEMS
MULTIPLE CHOICE QUESTIONS WITH ANSWERS ON NETWORK MANAGEMENT SYSTEMS
 
Resource Monitoring and management
Resource Monitoring and management  Resource Monitoring and management
Resource Monitoring and management
 
Os Question Bank
Os Question BankOs Question Bank
Os Question Bank
 
TFTP - Trivial File Transfer Protocol
TFTP - Trivial File Transfer ProtocolTFTP - Trivial File Transfer Protocol
TFTP - Trivial File Transfer Protocol
 
Operating system 18 process creation and termination
Operating system 18 process creation and terminationOperating system 18 process creation and termination
Operating system 18 process creation and termination
 
DHCP & DNS
DHCP & DNSDHCP & DNS
DHCP & DNS
 
Socket programming
Socket programmingSocket programming
Socket programming
 
Making Linux do Hard Real-time
Making Linux do Hard Real-timeMaking Linux do Hard Real-time
Making Linux do Hard Real-time
 
13 DHCP Configuration in Linux
13 DHCP Configuration in Linux13 DHCP Configuration in Linux
13 DHCP Configuration in Linux
 
TCP - IP Presentation
TCP - IP PresentationTCP - IP Presentation
TCP - IP Presentation
 
Snmp
SnmpSnmp
Snmp
 
Improving of software processes
Improving of software processesImproving of software processes
Improving of software processes
 

Destaque

Tuula Sjöstedt: Kestävän kaivostoiminnan verkosto
Tuula Sjöstedt: Kestävän kaivostoiminnan verkostoTuula Sjöstedt: Kestävän kaivostoiminnan verkosto
Tuula Sjöstedt: Kestävän kaivostoiminnan verkostoSitra / Ekologinen kestävyys
 
Servletarchitecture,lifecycle,get,post
Servletarchitecture,lifecycle,get,postServletarchitecture,lifecycle,get,post
Servletarchitecture,lifecycle,get,postvamsitricks
 
Fredrik Ek 31.10.2012: Maatilojen sähkön ja lämmön yhteistuotantoratkaisut bi...
Fredrik Ek 31.10.2012: Maatilojen sähkön ja lämmön yhteistuotantoratkaisut bi...Fredrik Ek 31.10.2012: Maatilojen sähkön ja lämmön yhteistuotantoratkaisut bi...
Fredrik Ek 31.10.2012: Maatilojen sähkön ja lämmön yhteistuotantoratkaisut bi...Sitra / Ekologinen kestävyys
 

Destaque (6)

Unit 4
Unit 4Unit 4
Unit 4
 
Tuula Sjöstedt: Kestävän kaivostoiminnan verkosto
Tuula Sjöstedt: Kestävän kaivostoiminnan verkostoTuula Sjöstedt: Kestävän kaivostoiminnan verkosto
Tuula Sjöstedt: Kestävän kaivostoiminnan verkosto
 
Unit 5
Unit 5Unit 5
Unit 5
 
Servletarchitecture,lifecycle,get,post
Servletarchitecture,lifecycle,get,postServletarchitecture,lifecycle,get,post
Servletarchitecture,lifecycle,get,post
 
Np unit1
Np unit1Np unit1
Np unit1
 
Fredrik Ek 31.10.2012: Maatilojen sähkön ja lämmön yhteistuotantoratkaisut bi...
Fredrik Ek 31.10.2012: Maatilojen sähkön ja lämmön yhteistuotantoratkaisut bi...Fredrik Ek 31.10.2012: Maatilojen sähkön ja lämmön yhteistuotantoratkaisut bi...
Fredrik Ek 31.10.2012: Maatilojen sähkön ja lämmön yhteistuotantoratkaisut bi...
 

Semelhante a Np unit iv ii

Byte Ordering - Unit 2.pptx
Byte Ordering - Unit 2.pptxByte Ordering - Unit 2.pptx
Byte Ordering - Unit 2.pptxRockyBhai46825
 
Socket programming using C
Socket programming using CSocket programming using C
Socket programming using CAjit Nayak
 
Socket网络编程
Socket网络编程Socket网络编程
Socket网络编程qhm123
 
Kernel Recipes 2014 - NDIV: a low overhead network traffic diverter
Kernel Recipes 2014 - NDIV: a low overhead network traffic diverterKernel Recipes 2014 - NDIV: a low overhead network traffic diverter
Kernel Recipes 2014 - NDIV: a low overhead network traffic diverterAnne Nicolas
 
1.1.2 - Concept of Network and TCP_IP Model (2).pptx
1.1.2 - Concept of Network and TCP_IP Model (2).pptx1.1.2 - Concept of Network and TCP_IP Model (2).pptx
1.1.2 - Concept of Network and TCP_IP Model (2).pptxVINAYTANWAR18
 
NAT 64 FPGA Implementation
NAT 64 FPGA ImplementationNAT 64 FPGA Implementation
NAT 64 FPGA ImplementationJanith Rukman
 
CN_UNIT4.ppt ytutuim jykhjl fjghkhj gjjj
CN_UNIT4.ppt ytutuim jykhjl fjghkhj gjjjCN_UNIT4.ppt ytutuim jykhjl fjghkhj gjjj
CN_UNIT4.ppt ytutuim jykhjl fjghkhj gjjjPRADEEPERUKULLA2
 
Protecting the Privacy of the Network – Using P4 to Prototype and Extend Netw...
Protecting the Privacy of the Network – Using P4 to Prototype and Extend Netw...Protecting the Privacy of the Network – Using P4 to Prototype and Extend Netw...
Protecting the Privacy of the Network – Using P4 to Prototype and Extend Netw...Open-NFP
 
CN_UNIT4.ppt notre knxckvj bjbDJKVHFL jb
CN_UNIT4.ppt notre knxckvj bjbDJKVHFL jbCN_UNIT4.ppt notre knxckvj bjbDJKVHFL jb
CN_UNIT4.ppt notre knxckvj bjbDJKVHFL jbPRADEEPERUKULLA2
 
Socket Programming
Socket ProgrammingSocket Programming
Socket ProgrammingCEC Landran
 
Introduction to sockets tcp ip protocol.ppt
Introduction to sockets tcp ip protocol.pptIntroduction to sockets tcp ip protocol.ppt
Introduction to sockets tcp ip protocol.pptMajedAboubennah
 
TCPIP SLIDES.ppt
TCPIP SLIDES.pptTCPIP SLIDES.ppt
TCPIP SLIDES.pptaymenshykh
 
CCNA (R & S) Module 01 - Introduction to Networks - Chapter 9
CCNA (R & S) Module 01 - Introduction to Networks - Chapter 9CCNA (R & S) Module 01 - Introduction to Networks - Chapter 9
CCNA (R & S) Module 01 - Introduction to Networks - Chapter 9Waqas Ahmed Nawaz
 

Semelhante a Np unit iv ii (20)

Byte Ordering - Unit 2.pptx
Byte Ordering - Unit 2.pptxByte Ordering - Unit 2.pptx
Byte Ordering - Unit 2.pptx
 
Socket programming using C
Socket programming using CSocket programming using C
Socket programming using C
 
Socket网络编程
Socket网络编程Socket网络编程
Socket网络编程
 
Kernel Recipes 2014 - NDIV: a low overhead network traffic diverter
Kernel Recipes 2014 - NDIV: a low overhead network traffic diverterKernel Recipes 2014 - NDIV: a low overhead network traffic diverter
Kernel Recipes 2014 - NDIV: a low overhead network traffic diverter
 
1.1.2 - Concept of Network and TCP_IP Model (2).pptx
1.1.2 - Concept of Network and TCP_IP Model (2).pptx1.1.2 - Concept of Network and TCP_IP Model (2).pptx
1.1.2 - Concept of Network and TCP_IP Model (2).pptx
 
NAT 64 FPGA Implementation
NAT 64 FPGA ImplementationNAT 64 FPGA Implementation
NAT 64 FPGA Implementation
 
QSpiders - Upper layer-protocols
QSpiders - Upper layer-protocolsQSpiders - Upper layer-protocols
QSpiders - Upper layer-protocols
 
CN_UNIT4.ppt ytutuim jykhjl fjghkhj gjjj
CN_UNIT4.ppt ytutuim jykhjl fjghkhj gjjjCN_UNIT4.ppt ytutuim jykhjl fjghkhj gjjj
CN_UNIT4.ppt ytutuim jykhjl fjghkhj gjjj
 
Elementary TCP Sockets
Elementary TCP SocketsElementary TCP Sockets
Elementary TCP Sockets
 
Network Programming Assignment Help
Network Programming Assignment HelpNetwork Programming Assignment Help
Network Programming Assignment Help
 
Protecting the Privacy of the Network – Using P4 to Prototype and Extend Netw...
Protecting the Privacy of the Network – Using P4 to Prototype and Extend Netw...Protecting the Privacy of the Network – Using P4 to Prototype and Extend Netw...
Protecting the Privacy of the Network – Using P4 to Prototype and Extend Netw...
 
CN_UNIT4.ppt notre knxckvj bjbDJKVHFL jb
CN_UNIT4.ppt notre knxckvj bjbDJKVHFL jbCN_UNIT4.ppt notre knxckvj bjbDJKVHFL jb
CN_UNIT4.ppt notre knxckvj bjbDJKVHFL jb
 
User Datagram Protocol
User Datagram ProtocolUser Datagram Protocol
User Datagram Protocol
 
Dropped image 170
Dropped image 170Dropped image 170
Dropped image 170
 
Socket Programming
Socket ProgrammingSocket Programming
Socket Programming
 
Introduction to sockets tcp ip protocol.ppt
Introduction to sockets tcp ip protocol.pptIntroduction to sockets tcp ip protocol.ppt
Introduction to sockets tcp ip protocol.ppt
 
TCPIP SLIDES.ppt
TCPIP SLIDES.pptTCPIP SLIDES.ppt
TCPIP SLIDES.ppt
 
CCNA (R & S) Module 01 - Introduction to Networks - Chapter 9
CCNA (R & S) Module 01 - Introduction to Networks - Chapter 9CCNA (R & S) Module 01 - Introduction to Networks - Chapter 9
CCNA (R & S) Module 01 - Introduction to Networks - Chapter 9
 
L5-Sockets.pptx
L5-Sockets.pptxL5-Sockets.pptx
L5-Sockets.pptx
 
Transport layer protocol
Transport layer protocolTransport layer protocol
Transport layer protocol
 

Mais de vamsitricks (19)

Unit 6
Unit 6Unit 6
Unit 6
 
Np unit iv i
Np unit iv iNp unit iv i
Np unit iv i
 
Unit 7
Unit 7Unit 7
Unit 7
 
Npc16
Npc16Npc16
Npc16
 
Npc14
Npc14Npc14
Npc14
 
Npc13
Npc13Npc13
Npc13
 
Unit 3
Unit 3Unit 3
Unit 3
 
Unit 2
Unit 2Unit 2
Unit 2
 
Unit 7
Unit 7Unit 7
Unit 7
 
Unit 6
Unit 6Unit 6
Unit 6
 
Unit4wt
Unit4wtUnit4wt
Unit4wt
 
Unit3wt
Unit3wtUnit3wt
Unit3wt
 
Unit2wt
Unit2wtUnit2wt
Unit2wt
 
Unit 1wt
Unit 1wtUnit 1wt
Unit 1wt
 
Jsp with mvc
Jsp with mvcJsp with mvc
Jsp with mvc
 
Cookies
CookiesCookies
Cookies
 
Servletarchitecture,lifecycle,get,post
Servletarchitecture,lifecycle,get,postServletarchitecture,lifecycle,get,post
Servletarchitecture,lifecycle,get,post
 
Javabeans
JavabeansJavabeans
Javabeans
 
Javabeanproperties
JavabeanpropertiesJavabeanproperties
Javabeanproperties
 

Np unit iv ii

  • 2. abstraction • Introduction • getsockopt and setsockopt function • socket state • Generic socket option • IPv4 socket option • ICMPv6 socket option • IPv6 socket option • TCP socket option
  • 3. 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
  • 4. 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.
  • 5. 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
  • 6. SO_KEEPALIVE • SO_KEEPALIVE=> • When the keep-alive option is set for a TCP socket and no data has been exchanged across the socket in either direction for two hours, TCP automatically sends a keep- alive probe to the peer. • 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…
  • 7. 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.
  • 8. SO_LINGER client server write data Close Data queued by TCP FIN close returns Ack of data and FIN Application reads queued data and FIN FIN close Ack of data and FIN Default operation of close:it returns immediately
  • 9. SO_LINGER client server write data Close Data queued by TCP FIN Ack of data and FIN close returns Application reads queued data and FIN FIN close Ack of data and FIN Close with SO_LINGER socket option set and l_linger a positive value
  • 10. SO_LINGER client server write data Shutdown Data queued by TCP FIN read block Ack of data and FIN Application reads queued data and FIN FIN close read returns 0 Ack of data and FIN Using shutdown to know that peer has received our data
  • 11. • A 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
  • 12.
  • 13.
  • 14. 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
  • 15. 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.
  • 16. SO_RCVTIMEO, SO_SNDTIMEO • allow us to place a timeout on socket receives and sends. • Default disabled
  • 17. 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
  • 18. SO_TYPE • Return the socket type. • Returned value is such as SOCK_STREAM, SOCK_DGRAM...
  • 19. 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.
  • 20. IPv4 socket option • Level => IPPROTO_IP • IP_HDRINCL => If this option is set for a raw IP socket, we must build our IP header for all the datagrams that we send on the raw socket.(chapter 26)
  • 21. When this option is set, we build a complete IP header, with the following exception: • IP always calculates and stores the IP header checksum. • If we set the IP identification field to 0, the kernel will set the field. • If the source IP address is INADDR_ANY, IP sets it to the primary IP address of the outgoing interface. • Setting IP options is implementation-dependent. Some implementations take any IP options that were set using the IP_OPTIONS socket option and append these to the header that we build, while others require our header to also contain any desired IP options. • Some fields must be in host byte order, and some in network byte order. This is implementation-dependent, which makes writing raw packets with IP_HDRINCL not as portable as we'd like.
  • 22. • IP_OPTIONS=>allows us to set IP option in IPv4 header.(chapter 24) • IP_RECVDSTADDR=>This socket option causes the destination IP address of a received UDP datagram to be returned as additional data by recvmsg.(chapter20)
  • 23. IP_RECVIF • Cause the index of the interface on which a UDP datagram is received to be returned as ancillary data by recvmsg.(chapter20)
  • 24. IP_TOS • lets us set the type-of-service(TOS) field in IP header for a TCP or UDP socket. • If we call getsockopt for this option, the current value that would be placed into the TOS(type of service) field in the IP header is returned.(figure A.1)
  • 25. IP_TTL • We can set and fetch the default TTL(time to live field)for unicast. • With this option, we can set and fetch the default TTL that the system will use for unicast packets sent on a given socket. (The multicast TTL is set using the IP_MULTICAST_TTL socket option)
  • 26. ICMPv6 socket option • This socket option is processed by ICMPv6 and has a level of IPPROTO_ICMPV6. • ICMP6_FILTER =>lets us fetch and set an icmp6_filter structure that specifies which of the 256possible ICMPv6 message types are passed to the process on a raw socket.(chapter 25)
  • 27. IPv6 socket option • This socket option is processed by IPv6 and have a level of IPPROTO_IPV6. • IPV6_ADDRFORM=>allow a socket to be converted from IPv4 to IPv6 or vice versa. (chapter 10) • IPV6_CHECKSUM=>specifies the byte offset into the user data of where the checksum field is located.
  • 28. IPV6_DSTOPTS • Specifies that any received IPv6 destination options are to be returned as ancillary data by recvmsg.
  • 29. IPV6_HOPLIMIT • Setting this option specifies that the received hop limit field be returned as ancillary data by recvmsg.(chapter 20) • Default off.
  • 30. IPV6_HOPOPTS • Setting this option specifies that any received IPv6 hop-by-hop option are to be returned as ancillary data by recvmsg.(chapter 24)
  • 31. IPV6_NEXTHOP • This is not a socket option but the type of an ancillary data object that can be specified to sendmsg. This object specifies the next-hop address for a datagram as a socket address structure.(chapter20)
  • 32. IPV6_PKTINFO • Setting this option specifies that the following two pieces of infoemation about a received IPv6 datagram are to be returned as ancillary data by recvmsg:the destination IPv6 address and the arriving interface index.(chapter 20)
  • 33. IPV6_PKTOPTIONS • Most of the IPv6 socket options assume a UDP socket with the information being passed between the kernel and the application using ancillary data with recvmsg and sendmsg. • A TCP socket fetch and store these values using IPV6_ PKTOPTIONS socket option.
  • 34. IPV6_RTHDR • Setting this option specifies that a received IPv6 routing header is to be returned as ancillary data by recvmsg.(chapter 24) • Default off
  • 35. IPV6_UNICAST_HOPS • This is similar to the IPv4 IP_TTL. • Specifies the default hop limit for outgoing datagram sent on the socket, while fetching the socket option returns the value for the hop limit that the kernel will use for the socket.
  • 36. TCP socket option • There are five socket option for TCP, but three are new with Posix.1g and not widely supported. • Specify the level as IPPROTO_TCP.
  • 37. TCP_KEEPALIVE • This is new with Posix.1g • It specifies the idle time in second for the connection before TCP starts sending keepalive probe. • Default 2hours • this option is effective only when the SO_KEEPALIVE socket option enabled.
  • 38. TCP_MAXRT • This is new with Posix.1g. • It specifies the amount of time in seconds before a connection is broken once TCP starts retransmitting data. – 0 : use default – -1:retransmit forever – positive value:rounded up to next transmission time
  • 39. TCP_MAXSEG • This allows us to fetch or set the maximum segment size(MSS) for TCP connection.
  • 40. TCP_NODELAY • This option disables TCP’s Nagle algorithm. (default this algorithm enabled) • purpose of the Nagle algorithm. ==>prevent a connection from having multiple small packets outstanding at any time. • Small packet => any packet smaller than MSS.
  • 41. Nagle algorithm • Default enabled. • Reduce the number of small packet on the WAN. • If given connection has outstanding data , then no small packet data will be sent on connection until the existing data is acknowledged.
  • 42. Nagle algorithm disabled Nagle algorithm disabled h 0 e 250 l 500 l 750 o 1000 ! 1250 1500 1500 1750 2000
  • 43. Nagle algorithm enabled h h 0 e 250 l 500 el l 750 o 1000 ! 1250 lo 1500 1500 1750 ! 2000 2250 2500