|
>Can I a DNS lookup inside an RPGLE or CL program????
>
>Mark Allen
>IS Manager
>Kelly's Kids
>markallen@kellyskids.com
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
Bryan Dietz
+---
| This is the Midrange System Mailing List!
| To submit a new message, send your mail to MIDRANGE-L@midrange.com.
| To subscribe to this list send email to MIDRANGE-L-SUB@midrange.com.
| To unsubscribe from this list send email to MIDRANGE-L-UNSUB@midrange.com.
| Questions should be directed to the list owner/operator: david@midrange.com
+---
As an Amazon Associate we earn from qualifying purchases.
This mailing list archive is Copyright 1997-2025 by midrange.com and David Gibbs as a compilation work. Use of the archive is restricted to research of a business or technical nature. Any other uses are prohibited. Full details are available on our policy page. If you have questions about this, please contact [javascript protected email address].
Operating expenses for this site are earned using the Amazon Associate program and Google Adsense.