From b8c5c3b44362778c099531f7a905c56a0423bcef Mon Sep 17 00:00:00 2001 From: Bjørn Mork Date: Fri, 15 May 2015 10:25:21 +0200 Subject: ripe-atlas-fw: imported version 4650 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Bjørn Mork --- libbb/Kbuild | 2 ++ libbb/atlas_timesync.c | 19 +++++++++++++++++++ libbb/bind_interface.c | 42 ++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 63 insertions(+) create mode 100644 libbb/atlas_timesync.c create mode 100644 libbb/bind_interface.c (limited to 'libbb') diff --git a/libbb/Kbuild b/libbb/Kbuild index 178347d..0b77f72 100644 --- a/libbb/Kbuild +++ b/libbb/Kbuild @@ -10,6 +10,7 @@ lib-y += appletlib.o lib-y += ask_confirmation.o lib-y += atlas_bb64.o lib-y += atlas_probe.o +lib-y += atlas_timesync.o lib-y += bb_askpass.o lib-y += bb_basename.o lib-y += bb_do_delay.o @@ -17,6 +18,7 @@ lib-y += bb_pwd.o lib-y += bb_qsort.o lib-y += bb_strtod.o lib-y += bb_strtonum.o +lib-y += bind_interface.o lib-y += change_identity.o lib-y += chomp.o lib-y += compare_string_array.o diff --git a/libbb/atlas_timesync.c b/libbb/atlas_timesync.c new file mode 100644 index 0000000..3434493 --- /dev/null +++ b/libbb/atlas_timesync.c @@ -0,0 +1,19 @@ +/* + * Copyright (c) 2013 RIPE NCC + * Licensed under GPLv2 or later, see file LICENSE in this tarball for details. + */ + +#include "libbb.h" +int get_timesync(void) +{ + FILE *fh; + int lastsync; + + fh= fopen(ATLAS_TIMESYNC_FILE, "r"); + if (!fh) + return -1; + fscanf(fh, "%d", &lastsync); + fclose(fh); + return time(NULL)-lastsync; +} + diff --git a/libbb/bind_interface.c b/libbb/bind_interface.c new file mode 100644 index 0000000..1eb4414 --- /dev/null +++ b/libbb/bind_interface.c @@ -0,0 +1,42 @@ +/* + * Copyright (c) 2014 RIPE NCC + * Licensed under GPLv2 or later, see file LICENSE in this tarball for details. + */ + +#include "libbb.h" + +int bind_interface(int socket, int af, char *name) +{ + struct sockaddr_storage sa; + + memset(&sa, '\0', sizeof(sa)); + + if (af == AF_INET) + { + sa.ss_family= AF_INET; + if (inet_pton(af, name, + &((struct sockaddr_in *)&sa)->sin_addr) == 1) + { + return bind(socket, (struct sockaddr *)&sa, + sizeof(sa)); + } + } + else + { + sa.ss_family= AF_INET6; + if (inet_pton(af, name, + &((struct sockaddr_in6 *)&sa)->sin6_addr) == 1) + { + return bind(socket, (struct sockaddr *)&sa, + sizeof(sa)); + } + } + if (setsockopt(socket, SOL_SOCKET, SO_BINDTODEVICE, name, + strlen(name)+1) == -1) + { + return -1; + } + + return 0; +} + -- cgit v1.2.3