Package raw enables reading and writing data at the device driver level for a network interface. MIT Licensed.

Related tags

Network raw
Overview

raw builds.sr.ht status GoDoc Go Report Card

Package raw enables reading and writing data at the device driver level for a network interface. MIT Licensed.

For more information about using raw sockets with Ethernet frames in Go, check out my blog post: Network Protocol Breakdown: Ethernet and Go.

Portions of this code are taken from the Go standard library. The Go standard library is Copyright (c) 2012 The Go Authors. All rights reserved. The Go license can be found at https://golang.org/LICENSE.

Stability

At this time, package raw is in a pre-v1.0.0 state. Changes are being made which may impact the exported API of this package and others in its ecosystem.

The general policy of this package is to only support the latest, stable version of Go. Compatibility shims may be added for prior versions of Go on an as-needed basis. If you would like to raise a concern, please file an issue.

If you depend on this package in your applications, please vendor it or use Go modules when building your application.

Comments
  • raw: potential regression after Go 1.12 runtime network poller integration

    raw: potential regression after Go 1.12 runtime network poller integration

    From a conversation in https://github.com/mdlayher/raw/pull/40.

    This commit broke router7’s dhcp4 client: rtr7/router7#25

    After a git revert f434146a17ecdf185e28b9ae8457ef45ee82077a, everything works as expected. At HEAD, dhcp4 gets one reply, then fails to ever send packets on the network interface, resulting in the > DHCP lease expiring.

    Haven’t investigated it any further, but perhaps this is sufficient to spot the mistake?

    /cc @hugelgupf @stapelberg

    bug 
    opened by mdlayher 11
  • Workaround deprecated functionality on OpenBSD.

    Workaround deprecated functionality on OpenBSD.

    Syscall BIOCSSEESENT as used in setBPFDirection is deprecated on OpenBSD. Some quick checking in CVS makes me wonder if it was ever supported. BIOCSDIRFILT however does work as intended.

    opened by arktos 6
  • BPF BSD Header Completion in raw_bsd.go

    BPF BSD Header Completion in raw_bsd.go

    Should the flag be 1 instead of 0? 1 will allow for MAC spoofing on the wire which i believe is what the comment is suggesting.

    Line 202 // Do not automatically complete source address in ethernet headers if err := syscall.SetBpfHeadercmpl(fd, 0); err != nil { return 0, err }

    0 flag sets automatic header completion per BPF man page (read interface address will be written in place of frame provided to BPF for outgoing transaction) BIOCSHDRCMPLT BIOCGHDRCMPLT (u_int) Set or get the status of the ``header complete'' flag. Set to zero if the link level source address should be filled in automatically by the interface output routine. Set to one if the link level source address will be written, as provided, to the wire. This flag is initialized to zero by default.

    opened by bpillatsch 5
  • ../../_go/src/github.com/mdlayher/raw/raw_linux.go:86:14: f.SyscallConn undefined (type *os.File has no field or method SyscallConn)

    ../../_go/src/github.com/mdlayher/raw/raw_linux.go:86:14: f.SyscallConn undefined (type *os.File has no field or method SyscallConn)

    $ go  get github.com/mdlayher/arp
    # github.com/mdlayher/raw
    ../../_go/src/github.com/mdlayher/raw/raw_linux.go:86:14: f.SyscallConn undefined (type *os.File has no field or method SyscallConn)
    

    I get this because I'm trying to build vip-manager, which apparently depends on github.com/mdlayher/arp which apparently depends on github.com/mdlayher/raw.

    Not being experienced with building go stuff I do not have a clue on how to fix this. The only thing I can google up is https://github.com/bettercap/bettercap/issues/468 which I'm unable to translate into a fix for not being able to go get github.com/mdlayher/raw.

    Any help is very appreciated.

    opened by tpo 4
  • Sending 802.11 WLAN Beacon frames

    Sending 802.11 WLAN Beacon frames

    Is it possible to send and receive beacon frames with this package? I'm hoping to implement very simple network-less wifi connectivity. Aiming to send and receive a custom frame containing a small amount of numerical information.

    On macOS, I can monitor beacon frames with:

    tcpdump "type mgt subtype beacon" -I -e -i en0
    
    opened by jpillora 4
  • raw ListenPacket can not get lldp(0x88cc) packages

    raw ListenPacket can not get lldp(0x88cc) packages

    hello, I listen packet use: conn, err := raw.ListenPacket(&ifi, uint16(lldp.EtherType), &raw.Config{}) when read package : n, addr, err := conn.ReadFrom(b)

    the lldp package can not be captured, but when change IPv4 and ARP, the packages can be captured.

    opened by GalenMa 3
  • build fails on debian jessie x86_64: undefined: unix.Errno

    build fails on debian jessie x86_64: undefined: unix.Errno

    Any suggestions?

    [email protected]:~# go get github.com/mdlayher/raw
    # github.com/mdlayher/raw
    /go/src/github.com/mdlayher/raw/raw_linux.go:317: undefined: unix.Errno
    /go/src/github.com/mdlayher/raw/raw_linux.go:330: undefined: unix.Errno
    [email protected]:/go/src/github.com/mdlayher/raw# uname -a
    Linux 31e07f454ad2 4.9.93-linuxkit-aufs #1 SMP Wed Jun 6 16:55:56 UTC 2018 x86_64 GNU/Linux
    [email protected]:/go/src/github.com/mdlayher/raw# cat /etc/*elease
    PRETTY_NAME="Debian GNU/Linux 8 (jessie)"
    NAME="Debian GNU/Linux"
    VERSION_ID="8"
    VERSION="8 (jessie)"
    ID=debian
    HOME_URL="http://www.debian.org/"
    SUPPORT_URL="http://www.debian.org/support"
    BUG_REPORT_URL="https://bugs.debian.org/"
    
    opened by atkinsj 3
  • Pointer variable used as pointer in raw.go

    Pointer variable used as pointer in raw.go

    While getting the library:

    go get github.com/mdlayher/raw

    github.com\mdlayher\raw\raw.go:136:37: cannot use *cfg (type Config) as type *Config in argument to listenPacket
    
    opened by JoseIgnacioTamayo 3
  • Add promisc

    Add promisc

    Add interface promisc to raw_bsd.go and raw_linux.go, include raw_others.go with 'not implemented' error. Expose SetPromisc(m int) method from raw.go, SetPromisc(m int) accepts integer similar to reference C implementation in BSD however it expects 1 for enable and 0 for disable, other values are not trapped.

    BSD implementation uses syscall.SetBpfPromisc, Linux implementation uses setsockopt.

    opened by bpillatsch 3
  • how to  capture lldp packets without promiscuous mode?

    how to capture lldp packets without promiscuous mode?

    @mdlayher hello expert, I have an question that how to capture lldp packets without promiscuous mode,I want use your code handle this, please help me ,thanks!

    opened by qinze118 2
  • Allow non-ethernet interfaces

    Allow non-ethernet interfaces

    This PR removes the strict length checking of the hardware address length, this is necessary to use other link types (for example, a tun0 interface from OpenVPN).

    opened by hdm 2
  • htons should depend on host endianness

    htons should depend on host endianness

    func htons should take host endianness into account:

    func htons(i uint16) uint16 {
    	return (i<<8)&0xff00 | i>>8
    }
    

    Depending on host endianness this should be a no-op or not.

    The issue was spotted when trying to use this lib on a device with a different endianness...

    opened by bhesmans 0
  • Error slice bounds out of range. Help!

    Error slice bounds out of range. Help!

    Hello, I encountered a problem during use in Macos, As follows:

    panic: runtime error: slice bounds out of range [:4098] with capacity 4096
    
    goroutine 886516 [running]:
    github.com/mdlayher/raw.(*packetConn).ReadFrom(0xc0061cd6e0, {0xc005833280, 0x80, 0x80})
        /github.com/mdlayher/raw/raw_bsd.go:163 +0x9e5
    github.com/mdlayher/raw.(*Conn).ReadFrom(0xc00462e278, {0xc005833280, 0x80, 0x80})
        /github.com/mdlayher/raw/raw.go:47 +0x99
    

    I searched the source code and found the problem here on raw_bsd.go:

    func (p *packetConn) ReadFrom(b []byte) (int, net.Addr, error) {
     ......
     
    	  // Skip past BPF header to retrieve ethernet frame
    	  out := copy(b, buf[bpfl:bpfl+n])
     ......
     }
    

    I carefully sorted out your logic. I think there's a small problem. Should it be:

      func (p *packetConn) ReadFrom(b []byte) (int, net.Addr, error) {
      .......
      
    	  // Skip past BPF header to retrieve ethernet frame
    	  out := copy(b, buf[bpfl:n])
      ......
      }
    

    I don't know if the understanding is correct. Please correct it. Thank you!

    opened by woguwo 0
  • use unix.Write to send packets to raw socket

    use unix.Write to send packets to raw socket

    Specifying a socketaddr is unnecessary when writing packets to a raw socket. According to packet(7) the supplied buffer should contain a physical-layer header. The sockaddr_ll is used for SOCK_DGRAM.

    SOCK_RAW packets are passed to and from the device driver without any changes in the packet data. When receiving a packet, the address is still parsed and passed in a standard sockaddr_ll address structure. When transmitting a packet, the user-supplied buffer should contain the physical-layer header. That packet is then queued unmodified to the network driver of the interface defined by the destination address.

    SOCK_DGRAM operates on a slightly higher level. The physical header is removed before the packet is passed to the user. Packets sent through a SOCK_DGRAM packet socket get a suitable physical-layer header based on the information in the sockaddr_ll destination address before they are queued.

    http://man7.org/linux/man-pages/man7/packet.7.html

    opened by pyther 0
  • add setMulticast function

    add setMulticast function

    This allows the interface to subscribe to a link-layer multicast address.

    I've written a small program to proxy eap packets from one interface to another. EAP (802.1x Auth) packets are sent to a link-layer multicast address. The Interface must either subscribe to the Multicast Address or be put in promisc mode. https://github.com/pyther/goeap_proxy/

    I wanted to put this out there as a starting point for discussion. Let me know what you think. Not sure if this is the best way to accomplish this? Maybe exposing SetSockoptPacketMreq to raw.conn is some capacity would allow for more flexibility?

    opened by pyther 1
Releases(v0.1.0)
  • v0.1.0(Feb 21, 2022)

    Please see https://github.com/mdlayher/raw#unmaintained. The recommended replacement package for Linux is https://github.com/mdlayher/packet, and a v1.0.0 stable release for that package has been tagged.

    Source code(tar.gz)
    Source code(zip)
Owner
Matt Layher
Software Engineer. Go, Linux, and open source software enthusiast. On and ever upward.
Matt Layher
Optimize Windows's network/NIC driver settings for NewTek's NDI(Network-Device-Interface).

windows-ndi-optimizer[WIP] Optimize Windows's network/NIC driver settings for NewTek's NDI(Network-Device-Interface). How it works This is batchfile d

Nil Hiiragi 3 Apr 15, 2022
Package ethernet implements marshaling and unmarshaling of IEEE 802.3 Ethernet II frames and IEEE 802.1Q VLAN tags. MIT Licensed.

ethernet Package ethernet implements marshaling and unmarshaling of IEEE 802.3 Ethernet II frames and IEEE 802.1Q VLAN tags. MIT Licensed. For more in

Matt Layher 246 Nov 9, 2022
Package arp implements the ARP protocol, as described in RFC 826. MIT Licensed.

arp Package arp implements the ARP protocol, as described in RFC 826. MIT Licensed. Portions of this code are taken from the Go standard library. The

