The data contained in this repository can be downloaded to your computer using one of several clients.
Please see the documentation of your version control software client for more information.

Please select the desired protocol below to get the URL.

This URL has Read-Only access.

Statistics
| Branch: | Revision:

main_repo / wiretap / cosine.c @ master

History | View | Annotate | Download (16.9 KB)

1 2925fdc2 Mr. Scottbert
/* cosine.c
2
 *
3
 * $Id$
4
 *
5
 * CoSine IPNOS L2 debug output parsing
6
 * Copyright (c) 2002 by Motonori Shindo <motonori@shin.do>
7
 *
8
 * Wiretap Library
9
 * Copyright (c) 1998 by Gilbert Ramirez <gram@alumni.rice.edu>
10
 *
11
 * This program is free software; you can redistribute it and/or
12
 * modify it under the terms of the GNU General Public License
13
 * as published by the Free Software Foundation; either version 2
14
 * of the License, or (at your option) any later version.
15
 *
16
 * This program is distributed in the hope that it will be useful,
17
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19
 * GNU General Public License for more details.
20
 *
21
 * You should have received a copy of the GNU General Public License
22
 * along with this program; if not, write to the Free Software
23
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
24
 */
25
26
#include "config.h"
27
#include "wtap-int.h"
28
#include "buffer.h"
29
#include "cosine.h"
30
#include "file_wrappers.h"
31
32
#include <stdio.h>
33
#include <stdlib.h>
34
#include <string.h>
35
#include <ctype.h>
36
37
/*
38

39
  IPNOS: CONFIG VPN(100) VR(1.1.1.1)# diags
40
  ipnos diags: Control (1/0) :: layer-2 ?
41
  Registered commands for area "layer-2"
42
      apply-pkt-log-profile  Configure packet logging on an interface
43
      create-pkt-log-profile  Set packet-log-profile to be used for packet logging (see layer-2 pkt-log)
44
      detail                Get Layer 2 low-level details
45

46
  ipnos diags: Control (1/0) :: layer-2 create ?
47
      create-pkt-log-profile  <pkt-log-profile-id ctl-tx-trace-length ctl-rx-trace-length data-tx-trace-length data-rx-trace-length pe-logging-or-control-blade>
48

49
  ipnos diags: Control (1/0) :: layer-2 create 1 32 32 0 0 0
50
  ipnos diags: Control (1/0) :: layer-2 create 2 32 32 100 100 0
51
  ipnos diags: Control (1/0) :: layer-2 apply ?
52
      apply-pkt-log-profile  <slot port channel subif pkt-log-profile-id>
53

54
  ipnos diags: Control (1/0) :: layer-2 apply 3 0x0701 100 0 1
55
  Successfully applied packet-log-profile on LI
56

57
  -- Note that only the control packets are logged because the data packet size parameters are 0 in profile 1
58
  IPNOS: CONFIG VPN(200) VR(3.3.3.3)# ping 20.20.20.43
59
  vpn 200 : [max tries 4, timeout 5 seconds, data length 64 bytes, ttl 255]
60
  ping #1 ok, RTT 0.000 seconds
61
  ping #2 ok, RTT 0.000 seconds
62
  ping #3 ok, RTT 0.000 seconds
63
  ping #4 ok, RTT 0.000 seconds
64
  [finished]
65

66
  IPNOS: CONFIG VPN(200) VR(3.3.3.3)# 2000-2-1,18:19:46.8:  l2-tx (PPP:3/7/1:100), Length:16, Pro:0, Off:0, Pri:0, RM:0, Err:0 [0x4000, 0x0]
67

68

69
  2000-2-1,18:19:46.8:  l2-rx (PPP:3/7/1:100), Length:16, Pro:0, Off:0, Pri:0, RM:0, Err:0 [0x4001, 0x30000]
70

71
  2000-2-1,18:19:46.8:  l2-tx (PPP:3/7/1:100), Length:16, Pro:0, Off:0, Pri:0, RM:0, Err:0 [0x4000, 0x0]
72

73
  2000-2-1,18:19:46.8:  l2-rx (PPP:3/7/1:100), Length:16, Pro:0, Off:0, Pri:0, RM:0, Err:0 [0x4001, 0x8030000]
74

75
  ipnos diags: Control (1/0) :: layer-2 apply 3 0x0701 100 0 0
76
  Successfully applied packet-log-profile on LI
77
  ipnos diags: Control (1/0) :: layer-2 apply 3 0x0701 100 0 2
78
  Successfully applied packet-log-profile on LI
79

80
  -- Note that both control and data packets are logged because the data packet size parameter is 100 in profile 2
81
     Please ignore the event-log messages getting mixed up with the ping command
82
  ping 20.20.20.43 cou2000-2-1,18:20:17.0:  l2-tx (PPP:3/7/1:100), Length:16, Pro:0, Off:0, Pri:0, RM:0, Err:0 [0x4000, 0x0]
83

84
          00 D0 D8 D2 FF 03 C0 21  09 29 00 08 6B 60 84 AA
85

86
  2000-2-1,18:20:17.0:  l2-rx (PPP:3/7/1:100), Length:16, Pro:0, Off:0, Pri:0, RM:0, Err:0 [0x4001, 0x30000]
87
          00 D0 D8 D2 FF 03 C0 21  09 29 00 08 6D FE FA AA
88

89
  2000-2-1,18:20:17.0:  l2-tx (PPP:3/7/1:100), Length:16, Pro:0, Off:0, Pri:0, RM:0, Err:0 [0x4000, 0x0]
90
          00 D0 D8 D2 FF 03 C0 21  0A 29 00 08 6B 60 84 AA
91

92
  2000-2-1,18:20:17.0:  l2-rx (PPP:3/7/1:100), Length:16, Pro:0, Off:0, Pri:0, RM:0, Err:0 [0x4001, 0x8030000]
93
          00 D0 D8 D2 FF 03 C0 21  0A 29 00 08 6D FE FA AA
94

95
  nt 1 length 500
96
  vpn 200 : [max tries 1, timeout 5 seconds, data length 500 bytes, ttl 255]
97
  2000-2-1,18:20:24.1:  l2-tx (PPP:3/7/1:100), Length:536, Pro:1, Off:8, Pri:7, RM:0, Err:0 [0x4070, 0x801]
98
          00 D0 D8 D2 FF 03 00 21  45 00 02 10 00 27 00 00
99
          FF 01 69 51 14 14 14 22  14 14 14 2B 08 00 AD B8
100
          00 03 00 01 10 11 12 13  14 15 16 17 18 19 1A 1B
101
          1C 1D 1E 1F 20 21 22 23  24 25 26 27 28 29 2A 2B
102
          2C 2D 2E 2F 30 31 32 33  34 35 36 37 38 39 3A 3B
103
          3C 3D 3E 3F 40 41 42 43  44 45 46 47 48 49 4A 4B
104
          4C 4D 4E 4F
105

106
  ping #1 ok, RTT 0.010 seconds
107
  2000-2-1,18:20:24.1:  l2-rx (PPP:3/7/1:100), Length:536, Pro:1, Off:8, Pri:7, RM:0, Err:0 [0x4071, 0x30801]
108
          00 D0 D8 D2 FF 03 00 21  45 00 02 10 00 23 00 00
109
          FF 01 69 55 14 14 14 2B  14 14 14 22 00 00 B5 B8
110
          00 03 00 01 10 11 12 13  14 15 16 17 18 19 1A 1B
111
          1C 1D 1E 1F 20 21 22 23  24 25 26 27 28 29 2A 2B
112
          2C 2D 2E 2F 30 31 32 33  34 35 36 37 38 39 3A 3B
113
          3C 3D 3E 3F 40 41 42 43  44 45 46 47 48 49 4A 4B
114
          4C 4D 4E 4F
115

116
  [finished]
117

118
  IPNOS: CONFIG VPN(200) VR(3.3.3.3)# 2000-2-1,18:20:27.0:  l2-tx (PPP:3/7/1:100), Length:16, Pro:0, Off:0, Pri:0, RM:0, Err:0 [0x4000, 0x0]
119

120
          00 D0 D8 D2 FF 03 C0 21  09 2A 00 08 6B 60 84 AA
121

122
  2000-2-1,18:20:27.0:  l2-rx (PPP:3/7/1:100), Length:16, Pro:0, Off:0, Pri:0, RM:0, Err:0 [0x4001, 0x30000]
123
          00 D0 D8 D2 FF 03 C0 21  09 2A 00 08 6D FE FA AA
124

125
  2000-2-1,18:20:27.0:  l2-tx (PPP:3/7/1:100), Length:16, Pro:0, Off:0, Pri:0, RM:0, Err:0 [0x4000, 0x0]
126
          00 D0 D8 D2 FF 03 C0 21  0A 2A 00 08 6B 60 84 AA
127

128
  2000-2-1,18:20:27.0:  l2-rx (PPP:3/7/1:100), Length:16, Pro:0, Off:0, Pri:0, RM:0, Err:0 [0x4001, 0x30000]
129
          00 D0 D8 D2 FF 03 C0 21  0A 2A 00 08 6D FE FA AA
130

131

132
  ipnos diags: Control (1/0) :: layer-2 apply 3 0x0701 100 0 0
133
  Successfully applied packet-log-profile on LI
134
  ipnos diags: Control (1/0) ::
135

136
 */
137
138
/* XXX TODO:
139

140
  o Handle a case where an empty line doesn't exists as a delimiter of
141
    each packet. If the output is sent to a control blade and
142
    displayed as an event log, there's always an empty line between
143
    each packet output, but it may not be true when it is an PE
144
    output.
145

146
  o Some telnet client on Windows may put in a line break at 80
147
    columns when it save the session to a text file ("CRT" is such an
148
    example). I don't think it's a good idea for the telnet client to
149
    do so, but CRT is widely used in Windows community, I should
150
    take care of that in the future.
151

152
*/
153
154
/* Magic text to check for CoSine L2 debug output */
155
#define COSINE_HDR_MAGIC_STR1        "l2-tx"
156
#define COSINE_HDR_MAGIC_STR2        "l2-rx"
157
158
/* Magic text for start of packet */
159
#define COSINE_REC_MAGIC_STR1        COSINE_HDR_MAGIC_STR1
160
#define COSINE_REC_MAGIC_STR2        COSINE_HDR_MAGIC_STR2
161
162
#define COSINE_HEADER_LINES_TO_CHECK        200
163
#define COSINE_LINE_LENGTH                240
164
165
#define COSINE_MAX_PACKET_LEN        65536
166
167
static gboolean empty_line(const gchar *line);
168
static gint64 cosine_seek_next_packet(wtap *wth, int *err, gchar **err_info,
169
        char *hdr);
