Skip to content

Get local IP address #209

@grill2010

Description

@grill2010

Is is somehow possible with this library to get the local IP address to which the socket is currently bound? E.g. I have following Android Java code which I need to translate to Swift

private static InetAddress getOutboundAddress(SocketAddress remoteAddress) {
        InetAddress localAddress = null;
        try {
            DatagramSocket sock = new DatagramSocket();
            // connect is needed to bind the socket and retrieve the local address later (it would return 0.0.0.0 otherwise)
            sock.connect(remoteAddress);
            localAddress = sock.getLocalAddress();

            sock.disconnect();
            sock.close();
        } catch (Exception e) {
            // ignore
        }

        return localAddress;
}

is there a way which is similar to localAddress = sock.getLocalAddress();?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions