Back to index

opendkim  2.6.4
Functions | Variables
manual.h File Reference
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <time.h>
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

int ar_res_parse (int *, struct sockaddr_in *, int *, long *)

Variables

static char manual_h_id [] = "@(#)$Id: manual.h,v 1.4 2009/12/10 22:17:30 cm-msk Exp $"

Function Documentation

int ar_res_parse ( int *  ,
struct sockaddr_in *  ,
int *  ,
long *   
)

Definition at line 71 of file manual.c.

{
       int data;
       int ns = 0;
       FILE *f;
       char *p;
       char *q;
       char *r;
       struct servent *srv;
       char buf[BUFRSZ];

       assert(out != NULL);
       assert(retry != NULL);
       assert(retrans != NULL);

       srv = getservbyname(SERVICE, PROTOCOL);
       if (srv == NULL)
              return -1;

       f = fopen(_PATH_RESCONF, "r");
       if (f == NULL)
       {
              struct sockaddr *sa;
              struct sockaddr_in *sin;

              /* apply defaults */
#ifdef AF_INET6
              sa = (struct sockaddr *) &out[0];
              sin = (struct sockaddr_in *) sa;
              sin->sin_family = AF_INET;
              sin->sin_port = srv->s_port;
              sin->sin_addr.s_addr = htonl(INADDR_LOOPBACK);
#else /* AF_INET6 */
              out[0].sin_family = AF_INET;
              out[0].sin_port = srv->s_port;
              out[0].sin_addr.s_addr = htonl(INADDR_LOOPBACK);
#endif /* AF_INET6 */

              ns = 1;

              *nscount = ns;

              return 0;
       }

       clearerr(f);
       while (fgets(buf, sizeof buf, f) != NULL)
       {
              /* chomp at \n, #, or ; */
              for (p = buf; *p != '\0'; p++)
              {
                     if (*p == '\n' || *p == ';' || *p == '#')
                     {
                            *p = '\0';
                            break;
                     }
              }

              /* now eat leading and trailing spaces */
              data = 0;
              r = NULL;
              for (p = buf, q = buf; *p != '\0'; p++)
              {
                     if (data == 0 && isascii(*p) && isspace(*p))
                            continue;

                     data = 1;
                     *q = *p;
                     if (!(isascii(*p) && isspace(*p)))
                            r = q;
                     q++;
              }
              if (r != NULL)
                     *(r + 1) = '\0';

              /* use the data */
              if (strncasecmp(buf, "nameserver", 10) == 0)
              {
                     struct in_addr addr;
#ifdef AF_INET6
                     struct in6_addr addr6;
                     struct sockaddr *sa;
                     struct sockaddr_in *sin;
                     struct sockaddr_in6 *sin6;
#endif /* AF_INET6 */

                     for (p = &buf[10]; *p != '\0'; p++)
                     {
                            if (!isascii(*p) || !isspace(*p))
                                   break;
                     }

                     if (*p == '\0')
                            continue;

#ifdef AF_INET6
                     sa = (struct sockaddr *) &out[ns];
                     if (inet_pton(AF_INET, p, (void *) &addr) == 1)
                     {
                            sin = (struct sockaddr_in *) sa;

                            memcpy(&sin->sin_addr, &addr,
                                   sizeof sin->sin_addr);
                            sin->sin_family = AF_INET;
                            sin->sin_port = srv->s_port;
                            ns++;
                     }
                     else if (inet_pton(AF_INET6, p,
                                        (void *) &addr6.s6_addr) == 1)
                     {
                            sin6 = (struct sockaddr_in6 *) sa;

                            memcpy(&sin6->sin6_addr, &addr6.s6_addr,
                                   sizeof sin6->sin6_addr);
                            sin6->sin6_family = AF_INET6;
                            sin6->sin6_port = srv->s_port;
                            ns++;
                     }
#else /* AF_INET6 */
                     addr.s_addr = inet_addr(p);
                     if (addr.s_addr == INADDR_NONE)
                            continue;

                     memcpy(&out[ns].sin_addr.s_addr,
                            &addr.s_addr,
                            sizeof out[ns].sin_addr.s_addr);
                     out[ns].sin_family = AF_INET;
                     out[ns].sin_port = srv->s_port;

                     ns++;
#endif /* AF_INET6 */
                     if (ns == *nscount)
                            break;
              }
       }

       fclose(f);

       *retry = RES_RETRY;
       *retrans = RES_TIMEOUT;

       /* if no "nameserver" lines were found, add a default one */
       if (ns == 0)
       {
#ifdef AF_INET6
              struct sockaddr *sa;
              struct sockaddr_in *sin;

              sa = (struct sockaddr *) &out[0];
              sin = (struct sockaddr_in *) sa;
              sin->sin_family = AF_INET;
              sin->sin_port = srv->s_port;
              sin->sin_addr.s_addr = htonl(INADDR_LOOPBACK);
#else /* AF_INET6 */
              out[0].sin_family = AF_INET;
              out[0].sin_port = srv->s_port;
              out[0].sin_addr.s_addr = htonl(INADDR_LOOPBACK);
#endif /* AF_INET6 */

              ns = 1;
       }

       *nscount = ns;

       return 0;
}

Here is the caller graph for this function:


Variable Documentation

char manual_h_id[] = "@(#)$Id: manual.h,v 1.4 2009/12/10 22:17:30 cm-msk Exp $" [static]

Definition at line 9 of file manual.h.