Matt Layher 300 Nov 10, 2022
Package dhcp6 implements a DHCPv6 server, as described in RFC 3315. MIT Licensed.

dhcp6 Package dhcp6 implements a DHCPv6 server, as described in IETF RFC 3315. MIT Licensed. At this time, the API is not stable, and may change over

Matt Layher 76 Sep 27, 2022
The included device-simple example device service demonstrates basic usage of device-sdk-go

device-simple The included device-simple example device service demonstrates basic usage of device-sdk-go. Protocol Driver To make a functional Device

Khalid 0 Oct 9, 2021
CoreRAD is an extensible and observable IPv6 Neighbor Discovery Protocol router advertisement daemon. Apache 2.0 Licensed.

CoreRAD CoreRAD is an extensible and observable IPv6 Neighbor Discovery Protocol router advertisement daemon. Apache 2.0 Licensed. To get started with

Matt Layher 122 Nov 14, 2022
A simple project which enables you to check wheather the website is up

Website Status Checker A simple project which enables you to check wheather the website is up and working fine or is the website has been crashed. Abo

Sujay 2 Nov 8, 2021
DORY is a tool who enables people to recover their access to an Active Directory service, by changing, resetting or unlocking their account.

DORY - Server Expose a simple API to manipulate AD. Password reinitialization Password changer Account Unlocking You must have LDAPS (port 636) active

