I am writing small code for generating the ICMP packet. For that I am following the code from golang net package.
I identified the following code to use for ICMP packet generation:
109 c, err := Dial(tt.net, tt.raddr)
110 if err != nil {
111 t.Fatalf("Dial failed: %v", err)
112 }
113 c.SetDeadline(time.Now().Add(100 * time.Millisecond))
114 defer c.Close()
115
116 typ := icmpv4EchoRequest
117 if net == "ip6" {
118 typ = icmpv6EchoRequest
119 }
120 xid, xseq := os.Getpid()&0xffff, i+1
121 wb, err := (&icmpMessage{
122 Type: typ, Code: 0,
123 Body: &icmpEcho{
124 ID: xid, Seq: xseq,
125 Data: bytes.Repeat([]byte("Go Go Gadget Ping!!!"), 3),
126 },
127 }).Marshal()
128 if err != nil {
129 t.Fatalf("icmpMessage.Marshal failed: %v", err)
130 }
131 if _, err := c.Write(wb); err != nil {
132 t.Fatalf("Conn.Write failed: %v", err)
133 }
I am not able to understand followings in this code :
Marshal()
is not included in the net package documentation, please let me know how to find this function and why it is not included in the net package.please explain me line #121 (
icmpMessage
struct and function calling as these are not defined in this file).