open_tty(const bool write)
{
FILE *ret;
- ret = fopen("/dev/tty", write ? "w" : "r");
+ ret = platform_fopen("/dev/tty", write ? "w" : "r");
if (!ret)
{
ret = write ? stderr : stdin;
{
if (fp != stderr && fp != stdin)
{
- fclose(fp);
+ platform_fclose(fp);
}
}
close_tty(fp);
fp = open_tty(false);
- if (fgets(input, capacity, fp) != NULL)
+ if (platform_fgets(input, capacity, fp) != NULL)
{
chomp(input);
ret = true;
crypto_uninit_lib(void)
{
#ifdef CRYPTO_MDEBUG
- FILE *fp = fopen("sdlog", "w");
+ FILE *fp = platform_fopen("sdlog", "w");
ASSERT(fp);
CRYPTO_mem_leaks_fp(fp);
- fclose(fp);
+ platform_fclose(fp);
#endif
#if HAVE_OPENSSL_ENGINE
(int)tv_tmp.tv_sec,
(int)tv_tmp.tv_usec);
- stat = select(ses->maxfd + 1, &ses->readfds, &ses->writefds, NULL, &tv_tmp);
+ stat = platform_select(ses->maxfd + 1, &ses->readfds, &ses->writefds, NULL, &tv_tmp);
if (stat > 0)
{
dmsg(D_EVENT_WAIT, "SE_WAIT_SCALEABLE maxfd=%d tv=%d/%d",
ses->maxfd, (int)tv_tmp.tv_sec, (int)tv_tmp.tv_usec);
- stat = select(ses->maxfd + 1, &read, &write, NULL, &tv_tmp);
+ stat = platform_select(ses->maxfd + 1, &read, &write, NULL, &tv_tmp);
if (stat > 0)
{
{
if (lsa->remote_list && free)
{
- freeaddrinfo(lsa->remote_list);
+ platform_freeaddrinfo(lsa->remote_list);
}
lsa->remote_list = NULL;
lsa->current_remote = NULL;
CLEAR(local);
actual = &get_link_socket_info(c)->lsa->actual;
remote = actual->dest;
- getsockname(c->c2.link_socket->sd, &local.addr.sa, &sa_len);
+ platform_getsockname(c->c2.link_socket->sd, &local.addr.sa, &sa_len);
#if ENABLE_IP_PKTINFO
if (!addr_defined(&local))
{
{
if (c->c1.link_socket_addr.bind_local && !c->options.resolve_in_advance)
{
- freeaddrinfo(c->c1.link_socket_addr.bind_local);
+ platform_freeaddrinfo(c->c1.link_socket_addr.bind_local);
}
c->c1.link_socket_addr.bind_local = NULL;
int status;
CLEAR(addr);
- status = getsockname(man->connection.sd_cli, (struct sockaddr *)&addr, &addrlen);
+ status = platform_getsockname(man->connection.sd_cli, (struct sockaddr *)&addr, &addrlen);
if (!status && addrlen == sizeof(addr))
{
const in_addr_t a = ntohl(addr.sin_addr.s_addr);
if (fp)
{
fprintf(fp, "%s\n%d\n", print_in_addr_t(a, 0, &gc), p);
- if (!fclose(fp))
+ if (!platform_fclose(fp))
{
success = true;
}
msg.msg_iov = iov;
msg.msg_iovlen = 1;
- return (sendmsg(fd, &msg, flags));
+ return (platform_sendmsg(fd, &msg, flags));
}
static ssize_t
msghdr.msg_iov = iov;
msghdr.msg_iovlen = 1;
- if ( (n = recvmsg(fd, &msghdr, flags)) <= 0)
+ if ( (n = platform_recvmsg(fd, &msghdr, flags)) <= 0)
{
return (n);
}
man->connection.lastfdreceived = fd;
}
#else /* ifdef TARGET_ANDROID */
- len = recv(man->connection.sd_cli, buf, sizeof(buf), MSG_NOSIGNAL);
+ len = platform_recv(man->connection.sd_cli, buf, sizeof(buf), MSG_NOSIGNAL);
#endif
if (len == 0)
}
else
#endif
- sent = send(man->connection.sd_cli, BPTR(buf), len, MSG_NOSIGNAL);
+ sent = platform_send(man->connection.sd_cli, BPTR(buf), len, MSG_NOSIGNAL);
if (sent >= 0)
{
buffer_list_advance(man->connection.out, sent);
{
if (ms->local)
{
- freeaddrinfo(ms->local);
+ platform_freeaddrinfo(ms->local);
}
free(ms->write_peer_info_file);
CLEAR(*ms);
{
#if defined(HAVE_SETSOCKOPT) && defined(IP_MTU_DISCOVER)
case AF_INET:
- if (setsockopt
+ if (platform_setsockopt
(sd, IPPROTO_IP, IP_MTU_DISCOVER, &mtu_type, sizeof(mtu_type)))
{
msg(M_ERR, "Error setting IP_MTU_DISCOVER type=%d on TCP/UDP socket",
#endif
#if defined(HAVE_SETSOCKOPT) && defined(IPV6_MTU_DISCOVER)
case AF_INET6:
- if (setsockopt
+ if (platform_setsockopt
(sd, IPPROTO_IPV6, IPV6_MTU_DISCOVER, &mtu_type, sizeof(mtu_type)))
{
msg(M_ERR, "Error setting IPV6_MTU_DISCOVER type=%d on TCP6/UDP6 socket",
msg.msg_control = cbuf;
msg.msg_controllen = 256; /* size of cbuf */
- res = recvmsg(fd, &msg, MSG_ERRQUEUE);
+ res = platform_recvmsg(fd, &msg, MSG_ERRQUEUE);
if (res < 0)
{
goto exit;
set_sock_extended_error_passing(int sd)
{
int on = 1;
- if (setsockopt(sd, SOL_IP, IP_RECVERR, (void *) &on, sizeof(on)))
+ if (platform_setsockopt(sd, SOL_IP, IP_RECVERR, (void *) &on, sizeof(on)))
{
msg(M_WARN | M_ERRNO,
"Note: enable extended error passing on TCP/UDP socket failed (IP_RECVERR)");
while (true)
{
char buf[80];
- if (!fgets(buf, sizeof(buf), stdin))
+ if (!platform_fgets(buf, sizeof(buf), stdin))
{
break;
}
memcpy(CMSG_DATA(h), &sd_null[0], sizeof(sd_null[0]));
}
- status = sendmsg(sd, &mesg, MSG_NOSIGNAL);
+ status = platform_sendmsg(sd, &mesg, MSG_NOSIGNAL);
if (status == -1)
{
msg(M_WARN|M_ERRNO, "PORT SHARE: sendmsg failed -- unable to communicate with background process (%d,%d,%d,%d)",
slen = sizeof(from.addr.sa);
dlen = sizeof(to.addr.sa);
if (!getpeername(pc->sd, (struct sockaddr *) &from.addr.sa, &slen)
- && !getsockname(cp->sd, (struct sockaddr *) &to.addr.sa, &dlen))
+ && !platform_getsockname(cp->sd, (struct sockaddr *) &to.addr.sa, &dlen))
{
const char *f = print_openvpn_sockaddr(&from, &gc);
const char *t = print_openvpn_sockaddr(&to, &gc);
struct proxy_connection *cp;
/* connect to port share server */
- if ((sd_server = socket(PF_INET, SOCK_STREAM, IPPROTO_TCP)) < 0)
+ if ((sd_server = platform_socket(PF_INET, SOCK_STREAM, IPPROTO_TCP)) < 0)
{
msg(M_WARN|M_ERRNO, "PORT SHARE PROXY: cannot create socket");
return false;
static const socket_descriptor_t socket_undefined = SOCKET_UNDEFINED;
memcpy(CMSG_DATA(h), &socket_undefined, sizeof(socket_undefined));
- status = recvmsg(sd_control, &mesg, MSG_NOSIGNAL);
+ status = platform_recvmsg(sd_control, &mesg, MSG_NOSIGNAL);
if (status != -1)
{
if (h == NULL
proxy_connection_io_recv(struct proxy_connection *pc)
{
/* recv data from socket */
- const int status = recv(pc->sd, BPTR(&pc->buf), BCAP(&pc->buf), MSG_NOSIGNAL);
+ const int status = platform_recv(pc->sd, BPTR(&pc->buf), BCAP(&pc->buf), MSG_NOSIGNAL);
if (status < 0)
{
return (errno == EAGAIN) ? IOSTAT_EAGAIN_ON_READ : IOSTAT_READ_ERROR;
proxy_connection_io_send(struct proxy_connection *pc, int *bytes_sent)
{
const socket_descriptor_t sd = pc->counterpart->sd;
- const int status = send(sd, BPTR(&pc->buf), BLEN(&pc->buf), MSG_NOSIGNAL);
+ const int status = platform_send(sd, BPTR(&pc->buf), BLEN(&pc->buf), MSG_NOSIGNAL);
if (status < 0)
{
host, port, 0, NULL, AF_INET, &ai);
ASSERT(status==0);
hostaddr = *((struct sockaddr_in *) ai->ai_addr);
- freeaddrinfo(ai);
+ platform_freeaddrinfo(ai);
/*
* Make a socket for foreground and background processes
crypto_msg(M_FATAL, "Error opening file %s", pkcs12_file);
}
p12 = d2i_PKCS12_fp(fp, NULL);
- fclose(fp);
+ platform_fclose(fp);
if (!p12)
{
crypto_msg(M_FATAL, "Error reading PKCS#12 file %s", pkcs12_file);
{
if (biofp)
{
- ASSERT(!fclose(biofp));
+ ASSERT(!platform_fclose(biofp));
biofp = NULL;
}
}
{
char fn[256];
openvpn_snprintf(fn, sizeof(fn), "bio/%d-%d.log", pid, biofp_toggle);
- biofp = fopen(fn, "w");
+ biofp = platform_fopen(fn, "w");
ASSERT(biofp);
biofp_last_open = time(NULL);
biofp_toggle ^= 1;
peercert_filename = create_temp_file(tmp_dir, "pcf", gc);
/* write peer-cert in tmp-file */
- peercert_file = fopen(peercert_filename, "w+");
+ peercert_file = platform_fopen(peercert_filename, "w+");
if (!peercert_file)
{
msg(M_ERR, "Failed to open temporary file : %s", peercert_filename);
msg(M_ERR, "Error writing PEM file containing certificate");
}
- fclose(peercert_file);
+ platform_fclose(peercert_file);
return peercert_filename;
}
unsigned int ret = ks->auth_control_status;
if (ret == ACF_UNDEFINED)
{
- FILE *fp = fopen(ks->auth_control_file, "r");
+ FILE *fp = platform_fopen(ks->auth_control_file, "r");
if (fp)
{
- const int c = fgetc(fp);
+ const int c = platform_fgetc(fp);
if (c == '1')
{
ret = ACF_SUCCEEDED;
{
ret = ACF_FAILED;
}
- fclose(fp);
+ platform_fclose(fp);
ks->auth_control_status = ret;
}
}
struct ifreq netifr;
int ctl_fd;
- if ((ctl_fd = socket(AF_INET, SOCK_DGRAM, 0)) >= 0)
+ if ((ctl_fd = platform_socket(AF_INET, SOCK_DGRAM, 0)) >= 0)
{
CLEAR(netifr);
strncpynt(netifr.ifr_name, ifr.ifr_name, IFNAMSIZ);
struct sockaddr_ctl sc;
int fd;
- fd = socket(PF_SYSTEM, SOCK_DGRAM, SYSPROTO_CONTROL);
+ fd = platform_socket(PF_SYSTEM, SOCK_DGRAM, SYSPROTO_CONTROL);
if (fd < 0)
{
}
/* Retrieve the assigned interface name. */
- if (getsockopt(fd, SYSPROTO_CONTROL, UTUN_OPT_IFNAME, utunname, &utunname_len))
+ if (platform_getsockopt(fd, SYSPROTO_CONTROL, UTUN_OPT_IFNAME, utunname, &utunname_len))
{
msg(M_ERR | M_ERRNO, "Error retrieving utun interface name");
}