1/*
2 *
3 *  BlueZ - Bluetooth protocol stack for Linux
4 *
5 *  Copyright (C) 2003-2011  Marcel Holtmann <marcel@holtmann.org>
6 *
7 *
8 *  This program is free software; you can redistribute it and/or modify
9 *  it under the terms of the GNU General Public License as published by
10 *  the Free Software Foundation; either version 2 of the License, or
11 *  (at your option) any later version.
12 *
13 *  This program is distributed in the hope that it will be useful,
14 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
15 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16 *  GNU General Public License for more details.
17 *
18 *  You should have received a copy of the GNU General Public License
19 *  along with this program; if not, write to the Free Software
20 *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
21 *
22 */
23
24#ifdef HAVE_CONFIG_H
25#include <config.h>
26#endif
27
28#include <stdio.h>
29#include <errno.h>
30#include <unistd.h>
31#include <stdlib.h>
32#include <string.h>
33#include <sys/types.h>
34
35#include <net/ethertypes.h>
36#include <netinet/in.h>
37#include <netinet/ip.h>
38
39#ifdef HAS_INET6
40#include <netinet/ip6.h>
41#endif
42
43#include <netinet/if_ether.h>
44#include <arpa/inet.h>
45#include <netdb.h>
46
47#include "parser.h"
48
49void arp_dump(int level, struct frame *frm)
50{
51#if 0
52	int i;
53	char buf[20];
54	struct sockaddr_in sai;
55	struct ether_arp *arp = (struct ether_arp *) frm->ptr;
56
57	printf("Src ");
58	for (i = 0; i < 5; i++)
59		printf("%02x:", arp->arp_sha[i]);
60	printf("%02x", arp->arp_sha[5]);
61	sai.sin_family = AF_INET;
62	memcpy(&sai.sin_addr, &arp->arp_spa, sizeof(sai.sin_addr));
63	getnameinfo((struct sockaddr *) &sai, sizeof(sai), buf, sizeof(buf),
64		    NULL, 0, NI_NUMERICHOST);
65	printf("(%s) ", buf);
66	printf("Tgt ");
67	for (i = 0; i < 5; i++)
68		printf("%02x:", arp->arp_tha[i]);
69	printf("%02x", arp->arp_tha[5]);
70	memcpy(&sai.sin_addr, &arp->arp_tpa, sizeof(sai.sin_addr));
71	getnameinfo((struct sockaddr *) &sai, sizeof(sai), buf, sizeof(buf),
72		    NULL, 0, NI_NUMERICHOST);
73	printf("(%s)\n", buf);
74	frm->ptr += sizeof(struct ether_arp);
75	frm->len -= sizeof(struct ether_arp);
76#endif
77	raw_dump(level, frm);		// not needed.
78
79}
80
81void ip_dump(int level, struct frame *frm)
82{
83#if 0
84	char src[50], dst[50];
85	struct ip *ip = (struct ip *) (frm->ptr);
86	uint8_t proto;
87	int len;
88
89	if (ip->ip_v == 4) {
90		struct sockaddr_in sai;
91		proto = ip->ip_p;
92		len = ip->ip_hl << 2;
93		memset(&sai, 0, sizeof(sai));
94		sai.sin_family = AF_INET;
95		memcpy(&sai.sin_addr, &ip->ip_src, sizeof(struct in_addr));
96		getnameinfo((struct sockaddr *) &sai, sizeof(sai),
97			    src, sizeof(src), NULL, 0, NI_NUMERICHOST);
98		memcpy(&sai.sin_addr, &ip->ip_dst, sizeof(struct in_addr));
99		getnameinfo((struct sockaddr *) &sai, sizeof(sai),
100			    dst, sizeof(dst), NULL, 0, NI_NUMERICHOST);
101	} else if (ip->ip_v == 6) {
102		struct sockaddr_in6 sai6;
103		struct ip6_hdr *ip6 = (struct ip6_hdr *) ip;
104		proto = ip6->ip6_nxt;
105		len = sizeof(struct ip6_hdr);
106		memset(&sai6, 0, sizeof(sai6));
107		sai6.sin6_family = AF_INET6;
108		memcpy(&sai6.sin6_addr, &ip6->ip6_src, sizeof(struct in6_addr));
109		getnameinfo((struct sockaddr *) &sai6, sizeof(sai6),
110			    src, sizeof(src), NULL, 0, NI_NUMERICHOST);
111		memcpy(&sai6.sin6_addr, &ip6->ip6_dst, sizeof(struct in6_addr));
112		getnameinfo((struct sockaddr *) &sai6, sizeof(sai6),
113			    dst, sizeof(dst), NULL, 0, NI_NUMERICHOST);
114	} else {
115		raw_dump(level, frm);
116		return;
117	}
118
119	printf("src %s ", src);
120	printf("dst %s\n", dst);
121
122	frm->ptr += len;
123	frm->len -= len;
124	p_indent(++level, frm);
125
126	switch (proto) {
127	case IPPROTO_TCP:
128		printf("TCP:\n");
129		break;
130
131	case IPPROTO_UDP:
132		printf("UDP:\n");
133		break;
134
135	case IPPROTO_ICMP:
136		printf("ICMP:\n");
137		break;
138
139	case IPPROTO_ICMPV6:
140		printf("ICMPv6:\n");
141		break;
142
143	default:
144		printf("Unknown Protocol: 0x%02x\n", ip->ip_p);
145		break;
146	}
147#endif
148	raw_dump(level, frm);
149}
150