From 3528cdb2db9bc1249ed3931ecf80932685e5243c Mon Sep 17 00:00:00 2001 From: Marcel Holtmann Date: Sat, 21 Jan 2006 15:19:33 +0000 Subject: [PATCH] hcidump: Move TCP/IP decoders into a separate file --- tools/parser/bnep.c | 59 --------------------------- tools/parser/parser.h | 2 + tools/parser/ppp.c | 2 - tools/parser/tcpip.c | 94 +++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 96 insertions(+), 61 deletions(-) create mode 100644 tools/parser/tcpip.c diff --git a/tools/parser/bnep.c b/tools/parser/bnep.c index 1af0c7951..05aad2a86 100644 --- a/tools/parser/bnep.c +++ b/tools/parser/bnep.c @@ -31,15 +31,9 @@ #include #include #include - #include -#include #include -#include -#include -#include -#include #include "parser.h" @@ -202,59 +196,6 @@ static void bnep_eval_extension(int level, struct frame *frm) } } -static void arp_dump(int level, struct frame *frm) -{ - int i; - struct ether_arp *arp = (struct ether_arp *) frm->ptr; - - printf("Src "); - for (i = 0; i < 5; i++) - printf("%02x:", arp->arp_sha[i]); - printf("%02x", arp->arp_sha[5]); - printf("(%s) ", inet_ntoa(*(struct in_addr *) &arp->arp_spa)); - printf("Tgt "); - for (i = 0; i < 5; i++) - printf("%02x:", arp->arp_tha[i]); - printf("%02x", arp->arp_tha[5]); - printf("(%s)\n", inet_ntoa(*(struct in_addr *) &arp->arp_tpa)); - frm->ptr += sizeof(struct ether_arp); - frm->len -= sizeof(struct ether_arp); - raw_dump(level, frm); // not needed. -} - -static void ip_dump(int level, struct frame *frm) -{ - struct ip *ip = (struct ip *) (frm->ptr); - int len = ip->ip_hl << 2; - frm->ptr += len; - frm->len -= len; - - printf("src %s ", inet_ntoa(*(struct in_addr *) &(ip->ip_src))); - printf("dst %s\n", inet_ntoa(*(struct in_addr *) &(ip->ip_dst))); - p_indent(++level, frm); - - switch (ip->ip_p) { - case IPPROTO_TCP: - printf("TCP:\n"); - raw_dump(level, frm); - break; - - case IPPROTO_UDP: - printf("UDP:\n"); - raw_dump(level, frm); - break; - - case IPPROTO_ICMP: - printf("ICMP:\n"); - raw_dump(level, frm); - break; - - default: - printf("Unknown Protocol: 0x%02x\n", ip->ip_p); - raw_dump(level, frm); - } -} - void bnep_dump(int level, struct frame *frm) { uint8_t type = get_u8(frm); diff --git a/tools/parser/parser.h b/tools/parser/parser.h index ee890fcd0..efaadfa38 100644 --- a/tools/parser/parser.h +++ b/tools/parser/parser.h @@ -231,6 +231,8 @@ void avctp_dump(int level, struct frame *frm); void obex_dump(int level, struct frame *frm); void capi_dump(int level, struct frame *frm); void ppp_dump(int level, struct frame *frm); +void arp_dump(int level, struct frame *frm); +void ip_dump(int level, struct frame *frm); void csr_dump(int level, struct frame *frm); void bpa_dump(int level, struct frame *frm); diff --git a/tools/parser/ppp.c b/tools/parser/ppp.c index c68c7ea92..1d4a4a6b1 100644 --- a/tools/parser/ppp.c +++ b/tools/parser/ppp.c @@ -30,9 +30,7 @@ #include #include #include - #include -#include #include "parser.h" diff --git a/tools/parser/tcpip.c b/tools/parser/tcpip.c new file mode 100644 index 000000000..d8791a7eb --- /dev/null +++ b/tools/parser/tcpip.c @@ -0,0 +1,94 @@ +/* + * + * BlueZ - Bluetooth protocol stack for Linux + * + * Copyright (C) 2003-2006 Marcel Holtmann + * + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * 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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + * + */ + +#ifdef HAVE_CONFIG_H +#include +#endif + +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include + +#include "parser.h" + +void arp_dump(int level, struct frame *frm) +{ + int i; + struct ether_arp *arp = (struct ether_arp *) frm->ptr; + + printf("Src "); + for (i = 0; i < 5; i++) + printf("%02x:", arp->arp_sha[i]); + printf("%02x", arp->arp_sha[5]); + printf("(%s) ", inet_ntoa(*(struct in_addr *) &arp->arp_spa)); + printf("Tgt "); + for (i = 0; i < 5; i++) + printf("%02x:", arp->arp_tha[i]); + printf("%02x", arp->arp_tha[5]); + printf("(%s)\n", inet_ntoa(*(struct in_addr *) &arp->arp_tpa)); + frm->ptr += sizeof(struct ether_arp); + frm->len -= sizeof(struct ether_arp); + raw_dump(level, frm); // not needed. +} + +void ip_dump(int level, struct frame *frm) +{ + struct ip *ip = (struct ip *) (frm->ptr); + int len = ip->ip_hl << 2; + frm->ptr += len; + frm->len -= len; + + printf("src %s ", inet_ntoa(*(struct in_addr *) &(ip->ip_src))); + printf("dst %s\n", inet_ntoa(*(struct in_addr *) &(ip->ip_dst))); + p_indent(++level, frm); + + switch (ip->ip_p) { + case IPPROTO_TCP: + printf("TCP:\n"); + raw_dump(level, frm); + break; + + case IPPROTO_UDP: + printf("UDP:\n"); + raw_dump(level, frm); + break; + + case IPPROTO_ICMP: + printf("ICMP:\n"); + raw_dump(level, frm); + break; + + default: + printf("Unknown Protocol: 0x%02x\n", ip->ip_p); + raw_dump(level, frm); + } +} -- 2.47.3