Expand PMF_FN_* macros.
[netbsd-mini2440.git] / usr.sbin / bootp / common / lookup.c
blob4ae82dfc5087921da6bdc28278d82dd94d7bf87f
1 /* $NetBSD: lookup.c,v 1.5 2002/07/14 00:26:17 wiz Exp $ */
3 #include <sys/cdefs.h>
4 #ifndef lint
5 __RCSID("$NetBSD: lookup.c,v 1.5 2002/07/14 00:26:17 wiz Exp $");
6 #endif
8 /*
9 * lookup.c - Lookup IP address, HW address, netmask
12 #include <sys/types.h>
13 #include <sys/socket.h>
15 #include <net/if.h>
16 #include <netinet/in.h>
18 #ifdef ETC_ETHERS
19 #include <net/if_ether.h>
20 #endif
22 #include <netdb.h>
23 #include <syslog.h>
24 #include <strings.h>
26 #include "bootp.h"
27 #include "lookup.h"
28 #include "report.h"
31 * Lookup an Ethernet address and return it.
32 * Return NULL if addr not found.
34 u_char *
35 lookup_hwa(char *hostname, int htype)
37 switch (htype) {
39 /* XXX - How is this done on other systems? -gwr */
40 #ifdef ETC_ETHERS
41 case HTYPE_ETHERNET:
42 case HTYPE_IEEE802:
44 static struct ether_addr ea;
45 /* This does a lookup in /etc/ethers */
46 if (ether_hostton(hostname, &ea)) {
47 report(LOG_ERR, "no HW addr for host \"%s\"",
48 hostname);
49 return (u_char *) 0;
51 return (u_char *) & ea;
53 #endif /* ETC_ETHERS */
55 default:
56 report(LOG_ERR, "no lookup for HW addr type %d", htype);
57 } /* switch */
59 /* If the system can't do it, just return an error. */
60 return (u_char *) 0;
65 * Lookup an IP address.
66 * Return non-zero on failure.
68 int
69 lookup_ipa(char *hostname, u_int32 *result)
71 struct hostent *hp;
72 hp = gethostbyname(hostname);
73 if (!hp)
74 return -1;
75 bcopy(hp->h_addr, result, sizeof(*result));
76 return 0;
81 * Lookup a netmask
82 * Return non-zero on failure.
84 * XXX - This is OK as a default, but to really make this automatic,
85 * we would need to get the subnet mask from the ether interface.
86 * If this is wrong, specify the correct value in the bootptab.
88 * Both inputs are in network order.
90 int
91 lookup_netmask(u_int32 addr, u_int32 *result)
93 int32 m, a;
95 a = ntohl(addr);
96 m = 0;
98 if (IN_CLASSA(a))
99 m = IN_CLASSA_NET;
101 if (IN_CLASSB(a))
102 m = IN_CLASSB_NET;
104 if (IN_CLASSC(a))
105 m = IN_CLASSC_NET;
107 if (!m)
108 return -1;
109 *result = htonl(m);
110 return 0;
114 * Local Variables:
115 * tab-width: 4
116 * c-indent-level: 4
117 * c-argdecl-indent: 4
118 * c-continued-statement-offset: 4
119 * c-continued-brace-offset: -4
120 * c-label-offset: -4
121 * c-brace-offset: 0
122 * End: