From 4cd6a4a5d7e49d54d53dcf4a6f3393d50bd88e8b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gwenol=C3=A9=20Beauchesne?= Date: Wed, 4 Jun 2003 18:44:09 +0000 Subject: Import dietlibc 0.22 + other fixes for AMD64 --- mdk-stage1/dietlibc/libcruft/res_mkquery.c | 75 ++++++++++++++++++++++++++++++ 1 file changed, 75 insertions(+) create mode 100644 mdk-stage1/dietlibc/libcruft/res_mkquery.c (limited to 'mdk-stage1/dietlibc/libcruft/res_mkquery.c') diff --git a/mdk-stage1/dietlibc/libcruft/res_mkquery.c b/mdk-stage1/dietlibc/libcruft/res_mkquery.c new file mode 100644 index 000000000..cf5693668 --- /dev/null +++ b/mdk-stage1/dietlibc/libcruft/res_mkquery.c @@ -0,0 +1,75 @@ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "dietfeatures.h" + +static char dnspacket[]="\xfe\xfe\001\000\000\001\000\000\000\000\000\000"; + +/* + 1 1 1 1 1 1 + 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 + +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+ + | ID | + +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+ + |QR| Opcode |AA|TC|RD|RA| Z | RCODE | + +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+ + | QDCOUNT | + +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+ + | ANCOUNT | + +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+ + | NSCOUNT | + +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+ + | ARCOUNT | + +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+ +*/ + +extern void __dns_make_fd(void); +extern int __dns_fd; + +extern int __dns_servers; +extern struct sockaddr __dns_server_ips[]; + +extern void __dns_readstartfiles(void); + +int res_mkquery(int op, const char *dname, int class, int type, char* data, + int datalen, const unsigned char* newrr, char* buf, int buflen) { + unsigned char packet[512]; + memmove(packet,dnspacket,12); + if ((_res.options&RES_RECURSE)==0) packet[2]=0; + *(unsigned short*)packet=rand(); + { + unsigned char* x; + const char* y,* tmp; + x=packet+12; y=dname; + while (*y) { + while (*y=='.') ++y; + for (tmp=y; *tmp && *tmp!='.'; ++tmp) ; + *x=tmp-y; + if (!(tmp-y)) break; + ++x; + if (x>=packet+510-(tmp-y)) { return -1; } + memmove(x,y,tmp-y); + x+=tmp-y; + if (!*tmp) { + *x=0; + break; + } + y=tmp; + } + *++x= 0; *++x= type; /* A */ + *++x= 0; *++x= class; /* IN */ + ++x; + if (x-packet>buflen) return -1; + memmove(buf,packet,x-packet); + return x-packet; + } +} + -- cgit v1.2.1