Ensure usage of struct in_addr is in network byte order.
Closes issue #81
This commit is contained in:
+9
-15
@@ -1666,7 +1666,7 @@ static int fill_prefix_v4(prefix_t *p, struct in_addr *a, int b, int mb) {
|
||||
|
||||
/* ******************************************* */
|
||||
|
||||
u_int16_t ndpi_network_ptree_match(struct ndpi_detection_module_struct *ndpi_struct, struct in_addr *pin) {
|
||||
u_int16_t ndpi_network_ptree_match(struct ndpi_detection_module_struct *ndpi_struct, struct in_addr *pin /* network byte order */) {
|
||||
prefix_t prefix;
|
||||
patricia_node_t *node;
|
||||
|
||||
@@ -1679,7 +1679,7 @@ u_int16_t ndpi_network_ptree_match(struct ndpi_detection_module_struct *ndpi_str
|
||||
|
||||
/* ******************************************* */
|
||||
|
||||
u_int16_t ndpi_host_ptree_match(struct ndpi_detection_module_struct *ndpi_struct, u_int32_t host) {
|
||||
u_int16_t ndpi_host_ptree_match(struct ndpi_detection_module_struct *ndpi_struct, u_int32_t host /* network byte order */) {
|
||||
struct in_addr pin;
|
||||
|
||||
pin.s_addr = host;
|
||||
@@ -1700,11 +1700,9 @@ u_int8_t ndpi_is_tor_flow(struct ndpi_detection_module_struct *ndpi_struct,
|
||||
struct ndpi_packet_struct *packet = &flow->packet;
|
||||
|
||||
if(packet->tcp != NULL) {
|
||||
if(flow->packet.iph) {
|
||||
struct in_addr saddr = { packet->iph->saddr };
|
||||
struct in_addr daddr = { packet->iph->daddr };
|
||||
if(tor_ptree_match(ndpi_struct, &saddr)
|
||||
|| tor_ptree_match(ndpi_struct, &daddr)) {
|
||||
if(packet->iph) {
|
||||
if(tor_ptree_match(ndpi_struct, (struct in_addr *)&packet->iph->saddr)
|
||||
|| tor_ptree_match(ndpi_struct, (struct in_addr *)&packet->iph->daddr)) {
|
||||
return(1);
|
||||
}
|
||||
}
|
||||
@@ -1751,7 +1749,6 @@ static int ndpi_add_host_ip_subprotocol(struct ndpi_detection_module_struct *ndp
|
||||
struct in_addr pin;
|
||||
|
||||
inet_pton(AF_INET, value, &pin);
|
||||
pin.s_addr = ntohl(pin.s_addr);
|
||||
|
||||
if((node = add_to_ptree(ndpi_struct->protocols_ptree, AF_INET, &pin, 32)) != NULL) {
|
||||
node->value.user_value = protocol_id;
|
||||
@@ -3424,12 +3421,9 @@ ndpi_protocol ndpi_detection_process_packet(struct ndpi_detection_module_struct
|
||||
if((ret.protocol == NDPI_PROTOCOL_UNKNOWN)
|
||||
&& flow->packet.iph
|
||||
&& (!flow->host_already_guessed)) {
|
||||
struct in_addr pin;
|
||||
|
||||
pin.s_addr = flow->packet.iph->saddr;
|
||||
if((flow->guessed_host_proto_id = ndpi_network_ptree_match(ndpi_struct, &pin)) == NDPI_PROTOCOL_UNKNOWN) {
|
||||
pin.s_addr = flow->packet.iph->daddr;
|
||||
flow->guessed_host_proto_id = ndpi_network_ptree_match(ndpi_struct, &pin);
|
||||
if((flow->guessed_host_proto_id = ndpi_network_ptree_match(ndpi_struct, (struct in_addr *)&flow->packet.iph->saddr)) == NDPI_PROTOCOL_UNKNOWN) {
|
||||
flow->guessed_host_proto_id = ndpi_network_ptree_match(ndpi_struct, (struct in_addr *)&flow->packet.iph->daddr);
|
||||
}
|
||||
|
||||
flow->host_already_guessed = 1;
|
||||
@@ -4252,11 +4246,11 @@ ndpi_protocol ndpi_guess_undetected_protocol(struct ndpi_detection_module_struct
|
||||
return(ret);
|
||||
|
||||
check_guessed_skype:
|
||||
addr.s_addr = shost;
|
||||
addr.s_addr = htonl(shost);
|
||||
if(ndpi_network_ptree_match(ndpi_struct, &addr) == NDPI_PROTOCOL_SKYPE) {
|
||||
ret.protocol = NDPI_PROTOCOL_SKYPE;
|
||||
} else {
|
||||
addr.s_addr = dhost;
|
||||
addr.s_addr = htonl(dhost);
|
||||
if(ndpi_network_ptree_match(ndpi_struct, &addr) == NDPI_PROTOCOL_SKYPE)
|
||||
ret.protocol = NDPI_PROTOCOL_SKYPE;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user