|
Scott,
Routine working well, errors if host not found.
How do I handle this?
CPF9898 40 ESC Host not found. DNSNAME
Paul
-----Original Message-----
From: MIDRANGE-L [mailto:midrange-l-bounces@xxxxxxxxxxxx] On Behalf Of
Scott Klement
Sent: Tuesday, May 19, 2015 6:17 PM
To: Midrange Systems Technical Discussion
Subject: Re: Input IPv4 address - return DNS name
Paul,
Sorry to hear that, you're missing out!
But, in any case, unless you want to write your own DNS routines from the ground up, you're going to need to use the ones provided in the binding directory.
For RPG programs, you can still use the CRTBNDRPG (or PDM #14) option, since it has a BNDDIR() parameter. But, CRTBNDCL doesn't have this, so you have to use the two separate commands to get access to the BNDDIR.
-SK
On 5/19/2015 4:05 PM, Steinmetz, Paul wrote:
Scott,--
Majority of our creates are *pgms.
We create very few *modules and don't use *BNDDIR that often.
Paul
-----Original Message-----
From: MIDRANGE-L [mailto:midrange-l-bounces@xxxxxxxxxxxx] On Behalf
Of Scott Klement
Sent: Tuesday, May 19, 2015 4:47 PM
To: Midrange Systems Technical Discussion
Subject: Re: Input IPv4 address - return DNS name
Paul,
QC2LE is the binding directory for the ILE C runtime library. The CL program is calling routines named 'strlen' and 'memcpy' that are found in that ILE C runtime library.
-SK
On 5/19/2015 3:42 PM, Steinmetz, Paul wrote:
Scott,--
I created CLLE DNSNAME, compiled as per 2 instructions below.
Also created DNSNAMETST CLP for testing, all worked.
DNSNAME *PGM QGPL CLLE DNS CL API
DNSNAMETST *PGM QGPL CLP Test DNSNAME CL
DNSNAME *MODULE QGPL CLLE DNS CL API
How is DNDDIR(QC2LE) related to this?
Paul
-----Original Message-----
From: MIDRANGE-L [mailto:midrange-l-bounces@xxxxxxxxxxxx] On Behalf
Of Scott Klement
Sent: Tuesday, May 19, 2015 10:29 AM
To: Midrange Systems Technical Discussion
Subject: Re: Input IPv4 address - return DNS name
Paul,
You didn't answer my question about whether you wanted this in CL or whether it could be RPG... RPG has better tools for dealing with C functions and Unix-type APIs.
well, no matter, I went ahead and did it in CL. Since this uses C functions, it's an ILE CL program and should be compiled with:
CRTCLMOD DNSNAME
CRTPGM DNSNAME BNDDIR(QC2LE)
Here's the code. Note that since this has a 256 long parameter, it
should not be called from the command line
PGM PARM(&ADDR &DNSNAM)
DCL VAR(&ADDR) TYPE(*CHAR) LEN(30)
DCL VAR(&DNSNAM) TYPE(*CHAR) LEN(256)
DCL VAR(&ADDRZ) TYPE(*CHAR) LEN(31)
DCL VAR(&ZERO) TYPE(*CHAR) LEN(1) VALUE(x'00')
DCL VAR(&IPADDR) TYPE(*UINT) LEN(4)
DCL VAR(&IPADRLEN) TYPE(*INT) LEN(4) VALUE(4)
DCL VAR(&ADDRFAM) TYPE(*INT) LEN(4) VALUE(2)
DCL VAR(&NULL) TYPE(*PTR)
DCL VAR(&P_HOSTENT) TYPE(*PTR)
DCL VAR(&HOSTENT) TYPE(*CHAR) LEN(56) +
STG(*BASED) BASPTR(&P_HOSTENT)
DCL VAR(&P_HOST) TYPE(*PTR) +
STG(*DEFINED) DEFVAR(&HOSTENT 1)
DCL VAR(&LEN) TYPE(*UINT) LEN(4)
DCL VAR(&RESPTR) TYPE(*PTR)
/* Convert Human-Readable IP address into binary format */
CHGVAR VAR(&ADDRZ) VALUE(&ADDR *TCAT &ZERO)
CALLPRC PRC('inet_addr') PARM((&ADDRZ *BYREF)) +
RTNVAL(&IPADDR)
IF (&IPADDR *EQ 4294967295) DO
SNDPGMMSG MSGID(CPF9898) MSGF(QCPFMSG) MSGTYPE(*ESCAPE) +
MSGDTA('Invalid IP address. Must be in format x.x.x.x')
RETURN
ENDDO
/* Perform DNS or Host-Table Lookup of binary IP Address */
CALLPRC PRC('gethostbyaddr') PARM((&IPADDR *BYREF) +
(&IPADRLEN *BYVAL) +
(&ADDRFAM *BYVAL)) +
RTNVAL(&P_HOSTENT)
IF (&P_HOSTENT *EQ &NULL) DO
SNDPGMMSG MSGID(CPF9898) MSGF(QCPFMSG) MSGTYPE(*ESCAPE) +
MSGDTA('Host not found')
RETURN
ENDDO
/* The result will be that &P_HOST is a pointer to a C-style +
string. Use some C functions to convert this to a CL
*CHAR */
CALLPRC PRC('strlen') PARM((&P_HOST *BYVAL)) +
RTNVAL(&LEN)
IF (&LEN *GT 0) DO
CALLPRC PRC('memcpy') PARM((&DNSNAM *BYREF) +
(&P_HOST *BYVAL) +
(&LEN *BYVAL)) +
RTNVAL(&RESPTR)
ENDDO
ENDPGM
On 5/19/2015 8:05 AM, Steinmetz, Paul wrote:
Scott,
I would be interested in the API and sample code, especially since Rob has found that DIG does not work 100%.
Paul
-----Original Message-----
From: MIDRANGE-L [mailto:midrange-l-bounces@xxxxxxxxxxxx] On Behalf
Of Scott Klement
Sent: Monday, May 18, 2015 5:35 PM
To: Midrange Systems Technical Discussion
Subject: Re: Input IPv4 address - return DNS name
IBM i has "resolver" routines built-in that do this sort of thing.
If all you need is IPv4, you could call the gethostbyaddr() API.
There are newer/better routines available that support IPv6
(though, I must admit, it'd take a bit of research for me to find
this.)
I wonder if it'd make sense for you to use these routines instead of calling the DIG program? Nothing wrong with using DIG, I guess... but calling the APIs directly would be faster, no need to output to a file
and read a file, it'd return the result directly. But, it does involve
some pointer work...
Want a code sample? (If so, is RPG alright, or does it need to be
CL?)
-SK
On 5/18/2015 3:36 PM, Steinmetz, Paul wrote:
I've created a utility that inputs an IPv4 address and returns the DNS name.--
It uses the DIG command with the out file option.
Does anything exist that does something similar?
I'm planning on using this as part of a larger project to create
and populate a log file of all external communications, (FTP, SSL,
SSH,
etc)
0008.00 PGM PARM(&IPV4 &DNSNAM)
0009.00
0010.00 /* VARIABLE DECLARATIONS */
0011.00
0012.00 DCL VAR(&IPV4) TYPE(*CHAR) LEN(30)
0013.00 DCL VAR(&DNSNAM) TYPE(*CHAR) LEN(256 )
0014.00
0015.00 RMVLNK OBJLNK('/DIGOUT')
0016.00
0017.00 DIG HOSTNAME(&IPV4) REVERSE(*YES) +
0018.00 IPVSN(*IPV4ONLY) SHORT(*YES) +
0019.00 IDENTIFY(*YES) TOSTMF(DIGOUT)
0020.00
0021.00 CPYFRMIMPF FROMSTMF('/DIGOUT') TOFILE(QGPL/DIGOUT) +
0022.00 MBROPT(*REPLACE) RCDDLM(*LF) +
0023.00 RPLNULLVAL(*FLDDFT)
0024.00
0025.00 CALL PGM(DIGCONV) PARM(&DNSNAM) /* Search DIG +
0026.00 outfile, find and return DNS name */
0027.00
0028.00 DMPCLPGM
0029.00
0030.00 END: ENDPGM
0001.00 H DEBUG
0009.00 **************************************************************************
0010.00 Fdigout ipe f 3965 disk
0011.00 **************************************************************************
0012.00 dsearchfor s 12
0013.00
******************************************************************
*
*
*
*
****
0014.00 * Input Parameters
0015.00 idigout AA 01
0016.00
0017.00 * Record type
0018.00
0019.00 i 1 3965 irec
0020.00 **************************************************************************
0021.00 C *entry plist
0022.00 C parm dnsfnd 256
0023.00
0024.00 c eval searchfor = 'from server '
0025.00 c exsr search
0026.00 **************************************************************************
0027.00 C search begsr
0028.00
******************************************************************
*
*
*
*
****
0029.00 /free
0030.00 pos = %scan(searchfor: irec :1);
0031.00 if pos <> 0;
0032.00 dnsfnd = %Subst(irec:1 :pos-3);
0033.00 endif;
0034.00 /end-free
0035.00 c endsr
Thank You
_____
Paul Steinmetz
IBM i Systems Administrator
Pencor Services, Inc.
462 Delaware Ave
Palmerton Pa 18071
610-826-9117 work
610-826-9188 fax
610-349-0913 cell
610-377-6012 home
psteinmetz@xxxxxxxxxx
http://www.pencor.com/
This is the Midrange Systems Technical Discussion (MIDRANGE-L)
mailing list To post a message email: MIDRANGE-L@xxxxxxxxxxxx To
subscribe, unsubscribe, or change list options,
visit: http://lists.midrange.com/mailman/listinfo/midrange-l
or email: MIDRANGE-L-request@xxxxxxxxxxxx Before posting, please take a moment to review the archives at http://archive.midrange.com/midrange-l.
--
This is the Midrange Systems Technical Discussion (MIDRANGE-L)
mailing list To post a message email: MIDRANGE-L@xxxxxxxxxxxx To
subscribe, unsubscribe, or change list options,
visit: http://lists.midrange.com/mailman/listinfo/midrange-l
or email: MIDRANGE-L-request@xxxxxxxxxxxx Before posting, please take a moment to review the archives at http://archive.midrange.com/midrange-l.
This is the Midrange Systems Technical Discussion (MIDRANGE-L)
mailing list To post a message email: MIDRANGE-L@xxxxxxxxxxxx To
subscribe, unsubscribe, or change list options,
visit: http://lists.midrange.com/mailman/listinfo/midrange-l
or email: MIDRANGE-L-request@xxxxxxxxxxxx Before posting, please take a moment to review the archives at http://archive.midrange.com/midrange-l.
This is the Midrange Systems Technical Discussion (MIDRANGE-L) mailing
list To post a message email: MIDRANGE-L@xxxxxxxxxxxx To subscribe,
unsubscribe, or change list options,
visit: http://lists.midrange.com/mailman/listinfo/midrange-l
or email: MIDRANGE-L-request@xxxxxxxxxxxx Before posting, please take a moment to review the archives at http://archive.midrange.com/midrange-l.
As an Amazon Associate we earn from qualifying purchases.
This mailing list archive is Copyright 1997-2024 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.