Skip to content

proxystore_ex.connectors.dim.utils

Shared functions used by DIM stores.

get_ip_address

get_ip_address(ifname: str) -> str

Get ip address provided an interface name.

Warning

This function does not work on MacOS/Darwin.

Parameters:

  • ifname (str) –

    The interface name.

Returns:

  • str

    The IP address.

Source code in proxystore_ex/connectors/dim/utils.py
def get_ip_address(ifname: str) -> str:  # pragma: darwin no cover
    """Get ip address provided an interface name.

    Warning:
        This function does not work on MacOS/Darwin.

    Args:
        ifname: The interface name.

    Returns:
        The IP address.
    """
    s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
    return socket.inet_ntoa(
        fcntl.ioctl(
            s.fileno(),
            0x8915,
            struct.pack(
                '256s',
                bytes(ifname[:15], 'utf-8'),
            ),  # SIOCGIFADDR
        )[20:24],
    )