summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--buffer.c6
-rw-r--r--buffer.h5
-rw-r--r--socket.c16
-rw-r--r--socket.h3
4 files changed, 21 insertions, 9 deletions
diff --git a/buffer.c b/buffer.c
index c43cb47..f69ec70 100644
--- a/buffer.c
+++ b/buffer.c
@@ -214,8 +214,10 @@ buf_printf (struct buffer *buf, const char *format, ...)
return ret;
}
-void buf_puts(struct buffer *buf, const char *str)
+bool
+buf_puts(struct buffer *buf, const char *str)
{
+ int ret = false;
uint8_t *ptr = BEND (buf);
int cap = buf_forward_capacity (buf);
if (cap > 0)
@@ -223,7 +225,9 @@ void buf_puts(struct buffer *buf, const char *str)
strncpynt ((char *)ptr,str, cap);
*(buf->data + buf->capacity - 1) = 0; /* windows vsnprintf needs this */
buf->len += (int) strlen ((char *)ptr);
+ ret = true;
}
+ return ret;
}
diff --git a/buffer.h b/buffer.h
index 3b24d09..0a394a7 100644
--- a/buffer.h
+++ b/buffer.h
@@ -277,6 +277,11 @@ bool buf_printf (struct buffer *buf, const char *format, ...)
;
/*
+ * puts append to a buffer with overflow check
+ */
+bool buf_puts (struct buffer *buf, const char *str);
+
+/*
* Like snprintf but guarantees null termination for size > 0
*/
int openvpn_snprintf(char *str, size_t size, const char *format, ...)
diff --git a/socket.c b/socket.c
index 344c0dd..3340314 100644
--- a/socket.c
+++ b/socket.c
@@ -1173,7 +1173,7 @@ openvpn_connect (socket_descriptor_t sd,
}
}
#else
- status = connect (sd, (struct sockaddr *) &remote->sa, sizeof (remote->sa));
+ status = connect (sd, &remote->addr.sa, af_addr_size(remote->addr.sa.sa_family));
if (status)
status = openvpn_errno_socket ();
#endif
@@ -2515,9 +2515,9 @@ void
setenv_sockaddr (struct env_set *es, const char *name_prefix, const struct openvpn_sockaddr *addr, const bool flags)
{
char name_buf[256];
- char buf[128];
#ifdef USE_PF_INET6
+ char buf[128];
switch(addr->addr.sa.sa_family)
{
case AF_INET:
@@ -2582,7 +2582,7 @@ struct proto_names {
const char *display_form;
bool is_dgram;
bool is_net;
- sa_family_t proto_af;
+ unsigned short proto_af;
};
/* Indexed by PROTO_x */
@@ -2629,7 +2629,7 @@ proto_is_tcp(int proto)
return (!proto_names[proto].is_dgram)&&proto_names[proto].is_net;
}
-sa_family_t
+unsigned short
proto_sa_family(int proto)
{
if (proto < 0 || proto >= PROTO_N)
@@ -2679,7 +2679,9 @@ proto2ascii_all (struct gc_arena *gc)
int
addr_guess_family(int proto, const char *name)
{
- sa_family_t ret;
+#ifdef USE_PF_INET6
+ unsigned short ret;
+#endif
if (proto)
{
return proto_sa_family(proto); /* already stamped */
@@ -3270,10 +3272,10 @@ socket_finalize (SOCKET s,
{
if (io->addrlen != sizeof (io->addr))
bad_address_length (io->addrlen, sizeof (io->addr));
- from->dest.addr.sa = io->addr;
+ from->dest.addr.in4 = io->addr;
}
else
- CLEAR (from->dest.addr.sa);
+ CLEAR (from->dest.addr);
}
if (buf)
diff --git a/socket.h b/socket.h
index 718805a..def8104 100644
--- a/socket.h
+++ b/socket.h
@@ -591,6 +591,7 @@ addr_defined_ipi (const struct link_socket_actual *lsa)
#else
ASSERT(0);
#endif
+ return false;
}
static inline bool
@@ -702,7 +703,7 @@ addr_inet4or6(struct sockaddr *addr)
int addr_guess_family(int proto, const char *name);
static inline int
-af_addr_size(sa_family_t af)
+af_addr_size(unsigned short af)
{
#if defined(USE_PF_INET6) || defined (USE_PF_UNIX)
switch(af) {