170
static gboolean cosine_check_file_type(wtap *wth, int *err, gchar **err_info);
171
static gboolean cosine_read(wtap *wth, int *err, gchar **err_info,
172
        gint64 *data_offset);
173
static gboolean cosine_seek_read(wtap *wth, gint64 seek_off,
174
        struct wtap_pkthdr *phdr, Buffer *buf,
175
        int len, int *err, gchar **err_info);
176
static int parse_cosine_rec_hdr(struct wtap_pkthdr *phdr, const char *line,
177
        int *err, gchar **err_info);
178
static gboolean parse_cosine_hex_dump(FILE_T fh, struct wtap_pkthdr *phdr,
179
        int pkt_len, Buffer* buf, int *err, gchar **err_info);
180
static int parse_single_hex_dump_line(char* rec, guint8 *buf,
181
        guint byte_offset);
182
183
/* Returns TRUE if the line appears to be an empty line. Otherwise it
184
   returns FALSE. */
185
static gboolean empty_line(const gchar *line)
186
{
187
        while (*line) {
188
                if (isspace((guchar)*line)) {
189
                        line++;
190
                        continue;
191
                } else {
192
                        break;
193
                }
194
        }
195
        if (*line == '\0')
196
                return TRUE;
197
        else
198
                return FALSE;
199
}
200
201
/* Seeks to the beginning of the next packet, and returns the
202
   byte offset. Copy the header line to hdr. Returns -1 on failure,
203
   and sets "*err" to the error and sets "*err_info" to null or an
204
   additional error string. */
205
static gint64 cosine_seek_next_packet(wtap *wth, int *err, gchar **err_info,
206
        char *hdr)
207
{
208
        gint64 cur_off;
209
        char buf[COSINE_LINE_LENGTH];
210
211
        while (1) {
212
                cur_off = file_tell(wth->fh);
213
                if (cur_off == -1) {
214
                        /* Error */
215
                        *err = file_error(wth->fh, err_info);
216
                        return -1;
217
                }
218
                if (file_gets(buf, sizeof(buf), wth->fh) == NULL) {
219
                        *err = file_error(wth->fh, err_info);
220
                        return -1;
221
                }
222
                if (strstr(buf, COSINE_REC_MAGIC_STR1) ||
223
                    strstr(buf, COSINE_REC_MAGIC_STR2)) {
224
                        g_strlcpy(hdr, buf, COSINE_LINE_LENGTH);
225
                        return cur_off;
226
                }
227
        }
228
        return -1;
229
}
230
231
/* Look through the first part of a file to see if this is
232
 * a CoSine L2 debug output.
233
 *
234
 * Returns TRUE if it is, FALSE if it isn't or if we get an I/O error;
235
 * if we get an I/O error, "*err" will be set to a non-zero value and
236
 * "*err_info" will be set to null or an additional error string.
237
 */
238
static gboolean cosine_check_file_type(wtap *wth, int *err, gchar **err_info)
239
{
240
        char        buf[COSINE_LINE_LENGTH];
241
        gsize        reclen;
242
        guint        line;
243
244
        buf[COSINE_LINE_LENGTH-1] = '\0';
245
246
        for (line = 0; line < COSINE_HEADER_LINES_TO_CHECK; line++) {
247
                if (file_gets(buf, COSINE_LINE_LENGTH, wth->fh) == NULL) {
248
                        /* EOF or error. */
249
                        *err = file_error(wth->fh, err_info);
250
                        return FALSE;
251
                }
252
253
                reclen = strlen(buf);
254
                if (reclen < strlen(COSINE_HDR_MAGIC_STR1) ||
255
                        reclen < strlen(COSINE_HDR_MAGIC_STR2)) {
256
                        continue;
257
                }
258
259
                if (strstr(buf, COSINE_HDR_MAGIC_STR1) ||
260
                    strstr(buf, COSINE_HDR_MAGIC_STR2)) {
261
                        return TRUE;
262
                }
263
        }
264
        *err = 0;
265
        return FALSE;
266
}
267
268
269
int cosine_open(wtap *wth, int *err, gchar **err_info)
270
{
271
        /* Look for CoSine header */
272
        if (!cosine_check_file_type(wth, err, err_info)) {
273
                if (*err != 0 && *err != WTAP_ERR_SHORT_READ)
274
                        return -1;
275
                return 0;
276
        }
277
278
        if (file_seek(wth->fh, 0L, SEEK_SET, err) == -1)        /* rewind */
279
                return -1;
280
281
        wth->file_encap = WTAP_ENCAP_COSINE;
282
        wth->file_type = WTAP_FILE_COSINE;
283
        wth->snapshot_length = 0; /* not known */
284
        wth->subtype_read = cosine_read;
285
        wth->subtype_seek_read = cosine_seek_read;
286
        wth->tsprecision = WTAP_FILE_TSPREC_CSEC;
287
288
        return 1;
289
}
290
291
/* Find the next packet and parse it; called from wtap_read(). */
292
static gboolean cosine_read(wtap *wth, int *err, gchar **err_info,
293
    gint64 *data_offset)
294
{
295
        gint64        offset;
296
        int        pkt_len;
297
        char        line[COSINE_LINE_LENGTH];
298
299
        /* Find the next packet */
300
        offset = cosine_seek_next_packet(wth, err, err_info, line);
301
        if (offset < 0)
302
                return FALSE;
303
        *data_offset = offset;
304
305
        /* Parse the header */
306
        pkt_len = parse_cosine_rec_hdr(&wth->phdr, line, err, err_info);
307
        if (pkt_len == -1)
308
                return FALSE;
309
310
        /* Convert the ASCII hex dump to binary data */
311
        return parse_cosine_hex_dump(wth->fh, &wth->phdr, pkt_len,
312
            wth->frame_buffer, err, err_info);
313
}
314
315
/* Used to read packets in random-access fashion */
316
static gboolean
317
cosine_seek_read(wtap *wth, gint64 seek_off, struct wtap_pkthdr *phdr,
318
        Buffer *buf, int len _U_, int *err, gchar **err_info)
