× 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: inet_ntoa?
  • From: Scott Klement <klemscot@xxxxxxxxxxxx>
  • Date: Fri, 3 Nov 2000 11:30:10 -0600 (CST)



On Wed, 1 Nov 2000, Keith McIntosh wrote:

> Can someone tell me what I am doing wrong 
> with the this?

A few things are wrong, I'll try to explain them:

>  
> Example:
> H DFTACTGRP(*NO) ACTGRP('QILE') BNDDIR('QC2LE')       
> 
>  
>  *-- InetAddr --- Transform IP address from dotted
> form 
> D InetAddr        Pr      10U 0 ExtProc('inet_addr')  
> D                           *   Value
> 
> *-- InetNtoa --- Transform IP address to dotted form 
> D InetNtoa        Pr        *   ExtProc('inet_ntoa')  
> 
> D                               10u 0                 

1)  in your prototype for InetNtoa, you need to have the parameter
       passed by VALUE.  The C prototype looks like this:
           char *inet_ntoa(struct in_addr in);
       Since there is no * in front of "in", its passed by value.

> 
> 
> D Address@        S         *                    
> D Address         S       30A   Based(Address@)       
> 
> 
> D test@           S         *
> D test            S       15a
> D InAddr          s       10U 0

2)  the variable "test" should really be 16 bytes long.  15 will
       work fine for this particular example, but take for example,
       this address:  "192.168.101.144"   As you can see its 15 bytes
       long -- but once you add the x'00' to the end, it'll be 16.
       If you leave it at 15 bytes, it could cause strange, hard to
       track down problems when calling inet_addr.

> 
> C             Eval      Test = '10.1.3.11' + x'00' 
> C             Eval      Test@  = %addr(test)    
> C             Eval      InAddr = InetAddr(test@) 

3) After calling InetAddr, you should really be checking for failure.
       Thats not as simple as it sounds with this particular function,
       failure is represented by this number:  4294967295

> C             Eval      Address@ = Inetntoa(InAddr)  
> C  Address    dsply                                  
> C             Eval      *InLR=*On                    
> C             Return  

4) Assuming you fix point #1 above, your next problem with inet_ntoa will
       be that you're not converting the string back from C to RPG.  You
       can't assume that the entire 30 bytes of "Address" will be 
       allocated by InetNtoa.  You should be careful to only deal with
       the data before the x'00' in Address.

       Something like this should work:

CL0N01Factor1+++++++Opcode&ExtFactor2+++++++Result++++++++Len++D+HiLoEq
c     x'00'         scan      Address       Length
c                   eval      UseMe = %subst(Address:1:Length-1)
c     UseMe         dsply

       (Except, of course that you'll want to add a little extra code to
       make sure that "Length" will be valid to use in the %subst.)


Hope that helps...


+---
| This is the RPG/400 Mailing List!
| To submit a new message, send your mail to RPG400-L@midrange.com.
| To subscribe to this list send email to RPG400-L-SUB@midrange.com.
| To unsubscribe from this list send email to RPG400-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 thread ...

Replies:

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.