res_pjsip_logger.c: correct the return value checks when writing to pcap

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
This commit is contained in:
Pirmin Walthert 2020-05-29 11:28:57 +02:00 committed by nappsoft
parent 2d14425e04
commit f444f2495b
1 changed files with 5 additions and 5 deletions

View 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));
}
}