Hello community, here is the log from the commit of package bluez-hcidump checked in at Tue Oct 31 14:56:43 CET 2006. -------- --- bluez-hcidump/bluez-hcidump.changes 2006-09-03 19:19:42.000000000 +0200 +++ /mounts/work_src_done/STABLE/bluez-hcidump/bluez-hcidump.changes 2006-10-31 12:24:28.000000000 +0100 @@ -1,0 +2,7 @@ +Tue Oct 31 12:24:02 CET 2006 - seife@suse.de + +- update to v1.33: + * Add support for IPv6 decoding. + * Add IPv6 connection support. + +------------------------------------------------------------------- Old: ---- bluez-hcidump-1.32.tar.gz New: ---- bluez-hcidump-1.33.tar.gz ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Other differences: ------------------ ++++++ bluez-hcidump.spec ++++++ --- /var/tmp/diff_new_pack.TQ8iEh/_old 2006-10-31 14:55:55.000000000 +0100 +++ /var/tmp/diff_new_pack.TQ8iEh/_new 2006-10-31 14:55:55.000000000 +0100 @@ -1,5 +1,5 @@ # -# spec file for package bluez-hcidump (Version 1.32) +# spec file for package bluez-hcidump (Version 1.33) # # Copyright (c) 2006 SUSE LINUX Products GmbH, Nuernberg, Germany. # This file and all modifications and additions to the pristine @@ -13,10 +13,10 @@ Name: bluez-hcidump BuildRequires: bluez-libs pkgconfig URL: http://bluez.sourceforge.net -Version: 1.32 +Version: 1.33 Release: 1 Summary: HCI Dumper for Debugging Bluetooth Connections -License: GPL +License: GNU General Public License (GPL) - all versions PreReq: %insserv_prereq Group: Development/Tools/Debuggers Autoreqprov: on @@ -66,6 +66,10 @@ %doc AUTHORS COPYING INSTALL ChangeLog NEWS README %changelog -n bluez-hcidump +* Tue Oct 31 2006 - seife@suse.de +- update to v1.33: + * Add support for IPv6 decoding. + * Add IPv6 connection support. * Sun Sep 03 2006 - seife@suse.de - update to v1.32: * Add decoding for link supervision timeout change event. ++++++ bluez-hcidump-1.32.tar.gz -> bluez-hcidump-1.33.tar.gz ++++++ diff -urN --exclude=CVS --exclude=.cvsignore --exclude=.svn --exclude=.svnignore old/bluez-hcidump-1.32/ChangeLog new/bluez-hcidump-1.33/ChangeLog --- old/bluez-hcidump-1.32/ChangeLog 2006-08-23 11:12:05.000000000 +0200 +++ new/bluez-hcidump-1.33/ChangeLog 2006-10-21 15:50:14.000000000 +0200 @@ -1,3 +1,7 @@ +ver 1.33: + Add support for IPv6 decoding. + Add IPv6 connection support. + ver 1.32: Add decoding for link supervision timeout change event. Add decoding for host controller to host flow control setting. diff -urN --exclude=CVS --exclude=.cvsignore --exclude=.svn --exclude=.svnignore old/bluez-hcidump-1.32/configure new/bluez-hcidump-1.33/configure --- old/bluez-hcidump-1.32/configure 2006-08-23 11:16:05.000000000 +0200 +++ new/bluez-hcidump-1.33/configure 2006-10-21 15:50:36.000000000 +0200 @@ -927,7 +927,7 @@ else echo "$as_me: WARNING: no configuration information is in $ac_dir" >&2 fi - cd "$ac_popdir" + cd $ac_popdir done fi @@ -1582,7 +1582,7 @@ # Define the identity of the package. PACKAGE=bluez-hcidump - VERSION=1.32 + VERSION=1.33 cat >>confdefs.h <<_ACEOF @@ -2353,7 +2353,8 @@ cat conftest.err >&5 echo "$as_me:$LINENO: \$? = $ac_status" >&5 (exit $ac_status); } && - { ac_try='test -z "$ac_c_werror_flag" || test ! -s conftest.err' + { ac_try='test -z "$ac_c_werror_flag" + || test ! -s conftest.err' { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 (eval $ac_try) 2>&5 ac_status=$? @@ -2411,7 +2412,8 @@ cat conftest.err >&5 echo "$as_me:$LINENO: \$? = $ac_status" >&5 (exit $ac_status); } && - { ac_try='test -z "$ac_c_werror_flag" || test ! -s conftest.err' + { ac_try='test -z "$ac_c_werror_flag" + || test ! -s conftest.err' { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 (eval $ac_try) 2>&5 ac_status=$? @@ -2527,7 +2529,8 @@ cat conftest.err >&5 echo "$as_me:$LINENO: \$? = $ac_status" >&5 (exit $ac_status); } && - { ac_try='test -z "$ac_c_werror_flag" || test ! -s conftest.err' + { ac_try='test -z "$ac_c_werror_flag" + || test ! -s conftest.err' { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 (eval $ac_try) 2>&5 ac_status=$? @@ -2581,7 +2584,8 @@ cat conftest.err >&5 echo "$as_me:$LINENO: \$? = $ac_status" >&5 (exit $ac_status); } && - { ac_try='test -z "$ac_c_werror_flag" || test ! -s conftest.err' + { ac_try='test -z "$ac_c_werror_flag" + || test ! -s conftest.err' { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 (eval $ac_try) 2>&5 ac_status=$? @@ -2626,7 +2630,8 @@ cat conftest.err >&5 echo "$as_me:$LINENO: \$? = $ac_status" >&5 (exit $ac_status); } && - { ac_try='test -z "$ac_c_werror_flag" || test ! -s conftest.err' + { ac_try='test -z "$ac_c_werror_flag" + || test ! -s conftest.err' { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 (eval $ac_try) 2>&5 ac_status=$? @@ -2670,7 +2675,8 @@ cat conftest.err >&5 echo "$as_me:$LINENO: \$? = $ac_status" >&5 (exit $ac_status); } && - { ac_try='test -z "$ac_c_werror_flag" || test ! -s conftest.err' + { ac_try='test -z "$ac_c_werror_flag" + || test ! -s conftest.err' { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 (eval $ac_try) 2>&5 ac_status=$? @@ -4150,6 +4156,11 @@ *) ac_INSTALL=$ac_top_builddir$INSTALL ;; esac + if test x"$ac_file" != x-; then + { echo "$as_me:$LINENO: creating $ac_file" >&5 +echo "$as_me: creating $ac_file" >&6;} + rm -f "$ac_file" + fi # Let's still pretend it is `configure' which instantiates (i.e., don't # use $as_me), people would be surprised to read: # /* config.h. Generated by config.status. */ @@ -4188,12 +4199,6 @@ fi;; esac done` || { (exit 1); exit 1; } - - if test x"$ac_file" != x-; then - { echo "$as_me:$LINENO: creating $ac_file" >&5 -echo "$as_me: creating $ac_file" >&6;} - rm -f "$ac_file" - fi _ACEOF cat >>$CONFIG_STATUS <<_ACEOF sed "$ac_vpsub diff -urN --exclude=CVS --exclude=.cvsignore --exclude=.svn --exclude=.svnignore old/bluez-hcidump-1.32/configure.in new/bluez-hcidump-1.33/configure.in --- old/bluez-hcidump-1.32/configure.in 2006-08-23 11:12:05.000000000 +0200 +++ new/bluez-hcidump-1.33/configure.in 2006-10-21 15:50:14.000000000 +0200 @@ -1,7 +1,7 @@ AC_PREREQ(2.50) AC_INIT() -AM_INIT_AUTOMAKE(bluez-hcidump, 1.32) +AM_INIT_AUTOMAKE(bluez-hcidump, 1.33) AM_CONFIG_HEADER(config.h) AM_MAINTAINER_MODE diff -urN --exclude=CVS --exclude=.cvsignore --exclude=.svn --exclude=.svnignore old/bluez-hcidump-1.32/parser/bnep.c new/bluez-hcidump-1.33/parser/bnep.c --- old/bluez-hcidump-1.32/parser/bnep.c 2006-01-21 16:19:33.000000000 +0100 +++ new/bluez-hcidump-1.33/parser/bnep.c 2006-10-21 15:47:13.000000000 +0200 @@ -56,6 +56,10 @@ /* BNEP Extension Type */ #define BNEP_EXTENSION_CONTROL 0x00 +#ifndef ETHERTYPE_IPV6 +#define ETHERTYPE_IPV6 ETH_P_IPV6 +#endif + static char *get_macaddr(struct frame *frm) { static char str[20]; @@ -63,8 +67,10 @@ sprintf(str, "%02x:%02x:%02x:%02x:%02x:%02x", buf[0], buf[1], buf[2], buf[3], buf[4], buf[5]); + frm->ptr += 6; frm->len -= 6; + return str; } @@ -131,12 +137,14 @@ break; case BNEP_SETUP_CONNECTION_RESPONSE_MSG: - printf("Setup Rsp(0x%02x) res 0x%04x\n", type, get_u16(frm)); + printf("Setup Rsp(0x%02x) res 0x%04x\n", + type, get_u16(frm)); break; case BNEP_FILTER_NET_TYPE_SET_MSG: length = get_u16(frm); - printf("Filter NetType Set(0x%02x) len 0x%04x\n", type, length); + printf("Filter NetType Set(0x%02x) len 0x%04x\n", + type, length); for (i = 0; i < length / 4; i++) { p_indent(level + 1, frm); printf("0x%04x - ", get_u16(frm)); @@ -145,12 +153,14 @@ break; case BNEP_FILTER_NET_TYPE_RESPONSE_MSG: - printf("Filter NetType Rsp(0x%02x) res 0x%04x\n", type, get_u16(frm)); + printf("Filter NetType Rsp(0x%02x) res 0x%04x\n", + type, get_u16(frm)); break; case BNEP_FILTER_MULT_ADDR_SET_MSG: length = get_u16(frm); - printf("Filter MultAddr Set(0x%02x) len 0x%04x\n", type, length); + printf("Filter MultAddr Set(0x%02x) len 0x%04x\n", + type, length); for (i = 0; i < length / 12; i++) { p_indent(level + 1, frm); printf("%s - ", get_macaddr(frm)); @@ -159,7 +169,8 @@ break; case BNEP_FILTER_MULT_ADDR_RESPONSE_MSG: - printf("Filter MultAddr Rsp(0x%02x) res 0x%04x\n", type, get_u16(frm)); + printf("Filter MultAddr Rsp(0x%02x) res 0x%04x\n", + type, get_u16(frm)); break; default: @@ -174,26 +185,28 @@ static void bnep_eval_extension(int level, struct frame *frm) { uint8_t type = get_u8(frm); - int extension = type & 0x80; uint8_t length = get_u8(frm); + int extension = type & 0x80; p_indent(level, frm); + switch (type & 0x7f) { case BNEP_EXTENSION_CONTROL: - printf("Ext Control(0x%02x|%s) len 0x%02x\n", type & 0x7f, extension ? "1" : "0", length); + printf("Ext Control(0x%02x|%s) len 0x%02x\n", + type & 0x7f, extension ? "1" : "0", length); bnep_control(level, frm, length); break; default: - printf("Ext Unknown(0x%02x|%s) len 0x%02x\n", type & 0x7f, extension ? "1" : "0", length); + printf("Ext Unknown(0x%02x|%s) len 0x%02x\n", + type & 0x7f, extension ? "1" : "0", length); raw_ndump(level + 1, frm, length); frm->ptr += length; frm->len -= length; } - if (extension) { + if (extension) bnep_eval_extension(level, frm); - } } void bnep_dump(int level, struct frame *frm) @@ -206,19 +219,22 @@ switch (type & 0x7f) { case BNEP_CONTROL: - printf("BNEP: Control(0x%02x|%s)\n", type & 0x7f, extension ? "1" : "0"); + printf("BNEP: Control(0x%02x|%s)\n", + type & 0x7f, extension ? "1" : "0"); bnep_control(level, frm, -1); break; case BNEP_COMPRESSED_ETHERNET: - printf("BNEP: Compressed(0x%02x|%s)\n", type & 0x7f, extension ? "1" : "0"); + printf("BNEP: Compressed(0x%02x|%s)\n", + type & 0x7f, extension ? "1" : "0"); p_indent(++level, frm); proto = get_u16(frm); printf("[proto 0x%04x]\n", proto); break; case BNEP_GENERAL_ETHERNET: - printf("BNEP: General ethernet(0x%02x|%s)\n", type & 0x7f, extension ? "1" : "0"); + printf("BNEP: General ethernet(0x%02x|%s)\n", + type & 0x7f, extension ? "1" : "0"); p_indent(++level, frm); printf("dst %s ", get_macaddr(frm)); printf("src %s ", get_macaddr(frm)); @@ -227,7 +243,8 @@ break; case BNEP_COMPRESSED_ETHERNET_DEST_ONLY: - printf("BNEP: Compressed DestOnly(0x%02x|%s)\n", type & 0x7f, extension ? "1" : "0"); + printf("BNEP: Compressed DestOnly(0x%02x|%s)\n", + type & 0x7f, extension ? "1" : "0"); p_indent(++level, frm); printf("dst %s ", get_macaddr(frm)); proto = get_u16(frm); @@ -235,7 +252,8 @@ break; case BNEP_COMPRESSED_ETHERNET_SOURCE_ONLY: - printf("BNEP: Compressed SrcOnly(0x%02x|%s)\n", type & 0x7f, extension ? "1" : "0"); + printf("BNEP: Compressed SrcOnly(0x%02x|%s)\n", + type & 0x7f, extension ? "1" : "0"); p_indent(++level, frm); printf("src %s ", get_macaddr(frm)); proto = get_u16(frm); @@ -287,6 +305,12 @@ ip_dump(level, frm); break; + case ETHERTYPE_IPV6: + p_indent(++level, frm); + printf("IPV6: "); + ip_dump(level, frm); + break; + default: raw_dump(level, frm); break; diff -urN --exclude=CVS --exclude=.cvsignore --exclude=.svn --exclude=.svnignore old/bluez-hcidump-1.32/parser/obex.c new/bluez-hcidump-1.33/parser/obex.c --- old/bluez-hcidump-1.32/parser/obex.c 2006-08-22 08:26:05.000000000 +0200 +++ new/bluez-hcidump-1.33/parser/obex.c 2006-09-03 11:23:54.000000000 +0200 @@ -269,8 +269,10 @@ set_status(frm->handle, frm->dlci, status); - if (frm->len == 0) + if (frm->len == 0) { + printf("\n"); break; + } switch (opcode & 0x7f) { case 0x00: /* Connect */ diff -urN --exclude=CVS --exclude=.cvsignore --exclude=.svn --exclude=.svnignore old/bluez-hcidump-1.32/parser/tcpip.c new/bluez-hcidump-1.33/parser/tcpip.c --- old/bluez-hcidump-1.32/parser/tcpip.c 2006-01-21 16:19:33.000000000 +0100 +++ new/bluez-hcidump-1.33/parser/tcpip.c 2006-10-21 15:50:14.000000000 +0200 @@ -35,26 +35,37 @@ #include <net/ethernet.h> #include <netinet/in.h> #include <netinet/ip.h> +#include <netinet/ip6.h> #include <netinet/if_ether.h> #include <arpa/inet.h> +#include <netdb.h> #include "parser.h" void arp_dump(int level, struct frame *frm) { int i; + char buf[20]; + struct sockaddr_in sai; 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)); + sai.sin_family = AF_INET; + memcpy(&sai.sin_addr, &arp->arp_spa, sizeof(sai.sin_addr)); + getnameinfo((struct sockaddr *) &sai, sizeof(sai), buf, sizeof(buf), + NULL, 0, NI_NUMERICHOST); + printf("(%s) ", buf); 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)); + memcpy(&sai.sin_addr, &arp->arp_tpa, sizeof(sai.sin_addr)); + getnameinfo((struct sockaddr *) &sai, sizeof(sai), buf, sizeof(buf), + NULL, 0, NI_NUMERICHOST); + printf("(%s)\n", buf); frm->ptr += sizeof(struct ether_arp); frm->len -= sizeof(struct ether_arp); raw_dump(level, frm); // not needed. @@ -62,33 +73,69 @@ void ip_dump(int level, struct frame *frm) { + char src[50], dst[50]; struct ip *ip = (struct ip *) (frm->ptr); - int len = ip->ip_hl << 2; + uint8_t proto; + int len; + + if (ip->ip_v == 4) { + struct sockaddr_in sai; + proto = ip->ip_p; + len = ip->ip_hl << 2; + memset(&sai, 0, sizeof(sai)); + sai.sin_family = AF_INET; + memcpy(&sai.sin_addr, &ip->ip_src, sizeof(struct in_addr)); + getnameinfo((struct sockaddr *) &sai, sizeof(sai), + src, sizeof(src), NULL, 0, NI_NUMERICHOST); + memcpy(&sai.sin_addr, &ip->ip_dst, sizeof(struct in_addr)); + getnameinfo((struct sockaddr *) &sai, sizeof(sai), + dst, sizeof(dst), NULL, 0, NI_NUMERICHOST); + } else if (ip->ip_v == 6) { + struct sockaddr_in6 sai6; + struct ip6_hdr *ip6 = (struct ip6_hdr *) ip; + proto = ip6->ip6_nxt; + len = sizeof(struct ip6_hdr); + memset(&sai6, 0, sizeof(sai6)); + sai6.sin6_family = AF_INET6; + memcpy(&sai6.sin6_addr, &ip6->ip6_src, sizeof(struct in6_addr)); + getnameinfo((struct sockaddr *) &sai6, sizeof(sai6), + src, sizeof(src), NULL, 0, NI_NUMERICHOST); + memcpy(&sai6.sin6_addr, &ip6->ip6_dst, sizeof(struct in6_addr)); + getnameinfo((struct sockaddr *) &sai6, sizeof(sai6), + dst, sizeof(dst), NULL, 0, NI_NUMERICHOST); + } else { + raw_dump(level, frm); + return; + } + + printf("src %s ", src); + printf("dst %s\n", dst); + 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) { + switch (proto) { 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; + + case IPPROTO_ICMPV6: + printf("ICMPv6:\n"); break; default: printf("Unknown Protocol: 0x%02x\n", ip->ip_p); - raw_dump(level, frm); + break; } + + raw_dump(level, frm); } diff -urN --exclude=CVS --exclude=.cvsignore --exclude=.svn --exclude=.svnignore old/bluez-hcidump-1.32/src/hcidump.8 new/bluez-hcidump-1.33/src/hcidump.8 --- old/bluez-hcidump-1.32/src/hcidump.8 2006-01-17 19:45:06.000000000 +0100 +++ new/bluez-hcidump-1.33/src/hcidump.8 2006-10-21 15:47:13.000000000 +0200 @@ -108,6 +108,12 @@ .TP .BR -N ", " "\-\^\-noappend" No appending to existing files. Always create new files. +.TP +.BR -4 ", " "\-\^\-ipv4" +Use IPv4 when sending information over the network +.TP +.BR -6 ", " "\-\^\-ipv6" +Use IPv6 when sending information over the network .SH FILTERS .B filter diff -urN --exclude=CVS --exclude=.cvsignore --exclude=.svn --exclude=.svnignore old/bluez-hcidump-1.32/src/hcidump.c new/bluez-hcidump-1.33/src/hcidump.c --- old/bluez-hcidump-1.32/src/hcidump.c 2006-01-17 19:45:06.000000000 +0100 +++ new/bluez-hcidump-1.33/src/hcidump.c 2006-10-21 15:47:13.000000000 +0200 @@ -66,7 +66,7 @@ #define hton64(x) ntoh64(x) #define SNAP_LEN HCI_MAX_FRAME_SIZE -#define DEFAULT_PORT 10839; +#define DEFAULT_PORT "10839"; /* Modes */ enum { @@ -92,8 +92,9 @@ static char *dump_file = NULL; static char *pppdump_file = NULL; static char *audio_file = NULL; -static in_addr_t dump_addr = INADDR_LOOPBACK; -static in_port_t dump_port = DEFAULT_PORT; +static char *dump_addr; +static char *dump_port = DEFAULT_PORT; +static int af = AF_UNSPEC; struct hcidump_hdr { uint16_t len; @@ -504,88 +505,146 @@ return sk; } -static int open_connection(in_addr_t addr, in_port_t port) +static int open_connection(char *addr, char *port) { - struct sockaddr_in sa; - int sk, opt; + struct sockaddr_storage ss; + struct addrinfo hints, *res0, *res; + int sk = -1, opt = 1; + + memset(&hints, 0, sizeof(hints)); + hints.ai_family = af; + hints.ai_socktype = SOCK_STREAM; + hints.ai_protocol = IPPROTO_TCP; + + if (getaddrinfo(addr, port, &hints, &res0)) + if(getaddrinfo(NULL, port, &hints, &res0)) { + perror("getaddrinfo"); + exit(1); + } + + for (res = res0; res; res = res->ai_next) { + sk = socket(res->ai_family, res->ai_socktype, res->ai_protocol); + if (sk < 0) { + if (res->ai_next) + continue; - sk = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP); - if (sk < 0) { - perror("Can't create inet socket"); - exit(1); - } + perror("Can't create socket"); + freeaddrinfo(res0); + exit(1); + } - opt = 1; - setsockopt(sk, SOL_SOCKET, SO_REUSEADDR, &opt, sizeof(opt)); + setsockopt(sk, SOL_SOCKET, SO_REUSEADDR, &opt, sizeof(opt)); + + memcpy(&ss, res->ai_addr, res->ai_addrlen); - sa.sin_family = AF_INET; - sa.sin_addr.s_addr = htonl(INADDR_ANY); - sa.sin_port = htons(0); - if (bind(sk, (struct sockaddr *) &sa, sizeof(sa)) < 0) { - perror("Can't bind inet socket"); - close(sk); - exit(1); - } + switch(ss.ss_family) { + case AF_INET: + ((struct sockaddr_in *) &ss)->sin_addr.s_addr = htonl(INADDR_ANY); + ((struct sockaddr_in *) &ss)->sin_port = 0; + break; + case AF_INET6: + memcpy(&((struct sockaddr_in6 *) &ss)->sin6_addr, &in6addr_any, sizeof(in6addr_any)); + ((struct sockaddr_in6 *) &ss)->sin6_port = 0; + break; + } - sa.sin_family = AF_INET; - sa.sin_addr.s_addr = htonl(addr); - sa.sin_port = htons(port); - if (connect(sk, (struct sockaddr *) &sa, sizeof(sa)) < 0) { - perror("Can't connect inet socket"); - close(sk); - exit(1); + if (bind(sk, (struct sockaddr *) &ss, sizeof(ss)) < 0) { + perror("Can't bind socket"); + close(sk); + freeaddrinfo(res0); + exit(1); + } + + if (connect(sk, res->ai_addr, res->ai_addrlen) < 0) { + perror("Can't connect socket"); + close(sk); + freeaddrinfo(res0); + exit(1); + } } + freeaddrinfo(res0); + return sk; } -static int wait_connection(in_addr_t addr, in_port_t port) +static int wait_connection(char *addr, char *port) { - struct sockaddr_in sa; - struct hostent *host; + char hname[100], hport[10]; + struct sockaddr_storage ss; + struct addrinfo hints, *res0, *res; socklen_t len; - int sk, nsk, opt; + int sk = -1, nsk, opt = 1; - sk = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP); - if (sk < 0) { - perror("Can't create inet socket"); - exit(1); - } + memset(&hints, 0, sizeof(hints)); + hints.ai_family = af; + hints.ai_socktype = SOCK_STREAM; + hints.ai_protocol = IPPROTO_TCP; + + if (getaddrinfo(addr, port, &hints, &res0)) + if (getaddrinfo(NULL, port, &hints, &res0)) { + perror("getaddrinfo"); + exit(1); + } + + for (res = res0; res; res = res->ai_next) { + sk = socket(res->ai_family, res->ai_socktype, res->ai_protocol); + if (sk < 0) { + if (res->ai_next) + continue; - opt = 1; - setsockopt(sk, SOL_SOCKET, SO_REUSEADDR, &opt, sizeof(opt)); + perror("Can't create socket"); + freeaddrinfo(res0); + exit(1); + } - sa.sin_family = AF_INET; - sa.sin_addr.s_addr = htonl(addr); - sa.sin_port = htons(port); - if (bind(sk, (struct sockaddr *) &sa, sizeof(sa)) < 0) { - perror("Can't bind inet socket"); - close(sk); - exit(1); - } + setsockopt(sk, SOL_SOCKET, SO_REUSEADDR, &opt, sizeof(opt)); + + if (bind(sk, res->ai_addr, res->ai_addrlen) < 0) { + if(res->ai_next) { + close(sk); + continue; + } - host = gethostbyaddr(&sa.sin_addr, sizeof(sa.sin_addr), AF_INET); - printf("device: %s:%d snap_len: %d filter: 0x%lx\n", - host ? host->h_name : inet_ntoa(sa.sin_addr), - ntohs(sa.sin_port), snap_len, filter); + perror("Can't bind socket"); + close(sk); + freeaddrinfo(res0); + exit(1); + } - if (listen(sk, 1)) { - perror("Can't listen on inet socket"); - close(sk); - exit(1); + getnameinfo(res->ai_addr, res->ai_addrlen, hname, sizeof(hname), + hport, sizeof(hport), NI_NUMERICSERV); + printf("device: %s:%s snap_len: %d filter: 0x%lx\n", + hname, hport, snap_len, filter); + if (listen(sk, 1) < 0) { + if (res->ai_next) { + close(sk); + continue; + } + + perror("Can't listen on socket"); + close(sk); + freeaddrinfo(res0); + exit(1); + } } - len = sizeof(sa); - nsk = accept(sk, (struct sockaddr *) &sa, &len); + freeaddrinfo(res0); + + len = sizeof(ss); + nsk = accept(sk, (struct sockaddr *) &ss, &len); if (nsk < 0) { - perror("Can't accept new inet socket"); + perror("Can't accept new socket"); close(sk); + freeaddrinfo(res0); exit(1); } - host = gethostbyaddr(&sa.sin_addr, sizeof(sa.sin_addr), AF_INET); - printf("device: %s snap_len: %d filter: 0x%lx\n", - host ? host->h_name : inet_ntoa(sa.sin_addr), snap_len, filter); + getnameinfo((struct sockaddr *) &ss, sizeof(ss), + hname, sizeof(hname), NULL, 0, 0); + + printf("device: %s snap_len: %d filter: 0x%lx\n", + hname, snap_len, filter); close(sk); @@ -657,6 +716,8 @@ " -V, --verbose Verbose decoding\n" " -Y, --novendor No vendor commands or events\n" " -N, --noappend No appending to existing files\n" + " -4, --ipv4 Use IPv4 as transport\n" + " -6 --ipv6 Use IPv6 as transport\n" " -h, --help Give this help list\n" " --usage Give a short usage message\n" ); @@ -687,19 +748,19 @@ { "novendor", 0, 0, 'Y' }, { "nopermcheck", 0, 0, 'Z' }, { "noappend", 0, 0, 'N' }, + { "ipv4", 0, 0, '4' }, + { "ipv6", 0, 0, '6' }, { "help", 0, 0, 'h' }, { 0 } }; int main(int argc, char *argv[]) { - struct hostent *host; - struct in_addr addr; int opt, pppdump_fd = -1, audio_fd = -1; printf("HCI sniffer - Bluetooth packet analyzer ver %s\n", VERSION); - while ((opt=getopt_long(argc, argv, "i:l:p:m:w:r:s:n:taxXRC:H:O:P:D:A:BVYZNh", main_options, NULL)) != -1) { + while ((opt=getopt_long(argc, argv, "i:l:p:m:w:r:s:n:taxXRC:H:O:P:D:A:BVYZN46h", main_options, NULL)) != -1) { switch(opt) { case 'i': if (strcasecmp(optarg, "none") && strcasecmp(optarg, "system")) @@ -732,28 +793,12 @@ case 's': mode = SEND; - host = gethostbyname(optarg); - if (host) { - bcopy(host->h_addr, &addr, sizeof(struct in_addr)); - dump_addr = ntohl(addr.s_addr); - dump_port = DEFAULT_PORT; - } else { - dump_addr = INADDR_LOOPBACK; - dump_port = DEFAULT_PORT; - } + dump_addr = optarg; break; case 'n': mode = RECEIVE; - host = gethostbyname(optarg); - if (host) { - bcopy(host->h_addr, &addr, sizeof(struct in_addr)); - dump_addr = ntohl(addr.s_addr); - dump_port = DEFAULT_PORT; - } else { - dump_addr = INADDR_LOOPBACK; - dump_port = DEFAULT_PORT; - } + dump_addr = optarg; break; case 't': @@ -820,6 +865,14 @@ noappend = 1; break; + case '4': + af = AF_INET; + break; + + case '6': + af = AF_INET6; + break; + case 'h': default: usage(); ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Remember to have fun... --------------------------------------------------------------------- To unsubscribe, e-mail: opensuse-commit+unsubscribe@opensuse.org For additional commands, e-mail: opensuse-commit+help@opensuse.org
participants (1)
-
root@suse.de