319
{
320
        int        pkt_len;
321
        char        line[COSINE_LINE_LENGTH];
322
323
        if (file_seek(wth->random_fh, seek_off, SEEK_SET, err) == -1)
324
                return FALSE;
325
326
        if (file_gets(line, COSINE_LINE_LENGTH, wth->random_fh) == NULL) {
327
                *err = file_error(wth->random_fh, err_info);
328
                if (*err == 0) {
329
                        *err = WTAP_ERR_SHORT_READ;
330
                }
331
                return FALSE;
332
        }
333
334
        /* Parse the header */
335
        pkt_len = parse_cosine_rec_hdr(phdr, line, err, err_info);
336
        if (pkt_len == -1)
337
                return FALSE;
338
339
        /* Convert the ASCII hex dump to binary data */
340
        return parse_cosine_hex_dump(wth->random_fh, phdr, pkt_len, buf, err,
341
            err_info);
342
}
343
344
/* Parses a packet record header. There are two possible formats:
345
    1) output to a control blade with date and time
346
        2002-5-10,20:1:31.4:  l2-tx (FR:3/7/1:1), Length:18, Pro:0, Off:0, Pri:0, RM:0, Err:0 [0x4000, 0x0]
347
    2) output to PE without date and time
348
        l2-tx (FR:3/7/1:1), Length:18, Pro:0, Off:0, Pri:0, RM:0, Err:0 [0x4000, 0x0] */
349
static int
350
parse_cosine_rec_hdr(struct wtap_pkthdr *phdr, const char *line,
351
     int *err, gchar **err_info)
352
{
353
        union wtap_pseudo_header *pseudo_header = &phdr->pseudo_header;
354
        int        num_items_scanned;
355
        int        yy, mm, dd, hr, min, sec, csec, pkt_len;
356
        int        pro, off, pri, rm, error;
357
        guint        code1, code2;
358
        char        if_name[COSINE_MAX_IF_NAME_LEN] = "", direction[6] = "";
359
        struct        tm tm;
360
361
        if (sscanf(line, "%4d-%2d-%2d,%2d:%2d:%2d.%9d:",
362
                   &yy, &mm, &dd, &hr, &min, &sec, &csec) == 7) {
363
                /* appears to be output to a control blade */
364
                num_items_scanned = sscanf(line,
365
                   "%4d-%2d-%2d,%2d:%2d:%2d.%9d: %5s (%127[A-Za-z0-9/:]), Length:%9d, Pro:%9d, Off:%9d, Pri:%9d, RM:%9d, Err:%9d [%8x, %8x]",
366
                        &yy, &mm, &dd, &hr, &min, &sec, &csec,
367
                                   direction, if_name, &pkt_len,
368
                                   &pro, &off, &pri, &rm, &error,
369
                                   &code1, &code2);
370
371
                if (num_items_scanned != 17) {
372
                        *err = WTAP_ERR_BAD_FILE;
373
                        *err_info = g_strdup("cosine: purported control blade line doesn't have code values");
374
                        return -1;
375
                }
376
        } else {
377
                /* appears to be output to PE */
378
                num_items_scanned = sscanf(line,
379
                   "%5s (%127[A-Za-z0-9/:]), Length:%9d, Pro:%9d, Off:%9d, Pri:%9d, RM:%9d, Err:%9d [%8x, %8x]",
380
                                   direction, if_name, &pkt_len,
381
                                   &pro, &off, &pri, &rm, &error,
382
                                   &code1, &code2);
383
384
                if (num_items_scanned != 10) {
385
                        *err = WTAP_ERR_BAD_FILE;
386
                        *err_info = g_strdup("cosine: header line is neither control blade nor PE output");
387
                        return -1;
388
                }
389
                yy = mm = dd = hr = min = sec = csec = 0;
390
        }
391
392
        phdr->presence_flags = WTAP_HAS_TS|WTAP_HAS_CAP_LEN;
393
        tm.tm_year = yy - 1900;
394
        tm.tm_mon = mm - 1;
395
        tm.tm_mday = dd;
396
        tm.tm_hour = hr;
397
        tm.tm_min = min;
398
        tm.tm_sec = sec;
399
        tm.tm_isdst = -1;
400
        phdr->ts.secs = mktime(&tm);
401
        phdr->ts.nsecs = csec * 10000000;
402
        phdr->len = pkt_len;
403
404
        /* XXX need to handle other encapsulations like Cisco HDLC,
405
           Frame Relay and ATM */
406
        if (strncmp(if_name, "TEST:", 5) == 0) {
407
                pseudo_header->cosine.encap = COSINE_ENCAP_TEST;
408
        } else if (strncmp(if_name, "PPoATM:", 7) == 0) {
409
                pseudo_header->cosine.encap = COSINE_ENCAP_PPoATM;
410
        } else if (strncmp(if_name, "PPoFR:", 6) == 0) {
411
                pseudo_header->cosine.encap = COSINE_ENCAP_PPoFR;
412
        } else if (strncmp(if_name, "ATM:", 4) == 0) {
413
                pseudo_header->cosine.encap = COSINE_ENCAP_ATM;
414
        } else if (strncmp(if_name, "FR:", 3) == 0) {
415
                pseudo_header->cosine.encap = COSINE_ENCAP_FR;
416
        } else if (strncmp(if_name, "HDLC:", 5) == 0) {
417
                pseudo_header->cosine.encap = COSINE_ENCAP_HDLC;
418
        } else if (strncmp(if_name, "PPP:", 4) == 0) {
419
                pseudo_header->cosine.encap = COSINE_ENCAP_PPP;
420
        } else if (strncmp(if_name, "ETH:", 4) == 0) {
421
                pseudo_header->cosine.encap = COSINE_ENCAP_ETH;
422
        } else {
423
                pseudo_header->cosine.encap = COSINE_ENCAP_UNKNOWN;
424
        }
425
        if (strncmp(direction, "l2-tx", 5) == 0) {
426
                pseudo_header->cosine.direction = COSINE_DIR_TX;
427
        } else if (strncmp(direction, "l2-rx", 5) == 0) {
428
                pseudo_header->cosine.direction = COSINE_DIR_RX;
429
        }
430
        g_strlcpy(pseudo_header->cosine.if_name, if_name,
431
                COSINE_MAX_IF_NAME_LEN);
432
        pseudo_header->cosine.pro = pro;
433
        pseudo_header->cosine.off = off;
434
        pseudo_header->cosine.pri = pri;
435
        pseudo_header->cosine.rm = rm;
436
        pseudo_header->cosine.err = error;
437
438
        return pkt_len;
439
}
440
441
/* Converts ASCII hex dump to binary data. Returns TRUE on success,
442
   FALSE if any error is encountered. */
