Text   |  XML   |  ReML   |   Visible Warnings:

Ignored Return Value  at text2pcap.c:659

No properties have been set. | edit properties
Jump to warning location ↓ warning details...
Show Events | Options

write_current_packet

(/home/sate/Testcases/c/cve/wireshark-1.2.0/text2pcap.c)expand/collapse
Show more  
 539  write_current_packet (void)
 540  {
 541      int length = 0;
 542      int proto_length = 0;
 543      int ip_length = 0;
 544      int eth_trailer_length = 0;
 545      int i, padding_length;
 546      guint32 u;
 547      struct pcaprec_hdr ph;
 548   
 549      if (curr_offset > 0) {
 550          /* Write the packet */
 551   
 552          /* Compute packet length */
 553          length = curr_offset;
 554          if (hdr_data_chunk) { length += sizeof(HDR_DATA_CHUNK) + number_of_padding_bytes(curr_offset); }
 555          if (hdr_sctp) { length += sizeof(HDR_SCTP); }
 556          if (hdr_udp) { length += sizeof(HDR_UDP); proto_length = length; }
 557          if (hdr_tcp) { length += sizeof(HDR_TCP); proto_length = length; }
 558          if (hdr_ip) { length += sizeof(HDR_IP); ip_length = length; }
 559          if (hdr_ethernet) {
 560              length += sizeof(HDR_ETHERNET);
 561              /* Pad trailer */
 562              if (length < 60) {
 563                  eth_trailer_length = 60 - length;
 564                  length = 60;
 565              }
 566          }
 567   
 568          /* Write PCAP header */
 569          ph.ts_sec = (guint32)ts_sec;
 570          ph.ts_usec = ts_usec;
 571          if (ts_fmt == NULL) { ts_usec++; }      /* fake packet counter */
 572          ph.incl_len = length;
 573          ph.orig_len = length;
 574          fwrite(&ph, sizeof(ph), 1, output_file);
 575   
 576          /* Write Ethernet header */
 577          if (hdr_ethernet) {
 578              HDR_ETHERNET.l3pid = g_htons(hdr_ethernet_proto);
 579              fwrite(&HDR_ETHERNET, sizeof(HDR_ETHERNET), 1, output_file);
 580          }
 581   
 582          /* Write IP header */
 583          if (hdr_ip) {
 584              HDR_IP.packet_length = g_htons(ip_length);
 585              HDR_IP.protocol = (guint8) hdr_ip_proto;
 586              HDR_IP.hdr_checksum = 0;
 587              HDR_IP.hdr_checksum = in_checksum(&HDR_IP, sizeof(HDR_IP));
 588              fwrite(&HDR_IP, sizeof(HDR_IP), 1, output_file);
 589          }
 590   
 591          /* initialize pseudo header for checksum calculation */
 592          pseudoh.src_addr    = HDR_IP.src_addr;
 593          pseudoh.dest_addr   = HDR_IP.dest_addr;
 594          pseudoh.zero        = 0;
 595          pseudoh.protocol    = (guint8) hdr_ip_proto;
 596          pseudoh.length      = g_htons(proto_length);
 597   
 598          /* Write UDP header */
 599          if (hdr_udp) {
 600              HDR_UDP.source_port = g_htons(hdr_src_port);
 601              HDR_UDP.dest_port = g_htons(hdr_dest_port);
 602              HDR_UDP.length = g_htons(proto_length);
 603   
 604              HDR_UDP.checksum = 0;
 605              u = g_ntohs(in_checksum(&pseudoh, sizeof(pseudoh))) +
 606                      g_ntohs(in_checksum(&HDR_UDP, sizeof(HDR_UDP))) +
 607                      g_ntohs(in_checksum(packet_buf, curr_offset));
 608              HDR_UDP.checksum = g_htons((u & 0xffff) + (u>>16));
 609              if (HDR_UDP.checksum == 0) /* differenciate between 'none' and 0 */
 610                      HDR_UDP.checksum = g_htons(1);
 611   
 612              fwrite(&HDR_UDP, sizeof(HDR_UDP), 1, output_file);
 613          }
 614   
 615          /* Write TCP header */
 616          if (hdr_tcp) {
 617              HDR_TCP.source_port = g_htons(hdr_src_port);
 618              HDR_TCP.dest_port = g_htons(hdr_dest_port);
 619              /* HDR_TCP.seq_num already correct */
 620              HDR_TCP.window = g_htons(0x2000);
 621   
 622              HDR_TCP.checksum = 0;
 623              u = g_ntohs(in_checksum(&pseudoh, sizeof(pseudoh))) +
 624                      g_ntohs(in_checksum(&HDR_TCP, sizeof(HDR_TCP))) +
 625                      g_ntohs(in_checksum(packet_buf, curr_offset));
 626              HDR_TCP.checksum = g_htons((u & 0xffff) + (u>>16));
 627              if (HDR_TCP.checksum == 0) /* differenciate between 'none' and 0 */
 628                      HDR_TCP.checksum = g_htons(1);
 629   
 630              fwrite(&HDR_TCP, sizeof(HDR_TCP), 1, output_file);
 631          }
 632   
 633          /* Compute DATA chunk header and append padding */
 634          if (hdr_data_chunk) {
 635              HDR_DATA_CHUNK.type   = hdr_data_chunk_type;
 636              HDR_DATA_CHUNK.bits   = hdr_data_chunk_bits;
 637              HDR_DATA_CHUNK.length = g_htons(curr_offset + sizeof(HDR_DATA_CHUNK));
 638              HDR_DATA_CHUNK.tsn    = g_htonl(hdr_data_chunk_tsn);
 639              HDR_DATA_CHUNK.sid    = g_htons(hdr_data_chunk_sid);
 640              HDR_DATA_CHUNK.ssn    = g_htons(hdr_data_chunk_ssn);
 641              HDR_DATA_CHUNK.ppid   = g_htonl(hdr_data_chunk_ppid);
 642   
 643              padding_length = number_of_padding_bytes(curr_offset);
 644              for (i=0; i<padding_length; i++)
 645                write_byte("0");
 646          }
 647   
 648          /* Write SCTP header */
 649          if (hdr_sctp) {
 650              HDR_SCTP.src_port  = g_htons(hdr_sctp_src);
 651              HDR_SCTP.dest_port = g_htons(hdr_sctp_dest);
 652              HDR_SCTP.tag       = g_htonl(hdr_sctp_tag);
 653              HDR_SCTP.checksum  = g_htonl(0);
 654              HDR_SCTP.checksum  = crc32c((guint8 *)&HDR_SCTP, sizeof(HDR_SCTP), ~0L);
 655              if (hdr_data_chunk)
 656                HDR_SCTP.checksum  = crc32c((guint8 *)&HDR_DATA_CHUNK, sizeof(HDR_DATA_CHUNK), HDR_SCTP.checksum);
 657              HDR_SCTP.checksum  = g_htonl(finalize_crc32c(crc32c(packet_buf, curr_offset, HDR_SCTP.checksum)));
 658   
 659              fwrite(&HDR_SCTP, sizeof(HDR_SCTP), 1, output_file);
 660          }
 661   
 662          /* Write DATA chunk header */
 663          if (hdr_data_chunk) {
 664              fwrite(&HDR_DATA_CHUNK, sizeof(HDR_DATA_CHUNK), 1, output_file);
 665          }
 666          /* Write packet */
 667          fwrite(packet_buf, curr_offset, 1, output_file);
 668   
 669          /* Write Ethernet trailer */
 670          if (hdr_ethernet && eth_trailer_length > 0) {
 671              memset(tempbuf, 0, eth_trailer_length);
 672              fwrite(tempbuf, eth_trailer_length, 1, output_file);
 673          }
 674   
 675          if (!quiet)
 676              fprintf(stderr, "Wrote packet of %lu bytes at %u\n", curr_offset, g_ntohl(HDR_TCP.seq_num));
 677          num_packets_written ++;
 678      }
 679   
 680      HDR_TCP.seq_num = g_htonl(g_ntohl(HDR_TCP.seq_num) + curr_offset);
 681   
 682      packet_start += curr_offset;
 683      curr_offset = 0;
 684  }
Show more  




Change Warning 5508.35780 : Ignored Return Value

Priority:
State:
Finding:
Owner:
Note: