Text   |  XML   |  ReML   |   Visible Warnings:

Unused Value  at ngsniffer.c:565

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

ngsniffer_open

(/home/sate/Testcases/c/cve/wireshark-1.2.0/wiretap/ngsniffer.c)expand/collapse
Show more  
 506  int ngsniffer_open(wtap *wth, int *err, gchar **err_info)
 507  {
 508          int bytes_read;
 509          char magic[sizeof ngsniffer_magic];
 510          char record_type[2];
 511          char record_length[4]; /* only the first 2 bytes are length,
 512                                    the last 2 are "reserved" and are thrown away */
 513          guint16 type, length;
 514          struct vers_rec version;
 515          guint16 maj_vers;
 516          guint16 start_date;
 517          guint16 start_time;
 518          static const int sniffer_encap[] = {
 519                  WTAP_ENCAP_TOKEN_RING,
 520                  WTAP_ENCAP_ETHERNET,
 521                  WTAP_ENCAP_ARCNET,
 522                  WTAP_ENCAP_UNKNOWN,     /* StarLAN */
 523                  WTAP_ENCAP_UNKNOWN,     /* PC Network broadband */
 524                  WTAP_ENCAP_UNKNOWN,     /* LocalTalk */
 525                  WTAP_ENCAP_UNKNOWN,     /* Znet */
 526                  WTAP_ENCAP_PER_PACKET,  /* Internetwork analyzer (synchronous) */
 527                  WTAP_ENCAP_PER_PACKET,  /* Internetwork analyzer (asynchronous) */
 528                  WTAP_ENCAP_FDDI_BITSWAPPED,
 529                  WTAP_ENCAP_ATM_PDUS 
 530          };
 531          #define NUM_NGSNIFF_ENCAPS (sizeof sniffer_encap / sizeof sniffer_encap[0])
 532          struct tm tm;
 533   
 534          /* Read in the string that should be at the start of a Sniffer file */
 535          errno = WTAP_ERR_CANT_READ;
 536          bytes_read = file_read(magic, 1, sizeof magic, wth->fh);
 537          if (bytes_read != sizeof magic) {
 538                  *err = file_error(wth->fh);
 539                  if (*err != 0)
 540                          return -1;
 541                  return 0;
 542          }
 543          wth->data_offset += sizeof magic;
 544   
 545          if (memcmp(magic, ngsniffer_magic, sizeof ngsniffer_magic)) {
 546                  return 0;
 547          }
 548   
 549          /*
 550           * Read the first record, which the manual says is a version 
 551           * record.
 552           */
 553          errno = WTAP_ERR_CANT_READ;
 554          bytes_read = file_read(record_type, 1, 2, wth->fh);
 555          bytes_read += file_read(record_length, 1, 4, wth->fh);
 556          if (bytes_read != 6) {
 557                  *err = file_error(wth->fh);
 558                  if (*err != 0)
 559                          return -1;
 560                  return 0;
 561          }
 562          wth->data_offset += 6;
 563   
 564          type = pletohs(record_type);
 565          length = pletohs(record_length);
 566   
 567          if (type != REC_VERS) {
 568                  *err = WTAP_ERR_BAD_RECORD;
 569                  *err_info = g_strdup_printf("ngsniffer: Sniffer file doesn't start with a version record");
 570                  return -1;
 571          }
 572   
 573          errno = WTAP_ERR_CANT_READ;
 574          bytes_read = file_read(&version, 1, sizeof version, wth->fh);
 575          if (bytes_read != sizeof version) {
 576                  *err = file_error(wth->fh);
 577                  if (*err != 0)
 578                          return -1;
 579                  return 0;
 580          }
 581          wth->data_offset += sizeof version;
 582   
 583          /* Check the data link type. */
 584          if (version.network >= NUM_NGSNIFF_ENCAPS 
 585              || sniffer_encap[version.network] == WTAP_ENCAP_UNKNOWN) {
 586                  *err = WTAP_ERR_UNSUPPORTED_ENCAP;
 587                  *err_info = g_strdup_printf("ngsniffer: network type %u unknown or unsupported",
 588                      version.network);
 589                  return -1;
 590          }
 591   
 592          /* Check the time unit */
 593          if (version.timeunit >= NUM_NGSNIFF_TIMEUNITS) {
 594                  *err = WTAP_ERR_UNSUPPORTED;
 595                  *err_info = g_strdup_printf("ngsniffer: Unknown timeunit %u", version.timeunit);
 596                  return -1;
 597          }
 598   
 599          /* compressed or uncompressed Sniffer file? */
 600          if (version.format != 1) {
 601                  wth->file_type = WTAP_FILE_NGSNIFFER_COMPRESSED;
 602   
 603          } else {
 604                  wth->file_type = WTAP_FILE_NGSNIFFER_UNCOMPRESSED;
 605          }
 606   
 607          /* Set encap type before reading header records because the 
 608           * header record may change encap type.
 609           */
 610          wth->file_encap = sniffer_encap[version.network];
 611   
 612          /*
 613           * We don't know how to handle the remaining header record types,
 614           * so we just skip them - except for REC_HEADER2 records, which 
 615           * we look at, for "Internetwork analyzer" captures, to attempt to 
 616           * determine what the link-layer encapsulation is.
 617           *
 618           * XXX - in some version 1.16 internetwork analyzer files 
 619           * generated by the Windows Sniffer when saving Windows
 620           * Sniffer files as DOS Sniffer files, there's no REC_HEADER2
 621           * record, but the first "rsvd" word is 1 for PRI ISDN files, 2 
 622           * for BRI ISDN files, and 0 for non-ISDN files; is that something 
 623           * the DOS Sniffer understands?
 624           */
 625          maj_vers = pletohs(&version.maj_vers);
 626          if (process_header_records(wth, err, err_info, maj_vers,
 627              version.network) < 0)
 628                  return -1;
 629          if ((version.network == NETWORK_SYNCHRO ||
 630              version.network == NETWORK_ASYNC) &&
 631              wth->file_encap == WTAP_ENCAP_PER_PACKET) {
 632                  /*
 633                   * Well, we haven't determined the internetwork analyzer
 634                   * subtype yet...
 635                   */
 636                  switch (maj_vers) {
 637   
 638                  case 1:
 639                          /*
 640                           * ... and this is a version 1 capture; look 
 641                           * at the first "rsvd" word.
 642                           */
 643                          switch (pletohs(&version.rsvd[0])) {
 644   
 645                          case 1:
 646                          case 2:
 647                                  wth->file_encap = WTAP_ENCAP_ISDN;
 648                                  break;
 649                          }
 650                          break;
 651   
 652                  case 3:
 653                          /*
 654                           * ...and this is a version 3 capture; we've
 655                           * seen nothing in those that obviously
 656                           * indicates the capture type, but the only 
 657                           * one we've seen is a Frame Relay capture,
 658                           * so mark it as Frame Relay for now.
 659                           */
 660                          wth->file_encap = WTAP_ENCAP_FRELAY_WITH_PHDR;
 661                          break;
 662                  }
 663          }
 664   
 665          /*
 666           * Now, if we have a random stream open, position it to the same 
 667           * location, which should be the beginning of the real data, and 
 668           * should be the beginning of the compressed data.
 669           *
 670           * XXX - will we see any records other than REC_FRAME2, REC_FRAME4,
 671           * or REC_EOF after this?  If not, we can get rid of the loop in
 672           * "ngsniffer_read()".
 673           */
 674          if (wth->random_fh != NULL) {
 675                  if (file_seek(wth->random_fh, wth->data_offset, SEEK_SET, err) == -1)
 676                          return -1;
 677          }
 678   
 679          /* This is a ngsniffer file */
 680          wth->capture.ngsniffer = g_malloc(sizeof(ngsniffer_t));
 681          wth->capture.ngsniffer->maj_vers = maj_vers;
 682          wth->capture.ngsniffer->min_vers = pletohs(&version.min_vers);
 683   
 684          /* We haven't allocated any uncompression buffers yet. */
 685          wth->capture.ngsniffer->seq.buf = NULL;
 686          wth->capture.ngsniffer->rand.buf = NULL;
 687   
 688          /* Set the current file offset; the offset in the compressed file
 689             and in the uncompressed data stream currently the same. */
 690          wth->capture.ngsniffer->seq.uncomp_offset = wth->data_offset;
 691          wth->capture.ngsniffer->seq.comp_offset = wth->data_offset;
 692          wth->capture.ngsniffer->rand.uncomp_offset = wth->data_offset;
 693          wth->capture.ngsniffer->rand.comp_offset = wth->data_offset;
 694   
 695          /* We don't yet have any list of compressed blobs. */
 696          wth->capture.ngsniffer->first_blob = NULL;
 697          wth->capture.ngsniffer->last_blob = NULL;
 698          wth->capture.ngsniffer->current_blob = NULL;
 699   
 700          wth->subtype_read = ngsniffer_read;
 701          wth->subtype_seek_read = ngsniffer_seek_read;
 702          wth->subtype_sequential_close = ngsniffer_sequential_close;
 703          wth->subtype_close = ngsniffer_close;
 704          wth->snapshot_length = 0;       /* not available in header, only in frame */
 705          wth->capture.ngsniffer->timeunit = Psec[version.timeunit];
 706          wth->capture.ngsniffer->network = version.network;
 707   
 708          /* Get capture start time */
 709          start_time = pletohs(&version.time);
 710          start_date = pletohs(&version.date);
 711          tm.tm_year = ((start_date&0xfe00)>>9) + 1980 - 1900;
 712          tm.tm_mon = ((start_date&0x1e0)>>5) - 1;
 713          tm.tm_mday = (start_date&0x1f);
 714          /* The time does not appear to act as an offset; only the date 
 715          tm.tm_hour = (start_time&0xf800)>>11;
 716          tm.tm_min = (start_time&0x7e0)>>5;
 717          tm.tm_sec = (start_time&0x1f)<<1;*/
 718          tm.tm_hour = 0;
 719          tm.tm_min = 0;
 720          tm.tm_sec = 0;
 721          tm.tm_isdst = -1;
 722          wth->capture.ngsniffer->start = mktime(&tm);
 723          /*
 724           * XXX - what if "secs" is -1?  Unlikely,
 725           * but if the capture was done in a time 
 726           * zone that switches between standard and
 727           * summer time sometime other than when we 
 728           * do, and thus the time was one that doesn't
 729           * exist here because a switch from standard 
 730           * to summer time zips over it, it could
 731           * happen.
 732           *
 733           * On the other hand, if the capture was done 
 734           * in a different time zone, this won't work 
 735           * right anyway; unfortunately, the time zone 
 736           * isn't stored in the capture file.
 737           */
 738   
 739          wth->tsprecision = WTAP_FILE_TSPREC_NSEC;       /* XXX */
 740   
 741          return 1;
 742  }
Show more  




Change Warning 1029.30205 : Unused Value

Priority:
State:
Finding:
Owner:
Note: