UNIX Network Programming 2nd Edition - PowerPoint PPT Presentation

1 / 32
About This Presentation
Title:

UNIX Network Programming 2nd Edition

Description:

UNIX Network Programming 2nd Edition Chapter 1. Introduction Contents Introduction A Simple Daytime Client Error Handling: Wrapper Functions A Simple Daytime Server ... – PowerPoint PPT presentation

Number of Views:77
Avg rating:3.0/5.0
Slides: 33
Provided by: sna1
Category:

less

Transcript and Presenter's Notes

Title: UNIX Network Programming 2nd Edition


1
UNIX Network Programming2nd Edition
2
Chapter 1. Introduction
  • Contents
  • Introduction
  • A Simple Daytime Client
  • Error Handling Wrapper Functions
  • A Simple Daytime Server
  • OSI Model
  • Unix Standards

3
1.1 Introduction
  • Client / Server

4
1.1 Introduction (continued)
  • Example Client and Server on the same Ethernet
    communication using TCP

5
1.1 Introduction (continued)
  • Example Client and Server on different LANs
    connected through WAN.

6
1.2 A Simple Daytime Client
  • include unp.h
  • int
  • main (int argc, char argv)
  • int sockfd, n
  • char recvlineMAXLINE1
  • struct sockaddr_in servaddr
  • if ( argc ! 2) err_quit(usage a.out
    ltIPaddressgt)
  • if ( (sockfd socket(AF_INET, SOCK_STREAM, 0))
    lt 0)
  • err_sys(socket error)
  • bzero( servaddr, sizeof(servaddr))
  • servaddr.sin_family AF_INET
  • servaddr.sin_port htons(13) / daytime server
    /
  • if (inet_pton(AF_INET, argv1,
    servaddr.sin_addr) lt 0)
  • err_quit(inet_pton error for s,argv1)

