Skip to content

socket module does not have if_nametoindex method #870

Description

@Kotlinlife

Chaquopy version 14.0.2

Devices or emulators where the issue happens

Any device

Relevant parts of your code

import socket
socket.if_nametoindex()

Describe your issue

The contained exception was: module 'socket' has no attribute 'if_nametoindex'

Activity

  1. mhsmith commented on May 10, 2023

    @mhsmith
    Member

    The NDK's include/net/if.h indicates that the underlying libc function isn't available until API level 24:

    if __ANDROID_API__ >= 24
    struct if_nameindex* if_nameindex(void) __INTRODUCED_IN(24);
    void if_freenameindex(struct if_nameindex* __ptr) __INTRODUCED_IN(24);
    #endif /* __ANDROID_API__ >= 24 */

    Since we currently compile Python against API level 21, the socket.if_... functions won't be available. I'll add this to the documentation.

    What do you need this function for?

  2. changed the title [-]soket module does not have if_nametoindex method[/-] [+]socket module does not have if_nametoindex method[/+] on May 10, 2023
  3. Kotlinlife commented on May 12, 2023

    @Kotlinlife
    Author

    @mhsmith Thanks for answer. I need this functions to wrap some python protocol library(reticulum) in kotlin. How can I fix it?

  4. mhsmith commented on May 13, 2023

    @mhsmith
    Member

    That depends on how the library uses the function. You might be able to get away with a minimal implementation like this:

    import socket
    
    def if_nametoindex(if_name):
        raise OSError("not implemented")
    
    socket.if_nametoIndex = if_nametoindex

    Or if the library needs the function to return real information, perhaps you could implement it using ctypes to call the underlying libc function.

  5. added this to the 15.0 milestone on May 13, 2023
  6. mhsmith commented on May 13, 2023

    @mhsmith
    Member

    Adding to the next milestone because it's better for these functions to return OSError as documented, rather than AttributeError, which user code is unlikely to catch.

  7. Kotlinlife commented on May 14, 2023

    @Kotlinlife
    Author

    Thanks a lot!

  8. added a commit that references this issue on Feb 7, 2024
    3853ff6
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions