Merge branch 'master' into 1.1
Conflicts: have.h lib/dropin.c lib/fake-getaddrinfo.c lib/pidfile.c src/Makefile.am src/bsd/device.c src/conf.c src/connection.c src/connection.h src/graph.c src/mingw/device.c src/net.c src/net_setup.c src/node.c src/protocol_key.c src/protocol_misc.c src/tincd.c
This commit is contained in:
commit
075e6828a7
43 changed files with 1094 additions and 306 deletions
35
lib/dropin.c
35
lib/dropin.c
|
@ -124,25 +124,34 @@ char *get_current_dir_name(void) {
|
|||
|
||||
#ifndef HAVE_ASPRINTF
|
||||
int asprintf(char **buf, const char *fmt, ...) {
|
||||
int status;
|
||||
int result;
|
||||
va_list ap;
|
||||
va_start(ap, fmt);
|
||||
result = vasprintf(buf, fmt, ap);
|
||||
va_end(ap);
|
||||
return result;
|
||||
}
|
||||
|
||||
int vasprintf(char **buf, const char *fmt, va_list ap) {
|
||||
int status;
|
||||
va_list aq;
|
||||
int len;
|
||||
|
||||
len = 4096;
|
||||
*buf = xmalloc(len);
|
||||
|
||||
va_start(ap, fmt);
|
||||
status = vsnprintf(*buf, len, fmt, ap);
|
||||
va_end(ap);
|
||||
va_copy(aq, ap);
|
||||
status = vsnprintf(*buf, len, fmt, aq);
|
||||
va_end(aq);
|
||||
|
||||
if(status >= 0)
|
||||
*buf = xrealloc(*buf, status + 1);
|
||||
|
||||
if(status > len - 1) {
|
||||
len = status;
|
||||
va_start(ap, fmt);
|
||||
status = vsnprintf(*buf, len, fmt, ap);
|
||||
va_end(ap);
|
||||
va_copy(aq, ap);
|
||||
status = vsnprintf(*buf, len, fmt, aq);
|
||||
va_end(aq);
|
||||
}
|
||||
|
||||
return status;
|
||||
|
@ -156,15 +165,3 @@ int gettimeofday(struct timeval *tv, void *tz) {
|
|||
return 0;
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifndef HAVE_RANDOM
|
||||
#include <openssl/rand.h>
|
||||
|
||||
long int random(void) {
|
||||
long int x;
|
||||
|
||||
RAND_pseudo_bytes((unsigned char *)&x, sizeof(x));
|
||||
|
||||
return x;
|
||||
}
|
||||
#endif
|
||||
|
|
10
lib/dropin.h
10
lib/dropin.h
|
@ -36,19 +36,11 @@ extern char *get_current_dir_name(void);
|
|||
|
||||
#ifndef HAVE_ASPRINTF
|
||||
extern int asprintf(char **, const char *, ...);
|
||||
#endif
|
||||
|
||||
#ifndef HAVE_GETNAMEINFO
|
||||
extern int getnameinfo(const struct sockaddr *sa, size_t salen, char *host,
|
||||
size_t hostlen, char *serv, size_t servlen, int flags);
|
||||
extern int vasprintf(char **, const char *, va_list ap);
|
||||
#endif
|
||||
|
||||
#ifndef HAVE_GETTIMEOFDAY
|
||||
extern int gettimeofday(struct timeval *, void *);
|
||||
#endif
|
||||
|
||||
#ifndef HAVE_RANDOM
|
||||
extern long int random(void);
|
||||
#endif
|
||||
|
||||
#endif /* __DROPIN_H__ */
|
||||
|
|
|
@ -16,7 +16,8 @@
|
|||
#include "fake-getaddrinfo.h"
|
||||
#include "xalloc.h"
|
||||
|
||||
#ifndef HAVE_GAI_STRERROR
|
||||
|
||||
#if !HAVE_DECL_GAI_STRERROR
|
||||
char *gai_strerror(int ecode) {
|
||||
switch (ecode) {
|
||||
case EAI_NODATA:
|
||||
|
@ -31,7 +32,7 @@ char *gai_strerror(int ecode) {
|
|||
}
|
||||
#endif /* !HAVE_GAI_STRERROR */
|
||||
|
||||
#ifndef HAVE_FREEADDRINFO
|
||||
#if !HAVE_DECL_FREEADDRINFO
|
||||
void freeaddrinfo(struct addrinfo *ai) {
|
||||
struct addrinfo *next;
|
||||
|
||||
|
@ -43,7 +44,7 @@ void freeaddrinfo(struct addrinfo *ai) {
|
|||
}
|
||||
#endif /* !HAVE_FREEADDRINFO */
|
||||
|
||||
#ifndef HAVE_GETADDRINFO
|
||||
#if !HAVE_DECL_GETADDRINFO
|
||||
static struct addrinfo *malloc_ai(uint16_t port, uint32_t addr) {
|
||||
struct addrinfo *ai;
|
||||
|
||||
|
|
|
@ -33,16 +33,16 @@ struct addrinfo {
|
|||
};
|
||||
#endif /* !HAVE_STRUCT_ADDRINFO */
|
||||
|
||||
#ifndef HAVE_GETADDRINFO
|
||||
#if !HAVE_DECL_GETADDRINFO
|
||||
int getaddrinfo(const char *hostname, const char *servname,
|
||||
const struct addrinfo *hints, struct addrinfo **res);
|
||||
#endif /* !HAVE_GETADDRINFO */
|
||||
|
||||
#ifndef HAVE_GAI_STRERROR
|
||||
#if !HAVE_DECL_GAI_STRERROR
|
||||
char *gai_strerror(int ecode);
|
||||
#endif /* !HAVE_GAI_STRERROR */
|
||||
|
||||
#ifndef HAVE_FREEADDRINFO
|
||||
#if !HAVE_DECL_FREEADDRINFO
|
||||
void freeaddrinfo(struct addrinfo *ai);
|
||||
#endif /* !HAVE_FREEADDRINFO */
|
||||
|
||||
|
|
|
@ -14,7 +14,7 @@
|
|||
#include "fake-getnameinfo.h"
|
||||
#include "fake-getaddrinfo.h"
|
||||
|
||||
#ifndef HAVE_GETNAMEINFO
|
||||
#if !HAVE_DECL_GETNAMEINFO
|
||||
|
||||
int getnameinfo(const struct sockaddr *sa, size_t salen, char *host, size_t hostlen, char *serv, size_t servlen, int flags) {
|
||||
struct sockaddr_in *sin = (struct sockaddr_in *)sa;
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
#ifndef _FAKE_GETNAMEINFO_H
|
||||
#define _FAKE_GETNAMEINFO_H
|
||||
|
||||
#ifndef HAVE_GETNAMEINFO
|
||||
#if !HAVE_DECL_GETNAMEINFO
|
||||
int getnameinfo(const struct sockaddr *sa, size_t salen, char *host,
|
||||
size_t hostlen, char *serv, size_t servlen, int flags);
|
||||
#endif /* !HAVE_GETNAMEINFO */
|
||||
|
|
|
@ -96,3 +96,10 @@ const char *winerror(int err) {
|
|||
}
|
||||
#endif
|
||||
|
||||
unsigned int bitfield_to_int(void *bitfield, size_t size) {
|
||||
unsigned int value = 0;
|
||||
if(size > sizeof value)
|
||||
size = sizeof value;
|
||||
memcpy(&value, bitfield, size);
|
||||
return value;
|
||||
}
|
||||
|
|
|
@ -43,4 +43,6 @@ extern const char *winerror(int);
|
|||
#define strerror(x) ((x)>0?strerror(x):winerror(GetLastError()))
|
||||
#endif
|
||||
|
||||
extern unsigned int bitfield_to_int(void *bitfield, size_t size);
|
||||
|
||||
#endif /* __TINC_UTILS_H__ */
|
||||
|
|
|
@ -24,3 +24,6 @@ void *xcalloc PARAMS ((size_t n, size_t s));
|
|||
void *xrealloc PARAMS ((void *p, size_t n)) __attribute__ ((__malloc__));
|
||||
|
||||
char *xstrdup PARAMS ((const char *s)) __attribute__ ((__malloc__));
|
||||
|
||||
extern int xasprintf(char **strp, const char *fmt, ...);
|
||||
extern int xvasprintf(char **strp, const char *fmt, va_list ap);
|
||||
|
|
|
@ -22,6 +22,8 @@
|
|||
#include <sys/types.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <stdarg.h>
|
||||
#include <errno.h>
|
||||
|
||||
#if STDC_HEADERS
|
||||
# include <stdlib.h>
|
||||
|
@ -138,3 +140,21 @@ xcalloc (n, s)
|
|||
}
|
||||
|
||||
#endif /* NOT_USED */
|
||||
|
||||
int xasprintf(char **strp, const char *fmt, ...) {
|
||||
int result;
|
||||
va_list ap;
|
||||
va_start(ap, fmt);
|
||||
result = xvasprintf(strp, fmt, ap);
|
||||
va_end(ap);
|
||||
return result;
|
||||
}
|
||||
|
||||
int xvasprintf(char **strp, const char *fmt, va_list ap) {
|
||||
int result = vasprintf(strp, fmt, ap);
|
||||
if(result < 0) {
|
||||
fprintf(stderr, "vasprintf() failed: %s\n", strerror(errno));
|
||||
exit(xalloc_exit_failure);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue