
Return to the EMail Tips
Validating email addresses
Question: Can I a DNS lookup inside an RPGLE or CL program?
Yes you can. The following code does it the reverse way, finding the host name for a given IP address.
You could change the gethostbyaddr() function to gethostbynam() and make the needed changes.
PGM PARM(&IP)
DCL VAR(&IP) TYPE(*CHAR) LEN(15)
DCL VAR(&HOST) TYPE(*CHAR) LEN(64)
CALL PGM(GETHOST1) PARM(&IP &HOST)
SNDPGMMSG MSG('The host name for TCP/IP address ' || +
&IP *BCAT 'is ' || &HOST)
ENDPGM
*===================================================================
* Bryan Dietz Some of the code borrowed from others
*
* 3X Corp.
*
* bdietz@3x.com
*
*==================================================================*
hdebug dftactgrp( *no ) bnddir( 'QC2LE' )
Dinet_addr PR 10U 0 ExtProc('inet_addr')
D IPAddr * Value
DGetHostByAddr PR * ExtProc('gethostbyaddr')
D HostEnt * Value
D AddrLen 5I 0 Value
D AddrType 5I 0 Value
DSysInfDS SDS
D CurDevice 244 253
DRcvVar DS
D Protocol 859 859
D IPAddress 878 892
DRcvLen S 9B 0
DFormat S 8
DDevice S 10
DIPAddr S *
DHostEnt S *
DHostAddr S *
DAddrLen S 5I 0
DAddrType S 5I 0
DHostEntS DS Based(HostEntP)
D HostNPtr *
DHostName S 64 Based(HostNameP)
DHostAddrS DS Based(HostAddrP)
D IP32Addr 10U 0
DAF_INET S 5I 0 Inz(2)
DSpaces S 64 Inz(*Blanks)
DAPIError DS
D NbrBytes 1 4B 0 Inz(15)
D CPFID 9 15
*****************************************************************
C *Entry PList
C Parm P#IPAddress 15
C Parm P#IPName 64
* Get IP-name
c Eval IPAddress = P#IPAddress
C Eval HostEntP = %Addr(HostEnt)
C Eval HostAddrP = %Addr(HostAddr)
C Eval IP32Addr = inet_addr(%Addr(IPAddress))
C Eval AddrLen = %Size(HostAddrS)
C Eval AddrType = AF_INET
C Eval HostEntP = GetHostByAddr(HostAddrP:
C AddrLen:
C AddrType)
C HostEntP IfEq *NULL
C Eval P#IPName = Spaces
C Else
C Eval HostNameP = HostNPtr
C Eval P#IPName = HostName
C X'00':X'40' XLate P#IPName P#IPName
C EndIf
* Return parameters
C Eval P#IPAddress = IPAddress
C SetOn Lr
C Return
[report a broken link by clicking here]






