Text   |  XML   |  ReML   |   Visible Warnings:

Useless Assignment  at lanalyzer.c:196

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

lanalyzer_open

(/home/sate/Testcases/c/cve/wireshark-1.2.0/wiretap/lanalyzer.c)expand/collapse
Show more  
 128  int lanalyzer_open(wtap *wth, int *err, gchar **err_info)
 129  {
 130          int bytes_read;
 131          char LE_record_type[2];
 132          char LE_record_length[2];
 133          char summary[210];
 134          guint16 board_type, mxslc;
 135          guint16 record_type, record_length;
 136          guint8 cr_day, cr_month;
 137          guint16 cr_year;
 138          struct tm tm;
 139   
 140          errno = WTAP_ERR_CANT_READ;
 141          bytes_read = file_read(LE_record_type, 1, 2, wth->fh);
 142          bytes_read += file_read(LE_record_length, 1, 2, wth->fh);
 143          if (bytes_read != 4) {
 144                  *err = file_error(wth->fh);
 145                  if (*err != 0)
 146                          return -1;
 147                  return 0;
 148          }
 149          wth->data_offset += 4;
 150          record_type = pletohs(LE_record_type);
 151          record_length = pletohs(LE_record_length); /* make sure to do this for while() loop */
 152   
 153          if (record_type != RT_HeaderRegular && record_type != RT_HeaderCyclic) {
 154                  return 0;
 155          }
 156   
 157          /* If we made it this far, then the file is a LANAlyzer file.
 158           * Let's get some info from it. Note that we get wth->snapshot_length
 159           * from a record later in the file. */
 160          wth->file_type = WTAP_FILE_LANALYZER;
 161          wth->capture.lanalyzer = g_malloc(sizeof(lanalyzer_t));
 162          wth->subtype_read = lanalyzer_read;
 163          wth->subtype_seek_read = lanalyzer_seek_read;
 164          wth->subtype_close = lanalyzer_close;
 165          wth->snapshot_length = 0;
 166          wth->tsprecision = WTAP_FILE_TSPREC_NSEC;
 167   
 168          /* Read records until we find the start of packets */
 169          while (1) {
 170                  if (file_seek(wth->fh, record_length, SEEK_CUR, err) == -1) {
 171                          g_free(wth->capture.lanalyzer);
 172                          return -1;
 173                  }
 174                  wth->data_offset += record_length;
 175                  errno = WTAP_ERR_CANT_READ;
 176                  bytes_read = file_read(LE_record_type, 1, 2, wth->fh);
 177                  bytes_read += file_read(LE_record_length, 1, 2, wth->fh);
 178                  if (bytes_read != 4) {
 179                          *err = file_error(wth->fh);
 180                          if (*err != 0) {
 181                                  g_free(wth->capture.lanalyzer);
 182                                  return -1;
 183                          }
 184                          g_free(wth->capture.lanalyzer);
 185                          return 0;
 186                  }
 187                  wth->data_offset += 4;
 188   
 189                  record_type = pletohs(LE_record_type);
 190                  record_length = pletohs(LE_record_length);
 191   
 192                  /*g_message("Record 0x%04X Length %d", record_type, record_length);*/
 193                  switch (record_type) {
 194                          /* Trace Summary Record */
 195                          case RT_Summary:
 196                                  errno = WTAP_ERR_CANT_READ;
 197                                  bytes_read = file_read(summary, 1, sizeof summary,
 198                                      wth->fh);
 199                                  if (bytes_read != sizeof summary) {
 200                                          *err = file_error(wth->fh);
 201                                          if (*err != 0) {
 202                                                  g_free(wth->capture.lanalyzer);
 203                                                  return -1;
 204                                          }
 205                                          g_free(wth->capture.lanalyzer);
 206                                          return 0;
 207                                  }
 208                                  wth->data_offset += sizeof summary;
 209   
 210                                  /* Assume that the date of the creation of the trace file 
 211                                   * is the same date of the trace. Lanalyzer doesn't
 212                                   * store the creation date/time of the trace, but only of 
 213                                   * the file. Unless you traced at 11:55 PM and saved at 00:05
 214                                   * AM, the assumption that trace.date == file.date is true.
 215                                   */
 216                                  cr_day = summary[0];
 217                                  cr_month = summary[1];
 218                                  cr_year = pletohs(&summary[2]);
 219                                  /*g_message("Day %d Month %d Year %d (%04X)", cr_day, cr_month,
 220                                                  cr_year, cr_year);*/
 221   
 222                                  /* Get capture start time. I learned how to do 
 223                                   * this from Guy's code in ngsniffer.c
 224                                   */
 225                                  tm.tm_year = cr_year - 1900;
 226                                  tm.tm_mon = cr_month - 1;
 227                                  tm.tm_mday = cr_day;
 228                                  tm.tm_hour = 0;
 229                                  tm.tm_min = 0;
 230                                  tm.tm_sec = 0;
 231                                  tm.tm_isdst = -1;
 232                                  wth->capture.lanalyzer->start = mktime(&tm);
 233                                  /*g_message("Day %d Month %d Year %d", tm.tm_mday,
 234                                                  tm.tm_mon, tm.tm_year);*/
 235                                  mxslc = pletohs(&summary[30]);
 236                                  wth->snapshot_length = mxslc;
 237   
 238                                  record_length = 0; /* to fake the next iteration of while() */
 239                                  board_type = pletohs(&summary[188]);
 240                                  switch (board_type) {
 241                                          case BOARD_325:
 242                                                  wth->file_encap = WTAP_ENCAP_ETHERNET;
 243                                                  break;
 244                                          case BOARD_325TR:
 245                                                  wth->file_encap = WTAP_ENCAP_TOKEN_RING;
 246                                                  break;
 247                                          default:
 248                                                  g_free(wth->capture.lanalyzer);
 249                                                  *err = WTAP_ERR_UNSUPPORTED_ENCAP;
 250                                                  *err_info = g_strdup_printf("lanalyzer: board type %u unknown",
 251                                                      board_type);
 252                                                  return -1;
 253                                  }
 254                                  break;
 255   
 256                          /* Trace Packet Data Record */
 257                          case RT_PacketData:
 258                                  /* Go back header number ob ytes so that lanalyzer_read 
 259                                   * can read this header */
 260                                  if (file_seek(wth->fh, -bytes_read, SEEK_CUR, err) == -1) {
 261                                          g_free(wth->capture.lanalyzer);
 262                                          return -1;
 263                                  }
 264                                  wth->data_offset -= bytes_read;
 265                                  return 1;
 266   
 267                          default:
 268                                  ; /* no action */
 269                  }
 270          }
 271  }
Show more  




Change Warning 1013.29837 : Useless Assignment

Priority:
State:
Finding:
Owner:
Note: