APIs by Example: TCP/IP Management APIs

Article ID: 17099

This week's API by Example from Carsten Flensburg provides program CBX105, which showcases three TCP/IP management APIs: Retrieve TCP/IP attributes (QtocRtvTCPA), List Network Connections (QtocLstNetCnn), and List Network Connection Data (QtocRtvNetCnnDta). CBX105 retrieves a list of current TCP/IP network connections, then retrieves information for each connection and prints it out to a report. The program also retrieves and prints a line for each servicing job associated with each network connection.

The earliest OS/400 release CBX105 runs on is V5R1. There were problems with the QtocRtvNetCnnDta API that have been fixed with the following PTFs:

VR51 SI09122
VR52 SI09175

Here's a truncated sample output from CBX105:

= = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =

8/12/03  22:01:57    Print TCP/IP connection status       Program: CBX105

Remote address - Port  Local address - Port Type Open State  Idle time ms

0.0.0.0             0  0.0.0.0         8479 *TCP PSV   LST     2812890470
  Connection job name: QNPSERVD   - user: QUSER     - number: 009342

206.71.122.180   1392  10.2.0.162        21 *TCP PSV   FIN2        121712
206.71.122.180   2740  10.2.0.162        23 *TCP PSV   EST          13668
  Connection job name: QPADEV0006 - user: DEVLUNDC  - number: 010092
  Connection job name: QTVDEVICE  - user: QTCP      - number: 009324

= = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =

Note that the bytes in and bytes out columns are not showing above, as the e-mail format is too narrow to show it.

Here's a list of the APIs and functions used in the program:

Retrieve TCP/IP Attributes (QtocRtvTCPA)
This API retrieves TCP/IPv4 and TCP/IPv6 stack attributes.
http://publib.boulder.ibm.com/iseries/v5r2/ic2924/info/apis/qtocrtvtcpa.htm

List Network Connections (QtocLstNetCnn)
This API returns a non-detailed list of all network connections or a subset of all network connections for a specified network connection type.
http://publib.boulder.ibm.com/iseries/v5r2/ic2924/info/apis/qtoclstnetcnn.htm

List Network Connection Data (QtocRtvNetCnnDta)
The QtocRtvNetCnnDta API retrieves detailed information about a specified IPv4 or IPv6 network connection -- including jobs using the connection.
http://publib.boulder.ibm.com/iseries/v5r2/ic2924/info/apis/qtocrtvnetcnndta.htm

List Fields (QUSLFLD)
This API generates a list of fields within a specified file record format name and places the list in a specified user space. You can use the QUSLFLD API only with database file types, such as *PF, *LF, and *DDMF, and device file types, such as *ICFF and *PRTF.
http://publib.boulder.ibm.com/iseries/v5r2/ic2924/info/apis/quslfld.htm

Create User Space (QUSCRTUS)
This API creates a user space in either the user domain or the system domain.
http://publib.boulder.ibm.com/iseries/v5r2/ic2924/info/apis/quscrtus.htm

Retrieve Pointer to User Space (QUSPTRUS)
QUSPTRUS retrieves a pointer to the contents of a user-domain user space.
http://publib.boulder.ibm.com/iseries/v5r2/ic2924/info/apis/qusptrus.htm

Delete User Space (QUSDLTUS)
This API deletes user spaces created with the Create User Space (QUSCRTUS) API.
http://publib.boulder.ibm.com/iseries/v5r2/ic2924/info/apis/qusdltus.htm

You can obtain the RPG IV sample program CBX105 at
http://www.iseriesnetwork.com/noderesources/code/clubtechcode/TCPIPManageAPIs.zip.

API QtocLstNetCnn was also mentioned in a previous newsletter item that described Bryan Dietz's free utility NStat, which uses QtocLstNetCnn. Details on the utility and how to obtain the source are available at http://www.iseriesnetwork.com/article.cfm?ID=15777.

The above source code was written by Carsten Flensburg. For questions regarding this tip, contact Carsten at mailto:flensburg@novasol.dk.

ProVIP Sponsors

ProVIP Sponsors