|
Hello Paul, The real problem is that the inet_addr function has been designed incorrectly. It should be returning an in_addr structure (well, really an in_addr_t) and indicate an error with INADDR_NONE. Now I know that the in_addr structure is really an unsigned 32-bit integer but that isn't the point. inet_addr has been deprecated on most systems and replaced by inet_aton but the AS/400 doesn't support that. Both of these are replaced by inet_pton in IPv6 which avoids these issues. The documentation is correct in so far as it describes a bad api. Yes, -1 is a signed value but the behaviour of shoving a signed value in to an unsigned variable is somewhat compiler dependent and covered by the ANSI C spec. The -1 signed number is promoted to an unsigned int and you can successfully test an unsigned value for -1 because of the way negative numbers are implemented. -1 in two's-complement form is X'FFFF'. Promoting the type results in -1 and x'FFFF' comparing equal. I'd guess that RPG IV implements signed and unsigned types in a similar manner to remain compatible with the C apis. This has the nasty side-effect of inet_addr (and utilities that use it such as ping) refusing to accept an IP address of 255.255.255.255 which is generally not considered a valid IP address anyway since it is the general broadcast address (unless you are using one of the few Unix systems that treats 0.0.0.0 as the broadcast address). Regards, Simon Coulter. «»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«» «» FlyByNight Software AS/400 Technical Specialists «» «» Eclipse the competition - run your business on an IBM AS/400. «» «» «» «» Phone: +61 3 9419 0175 Mobile: +61 0411 091 400 «» «» Fax: +61 3 9419 0175 mailto: shc@flybynight.com.au «» «» «» «» Windoze should not be open at Warp speed. «» «»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«» //--- forwarded letter ------------------------------------------------------- > Date: Wed, 03 May 00 16:21:20 -0700 > From: "Paul Jackson" <paulgjackson@yahoo.com> > To: RPG400-L@midrange.com > Reply-To: RPG400-L@midrange.com > Subject: inet_addr API question > > 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-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.