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

Implement socket.if_{nametoindex,indextoname} for Windows #81188

Closed
dtantsur mannequin opened this issue May 22, 2019 · 8 comments
Closed

Implement socket.if_{nametoindex,indextoname} for Windows #81188

dtantsur mannequin opened this issue May 22, 2019 · 8 comments
Labels
3.8 (EOL) end of life OS-windows type-feature A feature request or enhancement

Comments

@dtantsur
Copy link
Mannequin

dtantsur mannequin commented May 22, 2019

BPO 37007
Nosy @pfmoore, @tjguk, @dtantsur, @zware, @zooba, @ZackerySpytz
PRs
  • bpo-37007: Implement socket.if_nametoindex() and socket.if_indextoname() on Windows #13522
  • Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

    Show more details

    GitHub fields:

    assignee = None
    closed_at = <Date 2019-05-29.21:58:45.671>
    created_at = <Date 2019-05-22.11:01:24.930>
    labels = ['type-feature', '3.8', 'OS-windows']
    title = 'Implement socket.if_{nametoindex,indextoname} for Windows'
    updated_at = <Date 2019-05-29.21:58:45.671>
    user = 'https://github.com/dtantsur'

    bugs.python.org fields:

    activity = <Date 2019-05-29.21:58:45.671>
    actor = 'steve.dower'
    assignee = 'none'
    closed = True
    closed_date = <Date 2019-05-29.21:58:45.671>
    closer = 'steve.dower'
    components = ['Windows']
    creation = <Date 2019-05-22.11:01:24.930>
    creator = 'dtantsur'
    dependencies = []
    files = []
    hgrepos = []
    issue_num = 37007
    keywords = ['patch']
    message_count = 8.0
    messages = ['343171', '343285', '343303', '343347', '343892', '343900', '343913', '343925']
    nosy_count = 6.0
    nosy_names = ['paul.moore', 'tim.golden', 'dtantsur', 'zach.ware', 'steve.dower', 'ZackerySpytz']
    pr_nums = ['13522']
    priority = 'normal'
    resolution = 'fixed'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = 'enhancement'
    url = 'https://bugs.python.org/issue37007'
    versions = ['Python 3.8']

    @dtantsur
    Copy link
    Mannequin Author

    dtantsur mannequin commented May 22, 2019

    These two calls are currently Unix-only in the socket module. However, Windows supports them starting with Vista:
    https://docs.microsoft.com/en-us/windows/desktop/api/netioapi/nf-netioapi-if_indextoname
    https://docs.microsoft.com/en-us/windows/desktop/api/netioapi/nf-netioapi-if_nametoindex

    I checked with ctypes and they do seem to work. Unfortunately, if_nameindex is not implemented.

    @dtantsur dtantsur mannequin added stdlib Python modules in the Lib dir 3.8 (EOL) end of life type-feature A feature request or enhancement labels May 22, 2019
    @matrixise matrixise added OS-windows and removed stdlib Python modules in the Lib dir labels May 23, 2019
    @ZackerySpytz
    Copy link
    Mannequin

    ZackerySpytz mannequin commented May 23, 2019

    I've created a PR for this issue. Few changes are needed to implement these functions on Windows.

    @zooba
    Copy link
    Member

    zooba commented May 23, 2019

    Is it worth also implementing if_nameindex() using (I assume) GetIfTable2Ex 1? Or maybe just the simpler GetIfTable is sufficient - I'm not sure exactly what semantics Unix if_nameindex() has, whether it includes all logical adapters.

    @dtantsur
    Copy link
    Mannequin Author

    dtantsur mannequin commented May 24, 2019

    That would be fantastic, but I did not dare asking for it :)

    This is how the output of if_nameindex looks on my Fedora 29:

    [(1, 'lo'), (2, 'enp0s31f6'), (3, 'wlp4s0'), (4, 'virbr0'), (5, 'virbr0-nic'), (12, 'tun0')]

    It includes the loopback, two real adapters (ethernet and wifi) and devices apparently created by libvirt.

    This is how it looks on my OpenStack testing environment:

    [(1, 'lo'), (2, 'eth0'), (3, 'virbr0'), (4, 'virbr0-nic'), (5, 'ovs-system'), (6, 'br-int'), (7, 'br-ex'), (8, 'brbm'), (9, 'br-tun'), (14, 'ovs-node-0i1'), (15, 'tap-node-0i1'), (16, 'ovs-node-0i2'), (17, 'tap-node-0i2'), (18, 'ovs-node-1i1'), (19, 'tap-node-1i1'), (20, 'ovs-node-1i2'), (21, 'tap-node-1i2'), (22, 'ovs-node-2i1'), (23, 'tap-node-2i1'), (24, 'ovs-node-2i2'), (25, 'tap-node-2i2'), (26, 'ovs-tap'), (27, 'brbm-tap'), (34, 'br-inspector'), (35, 'brbm-inspector'), (55, 'macvtap2'), (56, 'macvtap3'), (79, 'macvtap0'), (80, 'macvtap1')]

    It seems to actually include everything.

    @ZackerySpytz
    Copy link
    Mannequin

    ZackerySpytz mannequin commented May 29, 2019

    Well, it turns out that implementing if_nameindex() on Windows using GetIfTable2Ex() was also quite simple. I've updated the PR.

    @zooba
    Copy link
    Member

    zooba commented May 29, 2019

    Great, thanks Zackery! (And thanks for the ping - I don't notice GitHub notifications.)

    Had a few comments about error handling, but it looks great.

    @ZackerySpytz
    Copy link
    Mannequin

    ZackerySpytz mannequin commented May 29, 2019

    Thanks, Steve. I've addressed your comments on the PR.

    @zooba
    Copy link
    Member

    zooba commented May 29, 2019

    New changeset 8f96c9f by Steve Dower (Zackery Spytz) in branch 'master':
    bpo-37007: Implement socket.if_nametoindex(), if_indextoname() and if_nameindex() on Windows (GH-13522)
    8f96c9f

    @zooba zooba closed this as completed May 29, 2019
    @ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Labels
    3.8 (EOL) end of life OS-windows type-feature A feature request or enhancement
    Projects
    None yet
    Development

    No branches or pull requests

    2 participants