Main Page | Alphabetical List | Data Structures | File List | Data Fields | Globals | Related Pages

dnsclient.c File Reference

#include <linux/module.h>
#include <linux/kernel.h>
#include "netdb.h"
#include "ares.h"
#include "ares_dns.h"
#include "memcopy.h"
#include "lwip/sys.h"
#include "lwip/ip_addr.h"
#include "lwip/inet.h"
#include "lwip/sockets.h"
#include <rtl_printf.h>

Include dependency graph for dnsclient.c:

Go to the source code of this file.

Defines

#define INADDR_NONE   0xffffffff
#define QUESTION   "cybeles.disca.upv.es"
#define DNS_SERVER_ADDR   "158.42.4.4"

Functions

void dns_client_callback (void *arg, int status, struct hostent *host)
void dns_client (void *arg)
int init_module (void)
void cleanup_module (void)


Define Documentation

#define DNS_SERVER_ADDR   "158.42.4.4"
 

Definition at line 26 of file dnsclient.c.

Referenced by dns_client().

#define INADDR_NONE   0xffffffff
 

Definition at line 22 of file dnsclient.c.

#define QUESTION   "cybeles.disca.upv.es"
 

Definition at line 25 of file dnsclient.c.

Referenced by dns_client().


Function Documentation

void cleanup_module void   ) 
 

Definition at line 109 of file dnsclient.c.

00109                          {
00110   printk("\n\nDNS client module removed.\n\n"); 
00111 }

void dns_client void *  arg  )  [static]
 

Definition at line 51 of file dnsclient.c.

References AF_INET, ares_channel, ares_destroy(), ares_fds(), ARES_FLAG_USEVC, ares_free_errmem(), ares_gethostbyaddr(), ares_gethostbyname(), ares_init_options(), ARES_OPT_FLAGS, ARES_OPT_SERVERS, ares_process(), ares_strerror(), ARES_SUCCESS, ares_timeout(), dns_client_callback(), DNS_SERVER_ADDR, FD_ZERO, ares_options::flags, INADDR_NONE, inet_addr(), inet_aton(), ares_options::nservers, NULL, QUESTION, in_addr::s_addr, ares_options::servers, status, and sys_thread_exit().

Referenced by init_module().

00051                                  {
00052   ares_channel channel;
00053   int status, nfds;
00054   fd_set read_fds, write_fds;
00055   struct timeval *tvp, tv;
00056   char *errmem;
00057   struct in_addr addr;
00058   struct in_addr ns1;
00059   struct ares_options options;
00060 
00061   inet_aton(DNS_SERVER_ADDR,&ns1);
00062 
00063   options.servers = &ns1;
00064   options.nservers = 1;
00065   options.flags = ARES_FLAG_USEVC;
00066 
00067   status = ares_init_options(&channel, &options, ARES_OPT_SERVERS | ARES_OPT_FLAGS);
00068 
00069   if (status != ARES_SUCCESS)
00070     {
00071       rtl_printf("ares_init: %s\n", ares_strerror(status, &errmem));      
00072       ares_free_errmem(errmem);
00073       sys_thread_exit();
00074     }
00075   
00076   
00077   addr.s_addr = inet_addr(QUESTION);
00078   if (addr.s_addr == INADDR_NONE){
00079     ares_gethostbyname(channel, QUESTION, AF_INET, dns_client_callback, QUESTION);
00080   }else{
00081       ares_gethostbyaddr(channel, &addr, sizeof(addr), AF_INET, dns_client_callback,
00082                          QUESTION);
00083   }
00084 
00085   /* Wait for all queries to complete. */
00086   while (1)
00087     {
00088       FD_ZERO(&read_fds);
00089       FD_ZERO(&write_fds);
00090       nfds = ares_fds(channel, &read_fds, &write_fds);
00091       if (nfds == 0)
00092         break;
00093       tvp = ares_timeout(channel, NULL, &tv);
00094       select(nfds, &read_fds, &write_fds, NULL, tvp);
00095       ares_process(channel, &read_fds, &write_fds);
00096     }
00097   
00098   ares_destroy(channel);
00099 }

Here is the call graph for this function:

void dns_client_callback void *  arg,
int  status,
struct hostent host
[static]
 

Definition at line 28 of file dnsclient.c.

References address, ares_free_errmem(), ares_strerror(), ARES_SUCCESS, hostent::h_addr_list, hostent::h_name, inet_ntoa(), memcopy(), and status.

Referenced by dns_client().

00029 {
00030   struct in_addr addr;
00031   char *mem, **p;
00032 
00033   if (status != ARES_SUCCESS)
00034     {
00035       rtl_printf("%s: %s\n", (char *) arg, ares_strerror(status, &mem));
00036       ares_free_errmem(mem);
00037       return;
00038     }
00039 
00040   for (p = host->h_addr_list; *p; p++)
00041     {
00042       char *address = "                                  ";
00043       memcopy(&addr, *p, sizeof(struct in_addr));
00044       address = inet_ntoa(addr);
00045       rtl_printf("%s: %s\n", host->h_name, address);
00046     }
00047 }

Here is the call graph for this function:

int init_module void   ) 
 

Definition at line 102 of file dnsclient.c.

References dns_client(), NULL, and sys_thread_new().

00102                      {
00103   printk("\n\nDNS client module inserted.\n\n"); 
00104   sys_thread_new(dns_client, NULL, 0);
00105   return 0;
00106 }

Here is the call graph for this function:


Generated on Wed Jan 14 12:59:03 2004 for RTL-lwIP-0.4 by doxygen 1.3.4