test/sample file to do that; fix bug in chain.c.
#include <stdio.h>
#include <ctype.h>
#include <string.h>
+#include <console.h>
#define SECTOR 512 /* bytes/sector */
int hd, drive, whichpart;
static com32sys_t inreg; /* In bss, so zeroed automatically */
+ openconsole(&dev_null_r, &dev_stdcon_w);
+
/* Parse command line */
while ( isspace(*cmdline) )
cmdline++;
bail:
return 255;
}
-
-
-
.SUFFIXES: .lss .c .o .elf .c32 .lnx
-all: hello.c32 cat.c32 \
+all: hello.c32 cat.c32 resolv.c32 \
fancyhello.c32 fancyhello.lnx \
keytest.c32 keytest.lnx \
--- /dev/null
+#ident "$Id$"
+/* ----------------------------------------------------------------------- *
+ *
+ * Copyright 2004 H. Peter Anvin - All Rights Reserved
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, Inc., 53 Temple Place Ste 330,
+ * Boston MA 02111-1307, USA; either version 2 of the License, or
+ * (at your option) any later version; incorporated herein by reference.
+ *
+ * ----------------------------------------------------------------------- */
+
+/*
+ * resolv.c
+ *
+ * Resolve an IP address
+ */
+
+#include <string.h>
+#include <stdio.h>
+#include <console.h>
+#include <stdlib.h>
+#include <com32.h>
+
+uint32_t resolv(const char *name)
+{
+ com32sys_t reg;
+
+ strcpy((char *)__com32.cs_bounce, name);
+
+ memset(®, 0, sizeof reg);
+ reg.eax.w[0] = 0x0010;
+ reg.ebx.w[0] = OFFS(__com32.cs_bounce);
+ reg.es = SEG(__com32.cs_bounce);
+
+ __intcall(0x22, ®, ®);
+
+ if ( reg.eflags.l & EFLAGS_CF )
+ return 0;
+ else
+ return reg.eax.l;
+}
+
+int main(int argc, char *argv[])
+{
+ uint32_t ip;
+
+ openconsole(&dev_null_r, &dev_stdcon_w);
+
+ if ( argc < 2 ) {
+ fputs("Usage: resolv hostname\n", stderr);
+ exit(1);
+ }
+
+ ip = resolv(argv[1]);
+
+ if ( ip ) {
+ printf("%s = %u.%u.%u.%u\n", argv[1],
+ (ip & 0xff), (ip >> 8) & 0xff,
+ (ip >> 16) & 0xff, (ip >> 24) & 0xff);
+ } else {
+ printf("%s not found\n", argv[1]);
+ }
+
+ return 0;
+}
; On return, DI points to the first byte after the label set,
; and SI to the terminating byte.
;
-; Assumes DS == ES. Change references to [bx] to [es:bx] to remove
-; that assumption.
-;
; On return, DX contains the number of dots encountered.
;
dns_mangle:
jz .endstring
cmp al,'.'
je .isdot
- inc byte [bx]
+ inc byte [es:bx]
stosb
jmp .getbyte
.endstring:
dec si
dec dx ; We always counted one high
- cmp byte [bx],0
+ cmp byte [es:bx],0
jz .done
xor al,al
stosb
pop ax
ret
-; Actual resolver function
-; Points to a null-terminated or :-terminated string in DS:SI
-; and returns the name in EAX if it exists and can be found.
-; If EAX = 0 on exit, the lookup failed.
-
; DNS header format
struc dnshdr
.id: resw 1
LastDNSServer dw DNSServers
+; Actual resolver function
+; Points to a null-terminated or :-terminated string in DS:SI
+; and returns the name in EAX if it exists and can be found.
+; If EAX = 0 on exit, the lookup failed.
+
section .text
dns_resolv:
+ push ds
+ push es
push di
push cx
push dx
- ; Initialize...
- mov eax,[MyIP]
- mov [pxe_udp_read_pkt_dns.dip],eax
+ push cs
+ pop es ; ES <- CS
; First, build query packet
mov di,DNSSendBuf+dnshdr.flags
- inc word [di-2] ; New query ID
+ inc word [es:di-2] ; New query ID
mov ax,htons(0100h) ; Recursion requested
stosw
mov ax,htons(1) ; One question
stosw
call dns_mangle ; Convert name to DNS labels
+
+ push cs ; DS <- CS
+ pop ds
+
push si ; Save pointer to after DNS string
+ ; Initialize...
+ mov eax,[MyIP]
+ mov [pxe_udp_read_pkt_dns.dip],eax
+
and dx,dx
jnz .fqdn ; If we have dots, assume it's FQDN
dec di ; Remove final null
pop dx
pop cx
pop di
+ pop es
+ pop ds
ret
.moreservers:
-CC = gcc -m32 -mregparm=3 -DREGPARM=3 -DDEBUG
+CC = gcc -m32 -mregparm=3 -DREGPARM=3
LD = ld -m elf_i386
OBJCOPY = objcopy
OPTFLAGS = -g -Os -march=i386 -falign-functions=0 -falign-jumps=0 -falign-loops=0 -fomit-frame-pointer