Debian Codegraph @

framestream_dump/main.go

raw symbols SCIP
1 /*
2 * Copyright (c) 2014 by Farsight Security, Inc.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17 package main
18
19 import (
20 "fmt"
21 "log"
22 "os"
23
24 "github.com/farsightsec/golang-framestream"
25 )
26
27 func main() {
28 // Arguments.
29 if len(os.Args) != 2 {
30 fmt.Fprintf(os.Stderr, "Usage: %s <INPUT FILE>\n", os.Args[0])
31 fmt.Fprintf(os.Stderr, "Dumps a FrameStreams formatted input file.\n\n")
32 os.Exit(1)
33 }
34 fname := os.Args[1]
35
36 // Open the input file.
37 file, err := os.Open(fname)
38 if err != nil {
39 log.Fatal(err)
40 }
41
42 // Create the decoder.
43 fs, err := framestream.NewDecoder(file, nil)
44 if err != nil {
45 log.Fatal(err)
46 }
47
48 // Print the data frames.
49 for {
50 frame, err := fs.Decode()
51 if err == framestream.EOF {
52 break
53 }
54 if err != nil {
55 log.Fatal(err)
56 }
57 fmt.Printf("Data frame (%v bytes): %x\n", len(frame), frame)
58 }
59 }