× The internal search function is temporarily non-functional. The current search engine is no longer viable and we are researching alternatives.
As a stop gap measure, we are using Google's custom search engine service.
If you know of an easy to use, open source, search engine ... please contact support@midrange.com.


  • Subject: Re: Sockets in RPGLE
  • From: "Scott Klement" <infosys@xxxxxxxxxxxx>
  • Date: 01 Jun 1999 13:32:59 -0500

Hmmm... thats very interesting.   I code my calls to inet_addr a bit
differently, and I'm actually surprised that you don't run into
problems doing it this way.

The business about not using "value" is absolutely correct.  However,
since the inet_addr function is designed for C programs, the string
SHOULD be null-terminated.  (correct me if I'm wrong!)

Therefore, my code would look like this:

D inet_addr       PR            10I 0 ExtProc('inet_addr')
D   DottedAddr                  16A

C                   eval      TcpAddr = %trim(TcpAddr) + x'00'
C                   eval      sin_addr = inet_addr(tcpAddr)

As you see, made the parameter to inet_addr 1 character longer, and
then added a x'00' to the end of the dotted-decimal address.  This
is how C programs know where a character string ends, by looking for
the EBCDIC (or ASCII) NUL character (which is x'00')

The danger of your "15A" approach is that it may try to look beyond
the 15 characters that you specify, causing unpredictable results,
since it never sees the x'00'.   Of course, the AS/400 implementation
of inet_addr MAY very well check to make sure it DOESNT make this
mistake, but unless you know this for certain, I wouldn't rely on it.

ALSO...

Someone else (maybe David Gibbs, but I'm not 100% certain) suggested
using gethostbyname FIRST, and calling inet_addr if that failed.

I'd suggest that you use the OPPOSITE strategy.  Use inet_addr first,
and if THAT fails, then try gethostbyname.

My reasoning here is that inet_addr is a simple "calculation" routine.
whereas gethostbyname actually does network communications (i.e. DNS
lookups) Again, the AS/400 implementation of gethostbyname may already
know that an IP address isn't a domain name, and thus skip the DNS
lookup, but unless you know this for certain, I'd do inet_addr first.
(Even if you DO know that for certain, it'd be a better habit to use
inet_addr first, IMHO)

That way, you only do network communications when you NEED to, which
should be more efficient, and less prone to errors.

Okay, I'll get off the soap box now :)   Seriously, I hope this
info is useful, and I'm not just preaching :)

Scott Klement
Information Systems Manager
Klement's Sausage Co, Inc.


Chris Bipes <ChrisB@cross-check.com> wrote:
> ---------------- Part 1 ----------------
> Thank You for all your help.  Now I have two ways of coding the same
> prototype.  The following also works:
>  *------------------------------------------------------------------
>  * Prototype for InetAddr().
>  *------------------------------------------------------------------
> D InetAddr        PR            10i 0 ExtProc('inet_addr')
> D SocketId                      15A
>  *------------------------------------------------------------------
> Notice the exclusion of the "VALUE" parameter.  This tip was from
>  Bruce at
> IBM.  I did not under stand what the "VALUE" parameter was until now
>
> C                   EVAL      sin_addr = inetaddr(TcpAddr)
>
> Either way you get correct results.
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* This is the RPG/400 Discussion Mailing List!  To submit a new         *
* message, send your mail to "RPG400-L@midrange.com".  To unsubscribe   *
* from this list send email to MAJORDOMO@midrange.com and specify       *
* 'unsubscribe RPG400-L' in the body of your message.  Questions should *
* be directed to the list owner / operator: david@midrange.com          *
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *


As an Amazon Associate we earn from qualifying purchases.

This thread ...


Follow On AppleNews
Return to Archive home page | Return to MIDRANGE.COM home page

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.