Grabbing raw ICMP network data

In this subsection, you will learn how to use the syscall package to capture raw ICMP network data and syscall.SetsockoptInt() in order to set the options of a socket.

Keep in mind that sending raw ICMP data is much more difficult, as you will have to construct the raw network packets on your own. The name of the utility is syscallNet.go, and it will be shown in four parts.

The first part of syscallNet.go is as follows:

package main 
import ( 

The second segment of syscallNet.go contains the following Go code:

func main() { fd, err := syscall.Socket(syscall.AF_INET, syscall.SOCK_RAW, syscall.IPPROTO_ICMP) if err != nil { fmt.Println("Error in syscall.Socket:", err) return } f := os.NewFile(uintptr(fd), ...

Get Mastering Go - Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.