/src/wireshark/wiretap/vms.c
Line | Count | Source |
1 | | /* vms.c |
2 | | * |
3 | | * Wiretap Library |
4 | | * Copyright (c) 2001 by Marc Milgram <ethereal@mmilgram.NOSPAMmail.net> |
5 | | * |
6 | | * SPDX-License-Identifier: GPL-2.0-or-later |
7 | | */ |
8 | | |
9 | | /* |
10 | | * VMS TCPTRACE |
11 | | * |
12 | | * DEC/Compaq/HP/VMS Software VMS's TCPIPTRACE/TCPTRACE format is supported. |
13 | | * This is the capture program that comes with TCP/IP or UCX as supplied by |
14 | | * VMS Software, Hewlett Packard Enterprise/HP, Compaq, or Digital Equipment |
15 | | * Corporation. |
16 | | * |
17 | | * Under UCX 4.x, it is invoked as TCPIPTRACE. Under TCPIP 5.x, it is invoked |
18 | | * as TCPTRACE. |
19 | | * |
20 | | * TCPTRACE produces an ASCII text based format that has changed slightly over |
21 | | * time. |
22 | | */ |
23 | | |
24 | | /* Notes: |
25 | | * TCPIPtrace TCP fragments don't have the header line. So, we are never |
26 | | * to look for that line for the first line of a packet except the first |
27 | | * packet. This allows us to read fragmented packets. Define |
28 | | * TCPIPTRACE_FRAGMENTS_HAVE_HEADER_LINE to expect the first line to be |
29 | | * at the start of every packet. |
30 | | */ |
31 | | #include "config.h" |
32 | | #include "vms.h" |
33 | | #include "wtap_module.h" |
34 | | #include "file_wrappers.h" |
35 | | |
36 | | #include <wsutil/strtoi.h> |
37 | | |
38 | | #include <stdlib.h> |
39 | | #include <string.h> |
40 | | |
41 | | /* This module reads the output of the various VMS TCPIP trace utilities |
42 | | * such as TCPIPTRACE, TCPTRACE and UCX$TRACE |
43 | | * |
44 | | * It was initially based on toshiba.c and refined with code from cosine.c |
45 | | |
46 | | -------------------------------------------------------------------------------- |
47 | | Example TCPIPTRACE TCPTRACE output data: |
48 | | |
49 | | TCPIPtrace full display RCV packet 8 at 10-JUL-2001 14:54:19.56 |
50 | | |
51 | | IP Version = 4, IHL = 5, TOS = 00, Total Length = 84 = ^x0054 |
52 | | IP Identifier = ^x178F, Flags (0=0,DF=0,MF=0), |
53 | | Fragment Offset = 0 = ^x0000, Calculated Offset = 0 = ^x0000 |
54 | | IP TTL = 64 = ^x40, Protocol = 17 = ^x11, Header Checksum = ^x4C71 |
55 | | IP Source Address = 10.12.1.80 |
56 | | IP Destination Address = 10.12.1.50 |
57 | | |
58 | | UDP Source Port = 731, UDP Destination Port = 111 |
59 | | UDP Header and Datagram Length = 64 = ^x0040, Checksum = ^xB6C0 |
60 | | |
61 | | 50010C0A 714C1140 00008F17 54000045 0000 E..T....@.Lq...P |
62 | | 27E54C3C | C0B64000 6F00DB02 | 32010C0A 0010 ...2...o.@..<L.' |
63 | | 02000000 A0860100 02000000 00000000 0020 ................ |
64 | | 00000000 00000000 00000000 03000000 0030 ................ |
65 | | 06000000 01000000 A5860100 00000000 0040 ................ |
66 | | 00000000 0050 .... |
67 | | -------------------------------------------------------------------------------- |
68 | | |
69 | | Example UCX$TRACE output data: |
70 | | |
71 | | UCX INTERnet trace RCV packet seq # = 1 at 14-MAY-2003 11:32:10.93 |
72 | | |
73 | | IP Version = 4, IHL = 5, TOS = 00, Total Length = 583 = ^x0247 |
74 | | IP Identifier = ^x702E, Flags (0=0,DF=0,MF=0), |
75 | | Fragment Offset = 0 = ^x0000, Calculated Offset = 0 = ^x0000 |
76 | | IP TTL = 128 = ^x80, Protocol = 17 = ^x11, Header Checksum = ^x70EC |
77 | | IP Source Address = 10.20.4.159 |
78 | | IP Destination Address = 10.20.4.255 |
79 | | |
80 | | UDP Source Port = 138, UDP Destination Port = 138 |
81 | | UDP Header and Datagram Length = 563 = ^x0233, Checksum = ^xB913 |
82 | | |
83 | | 9F04140A 70EC1180 0000702E 47020045 0000 E..G.p.....p.... |
84 | | B1B80E11 | B9133302 8A008A00 | FF04140A 0010 .........3...... |
85 | | 46484648 45200000 1D028A00 9F04140A 0020 ...........EHFHF |
86 | | 43414341 4341434D 454D4546 45454550 0030 PEEEFEMEMCACACAC |
87 | | |
88 | | -------------------------------------------------------------------------------- |
89 | | |
90 | | Alternate UCX$TRACE type output data: |
91 | | |
92 | | TCPIP INTERnet trace RCV packet seq # = 1 at 23-OCT-1998 15:19:33.29 |
93 | | |
94 | | IP Version = 4, IHL = 5, TOS = 00, Total Length = 217 = ^x00D9 |
95 | | IP Identifier = ^x0065, Flags (0=0,DF=0,MF=0), |
96 | | Fragment Offset = 0 = ^x0000, Calculated Offset = 0 = ^x0000 |
97 | | IP TTL = 32 = ^x20, Protocol = 17 = ^x11, Header Checksum = ^x8F6C |
98 | | IP Source Address = 16.20.168.93 |
99 | | IP Destination Address = 16.20.255.255 |
100 | | |
101 | | UDP Source Port = 138, UDP Destination Port = 138 |
102 | | UDP Header and Datagram Length = 197 = ^x00C5, Checksum = ^x0E77 |
103 | | |
104 | | 5DA81410 8F6C1120 00000065 D9000045 0000 E...awe.....l....] |
105 | | | 0E77C500 8A008A00 | FFFF1410 0010 ..........w. |
106 | | |
107 | | -------------------------------------------------------------------------------- |
108 | | |
109 | | The only difference between the utilities is the Packet header line, primarily |
110 | | the utility identifier and the packet sequence formats. |
111 | | |
112 | | There appear to be 2 formats for packet sequencing |
113 | | |
114 | | Format 1: |
115 | | |
116 | | ... packet nn at DD-MMM-YYYY hh:mm:ss.ss |
117 | | |
118 | | Format 2: |
119 | | |
120 | | ... packet seq # = nn at DD-MMM-YYYY hh:mm:ss.ss |
121 | | |
122 | | If there are other formats then code will have to be written in parse_vms_packet() |
123 | | to handle them. |
124 | | |
125 | | -------------------------------------------------------------------------------- |
126 | | |
127 | | */ |
128 | | |
129 | | /* Magic text to check for VMS-ness of file using possible utility names |
130 | | * |
131 | | */ |
132 | 0 | #define VMS_HDR_MAGIC_STR1 "TCPIPtrace" |
133 | 0 | #define VMS_HDR_MAGIC_STR2 "TCPtrace" |
134 | 0 | #define VMS_HDR_MAGIC_STR3 "INTERnet trace" |
135 | | |
136 | | /* Magic text for start of packet */ |
137 | | #define VMS_REC_MAGIC_STR1 VMS_HDR_MAGIC_STR1 |
138 | | #define VMS_REC_MAGIC_STR2 VMS_HDR_MAGIC_STR2 |
139 | | #define VMS_REC_MAGIC_STR3 VMS_HDR_MAGIC_STR3 |
140 | | |
141 | 0 | #define VMS_HEADER_LINES_TO_CHECK 200 |
142 | 0 | #define VMS_LINE_LENGTH 240 |
143 | | |
144 | | static bool vms_read(wtap *wth, wtap_rec *rec, int *err, |
145 | | char **err_info, int64_t *data_offset); |
146 | | static bool vms_seek_read(wtap *wth, int64_t seek_off, wtap_rec *rec, |
147 | | int *err, char **err_info); |
148 | | static bool parse_single_hex_dump_line(char* rec, Buffer *buf, |
149 | | int in_off, int remaining_bytes); |
150 | | static bool parse_vms_packet(wtap *wth, FILE_T fh, wtap_rec *rec, int *err, |
151 | | char **err_info); |
152 | | |
153 | | static int vms_file_type_subtype = -1; |
154 | | |
155 | | void register_vms(void); |
156 | | |
157 | | #ifdef TCPIPTRACE_FRAGMENTS_HAVE_HEADER_LINE |
158 | | /* Seeks to the beginning of the next packet, and returns the |
159 | | byte offset. Returns -1 on failure, and sets "*err" to the error |
160 | | and sets "*err_info" to null or an additional error string. */ |
161 | | static long vms_seek_next_packet(wtap *wth, int *err, char **err_info) |
162 | | { |
163 | | long cur_off; |
164 | | char buf[VMS_LINE_LENGTH]; |
165 | | |
166 | | while (1) { |
167 | | cur_off = file_tell(wth->fh); |
168 | | if (cur_off == -1) { |
169 | | /* Error */ |
170 | | *err = file_error(wth->fh, err_info); |
171 | | return -1; |
172 | | } |
173 | | if (file_gets(buf, sizeof(buf), wth->fh) == NULL) { |
174 | | /* EOF or error. */ |
175 | | *err = file_error(wth->fh, err_info); |
176 | | break; |
177 | | } |
178 | | if (strstr(buf, VMS_REC_MAGIC_STR1) || |
179 | | strstr(buf, VMS_REC_MAGIC_STR2) || |
180 | | strstr(buf, VMS_REC_MAGIC_STR2)) { |
181 | | (void) g_strlcpy(hdr, buf,VMS_LINE_LENGTH); |
182 | | return cur_off; |
183 | | } |
184 | | } |
185 | | return -1; |
186 | | } |
187 | | #endif /* TCPIPTRACE_FRAGMENTS_HAVE_HEADER_LINE */ |
188 | | |
189 | | /* Look through the first part of a file to see if this is |
190 | | * a VMS trace file. |
191 | | * |
192 | | * Returns true if it is, false if it isn't or if we get an I/O error; |
193 | | * if we get an I/O error, "*err" will be set to a non-zero value and |
194 | | * "*err_info will be set to null or an additional error string. |
195 | | * |
196 | | * Leaves file handle at beginning of line that contains the VMS Magic |
197 | | * identifier. |
198 | | */ |
199 | | static bool vms_check_file_type(wtap *wth, int *err, char **err_info) |
200 | 0 | { |
201 | 0 | char buf[VMS_LINE_LENGTH]; |
202 | 0 | unsigned reclen, line; |
203 | 0 | int64_t mpos; |
204 | |
|
205 | 0 | buf[VMS_LINE_LENGTH-1] = '\0'; |
206 | |
|
207 | 0 | for (line = 0; line < VMS_HEADER_LINES_TO_CHECK; line++) { |
208 | 0 | mpos = file_tell(wth->fh); |
209 | 0 | if (mpos == -1) { |
210 | | /* Error. */ |
211 | 0 | *err = file_error(wth->fh, err_info); |
212 | 0 | return false; |
213 | 0 | } |
214 | 0 | if (file_gets(buf, VMS_LINE_LENGTH, wth->fh) == NULL) { |
215 | | /* EOF or error. */ |
216 | 0 | *err = file_error(wth->fh, err_info); |
217 | 0 | return false; |
218 | 0 | } |
219 | | |
220 | 0 | reclen = (unsigned) strlen(buf); |
221 | 0 | if (reclen < strlen(VMS_HDR_MAGIC_STR1) || |
222 | 0 | reclen < strlen(VMS_HDR_MAGIC_STR2) || |
223 | 0 | reclen < strlen(VMS_HDR_MAGIC_STR3)) { |
224 | 0 | continue; |
225 | 0 | } |
226 | | |
227 | 0 | if (strstr(buf, VMS_HDR_MAGIC_STR1) || |
228 | 0 | strstr(buf, VMS_HDR_MAGIC_STR2) || |
229 | 0 | strstr(buf, VMS_HDR_MAGIC_STR3)) { |
230 | | /* Go back to the beginning of this line, so we will |
231 | | * re-read it. */ |
232 | 0 | if (file_seek(wth->fh, mpos, SEEK_SET, err) == -1) { |
233 | | /* Error. */ |
234 | 0 | return false; |
235 | 0 | } |
236 | 0 | return true; |
237 | 0 | } |
238 | 0 | } |
239 | 0 | *err = 0; |
240 | 0 | return false; |
241 | 0 | } |
242 | | |
243 | | |
244 | | wtap_open_return_val vms_open(wtap *wth, int *err, char **err_info) |
245 | 0 | { |
246 | | /* Look for VMS header */ |
247 | 0 | if (!vms_check_file_type(wth, err, err_info)) { |
248 | 0 | if (*err != 0 && *err != WTAP_ERR_SHORT_READ) |
249 | 0 | return WTAP_OPEN_ERROR; |
250 | 0 | return WTAP_OPEN_NOT_MINE; |
251 | 0 | } |
252 | | |
253 | 0 | wth->file_encap = WTAP_ENCAP_RAW_IP; |
254 | 0 | wth->file_type_subtype = vms_file_type_subtype; |
255 | 0 | wth->snapshot_length = 0; /* not known */ |
256 | 0 | wth->subtype_read = vms_read; |
257 | 0 | wth->subtype_seek_read = vms_seek_read; |
258 | 0 | wth->file_tsprec = WTAP_TSPREC_10_MSEC; |
259 | | |
260 | | /* |
261 | | * Add an IDB; we don't know how many interfaces were |
262 | | * involved, so we just say one interface, about which |
263 | | * we only know the link-layer type, snapshot length, |
264 | | * and time stamp resolution. |
265 | | */ |
266 | 0 | wtap_add_generated_idb(wth); |
267 | |
|
268 | 0 | return WTAP_OPEN_MINE; |
269 | 0 | } |
270 | | |
271 | | /* Find the next packet and parse it; called from wtap_read(). */ |
272 | | static bool vms_read(wtap *wth, wtap_rec *rec, int *err, |
273 | | char **err_info, int64_t *data_offset) |
274 | 0 | { |
275 | 0 | int64_t offset = 0; |
276 | | |
277 | | /* Find the next packet */ |
278 | | #ifdef TCPIPTRACE_FRAGMENTS_HAVE_HEADER_LINE |
279 | | offset = vms_seek_next_packet(wth, err, err_info); |
280 | | #else |
281 | 0 | offset = file_tell(wth->fh); |
282 | 0 | #endif |
283 | 0 | if (offset < 1) { |
284 | 0 | *err = file_error(wth->fh, err_info); |
285 | 0 | return false; |
286 | 0 | } |
287 | 0 | *data_offset = offset; |
288 | | |
289 | | /* Parse the packet */ |
290 | 0 | return parse_vms_packet(wth, wth->fh, rec, err, err_info); |
291 | 0 | } |
292 | | |
293 | | /* Used to read packets in random-access fashion */ |
294 | | static bool vms_seek_read(wtap *wth, int64_t seek_off, wtap_rec *rec, |
295 | | int *err, char **err_info) |
296 | 0 | { |
297 | 0 | if (file_seek(wth->random_fh, seek_off - 1, SEEK_SET, err) == -1) |
298 | 0 | return false; |
299 | | |
300 | 0 | if (!parse_vms_packet(wth, wth->random_fh, rec, err, err_info)) { |
301 | 0 | if (*err == 0) |
302 | 0 | *err = WTAP_ERR_SHORT_READ; |
303 | 0 | return false; |
304 | 0 | } |
305 | 0 | return true; |
306 | 0 | } |
307 | | |
308 | | /* isdumpline assumes that dump lines start with some non-alphanumerics |
309 | | * followed by 4 hex numbers - each 8 digits long, each hex number followed |
310 | | * by 3 spaces. |
311 | | */ |
312 | | static int |
313 | | isdumpline( char *line ) |
314 | 0 | { |
315 | 0 | int i, j; |
316 | |
|
317 | 0 | while (*line && !g_ascii_isalnum(*line)) |
318 | 0 | line++; |
319 | |
|
320 | 0 | for (j=0; j<4; j++) { |
321 | 0 | for (i=0; i<8; i++, line++) |
322 | 0 | if (! g_ascii_isxdigit(*line)) |
323 | 0 | return false; |
324 | | |
325 | 0 | for (i=0; i<3; i++, line++) |
326 | 0 | if (*line != ' ') |
327 | 0 | return false; |
328 | 0 | } |
329 | | |
330 | 0 | return g_ascii_isspace(*line); |
331 | 0 | } |
332 | | |
333 | | /* Parses a packet record. */ |
334 | | static bool |
335 | | parse_vms_packet(wtap *wth, FILE_T fh, wtap_rec *rec, int *err, char **err_info) |
336 | 0 | { |
337 | 0 | char line[VMS_LINE_LENGTH + 1]; |
338 | 0 | int num_items_scanned; |
339 | 0 | bool have_pkt_len = false; |
340 | 0 | uint32_t pkt_len = 0; |
341 | 0 | int pktnum; |
342 | 0 | int csec = 101; |
343 | 0 | struct tm tm; |
344 | 0 | char mon[4] = {'J', 'A', 'N', 0}; |
345 | 0 | char *p; |
346 | 0 | const char *endp; |
347 | 0 | static const char months[] = "JANFEBMARAPRMAYJUNJULAUGSEPOCTNOVDEC"; |
348 | 0 | uint32_t i; |
349 | 0 | int offset = 0; |
350 | |
|
351 | 0 | tm.tm_year = 1970; |
352 | 0 | tm.tm_mon = 0; |
353 | 0 | tm.tm_mday = 1; |
354 | 0 | tm.tm_hour = 1; |
355 | 0 | tm.tm_min = 1; |
356 | 0 | tm.tm_sec = 1; |
357 | | |
358 | | /* Skip lines until one starts with a hex number */ |
359 | 0 | do { |
360 | 0 | if (file_gets(line, VMS_LINE_LENGTH, fh) == NULL) { |
361 | 0 | *err = file_error(fh, err_info); |
362 | 0 | if ((*err == 0) && (csec != 101)) { |
363 | 0 | *err = WTAP_ERR_SHORT_READ; |
364 | 0 | } |
365 | 0 | return false; |
366 | 0 | } |
367 | 0 | line[VMS_LINE_LENGTH] = '\0'; |
368 | |
|
369 | 0 | if ((csec == 101) && (p = strstr(line, "packet ")) != NULL |
370 | 0 | && (! strstr(line, "could not save "))) { |
371 | | /* Find text in line starting with "packet ". */ |
372 | | |
373 | | /* First look for the Format 1 type sequencing */ |
374 | 0 | num_items_scanned = sscanf(p, |
375 | 0 | "packet %9d at %2d-%3s-%4d %2d:%2d:%2d.%9d", |
376 | 0 | &pktnum, &tm.tm_mday, mon, |
377 | 0 | &tm.tm_year, &tm.tm_hour, |
378 | 0 | &tm.tm_min, &tm.tm_sec, &csec); |
379 | | /* Next look for the Format 2 type sequencing */ |
380 | 0 | if (num_items_scanned != 8) { |
381 | 0 | num_items_scanned = sscanf(p, |
382 | 0 | "packet seq # = %9d at %2d-%3s-%4d %2d:%2d:%2d.%9d", |
383 | 0 | &pktnum, &tm.tm_mday, mon, |
384 | 0 | &tm.tm_year, &tm.tm_hour, |
385 | 0 | &tm.tm_min, &tm.tm_sec, &csec); |
386 | 0 | } |
387 | | /* if unknown format then exit with error */ |
388 | | /* We will need to add code to handle new format */ |
389 | 0 | if (num_items_scanned != 8) { |
390 | 0 | *err = WTAP_ERR_BAD_FILE; |
391 | 0 | *err_info = g_strdup("vms: header line not valid"); |
392 | 0 | return false; |
393 | 0 | } |
394 | 0 | } |
395 | 0 | if ( (! have_pkt_len) && (p = strstr(line, "Length "))) { |
396 | 0 | p += sizeof("Length "); |
397 | 0 | while (*p && ! g_ascii_isdigit(*p)) |
398 | 0 | p++; |
399 | |
|
400 | 0 | if ( !*p ) { |
401 | 0 | *err = WTAP_ERR_BAD_FILE; |
402 | 0 | *err_info = g_strdup("vms: Length field not valid"); |
403 | 0 | return false; |
404 | 0 | } |
405 | | |
406 | 0 | if (!ws_strtou32(p, &endp, &pkt_len) || (*endp != '\0' && !g_ascii_isspace(*endp))) { |
407 | 0 | *err = WTAP_ERR_BAD_FILE; |
408 | 0 | *err_info = ws_strdup_printf("vms: Length field '%s' not valid", p); |
409 | 0 | return false; |
410 | 0 | } |
411 | 0 | have_pkt_len = true; |
412 | 0 | break; |
413 | 0 | } |
414 | 0 | } while (! isdumpline(line)); |
415 | 0 | if (! have_pkt_len) { |
416 | 0 | *err = WTAP_ERR_BAD_FILE; |
417 | 0 | *err_info = ws_strdup_printf("vms: Length field not found"); |
418 | 0 | return false; |
419 | 0 | } |
420 | 0 | if (pkt_len > WTAP_MAX_PACKET_SIZE_STANDARD) { |
421 | | /* |
422 | | * Probably a corrupt capture file; return an error, |
423 | | * so that our caller doesn't blow up trying to allocate |
424 | | * space for an immensely-large packet. |
425 | | */ |
426 | 0 | *err = WTAP_ERR_BAD_FILE; |
427 | 0 | *err_info = ws_strdup_printf("vms: File has %u-byte packet, bigger than maximum of %u", |
428 | 0 | pkt_len, WTAP_MAX_PACKET_SIZE_STANDARD); |
429 | 0 | return false; |
430 | 0 | } |
431 | | |
432 | 0 | p = strstr(months, mon); |
433 | 0 | if (p) |
434 | 0 | tm.tm_mon = (int) (p - months) / 3; |
435 | 0 | tm.tm_year -= 1900; |
436 | 0 | tm.tm_isdst = -1; |
437 | |
|
438 | 0 | wtap_setup_packet_rec(rec, wth->file_encap); |
439 | 0 | rec->block = wtap_block_create(WTAP_BLOCK_PACKET); |
440 | 0 | rec->presence_flags = WTAP_HAS_TS; |
441 | 0 | rec->ts.secs = mktime(&tm); |
442 | 0 | rec->ts.nsecs = csec * 10000000; |
443 | 0 | rec->rec_header.packet_header.caplen = pkt_len; |
444 | 0 | rec->rec_header.packet_header.len = pkt_len; |
445 | | |
446 | | /* Make sure we have enough room for the packet */ |
447 | 0 | ws_buffer_assure_space(&rec->data, pkt_len); |
448 | | |
449 | | /* Convert the ASCII hex dump to binary data */ |
450 | 0 | for (i = 0; i < pkt_len; i += 16) { |
451 | 0 | if (file_gets(line, VMS_LINE_LENGTH, fh) == NULL) { |
452 | 0 | *err = file_error(fh, err_info); |
453 | 0 | if (*err == 0) { |
454 | 0 | *err = WTAP_ERR_SHORT_READ; |
455 | 0 | } |
456 | 0 | return false; |
457 | 0 | } |
458 | 0 | line[VMS_LINE_LENGTH] = '\0'; |
459 | 0 | if (i == 0) { |
460 | 0 | while (! isdumpline(line)) { /* advance to start of hex data */ |
461 | 0 | if (file_gets(line, VMS_LINE_LENGTH, fh) == NULL) { |
462 | 0 | *err = file_error(fh, err_info); |
463 | 0 | if (*err == 0) { |
464 | 0 | *err = WTAP_ERR_SHORT_READ; |
465 | 0 | } |
466 | 0 | return false; |
467 | 0 | } |
468 | 0 | line[VMS_LINE_LENGTH] = '\0'; |
469 | 0 | } |
470 | 0 | while (line[offset] && !g_ascii_isxdigit(line[offset])) |
471 | 0 | offset++; |
472 | 0 | } |
473 | 0 | if (!parse_single_hex_dump_line(line, &rec->data, |
474 | 0 | offset, pkt_len - i)) { |
475 | 0 | *err = WTAP_ERR_BAD_FILE; |
476 | 0 | *err_info = g_strdup("vms: hex dump not valid"); |
477 | 0 | return false; |
478 | 0 | } |
479 | 0 | } |
480 | | /* Avoid TCPIPTRACE-W-BUFFERSFUL, TCPIPtrace could not save n packets. |
481 | | * errors. |
482 | | * |
483 | | * XXX - when we support packet drop report information in the |
484 | | * Wiretap API, we should parse those lines and return "n" as |
485 | | * a packet drop count. */ |
486 | 0 | if (!file_gets(line, VMS_LINE_LENGTH, fh)) { |
487 | 0 | *err = file_error(fh, err_info); |
488 | 0 | if (*err == 0) { |
489 | | /* There is no next line, so there's no "TCPIPtrace could not |
490 | | * save n packets" line; not an error. */ |
491 | 0 | return true; |
492 | 0 | } |
493 | 0 | return false; |
494 | 0 | } |
495 | 0 | return true; |
496 | 0 | } |
497 | | |
498 | | /* |
499 | | 1 2 3 4 |
500 | | 0123456789012345678901234567890123456789012345 |
501 | | 50010C0A A34C0640 00009017 2C000045 0000 E..,....@.L....P |
502 | | 00000000 14945E52 0A00DC02 | 32010C0A 0010 ...2....R^...... |
503 | | 0000 | B4050402 00003496 00020260 0020 `....4........ |
504 | | */ |
505 | | |
506 | | #define START_POS 7 |
507 | | #define HEX_LENGTH ((8 * 4) + 7) /* eight clumps of 4 bytes with 7 inner spaces */ |
508 | | /* Take a string representing one line from a hex dump and converts the |
509 | | * text to binary data. We check the printed offset with the offset |
510 | | * we are passed to validate the record. We place the bytes in the buffer |
511 | | * at the specified offset. |
512 | | * |
513 | | * Returns true if good hex dump, false if bad. |
514 | | */ |
515 | | static bool |
516 | | parse_single_hex_dump_line(char* rec, Buffer *buf, int in_off, |
517 | 0 | int remaining_bytes) { |
518 | |
|
519 | 0 | int i; |
520 | 0 | char *s; |
521 | 0 | unsigned long value; |
522 | 0 | static const int offsets[16] = {39,37,35,33,28,26,24,22,17,15,13,11,6,4,2,0}; |
523 | 0 | char lbuf[3] = {0,0,0}; |
524 | 0 | uint8_t *pd; |
525 | | |
526 | | /* Get the byte_offset directly from the record */ |
527 | 0 | s = rec; |
528 | 0 | value = strtoul(s + 45 + in_off, NULL, 16); /* XXX - error check? */ |
529 | |
|
530 | 0 | if (value != ws_buffer_length(buf)) { |
531 | 0 | return false; |
532 | 0 | } |
533 | | |
534 | 0 | if (remaining_bytes > 16) |
535 | 0 | remaining_bytes = 16; |
536 | | |
537 | | /* Read the octets right to left, as that is how they are displayed |
538 | | * in VMS. |
539 | | */ |
540 | 0 | pd = ws_buffer_end_ptr(buf); |
541 | 0 | for (i = 0; i < remaining_bytes; i++) { |
542 | 0 | lbuf[0] = rec[offsets[i] + in_off]; |
543 | 0 | lbuf[1] = rec[offsets[i] + 1 + in_off]; |
544 | |
|
545 | 0 | pd[i] = (uint8_t) strtoul(lbuf, NULL, 16); |
546 | 0 | } |
547 | 0 | ws_buffer_increase_length(buf, remaining_bytes); |
548 | |
|
549 | 0 | return true; |
550 | 0 | } |
551 | | |
552 | | static const struct supported_block_type vms_blocks_supported[] = { |
553 | | /* |
554 | | * We support packet blocks, with no comments or other options. |
555 | | */ |
556 | | { WTAP_BLOCK_PACKET, MULTIPLE_BLOCKS_SUPPORTED, NO_OPTIONS_SUPPORTED } |
557 | | }; |
558 | | |
559 | | static const struct file_type_subtype_info vms_info = { |
560 | | "TCPIPtrace (VMS)", "tcpiptrace", "txt", NULL, |
561 | | false, BLOCKS_SUPPORTED(vms_blocks_supported), |
562 | | NULL, NULL, NULL |
563 | | }; |
564 | | |
565 | | void register_vms(void) |
566 | 16 | { |
567 | 16 | vms_file_type_subtype = wtap_register_file_type_subtype(&vms_info); |
568 | | |
569 | | /* |
570 | | * Register name for backwards compatibility with the |
571 | | * wtap_filetypes table in Lua. |
572 | | */ |
573 | 16 | wtap_register_backwards_compatibility_lua_name("VMS", |
574 | 16 | vms_file_type_subtype); |
575 | 16 | } |
576 | | |
577 | | /* |
578 | | * Editor modelines - https://www.wireshark.org/tools/modelines.html |
579 | | * |
580 | | * Local variables: |
581 | | * c-basic-offset: 4 |
582 | | * tab-width: 8 |
583 | | * indent-tabs-mode: nil |
584 | | * End: |
585 | | * |
586 | | * vi: set shiftwidth=4 tabstop=8 expandtab: |
587 | | * :indentSize=4:tabSize=8:noTabs=true: |
588 | | */ |