Tivoli NetView for z/OS, Version 5.4

CNMIPXLATE Examples: Conversion of Binary to Presentation Form

You can use the CNMIPXLATE macro to convert an IP address in binary to a presentation form.

The binary (network byte order) IP address that is passed must be either 4 bytes in length (indicating an IPv4 address) or 16 bytes in length (indicating an IPv6, IPv4-mapped, or IPv4-compatible address). Any length value other than these two is invalid input to the CNMIPXL macro, meaning that the HLBRC field has a non-zero value and no conversion occurs.

If the binary (network byte order) IP address is valid, but the output area is not large enough to hold the presentation form result, then CNMIPXL fills the output area with what can be placed there, the HLBRC field has a value of 40 (CNM_DATA_TRUNC), and the HLBLENG field contains the actual length that is required to hold the presentation form of the IP address.

CNMIPXLATE Example 1: Conversion of Binary to Presentation Form

The following example requests the conversion of a binary (network byte order) IP address to the standard presentation form. Upon completion, outData contains a presentation form dotted decimal IP address, namely "10.163.17.1", the HLBLENG field has a value of 11, and the HLBRC field has a value of 0.

DCL pInData PTR;
DCL lenInData FIXED BINARY(31,0);
DCL BIN_IPV4 CHAR(4) INIT('0AA31101'X);
DCL charOut CHAR(45);         /* Room for the maximum size presentation form  */
DCL pOutData PTR;
DCL lenOutData FIXED BINARY(31,0);

pInData = ADDR(BIN_IPV4);
lenInData = LENGTH(BIN_IPV4);
pOutData = ADDR(charOut);
lenOutData = LENGTH(charOut);

/* Request conversion of a binary (network byte order) IP address to the      */
/* standard presentation form (N2PSTD).  If successful, the charOut field     */
/* contains a string that represents the IP address.  Because the input       */
/* binary IP address is a 4-byte value, it must be an IPv4 address and,       */
/* therefore, the presentation form should be dotted decimal.                 */

CNMIPXLATE TYPE(N2PSTD)
           INDATA(pInData)
           INLEN(lenInData)
           OUTDATA(pOutData)
           OUTLEN(lenOutData);

CNMIPXLATE Example 2: Conversion of Binary to Presentation Form

The following example requests the conversion of an IPv6 address. Upon completion, outData contains "4BBE:4DB5:0:0:FOCA:530F:1049:4AC", the HLBLENG field has a value of 32, and the HLBRC field has a value of 0. Note that the standard form ensures that leading zeros are removed.

DCL BIN_IPV6 CHAR(16) INIT('4BBE4DB500000000F0CA530F104904AC'X);

pInData = ADDR(BIN_IPV6);
lenInData = LENGTH(BIN_IPV6);

/* Request conversion of a binary (network byte order) IP address to the      */
/* standard presentation form (N2PSTD).  If successful, the charOut field     */
/* contains a string that represents the IP address.  Because the input       */
/* binary IP address is a 16-byte value that does not contain the special     */
/* values for IPv4-mapped or IPv4-compatible IPv6 addresses, it must be an    */
/* IPv6 address and, therefore, the presentation form should be colon-hex.    */

CNMIPXLATE TYPE(N2PSTD)
           INDATA(pInData)
           INLEN(lenInData)
           OUTDATA(pOutData)
           OUTLEN(lenOutData);

CNMIPXLATE Example 3: Conversion of Binary to Presentation Form

Suppose that the function call requests a compressed presentation form, as in the following example. Upon completion, outData contains "4BBE:4DB5::F0CA:530F:1049:4AC", the HLBLENG field has a value of 29, and the HLBRC field has a value of 0. Note that the double-colon (::) indicates the compression of multiple groups of zeros in the IPv6 address.

CNMIPXLATE TYPE(N2PCOMP)
           INDATA(pInData)
           INLEN(lenInData)
           OUTDATA(pOutData)
           OUTLEN(lenOutData);

CNMIPXLATE Example 4: Conversion of Binary to Presentation Form

Suppose that the binary IP address to be converted is an IPv4-mapped IPv6 address.

DCL BIN_IPV6 CHAR(16) INIT('00000000000000000000FFFF0AA31101'X);

Suppose that you pass that binary IP address and use the N2PSTD function call, as in the following example. Upon completion, outData contains "10.163.17.1", the HLBLENG field has a value of 11, and the HLBRC field has a value of 0. This is because the IPv4-mapped IPv6 address is essentially an IPv4 address and the standard presentation form of an IPv4 address is a string that represents dotted decimal.

CNMIPXLATE TYPE(N2PSTD)
           INDATA(pInData)
           INLEN(lenInData)
           OUTDATA(pOutData)
           OUTLEN(lenOutData);



Feedback

[ Top of Page | Previous Page | Next Page | Contents ]