A simple wrapper around libpcap for the Go programming language

PCAP

This is a simple wrapper around libpcap for Go. Originally written by Andreas Krennmair [email protected] and only minorly touched up by Mark Smith [email protected].

Please see the included pcaptest.go and tcpdump.go programs for instructions on how to use this library.

Miek Gieben [email protected] has created a more Go-like package and replaced functionality with standard functions from the standard library. The package has also been renamed to pcap.

Owner
Comments
  • Compilation Error

    Compilation Error

    Doing go get github.com/akrennmair/gopcap

    gives

    .gvm/pkgsets/go1.2.1/global/src/github.com/akrennmair/gopcap/pcap.go:12:18: fatal error: pcap.h: No such file or directory
     #include <pcap.h>
    
  • Make packet headers a specific interface.

    Make packet headers a specific interface.

    This is a slightly more involved change than the first few I've sent. It changes a packet's Headers from interface{} to a new Header interface. Currently, this interface just as a HeaderType() (enumerated in decode.go) and a Bytes() slice, which returns the bytes detected to be part of the header.

    This allows for a couple of nice things. First, it makes switching based on header type easy (switch pkt.HeaderType() {}). Also, it opens up the ability to do cursory parsing of certain header types without fully coding them. If, for example, there's a header X that doesn't affect the ending payload, we can decode and skip it without fully coding the decode() function. I'm planning to do this next with IPv6 extensions, basically a quick initial implementation that does nothing but pulls out Bytes() and HeaderType(), and leaves the rest of the decoding for a later time.

  • fixing tcpdump's Usage errorout feedback on invalid cmdline args

    fixing tcpdump's Usage errorout feedback on invalid cmdline args

    If you improperly call the tcpdump tool, no error feedback is written to stdout. There is a missing flush call on the errout writer.

    You will now get the friendly feedback: usage: ./tcpdump [ -i interface ] [ -s snaplen ] [ -X ] [ expression ]

  • pppoe decode packet

    pppoe decode packet

    hi can be add pppoe decode packet code? "code.google.com/p/gopacket/" see code is very difficult i can not understand because i need to thank you very much.

  • Fixed precision of timestmaps.

    Fixed precision of timestmaps.

    The C pcap library uses {sec,usec} for timestamps, where usec are microsconds. Go's time.Time have nanosecond precisions, so we need to convert between the two.

  • Speedcopy

    Speedcopy

    Speed up the copy of packet data from C into Go, using C.GoBytes. Also avoid a copy of the packet header struct. Together, this seems to reduce packet read speed by ~50%

    Added a benchmark binary for testing this change.

    Old: (/tmp/bench is tools/benchmark with the old code) [email protected]:/$ /tmp/bench -file /tmp/foo Took 3.334896s to process 1000000 packets, 3.334us per packet, 0 nil packets [email protected]:/$ /tmp/bench -file /tmp/foo Took 3.329675s to process 1000000 packets, 3.329us per packet, 0 nil packets

    New: (/tmp/bench2 is tools/benchmark with the new code) [email protected]:/$ /tmp/bench2 -file /tmp/foo Took 1.588695s to process 1000000 packets, 1.588us per packet, 0 nil packets [email protected]:/$ /tmp/bench2 -file /tmp/foo Took 1.580306s to process 1000000 packets, 1.58us per packet, 0 nil packets

    About a 50% reduction in the initial packet copy. This seemed to work pretty repeatably.

  • VLAN tagging (802.1Q) support

    VLAN tagging (802.1Q) support

    I've added some decoding for VLAN-tagged IPs. Note there's a couple of extraneous changes to io.go and pcap.go... these were done by 'go fmt', not by me.

  • Cleanups

    Cleanups

    Hello,

    These commits remove a lot of code from gopcap and use the standard library a lot more. Esp the use of the encoding/binary instead of all the put4/put2, asUint16, etc.

    I also seems to run somewhat faster. :)

  • Initial testing for decode library.

    Initial testing for decode library.

    This includes a simple test of packet.Decode, doing full testing against decoding a single IPv4 TCP packet. It also provides a second test specifically for a small TCP packet with ethernet padding, to make sure that change works correctly as well.

  • Change decodeIp to only consider use up to byte Length bytes.

    Change decodeIp to only consider use up to byte Length bytes.

    This solves the issue where Ethernet packets must be a minimum of 60 bytes, but can take up only 54 bytes on the wire if there's no payload added. Without this change, packets of that type may appear to be TCP packets with 6 null bytes in their payload.

    See http://forums.devshed.com/networking-help-109/tcp-protocol-mysterious-6-null-byte-payload-303357.html for more discussion on this.

  • Make gopcap goinstallable.

    Make gopcap goinstallable.

    The Makefile is ignored by goinstall. This small change allows users of the wrapper to use goinstall to easily install the wrapper. See http://golang.org/cmd/goinstall/ for more information.

  • problem of cross compile gopacket in mips

    problem of cross compile gopacket in mips

    I got a problem of cross compiling program based on gopacket : the env of go is--------> GOARCH="mips" GOBIN="" GOEXE="" GOHOSTARCH="amd64" GOHOSTOS="linux" GOOS="linux" GOPATH="/root/go" GORACE="" GOROOT="/usr/local/go" GOTOOLDIR="/usr/local/go/pkg/tool/linux_amd64" GCCGO="gccgo" CC="mips-linux-gcc" GOGCCFLAGS="-fPIC -mabi=32 -march=mips32 -pthread -fmessage-length=0" CXX="mips-linux-g++" CGO_ENABLED="1" CGO_CFLAGS="-I/usr/include" CGO_CPPFLAGS="" CGO_CXXFLAGS="-g -O2" CGO_FFLAGS="-g -O2" CGO_LDFLAGS="-L/root/Desktop/libpcap-1.9.0" PKG_CONFIG="pkg-config"

    the result of it is:

    runtime/cgo

    cc1: warnings being treated as errors In file included from gcc_libinit.c:8: /usr/include/pthread.h:675: Warning:‘regparm’ attribute directive ignored /usr/include/pthread.h:687: Warning:‘regparm’ attribute directive ignored /usr/include/pthread.h:732: Warning:‘regparm’ attribute directive ignored

    I change the include path to "-I/root/Desktop/libpcap-1.9.0" ,the result is: loading DWARF type: decoding dwarf section info at offset 0x157: unexpected opcode

    I have no idea about that.Can u help me?: )

  • Tests failure: identifier may conflict with identifiers generated by cgo

    Tests failure: identifier may conflict with identifiers generated by cgo

    With Go 1.12.5 on Fedora Rawhide x86_64, commit 00e11033259acb75598ba416495bb708d864a010:

    Testing    in: /builddir/build/BUILD/gopcap-00e11033259acb75598ba416495bb708d864a010/_build/src
             PATH: /builddir/build/BUILD/gopcap-00e11033259acb75598ba416495bb708d864a010/_build/bin:/builddir/.local/bin:/builddir/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/sbin
           GOPATH: /builddir/build/BUILD/gopcap-00e11033259acb75598ba416495bb708d864a010/_build:/usr/share/gocode
      GO111MODULE: off
          command: go test -buildmode pie -compiler gc -ldflags "-X github.com/akrennmair/gopcap/version=0 -X github.com/akrennmair/gopcap/version.commit=00e11033259acb75598ba416495bb708d864a010 -extldflags '-Wl,-z,relro -Wl,--as-needed  -Wl,-z,now -specs=/usr/lib/rpm/redhat/redhat-hardened-ld '"
          testing: github.com/akrennmair/gopcap
    github.com/akrennmair/gopcap
    # github.com/akrennmair/gopcap
    ./pcap.go:129:13: identifier "_Ctype_struct_pcap_stat" may conflict with identifiers generated by cgo
    ./pcap.go:142:10: identifier "_Ctype_struct_bpf_program" may conflict with identifiers generated by cgo
    ./pcap.go:216:34: identifier "_Ctype_struct_pcap_addr" may conflict with identifiers generated by cgo
    ./pcap.go:219:56: identifier "_Ctype_struct_pcap_addr" may conflict with identifiers generated by cgo
    FAIL	github.com/akrennmair/gopcap [build failed]
    
  • Relationship with google/gopacket

    Relationship with google/gopacket

    I noticed https://github.com/google/gopacket, which says it was forked off this repo. Are there any advantages of using this repo versus https://github.com/google/gopacket?

Related tags
Wrapper around bufcli to make it do cross-repo compiles for private repos and use full paths.
Wrapper around bufcli to make it do cross-repo compiles for private repos and use full paths.

Bufme A tool for compiling protos with full directory paths and cross repo compiles. Introduction Protocol buffers rock, but protoc should die in a fi

Feb 5, 2022
An unofficial GUI wrapper around the Tailscale CLI client.
An unofficial GUI wrapper around the Tailscale CLI client.

Trayscale Trayscale is an unofficial GUI wrapper around the Tailscale CLI client, particularly for use on Linux, as no official Linux GUI client exist

Dec 26, 2022
A simple abstraction around ssh and sftp libraries in Go(Golang).

sshx A simple abstraction around ssh and sftp libraries in Go(Golang). Resources Installation Installation Install sshx as you normally would for any

Dec 14, 2022
This is a tool that allows you to check minecraft names availability, this tool can do around 3000~ names a minute or more!

Checker This is a tool that allows you to check minecraft names availability, this tool can do around 3000~ names a minute or more! Tutorial To instal

Feb 13, 2022
A snapshot of Mess With DNS's backend code from around when it was released

Mess With DNS This is a snapshot of Mess With DNS's backend code from around whe

Nov 9, 2022
Orion - a small lightweight framework written around grpc/protobuf with the aim to shorten time to build microservices at Carousell.