1
2
3
4
5
7
1.3 protocol Independence
  • include "unp.h"
  • int main(int argc, char argv)
  • int sockfd, n
  • struct sockaddr_in6 servaddr
  • char recvlineMAXLINE 1
  • if (argc ! 2) err_quit("usage a.out
    ltIPaddressgt")
  • if ( (sockfd socket(AF_INET6, SOCK_STREAM, 0))
    lt 0)

  • err_sys("socket error")
  • bzero(servaddr, sizeof(servaddr))
  • servaddr.sin6_family AF_INET6
  • servaddr.sin6_port htons(13) / daytime
    server /
  • if (inet_pton(AF_INET6, argv1,
    servaddr.sin6_addr) lt 0)
  • err_quit("inet_pton error for s", argv1)
  • if (connect(sockfd, (SA ) servaddr,
    sizeof(servaddr)) lt 0)

8
1.4 Error Handling Wrapper Functions
  • Since terminating on an error is the common case,
    we can shorten our program by defining a wrapper
    function that performs the actual function call,
    tests the return value, and terminates on an
    error.
  • sockfd Socket(AF_INET, SOCK_STREAM, 0)
  • int
  • Socket(int family, int type, int protocol)
  • int n
  • if( (n socket( family, type, protocol)) lt 0 )
  • err_sys(socket error)
  • return (n)
  • Unix errno Value

9
1.5 A Simple Daytime Server
  • include unp.h
  • include lttime.hgt
  • int
  • main(int argc, char argv)
  • int listenfd, connfd
  • struct sockaddr_in servaddr
  • char buffMAXLINE
  • time_t ticks
  • listenfd Socket(AF_INET, SOCK_STREAM, 0)
  • bzero(servaddr, sizeof(servaddr))
  • servaddr.sin_family AF_INET
  • servaddr.sin_addr.s_addr htonl(INADDR_ANY)
  • servaddr.sin_port htons(13) / daytime server
    /
  • Bind(listenfd, (SA ) servaddr,
    sizeof(servaddr) )

1
2
3
4
10
1.7 OSI Model
  • Why do both sockets and XTI provide the interface
    from the upper three layers of the OSI model into
    the transport layer?
  • First, the upper three layers handle all the
    details of the application and The lower four
    layers handle all the communication details.
  • Second, the upper three layers is called a user
    process while the lower four layers are provided
    as part of the operating system kernel.

11
1.10 Unix Standards
  • POSIX
  • Potable Operating System Interface
  • a family of standards being developed by IEEE
  • The Open Group
  • an international consortium of vendors and
    end-user customers from industry, government, and
    academia.
  • IETF (Internet Engineering Task Force)
  • a large open international community of network
    designers, operators, vendors, and researchers
    concerned with the evolution of the Internet
    architecture and the smooth operation of the
    internet.

12
Chapter 2. The Transport Layer TCP and
UDP
  • Contents
  • Introduction
  • The Big Picture
  • UDP User Datagram Protocol
  • TCP Transmission Control Protocol
  • TCP Connection Establishment and Termination
  • TIME_WAIT State
  • Port Numbers
  • TCP Port Numbers and Concurrent Servers
  • Buffer Sizes and Limitations

13
2.1 Introduction
  • Overview of the TCP / IP protocol
  • Transport layer TCP UDP

14
2.2 The Big Picture
15
2.3 UDP User Datagram Protocol
  • The application writes a datagram to a UDP
    socket, which is encapsulated as either a IPv4 of
    a IPv6 datagram, which is sent to its
    destination.
  • UDP provides a connectionless service.
  • Each UDP datagram has a length and we can
    consider a datagram as a record.
  • RFC 768Postel 1980

16
2.4 TCP Transmission Control Protocol
  • Provides connections between clients and servers.
  • Provides reliability.
  • RTT ( round-trip-time)
  • TCP also sequences the data by associating a
    sequence number with every byte that it sends.
  • TCP provides flow control.
  • window
  • A TCP connection is also full-duplex.

17
2.5 TCP Connection Establishment and Termination
  • Three-Way Handshake
  • SYN segment
  • ACK

18
TCP Header
19
Encapsulation
20
2.5 TCP Connection Establishment and Termination
(cont)
  • TCP Options
  • MSS option
  • With this option the TCP sending the SYN
    announces its maximum segment size, the maximum
    amount of data that it is willing to accept in
    each TCP segment, on this connection.
  • Window Scale option
  • Timestamp option

21
2.5 TCP Connection Establishment and Termination
(cont)
  • TCP Connection Termination
  • half-close Between steps 2 and 3 it is possible
    for data to flow from the end doing the passive
    close to the end doing active close.

22
2.5 TCP Connection Establishment and Termination
(cont)
- State transition diagram
23
2.5 TCP Connection Establishment and Termination
(cont)
  • Watching the Packets

24
2.6 TIME_WAIT State
  • The end that performs the active close is the end
    that remains in the TIME_WAIT stategtbecause that
    end is the one that might have to retransmit the
    final ACK.
  • There are two reason for TIME_WAIT state
  • to implement TCPs full-duplex connection
    termination reliably
  • to allow old duplicate segments to expire in the
    network

25
2.7 Port Numbers
26
2.8 TCP port Numbers and Concurrent Servers
27
2.8 TCP port Numbers and Concurrent Servers
28
2.9 Buffer Sizes and Limitations
  • Maximum size of IPv4 gt 65535 byte
  • Maximum size of IPv6 gt 65575 byte
  • MTU(maximum transmit unit) gt fragmentation
  • DF (dont fragment)
  • IPv4 and IPv6 define a minimum reassembly buffer
    size.
  • TCP has MSS(maximum segment size)

29
TCP output
30
UDP output
31
2.10 standard internet service
Notice TCP and UDP port number is same.
32
2.11protocol usage by common internet Application
Write a Comment
User Comments (0)
About PowerShow.com