eb01a3090721f7490a96fe42b7369fb925874a94
[people/xl0/gpxe.git] / src / core / resolv.c
1 #include "resolv.h"
2
3 static struct resolver resolvers[0]
4         __table_start ( struct resolver, resolver );
5 static struct resolver resolvers_end[0]
6         __table_end ( struct resolver, resolver );
7
8 /*
9  * Resolve a name (which may be just a dotted quad IP address) to an
10  * IP address.
11  *
12  */
13 int resolv ( struct in_addr *address, const char *name ) {
14         struct resolver *resolver;
15
16         /* Check for a dotted quad IP address first */
17         if ( inet_aton ( name, address ) ) {
18                 DBG ( "RESOLV saw valid IP address %s\n", name );
19                 return 1;
20         }
21
22         /* Try any compiled-in name resolution modules */
23         for ( resolver = resolvers ; resolver < resolvers_end ; resolver++ ) {
24                 if ( resolver->resolv ( address, name ) ) {
25                         DBG ( "RESOLV resolved \"%s\" to %@ using %s\n",
26                               name, address->s_addr, resolver->name );
27                         return 1;
28                 }
29         }
30
31         DBG ( "RESOLV failed to resolve %s\n", name );
32         return 0;
33 }