Back to index

courier  0.68.2
Functions
rfc1035qa.c File Reference
#include "rfc1035.h"
#include <errno.h>
#include <string.h>
#include <stdlib.h>
#include <arpa/inet.h>

Go to the source code of this file.

Functions

int rfc1035_a (struct rfc1035_res *res, const char *name, RFC1035_ADDR **iaptr, unsigned *iasize)

Function Documentation

int rfc1035_a ( struct rfc1035_res res,
const char *  name,
RFC1035_ADDR **  iaptr,
unsigned *  iasize 
)

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: