(/home/sate/Testcases/c/cve/wireshark-1.2.0/wiretap/netmon.c) |
| |
| 122 | | | int netmon_open(wtap *wth, int *err, gchar **err_info) |
| 123 | | | { |
| 124 | | | int bytes_read; |
| 125 | | | char magic[sizeof netmon_1_x_magic]; |
| 126 | | | struct netmon_hdr hdr; |
| 127 | | | int file_type; |
| 128 | | | static const int netmon_encap[] = { |
| 129 | | | WTAP_ENCAP_UNKNOWN, |
| 130 | | | WTAP_ENCAP_ETHERNET, |
| 131 | | | WTAP_ENCAP_TOKEN_RING, |
| 132 | | | WTAP_ENCAP_FDDI_BITSWAPPED, |
| 133 143 |  | | [ Lines 133 to 143 omitted. ] |
| 144 | | | int frame_table_offset; |
| 145 | | | guint32 frame_table_length; |
| 146 | | | guint32 frame_table_size; |
| 147 | | | guint32 *frame_table; |
| 148 | | | #ifdef WORDS_BIGENDIAN |
| 149 | | | unsigned int i; |
| 150 | | | #endif |
| 151 | | | |
| 152 | | | |
| 153 | | | |
| 154 | | | errno = WTAP_ERR_CANT_READ; |
| 155 | | | bytes_read = file_read(magic, 1, sizeof magic, wth->fh);
x /home/sate/Testcases/c/cve/wireshark-1.2.0/wiretap/file_wrappers.h |
| |
36 | #define file_read(buf, bsize, count, file) gzread((file),(buf),(unsigned)((count)*(bsize))) |
| |
|
| 156 | | | if (bytes_read != sizeof magic) { |
| 157 | | | *err = file_error(wth->fh); |
| 158 | | | if (*err != 0) |
| 159 | | | return -1; |
| 160 | | | return 0; |
| 161 | | | } |
| 162 | | | |
| 163 | | | if (memcmp(magic, netmon_1_x_magic, sizeof netmon_1_x_magic) != 0 |
| 164 | | | && memcmp(magic, netmon_2_x_magic, sizeof netmon_1_x_magic) != 0) { |
| 165 | | | return 0; |
| 166 | | | } |
| 167 | | | |
| 168 | | | |
| 169 | | | errno = WTAP_ERR_CANT_READ; |
| 170 | | | bytes_read = file_read(&hdr, 1, sizeof hdr, wth->fh);
x /home/sate/Testcases/c/cve/wireshark-1.2.0/wiretap/file_wrappers.h |
| |
36 | #define file_read(buf, bsize, count, file) gzread((file),(buf),(unsigned)((count)*(bsize))) |
| |
|
| 171 | | | if (bytes_read != sizeof hdr) { |
| 172 | | | *err = file_error(wth->fh); |
| 173 | | | if (*err != 0) |
| 174 | | | return -1; |
| 175 | | | return 0; |
| 176 | | | } |
| 177 | | | |
| 178 | | | switch (hdr.ver_major) { |
| 179 | | | |
| 180 | | | case 1: |
| 181 | | | file_type = WTAP_FILE_NETMON_1_x; |
| 182 | | | break; |
| 183 | | | |
| 184 | | | case 2: |
| 185 | | | file_type = WTAP_FILE_NETMON_2_x; |
| 186 | | | break; |
| 187 | | | |
| 188 | | | default: |
| 189 | | | *err = WTAP_ERR_UNSUPPORTED; |
| 190 | | | *err_info = g_strdup_printf("netmon: major version %u unsupported", hdr.ver_major); |
| 191 | | | return -1; |
| 192 | | | } |
| 193 | | | |
| 194 | | | hdr.network = pletohs(&hdr.network);
x /home/sate/Testcases/c/cve/wireshark-1.2.0/wiretap/wtap-int.h |
| |
373 | #define pletohs(p) ((guint16) \ |
374 | ((guint16)*((const guint8 *)(p)+1)<<8| \ |
375 | (guint16)*((const guint8 *)(p)+0)<<0)) |
| |
|
| 195 | | | if (hdr.network >= NUM_NETMON_ENCAPS
x /home/sate/Testcases/c/cve/wireshark-1.2.0/wiretap/netmon.c |
| |
142 | #define NUM_NETMON_ENCAPS (sizeof netmon_encap / sizeof netmon_encap[0]) |
| |
|
| 196 | | | || netmon_encap[hdr.network] == WTAP_ENCAP_UNKNOWN) { |
| 197 | | | *err = WTAP_ERR_UNSUPPORTED_ENCAP; |
| 198 | | | *err_info = g_strdup_printf("netmon: network type %u unknown or unsupported", |
| 199 | | | hdr.network); |
| 200 | | | return -1; |
| 201 | | | } |
| 202 | | | |
| 203 | | | |
| 204 | | | wth->file_type = file_type; |
| 205 | | | wth->capture.netmon = g_malloc(sizeof(netmon_t)); |
| 206 | | | wth->subtype_read = netmon_read; |
| 207 | | | wth->subtype_seek_read = netmon_seek_read; |
| 208 | | | wth->subtype_sequential_close = netmon_sequential_close; |
| 209 | | | wth->subtype_close = netmon_close; |
| 210 | | | wth->file_encap = netmon_encap[hdr.network]; |
| 211 | | | wth->snapshot_length = 0; |
| 212 | | | |
| 213 | | | |
| 214 | | | |
| 215 | | | |
| 216 | | | tm.tm_year = pletohs(&hdr.ts_year) - 1900;
x /home/sate/Testcases/c/cve/wireshark-1.2.0/wiretap/wtap-int.h |
| |
373 | #define pletohs(p) ((guint16) \ |
374 | ((guint16)*((const guint8 *)(p)+1)<<8| \ |
375 | (guint16)*((const guint8 *)(p)+0)<<0)) |
| |
|
| 217 | | | tm.tm_mon = pletohs(&hdr.ts_month) - 1;
x /home/sate/Testcases/c/cve/wireshark-1.2.0/wiretap/wtap-int.h |
| |
373 | #define pletohs(p) ((guint16) \ |
374 | ((guint16)*((const guint8 *)(p)+1)<<8| \ |
375 | (guint16)*((const guint8 *)(p)+0)<<0)) |
| |
|
| 218 | | | tm.tm_mday = pletohs(&hdr.ts_day);
x /home/sate/Testcases/c/cve/wireshark-1.2.0/wiretap/wtap-int.h |
| |
373 | #define pletohs(p) ((guint16) \ |
374 | ((guint16)*((const guint8 *)(p)+1)<<8| \ |
375 | (guint16)*((const guint8 *)(p)+0)<<0)) |
| |
|
| 219 | | | tm.tm_hour = pletohs(&hdr.ts_hour);
x /home/sate/Testcases/c/cve/wireshark-1.2.0/wiretap/wtap-int.h |
| |
373 | #define pletohs(p) ((guint16) \ |
374 | ((guint16)*((const guint8 *)(p)+1)<<8| \ |
375 | (guint16)*((const guint8 *)(p)+0)<<0)) |
| |
|
| 220 | | | tm.tm_min = pletohs(&hdr.ts_min);
x /home/sate/Testcases/c/cve/wireshark-1.2.0/wiretap/wtap-int.h |
| |
373 | #define pletohs(p) ((guint16) \ |
374 | ((guint16)*((const guint8 *)(p)+1)<<8| \ |
375 | (guint16)*((const guint8 *)(p)+0)<<0)) |
| |
|
| 221 | | | tm.tm_sec = pletohs(&hdr.ts_sec);
x /home/sate/Testcases/c/cve/wireshark-1.2.0/wiretap/wtap-int.h |
| |
373 | #define pletohs(p) ((guint16) \ |
374 | ((guint16)*((const guint8 *)(p)+1)<<8| \ |
375 | (guint16)*((const guint8 *)(p)+0)<<0)) |
| |
|
| 222 | | | tm.tm_isdst = -1; |
| 223 | | | wth->capture.netmon->start_secs = mktime(&tm); |
| 224 | | | |
| 225 | | | |
| 226 | | | |
| 227 | | | |
| 228 | | | |
| 229 | | | |
| 230 | | | |
| 231 | | | |
| 232 | | | |
| 233 | | | |
| 234 | | | |
| 235 | | | |
| 236 | | | |
| 237 | | | |
| 238 | | | wth->capture.netmon->start_usecs = pletohs(&hdr.ts_msec)*1000;
x /home/sate/Testcases/c/cve/wireshark-1.2.0/wiretap/wtap-int.h |
| |
373 | #define pletohs(p) ((guint16) \ |
374 | ((guint16)*((const guint8 *)(p)+1)<<8| \ |
375 | (guint16)*((const guint8 *)(p)+0)<<0)) |
| |
|
| 239 | | | |
| 240 | | | wth->capture.netmon->version_major = hdr.ver_major; |
| 241 | | | |
| 242 | | | |
| 243 | | | |
| 244 | | | |
| 245 | | | frame_table_offset = pletohl(&hdr.frametableoffset);
x /home/sate/Testcases/c/cve/wireshark-1.2.0/wiretap/wtap-int.h |
| |
386 | #define pletohl(p) ((guint32)*((const guint8 *)(p)+3)<<24| \ |
387 | (guint32)*((const guint8 *)(p)+2)<<16| \ |
388 | (guint32)*((const guint8 *)(p)+1)<<8| \ |
389 | (guint32)*((const guint8 *)(p)+0)<<0) |
| |
|
| 246 | | | |
| 247 | | | |
| 248 | | | |
| 249 | | | |
| 250 | | | |
| 251 | | | |
| 252 | | | |
| 253 | | | |
| 254 | | | |
| 255 | | | |
| 256 | | | |
| 257 | | | |
| 258 | | | frame_table_length = pletohl(&hdr.frametablelength);
x /home/sate/Testcases/c/cve/wireshark-1.2.0/wiretap/wtap-int.h |
| |
386 | #define pletohl(p) ((guint32)*((const guint8 *)(p)+3)<<24| \ |
387 | (guint32)*((const guint8 *)(p)+2)<<16| \ |
388 | (guint32)*((const guint8 *)(p)+1)<<8| \ |
389 | (guint32)*((const guint8 *)(p)+0)<<0) |
| |
|
| 259 | | | frame_table_size = frame_table_length / (guint32)sizeof (guint32); |
| 260 | | | if ((frame_table_size * sizeof (guint32)) != frame_table_length) { |
| 261 | | | *err = WTAP_ERR_UNSUPPORTED; |
| 262 | | | *err_info = g_strdup_printf("netmon: frame table length is %u, which is not a multiple of the size of an entry", |
| 263 | | | frame_table_length); |
| 264 | | | g_free(wth->capture.netmon); |
| 265 | | | return -1; |
| 266 | | | } |
| 267 | | | if (frame_table_size == 0) { |
| 268 | | | *err = WTAP_ERR_UNSUPPORTED; |
| 269 | | | *err_info = g_strdup_printf("netmon: frame table length is %u, which means it's less than one entry in size", |
| 270 | | | frame_table_length); |
| 271 | | | g_free(wth->capture.netmon); |
| 272 | | | return -1; |
| 273 | | | } |
| 274 | | | if (file_seek(wth->fh, frame_table_offset, SEEK_SET, err) == -1) {
x /usr/include/stdio.h |
| |
141 | #define SEEK_SET 0 /* Seek from beginning of file. */ |
| |
|
| 275 | | | g_free(wth->capture.netmon); |
| 276 | | | return -1; |
| 277 | | | } |
| 278 | | | frame_table = g_malloc(frame_table_length); |
| 279 | | | errno = WTAP_ERR_CANT_READ; |
Useless Assignment
This code assigns the variable the same value it already had. |
|
| 280 | | | bytes_read = file_read(frame_table, 1, frame_table_length, wth->fh);
x /home/sate/Testcases/c/cve/wireshark-1.2.0/wiretap/file_wrappers.h |
| |
36 | #define file_read(buf, bsize, count, file) gzread((file),(buf),(unsigned)((count)*(bsize))) |
| |
|
| 281 | | | if ((guint32)bytes_read != frame_table_length) { |
| 282 | | | *err = file_error(wth->fh); |
| 283 | | | if (*err == 0) |
| 284 | | | *err = WTAP_ERR_SHORT_READ; |
| 285 | | | g_free(frame_table); |
| 286 | | | g_free(wth->capture.netmon); |
| 287 | | | return -1; |
| 288 | | | } |
| 289 | | | wth->capture.netmon->frame_table_size = frame_table_size; |
| 290 | | | wth->capture.netmon->frame_table = frame_table; |
| 291 | | | |
| 292 | | | #ifdef WORDS_BIGENDIAN |
| 293 | | | |
| 294 | | | |
| 295 | | | |
| 296 | | | for (i = 0; i < frame_table_size; i++) |
| 297 | | | frame_table[i] = pletohl(&frame_table[i]); |
| 298 | | | #endif |
| 299 | | | |
| 300 | | | |
| 301 | | | wth->capture.netmon->current_frame = 0; |
| 302 | | | wth->tsprecision = WTAP_FILE_TSPREC_USEC; |
| 303 | | | |
| 304 | | | return 1; |
| 305 | | | } |
| |