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