Remove some unnecessary dependencies and cleanup some code

No need for the GTK dependency on dissectors/packet-ipv6.h.

Add the stream_addr typedef in follow.h to make some code simpler.

Change-Id: I1cf906f58734a90263141362f2da33a140f93533
Reviewed-on: https://code.wireshark.org/review/13063
Reviewed-by: João Valverde <j@v6e.pt>
Petri-Dish: Michael Mann <mmann78@netscape.net>
Tested-by: Petri Dish Buildbot <buildbot-no-reply@wireshark.org>
Reviewed-by: Michael Mann <mmann78@netscape.net>
This commit is contained in:
João Valverde 2016-01-05 11:30:16 +00:00 committed by Michael Mann
parent 7888c43a57
commit f410121cf2
9 changed files with 68 additions and 98 deletions

View File

@ -40,8 +40,6 @@
#include <epan/conversation.h>
#include <epan/tap.h>
#define MAX_IPADDR_LEN 16
typedef struct _tcp_frag {
guint32 seq;
guint32 len;
@ -60,7 +58,7 @@ static guint32 stream_to_follow[MAX_STREAM] = {0};
static gboolean find_addr[MAX_STREAM] = {FALSE};
static gboolean find_index[MAX_STREAM] = {FALSE};
static address tcp_addr[2];
static guint8 ip_address[2][MAX_IPADDR_LEN];
static stream_addr ip_address[2];
static guint port[2];
static guint bytes_written[2];
static gboolean is_ipv6 = FALSE;
@ -71,11 +69,11 @@ follow_stats(follow_stats_t* stats)
int i;
for (i = 0; i < 2 ; i++) {
memcpy(stats->ip_address[i], ip_address[i], MAX_IPADDR_LEN);
stats->ip_address[i] = ip_address[i];
stats->port[i] = port[i];
stats->bytes_written[i] = bytes_written[i];
stats->is_ipv6 = is_ipv6;
}
stats->is_ipv6 = is_ipv6;
}
/* This will build a display filter text that will only
@ -163,8 +161,8 @@ build_follow_conv_filter( packet_info *pi, const char* append_filter ) {
else {
return NULL;
}
memcpy(ip_address[0], pi->net_src.data, len);
memcpy(ip_address[1], pi->net_dst.data, len);
memcpy(&ip_address[0], pi->net_src.data, len);
memcpy(&ip_address[1], pi->net_dst.data, len);
port[0] = pi->srcport;
port[1] = pi->destport;
return buf;
@ -180,8 +178,8 @@ udp_follow_packet(void *tapdata _U_, packet_info *pinfo,
} else {
is_ipv6 = FALSE;
}
memcpy(ip_address[0], pinfo->net_src.data, pinfo->net_src.len);
memcpy(ip_address[1], pinfo->net_dst.data, pinfo->net_dst.len);
memcpy(&ip_address[0], pinfo->net_src.data, pinfo->net_src.len);
memcpy(&ip_address[1], pinfo->net_dst.data, pinfo->net_dst.len);
port[0] = pinfo->srcport;
port[1] = pinfo->destport;
find_addr[UDP_STREAM] = FALSE;
@ -197,7 +195,7 @@ udp_follow_packet(void *tapdata _U_, packet_info *pinfo,
static tcp_frag *frags[2] = { 0, 0 };
static guint32 seq[2];
static guint8 src_addr[2][MAX_IPADDR_LEN];
static stream_addr src_addr[2];
static guint src_port[2] = { 0, 0 };
void
@ -214,9 +212,9 @@ reset_stream_follow(stream_type stream) {
for( i=0; i<2; i++ ) {
seq[i] = 0;
memset(src_addr[i], '\0', MAX_IPADDR_LEN);
memset(&src_addr[i], 0, sizeof(src_addr[i]));
src_port[i] = 0;
memset(ip_address[i], '\0', MAX_IPADDR_LEN);
memset(&ip_address[i], 0, sizeof(src_addr[i]));
port[i] = 0;
bytes_written[i] = 0;
current = frags[i];
@ -273,16 +271,16 @@ follow_addr(stream_type stream, const address *addr0, guint port0,
}
memcpy(ip_address[0], addr0->data, addr0->len);
memcpy(&ip_address[0], addr0->data, addr0->len);
port[0] = port0;
memcpy(ip_address[1], addr1->data, addr1->len);
memcpy(&ip_address[1], addr1->data, addr1->len);
port[1] = port1;
if (stream == TCP_STREAM) {
find_index[TCP_STREAM] = TRUE;
set_address(&tcp_addr[0], addr0->type, addr0->len, ip_address[0]);
set_address(&tcp_addr[1], addr1->type, addr1->len, ip_address[1]);
set_address(&tcp_addr[0], addr0->type, addr0->len, &ip_address[0]);
set_address(&tcp_addr[1], addr1->type, addr1->len, &ip_address[1]);
}
return TRUE;

View File

@ -30,22 +30,26 @@ extern "C" {
#endif /* __cplusplus */
#include <epan/packet.h>
#include <epan/ipv6.h>
#include "ws_symbol_export.h"
#define MAX_IPADDR_LEN 16
typedef enum {
TCP_STREAM = 0,
UDP_STREAM,
MAX_STREAM
} stream_type;
typedef union _stream_addr {
guint32 ipv4;
struct e_in6_addr ipv6;
} stream_addr;
/* With MSVC and a libwireshark.dll, we need a special declaration. */
WS_DLL_PUBLIC gboolean empty_tcp_stream;
WS_DLL_PUBLIC gboolean incomplete_tcp_stream;
typedef struct _tcp_stream_chunk {
guint8 src_addr[MAX_IPADDR_LEN];
stream_addr src_addr;
guint16 src_port;
guint32 dlen;
guint32 packet_num;
@ -94,10 +98,10 @@ WS_DLL_PUBLIC
void reset_stream_follow(stream_type stream);
typedef struct {
guint8 ip_address[2][MAX_IPADDR_LEN];
guint32 port[2];
unsigned int bytes_written[2];
gboolean is_ipv6;
stream_addr ip_address[2];
guint32 port[2];
guint bytes_written[2];
gboolean is_ipv6;
} follow_stats_t;
WS_DLL_PUBLIC

View File

@ -328,7 +328,7 @@ follow_common_stream_packet(
if (tvbp->length > 0)
{
memcpy(sc.src_addr, pip->net_src.data, pip->net_src.len);
memcpy(&sc.src_addr, pip->net_src.data, pip->net_src.len);
sc.src_port = pip->srcport;
sc.dlen = tvbp->length;
sc.packet_num = pip->fd->num;
@ -391,7 +391,7 @@ followSslPacket(
if (length > 0)
{
memcpy(sc.src_addr, pip->net_src.data, pip->net_src.len);
memcpy(&sc.src_addr, pip->net_src.data, pip->net_src.len);
sc.src_port = pip->srcport;
sc.dlen = length;
sc.packet_num = pip->fd->num;
@ -518,15 +518,15 @@ followDraw(
if ((fp->type == type_TCP) || (fp->type == type_UDP))
{
static const guint8 ip_zero[MAX_IPADDR_LEN] = {0};
static const stream_addr ip_zero = {0};
follow_stats_t stats;
address_type type;
follow_stats(&stats);
if (stats.port[0] == 0 && stats.port[1] == 0 &&
memcmp(stats.ip_address[0], ip_zero, sizeof ip_zero) == 0 &&
memcmp(stats.ip_address[1], ip_zero, sizeof ip_zero) == 0)
memcmp(&stats.ip_address[0], &ip_zero, sizeof ip_zero) == 0 &&
memcmp(&stats.ip_address[1], &ip_zero, sizeof ip_zero) == 0)
{
type = AT_NONE;
len = 0;
@ -544,7 +544,7 @@ followDraw(
for (node = 0; node < 2; node++)
{
memcpy(fp->addrBuf[node], stats.ip_address[node], len);
memcpy(fp->addrBuf[node], &stats.ip_address[node], len);
set_address(&fp->addr[node], type, len, fp->addrBuf[node]);
fp->port[node] = stats.port[node];
}
@ -559,7 +559,7 @@ followDraw(
{
/* no data */
sc.dlen = 0;
memcpy(sc.src_addr, fp->addr[0].data, fp->addr[0].len) ;
memcpy(&sc.src_addr, fp->addr[0].data, fp->addr[0].len) ;
sc.src_port = fp->port[0];
break;
}
@ -571,7 +571,7 @@ followDraw(
}
/* node 0 is source of first chunk with data */
if (memcmp(sc.src_addr, fp->addr[0].data, fp->addr[0].len) == 0 &&
if (memcmp(&sc.src_addr, fp->addr[0].data, fp->addr[0].len) == 0 &&
sc.src_port == fp->port[0])
{
addr[0] = &fp->addr[0];
@ -608,7 +608,7 @@ followDraw(
while (chunk <= fp->chunkMax)
{
node = (memcmp(addr[0]->data, sc.src_addr, addr[0]->len) == 0 &&
node = (memcmp(addr[0]->data, &sc.src_addr, addr[0]->len) == 0 &&
port[0] == sc.src_port) ? 0 : 1;
if (chunk < fp->chunkMin)

View File

@ -42,7 +42,6 @@
#include <epan/addr_resolv.h>
#include <epan/epan_dissect.h>
#include <wsutil/filesystem.h>
#include <epan/dissectors/packet-ipv6.h>
#include <ui/alert_box.h>
#include <ui/last_open_dir.h>

View File

@ -176,17 +176,11 @@ follow_http_stream_cb(GtkWidget *w _U_, gpointer data _U_)
follow_stats(&stats);
if (stats.is_ipv6) {
struct e_in6_addr ipaddr;
memcpy(&ipaddr, stats.ip_address[0], 16);
hostname0 = get_hostname6(&ipaddr);
memcpy(&ipaddr, stats.ip_address[1], 16);
hostname1 = get_hostname6(&ipaddr);
hostname0 = get_hostname6(&stats.ip_address[0].ipv6);
hostname1 = get_hostname6(&stats.ip_address[1].ipv6);
} else {
guint32 ipaddr;
memcpy(&ipaddr, stats.ip_address[0], 4);
hostname0 = get_hostname(ipaddr);
memcpy(&ipaddr, stats.ip_address[1], 4);
hostname1 = get_hostname(ipaddr);
hostname0 = get_hostname(stats.ip_address[0].ipv4);
hostname1 = get_hostname(stats.ip_address[1].ipv4);
}
port0 = tcp_port_to_display(NULL, stats.port[0]);
@ -198,8 +192,8 @@ follow_http_stream_cb(GtkWidget *w _U_, gpointer data _U_)
both_directions_string = g_strdup_printf("Entire conversation (%u bytes)", follow_info->bytes_written[0] + follow_info->bytes_written[1]);
if ((follow_info->client_port == stats.port[0]) &&
((stats.is_ipv6 && (memcmp(follow_info->client_ip.data, stats.ip_address[0], 16) == 0)) ||
(!stats.is_ipv6 && (memcmp(follow_info->client_ip.data, stats.ip_address[0], 4) == 0)))) {
((stats.is_ipv6 && (memcmp(follow_info->client_ip.data, &stats.ip_address[0], 16) == 0)) ||
(!stats.is_ipv6 && (memcmp(follow_info->client_ip.data, &stats.ip_address[0], 4) == 0)))) {
server_to_client_string =
g_strdup_printf("%s:%s " UTF8_RIGHTWARDS_ARROW " %s:%s (%u bytes)",
hostname0, port0,

View File

@ -31,7 +31,6 @@
#include <gtk/gtk.h>
#include <epan/follow.h>
#include <epan/dissectors/packet-ipv6.h>
#include <epan/prefs.h>
#include <epan/addr_resolv.h>
#include <epan/epan_dissect.h>
@ -226,21 +225,15 @@ follow_ssl_stream_cb(GtkWidget * w _U_, gpointer data _U_)
follow_stats(&stats);
if (stats.is_ipv6) {
struct e_in6_addr ipaddr;
memcpy(&ipaddr, stats.ip_address[0], 16);
hostname0 = get_hostname6(&ipaddr);
memcpy(&ipaddr, stats.ip_address[1], 16);
hostname1 = get_hostname6(&ipaddr);
hostname0 = get_hostname6(&stats.ip_address[0].ipv6);
hostname1 = get_hostname6(&stats.ip_address[1].ipv6);
} else {
guint32 ipaddr;
memcpy(&ipaddr, stats.ip_address[0], 4);
hostname0 = get_hostname(ipaddr);
memcpy(&ipaddr, stats.ip_address[1], 4);
hostname1 = get_hostname(ipaddr);
hostname0 = get_hostname(stats.ip_address[0].ipv4);
hostname1 = get_hostname(stats.ip_address[1].ipv4);
}
port0 = (char*)tcp_port_to_display(NULL, stats.port[0]);
port1 = (char*)tcp_port_to_display(NULL, stats.port[1]);
port0 = tcp_port_to_display(NULL, stats.port[0]);
port1 = tcp_port_to_display(NULL, stats.port[1]);
follow_info->is_ipv6 = stats.is_ipv6;
@ -250,8 +243,8 @@ follow_ssl_stream_cb(GtkWidget * w _U_, gpointer data _U_)
/* ...and then the server-to-client and client-to-server directions. */
if ((follow_info->client_port == stats.port[0]) &&
((stats.is_ipv6 && (memcmp(follow_info->client_ip.data, stats.ip_address[0], 16) == 0)) ||
(!stats.is_ipv6 && (memcmp(follow_info->client_ip.data, stats.ip_address[0], 4) == 0)))) {
((stats.is_ipv6 && (memcmp(follow_info->client_ip.data, &stats.ip_address[0], 16) == 0)) ||
(!stats.is_ipv6 && (memcmp(follow_info->client_ip.data, &stats.ip_address[0], 4) == 0)))) {
server_hostname = hostname0;
server_port = port0;
client_hostname = hostname1;

View File

@ -187,30 +187,24 @@ follow_tcp_stream_cb(GtkWidget * w _U_, gpointer data _U_)
follow_stats(&stats);
if (stats.is_ipv6) {
struct e_in6_addr ipaddr;
memcpy(&ipaddr, stats.ip_address[0], 16);
hostname0 = get_hostname6(&ipaddr);
memcpy(&ipaddr, stats.ip_address[1], 16);
hostname1 = get_hostname6(&ipaddr);
hostname0 = get_hostname6(&stats.ip_address[0].ipv6);
hostname1 = get_hostname6(&stats.ip_address[1].ipv6);
} else {
guint32 ipaddr;
memcpy(&ipaddr, stats.ip_address[0], 4);
hostname0 = get_hostname(ipaddr);
memcpy(&ipaddr, stats.ip_address[1], 4);
hostname1 = get_hostname(ipaddr);
hostname0 = get_hostname(stats.ip_address[0].ipv4);
hostname1 = get_hostname(stats.ip_address[1].ipv4);
}
follow_info->is_ipv6 = stats.is_ipv6;
port0 = (char*)tcp_port_to_display(NULL, stats.port[0]);
port1 = (char*)tcp_port_to_display(NULL, stats.port[1]);
port0 = tcp_port_to_display(NULL, stats.port[0]);
port1 = tcp_port_to_display(NULL, stats.port[1]);
/* Both Stream Directions */
both_directions_string = g_strdup_printf("Entire conversation (%u bytes)", follow_info->bytes_written[0] + follow_info->bytes_written[1]);
if ((follow_info->client_port == stats.port[0]) &&
((stats.is_ipv6 && (memcmp(follow_info->client_ip.data, stats.ip_address[0], 16) == 0)) ||
(!stats.is_ipv6 && (memcmp(follow_info->client_ip.data, stats.ip_address[0], 4) == 0)))) {
((stats.is_ipv6 && (memcmp(follow_info->client_ip.data, &stats.ip_address[0], 16) == 0)) ||
(!stats.is_ipv6 && (memcmp(follow_info->client_ip.data, &stats.ip_address[0], 4) == 0)))) {
server_to_client_string =
g_strdup_printf("%s:%s " UTF8_RIGHTWARDS_ARROW " %s:%s (%u bytes)",
hostname0, port0,

View File

@ -176,17 +176,11 @@ follow_udp_stream_cb(GtkWidget *w _U_, gpointer data _U_)
follow_stats(&stats);
if (stats.is_ipv6) {
struct e_in6_addr ipaddr;
memcpy(&ipaddr, stats.ip_address[0], 16);
hostname0 = get_hostname6(&ipaddr);
memcpy(&ipaddr, stats.ip_address[1], 16);
hostname1 = get_hostname6(&ipaddr);
hostname0 = get_hostname6(&stats.ip_address[0].ipv6);
hostname1 = get_hostname6(&stats.ip_address[1].ipv6);
} else {
guint32 ipaddr;
memcpy(&ipaddr, stats.ip_address[0], 4);
hostname0 = get_hostname(ipaddr);
memcpy(&ipaddr, stats.ip_address[1], 4);
hostname1 = get_hostname(ipaddr);
hostname0 = get_hostname(stats.ip_address[0].ipv4);
hostname1 = get_hostname(stats.ip_address[1].ipv4);
}
port0 = udp_port_to_display(NULL, stats.port[0]);
@ -198,8 +192,8 @@ follow_udp_stream_cb(GtkWidget *w _U_, gpointer data _U_)
both_directions_string = g_strdup_printf("Entire conversation (%u bytes)", follow_info->bytes_written[0] + follow_info->bytes_written[1]);
if ((follow_info->client_port == stats.port[0]) &&
((stats.is_ipv6 && (memcmp(follow_info->client_ip.data, stats.ip_address[0], 16) == 0)) ||
(!stats.is_ipv6 && (memcmp(follow_info->client_ip.data, stats.ip_address[0], 4) == 0)))) {
((stats.is_ipv6 && (memcmp(follow_info->client_ip.data, &stats.ip_address[0], 16) == 0)) ||
(!stats.is_ipv6 && (memcmp(follow_info->client_ip.data, &stats.ip_address[0], 4) == 0)))) {
server_to_client_string =
g_strdup_printf("%s:%s " UTF8_RIGHTWARDS_ARROW " %s:%s (%u bytes)",
hostname0, port0,

View File

@ -1145,17 +1145,11 @@ bool FollowStreamDialog::follow(QString previous_filter, bool use_stream_index)
follow_stats(&stats);
if (stats.is_ipv6) {
struct e_in6_addr ipaddr;
memcpy(&ipaddr, stats.ip_address[0], 16);
hostname0 = get_hostname6(&ipaddr);
memcpy(&ipaddr, stats.ip_address[1], 16);
hostname1 = get_hostname6(&ipaddr);
hostname0 = get_hostname6(&stats.ip_address[0].ipv6);
hostname1 = get_hostname6(&stats.ip_address[1].ipv6);
} else {
guint32 ipaddr;
memcpy(&ipaddr, stats.ip_address[0], 4);
hostname0 = get_hostname(ipaddr);
memcpy(&ipaddr, stats.ip_address[1], 4);
hostname1 = get_hostname(ipaddr);
hostname0 = get_hostname(stats.ip_address[0].ipv4);
hostname1 = get_hostname(stats.ip_address[1].ipv4);
}
switch (follow_type_)
@ -1175,8 +1169,8 @@ bool FollowStreamDialog::follow(QString previous_filter, bool use_stream_index)
follow_info_.is_ipv6 = stats.is_ipv6;
if ((follow_info_.client_port == stats.port[0]) &&
((stats.is_ipv6 && (memcmp(follow_info_.client_ip.data, stats.ip_address[0], 16) == 0)) ||
(!stats.is_ipv6 && (memcmp(follow_info_.client_ip.data, stats.ip_address[0], 4) == 0)))) {
((stats.is_ipv6 && (memcmp(follow_info_.client_ip.data, &stats.ip_address[0], 16) == 0)) ||
(!stats.is_ipv6 && (memcmp(follow_info_.client_ip.data, &stats.ip_address[0], 4) == 0)))) {
server_to_client_string =
QString("%1:%2 %3 %4:%5 (%6)")
.arg(hostname0).arg(port0)