alias_dns.c revision c7877e6eaa7a11a5157991bf3dd7a1274393bdd4
/* $Id$ */
/** @file
* libalias helper for using the host resolver instead of dnsproxy.
*/
/*
* Copyright (C) 2009 Oracle Corporation
*
* This file is part of VirtualBox Open Source Edition (OSE), as
* available from http://www.virtualbox.org. This file is free software;
* General Public License (GPL) as published by the Free Software
* Foundation, in version 2 as it comes in the "COPYING" file of the
* VirtualBox OSE distribution. VirtualBox OSE is distributed in the
* hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
*/
#ifndef RT_OS_WINDOWS
# include <netdb.h>
#endif
#include <slirp.h>
#include "alias.h"
#include "alias_local.h"
#include "alias_mod.h"
#define DNS_CONTROL_PORT_NUMBER 53
/* see RFC 1035(4.1.1) */
union dnsmsg_header
{
struct
{
unsigned id:16;
unsigned rd:1;
unsigned tc:1;
unsigned aa:1;
unsigned opcode:4;
unsigned qr:1;
unsigned rcode:4;
unsigned Z:3;
unsigned ra:1;
} X;
};
struct dns_meta_data
{
};
struct dnsmsg_answer
{
struct dns_meta_data meta;
};
/* see RFC 1035(4.1) */
static int
{
return -1;
Log(("NAT:%s: ah(dport: %hd, sport: %hd) oaddr:%R[naipv4] aaddr:%R[naipv4]\n",
return 0;
return -1;
}
static void doanswer(struct libalias *la, union dnsmsg_header *hdr, struct dns_meta_data *pReqMeta, char *qname, struct ip *pip, struct hostent *h)
{
int i;
if (!h)
{
}
else
{
char *query;
char *answers;
char **cstr;
char *c;
uint16_t packet_len = 0;
struct dns_meta_data *meta;
#if 0
/* here is no compressed names+answers + new query */
#endif
+ sizeof(struct udphdr)
+ sizeof(union dnsmsg_header)
+ sizeof(struct dns_meta_data); /* ip + udp + header + query */
/* class & type informations lay right after symbolic inforamtion. */
/* answers zone lays after query in response packet */
/* add aliases */
{
}
/* add addresses */
{
}
/* don't forget update m_len */
}
}
static int
{
int i;
/* Parse dns request */
char cname[255];
int cname_len = 0;
struct dns_meta_data *meta;
return 0; /* this is respose */
{
static bool fMultiWarn;
if (!fMultiWarn)
{
LogRel(("NAT:alias_dns: multiple quieries isn't supported\n"));
fMultiWarn = true;
}
return 1;
}
{
Log(("qname:%s qtype:%hd qclass:%hd\n",
/* Some guests like win-xp adds _dot_ after host name
* and after domain name (not passed with host resolver)
* that confuses host resolver.
*/
if ( cname_len > 2
{
}
h = gethostbyname(cname);
}
/*
* We have changed the size and the content of udp, to avoid double csum calculation
* will assign to zero
*/
return 0;
}
/*
* qstr is z-string with -dot- replaced with \count to next -dot-
* e.g. ya.ru is \02ya\02ru
* Note: it's assumed that caller allocates buffer for cstr
*/
{
const char *q;
char *c;
{
if ( isalpha(*q)
|| isdigit(*q)
|| *q == '-'
|| *q == '_')
{
*c = *q;
c++;
}
else if (c != &pszStr[0])
{
*c = '.';
c++;
}
}
*c = '\0';
}
/*
*
*/
{
const char *c;
const char *pc;
char *q;
{
/* at the begining or at -dot- position */
{
if (c != pcszStr)
c++;
}
else
{
*q = *c;
c++;
}
}
*q = '\0';
}
int
{
}
int
{
}
static int
{
int error;
if (!handlers)
switch (type)
{
case MOD_LOAD:
error = 0;
break;
case MOD_UNLOAD:
error = 0;
break;
default:
}
return error;
}