hcidump: Move TCP/IP decoders into a separate file

This commit is contained in:
Marcel Holtmann 2006-01-21 15:19:33 +00:00
parent d3aa50e258
commit 3528cdb2db
4 changed files with 96 additions and 61 deletions

View File

@ -31,15 +31,9 @@
#include <unistd.h>
#include <stdlib.h>
#include <string.h>
#include <sys/types.h>
#include <netinet/in.h>
#include <net/ethernet.h>
#include <netinet/in.h>
#include <netinet/ip.h>
#include <netinet/if_ether.h>
#include <arpa/inet.h>
#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);

View File

@ -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);

View File

@ -30,9 +30,7 @@
#include <unistd.h>
#include <stdlib.h>
#include <string.h>
#include <sys/types.h>
#include <netinet/in.h>
#include "parser.h"

94
tools/parser/tcpip.c Normal file
View File

@ -0,0 +1,94 @@
/*
*
* BlueZ - Bluetooth protocol stack for Linux
*
* Copyright (C) 2003-2006 Marcel Holtmann <marcel@holtmann.org>
*
*
* 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 <config.h>
#endif
#include <stdio.h>
#include <errno.h>
#include <unistd.h>
#include <stdlib.h>
#include <string.h>
#include <sys/types.h>
#include <net/ethernet.h>
#include <netinet/in.h>
#include <netinet/ip.h>
#include <netinet/if_ether.h>
#include <arpa/inet.h>
#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);
}
}