Docsity

Socket Options - Advanced Unix Programming - Lecture Slides, Slides of Computer Programming

Partial preview of the text

Download Socket Options - Advanced Unix Programming - Lecture Slides and more Slides Computer Programming in PDF only on Docsity!

Week 9 Topics

• Socket options

  • getsockopt, setsockopt
  • fcntl
  • ioctl

• Introduction to UDP

  • TCP vs UDP
  • UDP interface

Socket options

• getsockopt, setsockopt

  • General socket options
  • IP options
  • TCP options

• fcntl

• ioctl

General socket options

  • level = SOL_SOCKET, optnames =

– SO_BROADCAST

  • Permit sending broadcast datagram
  • SO_KEEPALIVE
  • For TCP only, automatically send a keepalive message when inactive for 2 hours (can be modified)
  • SO_LINGER
  • for TCP only, determines behavior on close
  • SO_RCVBUF, SO_SNDBUF
  • Send and receive buffer size

General socket options (continued)

  • level = SOL_SOCKET, optnames =
    • SO_RCVLOWAT, SO_SENDLOWAT
      • low watermark – affects the select system call
    • SO_RCVTIMEO, SO_SNDTIMEO
      • Inherent timeout time (disabled by default)
    • SO_TYPE
      • Socket type: SOCK_STREAM and SOCK_DGRAM
    • Etc.

TCP options

  • level = IPPROTO_TCP, optname =
    • TCP_KEEPALIVE
      • Set the time
    • TCP_MAXRT
      • Maximum retransmission time
    • TCP_MAXSEG
      • Maximum segment size
  • See example1.c

fcntl and ioctl

• fcntl

  • File control on open files
    • Set file descriptor flags (FD_CLOEXEC)
    • Non-blocking mode, etc.

• ioctl

  • Some I/O control operations