]> andersk Git - openssh.git/blobdiff - openbsd-compat/getrrsetbyname.c
- (bal) "extration" -> "extraction" in ssh-rand-helper.c; repoted by john
[openssh.git] / openbsd-compat / getrrsetbyname.c
index 03637c9ef693c884469ef3d210f5aea9118018de..44fa2755b6bb26201f6086a13cd558cdcdb6e1c5 100644 (file)
@@ -1,4 +1,4 @@
-/* $OpenBSD: getrrsetbyname.c,v 1.4 2001/08/16 18:16:43 ho Exp $ */
+/* $OpenBSD: getrrsetbyname.c,v 1.7 2003/03/07 07:34:14 itojun Exp $ */
 
 /*
  * Copyright (c) 2001 Jakob Schlyter. All rights reserved.
 
 #include "includes.h"
 
-#ifndef HAVE_GETRRSETBYNAME
+#if defined(DNS) && !defined(HAVE_GETRRSETBYNAME)
 
 #include "getrrsetbyname.h"
 
+/* #include "thread_private.h" */
+
 #define ANSWER_BUFFER_SIZE 1024*64
 
 struct dns_query {
@@ -76,10 +78,10 @@ struct dns_response {
        struct dns_rr           *additional;
 };
 
-static struct dns_response *parse_dns_response(const char *, int);
-static struct dns_query *parse_dns_qsection(const char *, int, const char **,
-    int);
-static struct dns_rr *parse_dns_rrsection(const char *, int, const char **,
+static struct dns_response *parse_dns_response(const u_char *, int);
+static struct dns_query *parse_dns_qsection(const u_char *, int,
+    const u_char **, int);
+static struct dns_rr *parse_dns_rrsection(const u_char *, int, const u_char **,
     int);
 
 static void free_dns_query(struct dns_query *);
@@ -128,6 +130,7 @@ static int count_dns_rr(struct dns_rr *, u_int16_t, u_int16_t);
  * Routines to insert/extract short/long's.
  */
 
+#ifndef HAVE__GETSHORT
 static u_int16_t
 _getshort(msgp)
        register const u_char *msgp;
@@ -137,7 +140,9 @@ _getshort(msgp)
        GETSHORT(u, msgp);
        return (u);
 }
+#endif
 
+#ifndef HAVE__GETLONG
 static u_int32_t
 _getlong(msgp)
        register const u_char *msgp;
@@ -147,19 +152,22 @@ _getlong(msgp)
        GETLONG(u, msgp);
        return (u);
 }
+#endif
 
 int
 getrrsetbyname(const char *hostname, unsigned int rdclass,
     unsigned int rdtype, unsigned int flags,
     struct rrsetinfo **res)
 {
+       struct __res_state *_resp = &_res;
        int result;
        struct rrsetinfo *rrset = NULL;
        struct dns_response *response;
        struct dns_rr *rr;
        struct rdatainfo *rdata;
-       unsigned int length, index_ans, index_sig;
-       char answer[ANSWER_BUFFER_SIZE];
+       int length;
+       unsigned int index_ans, index_sig;
+       u_char answer[ANSWER_BUFFER_SIZE];
 
        /* check for invalid class and type */
        if (rdclass > 0xffff || rdtype > 0xffff) {
@@ -180,23 +188,24 @@ getrrsetbyname(const char *hostname, unsigned int rdclass,
        }
 
        /* initialize resolver */
-       if ((_res.options & RES_INIT) == 0 && res_init() == -1) {
+       if ((_resp->options & RES_INIT) == 0 && res_init() == -1) {
                result = ERRSET_FAIL;
                goto fail;
        }
 
 #ifdef DEBUG
-       _res.options |= RES_DEBUG;
+       _resp->options |= RES_DEBUG;
 #endif /* DEBUG */
 
 #ifdef RES_USE_DNSSEC
        /* turn on DNSSEC if EDNS0 is configured */
-       if (_res.options & RES_USE_EDNS0)
-               _res.options |= RES_USE_DNSSEC;
+       if (_resp->options & RES_USE_EDNS0)
+               _resp->options |= RES_USE_DNSSEC;
 #endif /* RES_USE_DNSEC */
 
        /* make query */
-       length = res_query(hostname, rdclass, rdtype, answer, sizeof(answer));
+       length = res_query(hostname, (signed int) rdclass, (signed int) rdtype,
+           answer, sizeof(answer));
        if (length < 0) {
                switch(h_errno) {
                case HOST_NOT_FOUND:
@@ -234,9 +243,11 @@ getrrsetbyname(const char *hostname, unsigned int rdclass,
        rrset->rri_ttl = response->answer->ttl;
        rrset->rri_nrdatas = response->header.ancount;
 
+#ifdef HAVE_HEADER_AD
        /* check for authenticated data */
        if (response->header.ad == 1)
                rrset->rri_flags |= RRSET_VALIDATED;
+#endif
 
        /* copy name from answer section */
        length = strlen(response->answer->name);
@@ -338,10 +349,10 @@ freerrset(struct rrsetinfo *rrset)
  * DNS response parsing routines
  */
 static struct dns_response *
-parse_dns_response(const char *answer, int size)
+parse_dns_response(const u_char *answer, int size)
 {
        struct dns_response *resp;
-       const char *cp;
+       const u_char *cp;
 
        /* allocate memory for the response */
        resp = calloc(1, sizeof(*resp));
@@ -403,7 +414,7 @@ parse_dns_response(const char *answer, int size)
 }
 
 static struct dns_query *
-parse_dns_qsection(const char *answer, int size, const char **cp, int count)
+parse_dns_qsection(const u_char *answer, int size, const u_char **cp, int count)
 {
        struct dns_query *head, *curr, *prev;
        int i, length;
@@ -449,7 +460,7 @@ parse_dns_qsection(const char *answer, int size, const char **cp, int count)
 }
 
 static struct dns_rr *
-parse_dns_rrsection(const char *answer, int size, const char **cp, int count)
+parse_dns_rrsection(const u_char *answer, int size, const u_char **cp, int count)
 {
        struct dns_rr *head, *curr, *prev;
        int i, length;
@@ -564,4 +575,4 @@ count_dns_rr(struct dns_rr *p, u_int16_t class, u_int16_t type)
        return (n);
 }
 
-#endif /* HAVE_GETRRSETBYNAME */
+#endif /* defined(DNS) && !defined(HAVE_GETRRSETBYNAME) */
This page took 0.084116 seconds and 4 git commands to generate.