#define _GNU_SOURCE #include #include #include #include #include #include #include #include #include #include "k.h" K get_socket_interface(K handle) { // Check that the handle is of type int if (handle->t != -KI) { return krr("handle type"); } int sock = handle->i; char if_name[IFNAMSIZ] = {0}; socklen_t optlen = sizeof(if_name); // Get the network interface associated with the socket if (getsockopt(sock, SOL_SOCKET, SO_BINDTODEVICE, if_name, &optlen) == -1) { return krr(strerror(errno)); } // Return the network interface name return kp(if_name); }