Loading libnetutils/dhcptool.c +5 −2 Original line number Diff line number Diff line Loading @@ -14,6 +14,7 @@ * limitations under the License. */ #include <err.h> #include <errno.h> #include <error.h> #include <stdbool.h> Loading @@ -29,12 +30,14 @@ int main(int argc, char* argv[]) { char* interface = argv[1]; if (ifc_init()) { error(EXIT_FAILURE, errno, "dhcptool %s: ifc_init failed", interface); err(errno, "dhcptool %s: ifc_init failed", interface); ifc_close(); return EXIT_FAILURE; } int rc = do_dhcp(interface); if (rc) { error(0, errno, "dhcptool %s: do_dhcp failed", interface); err(errno, "dhcptool %s: do_dhcp failed", interface); } ifc_close(); Loading libnetutils/ifc_utils.c +9 −0 Original line number Diff line number Diff line Loading @@ -19,6 +19,7 @@ #include <unistd.h> #include <string.h> #include <errno.h> #include <pthread.h> #include <sys/socket.h> #include <sys/select.h> Loading Loading @@ -57,6 +58,8 @@ static int ifc_ctl_sock = -1; static int ifc_ctl_sock6 = -1; static pthread_mutex_t ifc_sock_mutex = PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP; static pthread_mutex_t ifc_sock6_mutex = PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP; void printerr(char *fmt, ...); #define DBG 0 Loading Loading @@ -122,6 +125,8 @@ int string_to_ip(const char *string, struct sockaddr_storage *ss) { int ifc_init(void) { int ret; pthread_mutex_lock(&ifc_sock_mutex); if (ifc_ctl_sock == -1) { ifc_ctl_sock = socket(AF_INET, SOCK_DGRAM | SOCK_CLOEXEC, 0); if (ifc_ctl_sock < 0) { Loading @@ -136,6 +141,7 @@ int ifc_init(void) int ifc_init6(void) { pthread_mutex_lock(&ifc_sock6_mutex); if (ifc_ctl_sock6 == -1) { ifc_ctl_sock6 = socket(AF_INET6, SOCK_DGRAM | SOCK_CLOEXEC, 0); if (ifc_ctl_sock6 < 0) { Loading @@ -152,6 +158,7 @@ void ifc_close(void) (void)close(ifc_ctl_sock); ifc_ctl_sock = -1; } pthread_mutex_unlock(&ifc_sock_mutex); } void ifc_close6(void) Loading @@ -160,6 +167,7 @@ void ifc_close6(void) (void)close(ifc_ctl_sock6); ifc_ctl_sock6 = -1; } pthread_mutex_unlock(&ifc_sock6_mutex); } static void ifc_init_ifr(const char *name, struct ifreq *ifr) Loading Loading @@ -553,6 +561,7 @@ int ifc_act_on_ipv4_route(int action, const char *ifname, struct in_addr dst, in ifc_init(); if (ifc_ctl_sock < 0) { ifc_close(); return -errno; } Loading Loading
libnetutils/dhcptool.c +5 −2 Original line number Diff line number Diff line Loading @@ -14,6 +14,7 @@ * limitations under the License. */ #include <err.h> #include <errno.h> #include <error.h> #include <stdbool.h> Loading @@ -29,12 +30,14 @@ int main(int argc, char* argv[]) { char* interface = argv[1]; if (ifc_init()) { error(EXIT_FAILURE, errno, "dhcptool %s: ifc_init failed", interface); err(errno, "dhcptool %s: ifc_init failed", interface); ifc_close(); return EXIT_FAILURE; } int rc = do_dhcp(interface); if (rc) { error(0, errno, "dhcptool %s: do_dhcp failed", interface); err(errno, "dhcptool %s: do_dhcp failed", interface); } ifc_close(); Loading
libnetutils/ifc_utils.c +9 −0 Original line number Diff line number Diff line Loading @@ -19,6 +19,7 @@ #include <unistd.h> #include <string.h> #include <errno.h> #include <pthread.h> #include <sys/socket.h> #include <sys/select.h> Loading Loading @@ -57,6 +58,8 @@ static int ifc_ctl_sock = -1; static int ifc_ctl_sock6 = -1; static pthread_mutex_t ifc_sock_mutex = PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP; static pthread_mutex_t ifc_sock6_mutex = PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP; void printerr(char *fmt, ...); #define DBG 0 Loading Loading @@ -122,6 +125,8 @@ int string_to_ip(const char *string, struct sockaddr_storage *ss) { int ifc_init(void) { int ret; pthread_mutex_lock(&ifc_sock_mutex); if (ifc_ctl_sock == -1) { ifc_ctl_sock = socket(AF_INET, SOCK_DGRAM | SOCK_CLOEXEC, 0); if (ifc_ctl_sock < 0) { Loading @@ -136,6 +141,7 @@ int ifc_init(void) int ifc_init6(void) { pthread_mutex_lock(&ifc_sock6_mutex); if (ifc_ctl_sock6 == -1) { ifc_ctl_sock6 = socket(AF_INET6, SOCK_DGRAM | SOCK_CLOEXEC, 0); if (ifc_ctl_sock6 < 0) { Loading @@ -152,6 +158,7 @@ void ifc_close(void) (void)close(ifc_ctl_sock); ifc_ctl_sock = -1; } pthread_mutex_unlock(&ifc_sock_mutex); } void ifc_close6(void) Loading @@ -160,6 +167,7 @@ void ifc_close6(void) (void)close(ifc_ctl_sock6); ifc_ctl_sock6 = -1; } pthread_mutex_unlock(&ifc_sock6_mutex); } static void ifc_init_ifr(const char *name, struct ifreq *ifr) Loading Loading @@ -553,6 +561,7 @@ int ifc_act_on_ipv4_route(int action, const char *ifname, struct in_addr dst, in ifc_init(); if (ifc_ctl_sock < 0) { ifc_close(); return -errno; } Loading