Text   |  XML   |  ReML   |   Visible Warnings:

Useless Assignment  at libpcap.c:147

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

libpcap_open

(/home/sate/Testcases/c/cve/wireshark-1.2.0/wiretap/libpcap.c)expand/collapse
Show more  
 67  int libpcap_open(wtap *wth, int *err, gchar **err_info)
 68  {
 69          int bytes_read;
 70          guint32 magic;
 71          struct pcap_hdr hdr;
 72          gboolean byte_swapped;
 73          gboolean modified;
 74          gboolean aix;
 75          int file_encap;
 76   
 77          /* Read in the number that should be at the start of a "libpcap" file */
 78          errno = WTAP_ERR_CANT_READ;
 79          bytes_read = file_read(&magic, 1, sizeof magic, wth->fh);
 80          if (bytes_read != sizeof magic) {
 81                  *err = file_error(wth->fh);
 82                  if (*err != 0)
 83                          return -1;
 84                  return 0;
 85          }
 86          wth->data_offset += sizeof magic;
 87   
 88          switch (magic) {
 89   
 90          case PCAP_MAGIC:
 91                  /* Host that wrote it has our byte order, and was running 
 92                     a program using either standard or ss990417 libpcap. */
 93                  byte_swapped = FALSE;
 94                  modified = FALSE;
 95                  wth->tsprecision = WTAP_FILE_TSPREC_USEC;
 96                  break;
 97   
 98          case PCAP_MODIFIED_MAGIC:
 99                  /* Host that wrote it has our byte order, and was running 
 100                     a program using either ss990915 or ss991029 libpcap. */
 101                  byte_swapped = FALSE;
 102                  modified = TRUE;
 103                  wth->tsprecision = WTAP_FILE_TSPREC_USEC;
 104                  break;
 105   
 106          case PCAP_SWAPPED_MAGIC:
 107                  /* Host that wrote it has a byte order opposite to ours,
 108                     and was running a program using either standard or
 109                     ss990417 libpcap. */
 110                  byte_swapped = TRUE;
 111                  modified = FALSE;
 112                  wth->tsprecision = WTAP_FILE_TSPREC_USEC;
 113                  break;
 114   
 115          case PCAP_SWAPPED_MODIFIED_MAGIC:
 116                  /* Host that wrote it out has a byte order opposite to 
 117                     ours, and was running a program using either ss990915
 118                     or ss991029 libpcap. */
 119                  byte_swapped = TRUE;
 120                  modified = TRUE;
 121                  wth->tsprecision = WTAP_FILE_TSPREC_USEC;
 122                  break;
 123   
 124          case PCAP_NSEC_MAGIC:
 125                  /* Host that wrote it has our byte order, and was running 
 126                     a program using either standard or ss990417 libpcap. */
 127                  byte_swapped = FALSE;
 128                  modified = FALSE;
 129                  wth->tsprecision = WTAP_FILE_TSPREC_NSEC;
 130                  break;
 131   
 132          case PCAP_SWAPPED_NSEC_MAGIC:
 133                  /* Host that wrote it out has a byte order opposite to 
 134                     ours, and was running a program using either ss990915
 135                     or ss991029 libpcap. */
 136                  byte_swapped = TRUE;
 137                  modified = FALSE;
 138                  wth->tsprecision = WTAP_FILE_TSPREC_NSEC;
 139                  break;
 140   
 141          default:
 142                  /* Not a "libpcap" type we know about. */
 143                  return 0;
 144          }
 145   
 146          /* Read the rest of the header. */
 147          errno = WTAP_ERR_CANT_READ;
 148          bytes_read = file_read(&hdr, 1, sizeof hdr, wth->fh);
 149          if (bytes_read != sizeof hdr) {
 150                  *err = file_error(wth->fh);
 151                  if (*err != 0)
 152                          return -1;
 153                  return 0;
 154          }
 155          wth->data_offset += sizeof hdr;
 156   
 157          if (byte_swapped) {
 158                  /* Byte-swap the header fields about which we care. */
 159                  hdr.version_major = BSWAP16(hdr.version_major);
 160                  hdr.version_minor = BSWAP16(hdr.version_minor);
 161                  hdr.snaplen = BSWAP32(hdr.snaplen);
 162                  hdr.network = BSWAP32(hdr.network);
 163          }
 164          if (hdr.version_major < 2) {
 165                  /* We only support version 2.0 and later. */
 166                  *err = WTAP_ERR_UNSUPPORTED;
 167                  *err_info = g_strdup_printf("pcap: major version %u unsupported",
 168                      hdr.version_major);
 169                  return -1;
 170          }
 171   
 172          /*
 173           * AIX's non-standard tcpdump uses a minor version number of 2.
 174           * Unfortunately, older versions of libpcap might have used 
 175           * that as well.
 176           *
 177           * The AIX libpcap uses RFC 1573 ifType values rather than
 178           * DLT_ values in the header; the ifType values for LAN devices
 179           * are:
 180
196
Show [ Lines 180 to 196 omitted. ]
 197           *
 198           * I'm assuming those older versions of libpcap didn't
 199           * use DLT_IEEE802 for Token Ring, and didn't use DLT_SLIP_BSDOS
 200           * as that came later.  It may have used DLT_PPP, however, in 
 201           * which case we're out of luck; we assume it's Token Ring
 202           * in AIX libpcap rather than PPP in standard libpcap, as 
 203           * you're probably more likely to be handing an AIX libpcap 
 204           * token-ring capture than an old (pre-libpcap 0.4) PPP capture
 205           * to Wireshark.
 206           */
 207          aix = FALSE;    /* assume it's not AIX */
 208          if (hdr.version_major == 2 && hdr.version_minor == 2) {
 209                  switch (hdr.network) {
 210   
 211                  case 6:
 212                          hdr.network = 1;        /* DLT_EN10MB, Ethernet */
 213                          aix = TRUE;
 214                          break;
 215   
 216                  case 9:
 217                          hdr.network = 6;        /* DLT_IEEE802, Token Ring */
 218                          aix = TRUE;
 219                          break;
 220   
 221                  case 15:
 222                          hdr.network = 10;       /* DLT_FDDI, FDDI */
 223                          aix = TRUE;
 224                          break;
 225   
 226                  case 24:
 227                          hdr.network = 0;        /* DLT_NULL, loopback */
 228                          aix = TRUE;
 229                          break;
 230                  }
 231          }
 232   
 233          /*
 234           * We treat a DLT_ value of 13 specially - it appears that in
 235           * Nokia libpcap format, it's some form of ATM with what I 
 236           * suspect is a pseudo-header (even though Nokia's IPSO is
 237           * based on FreeBSD, which #defines DLT_SLIP_BSDOS as 13).
 238           *
 239           * We don't yet know whether this is a Nokia capture, so if
 240           * "wtap_pcap_encap_to_wtap_encap()" returned WTAP_ENCAP_UNKNOWN
 241           * but "hdr.network" is 13, we don't treat that as an error yet.
 242           */
 243          file_encap = wtap_pcap_encap_to_wtap_encap(hdr.network);
 244          if (file_encap == WTAP_ENCAP_UNKNOWN && hdr.network != 13) {
 245                  *err = WTAP_ERR_UNSUPPORTED_ENCAP;
 246                  *err_info = g_strdup_printf("pcap: network type %u unknown or unsupported",
 247                      hdr.network);
 248                  return -1;
 249          }
 250   
 251          /* This is a libpcap file */
 252          wth->capture.pcap = g_malloc(sizeof(libpcap_t));
 253          wth->capture.pcap->byte_swapped = byte_swapped;
 254          wth->capture.pcap->version_major = hdr.version_major;
 255          wth->capture.pcap->version_minor = hdr.version_minor;
 256          wth->subtype_read = libpcap_read;
 257          wth->subtype_seek_read = libpcap_seek_read;
 258          wth->subtype_close = libpcap_close;
 259          wth->file_encap = file_encap;
 260          wth->snapshot_length = hdr.snaplen;
 261   
 262          /* In file format version 2.3, the order of the "incl_len" and 
 263             "orig_len" fields in the per-packet header was reversed,
 264             in order to match the BPF header layout.
 265   
 266             Therefore, in files with versions prior to that, we must swap 
 267             those two fields.
 268   
 269             Unfortunately, some files were, according to a comment in the
 270             "libpcap" source, written with version 2.3 in their headers 
 271             but without the interchanged fields, so if "incl_len" is 
 272             greater than "orig_len" - which would make no sense - we 
 273             assume that we need to swap them in version 2.3 files 
 274             as well.
 275   
 276             In addition, DG/UX's tcpdump uses version 543.0, and writes
 277             the two fields in the pre-2.3 order. */
 278          switch (hdr.version_major) {
 279   
 280          case 2:
 281                  if (hdr.version_minor < 3)
 282                          wth->capture.pcap->lengths_swapped = SWAPPED;
 283                  else if (hdr.version_minor == 3)
 284                          wth->capture.pcap->lengths_swapped = MAYBE_SWAPPED;
 285                  else 
 286                          wth->capture.pcap->lengths_swapped = NOT_SWAPPED;
 287                  break;
 288   
 289          case 543:
 290                  wth->capture.pcap->lengths_swapped = SWAPPED;
 291                  break;
 292   
 293          default:
 294                  wth->capture.pcap->lengths_swapped = NOT_SWAPPED;
 295                  break;
 296          }
 297   
 298          /*
 299           * Is this AIX format?
 300           */
 301          if (aix) {
 302                  /*
 303                   * Yes.  Skip all the tests for other mutant formats,
 304                   * and set the precision to nanosecond precision.
 305                   */
 306                  wth->file_type = WTAP_FILE_PCAP_AIX;
 307                  wth->tsprecision = WTAP_FILE_TSPREC_NSEC;
 308                  return 1;
 309          }
 310   
 311          /*
 312           * No.  Let's look at the header for the first record,
 313           * and see if, interpreting it as a standard header (if the 
 314           * magic number was standard) or a modified header (if the 
 315           * magic number was modified), the position where it says the
 316           * header for the *second* record is contains a corrupted header.
 317           *
 318           * If so, then:
 319
333
Show [ Lines 319 to 333 omitted. ]
 334           *      header had some extra fields, and, alas, SuSE appear
 335           *      to have picked up that version of the patch for SuSE
 336           *      6.3, meaning that programs expecting the standard per-
 337           *      packet header in captures with the modified magic number
 338           *      can't read dumps from its tcpdump.
 339           *
 340           * Oh, and if it has the standard magic number, it might, instead,
 341           * be a Nokia libpcap file, so we may need to try that if
 342           * neither normal nor ss990417 headers work.
 343           */
 344          if (modified) {
 345                  /*
 346                   * Well, we have the magic number from Alexey's
 347                   * later two patches.
 348                   *
 349                   * Try ss991029, the last of his patches, first.
 350                   */
 351                  wth->file_type = WTAP_FILE_PCAP_SS991029;
 352                  switch (libpcap_try(wth, err)) {
 353   
 354                  case BAD_READ:
 355                          /*
 356                           * Well, we couldn't even read it.
 357                           * Give up.
 358                           */
 359                          g_free(wth->capture.pcap);
 360                          return -1;
 361   
 362                  case THIS_FORMAT:
 363                          /*
 364                           * Well, it looks as if it might be 991029.
 365                           * Put the seek pointer back, and return success.
 366                           */
 367                          if (file_seek(wth->fh, wth->data_offset, SEEK_SET, err) == -1) {
 368                                  g_free(wth->capture.pcap);
 369                                  return -1;
 370                          }
 371                          return 1;
 372   
 373                  case OTHER_FORMAT:
 374                          /*
 375                           * Try the next format.
 376                           */
 377                          break;
 378                  }
 379   
 380                  /*
 381                   * Well, it's not completely unreadable,
 382                   * but it's not ss991029.  Try ss990915;
 383                   * there are no other types to try after that,
 384                   * so we put the seek pointer back and treat 
 385                   * it as 990915.
 386                   */
 387                  wth->file_type = WTAP_FILE_PCAP_SS990915;
 388                  if (file_seek(wth->fh, wth->data_offset, SEEK_SET, err) == -1) {
 389                          g_free(wth->capture.pcap);
 390                          return -1;
 391                  }
 392          } else {
 393                  /*
 394                   * Well, we have the standard magic number.
 395                   *
 396                   * Try the standard format first.
 397                   */
 398                  if(wth->tsprecision == WTAP_FILE_TSPREC_NSEC) {
 399                          wth->file_type = WTAP_FILE_PCAP_NSEC;
 400                  } else {
 401                          wth->file_type = WTAP_FILE_PCAP;
 402                  }
 403                  switch (libpcap_try(wth, err)) {
 404   
 405                  case BAD_READ:
 406                          /*
 407                           * Well, we couldn't even read it.
 408                           * Give up.
 409                           */
 410                          g_free(wth->capture.pcap);
 411                          return -1;
 412   
 413                  case THIS_FORMAT:
 414                          /*
 415                           * Well, it looks as if it might be a standard 
 416                           * libpcap file.
 417                           * Put the seek pointer back, and return success.
 418                           */
 419                          if (file_seek(wth->fh, wth->data_offset, SEEK_SET, err) == -1) {
 420                                  g_free(wth->capture.pcap);
 421                                  return -1;
 422                          }
 423                          return 1;
 424   
 425                  case OTHER_FORMAT:
 426                          /*
 427                           * Try the next format.
 428                           */
 429                          break;
 430                  }
 431   
 432                  /*
 433                   * Well, it's not completely unreadable, but it's not 
 434                   * a standard file.  Put the seek pointer back and try
 435                   * ss990417.
 436                   */
 437                  wth->file_type = WTAP_FILE_PCAP_SS990417;
 438                  if (file_seek(wth->fh, wth->data_offset, SEEK_SET, err) == -1) {
 439                          g_free(wth->capture.pcap);
 440                          return -1;
 441                  }
 442                  switch (libpcap_try(wth, err)) {
 443   
 444                  case BAD_READ:
 445                          /*
 446                           * Well, we couldn't even read it.
 447                           * Give up.
 448                           */
 449                          g_free(wth->capture.pcap);
 450                          return -1;
 451   
 452                  case THIS_FORMAT:
 453                          /*
 454                           * Well, it looks as if it might be ss990417.
 455                           * Put the seek pointer back, and return success.
 456                           */
 457                          if (file_seek(wth->fh, wth->data_offset, SEEK_SET, err) == -1) {
 458                                  g_free(wth->capture.pcap);
 459                                  return -1;
 460                          }
 461                          return 1;
 462   
 463                  case OTHER_FORMAT:
 464                          /*
 465                           * Try the next format.
 466                           */
 467                          break;
 468                  }
 469   
 470                  /*
 471                   * Well, it's not completely unreadable,
 472                   * but it's not a standard file *nor* is it ss990417.
 473                   * Try it as a Nokia file; there are no other types 
 474                   * to try after that, so we put the seek pointer back 
 475                   * and treat it as a Nokia file.
 476                   */
 477                  wth->file_type = WTAP_FILE_PCAP_NOKIA;
 478                  if (file_seek(wth->fh, wth->data_offset, SEEK_SET, err) == -1) {
 479                          g_free(wth->capture.pcap);
 480                          return -1;
 481                  }
 482          }
 483   
 484          if (hdr.network == 13) {
 485                  /*
 486                   * OK, if this was a Nokia capture, make it
 487                   * WTAP_ENCAP_ATM_PDUS, otherwise return
 488                   * an error.
 489                   */
 490                  if (wth->file_type == WTAP_FILE_PCAP_NOKIA)
 491                          wth->file_encap = WTAP_ENCAP_ATM_PDUS;
 492                  else {
 493                          *err = WTAP_ERR_UNSUPPORTED_ENCAP;
 494                          *err_info = g_strdup_printf("pcap: network type %u unknown or unsupported",
 495                              hdr.network);
 496                          g_free(wth->capture.pcap);
 497                          return -1;
 498                  }
 499          }
 500   
 501          return 1;
 502  }
Show more  




Change Warning 1017.30042 : Useless Assignment

Priority:
State:
Finding:
Owner:
Note: