/*1* lookup.c - Lookup IP address, HW address, netmask2*/34#include <sys/types.h>5#include <sys/socket.h>67#include <sys/time.h> /* for struct timeval in net/if.h */8#include <net/if.h>9#include <netinet/in.h>1011#ifdef ETC_ETHERS12#include <net/ethernet.h>13#endif1415#include <netdb.h>16#include <strings.h>17#include <syslog.h>1819#include "bootp.h"20#include "lookup.h"21#include "report.h"2223/*24* Lookup an Ethernet address and return it.25* Return NULL if addr not found.26*/27u_char *28lookup_hwa(char *hostname, int htype)29{30switch (htype) {3132/* XXX - How is this done on other systems? -gwr */33#ifdef ETC_ETHERS34case HTYPE_ETHERNET:35case HTYPE_IEEE802:36{37static struct ether_addr ea;38/* This does a lookup in /etc/ethers */39if (ether_hostton(hostname, &ea)) {40report(LOG_ERR, "no HW addr for host \"%s\"",41hostname);42return (u_char *) 0;43}44return (u_char *) & ea;45}46#endif /* ETC_ETHERS */4748default:49report(LOG_ERR, "no lookup for HW addr type %d", htype);50} /* switch */5152/* If the system can't do it, just return an error. */53return (u_char *) 0;54}555657/*58* Lookup an IP address.59* Return non-zero on failure.60*/61int62lookup_ipa(char *hostname, u_int32 *result)63{64struct hostent *hp;65hp = gethostbyname(hostname);66if (!hp)67return -1;68bcopy(hp->h_addr, result, sizeof(*result));69return 0;70}717273/*74* Lookup a netmask75* Return non-zero on failure.76*77* XXX - This is OK as a default, but to really make this automatic,78* we would need to get the subnet mask from the ether interface.79* If this is wrong, specify the correct value in the bootptab.80*81* Both arguments are in network order82*/83int84lookup_netmask(u_int32 addr, u_int32 *result)85{86int32 m, a;8788a = ntohl(addr);89m = 0;9091if (IN_CLASSA(a))92m = IN_CLASSA_NET;9394if (IN_CLASSB(a))95m = IN_CLASSB_NET;9697if (IN_CLASSC(a))98m = IN_CLASSC_NET;99100if (!m)101return -1;102*result = htonl(m);103return 0;104}105106/*107* Local Variables:108* tab-width: 4109* c-indent-level: 4110* c-argdecl-indent: 4111* c-continued-statement-offset: 4112* c-continued-brace-offset: -4113* c-label-offset: -4114* c-brace-offset: 0115* End:116*/117118119