我正在使用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)