be ys 2 Oct 3, 2022
K8s_dns_chaos: enables inject DNS chaos in a Kubernetes cluster for Chaos Engineering

k8s_dns_chaos Name k8s_dns_chaos - enables inject DNS chaos in a Kubernetes cluster for Chaos Engineering. Description This plugin implements the Kube

邢凯 0 Dec 12, 2021
A LoRaWAN nodes' and network simulator that works with a real LoRaWAN environment (such as Chirpstack) and equipped with a web interface for real-time interaction.

LWN Simulator A LoRaWAN nodes' simulator to simulate a LoRaWAN Network. Table of Contents General Info Requirements Installation General Info LWN Simu

ARSLab 32 Nov 16, 2022
Forms814 - A website builder, useful for writing data collection webapps quickly.

forms814 A website builder, useful for writing data collection webapps quickly. Project Design The method in use here is to mix it with complicated fo

Bankole Ojo 1 Oct 25, 2022
Package for writing Nagios/Icinga/et cetera plugins in Go (golang)

nagiosplugin Package for writing Nagios/Icinga/et cetera plugins in Go (golang). Documentation See http://godoc.org/github.com/olorin/nagiosplugin. Us

Sharif Olorin 71 Aug 30, 2022
IRC bot for launch ddos attack, Mainly of scan target are IoT device that run linux and open default SSH port

IRC bot for launch ddos attack, Mainly of scan target are IoT device that run linux and open default SSH port

R4bin 3 Nov 10, 2021
Magma is an open-source software platform that gives network operators an open, flexible and extendable mobile core network solution.

Connecting the Next Billion People Magma is an open-source software platform that gives network operators an open, flexible and extendable mobile core

Magma 1.4k Nov 26, 2022
Zero Trust Network Communication Sentinel provides peer-to-peer, multi-protocol, automatic networking, cross-CDN and other features for network communication.

Thank you for your interest in ZASentinel ZASentinel helps organizations improve information security by providing a better and simpler way to protect

ZTALAB 8 Nov 1, 2022
gNXI Tools - gRPC Network Management/Operations Interface Tools

gNxI Tools gNMI - gRPC Network Management Interface gNOI - gRPC Network Operations Interface A collection of tools for Network Management that use the

Google 226 Nov 11, 2022
Dockin CNI - Dockin Container Network Interface

Dockin CNI - Dockin Container Network Interface

WeBankFinTech 29 Aug 12, 2022
Deskreen turns any device with a web browser into a secondary screen for your computer

Deskreen Website: https://deskreen.com ▶️ Deskreen Youtube channel (video tutorials, demos, use cases for Deskreen day to day usage) Deskreen turns an

Paul Pavlo Buidenkov 13.6k Nov 25, 2022
Go wrapper around Device Console Windows tool.

go-devcon Go wrapper around the Windows Device Console (devcon.exe). go install github.com/mikerourke/go-devcon Introduction Here's a brief overview

Mike Rourke 0 Nov 4, 2021