From e81da3a2fab6af4969902b6c268c8dfac43ea6fb Mon Sep 17 00:00:00 2001 From: "R.E. Wolff" Date: Tue, 5 Feb 2013 15:58:25 +0100 Subject: [PATCH] missed adding asn.[ch] when committing the asn patch! --- asn.c | 109 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ asn.h | 27 +++++++++++++++ 2 files changed, 136 insertions(+) create mode 100644 asn.c create mode 100644 asn.h diff --git a/asn.c b/asn.c new file mode 100644 index 0000000..9ad8907 --- /dev/null +++ b/asn.c @@ -0,0 +1,109 @@ +/* + mtr -- a network diagnostic tool + Copyright (C) 1997,1998 Matt Kimball + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License version 2 as + published by the Free Software Foundation. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +*/ + +/* + Copyright (C) 2010 by Roderick Groesbeek + Released under GPL, as above. +*/ + +#include + +#include +#include +#include + +#include +#include +#include +#include +#include +#include + + +#include + + +int PrintAS = 0; +GHashTable * ashash = NULL; + +char *asn_lookup(const char *domain) +{ + unsigned char answer[PACKETSZ], *pt; + char host[128]; + char *txt; + int len, exp, cttl, size, txtlen, type; + + + if(res_init() < 0) { + fprintf(stderr,"@res_init failedn"); + return NULL; + } + + memset(answer, 0, PACKETSZ); + if((len = res_query(domain, C_IN, T_TXT, answer, PACKETSZ)) < 0) { + return "-1"; + } + + pt = answer + sizeof(HEADER); + + if((exp = dn_expand(answer, answer + len, pt, host, sizeof(host))) < 0) { + printf("@dn_expand failedn"); return NULL; + } + + pt += exp; + + GETSHORT(type, pt); + if(type != T_TXT) { + printf("@Broken DNS reply.n"); return NULL; + } + + pt += INT16SZ; /* class */ + + if((exp = dn_expand(answer, answer + len, pt, host, sizeof(host))) < 0) { + printf("@second dn_expand failedn"); return NULL; + } + + pt += exp; + GETSHORT(type, pt); + if(type != T_TXT) { + printf("@Not a TXT recordn"); return NULL; + } + + pt += INT16SZ; /* class */ + GETLONG(cttl, pt); + GETSHORT(size, pt); + txtlen = *pt; + + + if(txtlen >= size || !txtlen) { + printf("@Broken TXT record (txtlen = %d, size = %d)n", txtlen, size); return NULL; + } + + if(!(txt = malloc(txtlen + 1))) + return NULL; + + pt++; + strncpy(txt, (char*) pt, txtlen); + txt[txtlen] = 0; + + return txt; +} + + + + diff --git a/asn.h b/asn.h new file mode 100644 index 0000000..fde9af2 --- /dev/null +++ b/asn.h @@ -0,0 +1,27 @@ +/* + mtr -- a network diagnostic tool + Copyright (C) 1997,1998 Matt Kimball + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License version 2 as + published by the Free Software Foundation. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +*/ + +#include + + +/* Prototypes for asn.c */ + +extern int PrintAS; +extern GHashTable * ashash; +char *asn_lookup(const char *domain); + -- 2.47.2