Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Save more on your purchases! discount-offer-chevron-icon
Savings automatically calculated. No voucher code required.
Arrow left icon
All Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Newsletter Hub
Free Learning
Arrow right icon
timer SALE ENDS IN
0 Days
:
00 Hours
:
00 Minutes
:
00 Seconds
Arrow up icon
GO TO TOP
Security with Go

You're reading from   Security with Go Explore the power of Golang to secure host, web, and cloud services

Arrow left icon
Product type Paperback
Published in Jan 2018
Publisher Packt
ISBN-13 9781788627917
Length 340 pages
Edition 1st Edition
Languages
Arrow right icon
Authors (2):
Arrow left icon
John Daniel Leon John Daniel Leon
Author Profile Icon John Daniel Leon
John Daniel Leon
 Gaekwad Gaekwad
Author Profile Icon Gaekwad
Gaekwad
Arrow right icon
View More author details
Toc

Table of Contents (21) Chapters Close

Title Page
Copyright and Credits
Packt Upsell
Contributors
Preface
1. Introduction to Security with Go FREE CHAPTER 2. The Go Programming Language 3. Working with Files 4. Forensics 5. Packet Capturing and Injection 6. Cryptography 7. Secure Shell (SSH) 8. Brute Force 9. Web Applications 10. Web Scraping 11. Host Discovery and Enumeration 12. Social Engineering 13. Post Exploitation 14. Conclusions 1. Another Book You May Enjoy Index

Decoding packets faster


If we know what layers to expect, we can use existing structures to store the packet information instead of creating new structs for every packet that takes time and memory. It is faster to use DecodingLayerParser. It is like marshaling and unmarshaling data.

This example demonstrates how to create layer variables at the beginning of the program and reuse the same variables over and over instead of creating new ones for each packet. A parser is created with gopacket.NewDecodingLayerParser(), which we provide with the layer variables we want to use. One caveat here is that it will only decode the layer types that you created initially.

The following is the code implementation of this example:

package main

import (
   "fmt"
   "github.com/google/gopacket"
   "github.com/google/gopacket/layers"
   "github.com/google/gopacket/pcap"
   "log"
   "time"
)

var (
   device            = "eth0"
   snapshotLen int32 = 1024
   promiscuous       = false
   err         error
   timeout...
lock icon The rest of the chapter is locked
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at £13.99/month. Cancel anytime
Visually different images