我正在使用 gopacket/layers api 从数据包中提取 upd 数据,然后通过另一个 udp 流再次发送它,我不确定这样做是否正确,如果有人可以指出我也遇到了一些错误我的代码正确的方向
conn, err := net.Dial("udp", 1.1.1.1)
udp, _ := updpLayer.(*layers.UDP)
/*now if i send it like this*/
conn.Write(udp)
/*i get the errors: cannot use udp (type *layers.UDP) as type []byte in argument to conn.Write*/
/*I tried to convert to bytes using unsafe*/
con := *(*[unsafe.Sizeof(udp)]byte)(unsafe.Pointer(&udp))
/* I get cannot use conv (type [8]byte) as type []byte in argument to conn.Write */
/* I used ecoding/gob, but is it sending it as a byte stream?*/
encoder := gob.NewEncoder(conn)
encoder.Encode(udp) //or Encode(udp)