From f64df866477b76fa3c3bbd133de0d474fa8fc129 Mon Sep 17 00:00:00 2001 From: "Gerd v. Egidy" Date: Sat, 7 May 2022 16:43:23 +0200 Subject: [PATCH] fix recvfrom() call in capture_eep_receive_v*() - the addrlen parameter must be filled with the size available for src_addr before calling recvfrom() - the size of the src_addr isn't really known before calling recvfrom, it can be of different types. So use struct sockaddr_storage for it which is large enough to allow different actual address types --- src/capture_eep.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/capture_eep.c b/src/capture_eep.c index 04543ed..ea15030 100644 --- a/src/capture_eep.c +++ b/src/capture_eep.c @@ -595,8 +595,8 @@ capture_eep_receive_v2() //! New created packet pointer packet_t *pkt; //! EEP client data - struct sockaddr eep_client; - socklen_t eep_client_len; + struct sockaddr_storage eep_client; + socklen_t eep_client_len=sizeof(eep_client); struct hep_hdr hdr; struct hep_timehdr hep_time; struct hep_iphdr hep_ipheader; @@ -611,7 +611,7 @@ capture_eep_receive_v2() memset(buffer, 0, MAX_CAPTURE_LEN); /* Receive EEP generic header */ - if (recvfrom(eep_cfg.server_sock, buffer, MAX_CAPTURE_LEN, 0, &eep_client, &eep_client_len) == -1) + if (recvfrom(eep_cfg.server_sock, buffer, MAX_CAPTURE_LEN, 0, (struct sockaddr*)&eep_client, &eep_client_len) == -1) return NULL; /* Copy initial bytes to HEPv2 header */ @@ -716,8 +716,8 @@ capture_eep_receive_v3(const u_char *pkt, uint32_t size) //! Source and Destination Address address_t src, dst; //! EEP client data - struct sockaddr eep_client; - socklen_t eep_client_len; + struct sockaddr_storage eep_client; + socklen_t eep_client_len=sizeof(eep_client); //! Packet header struct pcap_pkthdr header; //! New created packet pointer @@ -728,7 +728,7 @@ capture_eep_receive_v3(const u_char *pkt, uint32_t size) if(!pkt) { /* Receive EEP generic header */ - if (recvfrom(eep_cfg.server_sock, buffer, MAX_CAPTURE_LEN, 0, &eep_client, &eep_client_len) == -1) + if (recvfrom(eep_cfg.server_sock, buffer, MAX_CAPTURE_LEN, 0, (struct sockaddr*)&eep_client, &eep_client_len) == -1) return NULL; } else { memcpy(&buffer, pkt, size);