Exit when a packet with an invalid family is found
Fixes compiler warnings
This commit is contained in:
12
nethogs.cpp
12
nethogs.cpp
@@ -123,20 +123,22 @@ int process_tcp (u_char * userdata, const dp_header * header, const u_char * m_p
|
|||||||
Packet * packet;
|
Packet * packet;
|
||||||
switch (args->sa_family)
|
switch (args->sa_family)
|
||||||
{
|
{
|
||||||
case (AF_INET):
|
case AF_INET:
|
||||||
#ifdef __APPLE__
|
#ifdef __APPLE__
|
||||||
packet = new Packet (args->ip_src, ntohs(tcp->th_sport), args->ip_dst, ntohs(tcp->th_dport), header->len, header->ts);
|
packet = new Packet (args->ip_src, ntohs(tcp->th_sport), args->ip_dst, ntohs(tcp->th_dport), header->len, header->ts);
|
||||||
#else
|
#else
|
||||||
packet = new Packet (args->ip_src, ntohs(tcp->source), args->ip_dst, ntohs(tcp->dest), header->len, header->ts);
|
packet = new Packet (args->ip_src, ntohs(tcp->source), args->ip_dst, ntohs(tcp->dest), header->len, header->ts);
|
||||||
#endif
|
#endif
|
||||||
break;
|
break;
|
||||||
case (AF_INET6):
|
case AF_INET6:
|
||||||
#ifdef __APPLE__
|
#ifdef __APPLE__
|
||||||
packet = new Packet (args->ip6_src, ntohs(tcp->th_sport), args->ip6_dst, ntohs(tcp->th_dport), header->len, header->ts);
|
packet = new Packet (args->ip6_src, ntohs(tcp->th_sport), args->ip6_dst, ntohs(tcp->th_dport), header->len, header->ts);
|
||||||
#else
|
#else
|
||||||
packet = new Packet (args->ip6_src, ntohs(tcp->source), args->ip6_dst, ntohs(tcp->dest), header->len, header->ts);
|
packet = new Packet (args->ip6_src, ntohs(tcp->source), args->ip6_dst, ntohs(tcp->dest), header->len, header->ts);
|
||||||
#endif
|
#endif
|
||||||
break;
|
break;
|
||||||
|
default:
|
||||||
|
forceExit(false, "invalid address family for TCP packet: %d", args->sa_family);
|
||||||
}
|
}
|
||||||
|
|
||||||
Connection * connection = findConnection(packet);
|
Connection * connection = findConnection(packet);
|
||||||
@@ -165,20 +167,22 @@ int process_udp (u_char * userdata, const dp_header * header, const u_char * m_p
|
|||||||
Packet * packet;
|
Packet * packet;
|
||||||
switch (args->sa_family)
|
switch (args->sa_family)
|
||||||
{
|
{
|
||||||
case (AF_INET):
|
case AF_INET:
|
||||||
#ifdef __APPLE__
|
#ifdef __APPLE__
|
||||||
packet = new Packet (args->ip_src, ntohs(udp->uh_sport), args->ip_dst, ntohs(udp->uh_dport), header->len, header->ts);
|
packet = new Packet (args->ip_src, ntohs(udp->uh_sport), args->ip_dst, ntohs(udp->uh_dport), header->len, header->ts);
|
||||||
#else
|
#else
|
||||||
packet = new Packet (args->ip_src, ntohs(udp->source), args->ip_dst, ntohs(udp->dest), header->len, header->ts);
|
packet = new Packet (args->ip_src, ntohs(udp->source), args->ip_dst, ntohs(udp->dest), header->len, header->ts);
|
||||||
#endif
|
#endif
|
||||||
break;
|
break;
|
||||||
case (AF_INET6):
|
case AF_INET6:
|
||||||
#ifdef __APPLE__
|
#ifdef __APPLE__
|
||||||
packet = new Packet (args->ip6_src, ntohs(udp->uh_sport), args->ip6_dst, ntohs(udp->uh_dport), header->len, header->ts);
|
packet = new Packet (args->ip6_src, ntohs(udp->uh_sport), args->ip6_dst, ntohs(udp->uh_dport), header->len, header->ts);
|
||||||
#else
|
#else
|
||||||
packet = new Packet (args->ip6_src, ntohs(udp->source), args->ip6_dst, ntohs(udp->dest), header->len, header->ts);
|
packet = new Packet (args->ip6_src, ntohs(udp->source), args->ip6_dst, ntohs(udp->dest), header->len, header->ts);
|
||||||
#endif
|
#endif
|
||||||
break;
|
break;
|
||||||
|
default:
|
||||||
|
forceExit(false, "Invalid address family for UDP packet: %d", args->sa_family);
|
||||||
}
|
}
|
||||||
|
|
||||||
//if (DEBUG)
|
//if (DEBUG)
|
||||||
|
|||||||
Reference in New Issue
Block a user