diff options
author | Erik Andersen <andersen@codepoet.org> | 2000-05-14 04:16:35 +0000 |
---|---|---|
committer | Erik Andersen <andersen@codepoet.org> | 2000-05-14 04:16:35 +0000 |
commit | 64bc6412188b141c010ac3b8e813b837dd991e80 (patch) | |
tree | ffa12b79ea4b13191754f54b872eb1a4f9e3a04b /libc |
Initial revision
Diffstat (limited to 'libc')
102 files changed, 15349 insertions, 0 deletions
diff --git a/libc/inet/Makefile b/libc/inet/Makefile new file mode 100644 index 000000000..28565cecd --- /dev/null +++ b/libc/inet/Makefile @@ -0,0 +1,43 @@ +# Copyright (C) 1995,1996 Robert de Bath <rdebath@cix.compulink.co.uk> +# Copyright (C) 1998-1999 D. Jeff Dionne <jeff@rt-control.com> +# Copyright (C) 1998 Kenneth Albanowski <kjahds@kjahds.com> +# Copyright (C) 1999 D. Jeff Dionne <jeff@rt-control.com> +# under the GNU Library General Public License. + +LIBC=../libc.a + +CC=m68k-pic-coff-gcc +AR=m68k-pic-coff-ar +RANLIB=m68k-pic-coff-ranlib + +CCFLAGS= -O2 -m68000 -msoft-float -fno-builtin -I../include + +ASRC=addr.c +AOBJ=inet_aton.o inet_addr.o inet_ntoa.o + +RSRC=resolv.c +ROBJ= encodeh.o decodeh.o encoded.o decoded.o lengthd.o encodeq.o \ +decodeq.o lengthq.o encodea.o decodea.o encodep.o decodep.o \ +formquery.o dnslookup.o resolveaddress.o resolvemailbox.o \ +opennameservers.o closenameservers.o resolvename.o gethostbyname.o\ +gethostbyaddr.o + +OBJ=$(AOBJ) $(ROBJ) + +CFLAGS=$(ARCH) $(CCFLAGS) $(DEFS) + +all: $(LIBC) + @$(RM) $(OBJ) + +$(LIBC): $(LIBC)($(OBJ)) + +$(LIBC)($(AOBJ)): $(ASRC) + $(CC) $(CFLAGS) -DL_$* $< -c -o $*.o + $(AR) $(ARFLAGS) $@ $*.o + +$(LIBC)($(ROBJ)): $(RSRC) + $(CC) $(CFLAGS) -DL_$* $< -c -o $*.o + $(AR) $(ARFLAGS) $@ $*.o + +clean: + rm -f *.o libc.a diff --git a/libc/inet/addr.c b/libc/inet/addr.c new file mode 100644 index 000000000..bb27753bf --- /dev/null +++ b/libc/inet/addr.c @@ -0,0 +1,85 @@ +/* Copyright (C) 1995,1996 Robert de Bath <rdebath@cix.compulink.co.uk> + * This file is part of the Linux-8086 C library and is distributed + * under the GNU Library General Public License. + */ + +#include <string.h> +#include <ctype.h> +#include <netinet/in.h> + + +#ifdef L_inet_aton +int +inet_aton(cp, inp) +const char *cp; +struct in_addr *inp; +{ + unsigned long addr; + int value; + int part; + + if (!inp) + return 0; + + addr = 0; + for (part=1;part<=4;part++) { + + if (!isdigit(*cp)) + return 0; + + value = 0; + while (isdigit(*cp)) { + value *= 10; + value += *cp++ - '0'; + if (value > 255) + return 0; + } + + if (*cp++ != ((part == 4) ? '\0' : '.')) + return 0; + + addr <<= 8; + addr |= value; + } + + inp->s_addr = htonl(addr); + + return 1; +} +#endif + +#ifdef L_inet_addr +unsigned long +inet_addr(cp) +const char *cp; +{ + struct in_addr a; + if (!inet_aton(cp, &a)) + return -1; + else + return a.s_addr; +} +#endif + +#ifdef L_inet_ntoa + +extern char * itoa(int); + +char * +inet_ntoa(in) +struct in_addr in; +{ + static char buf[18]; + unsigned long addr = ntohl(in.s_addr); + + strcpy(buf, itoa((addr >> 24) & 0xff)); + strcat(buf, "."); + strcat(buf, itoa((addr >> 16) & 0xff)); + strcat(buf, "."); + strcat(buf, itoa((addr >> 8) & 0xff)); + strcat(buf, "."); + strcat(buf, itoa(addr & 0xff)); + + return buf; +} +#endif diff --git a/libc/inet/resolv.c b/libc/inet/resolv.c new file mode 100644 index 000000000..b4cfab104 --- /dev/null +++ b/libc/inet/resolv.c @@ -0,0 +1,892 @@ +/* resolv.c: DNS Resolver + * + * Copyright (C) 1998 Kenneth Albanowski <kjahds@kjahds.com>, + * The Silver Hammer Group, Ltd. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + */ + +#include <string.h> +#include <stdio.h> +#include <signal.h> +#include <sys/socket.h> +#include <sys/types.h> +#include <netinet/in.h> +#include <arpa/inet.h> +#include <stdlib.h> +#include <unistd.h> +#include <cfgfile.h> +#include <resolv.h> + +#define DNS_SERVICE 53 +#define MAX_RECURSE 5 +#define REPLY_TIMEOUT 10 +#define MAX_RETRIES 15 + +#undef DEBUG +#ifdef DEBUG +#define DPRINTF(X,args...) printf(X,args...) +#else +#define DPRINTF(X,args...) +#endif /* DEBUG */ + +#ifdef L_encodeh +int encode_header(struct resolv_header * h, unsigned char * dest, int maxlen) +{ + if (maxlen < 12) + return -1; + + dest[0] = (h->id & 0xff00) >> 8; + dest[1] = (h->id & 0x00ff) >> 0; + dest[2] = (h->qr ? 0x80 : 0) | + ((h->opcode & 0x0f) << 3) | + (h->aa ? 0x04 : 0) | + (h->tc ? 0x02 : 0) | + (h->rd ? 0x01 : 0); + dest[3] = (h->ra ? 0x80 : 0) | + (h->rcode & 0x0f); + dest[4] = (h->qdcount & 0xff00) >> 8; + dest[5] = (h->qdcount & 0x00ff) >> 0; + dest[6] = (h->ancount & 0xff00) >> 8; + dest[7] = (h->ancount & 0x00ff) >> 0; + dest[8] = (h->nscount & 0xff00) >> 8; + dest[9] = (h->nscount & 0x00ff) >> 0; + dest[10] = (h->arcount & 0xff00) >> 8; + dest[11] = (h->arcount & 0x00ff) >> 0; + + return 12; +} +#endif + +#ifdef L_decodeh +int decode_header(unsigned char * data, struct resolv_header * h) +{ + h->id = (data[0] << 8) | data[1]; + h->qr = (data[2] & 0x80) ? 1 : 0; + h->opcode = (data[2] >> 3) & 0x0f; + h->aa = (data[2] & 0x04) ? 1 : 0; + h->tc = (data[2] & 0x02) ? 1 : 0; + h->rd = (data[2] & 0x01) ? 1 : 0; + h->ra = (data[3] & 0x80) ? 1 : 0; + h->rcode = data[3] & 0x0f; + h->qdcount = (data[4] << 8) | data[5]; + h->ancount = (data[6] << 8) | data[7]; + h->nscount = (data[8] << 8) | data[9]; + h->arcount = (data[10] << 8) | data[11]; + + return 12; +} +#endif + +#ifdef L_encoded +/* Encode a dotted string into nameserver transport-level encoding. + This routine is fairly dumb, and doesn't attempt to compress + the data */ + +int encode_dotted(const char * dotted, unsigned char * dest, int maxlen) +{ + int used=0; + + while(dotted && *dotted) { + char * c = strchr(dotted, '.'); + int l = c ? c - dotted : strlen(dotted); + + if (l >= (maxlen-used-1)) + return -1; + + dest[used++] = l; + memcpy(dest+used, dotted, l); + used += l; + + if (c) + dotted = c+1; + else + break; + } + + if (maxlen < 1) + return -1; + + dest[used++] = 0; + + return used; +} +#endif + +#ifdef L_decoded +/* Decode a dotted string from nameserver transport-level encoding. + This routine understands compressed data. */ + +int decode_dotted(const unsigned char * data, int offset, + char * dest, int maxlen) +{ + int l; + int measure=1; + int total = 0; + int used=0; + + if (!data) + return -1; + + while ((measure && total++), (l=data[offset++])) { + + if ((l & 0xc0) == (0xc0)) { + if (measure) + total++; + /* compressed item, redirect */ + offset = ((l & 0x3f) << 8) | data[offset]; + measure = 0; + continue; + } + + if ((used+l+1) >= maxlen) + return -1; + + memcpy(dest+used, data+offset, l); + offset += l; + used += l; + if (measure) + total += l; + + if (data[offset] != 0) + dest[used++] = '.'; + else + dest[used++] = '\0'; + } + + DPRINTF("Total decode len = %d\n", total); + + return total; +} +#endif + +#ifdef L_lengthd + +int length_dotted(const unsigned char * data, int offset) +{ + int orig_offset = offset; + int l; + + if (!data) + return -1; + + while ((l=data[offset++])) { + + if ((l & 0xc0) == (0xc0)) { + offset++; + break; + } + + offset += l; + } + + return offset-orig_offset; +} +#endif + +#ifdef L_encodeq +int encode_question(struct resolv_question * q, + unsigned char * dest, int maxlen) +{ + int i; |