Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!zaphod.mps.ohio-state.edu!swrinde!elroy.jpl.nasa.gov!decwrl!sgi!arc@kaibab.wpd.sgi.com From: arc@kaibab.wpd.sgi.com (Andrew Cherenson) Newsgroups: comp.sys.sgi Subject: Re: What do I have to do to get gethostbyaddr to work? Message-ID: <95351@sgi.sgi.com> Date: 4 Apr 91 01:39:07 GMT References: <63465@bbn.BBN.COM> Sender: guest@sgi.sgi.com Reply-To: arc@sgi.com (Andrew Cherenson) Distribution: comp Organization: Silicon Graphics, Inc., Mountain View, CA Lines: 53 In article <63465@bbn.BBN.COM> pplacewa@bbn.com (Paul W Placeway) writes: >I'm stumped. I can't seem to make gethostbyaddr to work right. The >host is in /etc/hosts (which shouldn't even exist, but that's another >issue), AND it's in the YP version of hosts ("ypmatch hosts.byaddr" >works), AND the DNS knows about it. I've tried compiling this tidbit >normally, with -D_BSD_COMPAT and -lbsd, and with -D_BSD_COMPAT, -lsun >-lbsd (to get YP stuff). None of them work. It works fine on our >Suns. > >This is on a 4d/240 running Irix 3.3.2. > > -- Paul Placeway > >================ cut here ================ >#! /bin/sh ># To extract, remove mail header lines and type "sh filename" >echo x - FOO.c >sed -e 's/^X//' > FOO.c << '!FaR!OuT!' >X#include >X#include >X#include >X#include >X >Xmain(argc, argv) >Xint argc; >Xchar *argv[]; >X{ >X struct hostent *h; >X char *host_addr; >X long l; >X >X if (sscanf(argv[1], "%ld", &l) != 1) >X exit (1); >X >X host_addr = (char *) &l; >X h = gethostbyaddr (host_addr, sizeof (long), 0); >X if (h == (struct hostent *) 0) { >X#ifdef sun >X printf("h_errno == %d\n", h_errno); >X#else >X herror("gethostbyaddr"); >X#endif >X } else { >X printf("%s\n", h->h_name); >X } >X >X exit (0); >X} >X >!FaR!OuT! >exit Change the trailing 0 in the gethostbyaddr call to AF_INET.