Skip to content

Instantly share code, notes, and snippets.

🌴
Vacation / GopherCon

Matt Layher mdlayher

🌴
Vacation / GopherCon
Block or report user

Report or block mdlayher

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@mdlayher
mdlayher / unixhttp.go
Created Jan 18, 2019
Using SO_PEERCRED on a UNIX socket connected over HTTP.
View unixhttp.go
package main
import (
"fmt"
"io"
"log"
"net"
"net/http"
"os/user"
"strconv"
View gist:7102a53ea445cbf7581e259b10ae25d0
U-Boot 2016.07-00036-g8b3fd4183a (Sep 28 2018 - 08:21:51 -0400)
DRAM: 240 MiB
WARNING: Caches not enabled
Flash: 32 MiB
Using default environment
In: serial
@mdlayher
mdlayher / main.rs
Created Sep 25, 2018
Rust FLAC parser experiment
View main.rs
extern crate byteorder;
use byteorder::{ByteOrder, BE};
use std::fs::File;
use std::io;
use std::io::prelude::*;
fn main() -> std::io::Result<()> {
let files: Vec<String> = std::env::args().skip(1).collect();
View attrenc.patch
diff --git a/attribute.go b/attribute.go
index be4a8d0..02cd016 100644
--- a/attribute.go
+++ b/attribute.go
@@ -300,10 +300,10 @@ func (ad *AttributeDecoder) Do(fn func(b []byte) error) {
// An AttributeEncoder provides a safe way to encode attributes.
//
// It is recommended to use an AttributeEncoder where possible instead of
-// calling MarshalBinary and using package nlenc directly.
+// calling MarshalAttributes and using package nlenc directly.
@mdlayher
mdlayher / gist:2079ac2ed8201f183c8de043c8882e14
Created Aug 6, 2018
go build -race + GOTRACEBACK=crash ./nlstress
View gist:2079ac2ed8201f183c8de043c8882e14
fatal error: schedule: holding locks
runtime stack:
runtime.throw(0x950cc3, 0x17)
/usr/local/go/src/runtime/panic.go:616 +0x81 fp=0x7f8bef7fdde8 sp=0x7f8bef7fddc8 pc=0x455761
runtime.schedule()
/usr/local/go/src/runtime/proc.go:2489 +0x391 fp=0x7f8bef7fde38 sp=0x7f8bef7fdde8 pc=0x45ccd1
runtime.park_m(0xc420001c80)
/usr/local/go/src/runtime/proc.go:2604 +0x81 fp=0x7f8bef7fde68 sp=0x7f8bef7fde38 pc=0x45ce41
runtime.mcall
@mdlayher
mdlayher / gist:a46edb0cb062a961431ebaad741b5b24
Created Aug 6, 2018
go build + GOTRACEBACK=crash ./nlstress
View gist:a46edb0cb062a961431ebaad741b5b24
fatal error: runtime·unlock: lock count
fatal error: runtime·unlock: lock count
fatal error: runtime·unlock: lock count
fatal error: runtime·unlock: lock count
fatal error: runtime·unlock: lock count
fatal error: runtime·unlock: lock count
fatal error: runtime·unlock: lock count
fatal error: runtime·unlock: lock count
fata
@mdlayher
mdlayher / decoder.go
Created Jul 25, 2018
netlink.AttributeDecoder usage.
View decoder.go
// parseDevice parses a Device from a generic netlink message.
func parseDevice(m genetlink.Message) (*wgtypes.Device, error) {
ad, err := netlink.NewAttributeDecoder(m.Data)
if err != nil {
return nil, err
}
var d wgtypes.Device
for ad.Next() {
switch ad.Type() {
@mdlayher
mdlayher / ip4checksumusage.go
Created Jul 24, 2018
Demonstration of IPv4 checksum creation when dealing with Ethernet frames, IPv4, and UDP in Go.
View ip4checksumusage.go
// ipv4Checksum computes the IPv4 header checksum for input IPv4 header bytes.
func ipv4Checksum(b []byte) (uint16, error) {
if l := len(b); l < ipv4.HeaderLen {
return 0, fmt.Errorf("not enough bytes to compute IPv4 header checksum: %d", l)
}
// Algorithm taken from: https://en.wikipedia.org/wiki/IPv4_header_checksum.
// "First calculate the sum of each 16 bit value within the header,
// skipping only the checksum field itself."
@mdlayher
mdlayher / ndprs.go
Created May 29, 2018
How to send an NDP router solicitation and wait for a router advertisement in Go.
View ndprs.go
// Build a router solicitation message, specifying our source link-layer
// address so the router does not have to ask it for it explicitly.
m := &ndp.RouterSolicitation{
Options: []ndp.Option{
&ndp.LinkLayerAddress{
Direction: ndp.Source,
Addr: ifi.HardwareAddr,
},
},
}
@mdlayher
mdlayher / ndpns.go
Created May 29, 2018
How to send an NDP neighbor solicitation and wait for a neighbor advertisement in Go.
View ndpns.go
// Choose a target with a known IPv6 link-local address.
target := net.ParseIP("fe80::1e1b:dff:feea:830f")
// Use target's solicited-node multicast address to request that the target
// respond with a neighbor advertisement.
snm, err := ndp.SolicitedNodeMulticast(target)
if err != nil {
log.Fatalf("failed to determine solicited-node multicast address: %v", err)
}
You can’t perform that action at this time.