djbdnscurve6 45
djbdnscurve6
Loading...
Searching...
No Matches
qlog.c
Go to the documentation of this file.
1#include "buffer.h"
2#include "qlog.h"
3#include "fmt.h"
4#include "ip.h"
5
6static void put(char c)
7{
8 buffer_put(buffer_2,&c,1);
9}
10
11static void puts(const char *s)
12{
13 buffer_puts(buffer_2,s);
14}
15
16static void hex(unsigned char c)
17{
18 put("0123456789abcdef"[(c >> 4) & 15]);
19 put("0123456789abcdef"[c & 15]);
20}
21
22static void octal(unsigned char c)
23{
24 put('\\');
25 put('0' + ((c >> 6) & 7));
26 put('0' + ((c >> 3) & 7));
27 put('0' + (c & 7));
28}
29
30void log_start(const char *s,const char ip[16],uint32 scope)
31{
32 char strnum[FMT_ULONG];
33
34 strnum[fmt_ulong(strnum,scope)] = 0;
35
36 puts(s);
37 puts("listening on ip ");
38 {
39 int i;
40 int j = ip6_isv4mapped(ip);
41
42 for (i = 12 * j; i < 16; ++i)
43 hex(ip[i]);
44
45 if (!j) { puts("%"); puts(strnum); }
46 put('\n');
47 buffer_flush(buffer_2);
48 }
49}
50
51void qlog(const char ip[16],uint16 port,const char id[2],const char *q,const char qtype[2],const char *result)
52{
53 char ch;
54 char ch2;
55
56 {
57 int i;
58
59 for (i = 12 * ip6_isv4mapped(ip); i < 16; ++i)
60 hex(ip[i]);
61 }
62 put(':');
63 hex(port >> 8);
64 hex(port & 255);
65 put(':');
66 hex(id[0]);
67 hex(id[1]);
68 buffer_puts(buffer_2,result);
69 hex(qtype[0]);
70 hex(qtype[1]);
71 put(' ');
72
73 if (!*q)
74 put('.');
75 else
76 for (;;) {
77 ch = *q++;
78 while (ch--) {
79 ch2 = *q++;
80 if ((ch2 >= 'A') && (ch2 <= 'Z'))
81 ch2 += 32;
82 if (((ch2 >= 'a') && (ch2 <= 'z')) || ((ch2 >= '0') && (ch2 <= '9')) || (ch2 == '-') || (ch2 == '_'))
83 put(ch2);
84 else
85 octal(ch2);
86 }
87 if (!*q) break;
88 put('.');
89 }
90
91 put('\n');
92 buffer_flush(buffer_2);
93}
int puts(const char *s)
Definition: auto-str.c:7
void put(char *buf, unsigned int len)
Definition: axfr-get.c:107
unsigned long port
Definition: axfrdns.c:126
char ip[16]
Definition: axfrdns.c:125
char strnum[FMT_ULONG]
Definition: dnsmx.c:22
void qlog(const char ip[16], uint16 port, const char id[2], const char *q, const char qtype[2], const char *result)
Definition: qlog.c:51
void log_start(const char *s, const char ip[16], uint32 scope)
Definition: qlog.c:30