Fix MLINK.
[dragonfly/vkernel-mp.git] / libexec / bootpd / lookup.c
blob738953ef93222752dde289dbcc8a33da29321049
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 06: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(hostname, htype)
39 char *hostname;
40 int htype;
42 switch (htype) {
44 /* XXX - How is this done on other systems? -gwr */
45 #ifdef ETC_ETHERS
46 case HTYPE_ETHERNET:
47 case HTYPE_IEEE802:
49 static struct ether_addr ea;
50 /* This does a lookup in /etc/ethers */
51 if (ether_hostton(hostname, &ea)) {
52 report(LOG_ERR, "no HW addr for host \"%s\"",
53 hostname);
54 return (u_char *) 0;
56 return (u_char *) & ea;
58 #endif /* ETC_ETHERS */
60 default:
61 report(LOG_ERR, "no lookup for HW addr type %d", htype);
62 } /* switch */
64 /* If the system can't do it, just return an error. */
65 return (u_char *) 0;
70 * Lookup an IP address.
71 * Return non-zero on failure.
73 int
74 lookup_ipa(hostname, result)
75 char *hostname;
76 u_int32 *result;
78 struct hostent *hp;
79 hp = gethostbyname(hostname);
80 if (!hp)
81 return -1;
82 bcopy(hp->h_addr, result, sizeof(*result));
83 return 0;
88 * Lookup a netmask
89 * Return non-zero on failure.
91 * XXX - This is OK as a default, but to really make this automatic,
92 * we would need to get the subnet mask from the ether interface.
93 * If this is wrong, specify the correct value in the bootptab.
95 int
96 lookup_netmask(addr, result)
97 u_int32 addr; /* both in network order */
98 u_int32 *result;
100 int32 m, a;
102 a = ntohl(addr);
103 m = 0;
105 if (IN_CLASSA(a))
106 m = IN_CLASSA_NET;
108 if (IN_CLASSB(a))
109 m = IN_CLASSB_NET;
111 if (IN_CLASSC(a))
112 m = IN_CLASSC_NET;
114 if (!m)
115 return -1;
116 *result = htonl(m);
117 return 0;
121 * Local Variables:
122 * tab-width: 4
123 * c-indent-level: 4
124 * c-argdecl-indent: 4
125 * c-continued-statement-offset: 4
126 * c-continued-brace-offset: -4
127 * c-label-offset: -4
128 * c-brace-offset: 0
129 * End: