kernel - TMPFS - Stabilization pass, fix vnode list corruption
[dragonfly.git] / libexec / bootpd / lookup.c
blobe37891b26e80144fbd1a1d74e692ff7bbfb50e6b
1 /*
2 * lookup.c - Lookup IP address, HW address, netmask
4 * $FreeBSD: src/libexec/bootpd/lookup.c,v 1.7 1999/08/28 00:09:19 peter Exp $
5 * $DragonFly: src/libexec/bootpd/lookup.c,v 1.2 2003/06/17 04:27:07 dillon Exp $
6 */
8 #include <sys/types.h>
9 #include <sys/socket.h>
11 #include <sys/time.h> /* for struct timeval in net/if.h */
12 #include <net/if.h>
13 #include <netinet/in.h>
15 #ifdef ETC_ETHERS
16 #include <net/ethernet.h>
17 extern int ether_hostton();
18 #endif
20 #include <netdb.h>
21 #include <syslog.h>
23 #ifndef USE_BFUNCS
24 #include <memory.h>
25 /* Yes, memcpy is OK here (no overlapped copies). */
26 #define bcopy(a,b,c) memcpy(b,a,c)
27 #endif
29 #include "bootp.h"
30 #include "lookup.h"
31 #include "report.h"
34 * Lookup an Ethernet address and return it.
35 * Return NULL if addr not found.
37 u_char *
38 lookup_hwa(char *hostname, int htype)
40 switch (htype) {
42 /* XXX - How is this done on other systems? -gwr */
43 #ifdef ETC_ETHERS
44 case HTYPE_ETHERNET:
45 case HTYPE_IEEE802:
47 static struct ether_addr ea;
48 /* This does a lookup in /etc/ethers */
49 if (ether_hostton(hostname, &ea)) {
50 report(LOG_ERR, "no HW addr for host \"%s\"",
51 hostname);
52 return NULL;
54 return (u_char *) & ea;
56 #endif /* ETC_ETHERS */
58 default:
59 report(LOG_ERR, "no lookup for HW addr type %d", htype);
60 } /* switch */
62 /* If the system can't do it, just return an error. */
63 return NULL;
68 * Lookup an IP address.
69 * Return non-zero on failure.
71 int
72 lookup_ipa(char *hostname, u_int32 *result)
74 struct hostent *hp;
75 hp = gethostbyname(hostname);
76 if (!hp)
77 return -1;
78 bcopy(hp->h_addr, result, sizeof(*result));
79 return 0;
84 * Lookup a netmask
85 * addr and result are both in network order. Return non-zero on failure.
87 * XXX - This is OK as a default, but to really make this automatic,
88 * we would need to get the subnet mask from the ether interface.
89 * If this is wrong, specify the correct value in the bootptab.
91 int
92 lookup_netmask(u_int32 addr, u_int32 *result)
94 int32 m, a;
96 a = ntohl(addr);
97 m = 0;
99 if (IN_CLASSA(a))
100 m = IN_CLASSA_NET;
102 if (IN_CLASSB(a))
103 m = IN_CLASSB_NET;
105 if (IN_CLASSC(a))
106 m = IN_CLASSC_NET;
108 if (!m)
109 return -1;
110 *result = htonl(m);
111 return 0;
115 * Local Variables:
116 * tab-width: 4
117 * c-indent-level: 4
118 * c-argdecl-indent: 4
119 * c-continued-statement-offset: 4
120 * c-continued-brace-offset: -4
121 * c-label-offset: -4
122 * c-brace-offset: 0
123 * End: