I have written the function FromBytes
which converts bytes to integer format and passes it to IP4()
based on endianness as follows:
type IP4 uint32
func FromBytes(ip []byte) IP4 {
var pi IP4
buf := bytes.NewReader(ip)
if <little endian>
err := binary.Read(buf, binary.LittleEndian, &pi)
else
err := binary.Read(buf, binary.BigEndian, &pi)
if err != nil {
fmt.Println("binary.Read failed:", err)
}
return IP4(pi)
}
I need help writing a function which will convert from integer to bytes:
func (ip IP4) Octets() (a, b, c, d byte) {
if <little endian>
// code to convert from integer to bytes for little endian
} else {
// code to convert from integer to bytes for big endian
}
return
}