diff options
author | Henryk Plötz <henryk@ploetzli.ch> | 2014-10-03 19:58:52 +0200 |
---|---|---|
committer | Henryk Plötz <henryk@ploetzli.ch> | 2014-10-03 19:58:52 +0200 |
commit | 0e5b2871ca6456b01d4bf037a6e68badf1ff1a41 (patch) | |
tree | 97b95b74c9618d85da9aa9451a55a819cd7b1c2e /qlog.c | |
download | tinydnssec-0e5b2871ca6456b01d4bf037a6e68badf1ff1a41.tar.gz tinydnssec-0e5b2871ca6456b01d4bf037a6e68badf1ff1a41.tar.bz2 |
Initial commit of djbdns-1.05.tar.gz
Source was http://cr.yp.to/djbdns/djbdns-1.05.tar.gz, SHA1 2efdb3a039d0c548f40936aa9cb30829e0ce8c3d
Diffstat (limited to 'qlog.c')
-rw-r--r-- | qlog.c | 63 |
1 files changed, 63 insertions, 0 deletions
@@ -0,0 +1,63 @@ +#include "buffer.h" +#include "qlog.h" + +static void put(char c) +{ + buffer_put(buffer_2,&c,1); +} + +static void hex(unsigned char c) +{ + put("0123456789abcdef"[(c >> 4) & 15]); + put("0123456789abcdef"[c & 15]); +} + +static void octal(unsigned char c) +{ + put('\\'); + put('0' + ((c >> 6) & 7)); + put('0' + ((c >> 3) & 7)); + put('0' + (c & 7)); +} + +void qlog(const char ip[4],uint16 port,const char id[2],const char *q,const char qtype[2],const char *result) +{ + char ch; + char ch2; + + hex(ip[0]); + hex(ip[1]); + hex(ip[2]); + hex(ip[3]); + put(':'); + hex(port >> 8); + hex(port & 255); + put(':'); + hex(id[0]); + hex(id[1]); + buffer_puts(buffer_2,result); + hex(qtype[0]); + hex(qtype[1]); + put(' '); + + if (!*q) + put('.'); + else + for (;;) { + ch = *q++; + while (ch--) { + ch2 = *q++; + if ((ch2 >= 'A') && (ch2 <= 'Z')) + ch2 += 32; + if (((ch2 >= 'a') && (ch2 <= 'z')) || ((ch2 >= '0') && (ch2 <= '9')) || (ch2 == '-') || (ch2 == '_')) + put(ch2); + else + octal(ch2); + } + if (!*q) break; + put('.'); + } + + put('\n'); + buffer_flush(buffer_2); +} |