Text   |  XML   |  ReML   |   Visible Warnings:

Useless Assignment  at snoop.c:255

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

snoop_open

(/home/sate/Testcases/c/cve/wireshark-1.2.0/wiretap/snoop.c)expand/collapse
Show more  
 178  int snoop_open(wtap *wth, int *err, gchar **err_info)
 179  {
 180          int bytes_read;
 181          char magic[sizeof snoop_magic];
 182          struct snoop_hdr hdr;
 183          struct snooprec_hdr rec_hdr;
 184          guint padbytes;
 185          gboolean is_shomiti;
 186          static const int snoop_encap[] = {
 187                  WTAP_ENCAP_ETHERNET,    /* IEEE 802.3 */
 188                  WTAP_ENCAP_UNKNOWN,     /* IEEE 802.4 Token Bus */
 189
229
Show [ Lines 189 to 229 omitted. ]
 230                  WTAP_ENCAP_TOKEN_RING,  /* "4MB IEEE 802.5 Shomiti" */
 231                  WTAP_ENCAP_UNKNOWN,     /* Other */
 232                  WTAP_ENCAP_UNKNOWN,     /* Other */
 233                  WTAP_ENCAP_UNKNOWN,     /* Other */
 234                  WTAP_ENCAP_IEEE_802_11_WITH_RADIO,
 235          };
 236          #define NUM_SHOMITI_ENCAPS (sizeof shomiti_encap / sizeof shomiti_encap[0])
 237          int file_encap;
 238   
 239          /* Read in the string that should be at the start of a "snoop" file */
 240          errno = WTAP_ERR_CANT_READ;
 241          bytes_read = file_read(magic, 1, sizeof magic, wth->fh);
 242          if (bytes_read != sizeof magic) {
 243                  *err = file_error(wth->fh);
 244                  if (*err != 0)
 245                          return -1;
 246                  return 0;
 247          }
 248          wth->data_offset += sizeof magic;
 249   
 250          if (memcmp(magic, snoop_magic, sizeof snoop_magic) != 0) {
 251                  return 0;
 252          }
 253   
 254          /* Read the rest of the header. */
 255          errno = WTAP_ERR_CANT_READ;
 256          bytes_read = file_read(&hdr, 1, sizeof hdr, wth->fh);
 257          if (bytes_read != sizeof hdr) {
 258                  *err = file_error(wth->fh);
 259                  if (*err != 0)
 260                          return -1;
 261                  return 0;
 262          }
 263          wth->data_offset += sizeof hdr;
 264   
 265          /*
 266           * Make sure it's a version we support.
 267           */
 268          hdr.version = g_ntohl(hdr.version);
 269          switch (hdr.version) {
 270   
 271          case 2:         /* Solaris 2.x and later snoop, and Shomiti
 272                             Surveyor prior to 3.0, or 3.0 and later
 273                             with NDIS card */
 274          case 3:         /* Surveyor 3.0 and later, with Shomiti CMM2 hardware */
 275          case 4:         /* Surveyor 3.0 and later, with Shomiti GAM hardware */
 276          case 5:         /* Surveyor 3.0 and later, with Shomiti THG hardware */
 277                  break;
 278   
 279          default:
 280                  *err = WTAP_ERR_UNSUPPORTED;
 281                  *err_info = g_strdup_printf("snoop: version %u unsupported", hdr.version);
 282                  return -1;
 283          }
 284   
 285          /*
 286           * Oh, this is lovely.
 287           *
 288           * I suppose Shomiti could give a bunch of lawyerly noise about 
 289           * how "well, RFC 1761 said they were unassigned, and that's
 290           * the standard, not the DLPI header file, so it's perfectly OK
 291           * for us to use them, blah blah blah", but it's still irritating
 292           * as hell that they used the unassigned-in-RFC-1761 values for
 293
302
Show [ Lines 293 to 302 omitted. ]
 303           *
 304           * The only way I can see to determine that is to check how much
 305           * padding there is in the first packet - if there's enough 
 306           * padding for a Shomiti trailer, it's probably a Shomiti 
 307           * capture, and otherwise, it's probably from Snoop.
 308           */
 309   
 310          /*
 311           * Start out assuming it's not a Shomiti capture.
 312           */
 313          is_shomiti = FALSE;
 314   
 315          /* Read first record header. */
 316          errno = WTAP_ERR_CANT_READ;
 317          bytes_read = file_read(&rec_hdr, 1, sizeof rec_hdr, wth->fh);
 318          if (bytes_read != sizeof rec_hdr) {
 319                  *err = file_error(wth->fh);
 320                  if (*err == 0 && bytes_read != 0)
 321                          *err = WTAP_ERR_SHORT_READ;
 322                  if (*err != 0) {
 323                          /*
 324                           * A real-live error.
 325                           */
 326                          return -1;
 327                  }
 328   
 329                  /*
 330                   * The file ends after the record header, which means this 
 331                   * is a capture with no packets.
 332                   *
 333                   * We assume it's a snoop file; the actual type of file is
 334                   * irrelevant, as there are no records in it, and thus no 
 335                   * extra information if it's a Shomiti capture, and no
 336                   * link-layer headers whose type we have to know, and no
 337                   * Ethernet frames that might have an FCS.
 338                   */
 339          } else {
 340                  /*
 341                   * Compute the number of bytes of padding in the 
 342                   * record.  If it's at least the size of a Shomiti 
 343                   * trailer record, we assume this is a Shomiti
 344                   * capture.  (Some atmsnoop captures appear 
 345                   * to have 4 bytes of padding, and at least one
 346                   * snoop capture appears to have 6 bytes of padding;
 347                   * the Shomiti header is larger than either of those.)
 348                   */
 349                  if (g_ntohl(rec_hdr.rec_len) >
 350                      (sizeof rec_hdr + g_ntohl(rec_hdr.incl_len))) {
 351                          /*
 352                           * Well, we have padding; how much?
 353                           */
 354                          padbytes = g_ntohl(rec_hdr.rec_len) -
 355                              ((guint)sizeof rec_hdr + g_ntohl(rec_hdr.incl_len));
 356   
 357                          /*
 358                           * Is it at least the size of a Shomiti trailer?
 359                           */
 360                          is_shomiti =
 361                              (padbytes >= sizeof (struct shomiti_trailer));
 362                  }
 363          }
 364   
 365          /*
 366           * Seek back to the beginning of the first record.
 367           */
 368          if (file_seek(wth->fh, wth->data_offset, SEEK_SET, err) == -1)
 369                  return -1;
 370   
 371          hdr.network = g_ntohl(hdr.network);
 372          if (is_shomiti) {
 373                  if (hdr.network >= NUM_SHOMITI_ENCAPS 
 374                      || shomiti_encap[hdr.network] == WTAP_ENCAP_UNKNOWN) {
 375                          *err = WTAP_ERR_UNSUPPORTED_ENCAP;
 376                          *err_info = g_strdup_printf("snoop: Shomiti network type %u unknown or unsupported",
 377                              hdr.network);
 378                          return -1;
 379                  }
 380                  file_encap = shomiti_encap[hdr.network];
 381   
 382                  /* This is a Shomiti file */
 383                  wth->file_type = WTAP_FILE_SHOMITI;
 384          } else {
 385                  if (hdr.network >= NUM_SNOOP_ENCAPS 
 386                      || snoop_encap[hdr.network] == WTAP_ENCAP_UNKNOWN) {
 387                          *err = WTAP_ERR_UNSUPPORTED_ENCAP;
 388                          *err_info = g_strdup_printf("snoop: network type %u unknown or unsupported",
 389                              hdr.network);
 390                          return -1;
 391                  }
 392                  file_encap = snoop_encap[hdr.network];
 393   
 394                  /* This is a snoop file */
 395                  wth->file_type = WTAP_FILE_SNOOP;
 396          }
 397   
 398          /*
 399           * We don't currently use the extra information in Shomiti 
 400           * records, so we use the same routines to read snoop and
 401           * Shomiti files.
 402           */
 403          wth->subtype_read = snoop_read;
 404          wth->subtype_seek_read = snoop_seek_read;
 405          wth->file_encap = file_encap;
 406          wth->snapshot_length = 0;       /* not available in header */
 407          wth->tsprecision = WTAP_FILE_TSPREC_USEC;
 408          return 1;
 409  }
Show more  




Change Warning 1052.29851 : Useless Assignment

Because they are very similar, this warning shares annotations with warning 1052.29852.

Priority:
State:
Finding:
Owner:
Note: