Back to index

courier  0.68.2
Classes | Defines | Typedefs | Functions
rfc1035.h File Reference
#include "random128/random128.h"
#include "md5/md5.h"
#include <stdio.h>
#include <sys/types.h>
#include <sys/socket.h>
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  rfc1035_query
struct  rfc1035_res
struct  rfc1035_rr
struct  rfc1035_reply
struct  rfc1035_ifconf
union  rfc1035_rr.rr
struct  rfc1035_rr.rr.hinfo
struct  rfc1035_rr.rr.minfo
struct  rfc1035_rr.rr.mx
struct  rfc1035_rr.rr.soa
struct  rfc1035_rr.rr.rrsig

Defines

#define RFC1035_ADDRANY   rfc1035_addr_any
#define RFC1035_TYPE_A   1
#define RFC1035_TYPE_NS   2
#define RFC1035_TYPE_MD   3
#define RFC1035_TYPE_MF   4
#define RFC1035_TYPE_CNAME   5
#define RFC1035_TYPE_SOA   6
#define RFC1035_TYPE_MB   7
#define RFC1035_TYPE_MG   8
#define RFC1035_TYPE_MR   9
#define RFC1035_TYPE_NULL   10
#define RFC1035_TYPE_WKS   11
#define RFC1035_TYPE_PTR   12
#define RFC1035_TYPE_HINFO   13
#define RFC1035_TYPE_MINFO   14
#define RFC1035_TYPE_MX   15
#define RFC1035_TYPE_TXT   16
#define RFC1035_TYPE_AAAA
#define RFC1035_TYPE_OPT   41
#define RFC1035_TYPE_RRSIG   46
#define RFC1035_TYPE_AXFR   252
#define RFC1035_TYPE_MAILB   253
#define RFC1035_TYPE_MAILA   254
#define RFC1035_TYPE_ANY   255
#define RFC1035_CLASS_IN   1
#define RFC1035_CLASS_CSNET   2
#define RFC1035_CLASS_CHAOS   3
#define RFC1035_CLASS_HESIOD   4
#define RFC1035_CLASS_ANY   255
#define RFC1035_OPCODE_QUERY   0
#define RFC1035_OPCODE_IQUERY   1
#define RFC1035_OPCODE_STATUS   2
#define RFC1035_RCODE_NOERROR   0
#define RFC1035_RCODE_FORMAT   1
#define RFC1035_RCODE_SERVFAIL   2
#define RFC1035_RCODE_NXDOMAIN   3
#define RFC1035_RCODE_UNIMPLEMENTED   4
#define RFC1035_RCODE_REFUSED   5
#define RFC1035_MAXNS   10
#define RFC1035_DEFAULT_INITIAL_TIMEOUT   5
#define RFC1035_DEFAULT_MAXIMUM_BACKOFF   3
#define RFC1035_ERR_CNAME_RECURSIVE   -2
#define RFC1035_X_RANDOMIZE   1 /* Randomize query results */
#define RFC1035_MAXNAMESIZE   255
#define RFC1035_RESOLVE_RECURSIVE   1 /* Ask nameserver to do the recursion */
#define RFC1035_MAXTIMEBUFSIZE   40
#define RFC1035_NTOABUFSIZE   16

Typedefs

typedef struct in_addr
typedef struct sockaddr_in
typedef struct sockaddr

Functions

void rfc1035_type_itostr (int, void(*)(const char *, void *), void *)
int rfc1035_type_strtoi (const char *)
const char * rfc1035_class_itostr (int)
int rfc1035_class_strtoi (const char *)
const char * rfc1035_opcode_itostr (int)
int rfc1035_opcode_strtoi (const char *)
const char * rfc1035_rcode_itostr (int)
int rfc1035_rcode_strtoi (const char *)
void rfc1035_init_timeout (struct rfc1035_res *, unsigned, unsigned)
void rfc1035_init_ns (struct rfc1035_res *, const RFC1035_ADDR *, unsigned)
void rfc1035_init_norecursive (struct rfc1035_res *, int)
void rfc1035_init_dnssec_enable (struct rfc1035_res *, int)
void rfc1035_init_edns_payload (struct rfc1035_res *, int)
void rfc1035_init_resolv (struct rfc1035_res *)
void rfc1035_destroy_resolv (struct rfc1035_res *)
struct rfc1035_replyrfc1035_resolve (struct rfc1035_res *, int, const char *, unsigned, unsigned)
struct rfc1035_replyrfc1035_resolve_multiple (struct rfc1035_res *, int, const struct rfc1035_query *, unsigned)
int rfc1035_resolve_cname (struct rfc1035_res *, char *, unsigned, unsigned, struct rfc1035_reply **, int)
void rfc1035_replyfree (struct rfc1035_reply *)
const char * rfc1035_replyhostname (const struct rfc1035_reply *, const char *, char *)
int rfc1035_a (struct rfc1035_res *, const char *, RFC1035_ADDR **, unsigned *)
int rfc1035_ptr (struct rfc1035_res *, const RFC1035_ADDR *, char *)
int rfc1035_ptr_x (struct rfc1035_res *res, const RFC1035_ADDR *addr, void(*cb_func)(const char *, void *), void *cb_arg)
const char * rfc1035_replyuncompress (const char **, const struct rfc1035_reply *, char *)
int rfc1035_hostnamecmp (const char *, const char *)
int rfc1035_replysearch_an (const struct rfc1035_res *, const struct rfc1035_reply *, const char *, unsigned, unsigned, int)
int rfc1035_replysearch_ns (const struct rfc1035_res *, const struct rfc1035_reply *, const char *, unsigned, unsigned, int)
int rfc1035_replysearch_all (const struct rfc1035_res *, const struct rfc1035_reply *, const char *, unsigned, unsigned, int)
int rfc1035_mkquery (struct rfc1035_res *, unsigned,#define RFC1035_RESOLVE_RECURSIVE const struct rfc1035_query *, unsigned, void(*)(const char *, unsigned, void *), void *)
int rfc1035_open_udp (int *af)
int rfc1035_send_udp (int, const struct sockaddr *, int, const char *, unsigned)
int rfc1035_wait_reply (int, unsigned)
int rfc1035_wait_query (int, unsigned)
char * rfc1035_recv_udp (int, const struct sockaddr *, int, int *, const char *)
char * rfc1035_query_udp (struct rfc1035_res *, int, const struct sockaddr *, int, const char *, unsigned, int *, unsigned)
int rfc1035_open_tcp (struct rfc1035_res *, const RFC1035_ADDR *)
int rfc1035_send_tcp (int, const char *, unsigned)
char * rfc1035_recv_tcp (struct rfc1035_res *, int, int *, unsigned)
char * rfc1035_query_tcp (struct rfc1035_res *, int, const char *, unsigned, int *, unsigned)
struct rfc1035_replyrfc1035_replyparse (const char *, unsigned)
void rfc1035_rr_rand_an (struct rfc1035_reply *rr)
void rfc1035_rr_rand_ns (struct rfc1035_reply *rr)
void rfc1035_rr_rand_ar (struct rfc1035_reply *rr)
void rfc1035_rr_rand (struct rfc1035_reply *rr)
void rfc1035_dump (struct rfc1035_reply *, FILE *)
const char * rfc1035_fmttime (unsigned long, char *)
char * rfc1035_dumprrdata (struct rfc1035_reply *, struct rfc1035_rr *)
int rfc1035_rr_gettxt (struct rfc1035_rr *, int, char buf[256])
void rfc1035_ntoa_ipv4 (const struct in_addr *in, char *buf)
int rfc1035_aton_ipv4 (const char *p, struct in_addr *in4)
int rfc1035_sockaddrip (const RFC1035_NETADDR *, int, RFC1035_ADDR *)
int rfc1035_sockaddrport (const RFC1035_NETADDR *, int, int *)
void rfc1035_ntoa (const RFC1035_ADDR *, char *)
int rfc1035_aton (const char *, RFC1035_ADDR *)
int rfc1035_same_ip (const void *, int, const void *, int)
int rfc1035_bindsource (int sockfd, const struct sockaddr *addr, int addrlen)
int rfc1035_mksocket (int sock_type, int sock_protocol, int *af)
int rfc1035_mkaddress (int af, RFC1035_NETADDR *buf, const RFC1035_ADDR *addr, int port, const struct sockaddr **ptr, int *len)
struct rfc1035_ifconfrfc1035_ifconf (int *errflag)
void rfc1035_ifconf_free (struct rfc1035_ifconf *ifconf_list)

Class Documentation

struct rfc1035_query

Definition at line 99 of file rfc1035.h.

Class Members
const char * name
unsigned qclass
unsigned qtype
struct rfc1035_res

Definition at line 117 of file rfc1035.h.

Class Members
int dnssec_payload_size
RFC1035_ADDR nameservers
int norecursive
MD5_DIGEST randbuf
unsigned randptr
random128binbuf randseed
char * rfc1035_defaultdomain
unsigned rfc1035_good_ns
int rfc1035_nnameservers
unsigned rfc1035_timeout_backoff
unsigned rfc1035_timeout_initial
struct rfc1035_rr

Definition at line 432 of file rfc1035.h.

Class Members
const char * rdata
unsigned rdlength
union rfc1035_rr rr
unsigned rrclass
const char * rrname
unsigned rrtype
RFC1035_UINT32 ttl
struct rfc1035_reply

Definition at line 493 of file rfc1035.h.

Collaboration diagram for rfc1035_reply:
Class Members
unsigned char aa
unsigned char ad
struct rfc1035_rr ** allrrs
unsigned ancount
struct rfc1035_rr * anptr
unsigned arcount
struct rfc1035_rr * arptr
unsigned char cd
char * mallocedbuf
struct rfc1035_reply * next
unsigned nscount
struct rfc1035_rr * nsptr
unsigned char opcode
unsigned qdcount
struct rfc1035_query * qdptr
unsigned char qr
unsigned char ra
unsigned char rcode
unsigned char rd
const char * reply
unsigned replylen
RFC1035_NETADDR server_addr
unsigned char tc
struct rfc1035_ifconf

Definition at line 616 of file rfc1035.h.

Collaboration diagram for rfc1035_ifconf:
Class Members
RFC1035_ADDR ifaddr
char * ifname
struct rfc1035_ifconf * next
union rfc1035_rr.rr

Definition at line 439 of file rfc1035.h.

Class Members
const char * domainname
rr hinfo
rr minfo
rr mx
rr rrsig
rr soa
struct rfc1035_rr.rr.hinfo

Definition at line 440 of file rfc1035.h.

Class Members
const char * hinfo_str
const char * os_str
struct rfc1035_rr.rr.minfo

Definition at line 453 of file rfc1035.h.

Class Members
const char * emailbx_label
const char * rmailbx_label
struct rfc1035_rr.rr.mx

Definition at line 458 of file rfc1035.h.

Class Members
const char * mx_label
unsigned preference
struct rfc1035_rr.rr.soa

Definition at line 463 of file rfc1035.h.

Class Members
RFC1035_UINT32 expire
RFC1035_UINT32 minimum
const char * mname_label
RFC1035_UINT32 refresh
RFC1035_UINT32 retry
const char * rname_label
RFC1035_UINT32 serial
struct rfc1035_rr.rr.rrsig

Definition at line 473 of file rfc1035.h.

Class Members
unsigned char algorithm
RFC1035_UINT16 key_tag
unsigned char labels
RFC1035_UINT16 original_ttl
const char * signature
RFC1035_UINT32 signature_expiration
RFC1035_UINT32 signature_inception
RFC1035_UINT16 signature_len
const char * signer_name
RFC1035_UINT16 type_covered

Define Documentation

#define RFC1035_ADDRANY   rfc1035_addr_any

Definition at line 40 of file rfc1035.h.

#define RFC1035_CLASS_ANY   255

Definition at line 77 of file rfc1035.h.

#define RFC1035_CLASS_CHAOS   3

Definition at line 75 of file rfc1035.h.

#define RFC1035_CLASS_CSNET   2

Definition at line 74 of file rfc1035.h.

#define RFC1035_CLASS_HESIOD   4

Definition at line 76 of file rfc1035.h.

#define RFC1035_CLASS_IN   1

Definition at line 73 of file rfc1035.h.

Definition at line 113 of file rfc1035.h.

Definition at line 114 of file rfc1035.h.

#define RFC1035_ERR_CNAME_RECURSIVE   -2

Definition at line 216 of file rfc1035.h.

#define RFC1035_MAXNAMESIZE   255

Definition at line 280 of file rfc1035.h.

#define RFC1035_MAXNS   10

Definition at line 112 of file rfc1035.h.

#define RFC1035_MAXTIMEBUFSIZE   40

Definition at line 537 of file rfc1035.h.

#define RFC1035_NTOABUFSIZE   16

Definition at line 573 of file rfc1035.h.

#define RFC1035_OPCODE_IQUERY   1

Definition at line 83 of file rfc1035.h.

#define RFC1035_OPCODE_QUERY   0

Definition at line 82 of file rfc1035.h.

#define RFC1035_OPCODE_STATUS   2

Definition at line 84 of file rfc1035.h.

#define RFC1035_RCODE_FORMAT   1

Definition at line 90 of file rfc1035.h.

#define RFC1035_RCODE_NOERROR   0

Definition at line 89 of file rfc1035.h.

#define RFC1035_RCODE_NXDOMAIN   3

Definition at line 92 of file rfc1035.h.

#define RFC1035_RCODE_REFUSED   5

Definition at line 94 of file rfc1035.h.

#define RFC1035_RCODE_SERVFAIL   2

Definition at line 91 of file rfc1035.h.

Definition at line 93 of file rfc1035.h.

#define RFC1035_RESOLVE_RECURSIVE   1 /* Ask nameserver to do the recursion */
#define RFC1035_TYPE_A   1

Definition at line 43 of file rfc1035.h.

Value:
28     /* RFC 1886. Even if we don't have
                                   IPv6 */

Definition at line 60 of file rfc1035.h.

#define RFC1035_TYPE_ANY   255

Definition at line 68 of file rfc1035.h.

#define RFC1035_TYPE_AXFR   252

Definition at line 65 of file rfc1035.h.

#define RFC1035_TYPE_CNAME   5

Definition at line 47 of file rfc1035.h.

#define RFC1035_TYPE_HINFO   13

Definition at line 55 of file rfc1035.h.

#define RFC1035_TYPE_MAILA   254

Definition at line 67 of file rfc1035.h.

#define RFC1035_TYPE_MAILB   253

Definition at line 66 of file rfc1035.h.

#define RFC1035_TYPE_MB   7

Definition at line 49 of file rfc1035.h.

#define RFC1035_TYPE_MD   3

Definition at line 45 of file rfc1035.h.

#define RFC1035_TYPE_MF   4

Definition at line 46 of file rfc1035.h.

#define RFC1035_TYPE_MG   8

Definition at line 50 of file rfc1035.h.

#define RFC1035_TYPE_MINFO   14

Definition at line 56 of file rfc1035.h.

#define RFC1035_TYPE_MR   9

Definition at line 51 of file rfc1035.h.

#define RFC1035_TYPE_MX   15

Definition at line 57 of file rfc1035.h.

#define RFC1035_TYPE_NS   2

Definition at line 44 of file rfc1035.h.

#define RFC1035_TYPE_NULL   10

Definition at line 52 of file rfc1035.h.

#define RFC1035_TYPE_OPT   41

Definition at line 62 of file rfc1035.h.

#define RFC1035_TYPE_PTR   12

Definition at line 54 of file rfc1035.h.

#define RFC1035_TYPE_RRSIG   46

Definition at line 63 of file rfc1035.h.

#define RFC1035_TYPE_SOA   6

Definition at line 48 of file rfc1035.h.

#define RFC1035_TYPE_TXT   16

Definition at line 58 of file rfc1035.h.

#define RFC1035_TYPE_WKS   11

Definition at line 53 of file rfc1035.h.

#define RFC1035_X_RANDOMIZE   1 /* Randomize query results */

Definition at line 228 of file rfc1035.h.


Typedef Documentation

typedef struct in_addr

Definition at line 35 of file rfc1035.h.

typedef struct sockaddr

Definition at line 37 of file rfc1035.h.

typedef struct sockaddr_in

Definition at line 36 of file rfc1035.h.


Function Documentation

int rfc1035_a ( struct rfc1035_res ,
const char *  ,
RFC1035_ADDR **  ,
unsigned *   
)

Definition at line 19 of file rfc1035qa.c.

{
struct rfc1035_reply *reply;
int    n, o;
char   namebuf[RFC1035_MAXNAMESIZE+1];

       namebuf[0]=0;
       strncat(namebuf, name, RFC1035_MAXNAMESIZE);

       *iasize=0;
       if (rfc1035_resolve_cname(res, namebuf,
              RFC1035_TYPE_A, RFC1035_CLASS_IN, &reply, 0) < 0 ||
              reply == 0 ||
              (n=rfc1035_replysearch_an( res, reply, namebuf, RFC1035_TYPE_A,
                     RFC1035_CLASS_IN, 0)) < 0)
       {
              if (reply && reply->rcode != RFC1035_RCODE_NXDOMAIN &&
                     reply->rcode != RFC1035_RCODE_NOERROR)
              {
                     errno=EAGAIN;
                     rfc1035_replyfree(reply);
                     return (1);   /* soft error */
              }

              if (reply) rfc1035_replyfree(reply);
              errno=ENOENT;
              return (-1); /* hard error */
       }

       for (o=n; o >= 0; o=rfc1035_replysearch_an(res, reply, namebuf,
                     RFC1035_TYPE_A, RFC1035_CLASS_IN, o+1))
              ++*iasize;

       if ( *iasize == 0 )
       {
              errno=EAGAIN;
              rfc1035_replyfree(reply);
              return (-1);
       }

       if ( (*iaptr=(struct in_addr *)malloc(sizeof(**iaptr)* *iasize)) == 0)
       {
              rfc1035_replyfree(reply);
              return (-1);
       }

       for (*iasize=0; n >= 0; n=rfc1035_replysearch_an(res, reply, namebuf,
                     RFC1035_TYPE_A, RFC1035_CLASS_IN, n+1))
       {
              (*iaptr)[*iasize]= reply->allrrs[n]->rr.inaddr;
              ++*iasize;
       }

       rfc1035_replyfree(reply);
       return (0);
}

Here is the call graph for this function:

Here is the caller graph for this function:

int rfc1035_aton ( const char *  ,
RFC1035_ADDR *   
)

Definition at line 137 of file rfc1035an.c.

{
       return (rfc1035_aton_ipv4(p, in4));
}

Here is the call graph for this function:

Here is the caller graph for this function:

int rfc1035_aton_ipv4 ( const char *  p,
struct in_addr in4 
)

Definition at line 100 of file rfc1035an.c.

{
int    dummy;
RFC1035_UINT32 n=doaton(p, &dummy);
union  {
       unsigned char addr[4];
       struct in_addr n;
       } u;

       u.addr[3]=n;
       u.addr[2]=n >> 8;
       u.addr[1]=n >> 16;
       u.addr[0]=n >> 24;

       if (dummy)    errno=EINVAL;
       *in4=u.n;
       return (dummy);
}

Here is the call graph for this function:

Here is the caller graph for this function:

int rfc1035_bindsource ( int  sockfd,
const struct sockaddr addr,
int  addrlen 
)

Definition at line 18 of file rfc1035bindsource.c.

{
       return bind(sockfd, addr, addrlen);
}

Here is the caller graph for this function:

const char* rfc1035_class_itostr ( int  )

Definition at line 89 of file rfc1035str.c.

{
unsigned i;

       for (i=0; i<sizeof(classtab)/sizeof(classtab[0]); i++)
              if (classtab[i].num == n) return (classtab[i].name);
       return ("unknown");
}

Here is the caller graph for this function:

int rfc1035_class_strtoi ( const char *  )

Definition at line 98 of file rfc1035str.c.

{
unsigned i;

       for (i=0; i<sizeof(classtab)/sizeof(classtab[0]); i++)
              if (COMPARE(classtab[i].name, n) == 0) return (classtab[i].num);
       return (-1);
}

Here is the caller graph for this function:

void rfc1035_destroy_resolv ( struct rfc1035_res )

Definition at line 173 of file rfc1035.c.

{
       if (res->rfc1035_defaultdomain)
       {
              free(res->rfc1035_defaultdomain);
       }
}

Here is the caller graph for this function:

void rfc1035_dump ( struct rfc1035_reply ,
FILE *   
)

Definition at line 37 of file rfc1035dump.c.

{
unsigned n;
char namebuf[RFC1035_MAXNAMESIZE+1];
char timebuf[RFC1035_MAXTIMEBUFSIZE+1];
char   ipbuf[RFC1035_NTOABUFSIZE];
struct rfc1035_reply *qr;

       fprintf(f, ";;HEADER");

       rfc1035_ntoa((const RFC1035_ADDR *)&r->server_addr, ipbuf);

       fprintf(f, " (server %s)", ipbuf);

       fprintf(f, ":\n;;  Bytes: %ld\n", 
              (long)r->replylen);

       fprintf(f, ";;  Opcode: %s\n", 
              rfc1035_opcode_itostr(r->opcode));
       fprintf(f, ";;  Flags:");
       if (r->qr)
              fprintf(f, " qr");
       if (r->aa)
              fprintf(f, " aa");
       if (r->tc)
              fprintf(f, " tc");
       if (r->rd)
              fprintf(f, " rd");
       if (r->ra)
              fprintf(f, " ra");
       if (r->ad)
              fprintf(f, " ad");
       if (r->cd)
              fprintf(f, " cd");
       fprintf(f, "\n;;  Status: %s\n", rfc1035_rcode_itostr(r->rcode));
       fprintf(f, ";;  # questions: %u\n", r->qdcount);
       fprintf(f, ";;  # answers: %u\n", r->ancount);
       fprintf(f, ";;  # authoritative: %u\n", r->nscount);
       fprintf(f, ";;  # additional: %u\n", r->arcount);

       fprintf(f, ";;\n;;QUESTIONS:\n");
       for (n=0; n<r->qdcount; n++)
       {
              fprintf(f, ";;  ");
              print_hostname(f, rfc1035_replyhostname(r, r->qdptr[n].name,
                                                 namebuf));
              fprintf(f,".\t%s ",
                     rfc1035_class_itostr(r->qdptr[n].qclass));

              rfc1035_type_itostr(r->qdptr[n].qtype, tostr_callback, &f);

              fprintf(f, "\n");
       }

       fprintf(f, "\n;;ANSWERS:\n");
       for (qr=r; qr; qr=qr->next)
       {
              for (n=0; n<qr->ancount; n++)
              {
                     char   *c;

                     fprintf(f, " ");
                     print_hostname(f,
                                   rfc1035_replyhostname(qr,
                                                      qr->anptr[n]
                                                      .rrname,
                                                      namebuf));
                     fprintf(f, ".\t%s\t%s ",
                            rfc1035_fmttime(qr->anptr[n].ttl, timebuf),
                            rfc1035_class_itostr(qr->anptr[n].rrclass));

                     rfc1035_type_itostr(qr->anptr[n].rrtype, tostr_callback,
                                       &f);

                     c=rfc1035_dumprrdata(qr, qr->anptr+n);
                     if (c)
                     {
                            fprintf(f, "\t%s", c);
                            free(c);
                     }
                     fprintf(f, "\n");
              }
       }
       fprintf(f, "\n;;AUTHORITATIVE:\n");
       for (n=0; n<r->nscount; n++)
       {
              char   *c;

              fprintf(f, " ");
              print_hostname(f, rfc1035_replyhostname(r,
                                                 r->nsptr[n].rrname,
                                                 namebuf));
              fprintf(f, ".\t%s\t%s ",
                     rfc1035_fmttime(r->nsptr[n].ttl, timebuf),
                     rfc1035_class_itostr(r->nsptr[n].rrclass));

              rfc1035_type_itostr(r->nsptr[n].rrtype, tostr_callback, &f);

              c=rfc1035_dumprrdata(r, r->nsptr+n);
              if (c)
              {
                     fprintf(f, "\t%s", c);
                     free(c);
              }
              fprintf(f, "\n");
       }

       fprintf(f, "\n;;ADDITIONAL:\n");
       for (n=0; n<r->arcount; n++)
       {
              char   *c;

              if (r->arptr[n].rrtype == RFC1035_TYPE_OPT)
                     continue;

              fprintf(f, " ");
              print_hostname(f, rfc1035_replyhostname(r,
                                                 r->arptr[n].rrname,
                                                 namebuf));
              fprintf(f, ".\t%s\t%s ",
                     rfc1035_fmttime(r->arptr[n].ttl, timebuf),
                     rfc1035_class_itostr(r->arptr[n].rrclass));

              rfc1035_type_itostr(r->arptr[n].rrtype, tostr_callback, &f);

              c=rfc1035_dumprrdata(r, r->arptr+n);
              if (c)
              {
                     fprintf(f, "\t%s", c);
                     free(c);
              }
              fprintf(f, "\n");
       }
}

Here is the call graph for this function:

Here is the caller graph for this function:

char* rfc1035_dumprrdata ( struct rfc1035_reply ,
struct rfc1035_rr  
)

Definition at line 266 of file rfc1035dumprrdata.c.

{
       if (rr->rrclass != RFC1035_CLASS_IN)      return (0);
       switch (rr->rrtype)  {
       case RFC1035_TYPE_A:
              {
              char   ipbuf[RFC1035_NTOABUFSIZE];

                     rfc1035_ntoa_ipv4(&rr->rr.inaddr, ipbuf);
                     return (strdup(ipbuf));
              }
#if    RFC1035_IPV6
       case RFC1035_TYPE_AAAA:
              {
              char   ipbuf[INET6_ADDRSTRLEN];

                     if (inet_ntop(AF_INET6, &rr->rr.in6addr,
                            ipbuf, sizeof(ipbuf)) == 0)
                            ipbuf[0]=0;
                     return (strdup(ipbuf));
              }
#endif
       case RFC1035_TYPE_TXT:
              return (dumptxt(r, rr));
       case RFC1035_TYPE_CNAME:
       case RFC1035_TYPE_MB:
       case RFC1035_TYPE_MG:
       case RFC1035_TYPE_MR:
       case RFC1035_TYPE_MD:
       case RFC1035_TYPE_MF:
       case RFC1035_TYPE_NS:
       case RFC1035_TYPE_PTR:
              {
              char   p[RFC1035_MAXNAMESIZE+1], *q;

                     rfc1035_replyhostname(r, rr->rr.domainname, p);

                     if ((q=(char *)malloc(strlen(p)+2)) != 0)
                            strcat(strcpy(q, p), ".");
                     return (q);
              }

       case RFC1035_TYPE_SOA:
              return (dumpsoa(r, rr));
              break;
       case RFC1035_TYPE_MX:

              {
              char   p[RFC1035_MAXNAMESIZE+1], *q;

                     rfc1035_replyhostname(r, rr->rr.mx.mx_label, p);

                     if ((q=(char *)malloc(strlen(p)+40)) != 0)
                     {
                            sprintf(q, "%d %s.",
                                   (int)rr->rr.mx.preference, p);
                     }
                     return (q);
              }

       case RFC1035_TYPE_HINFO:
              {
              char *p=malloc( (int)(unsigned char)*rr->rr.hinfo.hinfo_str+
                            (int)(unsigned char)*rr->rr.hinfo.os_str+10);

                     if (p)
                     {
                     const char *q=rr->rr.hinfo.hinfo_str;

                            *p=0;
                            str_cat(p, &q);
                            strcat(p, ", ");
                            q=rr->rr.hinfo.os_str;
                            str_cat(p, &q);
                     }
                     return (p);
              }
       case RFC1035_TYPE_MINFO:
              {
              char   p[RFC1035_MAXNAMESIZE+1], t[RFC1035_MAXNAMESIZE+1], *q;

                     rfc1035_replyhostname(r, rr->rr.minfo.rmailbx_label, p);
                     rfc1035_replyhostname(r, rr->rr.minfo.emailbx_label, t);

                     if ((q=(char *)malloc(strlen(p)+strlen(t)+4)) == 0)
                            return (0);
                     strcat(strcat(strcat(strcpy(q, p), ". "), t), ".");
                     return (q);
              }

       case RFC1035_TYPE_RRSIG:
              {
                     time_t now=time(NULL);

                     size_t n=fmt_rrsig(r, rr, now, NULL);
                     char *p;

                     if ((p=malloc(n+1)) == 0)
                            return (0);

                     fmt_rrsig(r, rr, now, p);

                     p[n]=0;
                     return p;
              }
       }
       return (0);
}

Here is the call graph for this function:

Here is the caller graph for this function:

const char* rfc1035_fmttime ( unsigned  long,
char *   
)

Definition at line 10 of file rfc1035fmttime.c.

{
unsigned long s,m,h;

       s = n % 60; n=n/60;
       m = n % 60; n=n/60;
       h = n % 24; n=n/24;

       buf[0]='\0';
       if (n) sprintf(buf,"%lud",n);
       if (n || h)   sprintf(buf+strlen(buf), "%luh", h);
       if (n || h || m)     sprintf(buf+strlen(buf), "%lum", m);
       sprintf(buf+strlen(buf), "%lus", s);
       return (buf);
}

Here is the caller graph for this function:

int rfc1035_hostnamecmp ( const char *  ,
const char *   
)

Definition at line 294 of file rfc1035.c.

{
       while (*p || *q)
       {
              if (*p == '.' || *q == '.' )
              {
                     if ( (*p && *p != '.') || (*q && *q != '.'))
                            return (1);
                     while (*p == '.')    ++p;
                     while (*q == '.')    ++q;
                     continue;
              }
              if (!*p || !*q)      return (1);
              if ( tl(*p) != tl(*q))      return (1);
              ++p;
              ++q;
       }
       return (0);
}

Here is the call graph for this function:

Here is the caller graph for this function:

struct rfc1035_ifconf* rfc1035_ifconf ( int *  errflag) [read]

Definition at line 164 of file rfc1035ifconf.c.

{
       if (errflag)
              *errflag=0;
       return NULL;
}

Here is the caller graph for this function:

void rfc1035_ifconf_free ( struct rfc1035_ifconf ifconf_list)

Definition at line 172 of file rfc1035ifconf.c.

{
       while (ifconf_list)
       {
              struct rfc1035_ifconf *p=ifconf_list->next;

              free(ifconf_list->ifname);
              free(ifconf_list);
              ifconf_list=p;
       }
}
void rfc1035_init_dnssec_enable ( struct rfc1035_res ,
int   
)

Definition at line 107 of file rfc1035.c.

{
       rfc1035_init_edns_payload(res, flag ? 1280:0);
}

Here is the call graph for this function:

Here is the caller graph for this function:

void rfc1035_init_edns_payload ( struct rfc1035_res ,
int   
)

Definition at line 113 of file rfc1035.c.

{
       res->dnssec_payload_size=payload_size;
}

Here is the caller graph for this function:

void rfc1035_init_norecursive ( struct rfc1035_res ,
int   
)
void rfc1035_init_ns ( struct rfc1035_res ,
const RFC1035_ADDR *  ,
unsigned   
)

Definition at line 47 of file rfc1035.c.

{
unsigned i;
unsigned j;

       j=0;

       random128_binary(&res->randseed);
       md5_digest(&res->randseed, sizeof(res->randseed), res->randbuf);
       res->randptr=0;

       for (i=0; i == 0 || (i<n && i<RFC1035_MAXNS); i++)
       {
#if RFC1035_IPV6
       struct in6_addr sin;

              if (n == 0)
                     sin=in6addr_loopback;
              else
                     sin=a[(j+i)%n];

#else
       struct in_addr sin;

              if (n == 0)
              {
                     rfc1035_aton("127.0.0.1", &sin);
              }
              else
                     sin=a[(j+i)%n];
              memset(&res->nameservers[i], 0, sizeof(res->nameservers[i]));
              res->nameservers[i]=sin;
#endif
              res->nameservers[i]=sin;
       }
       res->rfc1035_nnameservers=i;

}

Here is the call graph for this function:

Here is the caller graph for this function:

void rfc1035_init_resolv ( struct rfc1035_res )

Definition at line 126 of file rfc1035.c.

{
FILE   *fp=fopen("/etc/resolv.conf", "r");
char rfc1035_buf[512];
RFC1035_ADDR ns[RFC1035_MAXNS];
int nns=0;

       memset(res, 0, sizeof(*res));

       while (fp && fgets(rfc1035_buf, sizeof(rfc1035_buf), fp))
       {
       char   *p;

              for (p=rfc1035_buf; *p; p++)
                     *p=tl(*p);

              for (p=rfc1035_buf; *p; p++)
                     if (ISSPACE(*p))     break;
              if (*p)       *p++=0;

              if (strcmp(rfc1035_buf, "domain") == 0)
              {
                     while (p && ISSPACE(*p))
                            ++p;
                     rfc1035_init_defaultdomain(res, p);
                     continue;
              }

              if (strcmp(rfc1035_buf, "nameserver"))    continue;
              while (*p && ISSPACE(*p))   p++;
              if (nns < RFC1035_MAXNS)
              {
              char   *q;

                     for (q=p; *q && !ISSPACE(*q); q++)
                            ;
                     *q=0;

                     if (rfc1035_aton(p, &ns[nns++]) < 0)
                            --nns;
              }
       }
       if (fp) fclose(fp);

       rfc1035_init_ns(res, ns, nns);
}

Here is the call graph for this function:

Here is the caller graph for this function:

void rfc1035_init_timeout ( struct rfc1035_res ,
unsigned  ,
unsigned   
)

Definition at line 41 of file rfc1035.c.

{
       res->rfc1035_timeout_initial=s;
       res->rfc1035_timeout_backoff=n;
}
int rfc1035_mkaddress ( int  af,
RFC1035_NETADDR *  buf,
const RFC1035_ADDR *  addr,
int  port,
const struct sockaddr **  ptr,
int *  len 
)

Definition at line 19 of file rfc1035mkaddress.c.

{
struct sockaddr_in sin;

#if    RFC1035_IPV6

       if (af == AF_INET6)
       {
       struct sockaddr_in6 sin6;

              memset(&sin6, 0, sizeof(sin6));
              sin6.sin6_family=af;
              sin6.sin6_addr= *addr;
              sin6.sin6_port=port;
              memcpy(buf, &sin6, sizeof(sin6));
              *ptr=(struct sockaddr *)buf;
              *len=sizeof(sin6);
              return (0);
       }

       if (af != AF_INET || (!IN6_IS_ADDR_V4MAPPED(addr) && memcmp(addr, &in6addr_any, sizeof(*addr))))
       {
              errno=EAFNOSUPPORT;
              return (-1);
       }

       memset(&sin, 0, sizeof(sin));
       sin.sin_family=af;
       rfc1035_ipv6to4(&sin.sin_addr, addr);
       sin.sin_port=port;
#else
       if (af != AF_INET)
       {
              errno=EINVAL;
              return (-1);
       }
       memset(&sin, 0, sizeof(sin));
       sin.sin_family=af;
       sin.sin_addr= *addr;
       sin.sin_port=port;
#endif
       memcpy(buf, &sin, sizeof(sin));
       *ptr=(struct sockaddr *)buf;
       *len=sizeof(sin);
       return (0);
}

Here is the caller graph for this function:

int rfc1035_mkquery ( struct rfc1035_res ,
unsigned  ,
#define RFC1035_RESOLVE_RECURSIVE const struct rfc1035_query ,
unsigned  ,
void(*)(const char *, unsigned, void *)  ,
void *   
)
int rfc1035_mksocket ( int  sock_type,
int  sock_protocol,
int *  af 
)

Definition at line 19 of file rfc1035mksocket.c.

{
#if    RFC1035_IPV6
       int    s;
       int    on=0;

       *af=AF_INET6;
       if ( (s=socket(PF_INET6, sock_type, sock_protocol)) >= 0)
       {
#ifdef IPV6_V6ONLY

              setsockopt(s, IPPROTO_IPV6, IPV6_V6ONLY,
                        (char *)&on, sizeof(on));
#endif

              return (s);
       }
#endif
       *af=AF_INET;
       return (socket(PF_INET, sock_type, sock_protocol));
}

Here is the caller graph for this function:

void rfc1035_ntoa ( const RFC1035_ADDR *  ,
char *   
)

Definition at line 41 of file rfc1035an.c.

{
#if    RFC1035_IPV6
       inet_ntop(AF_INET6, in, buf, RFC1035_MAXNAMESIZE+1);
#else
       rfc1035_ntoa_ipv4(in, buf);
#endif
}

Here is the call graph for this function:

Here is the caller graph for this function:

void rfc1035_ntoa_ipv4 ( const struct in_addr in,
char *  buf 
)

Definition at line 14 of file rfc1035an.c.

{
union  {
       unsigned char addr[4];
       RFC1035_UINT32 n;
       } u;

int    i;
char   *p;
char   pbuf[4];

       u.n=in->s_addr;
       for (i=0; i<4; i++)
       {
              if (i) *buf++='.';
              p=pbuf+3;
              *p=0;
              do
              {
                     *--p = '0' + (u.addr[i] % 10);
              } while ( (u.addr[i] /= 10) != 0);
              while (*p)
                     *buf++ = *p++;
       }
       *buf=0;
}

Here is the caller graph for this function:

const char* rfc1035_opcode_itostr ( int  )

Definition at line 107 of file rfc1035str.c.

{
unsigned i;

       for (i=0; i<sizeof(opcodetab)/sizeof(opcodetab[0]); i++)
              if (opcodetab[i].num == n) return (opcodetab[i].name);
       return ("unknown");
}

Here is the caller graph for this function:

int rfc1035_opcode_strtoi ( const char *  )

Definition at line 116 of file rfc1035str.c.

{
unsigned i;

       for (i=0; i<sizeof(opcodetab)/sizeof(opcodetab[0]); i++)
              if (COMPARE(opcodetab[i].name, n) == 0)
                            return (opcodetab[i].num);
       return (-1);
}
int rfc1035_open_tcp ( struct rfc1035_res ,
const RFC1035_ADDR *   
)

Definition at line 31 of file rfc1035tcp.c.

{
RFC1035_NETADDR addrbuf;
int    af;
const struct sockaddr *addrptr;
int    addrptrlen;

int    fd=rfc1035_mksocket(SOCK_STREAM, 0, &af);

       if (fd < 0)   return (-1);

       if (rfc1035_mkaddress(af, &addrbuf,
              addr, htons(53),
              &addrptr, &addrptrlen))
       {
              close(fd);
              return (-1);
       }

       if (fcntl(fd, F_SETFL, fcntl(fd, F_GETFL, 0) | O_NDELAY) < 0)
       {
              sox_close(fd);
              return (-1);
       }

       if (sox_connect(fd, addrptr, addrptrlen) == 0)
              return (fd);

       if (errno == EINPROGRESS || errno == EAGAIN)
       {
       unsigned      w=res->rfc1035_timeout_initial;

              if (!w)       w=RFC1035_DEFAULT_INITIAL_TIMEOUT;
              if (rfc1035_wait_query(fd, w) == 0 &&
                     (sox_connect(fd, addrptr, addrptrlen) == 0
                            || errno == EISCONN))
              {
                     return (fd);
              }
       }
       sox_close(fd);
       return (-1);
}

Here is the call graph for this function:

Here is the caller graph for this function:

int rfc1035_open_udp ( int *  af)

Definition at line 29 of file rfc1035udp.c.

{
       return (rfc1035_mksocket(SOCK_DGRAM, 0, af));
}

Here is the call graph for this function:

Here is the caller graph for this function:

int rfc1035_ptr ( struct rfc1035_res ,
const RFC1035_ADDR *  ,
char *   
)

Definition at line 20 of file rfc1035qptr.c.

{
       return rfc1035_ptr_x(res, addr, save_name, name);
}

Here is the call graph for this function:

Here is the caller graph for this function:

int rfc1035_ptr_x ( struct rfc1035_res res,
const RFC1035_ADDR *  addr,
void(*)(const char *, void *)  cb_func,
void *  cb_arg 
)

Definition at line 45 of file rfc1035qptr.c.

{
       return (ptr(res, a, AF_INET, cb_func, cb_arg));
}

Here is the call graph for this function:

Here is the caller graph for this function:

char* rfc1035_query_tcp ( struct rfc1035_res ,
int  ,
const char *  ,
unsigned  ,
int *  ,
unsigned   
)

Definition at line 183 of file rfc1035tcp.c.

{
char   *p;

       if ( rfc1035_send_tcp(fd, query, query_len) < 0 ||
              (p=rfc1035_recv_tcp(res, fd, buflen, s)) == 0)
              return (0);
       return (p);
}

Here is the call graph for this function:

Here is the caller graph for this function:

char* rfc1035_query_udp ( struct rfc1035_res ,
int  ,
const struct sockaddr ,
int  ,
const char *  ,
unsigned  ,
int *  ,
unsigned   
)

Definition at line 139 of file rfc1035udp.c.

{
time_t current_time, final_time;
char   *rc;

       time(&current_time);

       if (rfc1035_send_udp(fd, sin, sin_len, query, query_len))
              return (0);

       final_time=current_time+w;

       while (current_time < final_time)
       {
              if (rfc1035_wait_reply(fd, final_time-current_time))
                     break;

              rc=rfc1035_recv_udp(fd, sin, sin_len, buflen, query);
              if (rc)       return (rc);

              if (errno != EAGAIN) break;

              time(&current_time);
       }
       errno=EAGAIN;
       return (0);
}

Here is the call graph for this function:

Here is the caller graph for this function:

const char* rfc1035_rcode_itostr ( int  )

Definition at line 126 of file rfc1035str.c.

{
unsigned i;

       for (i=0; i<sizeof(rcodetab)/sizeof(rcodetab[0]); i++)
              if (rcodetab[i].num == n) return (rcodetab[i].name);
       return ("unknown");
}

Here is the caller graph for this function:

int rfc1035_rcode_strtoi ( const char *  )

Definition at line 135 of file rfc1035str.c.

{
unsigned i;

       for (i=0; i<sizeof(rcodetab)/sizeof(rcodetab[0]); i++)
              if (COMPARE(rcodetab[i].name, n) == 0)
                            return (rcodetab[i].num);
       return (-1);
}
char* rfc1035_recv_tcp ( struct rfc1035_res ,
int  ,
int *  ,
unsigned   
)

Definition at line 117 of file rfc1035tcp.c.

{
int    len;
unsigned response_len;
char lenbuf[2];
char   *mallocedbuf=0;
time_t current_time, finish_time;

       time(&current_time);
       finish_time=current_time+w;

       if (rfc1035_wait_reply(fd, w))
              return (0);

       len=doread(fd, lenbuf, 2);
       if (len <= 0)
       {
              errno=EIO;
              return (0);
       }
       if (len == 1)
       {
              time(&current_time);
              if (current_time >= finish_time)   return (0);
              if (rfc1035_wait_reply(fd, finish_time - current_time))
                     return (0);

              len=doread(fd, lenbuf+1, 1);
              if (len <= 0)
              {
                     errno=EIO;
                     return (0);
              }
              ++len;
       }

       response_len= ((unsigned)(unsigned char)lenbuf[0] << 8)
                     | (unsigned char)lenbuf[1];

       if ((mallocedbuf=malloc(response_len)) == 0)
              return (0);

       *buflen=0;

       while ((unsigned)*buflen < response_len)
       {
              time(&current_time);
              if (current_time >= finish_time ||
                     rfc1035_wait_reply(fd, finish_time - current_time))
              {
                     len=0;
                     errno=ETIMEDOUT;
              }
              else
                     len=doread(fd, mallocedbuf + *buflen,
                                          response_len - *buflen);
              if (len <= 0)
              {
                     free(mallocedbuf);
                     return (0);
              }
              *buflen += len;
       }
       return (mallocedbuf);
}

Here is the call graph for this function:

Here is the caller graph for this function:

char* rfc1035_recv_udp ( int  ,
const struct sockaddr ,
int  ,
int *  ,
const char *   
)

Definition at line 55 of file rfc1035udp.c.

{
int    len;

#if    RFC1035_IPV6

struct sockaddr_storage addrfrom;

#else

struct sockaddr_in addrfrom;

#endif

socklen_t addrfromlen;
char   rfc1035_buf[512];
char   *bufptr=rfc1035_buf;
char   *mallocedbuf=0;

       *buflen=sizeof(rfc1035_buf);

       while ((len=dorecv(fd, bufptr, *buflen, MSG_PEEK, 0, 0)) >= *buflen )
       {
              if (len == *buflen)  len += 511;
              ++len;

              if (mallocedbuf)     free(mallocedbuf);
              mallocedbuf=(char *)malloc(len);
              if (!mallocedbuf)    return (0);
              bufptr= mallocedbuf;
              *buflen=len;
       }

       addrfromlen=sizeof(addrfrom);
       if (len < 0 || (len=dorecv(fd, bufptr, *buflen, 0,
              (struct sockaddr *)&addrfrom, &addrfromlen)) < 0)
       {
              if (mallocedbuf)
                     free(mallocedbuf);
              errno=EIO;
              return (0);
       }

       *buflen=len;

       if ( !rfc1035_same_ip( &addrfrom, addrfromlen,
                            addrshouldfrom, addrshouldfrom_len))
       {
              if (mallocedbuf)
                     free(mallocedbuf);

              errno=EAGAIN;
              return (0);
       }

       if ( *buflen < 2)
       {
              if (mallocedbuf)
                     free(mallocedbuf);
              errno=EIO;
              return (0);
       }

       if ( query && (bufptr[0] != query[0] || bufptr[1] != query[1]
              || (unsigned char)(bufptr[2] & 0x80) == 0 ))
       {
              if (mallocedbuf)
                     free(mallocedbuf);
              errno=EAGAIN;
              return (0);
       }
       if (!mallocedbuf)
       {
              if ((mallocedbuf=malloc( *buflen )) == 0)
                     return (0);

              memcpy(mallocedbuf, bufptr, *buflen);
              bufptr=mallocedbuf;
       }
       return (bufptr);
}

Here is the call graph for this function:

Here is the caller graph for this function:

void rfc1035_replyfree ( struct rfc1035_reply )

Definition at line 12 of file rfc1035reply.c.

{
struct rfc1035_reply *q;

       while (p)
       {
              q=p->next;
              if (p->mallocedbuf)  free(p->mallocedbuf);
              if (p->qdptr) free(p->qdptr);
              if (p->anptr) free(p->anptr);
              if (p->nsptr) free(p->nsptr);
              if (p->arptr) free(p->arptr);
              if (p->allrrs)       free(p->allrrs);
              free(p);
              p=q;
       }
}

Here is the caller graph for this function:

const char* rfc1035_replyhostname ( const struct rfc1035_reply ,
const char *  ,
char *   
)

Definition at line 78 of file rfc1035reply.c.

{
const char *p=rfc1035_replyuncompress(&n, r, namebuf);

       if (!p)       strcpy(namebuf, "error");
       return (p);
}

Here is the call graph for this function:

Here is the caller graph for this function:

struct rfc1035_reply* rfc1035_replyparse ( const char *  ,
unsigned   
) [read]

Definition at line 89 of file rfc1035reply.c.

{
struct rfc1035_reply *r=(struct rfc1035_reply *)
       malloc(sizeof(struct rfc1035_reply));
char   c;
unsigned n;
int    pass;
unsigned *lenptrs[3];
struct rfc1035_rr *rrptrs[3];
const char *end=p+l;
unsigned allcnt;

       if (!r)       return (0);
       r->next=0;
       r->reply=p;
       r->replylen=l;
       r->mallocedbuf=0;
       memset(&r->server_addr, 0, sizeof(r->server_addr));
       r->qdptr=0;
       r->anptr=0;
       r->nsptr=0;
       r->arptr=0;
       r->allrrs=0;

       if (l < 12)
       {
              errno=EINVAL;
              rfc1035_replyfree(r);
              return (0);
       }

       c=p[2];
       r->rd= c & 1;
       c >>= 1;
       r->tc= c & 1;
       c >>= 1;
       r->aa= c & 1;
       c >>= 1;
       r->opcode= c & 15;
       c >>= 4;
       r->qr= c & 1;

       r->ra=(p[3] >> 7) & 1;
       r->ad=(p[3] >> 5) & 1;
       r->cd=(p[3] >> 4) & 1;
       r->rcode=p[3] & 15;

       r->qdcount= ((unsigned)(unsigned char)p[4] << 8) | (unsigned char)p[5];
       r->ancount= ((unsigned)(unsigned char)p[6] << 8) | (unsigned char)p[7];
       r->nscount= ((unsigned)(unsigned char)p[8] << 8) | (unsigned char)p[9];
       r->arcount= ((unsigned)(unsigned char)p[10]<< 8) | (unsigned char)p[11];

       if (r->qdcount >= l || r->ancount >= l || r->nscount >= l ||
              r->arcount >= l ||
              (n=r->qdcount + r->ancount) >= l ||
              (n += r->nscount) >= l ||
              n + r->arcount >= l)
       {
              errno=EINVAL;
              rfc1035_replyfree(r);
              return (0);
       }

       if ((r->qdcount && (r->qdptr=malloc(sizeof(struct rfc1035_query)
                            * r->qdcount)) == 0) ||
              (r->ancount && (r->anptr=malloc(sizeof(struct rfc1035_rr)
                            * r->ancount)) == 0) ||
              (r->nscount && (r->nsptr=malloc(sizeof(struct rfc1035_rr)
                            * r->nscount)) == 0) ||
              (r->arcount && (r->arptr=malloc(sizeof(struct rfc1035_rr)
                            * r->arcount)) == 0) ||
              (r->ancount + r->nscount + r->arcount &&
                     (r->allrrs=malloc(sizeof(*r->allrrs)*(
                            r->ancount + r->nscount + r->arcount))) == 0)
              )
       {
              rfc1035_replyfree(r);
              return (0);
       }

       p += 12;
       l -= 12;
       for (n=0; n<r->qdcount; n++)
       {
              r->qdptr[n].name=p;
              if (rfc1035_replyuncompress( &p, r, 0 ) == 0)
              {
                     errno=EINVAL;
                     rfc1035_replyfree(r);
                     return (0);
              }

              if (p > end-4)       return (0);

              r->qdptr[n].qtype=((unsigned)(unsigned char)p[0] << 8)
                            | (unsigned char)p[1];
              p += 2;
              r->qdptr[n].qclass=((unsigned)(unsigned char)p[0] << 8)
                            | (unsigned char)p[1];
              p += 2;
       }

       lenptrs[0]= &r->ancount;
       lenptrs[1]= &r->nscount;
       lenptrs[2]= &r->arcount;
       rrptrs[0]= r->anptr;
       rrptrs[1]= r->nsptr;
       rrptrs[2]= r->arptr;

       allcnt=0;

       for (pass=0; pass<3; pass++)
       {
       struct rfc1035_rr *rrp= rrptrs[pass];

              for (n=0; n< *lenptrs[pass]; n++)
              {
                     r->allrrs[allcnt++]=rrp;
                     rrp->rrname=p;
                     if (rfc1035_replyuncompress( &p, r, 0 )
                            == 0)
                     {
                            errno=EINVAL;
                            rfc1035_replyfree(r);
                            return (0);
                     }

                     if (p > end-10)      return (0);
                     rrp->rrtype=((unsigned)(unsigned char)p[0] << 8)
                            | (unsigned char)p[1];
                     p += 2;
                     rrp->rrclass=((unsigned)(unsigned char)p[0] << 8)
                            | (unsigned char)p[1];
                     p += 2;
                     rrp->ttl=((RFC1035_UINT32)(unsigned char)p[0] << 24) |
                            ((RFC1035_UINT32)(unsigned char)p[1] << 16) |
                            ((RFC1035_UINT32)(unsigned char)p[2] << 8) |
                            (unsigned char)p[3];
                     p += 4;

                     rrp->rdlength=((unsigned)(unsigned char)p[0] << 8)
                            | (unsigned char)p[1];
                     p += 2;
                     rrp->rdata= rrp->rdlength ? p:0;
                     if (end - p < rrp->rdlength)
                     {
                            errno=EINVAL;
                            rfc1035_replyfree(r);
                            return (0);
                     }
                     p += rrp->rdlength;
                     doparse(r, rrp);
                     ++rrp;
              }
       }
       return (r);
}

Here is the call graph for this function:

Here is the caller graph for this function:

int rfc1035_replysearch_all ( const struct rfc1035_res ,
const struct rfc1035_reply ,
const char *  ,
unsigned  ,
unsigned  ,
int   
)

Definition at line 112 of file rfc1035search.c.

{
       unsigned s;

       if (res->rfc1035_defaultdomain && strchr(h, '.') == NULL)
       {
              char *buf;
              int rc;

              /* Append default domain */

              if ((buf=malloc(strlen(h)+
                            strlen(res->rfc1035_defaultdomain)+2)) == 0)
                     return (-1);

              strcat(strcat(strcpy(buf, h), "."),
                     res->rfc1035_defaultdomain);

              rc=rfc1035_replysearch_all(res, r, buf, qtype, qclass, pos);
              free(buf);
              return (rc);
       }

       s=r->ancount+r->nscount+r->arcount;

       for ( ; pos >= 0 && pos < s; pos++)
              if (found(r, r->allrrs[pos], h, qclass, qtype))  return (pos);
       return (-1);
}

Here is the call graph for this function:

Here is the caller graph for this function:

int rfc1035_replysearch_an ( const struct rfc1035_res ,
const struct rfc1035_reply ,
const char *  ,
unsigned  ,
unsigned  ,
int   
)

Definition at line 28 of file rfc1035search.c.

{
       if (res->rfc1035_defaultdomain && strchr(h, '.') == NULL)
       {
              char *buf;
              int rc;

              /* Append default domain */

              if ((buf=malloc(strlen(h)+
                            strlen(res->rfc1035_defaultdomain)+2)) == 0)
                     return (-1);

              strcat(strcat(strcpy(buf, h), "."),
                     res->rfc1035_defaultdomain);

              rc=rfc1035_replysearch_an(res, r, buf, qtype, qclass, pos);
              free(buf);
              return (rc);
       }

       for ( ; pos >= 0 && pos < r->ancount; pos++)
              if (found(r, r->anptr+pos, h, qclass, qtype))    return (pos);
       return (-1);
}

Here is the call graph for this function:

Here is the caller graph for this function:

int rfc1035_replysearch_ns ( const struct rfc1035_res ,
const struct rfc1035_reply ,
const char *  ,
unsigned  ,
unsigned  ,
int   
)

Definition at line 56 of file rfc1035search.c.

{
       if (res->rfc1035_defaultdomain && strchr(h, '.') == NULL)
       {
              char *buf;
              int rc;

              /* Append default domain */

              if ((buf=malloc(strlen(h)+
                            strlen(res->rfc1035_defaultdomain)+2)) == 0)
                     return (-1);

              strcat(strcat(strcpy(buf, h), "."),
                     res->rfc1035_defaultdomain);

              rc=rfc1035_replysearch_ns(res, r, buf, qtype, qclass, pos);
              free(buf);
              return (rc);
       }

       for ( ; pos >= 0 && pos < r->nscount; pos++)
              if (found(r, r->nsptr+pos, h, qclass, qtype))    return (pos);
       return (-1);
}

Here is the call graph for this function:

Here is the caller graph for this function:

const char* rfc1035_replyuncompress ( const char **  ,
const struct rfc1035_reply ,
char *   
)

Definition at line 30 of file rfc1035reply.c.

{
unsigned i=0;
unsigned l;
const char *end=reply->reply+reply->replylen;
const char *newptr=0;
int    cnt=0;

       for (;;)
       {
              if ( (*ptr) == end)  return (0);
              l=(unsigned char)*(*ptr)++;
              if (l > 63)
              {
                     if ((l & 0xC0) != 0xC0)     return (0);
                     if ( (*ptr) == end)  return (0);
                     l= ((l & 63) << 8) + (unsigned char)*(*ptr)++;
                     if (l >= reply->replylen)   return (0);
                     ptr= &newptr;
                     newptr=reply->reply+l;
                     if ( ++cnt > 100)    return (0);
                                          /* Detect loops */

                     continue;
              }
              if (l == 0)   break;
              if (i)
              {
                     if (i >= RFC1035_MAXNAMESIZE)      return (0);
                     if (namebuf) namebuf[i]='.';
                     ++i;
              }
              if (RFC1035_MAXNAMESIZE-i < l)     return (0);

              if (reply->reply + reply->replylen - (*ptr) < l)
                     return (0);

              if (namebuf)
                     memcpy(namebuf+i, *ptr, l);
              i += l;
              *ptr += l;
       }

       if (namebuf)  namebuf[i]=0;
       return (namebuf ? namebuf:"");
}

Here is the caller graph for this function:

struct rfc1035_reply* rfc1035_resolve ( struct rfc1035_res ,
int  ,
const char *  ,
unsigned  ,
unsigned   
) [read]

Definition at line 223 of file rfc1035resolve.c.

{
struct rfc1035_query q;

       q.name=name;
       q.qtype=qtype;
       q.qclass=qclass;
       return (rfc1035_resolve_multiple(res, opcode, &q, 1));
}

Here is the call graph for this function:

Here is the caller graph for this function:

int rfc1035_resolve_cname ( struct rfc1035_res ,
char *  ,
unsigned  ,
unsigned  ,
struct rfc1035_reply **  ,
int   
)

Definition at line 144 of file rfc1035search.c.

{
int    n;
int    recursion_count=10;

       if ( (*ptr=rfc1035_resolve(res, RFC1035_OPCODE_QUERY,
                     namebuf, qtype, qclass)) == 0)
              return (-1);

       if (x_flags && RFC1035_X_RANDOMIZE &&
           (*ptr)->rcode == RFC1035_RCODE_NOERROR)
              rfc1035_rr_rand(*ptr);

       if ( (*ptr)->rcode != RFC1035_RCODE_NOERROR ||
              (n=rfc1035_replysearch_an( res,
                                      *ptr, namebuf, qtype, qclass, 0))<0)
              return (-1);

       if ( (*ptr)->anptr[n].rrtype == qtype)    return (n);

       /* Must've gotten back a CNAME when we were looking for something else
       */

       for (;;)
       {

              if (rfc1035_replyhostname( *ptr, (*ptr)->anptr[n].rr.domainname,
                     namebuf) == 0)
              {
                     rfc1035_replyfree( *ptr );
                     *ptr=0;
                     return (-1);
              }

       /* Let's see if we already have the answer for the canonical name */

              if ( (n=rfc1035_replysearch_all( res, *ptr, namebuf, qtype,
                            qclass, 0)) >= 0)
              {
                     if ( (*ptr)->anptr[n].rrtype == qtype)    return (n);
                     if ( --recursion_count > 0)
                            continue;

                     rfc1035_replyfree( *ptr );  /* Recursive CNAME */
                     *ptr=0;
                     return (RFC1035_ERR_CNAME_RECURSIVE);
              }

              rfc1035_replyfree( *ptr );
              if ( (*ptr=rfc1035_resolve(res, RFC1035_OPCODE_QUERY,
                            namebuf, qtype, qclass)) == 0)
                     return (-1);

              if ( (*ptr)->rcode == RFC1035_RCODE_NOERROR &&
                     (n=rfc1035_replysearch_an( res, *ptr, namebuf,
                            qtype, qclass, 0)) >= 0)
              {
                     if ( (*ptr)->anptr[n].rrtype == qtype)    return (n);
                     if ( --recursion_count > 0)
                            continue;
                     rfc1035_replyfree( *ptr );  /* Recursive CNAME */
                     *ptr=0;
                     return (RFC1035_ERR_CNAME_RECURSIVE);
              }
              return (-1);
       }
}

Here is the call graph for this function:

Here is the caller graph for this function:

struct rfc1035_reply* rfc1035_resolve_multiple ( struct rfc1035_res ,
int  ,
const struct rfc1035_query ,
unsigned   
) [read]

Definition at line 33 of file rfc1035resolve.c.

{
struct querybuf qbuf;
int    udpfd;
int    attempt;
const RFC1035_ADDR *ns;
unsigned nscount;
unsigned current_timeout, timeout_backoff;
unsigned nbackoff, backoff_num;
int    af;
static const char fakereply[]={0, 0, 0, RFC1035_RCODE_SERVFAIL,
              0, 0,
              0, 0,
              0, 0,
              0, 0};

       nscount=res->rfc1035_nnameservers;
       ns=res->nameservers;

       if (res->rfc1035_good_ns >= nscount)
              res->rfc1035_good_ns=0;

       qbuf.qbuflen=0;
       if ( rfc1035_mkquery(res,
              opcode, queries, nqueries, &putqbuf, &qbuf))
       {
              errno=EINVAL;
              return (0);
       }

       /* Prepare the UDP socket */

       if ((udpfd=rfc1035_open_udp(&af)) < 0)    return (0);

       /* Keep trying until we get an answer from a nameserver */

       current_timeout=res->rfc1035_timeout_initial;
       nbackoff=res->rfc1035_timeout_backoff;
       if (!current_timeout)       current_timeout=RFC1035_DEFAULT_INITIAL_TIMEOUT;
       if (!nbackoff)       nbackoff=RFC1035_DEFAULT_MAXIMUM_BACKOFF;

       timeout_backoff=current_timeout;
    for (backoff_num=0; backoff_num < nbackoff; backoff_num++,
                                   current_timeout *= timeout_backoff)


       for ( attempt=0; attempt < nscount; ++attempt)
       {
       int    nbytes;
       char   *reply;
       struct rfc1035_reply *rfcreply=0;

       const RFC1035_ADDR *sin=&ns[(res->rfc1035_good_ns+attempt) % nscount];
       int    sin_len=sizeof(*sin);

       int    dotcp=0, isaxfr=0;
       unsigned i;

              for (i=0; i<nqueries; i++)
                     if (queries[i].qtype == RFC1035_TYPE_AXFR)
                     {
                            dotcp=1;
                            isaxfr=1;
                            break;
                     }

              if (isaxfr && nqueries > 1)
                     return (rfc1035_replyparse(fakereply,
                            sizeof(fakereply)));

              if (!dotcp)
              {
              /* Send the query via UDP */
              RFC1035_NETADDR      addrbuf;
              const struct sockaddr *addrptr;
              int    addrptrlen;

                     if (rfc1035_mkaddress(af, &addrbuf,
                            sin, htons(53),
                            &addrptr, &addrptrlen))
                            continue;

                     if ((reply=rfc1035_query_udp(res, udpfd, addrptr,
                            addrptrlen, qbuf.qbuf, qbuf.qbuflen, &nbytes,
                                   current_timeout)) == 0)
                            continue;

                     res->rfc1035_good_ns= (res->rfc1035_good_ns + attempt) %
                                   nscount;

              /* Parse the reply */

                     rfcreply=rfc1035_replyparse(reply, nbytes);
                     if (!rfcreply)
                     {
                            free(reply);
                            if (errno == ENOMEM) break;
                            continue;
                     /* Bad response from the server, try the next one. */
                     }
                     rfcreply->mallocedbuf=reply;
              /*
              ** If the reply came back with the truncated bit set,
              ** retry the query via TCP.
              */

                     if (rfcreply->tc)
                     {
                            dotcp=1;
                            rfc1035_replyfree(rfcreply);
                     }
              }

              if (dotcp)
              {
              int    tcpfd;
              struct rfc1035_reply *firstreply=0, *lastreply=0;

                     if ((tcpfd=rfc1035_open_tcp(res, sin)) < 0)
                            continue;     /*
                                          ** Can't connect via TCP,
                                          ** try the next server.
                                          */

                     reply=rfc1035_query_tcp(res, tcpfd, qbuf.qbuf,
                            qbuf.qbuflen, &nbytes, current_timeout);

                     if (!reply)
                     {
                            sox_close(tcpfd);
                            continue;
                     }

                     res->rfc1035_good_ns= (res->rfc1035_good_ns
                                   + attempt) % nscount;

                     rfcreply=rfc1035_replyparse(reply, nbytes);
                     if (!rfcreply)
                     {
                            free(reply);
                            sox_close(tcpfd);
                            continue;
                     }
                     rfcreply->mallocedbuf=reply;
                     firstreply=lastreply=rfcreply;
                     while (isaxfr && rfcreply->rcode == 0)
                     {
                            if ((reply=rfc1035_recv_tcp(res,
                                   tcpfd, &nbytes, current_timeout))==0)
                                   break;
                            
                            rfcreply=rfc1035_replyparse(reply, nbytes);
                            if (!rfcreply)
                            {
                                   free(reply);
                                   rfc1035_replyfree(firstreply);
                                   firstreply=0;
                                   break;
                            }
                            rfcreply->mallocedbuf=reply;
                            lastreply->next=rfcreply;
                            lastreply=rfcreply;

                            if ( rfcreply->ancount &&
                                   rfcreply->anptr[0].rrtype ==
                                          RFC1035_TYPE_SOA)
                                   break;
                     }
                     sox_close(tcpfd);
                     if (!firstreply)
                            return (0);
                     rfcreply=firstreply;
              }
              memcpy(&rfcreply->server_addr, sin, sin_len);
              sox_close(udpfd);
              return (rfcreply);
       }

       /*
       ** Return a fake server failure reply, when we couldn't contact
       ** any name server.
       */
       sox_close(udpfd);
       return (rfc1035_replyparse(fakereply, sizeof(fakereply)));
}

Here is the call graph for this function:

Here is the caller graph for this function:

int rfc1035_rr_gettxt ( struct rfc1035_rr ,
int  ,
char  buf[256] 
)

Definition at line 10 of file rfc1035gettxt.c.

{
unsigned l;

       if (startpos < 0 || (unsigned)startpos >= p->rdlength ||
              p->rdlength - (unsigned)startpos <=
                     (l=(unsigned)(unsigned char)p->rdata[startpos]))
       {
              buf[0]=0;
              return (-1);
       }

       ++startpos;

       memcpy(buf, p->rdata + startpos, l);
       buf[l]=0;
       startpos += l;
       if (startpos >= p->rdlength)
              startpos= -1;
       return (startpos);
}

Here is the caller graph for this function:

void rfc1035_rr_rand ( struct rfc1035_reply rr)

Definition at line 474 of file rfc1035reply.c.

Here is the call graph for this function:

Here is the caller graph for this function:

void rfc1035_rr_rand_an ( struct rfc1035_reply rr)

Definition at line 459 of file rfc1035reply.c.

{
       rr_random(rr->anptr, rr->ancount);
}

Here is the call graph for this function:

Here is the caller graph for this function:

void rfc1035_rr_rand_ar ( struct rfc1035_reply rr)

Definition at line 469 of file rfc1035reply.c.

{
       rr_random(rr->arptr, rr->arcount);
}

Here is the call graph for this function:

Here is the caller graph for this function:

void rfc1035_rr_rand_ns ( struct rfc1035_reply rr)

Definition at line 464 of file rfc1035reply.c.

{
       rr_random(rr->nsptr, rr->nscount);
}

Here is the call graph for this function:

Here is the caller graph for this function:

int rfc1035_same_ip ( const void *  ,
int  ,
const void *  ,
int   
)

Definition at line 40 of file rfc1035sameip.c.

{
       if ( ((const struct sockaddr_in *)a)->sin_family != AF_INET ||
              ((const struct sockaddr_in *)b)->sin_family != AF_INET ||
              al < sizeof(struct sockaddr_in) ||
              bl < sizeof(struct sockaddr_in))
       {
              return (0);
       }

       return ( ((const struct sockaddr_in *)a)->sin_addr.s_addr ==
              ((const struct sockaddr_in *)b)->sin_addr.s_addr);
}

Here is the caller graph for this function:

int rfc1035_send_tcp ( int  ,
const char *  ,
unsigned   
)

Definition at line 75 of file rfc1035tcp.c.

{
int    n=query_len+2;
char   *buf=malloc(n);
char   *p;
int    pl;

       if (!buf)     return (-1);

       buf[0]=query_len >> 8;
       buf[1]=query_len;

       memcpy(buf+2, query, query_len);

       p=buf;
       pl=n;
       while (pl)
       {
       int    i=sox_write(fd, p, pl);

              if (i < 0 && errno == EINTR)       continue;
              if (i <= 0)   break;
              p += i;
              pl -= i;
       }
       free(buf);

       if (pl)       return (-1);
       return (0);
}

Here is the caller graph for this function:

int rfc1035_send_udp ( int  ,
const struct sockaddr ,
int  ,
const char *  ,
unsigned   
)

Definition at line 34 of file rfc1035udp.c.

{
       if (sox_sendto(fd, (const char *)query, query_len, 0,
              sin, sin_len) == query_len)
              return (0);
       return (-1);
}

Here is the caller graph for this function:

int rfc1035_sockaddrip ( const RFC1035_NETADDR *  ,
int  ,
RFC1035_ADDR *   
)

Definition at line 14 of file rfc1035sockaddrip.c.

{
int    af=((const struct sockaddr_in *)a)->sin_family;

       if ( af == AF_INET )
       {
              if (al >= sizeof(struct sockaddr_in))
              {
#if RFC1035_IPV6
                     rfc1035_ipv4to6(ip,
                            &((const struct sockaddr_in *)a)->sin_addr);
#else
                     *ip=((const struct sockaddr_in *)a)->sin_addr;
#endif
                     return (0);
              }
       }

#if RFC1035_IPV6

       if ( af == AF_INET6 )
       {
              if (al >= sizeof(struct sockaddr_in6))
              {
                     *ip=((const struct sockaddr_in6 *)a)->sin6_addr;
                     return (0);
              }
       }
#endif
       return (-1);
}

Here is the caller graph for this function:

int rfc1035_sockaddrport ( const RFC1035_NETADDR *  ,
int  ,
int *   
)

Definition at line 13 of file rfc1035sockaddrport.c.

{
int    af=((const struct sockaddr_in *)a)->sin_family;

       if ( af == AF_INET )
       {
              if (al >= sizeof(struct sockaddr_in))
              {
                     *port=((const struct sockaddr_in *)a)->sin_port;
                     return (0);
              }
       }

#if RFC1035_IPV6

       if ( af == AF_INET6 )
       {
              if (al >= sizeof(struct sockaddr_in6))
              {
                     *port=((const struct sockaddr_in6 *)a)->sin6_port;
                     return (0);
              }
       }
#endif
       return (-1);
}

Here is the caller graph for this function:

void rfc1035_type_itostr ( int  ,
void(*)(const char *, void *)  ,
void *   
)

Definition at line 61 of file rfc1035str.c.

{
       unsigned i;
       char buf[30];

       for (i=0; i<sizeof(typetab)/sizeof(typetab[0]); i++)
              if (typetab[i].num == n)
              {
                     (*func)(typetab[i].name, arg);
                     return;
              }

       snprintf(buf, sizeof(buf), "TYPE%d", n);

       buf[sizeof(buf)-1]=0;

       (*func)(buf, arg);
}

Here is the caller graph for this function:

int rfc1035_type_strtoi ( const char *  )

Definition at line 80 of file rfc1035str.c.

{
unsigned i;

       for (i=0; i<sizeof(typetab)/sizeof(typetab[0]); i++)
              if (COMPARE(typetab[i].name, n) == 0) return (typetab[i].num);
       return (-1);
}

Here is the caller graph for this function:

int rfc1035_wait_query ( int  ,
unsigned   
)

Definition at line 476 of file rfc1035.c.

{
fd_set fds;
struct timeval tv;
int    n;

       FD_ZERO(&fds);
       FD_SET(fd, &fds);
       tv.tv_sec=nsecs;
       tv.tv_usec=0;
       while ((n=sox_select(fd+1, 0, &fds, 0, &tv)) < 0)
       {
              if (errno != EINTR)
                     break;
       }

       if (n > 0 && FD_ISSET(fd, &fds))
              return (0);
       errno=ETIMEDOUT;
       return (-1);
}

Here is the caller graph for this function:

int rfc1035_wait_reply ( int  ,
unsigned   
)

Definition at line 454 of file rfc1035.c.

{
fd_set fds;
struct timeval tv;
int    n;

       FD_ZERO(&fds);
       FD_SET(fd, &fds);
       tv.tv_sec=nsecs;
       tv.tv_usec=0;
       while ((n=sox_select(fd+1, &fds, 0, 0, &tv)) < 0)
       {
              if (errno != EINTR)
                     break;
       }

       if (n > 0 && FD_ISSET(fd, &fds))
              return (0);
       errno=ETIMEDOUT;
       return (-1);
}

Here is the caller graph for this function: