|
The return value of -1 is "sort of" correct... In C the unsigned value of 0xFFFFFFFF (decimal 4294967295) corresponds to the signed value of -1. (Because of the twos complement representation of integers) However, this won't work in RPG (at least not at V3R2) It won't view -1 as being the same as 4294967295. What I do to solve this problem is to define a constant like this: D INADDR_NON C CONST(4294967295) And then check the result of inet_addr, something like this: c eval MyIP = inet_addr(charIP) c if MyIP = INADDR_NON c callp SetMsg('Invalid IP Address..') c endif The big flaw in the design of this API (there has been much criticism of this in UNIX circles) is that IPADDR_NON is the correct "integer IP" response for an IP of 255.255.255.255. This rarely matters, however, since 255.255.255.255 would be the IP you'd use if you wanted to broadcast your data to EVERY LOCATION ON THE INTERNET... (Which is a bad idea to say the least!) Hope that helps... On Wed, 3 May 2000, Paul Jackson wrote: > Greetings sockets & API gurus, > > I am trying to use the "inet_addr" sockets api to > convert a dotted decimal IP address into a 4 byte > integer. > My confusion lies in the fact that the documentation > for the API specifies an unsigned integer as the > return value. The documentation also specifies that > the return value will be set to -1 if there is an > error on the call to the API. > > The example in the new RPG redbook on page 197, > specifies the prototype return value as 10U 0 as per > the documentation and also mentions -1 as an error > return value. > > My question is, how can you test for -1 on an unsigned > integer field? and if this is just incorrect > documentation of the API? Also if I make the return > variable a signed integer, then I sometimes get > overflow errors when translating test IP address such > as 255.255.255.255. > > I look forward to hearing any comments relating to > this problem. > > Paul Jackson > Systems Programmer/Analyst > Costco Wholesale > Issaquah, WA USA > +--- | 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 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.