]> git.ipfire.org Git - thirdparty/asterisk.git/commitdiff
res_pjsip_logger.c: correct the return value checks when writing to pcap
authorPirmin Walthert <infos@nappsoft.ch>
Fri, 29 May 2020 09:28:57 +0000 (11:28 +0200)
committerJoshua Colp <jcolp@sangoma.com>
Mon, 1 Jun 2020 12:00:09 +0000 (07:00 -0500)
files

fwrite() does return the number of elements written and not the
number of bytes. However asterisk is currently comparing the return
value to the size of the written element what means that asterisk logs
five WARNING messages on every packet written to the pcap file.

This patch changes the code to check for the correct value, which will
always be 1.

ASTERISK-28921 #close

Change-Id: I2455032d9cb4c5a500692923f9e2a22e68b08fc2

res/res_pjsip_logger.c

index cc79f61718f300a06725b7c13068a9d85718f203..8380bd6fb1fc1898a9ed539579c3f9290ec4c425 100644 (file)
@@ -246,19 +246,19 @@ static void pjsip_logger_write_to_pcap(struct pjsip_logger_session *session, con
        /* We lock the logger session since we're writing these out in parts */
        ao2_wrlock(session);
        if (session->pcap_file) {
-               if (fwrite(&pcap_record_header, sizeof(struct pcap_record_header), 1, session->pcap_file) != sizeof(struct pcap_record_header)) {
+               if (fwrite(&pcap_record_header, sizeof(struct pcap_record_header), 1, session->pcap_file) != 1) {
                        ast_log(LOG_WARNING, "Writing PCAP header failed: %s\n", strerror(errno));
                }
-               if (fwrite(&pcap_ethernet_header, sizeof(struct pcap_ethernet_header), 1, session->pcap_file) != sizeof(struct pcap_ethernet_header)) {
+               if (fwrite(&pcap_ethernet_header, sizeof(struct pcap_ethernet_header), 1, session->pcap_file) != 1) {
                        ast_log(LOG_WARNING, "Writing ethernet header to pcap failed: %s\n", strerror(errno));
                }
-               if (fwrite(pcap_ip_header, pcap_ip_header_len, 1, session->pcap_file) != pcap_ip_header_len) {
+               if (fwrite(pcap_ip_header, pcap_ip_header_len, 1, session->pcap_file) != 1) {
                        ast_log(LOG_WARNING, "Writing IP header to pcap failed: %s\n", strerror(errno));
                }
-               if (fwrite(&pcap_udp_header, sizeof(struct pcap_udp_header), 1, session->pcap_file) != sizeof(struct pcap_udp_header)) {
+               if (fwrite(&pcap_udp_header, sizeof(struct pcap_udp_header), 1, session->pcap_file) != 1) {
                        ast_log(LOG_WARNING, "Writing UDP header to pcap failed: %s\n", strerror(errno));
                }
-               if (fwrite(msg, msg_len, 1, session->pcap_file) != msg_len) {
+               if (fwrite(msg, msg_len, 1, session->pcap_file) != 1) {
                        ast_log(LOG_WARNING, "Writing UDP payload to pcap failed: %s\n", strerror(errno));
                }
        }