allocSockaddrCan function
Allocate and populate a struct sockaddr_can for AF_CAN with the
supplied interface index.
Implementation
Pointer<Uint8> allocSockaddrCan(int ifIndex) {
final buf = calloc<Uint8>(kSockAddrCanSize);
// can_family (sa_family_t = 2 bytes) at offset 0.
buf[0] = kAfCan & 0xFF;
buf[1] = (kAfCan >> 8) & 0xFF;
// 2 bytes of padding to align can_ifindex on a 4-byte boundary.
// can_ifindex (int) at offset 4.
buf[4] = ifIndex & 0xFF;
buf[5] = (ifIndex >> 8) & 0xFF;
buf[6] = (ifIndex >> 16) & 0xFF;
buf[7] = (ifIndex >> 24) & 0xFF;
// The remaining 8 bytes hold the can_addr union — left as zero.
return buf;
}