2
* Copyright (C) 2004 Tomasz Kojm <tkojm@clamav.net>
4
* This program is free software; you can redistribute it and/or modify
5
* it under the terms of the GNU General Public License as published by
6
* the Free Software Foundation; either version 2 of the License, or
7
* (at your option) any later version.
9
* This program is distributed in the hope that it will be useful,
10
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
* GNU General Public License for more details.
14
* You should have received a copy of the GNU General Public License
15
* along with this program; if not, write to the Free Software
16
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20
#include "clamav-config.h"
28
#include <sys/types.h>
29
#include <netinet/in.h>
30
#include <arpa/nameser.h>
32
#include <sys/types.h>
41
char *txtquery(const char *domain, unsigned int *ttl)
43
unsigned char answer[PACKETSZ], host[128], *pt, *txt;
44
int len, exp, cttl, size, txtlen, type;
48
mprintf("@res_init failed\n");
52
mprintf("*Querying %s\n", domain);
54
memset(answer, 0, PACKETSZ);
55
if((len = res_query(domain, C_IN, T_TXT, answer, PACKETSZ)) < 0) {
56
mprintf("@Can't query %s\n", domain);
60
pt = answer + sizeof(HEADER);
62
if((exp = dn_expand(answer, answer + len, pt, host, sizeof(host))) < 0) {
63
mprintf("@dn_expand failed\n");
71
mprintf("@Broken DNS reply.\n");
75
pt += INT16SZ; /* class */
77
if((exp = dn_expand(answer, answer + len, pt, host, sizeof(host))) < 0) {
78
mprintf("@second dn_expand failed\n");
85
mprintf("@Not a TXT record\n");
89
pt += INT16SZ; /* class */
95
if(txtlen >= size || !txtlen) {
96
mprintf("@Broken TXT record (txtlen = %d, size = %d)\n", txtlen, size);
100
if(!(txt = mmalloc(txtlen + 1)))
104
strncpy(txt, pt, txtlen);
112
char *txtquery(const char *domain, unsigned int *ttl)