56
56
#include <sys/stat.h> /* open(), S_ISREG */
57
57
#include <sys/socket.h> /* socket(), struct sockaddr_in6,
58
inet_pton(), connect() */
58
inet_pton(), connect(),
59
60
#include <fcntl.h> /* open() */
60
61
#include <dirent.h> /* opendir(), struct dirent, readdir()
73
74
#include <unistd.h> /* close(), SEEK_SET, off_t, write(),
74
75
getuid(), getgid(), seteuid(),
75
76
setgid(), pause(), _exit() */
76
#include <arpa/inet.h> /* inet_pton(), htons, inet_ntop() */
77
#include <arpa/inet.h> /* inet_pton(), htons() */
77
78
#include <iso646.h> /* not, or, and */
78
79
#include <argp.h> /* struct argp_option, error_t, struct
79
80
argp_state, struct argp,
91
92
argz_delete(), argz_append(),
92
93
argz_stringify(), argz_add(),
95
#include <netdb.h> /* getnameinfo(), NI_NUMERICHOST,
96
EAI_SYSTEM, gai_strerror() */
96
99
#include <sys/klog.h> /* klogctl() */
229
232
perror_plus("strdup");
235
ret = clock_gettime(CLOCK_MONOTONIC, &(new_server->last_seen));
237
perror_plus("clock_gettime");
232
240
/* Special case of first server */
233
241
if(*current_server == NULL){
234
242
new_server->next = new_server;
241
249
new_server->prev->next = new_server;
242
250
(*current_server)->prev = new_server;
244
ret = clock_gettime(CLOCK_MONOTONIC, &(*current_server)->last_seen);
246
perror_plus("clock_gettime");
631
634
int af, mandos_context *mc){
632
635
int ret, tcp_sd = -1;
635
struct sockaddr_in in;
636
struct sockaddr_in6 in6;
637
struct sockaddr_storage to;
638
638
char *buffer = NULL;
639
639
char *decrypted_buffer = NULL;
640
640
size_t buffer_length = 0;
722
722
memset(&to, 0, sizeof(to));
723
723
if(af == AF_INET6){
724
to.in6.sin6_family = (sa_family_t)af;
725
ret = inet_pton(af, ip, &to.in6.sin6_addr);
724
((struct sockaddr_in6 *)&to)->sin6_family = (sa_family_t)af;
725
ret = inet_pton(af, ip, &((struct sockaddr_in6 *)&to)->sin6_addr);
726
726
} else { /* IPv4 */
727
to.in.sin_family = (sa_family_t)af;
728
ret = inet_pton(af, ip, &to.in.sin_addr);
727
((struct sockaddr_in *)&to)->sin_family = (sa_family_t)af;
728
ret = inet_pton(af, ip, &((struct sockaddr_in *)&to)->sin_addr);
742
742
if(af == AF_INET6){
743
to.in6.sin6_port = htons(port);
745
#pragma GCC diagnostic push
746
#pragma GCC diagnostic ignored "-Wstrict-aliasing"
748
if(IN6_IS_ADDR_LINKLOCAL /* Spurious warnings from */
749
(&to.in6.sin6_addr)){ /* -Wstrict-aliasing=2 or lower */
751
#pragma GCC diagnostic pop
743
((struct sockaddr_in6 *)&to)->sin6_port = htons(port);
744
if(IN6_IS_ADDR_LINKLOCAL
745
(&((struct sockaddr_in6 *)&to)->sin6_addr)){
753
746
if(if_index == AVAHI_IF_UNSPEC){
754
747
fprintf_plus(stderr, "An IPv6 link-local address is"
755
748
" incomplete without a network interface\n");
759
752
/* Set the network interface number as scope */
760
to.in6.sin6_scope_id = (uint32_t)if_index;
753
((struct sockaddr_in6 *)&to)->sin6_scope_id = (uint32_t)if_index;
763
to.in.sin_port = htons(port);
756
((struct sockaddr_in *)&to)->sin_port = htons(port);
784
777
char addrstr[(INET_ADDRSTRLEN > INET6_ADDRSTRLEN) ?
785
778
INET_ADDRSTRLEN : INET6_ADDRSTRLEN] = "";
787
779
if(af == AF_INET6){
788
pcret = inet_ntop(af, &(to.in6.sin6_addr), addrstr,
780
ret = getnameinfo((struct sockaddr *)&to,
781
sizeof(struct sockaddr_in6),
782
addrstr, sizeof(addrstr), NULL, 0,
791
pcret = inet_ntop(af, &(to.in.sin_addr), addrstr,
785
ret = getnameinfo((struct sockaddr *)&to,
786
sizeof(struct sockaddr_in),
787
addrstr, sizeof(addrstr), NULL, 0,
795
perror_plus("inet_ntop");
797
if(strcmp(addrstr, ip) != 0){
798
fprintf_plus(stderr, "Canonical address form: %s\n", addrstr);
790
if(ret == EAI_SYSTEM){
791
perror_plus("getnameinfo");
792
} else if(ret != 0) {
793
fprintf_plus(stderr, "getnameinfo: %s", gai_strerror(ret));
794
} else if(strcmp(addrstr, ip) != 0){
795
fprintf_plus(stderr, "Canonical address form: %s\n", addrstr);
808
804
if(af == AF_INET6){
809
ret = connect(tcp_sd, &to.in6, sizeof(to));
805
ret = connect(tcp_sd, (struct sockaddr *)&to,
806
sizeof(struct sockaddr_in6));
811
ret = connect(tcp_sd, &to.in, sizeof(to)); /* IPv4 */
808
ret = connect(tcp_sd, (struct sockaddr *)&to, /* IPv4 */
809
sizeof(struct sockaddr_in));
814
812
if ((errno != ECONNREFUSED and errno != ENETUNREACH) or debug){