syslinux-3.08-2 sources from FC4
[bootcd.git] / syslinux / com32 / samples / resolv.c
1 #ident "$Id: resolv.c,v 1.1 2004/12/28 23:49:43 hpa Exp $"
2 /* ----------------------------------------------------------------------- *
3  *   
4  *   Copyright 2004 H. Peter Anvin - All Rights Reserved
5  *
6  *   This program is free software; you can redistribute it and/or modify
7  *   it under the terms of the GNU General Public License as published by
8  *   the Free Software Foundation, Inc., 53 Temple Place Ste 330,
9  *   Boston MA 02111-1307, USA; either version 2 of the License, or
10  *   (at your option) any later version; incorporated herein by reference.
11  *
12  * ----------------------------------------------------------------------- */
13
14 /*
15  * resolv.c
16  *
17  * Resolve an IP address
18  */
19
20 #include <string.h>
21 #include <stdio.h>
22 #include <console.h>
23 #include <stdlib.h>
24 #include <com32.h>
25
26 uint32_t resolv(const char *name)
27 {
28   com32sys_t reg;
29
30   strcpy((char *)__com32.cs_bounce, name);
31
32   memset(&reg, 0, sizeof reg);
33   reg.eax.w[0] = 0x0010;
34   reg.ebx.w[0] = OFFS(__com32.cs_bounce);
35   reg.es       = SEG(__com32.cs_bounce);
36
37   __intcall(0x22, &reg, &reg);
38
39   if ( reg.eflags.l & EFLAGS_CF )
40     return 0;
41   else
42     return reg.eax.l;
43 }
44
45 int main(int argc, char *argv[])
46 {
47   uint32_t ip;
48
49   openconsole(&dev_null_r, &dev_stdcon_w);
50
51   if ( argc < 2 ) {
52     fputs("Usage: resolv hostname\n", stderr);
53     exit(1);
54   }
55
56   ip = resolv(argv[1]);
57
58   if ( ip ) {
59     printf("%s = %u.%u.%u.%u\n", argv[1],
60            (ip & 0xff), (ip >> 8) & 0xff,
61            (ip >> 16) & 0xff, (ip >> 24) & 0xff);
62   } else {
63     printf("%s not found\n", argv[1]);
64   }
65     
66   return 0;
67 }