Advertisement
yerden

Pcap to Go generator README

May 24th, 2022
192
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.37 KB | None | 0 0
  1. Overview
  2. ========
  3.  
  4. This small utility takes pcap file and generates go code with byte slices containing packet data.
  5.  
  6. Example: Command
  7. ```bash
  8. go run main.go -o gen.go -prefix somePackets -f /path/to/capture.pcap -package main
  9. ```
  10.  
  11. generates code in file `gen.go`:
  12. ```go
  13. package main
  14.  
  15. //
  16. // This file is generated automatically. DO NOT EDIT.
  17. // Generated on 2020-05-01 18:26:04.419441164 +0500 +05 m=+0.006958750
  18. //
  19. import "time"
  20. import "github.com/google/gopacket"
  21.  
  22. var somePackets = []struct {
  23. Data []byte
  24. gopacket.CaptureInfo
  25. }{
  26. //
  27. // Frame 1
  28. {
  29. []byte{
  30. //
  31. // Ethernet, off: 0, len: 14
  32. 0xF8, 0x6E, 0xEE, 0x8B, 0xA4, 0x26, 0x8C, 0x90,
  33. 0xD3, 0x1E, 0x65, 0x4C, 0x81, 0x00,
  34. //
  35. // Dot1Q, off: 14, len: 4
  36. 0x02, 0x59, 0x08, 0x00,
  37. //
  38. // IPv4, off: 18, len: 20
  39. 0x45, 0xC0, 0x00, 0xC2, 0x9D, 0x66, 0x00, 0x00,
  40. 0x3D, 0x11, 0x09, 0x36, 0x2E, 0xE3, 0xBD, 0x01,
  41. 0x2E, 0xE3, 0xBB, 0x07,
  42. //
  43. // UDP, off: 38, len: 8
  44. 0x08, 0x4B, 0x08, 0x4B, 0x00, 0xAE, 0x00, 0x00,
  45. //
  46. // ... other layers
  47. },
  48. gopacket.CaptureInfo{
  49. // 2019-06-07T21:07:39.420703+05:00
  50. Timestamp: time.Unix(1559923659, 420703000),
  51. CaptureLength: 95,
  52. Length: 95,
  53. },
  54. },
  55. //
  56. // Frame 2
  57. // ... other frames follow
  58. }
  59. ```
  60. You may then traverse resulting array, implement `gopacket.PacketDataSource` over it, etc.
  61.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement