Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

IFF_PROMISC, IFF_BROADCAST missing from std.os.linux #21890

Closed
kj4tmp opened this issue Nov 3, 2024 · 3 comments
Closed

IFF_PROMISC, IFF_BROADCAST missing from std.os.linux #21890

kj4tmp opened this issue Nov 3, 2024 · 3 comments
Labels
contributor friendly This issue is limited in scope and/or knowledge of Zig internals. enhancement Solving this issue will likely involve adding new logic or components to the codebase. os-linux standard library This issue involves writing Zig code for the standard library.
Milestone

Comments

@kj4tmp
Copy link
Contributor

kj4tmp commented Nov 3, 2024

These are used when configuring low level network interfaces. More information can be found in man netdevice

Here is a use case of setting the promiscuous and broadcast flags on a network device.

(yes this is currently brutal):

var ifr: std.posix.ifreq = std.mem.zeroInit(std.posix.ifreq, .{});
@memcpy(ifr.ifrn.name[0..ifname.len], ifname);
ifr.ifrn.name[ifname.len] = 0;
try std.posix.ioctl_SIOCGIFINDEX(socket, &ifr);
const ifindex: i32 = ifr.ifru.ivalue;

var rval = std.posix.errno(std.os.linux.ioctl(socket, std.os.linux.SIOCGIFFLAGS, @intFromPtr(&ifr)));
switch (rval) {
    .SUCCESS => {},
    else => {
        return error.NicError;
    },
}
const IFF_PROMISC = 256;
const IFF_BROADCAST = 2;
ifr.ifru.flags = ifr.ifru.flags | IFF_BROADCAST | IFF_PROMISC;
rval = std.posix.errno(std.os.linux.ioctl(socket, std.os.linux.SIOCSIFFLAGS, @intFromPtr(&ifr)));
switch (rval) {
    .SUCCESS => {},
    else => {
        return error.NicError;
    },
}
@alexrp alexrp added standard library This issue involves writing Zig code for the standard library. enhancement Solving this issue will likely involve adding new logic or components to the codebase. os-linux labels Nov 3, 2024
@alexrp alexrp added this to the unplanned milestone Nov 3, 2024
@alexrp alexrp added the contributor friendly This issue is limited in scope and/or knowledge of Zig internals. label Nov 3, 2024
@bentheklutz
Copy link
Contributor

@kj4tmp
Copy link
Contributor Author

kj4tmp commented Nov 14, 2024

Thanks!!!

@kj4tmp kj4tmp closed this as completed Nov 14, 2024
@nektro
Copy link
Contributor

nektro commented Nov 14, 2024

fixed by #21958

@alexrp alexrp modified the milestones: unplanned, 0.14.0 Nov 15, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
contributor friendly This issue is limited in scope and/or knowledge of Zig internals. enhancement Solving this issue will likely involve adding new logic or components to the codebase. os-linux standard library This issue involves writing Zig code for the standard library.
Projects
None yet
Development

No branches or pull requests

4 participants