443
static gboolean
444
parse_cosine_hex_dump(FILE_T fh, struct wtap_pkthdr *phdr, int pkt_len,
445
    Buffer* buf, int *err, gchar **err_info)
446
{
447
        guint8 *pd;
448
        gchar        line[COSINE_LINE_LENGTH];
449
        int        i, hex_lines, n, caplen = 0;
450
451
        /* Make sure we have enough room for the packet */
452
        buffer_assure_space(buf, COSINE_MAX_PACKET_LEN);
453
        pd = buffer_start_ptr(buf);
454
455
        /* Calculate the number of hex dump lines, each
456
         * containing 16 bytes of data */
457
        hex_lines = pkt_len / 16 + ((pkt_len % 16) ? 1 : 0);
458
459
        for (i = 0; i < hex_lines; i++) {
460
                if (file_gets(line, COSINE_LINE_LENGTH, fh) == NULL) {
461
                        *err = file_error(fh, err_info);
462
                        if (*err == 0) {
463
                                *err = WTAP_ERR_SHORT_READ;
464
                        }
465
                        return FALSE;
466
                }
467
                if (empty_line(line)) {
468
                        break;
469
                }
470
                if ((n = parse_single_hex_dump_line(line, pd, i*16)) == -1) {
471
                        *err = WTAP_ERR_BAD_FILE;
472
                        *err_info = g_strdup("cosine: hex dump line doesn't have 16 numbers");
473
                        return FALSE;
474
                }
475
                caplen += n;
476
        }
477
        phdr->caplen = caplen;
478
        return TRUE;
479
}
480
481
482
/* Take a string representing one line from a hex dump and converts
483
 * the text to binary data. We place the bytes in the buffer at the
484
 * specified offset.
485
 *
486
 * Returns number of bytes successfully read, -1 if bad.  */
487
static int
488
parse_single_hex_dump_line(char* rec, guint8 *buf, guint byte_offset)
489
{
490
        int num_items_scanned, i;
491
        unsigned int bytes[16];
492
493
        num_items_scanned = sscanf(rec, "%02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x",
494
                               &bytes[0], &bytes[1], &bytes[2], &bytes[3],
495
                               &bytes[4], &bytes[5], &bytes[6], &bytes[7],
496
                               &bytes[8], &bytes[9], &bytes[10], &bytes[11],
497
                               &bytes[12], &bytes[13], &bytes[14], &bytes[15]);
498
        if (num_items_scanned == 0)
499
                return -1;
500
501
        if (num_items_scanned > 16)
502
                num_items_scanned = 16;
503
504
        for (i=0; i<num_items_scanned; i++) {
505
                buf[byte_offset + i] = (guint8)bytes[i];
506
        }
507
508
        return num_items_scanned;
509
}