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)
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;
}
#endif
;
+/*
+ * 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
*/
}
}
#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
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:
const char *display_form;
bool is_dgram;
bool is_net;
- sa_family_t proto_af;
+ unsigned short proto_af;
};
/* Indexed by PROTO_x */
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)
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 */
{
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)
#else
ASSERT(0);
#endif
+ return false;
}
static inline bool
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) {