Skip to content

apple: add missing SIOC ioctl constants#5263

Merged
tgross35 merged 1 commit into
rust-lang:mainfrom
yabanana:apple-sioc-ioctls
Jul 9, 2026
Merged

apple: add missing SIOC ioctl constants#5263
tgross35 merged 1 commit into
rust-lang:mainfrom
yabanana:apple-sioc-ioctls

Conversation

@yabanana

@yabanana yabanana commented Jul 8, 2026

Copy link
Copy Markdown
Contributor

Description

Add the socket and network interface ioctl constants from <sys/sockio.h> for Apple targets: everything public in the header except SIOCGIFADDR, which is already defined at the BSD level. SIOCSETVLAN and SIOCGETVLAN are aliases, as in the header.

sys/sockio.h is added to the libc-test headers so ctest checks the values.

Closes #3626

Sources

https://github.com/apple-oss-distributions/xnu/blob/f6217f891ac0bb64f3d375211650a4c1ff8ca1ea/bsd/sys/sockio.h

Checklist

  • Relevant tests in libc-test/semver have been updated
  • No placeholder or unstable values like *LAST or *MAX are
    included (see #3131)
  • Tested locally (cd libc-test && cargo test --target aarch64-apple-darwin)

@rustbot label +stable-nominated

@rustbot rustbot added S-waiting-on-review stable-nominated This PR should be considered for cherry-pick to libc's stable release branch labels Jul 8, 2026
Comment thread src/unix/bsd/apple/mod.rs Outdated
Comment on lines +2319 to +2389
pub const SIOCSHIWAT: c_ulong = 0x80047300;
pub const SIOCGHIWAT: c_ulong = 0x40047301;
pub const SIOCSLOWAT: c_ulong = 0x80047302;
pub const SIOCGLOWAT: c_ulong = 0x40047303;
pub const SIOCATMARK: c_ulong = 0x40047307;
pub const SIOCSPGRP: c_ulong = 0x80047308;
pub const SIOCGPGRP: c_ulong = 0x40047309;
pub const SIOCSIFADDR: c_ulong = 0x8020690c;
pub const SIOCSIFDSTADDR: c_ulong = 0x8020690e;
pub const SIOCSIFFLAGS: c_ulong = 0x80206910;
pub const SIOCGIFFLAGS: c_ulong = 0xc0206911;
pub const SIOCSIFBRDADDR: c_ulong = 0x80206913;
pub const SIOCSIFNETMASK: c_ulong = 0x80206916;
pub const SIOCGIFMETRIC: c_ulong = 0xc0206917;
pub const SIOCSIFMETRIC: c_ulong = 0x80206918;
pub const SIOCDIFADDR: c_ulong = 0x80206919;
pub const SIOCAIFADDR: c_ulong = 0x8040691a;
pub const SIOCGIFDSTADDR: c_ulong = 0xc0206922;
pub const SIOCGIFBRDADDR: c_ulong = 0xc0206923;
pub const SIOCGIFCONF: c_ulong = 0xc00c6924;
pub const SIOCGIFNETMASK: c_ulong = 0xc0206925;
pub const SIOCAUTOADDR: c_ulong = 0xc0206926;
pub const SIOCAUTONETMASK: c_ulong = 0x80206927;
pub const SIOCARPIPLL: c_ulong = 0xc0206928;
pub const SIOCADDMULTI: c_ulong = 0x80206931;
pub const SIOCDELMULTI: c_ulong = 0x80206932;
pub const SIOCGIFMTU: c_ulong = 0xc0206933;
pub const SIOCSIFMTU: c_ulong = 0x80206934;
pub const SIOCGIFPHYS: c_ulong = 0xc0206935;
pub const SIOCSIFPHYS: c_ulong = 0x80206936;
pub const SIOCSIFMEDIA: c_ulong = 0xc0206937;
pub const SIOCGIFMEDIA: c_ulong = 0xc02c6938;
pub const SIOCSIFGENERIC: c_ulong = 0x80206939;
pub const SIOCGIFGENERIC: c_ulong = 0xc020693a;
pub const SIOCRSLVMULTI: c_ulong = 0xc010693b;
pub const SIOCSIFLLADDR: c_ulong = 0x8020693c;
pub const SIOCGIFSTATUS: c_ulong = 0xc331693d;
pub const SIOCSIFPHYADDR: c_ulong = 0x8040693e;
pub const SIOCGIFPSRCADDR: c_ulong = 0xc020693f;
pub const SIOCGIFPDSTADDR: c_ulong = 0xc0206940;
pub const SIOCDIFPHYADDR: c_ulong = 0x80206941;
pub const SIOCGIFDEVMTU: c_ulong = 0xc0206944;
pub const SIOCSIFALTMTU: c_ulong = 0x80206945;
pub const SIOCGIFALTMTU: c_ulong = 0xc0206948;
pub const SIOCSIFBOND: c_ulong = 0x80206946;
pub const SIOCGIFBOND: c_ulong = 0xc0206947;
pub const SIOCGIFXMEDIA: c_ulong = 0xc02c6948;
pub const SIOCSIFCAP: c_ulong = 0x8020695a;
pub const SIOCGIFCAP: c_ulong = 0xc020695b;
pub const SIOCSIFMANAGEMENT: c_ulong = 0xc020695c;
pub const SIOCIFCREATE: c_ulong = 0xc0206978;
pub const SIOCIFDESTROY: c_ulong = 0x80206979;
pub const SIOCIFCREATE2: c_ulong = 0xc020697a;
pub const SIOCSDRVSPEC: c_ulong = 0x8028697b;
pub const SIOCGDRVSPEC: c_ulong = 0xc028697b;
pub const SIOCSIFVLAN: c_ulong = 0x8020697e;
pub const SIOCGIFVLAN: c_ulong = 0xc020697f;
pub const SIOCSETVLAN: c_ulong = SIOCSIFVLAN;
pub const SIOCGETVLAN: c_ulong = SIOCGIFVLAN;
pub const SIOCIFGCLONERS: c_ulong = 0xc0106981;
pub const SIOCGIFASYNCMAP: c_ulong = 0xc020697c;
pub const SIOCSIFASYNCMAP: c_ulong = 0x8020697d;
pub const SIOCGIFMAC: c_ulong = 0xc0206982;
pub const SIOCSIFMAC: c_ulong = 0x80206983;
pub const SIOCSIFKPI: c_ulong = 0x80206986;
pub const SIOCGIFKPI: c_ulong = 0xc0206987;
pub const SIOCGIFWAKEFLAGS: c_ulong = 0xc0206988;
pub const SIOCGIFFUNCTIONALTYPE: c_ulong = 0xc02069ad;
pub const SIOCSIF6LOWPAN: c_ulong = 0x802069c4;
pub const SIOCGIF6LOWPAN: c_ulong = 0xc02069c5;
pub const SIOCGIFDIRECTLINK: c_ulong = 0xc02069de;

@tgross35 tgross35 Jul 9, 2026

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We're trying to nudge anything completely new to the more organized new module. Would you be able to put this in a new file under src/new/apple/xnu/sys?

View changes since the review

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(Maybe it'd be helpful that there's CI gate or something else to enforce it 🤔)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done, moved to src/new/apple/xnu/sys/sockio.rs.

@rustbot

rustbot commented Jul 9, 2026

Copy link
Copy Markdown
Collaborator

Reminder, once the PR becomes ready for a review, use @rustbot ready.

@yabanana

yabanana commented Jul 9, 2026

Copy link
Copy Markdown
Contributor Author

@rustbot ready

Comment thread src/new/apple/xnu/sys/sockio.rs Outdated
Comment on lines +7 to +77
pub const SIOCSHIWAT: c_ulong = 0x80047300;
pub const SIOCGHIWAT: c_ulong = 0x40047301;
pub const SIOCSLOWAT: c_ulong = 0x80047302;
pub const SIOCGLOWAT: c_ulong = 0x40047303;
pub const SIOCATMARK: c_ulong = 0x40047307;
pub const SIOCSPGRP: c_ulong = 0x80047308;
pub const SIOCGPGRP: c_ulong = 0x40047309;
pub const SIOCSIFADDR: c_ulong = 0x8020690c;
pub const SIOCSIFDSTADDR: c_ulong = 0x8020690e;
pub const SIOCSIFFLAGS: c_ulong = 0x80206910;
pub const SIOCGIFFLAGS: c_ulong = 0xc0206911;
pub const SIOCSIFBRDADDR: c_ulong = 0x80206913;
pub const SIOCSIFNETMASK: c_ulong = 0x80206916;
pub const SIOCGIFMETRIC: c_ulong = 0xc0206917;
pub const SIOCSIFMETRIC: c_ulong = 0x80206918;
pub const SIOCDIFADDR: c_ulong = 0x80206919;
pub const SIOCAIFADDR: c_ulong = 0x8040691a;
pub const SIOCGIFDSTADDR: c_ulong = 0xc0206922;
pub const SIOCGIFBRDADDR: c_ulong = 0xc0206923;
pub const SIOCGIFCONF: c_ulong = 0xc00c6924;
pub const SIOCGIFNETMASK: c_ulong = 0xc0206925;
pub const SIOCAUTOADDR: c_ulong = 0xc0206926;
pub const SIOCAUTONETMASK: c_ulong = 0x80206927;
pub const SIOCARPIPLL: c_ulong = 0xc0206928;
pub const SIOCADDMULTI: c_ulong = 0x80206931;
pub const SIOCDELMULTI: c_ulong = 0x80206932;
pub const SIOCGIFMTU: c_ulong = 0xc0206933;
pub const SIOCSIFMTU: c_ulong = 0x80206934;
pub const SIOCGIFPHYS: c_ulong = 0xc0206935;
pub const SIOCSIFPHYS: c_ulong = 0x80206936;
pub const SIOCSIFMEDIA: c_ulong = 0xc0206937;
pub const SIOCGIFMEDIA: c_ulong = 0xc02c6938;
pub const SIOCSIFGENERIC: c_ulong = 0x80206939;
pub const SIOCGIFGENERIC: c_ulong = 0xc020693a;
pub const SIOCRSLVMULTI: c_ulong = 0xc010693b;
pub const SIOCSIFLLADDR: c_ulong = 0x8020693c;
pub const SIOCGIFSTATUS: c_ulong = 0xc331693d;
pub const SIOCSIFPHYADDR: c_ulong = 0x8040693e;
pub const SIOCGIFPSRCADDR: c_ulong = 0xc020693f;
pub const SIOCGIFPDSTADDR: c_ulong = 0xc0206940;
pub const SIOCDIFPHYADDR: c_ulong = 0x80206941;
pub const SIOCGIFDEVMTU: c_ulong = 0xc0206944;
pub const SIOCSIFALTMTU: c_ulong = 0x80206945;
pub const SIOCGIFALTMTU: c_ulong = 0xc0206948;
pub const SIOCSIFBOND: c_ulong = 0x80206946;
pub const SIOCGIFBOND: c_ulong = 0xc0206947;
pub const SIOCGIFXMEDIA: c_ulong = 0xc02c6948;
pub const SIOCSIFCAP: c_ulong = 0x8020695a;
pub const SIOCGIFCAP: c_ulong = 0xc020695b;
pub const SIOCSIFMANAGEMENT: c_ulong = 0xc020695c;
pub const SIOCIFCREATE: c_ulong = 0xc0206978;
pub const SIOCIFDESTROY: c_ulong = 0x80206979;
pub const SIOCIFCREATE2: c_ulong = 0xc020697a;
pub const SIOCSDRVSPEC: c_ulong = 0x8028697b;
pub const SIOCGDRVSPEC: c_ulong = 0xc028697b;
pub const SIOCSIFVLAN: c_ulong = 0x8020697e;
pub const SIOCGIFVLAN: c_ulong = 0xc020697f;
pub const SIOCSETVLAN: c_ulong = SIOCSIFVLAN;
pub const SIOCGETVLAN: c_ulong = SIOCGIFVLAN;
pub const SIOCIFGCLONERS: c_ulong = 0xc0106981;
pub const SIOCGIFASYNCMAP: c_ulong = 0xc020697c;
pub const SIOCSIFASYNCMAP: c_ulong = 0x8020697d;
pub const SIOCGIFMAC: c_ulong = 0xc0206982;
pub const SIOCSIFMAC: c_ulong = 0x80206983;
pub const SIOCSIFKPI: c_ulong = 0x80206986;
pub const SIOCGIFKPI: c_ulong = 0xc0206987;
pub const SIOCGIFWAKEFLAGS: c_ulong = 0xc0206988;
pub const SIOCGIFFUNCTIONALTYPE: c_ulong = 0xc02069ad;
pub const SIOCSIF6LOWPAN: c_ulong = 0x802069c4;
pub const SIOCGIF6LOWPAN: c_ulong = 0xc02069c5;
pub const SIOCGIFDIRECTLINK: c_ulong = 0xc02069de;

@tgross35 tgross35 Jul 9, 2026

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry but just realized these are ioctl constants, we should avoid hardcoding them since they differ across platforms. I added the _IO* functions just now to https://github.com/rust-lang/libc/blob/f24764dc460a26c90b2d967fcffb7b341f8393f3/src/new/apple/xnu/sys/ioccom.rs, would you be able to use those?

Please squash when done then I think this should be all set.

View changes since the review

@yabanana yabanana Jul 9, 2026

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rebased on main and switched to the _IO* functions. For the structs that aren't in libc yet (ifaliasreq, ifmediareq, ...) I went with raw _IOC and the size, same as TIOCPTYGNAME in ttycom.rs. Squashed into a single commit.

Add the socket and network interface ioctls from <sys/sockio.h> that
were not yet exposed (SIOCGIFADDR is already defined at the BSD level).

Link: https://github.com/apple-oss-distributions/xnu/blob/f6217f891ac0bb64f3d375211650a4c1ff8ca1ea/bsd/sys/sockio.h
@yabanana
yabanana force-pushed the apple-sioc-ioctls branch from 459d0a9 to d186129 Compare July 9, 2026 11:01
@yabanana

yabanana commented Jul 9, 2026

Copy link
Copy Markdown
Contributor Author

@rustbot ready

@rustbot

rustbot commented Jul 9, 2026

Copy link
Copy Markdown
Collaborator

This PR was rebased onto a different main commit. Here's a range-diff highlighting what actually changed.

Rebasing is a normal part of keeping PRs up to date, so no action is needed—this note is just to help reviewers.

@tgross35 tgross35 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great, thank you!

View changes since this review

@tgross35
tgross35 added this pull request to the merge queue Jul 9, 2026
Merged via the queue into rust-lang:main with commit 8ed7e2d Jul 9, 2026
57 checks passed
tgross35 pushed a commit to tgross35/rust-libc that referenced this pull request Jul 20, 2026
Add the socket and network interface ioctls from <sys/sockio.h> that
were not yet exposed (SIOCGIFADDR is already defined at the BSD level).

Link: https://github.com/apple-oss-distributions/xnu/blob/f6217f891ac0bb64f3d375211650a4c1ff8ca1ea/bsd/sys/sockio.h

(backport <rust-lang#5263>)
(cherry picked from commit 8ed7e2d)
tgross35 pushed a commit to tgross35/rust-libc that referenced this pull request Jul 20, 2026
Add the socket and network interface ioctls from <sys/sockio.h> that
were not yet exposed (SIOCGIFADDR is already defined at the BSD level).

Link: https://github.com/apple-oss-distributions/xnu/blob/f6217f891ac0bb64f3d375211650a4c1ff8ca1ea/bsd/sys/sockio.h

(backport <rust-lang#5263>)
(cherry picked from commit 8ed7e2d)
This was referenced Jul 20, 2026
tgross35 pushed a commit to tgross35/rust-libc that referenced this pull request Jul 20, 2026
Add the socket and network interface ioctls from <sys/sockio.h> that
were not yet exposed (SIOCGIFADDR is already defined at the BSD level).

Link: https://github.com/apple-oss-distributions/xnu/blob/f6217f891ac0bb64f3d375211650a4c1ff8ca1ea/bsd/sys/sockio.h

(backport <rust-lang#5263>)
(cherry picked from commit 8ed7e2d)
@tgross35 tgross35 added stable-applied This PR has been cherry-picked to libc's stable release branch and removed stable-nominated This PR should be considered for cherry-pick to libc's stable release branch labels Jul 21, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

stable-applied This PR has been cherry-picked to libc's stable release branch

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Missing SIOC ioctl constants on MacOS

4 participants