Skip to content

Instantly share code, notes, and snippets.

@grahamking grahamking/recv.go
Last active Aug 29, 2015

Embed
What would you like to do?
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
You can’t perform that action at this time.