• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  *
3  *  BlueZ - Bluetooth protocol stack for Linux
4  *
5  *  Copyright (C) 2003-2007  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 <netinet/in.h>
36 #include <netinet/ip.h>
37 #include <netinet/if_ether.h>
38 #include <arpa/inet.h>
39 #include <netdb.h>
40 
41 #include "parser.h"
42 
arp_dump(int level,struct frame * frm)43 void arp_dump(int level, struct frame *frm)
44 {
45 #if 0
46 	int i;
47 	char buf[20];
48 	struct sockaddr_in sai;
49 	struct ether_arp *arp = (struct ether_arp *) frm->ptr;
50 
51 	printf("Src ");
52 	for (i = 0; i < 5; i++)
53 		printf("%02x:", arp->arp_sha[i]);
54 	printf("%02x", arp->arp_sha[5]);
55 	sai.sin_family = AF_INET;
56 	memcpy(&sai.sin_addr, &arp->arp_spa, sizeof(sai.sin_addr));
57 	getnameinfo((struct sockaddr *) &sai, sizeof(sai), buf, sizeof(buf),
58 		    NULL, 0, NI_NUMERICHOST);
59 	printf("(%s) ", buf);
60 	printf("Tgt ");
61 	for (i = 0; i < 5; i++)
62 		printf("%02x:", arp->arp_tha[i]);
63 	printf("%02x", arp->arp_tha[5]);
64 	memcpy(&sai.sin_addr, &arp->arp_tpa, sizeof(sai.sin_addr));
65 	getnameinfo((struct sockaddr *) &sai, sizeof(sai), buf, sizeof(buf),
66 		    NULL, 0, NI_NUMERICHOST);
67 	printf("(%s)\n", buf);
68 	frm->ptr += sizeof(struct ether_arp);
69 	frm->len -= sizeof(struct ether_arp);
70 #endif
71 	raw_dump(level, frm);		// not needed.
72 }
73 
ip_dump(int level,struct frame * frm)74 void ip_dump(int level, struct frame *frm)
75 {
76 #if 0
77 	char src[50], dst[50];
78 	struct ip *ip = (struct ip *) (frm->ptr);
79 	uint8_t proto;
80 	int len;
81 
82 	if (ip->ip_v == 4) {
83 		struct sockaddr_in sai;
84 		proto = ip->ip_p;
85 		len = ip->ip_hl << 2;
86 		memset(&sai, 0, sizeof(sai));
87 		sai.sin_family = AF_INET;
88 		memcpy(&sai.sin_addr, &ip->ip_src, sizeof(struct in_addr));
89 		getnameinfo((struct sockaddr *) &sai, sizeof(sai),
90 			    src, sizeof(src), NULL, 0, NI_NUMERICHOST);
91 		memcpy(&sai.sin_addr, &ip->ip_dst, sizeof(struct in_addr));
92 		getnameinfo((struct sockaddr *) &sai, sizeof(sai),
93 			    dst, sizeof(dst), NULL, 0, NI_NUMERICHOST);
94 	} else if (ip->ip_v == 6) {
95 		struct sockaddr_in6 sai6;
96 		struct ip6_hdr *ip6 = (struct ip6_hdr *) ip;
97 		proto = ip6->ip6_nxt;
98 		len = sizeof(struct ip6_hdr);
99 		memset(&sai6, 0, sizeof(sai6));
100 		sai6.sin6_family = AF_INET6;
101 		memcpy(&sai6.sin6_addr, &ip6->ip6_src, sizeof(struct in6_addr));
102 		getnameinfo((struct sockaddr *) &sai6, sizeof(sai6),
103 			    src, sizeof(src), NULL, 0, NI_NUMERICHOST);
104 		memcpy(&sai6.sin6_addr, &ip6->ip6_dst, sizeof(struct in6_addr));
105 		getnameinfo((struct sockaddr *) &sai6, sizeof(sai6),
106 			    dst, sizeof(dst), NULL, 0, NI_NUMERICHOST);
107 	} else {
108 		raw_dump(level, frm);
109 		return;
110 	}
111 
112 	printf("src %s ", src);
113 	printf("dst %s\n", dst);
114 
115 	frm->ptr += len;
116 	frm->len -= len;
117 	p_indent(++level, frm);
118 
119 	switch (proto) {
120 	case IPPROTO_TCP:
121 		printf("TCP:\n");
122 		break;
123 
124 	case IPPROTO_UDP:
125 		printf("UDP:\n");
126 		break;
127 
128 	case IPPROTO_ICMP:
129 		printf("ICMP:\n");
130 		break;
131 
132 	case IPPROTO_ICMPV6:
133 		printf("ICMPv6:\n");
134 		break;
135 
136 	default:
137 		printf("Unknown Protocol: 0x%02x\n", ip->ip_p);
138 		break;
139 	}
140 #endif
141 	raw_dump(level, frm);
142 }
143