11#define number(x) ( (u64 = (x)), u64_print() ) 
   13static void u64_print(
void)
 
   21    buf[--pos] = 
'0' + (
u64 % 10);
 
   25  buffer_put(buffer_2,
buf + pos,
sizeof(
buf) - pos);
 
   28static void hex(
unsigned char c)
 
   30  buffer_put(buffer_2,
"0123456789abcdef" + (c >> 4),1);
 
   31  buffer_put(buffer_2,
"0123456789abcdef" + (c & 15),1);
 
   34static void string(
const char *s)
 
   36  buffer_puts(buffer_2,s);
 
   42  buffer_flush(buffer_2);
 
   45static void space(
void)
 
   50static void ip(
const char i[16])
 
   54  if (ip6_isv4mapped(i)) 
 
   55    for (j = 12; j < 16; ++j) hex(i[j]);
 
   57    for (j = 0; j < 16; ++j) hex(i[j]);
 
   60static void logid(
const char id[2])
 
   66static void logtype(
const char type[2])
 
   70  uint16_unpack_big(
type,&u);
 
   74static void name(
const char *q)
 
   83  while ((state = *q++)) {
 
   87      if ((ch <= 32) || (ch > 126)) ch = 
'?';
 
   88      if ((ch >= 
'A') && (ch <= 
'Z')) ch += 32;
 
   89      buffer_put(buffer_2,&ch,1);
 
   95void log_startup(
const char listip[16],uint32 scope,
const char sendip[16],
int size)
 
   99  string(
"starting dnscache listening on ip ");
 
  104  string(
" sending queries from ip ");
 
  107  string(
" udp maxsize = "); string(
strnum); 
 
 
  111void log_query(uint64 *qnum,
const char client[16],
unsigned int port,
const char id[2],
const char *q,
const char qtype[2],
const char *
p)
 
  113  string(
p); string(
".query "); 
number(*qnum); space();
 
  114  ip(client); string(
":"); hex(
port >> 8); hex(
port & 255);
 
  115  string(
":"); logid(
id); space();
 
  116  logtype(qtype); space(); 
name(q);
 
 
  122  string(
p); string(
".sent "); 
number(*qnum); space();
 
 
  129  const char *
x = errstr(errno);
 
  131  string(
p); string(
".drop "); 
number(*qnum); space();
 
 
  138   string(
"ignored referral "); 
ip(server); space();
 
  139   name(control); space(); 
name(referral);
 
 
  146  ip(client); string(
":"); hex(
port >> 8); hex(
port & 255);
 
 
  152  const char *
x = errstr(errno);
 
  154  ip(client); string(
":"); hex(
port >> 8); hex(
port & 255); space();
 
 
  163  string(
"tx "); 
number(gluelessness); space();
 
  164  logtype(qtype); space(); 
 
  167    case -1: string(
" !"); 
break;
 
  168    case  0: string(
" -"); 
break;
 
  169    case  1: string(
" +"); 
break;
 
  170    case  2: string(
" *"); 
break;
 
  174    if (byte_diff(
servers + i,16,V6localnet)) {
 
 
  183  string(
"cached "); logtype(
type); space();
 
 
  190  string(
"cached cname "); 
name(dn); space(); 
name(dn2);
 
 
  196  string(
"cached ns "); 
name(control); space(); 
name(ns); 
 
 
  202  string(
"cached nxdomain "); 
name(dn);
 
 
  208  string(
"nxdomain "); 
ip(server); space(); 
number(ttl); space();
 
 
  213void log_nodata(
const char server[16],
const char *q,
const char qtype[2],
unsigned int ttl)
 
  215  string(
"nodata "); 
ip(server); space(); 
number(ttl); space();
 
  216  logtype(qtype); space(); 
name(q);
 
 
  220void log_lame(
const char server[16],
const char *control,
const char *referral)
 
  222  string(
"lame "); 
ip(server); space();
 
  223  name(control); space(); 
name(referral);
 
 
  229  string(
"servflagged "); 
 
  230  if (flag == 1) string(
"% ");
 
  231  if (flag == -1) string(
"- ");
 
  232  if (flag == -2) string(
"! ");
 
 
  239  const char *
x = errstr(errno);
 
  241  string(
"servfail "); 
name(dn); space();
 
 
  246void log_rr(
const char server[16],
const char *q,
const char type[2],
const char *
buf,
unsigned int len,
unsigned int ttl)
 
  250  string(
"rr "); 
ip(server); space(); 
number(ttl); space();
 
  251  logtype(
type); space(); 
name(q); space();
 
  253  for (i = 0; i < 
len; ++i) {
 
 
  263void log_rrns(
const char server[16],
const char *q,
const char *
data,
unsigned int ttl)
 
  265  string(
"rr "); 
ip(server); space(); 
number(ttl);
 
  266  string(
" ns "); 
name(q); space();
 
 
  270void log_rrcname(
const char server[16],
const char *q,
const char *
data,
unsigned int ttl)
 
  272  string(
"rr "); 
ip(server); space(); 
number(ttl);
 
  273  string(
" cname "); 
name(q); space();
 
 
  278void log_rrptr(
const char server[16],
const char *q,
const char *
data,
unsigned int ttl)
 
  280  string(
"rr "); 
ip(server); space(); 
number(ttl);
 
  281  string(
" ptr "); 
name(q); space();
 
 
  286void log_rrmx(
const char server[16],
const char *q,
const char *mx,
const char pref[2],
unsigned int ttl)
 
  290  string(
"rr "); 
ip(server); space(); 
number(ttl);
 
  291  string(
" mx "); 
name(q); space();
 
  292  uint16_unpack_big(pref,&u);
 
 
  297void log_rrsoa(
const char server[16],
const char *q,
const char *n1,
const char *n2,
const char misc[20],
unsigned int ttl)
 
  302  string(
"rr "); 
ip(server); space(); 
number(ttl);
 
  303  string(
" soa "); 
name(q); space();
 
  305  for (i = 0; i < 20; i += 4) {
 
  306    uint32_unpack_big(misc + i,&u);
 
 
char servers[QUERY_MAXIPLEN]
 
char name[DNS_NAME6_DOMAIN]
 
void log_rrmx(const char server[16], const char *q, const char *mx, const char pref[2], unsigned int ttl)
 
void log_tcpclose(const char client[16], unsigned int port)
 
void log_rrcname(const char server[16], const char *q, const char *data, unsigned int ttl)
 
void log_servflag(const char server[16], int flag)
 
void log_servfail(const char *dn)
 
void log_tcpopen(const char client[16], unsigned int port)
 
void log_cachedanswer(const char *q, const char type[2])
 
void log_nxdomain(const char server[16], const char *q, unsigned int ttl)
 
void log_cachednxdomain(const char *dn)
 
void log_nodata(const char server[16], const char *q, const char qtype[2], unsigned int ttl)
 
void log_rrptr(const char server[16], const char *q, const char *data, unsigned int ttl)
 
void log_ignore_referral(const char server[16], const char *control, const char *referral)
 
void log_querydone(uint64 *qnum, unsigned int len, const char *p)
 
void log_tx(const char *q, const char qtype[2], const char *control, const char servers[QUERY_MAXIPLEN], int flagkey, unsigned int gluelessness)
 
void log_startup(const char listip[16], uint32 scope, const char sendip[16], int size)
 
void log_lame(const char server[16], const char *control, const char *referral)
 
void log_query(uint64 *qnum, const char client[16], unsigned int port, const char id[2], const char *q, const char qtype[2], const char *p)
 
void log_cachedcname(const char *dn, const char *dn2)
 
void log_rrsoa(const char server[16], const char *q, const char *n1, const char *n2, const char misc[20], unsigned int ttl)
 
void log_rrns(const char server[16], const char *q, const char *data, unsigned int ttl)
 
void log_cachedns(const char *control, const char *ns)
 
void log_rr(const char server[16], const char *q, const char type[2], const char *buf, unsigned int len, unsigned int ttl)
 
void log_querydrop(uint64 *qnum, const char *p)