Orion Orion is a small lightweight framework written around grpc/protobuf with the aim to shorten time to build microservices at Carousell. It is deri

Nov 16, 2022
BGP implemented in the Go Programming Language

GoBGP: BGP implementation in Go GoBGP is an open source BGP implementation designed from scratch for modern environment and implemented in a modern pr

Dec 31, 2022
Diameter stack and Base Protocol (RFC 6733) for the Go programming language

Diameter Base Protocol Package go-diameter is an implementation of the Diameter Base Protocol RFC 6733 and a stack for the Go programming language. St

Dec 28, 2022
SMPP 3.4 Protocol for the Go programming language

SMPP 3.4 This is an implementation of SMPP 3.4 for Go, based on the original smpp34 from Kevin Patel. The API has been refactored to idiomatic Go code

Dec 13, 2022
Basic LDAP v3 functionality for the GO programming language.

Basic LDAP v3 functionality for the GO programming language. Install For the latest version use: go get gopkg.in/ldap.v2 Import the latest version wi

May 24, 2022
Go-web-dev - Web Development With Google's Golang Programming Language Code Snippet and Exercises.

Web Development With Google's Golang Programming Language Code Snippet and Exercises This repository contains my code snippets, hands on exercises and

Jan 16, 2022
A simple wrapper for ssh to select profiles.
A simple wrapper for ssh to select profiles.

qSSH A simple wrapper for ssh to select profiles from your ~/.ssh/config file. Can be aliased to ssh Installation Download binary from Releases, or bu

Nov 9, 2021
SFTP client simple wrapper.
SFTP client simple wrapper.

Installation go get -u github.com/coolstina/sftpclient Example package main import ( "fmt" "log" "os" "github.com/coolstina/sftpclient" ) func

Nov 3, 2021
A protoc-gen-go wrapper including an RPC stub generator

// Copyright 2013 Google. All rights reserved. // // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE fi

Nov 17, 2022
go http wrapper for boomer

什么是 go-httpwrapper? 如果你想快速实现http协议的分布式压测,那么go-httpwrapper将会是一个不错的选择! Boomer 是Locust框架worker端的go实现,它很好地弥补了Locust使用Python实现而导致性能不佳的缺陷。 go-httpwrapper对Bo

May 5, 2022
A vote botting wrapper for GoLang designed for Minecraft: Pocket Servers.

libvote A vote botting wrapper for GoLang designed for Minecraft: Pocket Servers by Jviguy and JustTal. Disclaimer Usage of libvote requires your own

Apr 17, 2022
golang http server wrapper

Yong Simple Web Framework This project benchmarked gin-gonic. Installation Go command to install Yong. $ go get -u github.com/rladyd818/yong Import it

May 12, 2021
Go wrapper for gram-tgcalls.
Go wrapper for gram-tgcalls.

Go wrapper for gram-tgcalls. Features Doesn't let you worry about running Telegram clients, it starts an unlimited number of lightweight Gra

Dec 8, 2021