3376c210

Lemur zaprasza


TCP/IP Tutorial and Technical Overview

RARP
Concept





2.10 Ports and Sockets

In this section we will introduce the concepts of port and
socket.

2.10.1 Ports

Each process that wants to communicate with
another process identifies itself to the TCP/IP protocol suite by one or more
ports. A port is a 16-bit number, used by the host-to-host protocol to
identify to which higher-level protocol or application program (process) it
must deliver incoming messages.

As some higher-level programs are themselves protocols, standardized in the
TCP/IP protocol suite, such as TELNET and FTP, they use the same port number in
all TCP/IP implementations. Those "assigned" port numbers
are called well-known ports and the standard
applications well-known services.

The "well-known" ports are controlled and assigned by the Internet Assigned
Numbers Authority (IANA) and on most systems can only be used by system
processes or by programs executed by privileged users. The assigned
"well-known" ports occupy port numbers in the range 0 to 1023. The ports with
numbers in the range 1024-65535 are not controlled by the IANA and on most
systems can be used by ordinary user-developed programs.

Confusion due to two different applications trying to use the same port
numbers on one host is avoided by writing those applications to request an
available port from TCP/IP. Because this port number is dynamically assigned,
it may differ from one invocation of an application to the next.

UDP, TCP and ISO TP-4 all use the same "port principle". (Please see
Figure - UDP, A Demultiplexer Based on
Ports and .) To
the extent possible, the same port numbers are used for the same services on
top of UDP, TCP and ISO TP-4.

2.10.2 Sockets

Let us first consider the following terminologies:


    lA socket is a special type of file handle which is used by a
    process to request network services from the operating system.
    lA socket address is the triple:

    {protocol, local-address, local-process}

    In the TCP/IP suite, for example:

    {tcp, 193.44.234.3, 12345}
    lA conversation is the communication link
    between two processes.
    lAn association is the 5-tuple that completely
    specifies the two processes that comprise a connection:

    {protocol, local-address, local-process, foreign-address,
    foreign-process
    }

    In the TCP/IP suite, for example:

    {tcp, 193.44.234.3, 1500, 193.44.234.5, 21}

    could be a valid association.
    lA half-association is either:

    {protocol, local-address, local-process}

    or

    {protocol, foreign-address, foreign-process}

    which specify each half of a connection.
    lThe half-association is also called a socket or a transport
    address
    . That is, a socket is an end point for
    communication that can be named and addressed in a network.


The socket interface is one of several application
programming interfaces (APIs)
to the communication protocols. Designed to
be a generic communication programming interface, it was first introduced by
the 4.2BSD UNIX system. Although it has not been standardized, it has become a
de facto industry standard.

4.2BSD allowed two different communication domains: Internet and UNIX.
4.3BSD has added the Xerox Network System (XNS) protocols and 4.4BSD will add
an extended interface to support the ISO OSI protocols.

2.10.3 Basic Socket Calls

The following lists some basic socket interface calls. In the next section
we shall see an example scenario of using these socket interface calls.


    lInitialize a socket

    FORMAT: int sockfd = socket(int family, int
    type, int protocol)

    where:


      lfamily stands for addressing family. It can take on values
      such as AF_UNIX, AF_INET, AF_NS and AF_IUCV. Its purpose is to specify the
      method of addressing used by the socket.
      ltype stands for the type of socket interface to be used. It can take
      on values such as SOCK_STREAM, SOCK_DGRAM, SOCK_RAW, and SOCK_SEQPACKET.
      lprotocol can be UDP, TCP, IP or ICMP.
      lsockfd is an integer (similar to a file descriptor) returned by the
      socket call.

    lBind (Register) a socket to a port address

    FORMAT: int bind(int sockfd, struct sockaddr
    *localaddr, int addrlen)

    where:


      lsockfd is the same integer returned by the socket call.
      llocaladdr is the local address returned by the bind call.

    Note that after the bind call, we now have values for the first three
    parameters inside our 5-tuple association:

    {protocol, local-address, local-process, foreign-address,
    foreign-process
    }
    lIndicate readiness to receive connections

    FORMAT: int listen(int sockfd, int queue-size)

    where:


      lsockfd is the same integer returned by the socket call.
      lqueue-size indicates the number of connection requests which can be
      queued by the system while the local process has not yet issued the
      accept call.

    lAccept a connection

    FORMAT: int accept(int sockfd, struct sockaddr
    *foreign-address, int addrlen)

    where:


      lsockfd is the same integer returned by the socket call.
      lforeign-address is the address of the foreign (client) process
      returned by the accept call.

    Note that this accept call is issued by a server process rather than
    a client process. If there is a connection request waiting on the queue for
    this socket connection, accept takes the first request on the queue and
    creates another socket with the same properties as sockfd; otherwise,
    accept will block the caller process until a connection request arrives.
    lRequest connection to the server

    FORMAT: int connect(int sockfd, struct sockaddr
    *foreign-address, int addrlen)

    where:


      lsockfd is the same integer returned by the socket call.
      lforeign-address is the address of the foreign (server) process
      returned by the connect call.

    Note that this call is issued by a client process rather than a server
    process.
    lSend and/or receive data

    The read(), readv(sockfd, char *buffer, int
    addrlen), recv(), readfrom(), send(sockfd, msg,
    len, flags
    ), write() calls can be used to receive and send data in
    an established socket association (or connection).

    Note that these calls are similar to the standard read and
    write file I/O system calls.
    lClose a socket

    FORMAT: int close(int sockfd)

    where:


      lsockfd is the same integer returned by the socket call.


For more details, please refer to [Stevens] and the product implementation
manuals listed in .

2.10.4 An Example Scenario

As an example, consider the socket system calls for a connection-oriented
protocol.





Figure: Socket System Calls for Connection-Oriented Protocol


Consider the previous socket system calls in terms of
specifying the elements of the association:





Figure: Socket System Calls and Association


The socket interface is differentiated by the different services that are
provided. Stream, datagram, and raw sockets each define a different service
available to applications.


    lStream socket interface (SOCK_STREAM): It
    defines a reliable connection-oriented service (over TCP for example). Data is
    sent without errors or duplication and is received in the same order as it is
    sent. Flow control is built-in to avoid data overruns. No boundaries are
    imposed on the exchanged data, which is considered to be a stream of bytes. An
    example of an application that uses stream sockets is the File Transfer Program
    (FTP).
    lDatagram socket interface (SOCK_DGRAM): It defines a
    connectionless service (over UDP for example). Datagrams
    are sent as independent packets. The service provides no guarantees; data can
    be lost or duplicated, and datagrams can arrive out of order. No disassembly
    and reassembly of packets is performed. An example of an application that uses
    datagram sockets is the Network File System (NFS).
    lRaw socket interface (SOCK_RAW): It allows direct access
    to lower-layer protocols such as IP and ICMP. This
    interface is often used for testing new protocol implementations. An example of
    an application that uses raw sockets is the Ping command.


2.10.5 Implementations

In this section we discuss how sockets are implemented in the IBM TCP/IP
products.

2.10.5.1 VM and MVS

The socket implementation in TCP/IP for VM and MVS supports two addressing
families: AF_INET, and AF_IUCV. The AF_INET domain defines
addressing in the Internet domain. The AF_IUCV domain
defines addressing in the IUCV domain. In the IUCV domain,
address spaces or virtual machines can use the socket interface to communicate
with other virtual machines or address spaces within the same operating system.
Only stream sockets are supported in the AF_IUCV domain.

In an MVS OpenEdition environment AF_UNIX sockets are also supported.

2.10.5.2 OS/2 and DOS

TCP/IP for OS/2 and TCP/IP for DOS both support the AF_INET
addressing family. They both support the Stream and Datagram socket
interfaces.

2.10.5.3 AIX

All AIX implementations support the AF_INET and AF_UNIX
addressing families.

They all support the 4.3BSD sockets and the datagram and stream socket
interfaces.

User
Datagram Protocol (UDP)

  • zanotowane.pl
  • doc.pisz.pl
  • pdf.pisz.pl
  • teen-mushing.xlx.pl
  • Wątki
    Powered by wordpress | Theme: simpletex | © Lemur zaprasza