Text   |  XML   |  ReML   |   Visible Warnings:

Useless Assignment  at netxray.c:389

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

netxray_open

(/home/sate/Testcases/c/cve/wireshark-1.2.0/wiretap/netxray.c)expand/collapse
Show more  
 330  int netxray_open(wtap *wth, int *err, gchar **err_info)
 331  {
 332          int bytes_read;
 333          char magic[sizeof netxray_magic];
 334          gboolean is_old;
 335          struct netxray_hdr hdr;
 336          guint network_type;
 337          double ticks_per_sec;
 338          int version_major, version_minor;
 339          int file_type;
 340          double start_timestamp;
 341
355
Show [ Lines 341 to 355 omitted. ]
 356                  WTAP_ENCAP_UNKNOWN,             /* "DIX" - should not occur */
 357                  WTAP_ENCAP_UNKNOWN,             /* ARCNET raw */
 358                  WTAP_ENCAP_UNKNOWN,             /* ARCNET 878.2 */
 359                  WTAP_ENCAP_ATM_PDUS_UNTRUNCATED,/* ATM */
 360                  WTAP_ENCAP_IEEE_802_11_WITH_RADIO,
 361                                                  /* Wireless WAN with radio information */
 362                  WTAP_ENCAP_UNKNOWN              /* IrDA */
 363          };
 364          #define NUM_NETXRAY_ENCAPS (sizeof netxray_encap / sizeof netxray_encap[0])
 365          int file_encap;
 366          guint isdn_type = 0;
 367   
 368          /* Read in the string that should be at the start of a NetXRay 
 369           * file */
 370          errno = WTAP_ERR_CANT_READ;
 371          bytes_read = file_read(magic, 1, sizeof magic, wth->fh);
 372          if (bytes_read != sizeof magic) {
 373                  *err = file_error(wth->fh);
 374                  if (*err != 0)
 375                          return -1;
 376                  return 0;
 377          }
 378          wth->data_offset += sizeof magic;
 379   
 380          if (memcmp(magic, netxray_magic, sizeof magic) == 0) {
 381                  is_old = FALSE;
 382          } else if (memcmp(magic, old_netxray_magic, sizeof magic) == 0) {
 383                  is_old = TRUE;
 384          } else {
 385                  return 0;
 386          }
 387   
 388          /* Read the rest of the header. */
 389          errno = WTAP_ERR_CANT_READ;
 390          bytes_read = file_read(&hdr, 1, sizeof hdr, wth->fh);
 391          if (bytes_read != sizeof hdr) {
 392                  *err = file_error(wth->fh);
 393                  if (*err != 0)
 394                          return -1;
 395                  return 0;
 396          }
 397          wth->data_offset += sizeof hdr;
 398   
 399          if (is_old) {
 400                  version_major = 0;
 401                  version_minor = 0;
 402                  file_type = WTAP_FILE_NETXRAY_OLD;
 403          } else {
 404                  /* It appears that version 1.1 files (as produced by Windows 
 405                   * Sniffer Pro 2.0.01) have the time stamp in microseconds,
 406                   * rather than the milliseconds version 1.0 files appear to 
 407                   * have.
 408                   *
 409                   * It also appears that version 2.00x files have per-packet
 410                   * headers with some extra fields. */
 411                  if (memcmp(hdr.version, vers_1_0, sizeof vers_1_0) == 0) {
 412                          version_major = 1;
 413                          version_minor = 0;
 414                          file_type = WTAP_FILE_NETXRAY_1_0;
 415                  } else if (memcmp(hdr.version, vers_1_1, sizeof vers_1_1) == 0) {
 416                          version_major = 1;
 417                          version_minor = 1;
 418                          file_type = WTAP_FILE_NETXRAY_1_1;
 419                  } else if (memcmp(hdr.version, vers_2_000, sizeof vers_2_000) == 0) {
 420                          version_major = 2;
 421                          version_minor = 0;
 422                          file_type = WTAP_FILE_NETXRAY_2_00x;
 423                  } else if (memcmp(hdr.version, vers_2_001, sizeof vers_2_001) == 0) {
 424                          version_major = 2;
 425                          version_minor = 1;
 426                          file_type = WTAP_FILE_NETXRAY_2_00x;
 427                  } else if (memcmp(hdr.version, vers_2_002, sizeof vers_2_002) == 0) {
 428                          version_major = 2;
 429                          version_minor = 2;
 430                          file_type = WTAP_FILE_NETXRAY_2_00x;
 431                  } else if (memcmp(hdr.version, vers_2_003, sizeof vers_2_003) == 0) {
 432                          version_major = 2;
 433                          version_minor = 3;
 434                          file_type = WTAP_FILE_NETXRAY_2_00x;
 435                  } else {
 436                          *err = WTAP_ERR_UNSUPPORTED;
 437                          *err_info = g_strdup_printf("netxray: version \"%.8s\" unsupported", hdr.version);
 438                          return -1;
 439                  }
 440          }
 441   
 442          switch (hdr.network_plus) {
 443   
 444          case 0:
 445                  /*
 446                   * The byte after hdr.network is usually 0, in which case 
 447                   * the hdr.network byte is an NDIS network type value - 1.
 448                   */
 449                  network_type = hdr.network + 1;
 450                  break;
 451   
 452          case 2:
 453                  /*
 454                   * However, in some Ethernet captures, it's 2, and the
 455                   * hdr.network byte is 1 rather than 0.  We assume 
 456                   * that if there's a byte after hdr.network with the value 
 457                   * 2, the hdr.network byte is an NDIS network type, rather 
 458                   * than an NDIS network type - 1.
 459                   */
 460                  network_type = hdr.network;
 461                  break;
 462   
 463          default:
 464                  *err = WTAP_ERR_UNSUPPORTED;
 465                  *err_info = g_strdup_printf("netxray: the byte after the network type has the value %u, which I don't understand",
 466                      hdr.network_plus);
 467                  return -1;
 468          }
 469   
 470          if (network_type >= NUM_NETXRAY_ENCAPS 
 471              || netxray_encap[network_type] == WTAP_ENCAP_UNKNOWN) {
 472                  *err = WTAP_ERR_UNSUPPORTED_ENCAP;
 473                  *err_info = g_strdup_printf("netxray: network type %u (%u) unknown or unsupported",
 474                      network_type, hdr.network_plus);
 475                  return -1;
 476          }
 477   
 478          /*
 479           * Figure out the time stamp units and start time stamp.
 480           */
 481          start_timestamp = (double)pletohl(&hdr.timelo)
 482              + (double)pletohl(&hdr.timehi)*4294967296.0;
 483          switch (file_type) {
 484   
 485          case WTAP_FILE_NETXRAY_OLD:
 486                  ticks_per_sec = 1000.0;
 487                  wth->tsprecision = WTAP_FILE_TSPREC_MSEC;
 488                  break;
 489   
 490          case WTAP_FILE_NETXRAY_1_0:
 491                  ticks_per_sec = 1000.0;
 492                  wth->tsprecision = WTAP_FILE_TSPREC_MSEC;
 493                  break;
 494   
 495          case WTAP_FILE_NETXRAY_1_1:
 496                  /*
 497                   * In version 1.1 files (as produced by Windows Sniffer
 498                   * Pro 2.0.01), the time stamp is in microseconds,
 499                   * rather than the milliseconds time stamps in NetXRay
 500                   * and older versions of Windows Sniffer.
 501                   */
 502                  ticks_per_sec = 1000000.0;
 503                  wth->tsprecision = WTAP_FILE_TSPREC_USEC;
 504                  break;
 505   
 506          case WTAP_FILE_NETXRAY_2_00x:
 507                  /*
 508                   * Get the time stamp units from the appropriate TpS 
 509                   * table or from the file header.
 510                   */
 511                  switch (network_type) {
 512   
 513                  case 1:
 514                          /*
 515                           * Ethernet - the table to use depends on whether 
 516                           * this is an NDIS or pod capture.
 517                           */
 518                          switch (hdr.captype) {
 519   
 520                          case CAPTYPE_NDIS:
 521                                  if (hdr.timeunit >= NUM_NETXRAY_TIMEUNITS) {
 522                                          *err = WTAP_ERR_UNSUPPORTED;
 523                                          *err_info = g_strdup_printf(
 524                                              "netxray: Unknown timeunit %u for Ethernet/CAPTYPE_NDIS version %.8s capture",
 525                                              hdr.timeunit, hdr.version);
 526                                          return -1;
 527                                  }
 528                                  /*  
 529                                  XXX: 05/29/07: Use 'realtick' instead of TpS table if timeunit=2;
 530                                          Using 'realtick' in this case results
 531                                          in the correct 'ticks per second' for all the captures that 
 532                                          I have of this type (including captures from a number of Wirshark
 533                                          bug reports).
 534                                  */
 535                                  if (hdr.timeunit == 2) {
 536                                          ticks_per_sec = pletohl(hdr.realtick);
 537                                  }
 538                                  else {
 539                                          ticks_per_sec = TpS[hdr.timeunit];
 540                                  }
 541                                  break;
 542   
 543                          case ETH_CAPTYPE_GIGPOD:
 544                                  if (hdr.timeunit >= NUM_NETXRAY_TIMEUNITS_GIGPOD 
 545                                      || TpS_gigpod[hdr.timeunit] == 0.0) {
 546                                          *err = WTAP_ERR_UNSUPPORTED;
 547                                          *err_info = g_strdup_printf(
 548                                              "netxray: Unknown timeunit %u for Ethernet/ETH_CAPTYPE_GIGPOD version %.8s capture",
 549                                              hdr.timeunit, hdr.version);
 550                                          return -1;
 551                                  }
 552                                  ticks_per_sec = TpS_gigpod[hdr.timeunit];
 553   
 554                                  /*
 555                                   * At least for 002.002 and 002.003
 556                                   * captures, the start time stamp is 0,
 557                                   * not the value in the file.
 558                                   */
 559                                  if (version_minor == 2 || version_minor == 3)
 560                                          start_timestamp = 0.0;
 561                                  break;
 562   
 563                          case ETH_CAPTYPE_OTHERPOD:
 564                                  if (hdr.timeunit >= NUM_NETXRAY_TIMEUNITS_OTHERPOD 
 565                                      || TpS_otherpod[hdr.timeunit] == 0.0) {
 566                                          *err = WTAP_ERR_UNSUPPORTED;
 567                                          *err_info = g_strdup_printf(
 568                                              "netxray: Unknown timeunit %u for Ethernet/ETH_CAPTYPE_OTHERPOD version %.8s capture",
 569                                              hdr.timeunit, hdr.version);
 570                                          return -1;
 571                                  }
 572                                  ticks_per_sec = TpS_otherpod[hdr.timeunit];
 573   
 574                                  /*
 575                                   * At least for 002.002 and 002.003
 576                                   * captures, the start time stamp is 0,
 577                                   * not the value in the file.
 578                                   */
 579                                  if (version_minor == 2 || version_minor == 3)
 580                                          start_timestamp = 0.0;
 581                                  break;
 582   
 583                          case ETH_CAPTYPE_OTHERPOD2:
 584                                  if (hdr.timeunit >= NUM_NETXRAY_TIMEUNITS_OTHERPOD2 
 585                                      || TpS_otherpod2[hdr.timeunit] == 0.0) {
 586                                          *err = WTAP_ERR_UNSUPPORTED;
 587                                          *err_info = g_strdup_printf(
 588                                              "netxray: Unknown timeunit %u for Ethernet/ETH_CAPTYPE_OTHERPOD2 version %.8s capture",
 589                                              hdr.timeunit, hdr.version);
 590                                          return -1;
 591                                  }
 592                                  ticks_per_sec = TpS_otherpod2[hdr.timeunit];
 593                                  /*
 594                                   * XXX: start time stamp in the one capture file examined of this type was 0;
 595                                   *      We'll assume the start time handling is the same as for other pods.
 596                                   *
 597                                   * At least for 002.002 and 002.003
 598                                   * captures, the start time stamp is 0,
 599                                   * not the value in the file.
 600                                   */
 601                                  if (version_minor == 2 || version_minor == 3)
 602                                          start_timestamp = 0.0;
 603                                  break;
 604   
 605                          case ETH_CAPTYPE_GIGPOD2:
 606                                  if (hdr.timeunit >= NUM_NETXRAY_TIMEUNITS_GIGPOD2 
 607                                      || TpS_gigpod2[hdr.timeunit] == 0.0) {
 608                                          *err = WTAP_ERR_UNSUPPORTED;
 609                                          *err_info = g_strdup_printf(
 610                                              "netxray: Unknown timeunit %u for Ethernet/ETH_CAPTYPE_GIGPOD2 version %.8s capture",
 611                                              hdr.timeunit, hdr.version);
 612                                          return -1;
 613                                  }
 614                                  ticks_per_sec = TpS_gigpod2[hdr.timeunit];
 615                                  /*
 616                                   * XXX: start time stamp in the one capture file examined of this type was 0;
 617                                   *      We'll assume the start time handling is the same as for other pods.
 618                                   *
 619                                   * At least for 002.002 and 002.003
 620                                   * captures, the start time stamp is 0,
 621                                   * not the value in the file.
 622                                   */
 623                                  if (version_minor == 2 || version_minor == 3)
 624                                          start_timestamp = 0.0;
 625                                  break;
 626   
 627                          default:
 628                                  *err = WTAP_ERR_UNSUPPORTED;
 629                                  *err_info = g_strdup_printf(
 630                                      "netxray: Unknown capture type %u for Ethernet version %.8s capture",
 631                                      hdr.captype, hdr.version);
 632                                  return -1;
 633                          }
 634                          break;
 635   
 636                  default:
 637                          if (hdr.timeunit >= NUM_NETXRAY_TIMEUNITS) {
 638                                  *err = WTAP_ERR_UNSUPPORTED;
 639                                  *err_info = g_strdup_printf(
 640                                      "netxray: Unknown timeunit %u for %u/%u version %.8s capture",
 641                                      hdr.timeunit, network_type, hdr.captype,
 642                                      hdr.version);
 643                                  return -1;
 644                          }
 645                          ticks_per_sec = TpS[hdr.timeunit];
 646                          break;
 647                  }
 648   
 649                  /*
 650                   * If the number of ticks per second is greater than
 651                   * 1 million, make the precision be nanoseconds rather
 652                   * than microseconds.
 653                   *
 654                   * XXX - do values only slightly greater than one million
 655                   * correspond to a resolution sufficiently better than 
 656                   * 1 microsecond to display more digits of precision?
 657                   * XXX - Seems reasonable to use nanosecs only if TPS >= 10M 
 658                   */
 659                  if (ticks_per_sec >= 1e7)
 660                          wth->tsprecision = WTAP_FILE_TSPREC_NSEC;
 661                  else 
 662                          wth->tsprecision = WTAP_FILE_TSPREC_USEC;
 663                  break;
 664   
 665          default:
 666                  g_assert_not_reached();
 667                  ticks_per_sec = 0.0;
 668          }
 669          start_timestamp = start_timestamp/ticks_per_sec;
 670   
 671          if (network_type == 4) {
 672                  /*
 673                   * In version 0 and 1, we assume, for now, that all
 674                   * WAN captures have frames that look like Ethernet
 675                   * frames (as a result, presumably, of having passed 
 676                   * through NDISWAN).
 677                   *
 678                   * In version 2, it looks as if there's stuff in the 
 679                   * file header to specify what particular type of WAN 
 680                   * capture we have.
 681                   */
 682                  if (version_major == 2) {
 683                          switch (hdr.captype) {
 684   
 685                          case WAN_CAPTYPE_PPP:
 686                                  /*
 687                                   * PPP.
 688                                   */
 689                                  file_encap = WTAP_ENCAP_PPP_WITH_PHDR;
 690                                  break;
 691   
 692                          case WAN_CAPTYPE_FRELAY:
 693                                  /*
 694                                   * Frame Relay.
 695                                   *
 696                                   * XXX - in at least one capture, this 
 697                                   * is Cisco HDLC, not Frame Relay, but 
 698                                   * in another capture, it's Frame Relay.
 699                                   *
 700                                   * [Bytes in each capture:
 701                                   * Cisco HDLC:  hdr.xxx_x60[06:10]: 0x02 0x00 0x01 0x00 0x06 
 702                                   * Frame Relay: hdr.xxx_x60[06:10]  0x00 0x00 0x00 0x00 0x00
 703   
 704                                   * Cisco HDLC:  hdr.xxx_x60[14:15]: 0xff 0xff
 705                                   * Frame Relay: hdr.xxx_x60[14:15]: 0x00 0x00
 706                                   * ]
 707                                   */
 708                                  file_encap = WTAP_ENCAP_FRELAY_WITH_PHDR;
 709                                  break;
 710   
 711                          case WAN_CAPTYPE_HDLC:
 712                          case WAN_CAPTYPE_HDLC2:
 713                                  /*
 714                                   * Various HDLC flavors?
 715                                   */
 716                                  switch (hdr.wan_hdlc_subsub_captype) {
 717   
 718                                  case 0: /* LAPB/X.25 */
 719                                          file_encap = WTAP_ENCAP_LAPB;
 720                                          break;
 721   
 722                                  case 1: /* E1 PRI */
 723                                  case 2: /* T1 PRI */
 724                                  case 3: /* BRI */
 725                                          file_encap = WTAP_ENCAP_ISDN;
 726                                          isdn_type = hdr.wan_hdlc_subsub_captype;
 727                                          break;
 728   
 729                                  default:
 730                                          *err = WTAP_ERR_UNSUPPORTED_ENCAP;
 731                                          *err_info = g_strdup_printf("netxray: WAN HDLC capture subsubtype 0x%02x unknown or unsupported",
 732                                             hdr.wan_hdlc_subsub_captype);
 733                                          return -1;
 734                                  }
 735                                  break;
 736   
 737                          case WAN_CAPTYPE_SDLC:
 738                                  /*
 739                                   * SDLC.
 740                                   */
 741                                  file_encap = WTAP_ENCAP_SDLC;
 742                                  break;
 743   
 744                          case WAN_CAPTYPE_CHDLC:
 745                                  /*
 746                                   *  Cisco router (CHDLC) captured with pod 
 747                                   */
 748                                  file_encap = WTAP_ENCAP_CHDLC_WITH_PHDR;
 749                                  break;
 750   
 751                          default:
 752                                  *err = WTAP_ERR_UNSUPPORTED_ENCAP;
 753                                  *err_info = g_strdup_printf("netxray: WAN capture subtype 0x%02x unknown or unsupported",
 754                                     hdr.captype);
 755                                  return -1;
 756                          }
 757                  } else 
 758                          file_encap = WTAP_ENCAP_ETHERNET;
 759          } else 
 760                  file_encap = netxray_encap[network_type];
 761   
 762          /* This is a netxray file */
 763          wth->file_type = file_type;
 764          wth->capture.netxray = g_malloc(sizeof(netxray_t));
 765          wth->subtype_read = netxray_read;
 766          wth->subtype_seek_read = netxray_seek_read;
 767          wth->subtype_close = netxray_close;
 768          wth->file_encap = file_encap;
 769          wth->snapshot_length = 0;       /* not available in header */
 770          wth->capture.netxray->start_time = pletohl(&hdr.start_time);
 771          wth->capture.netxray->ticks_per_sec = ticks_per_sec;
 772          wth->capture.netxray->start_timestamp = start_timestamp;
 773          wth->capture.netxray->version_major = version_major;
 774   
 775          /*
 776           * If frames have an extra 4 bytes of stuff at the end, is 
 777           * it an FCS, or just junk?
 778           */
 779          wth->capture.netxray->fcs_valid = FALSE;
 780          switch (file_encap) {
 781   
 782          case WTAP_ENCAP_ETHERNET:
 783          case WTAP_ENCAP_IEEE_802_11_WITH_RADIO:
 784          case WTAP_ENCAP_ISDN:
 785          case WTAP_ENCAP_LAPB:
 786                  /*
 787                   * It appears that, in at least some version 2 Ethernet 
 788                   * captures, for frames that have 0xff in hdr_2_x.xxx[2]
 789                   * and hdr_2_x.xxx[3] in the per-packet header:
 790                   *
 791                   *      if, in the file header, hdr.realtick[1] is 0x34
 792                   *      and hdr.realtick[2] is 0x12, the frames have an
 793                   *      FCS at the end;
 794                   *
 795                   *      otherwise, they have 4 bytes of junk at the end.
 796
853
Show [ Lines 796 to 853 omitted. ]
 854                   * 05/29/07: Examination of numerous sniffer captures suggests
 855                   *            that the apparent correlation of certain realtick  
 856                   *            bytes to 'FCS presence' may actually be 
 857                   *            a 'false positive'.
 858                   *           ToDo: Review analysis and update code.
 859                   *           It might be that the ticks-per-second value 
 860                   *           is hardware-dependent, and that hardware with
 861                   *           a particular realtick value puts an FCS there
 862                   *           and other hardware doesn't.
 863                   */
 864                  if (version_major == 2) {
 865                          if (hdr.realtick[1] == 0x34 && hdr.realtick[2] == 0x12)
 866                                  wth->capture.netxray->fcs_valid = TRUE;
 867                  }
 868                  break;
 869          }
 870   
 871          /*
 872           * Remember the ISDN type, as we need it to interpret the 
 873           * channel number in ISDN captures.
 874           */
 875          wth->capture.netxray->isdn_type = isdn_type;
 876   
 877          /* Remember the offset after the last packet in the capture (which
 878           * isn't necessarily the last packet in the file), as it appears 
 879           * there's sometimes crud after it.
 880           * XXX: Remember 'start_offset' to help testing for 'short file' at EOF
 881           */
 882          wth->capture.netxray->wrapped      = FALSE;
 883          wth->capture.netxray->nframes      = pletohl(&hdr.nframes);
 884          wth->capture.netxray->start_offset = pletohl(&hdr.start_offset);
 885          wth->capture.netxray->end_offset   = pletohl(&hdr.end_offset);
 886   
 887          /* Seek to the beginning of the data records. */
 888          if (file_seek(wth->fh, pletohl(&hdr.start_offset), SEEK_SET, err) == -1) {
 889                  g_free(wth->capture.netxray);
 890                  return -1;
 891          }
 892          wth->data_offset = pletohl(&hdr.start_offset);
 893   
 894          return 1;
 895  }
Show more  




Change Warning 1024.29842 : Useless Assignment

Priority:
State:
Finding:
Owner:
Note: