allocIfReq function
Allocate a properly-sized struct ifreq and copy name into the
ifr_name field. Caller frees with calloc.free.
Implementation
Pointer<Uint8> allocIfReq(String name) {
if (name.length >= kIfNameSize) {
throw ArgumentError.value(
name, 'name', 'interface name exceeds IFNAMSIZ-1 (${kIfNameSize - 1})',
);
}
final buf = calloc<Uint8>(kIfReqSize);
final bytes = name.codeUnits;
for (var i = 0; i < bytes.length; i++) {
buf[i] = bytes[i] & 0xFF;
}
// ifr_name is NUL-terminated by virtue of calloc's zero fill.
return buf;
}