Bug in inet(3N) library

craig at SRN-VAX.ARPA craig at SRN-VAX.ARPA
Mon Aug 20 23:36:47 AEST 1984


From:  Craig Partridge <craig at SRN-VAX.ARPA>


    Compiled with -DDONTWORK (which produces a program conforming
to what Berkeley tells you to do) the following program doesn't work.
It gives the wrong answer on VAXen and core dumps on SUNs.

---------------------------------------------
/* program to show a bug */
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>

#ifdef DONTWORK
#include <arpa/inet.h>
#else
extern char *inet_ntoa();
extern u_long inet_addr();
#endif

main()
{
/* pretty sure the address used is not critical */
printf("%s\n",inet_ntoa(inet_addr("128.11.0.0")));
}
__________________________________________________

Problem is that the compiler handles the structure in_addr, differently
from a u_long, and while the include file <arpa/inet.h> declares inet_addr
as a struct in_addr (a portable??? network address structure), in fact it
returns a u_long.  The different declarations produce different code, and
the one for struct in_addr is wrong.

The best solution is probably to just edit <arpa/inet.h> and redeclare
inet_addr to be a u_long and forget this structure farce.

Craig Partridge
craig at bbn-unix
{ihnp4,wjh12,{and others}}!bbncca!craig



More information about the Comp.unix.wizards mailing list