Previous topic |
Next topic |
Contents |
Contact z/OS |
Library |
PDF
Ports z/OS Communications Server: IP Sockets Application Programming Interface Guide and Reference SC27-3660-00 |
|
A port is used to differentiate among different applications using the same network interface. It is an additional qualifier used by the system software to get data to the correct application. Physically, a port is a 16-bit integer. Some ports are reserved for particular applications; they are labeled as well-known ports. In the client/server model, the server provides a resource by listening
for clients on a particular port. Some applications, such as FTP,
SMTP, and Telnet, are standardized protocols and listen on a well-known
port. Such standardized applications use the same port number on all
TCP/IP hosts. For your client/server applications, however, you need
a way to assign port numbers to represent the services you intend
to provide. An easy way to define services and their ports is to enter
them into data set hlq.ETC.SERVICES. In C, the programmer uses the getservbyname() function
to determine the port for a particular service. Should the port number
for a particular service change, only the hlq.ETC.SERVICES
data set needs to be modified.
Note: Note that hlq is the
high-level qualifier. z/OS® Communications
Server ships with a default hlq of TCPIP. Use this
default or override it using the DATASETPREFIX statement in the PROFILE.TCPIP
and TCPIP.DATA configuration files. TCP/IP is
shipped with data set hlq.ETC.SERVICES
that contains the well-known services of FTP, SMTP, and Telnet. Data
set hlq.ETC.SERVICES
is described in the z/OS Communications Server: IP Configuration
Reference.
A socket program in an IP host identifies itself to the underlying TCP/IP protocol layers by port number. A port number is a 16-bit integer ranging from 0 to 65535. A port number uniquely identifies this application to the protocol underlying this TCP/IP host (TCP, UDP, or IP). Other applications in the TCP/IP network can contact this application by way of reference to the port number on this specific IP host. Figure 1 shows the port
concept.
Figure 1. The port concept
Both server applications and client applications have port numbers. A server application uses a specific port number to uniquely identify this server application. The port number can be reserved to a particular server, so no other process ever uses it. In an IBM® TCP/IP Services environment, you can do this using the PORT statement in the hlq.PROFILE.TCP/IP configuration data set. When the server application initializes, it uses the bind() socket call to identify its port number. A client application must know the port number of a server application in order to contact it. Because advance knowledge of the client's port number is not needed, a client often leaves it to TCP/IP to assign a free port number when the client issues the connect() socket call to connect to a server. Such a port number is called an ephemeral port number; this means it is a port number with a short life. The selected port number is assigned to the client for the duration of the connection, and is then made available to other processes. It is the responsibility of the TCP/IP software to ensure that a port number is assigned to only one process at a time. Well-known official Internet port numbers are in the range of 0 - 255. See http://www.iana.org/assignments/multicast-addresses for details. In addition, port numbers in the range of 256 - 1023 are reserved for other well-known services. Port numbers in the range of 1024 - 65535, which are neither in-use nor reserved, are used when TCP/IP automatically assigns port numbers to client programs that do not use specific port numbers. Figure 2 shows port
number assignments.
Figure 2. Port
number assignments
Before you select a port number for your server application, consult the hlq.ETC.SERVICES data set. This data set is used to assign port numbers to server applications. The server application can use socket call getservbyname() to retrieve the port number assigned to a given server name. Add the names of your server applications to this data set and use socket call getservbyname(). With this technique, you avoid hard coding the port number into your server program. The client program must know the port number of the server on the server host. There is no socket call to obtain that information from the server host. To compensate, synchronize the contents of data sets ETC.SERVICES on all TCP/IP hosts in your network. Client application can then use the getservbyname() socket call to query its local ETC.SERVICES data set for the port number of the server. Use this technique to develop your own local well-known services. |
Copyright IBM Corporation 1990, 2014
|