Skip to content

Instantly share code, notes, and snippets.

@grahamking
Last active August 29, 2015 14:14
Show Gist options
  • Save grahamking/e154a6bc60507c99cdcf to your computer and use it in GitHub Desktop.
Save grahamking/e154a6bc60507c99cdcf to your computer and use it in GitHub Desktop.
ICMP raw receive
package main
import (
"fmt"
"os"
"syscall"
)
func main() {
fd, _ := syscall.Socket(syscall.AF_INET, syscall.SOCK_RAW, syscall.IPPROTO_ICMP)
f := os.NewFile(uintptr(fd), fmt.Sprintf("fd %d", fd))
for {
buf := make([]byte, 1024)
numRead, err := f.Read(buf)
if err != nil {
fmt.Println(err)
}
fmt.Printf("% X\n", buf[:numRead])
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment