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

Flags for SIOC{G,S}IFFLAGS #21958

Merged
merged 1 commit into from
Nov 13, 2024
Merged

Flags for SIOC{G,S}IFFLAGS #21958

merged 1 commit into from
Nov 13, 2024

Conversation

bentheklutz
Copy link
Contributor

@bentheklutz bentheklutz commented Nov 11, 2024

Adds a packed struct for SIOCGIFFLAGS and SIOCSIFFLAGS

Addresses #21890
Quick checked this with the following code.

const std = @import("std");

pub fn main() !void {
    const sock = try std.posix.socket(std.posix.AF.INET, std.posix.SOCK.STREAM, 0);
    const ifname = "wlp0s20f3";
    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(sock, &ifr);
    const rval = std.posix.errno(std.os.linux.ioctl(sock, std.os.linux.SIOCGIFFLAGS, @intFromPtr(&ifr)));
    if (rval != .SUCCESS) {
        return error.FlagsGetFailed;
    }

    std.debug.print("Flags set:\n", .{});

    if (ifr.ifru.flags.UP) {
        std.debug.print("UP\n", .{});
    }
    if (ifr.ifru.flags.BROADCAST) {
        std.debug.print("BROADCAST\n", .{});
    }
    if (ifr.ifru.flags.DEBUG) {
        std.debug.print("DEBUG\n", .{});
    }
    if (ifr.ifru.flags.LOOPBACK) {
        std.debug.print("LOOPBACK\n", .{});
    }
    if (ifr.ifru.flags.POINTOPOINT) {
        std.debug.print("POINTOPOINT\n", .{});
    }
    if (ifr.ifru.flags.NOTRAILERS) {
        std.debug.print("NOTRAILERS\n", .{});
    }
    if (ifr.ifru.flags.RUNNING) {
        std.debug.print("RUNNING\n", .{});
    }
    if (ifr.ifru.flags.NOARP) {
        std.debug.print("NOARP\n", .{});
    }
    if (ifr.ifru.flags.PROMISC) {
        std.debug.print("PROMISC\n", .{});
    }

    // requires elevated permissions to execute
    // ifr.ifru.flags.PROMISC = true;
    // ifr.ifru.flags.BROADCAST = true;

    // rval = std.posix.errno(std.os.linux.ioctl(sock, std.os.linux.SIOCSIFFLAGS, @intFromPtr(&ifr)));
    // switch (rval) {
    //     .SUCCESS => {},
    //     .PERM => return error.FailedPermissions,
    //     else => {},
    // }
}

@bentheklutz bentheklutz force-pushed the 21890-IFF branch 2 times, most recently from d8ebecd to 91a52ee Compare November 11, 2024 14:26
lib/std/os/linux.zig Outdated Show resolved Hide resolved
@bentheklutz bentheklutz force-pushed the 21890-IFF branch 3 times, most recently from ae587f2 to 5112488 Compare November 12, 2024 00:17
@bentheklutz
Copy link
Contributor Author

Should be actually good now. I didn't configure zig to use std from the compiler's source tree, so I was making changes in two places and not keeping them in sync.

lib/std/os/linux.zig Outdated Show resolved Hide resolved
@alexrp alexrp enabled auto-merge (rebase) November 13, 2024 04:36
@alexrp alexrp merged commit c59aee0 into ziglang:master Nov 13, 2024
10 checks passed
@bentheklutz bentheklutz deleted the 21890-IFF branch November 13, 2024 17:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants