Red Hat axp-list: Linux on Alpha (1995-2022)
 help / color / mirror / Atom feed
* Minor problem with RHCL/AXP 2.1
@ 1996-06-03 15:50 Nigel Metheringham
  0 siblings, 0 replies; 2+ messages in thread
From: Nigel Metheringham @ 1996-06-03 15:50 UTC (permalink / raw)


I have been running a SQUID cache on our alpha box running RHCL/AXP 
2.1.

The new version broke, badly!

This was due to a line like this:-

	if (inet_addr(ip) != -1) {

which never failed (ie never returned -1).  This is becuase in 
/usr/include/arpa/inet.h there was a definition like this...
   unsigned long   inet_addr __P((const char *));

Its the "good old lets shove an ip address in a long because they are 
always 32 bits" mindset problem!  I don't have 3.0.3 so don't know if 
its now fixed!

	Nigel.

-- 
[ Nigel.Metheringham@theplanet.net   - Unix Applications Engineer ]
[ *Views expressed here are personal and not supported by PLAnet* ]
[ PLAnet Online : The White House          Tel : +44 113 251 6012 ]
[ Melbourne Street, Leeds LS2 7PS UK.      Fax : +44 113 2345656  ]

^ permalink raw reply	[flat|nested] 2+ messages in thread
* Re: Minor problem with RHCL/AXP 2.1
@ 1996-06-03 16:07 David Mosberger-Tang
  0 siblings, 0 replies; 2+ messages in thread
From: David Mosberger-Tang @ 1996-06-03 16:07 UTC (permalink / raw)


>>>>> On Mon, 03 Jun 1996 16:50:36 +0100, Nigel Metheringham <Nigel.Metheringham@theplanet.net> said:

  Nigel> I have been running a SQUID cache on our alpha box running
  Nigel> RHCL/AXP 2.1.

  Nigel> The new version broke, badly!

  Nigel> This was due to a line like this:-

  Nigel> 	if (inet_addr(ip) != -1) {

  Nigel> which never failed (ie never returned -1).  This is becuase
  Nigel> in /usr/include/arpa/inet.h there was a definition like
  Nigel> this...  unsigned long inet_addr __P((const char *));

inet_addr() returns INADDR_NONE in case of failure.  It is wrong to
test for -1 (the Linux man-page is incorrect in this respect).  OSF/1
declare inet_addr() to return an "unsigned int" which works around the
problem, but it is apparently inconsistent with one of the POSIX
standards.  The correct way to test the return value of inet_addr is:

	if (inet_addr(ip) == INADDR_NONE)

or, if you insist on using -1 instead of INADDR_NONE:

	if ((int32_t) inet_addr(ip) == -1)

An even better solution is to use inet_aton():

	if (!inet_aton (ip, NULL))

because this will work even in the case "ip" specifies a local
broadcast address.

	--david

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~1996-06-03 16:07 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
1996-06-03 15:50 Minor problem with RHCL/AXP 2.1 Nigel Metheringham
  -- strict thread matches above, loose matches on Subject: below --
1996-06-03 16:07 David Mosberger-Tang

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox