prefix SOCKET symbols with rk_
This commit is contained in:
@@ -217,7 +217,7 @@ parse_ports(krb5_context context,
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
struct descr {
|
struct descr {
|
||||||
SOCKET s;
|
krb5_socket_t s;
|
||||||
int type;
|
int type;
|
||||||
int port;
|
int port;
|
||||||
unsigned char *buf;
|
unsigned char *buf;
|
||||||
@@ -235,7 +235,7 @@ init_descr(struct descr *d)
|
|||||||
{
|
{
|
||||||
memset(d, 0, sizeof(*d));
|
memset(d, 0, sizeof(*d));
|
||||||
d->sa = (struct sockaddr *)&d->__ss;
|
d->sa = (struct sockaddr *)&d->__ss;
|
||||||
d->s = INVALID_SOCKET;
|
d->s = rk_INVALID_SOCKET;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@@ -271,7 +271,7 @@ init_socket(krb5_context context,
|
|||||||
if (ret) {
|
if (ret) {
|
||||||
krb5_warn(context, ret, "krb5_addr2sockaddr");
|
krb5_warn(context, ret, "krb5_addr2sockaddr");
|
||||||
closesocket(d->s);
|
closesocket(d->s);
|
||||||
d->s = INVALID_SOCKET;
|
d->s = rk_INVALID_SOCKET;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -279,9 +279,9 @@ init_socket(krb5_context context,
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
d->s = socket(family, type, 0);
|
d->s = socket(family, type, 0);
|
||||||
if(IS_BAD_SOCKET(d->s)){
|
if(rk_IS_BAD_SOCKET(d->s)){
|
||||||
krb5_warn(context, errno, "socket(%d, %d, 0)", family, type);
|
krb5_warn(context, errno, "socket(%d, %d, 0)", family, type);
|
||||||
d->s = INVALID_SOCKET;
|
d->s = rk_INVALID_SOCKET;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
#if defined(HAVE_SETSOCKOPT) && defined(SOL_SOCKET) && defined(SO_REUSEADDR)
|
#if defined(HAVE_SETSOCKOPT) && defined(SOL_SOCKET) && defined(SO_REUSEADDR)
|
||||||
@@ -293,24 +293,24 @@ init_socket(krb5_context context,
|
|||||||
d->type = type;
|
d->type = type;
|
||||||
d->port = port;
|
d->port = port;
|
||||||
|
|
||||||
if(IS_SOCKET_ERROR(bind(d->s, sa, sa_size))){
|
if(rk_IS_SOCKET_ERROR(bind(d->s, sa, sa_size))){
|
||||||
char a_str[256];
|
char a_str[256];
|
||||||
size_t len;
|
size_t len;
|
||||||
|
|
||||||
krb5_print_address (a, a_str, sizeof(a_str), &len);
|
krb5_print_address (a, a_str, sizeof(a_str), &len);
|
||||||
krb5_warn(context, errno, "bind %s/%d", a_str, ntohs(port));
|
krb5_warn(context, errno, "bind %s/%d", a_str, ntohs(port));
|
||||||
closesocket(d->s);
|
closesocket(d->s);
|
||||||
d->s = INVALID_SOCKET;
|
d->s = rk_INVALID_SOCKET;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if(type == SOCK_STREAM && IS_SOCKET_ERROR(listen(d->s, SOMAXCONN))){
|
if(type == SOCK_STREAM && rk_IS_SOCKET_ERROR(listen(d->s, SOMAXCONN))){
|
||||||
char a_str[256];
|
char a_str[256];
|
||||||
size_t len;
|
size_t len;
|
||||||
|
|
||||||
krb5_print_address (a, a_str, sizeof(a_str), &len);
|
krb5_print_address (a, a_str, sizeof(a_str), &len);
|
||||||
krb5_warn(context, errno, "listen %s/%d", a_str, ntohs(port));
|
krb5_warn(context, errno, "listen %s/%d", a_str, ntohs(port));
|
||||||
closesocket(d->s);
|
closesocket(d->s);
|
||||||
d->s = INVALID_SOCKET;
|
d->s = rk_INVALID_SOCKET;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -348,7 +348,7 @@ init_sockets(krb5_context context,
|
|||||||
for (j = 0; j < addresses.len; ++j) {
|
for (j = 0; j < addresses.len; ++j) {
|
||||||
init_socket(context, config, &d[num], &addresses.val[j],
|
init_socket(context, config, &d[num], &addresses.val[j],
|
||||||
ports[i].family, ports[i].type, ports[i].port);
|
ports[i].family, ports[i].type, ports[i].port);
|
||||||
if(d[num].s != INVALID_SOCKET){
|
if(d[num].s != rk_INVALID_SOCKET){
|
||||||
char a_str[80];
|
char a_str[80];
|
||||||
size_t len;
|
size_t len;
|
||||||
|
|
||||||
@@ -423,15 +423,16 @@ send_reply(krb5_context context,
|
|||||||
l[1] = (reply->length >> 16) & 0xff;
|
l[1] = (reply->length >> 16) & 0xff;
|
||||||
l[2] = (reply->length >> 8) & 0xff;
|
l[2] = (reply->length >> 8) & 0xff;
|
||||||
l[3] = reply->length & 0xff;
|
l[3] = reply->length & 0xff;
|
||||||
if(IS_SOCKET_ERROR(sendto(d->s, l, sizeof(l), 0, d->sa, d->sock_len))) {
|
if(rk_IS_SOCKET_ERROR(sendto(d->s, l, sizeof(l), 0, d->sa, d->sock_len))) {
|
||||||
kdc_log (context, config,
|
kdc_log (context, config,
|
||||||
0, "sendto(%s): %s", d->addr_string, strerror(SOCK_ERRNO));
|
0, "sendto(%s): %s", d->addr_string,
|
||||||
|
strerror(rk_SOCK_ERRNO));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if(IS_SOCKET_ERROR(sendto(d->s, reply->data, reply->length, 0, d->sa, d->sock_len))) {
|
if(rk_IS_SOCKET_ERROR(sendto(d->s, reply->data, reply->length, 0, d->sa, d->sock_len))) {
|
||||||
kdc_log (context, config,
|
kdc_log (context, config, 0, "sendto(%s): %s", d->addr_string,
|
||||||
0, "sendto(%s): %s", d->addr_string, strerror(SOCK_ERRNO));
|
strerror(rk_SOCK_ERRNO));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -489,8 +490,8 @@ handle_udp(krb5_context context,
|
|||||||
|
|
||||||
d->sock_len = sizeof(d->__ss);
|
d->sock_len = sizeof(d->__ss);
|
||||||
n = recvfrom(d->s, buf, max_request, 0, d->sa, &d->sock_len);
|
n = recvfrom(d->s, buf, max_request, 0, d->sa, &d->sock_len);
|
||||||
if(IS_SOCKET_ERROR(n))
|
if(rk_IS_SOCKET_ERROR(n))
|
||||||
krb5_warn(context, SOCK_ERRNO, "recvfrom");
|
krb5_warn(context, rk_SOCK_ERRNO, "recvfrom");
|
||||||
else {
|
else {
|
||||||
addr_to_string (context, d->sa, d->sock_len,
|
addr_to_string (context, d->sa, d->sock_len,
|
||||||
d->addr_string, sizeof(d->addr_string));
|
d->addr_string, sizeof(d->addr_string));
|
||||||
@@ -523,9 +524,9 @@ clear_descr(struct descr *d)
|
|||||||
if(d->buf)
|
if(d->buf)
|
||||||
memset(d->buf, 0, d->size);
|
memset(d->buf, 0, d->size);
|
||||||
d->len = 0;
|
d->len = 0;
|
||||||
if(d->s != INVALID_SOCKET)
|
if(d->s != rk_INVALID_SOCKET)
|
||||||
closesocket(d->s);
|
closesocket(d->s);
|
||||||
d->s = INVALID_SOCKET;
|
d->s = rk_INVALID_SOCKET;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -559,15 +560,15 @@ add_new_tcp (krb5_context context,
|
|||||||
krb5_kdc_configuration *config,
|
krb5_kdc_configuration *config,
|
||||||
struct descr *d, int parent, int child)
|
struct descr *d, int parent, int child)
|
||||||
{
|
{
|
||||||
SOCKET s;
|
krb5_socket_t s;
|
||||||
|
|
||||||
if (child == -1)
|
if (child == -1)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
d[child].sock_len = sizeof(d[child].__ss);
|
d[child].sock_len = sizeof(d[child].__ss);
|
||||||
s = accept(d[parent].s, d[child].sa, &d[child].sock_len);
|
s = accept(d[parent].s, d[child].sa, &d[child].sock_len);
|
||||||
if(IS_BAD_SOCKET(s)) {
|
if(rk_IS_BAD_SOCKET(s)) {
|
||||||
krb5_warn(context, SOCK_ERRNO, "accept");
|
krb5_warn(context, rk_SOCK_ERRNO, "accept");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -720,14 +721,14 @@ handle_http_tcp (krb5_context context,
|
|||||||
kdc_log(context, config, 0, "HTTP request from %s is non KDC request", d->addr_string);
|
kdc_log(context, config, 0, "HTTP request from %s is non KDC request", d->addr_string);
|
||||||
kdc_log(context, config, 5, "HTTP request: %s", t);
|
kdc_log(context, config, 5, "HTTP request: %s", t);
|
||||||
free(data);
|
free(data);
|
||||||
if (IS_SOCKET_ERROR(send(d->s, proto, strlen(proto), 0))) {
|
if (rk_IS_SOCKET_ERROR(send(d->s, proto, strlen(proto), 0))) {
|
||||||
kdc_log(context, config, 0, "HTTP write failed: %s: %s",
|
kdc_log(context, config, 0, "HTTP write failed: %s: %s",
|
||||||
d->addr_string, strerror(SOCK_ERRNO));
|
d->addr_string, strerror(rk_SOCK_ERRNO));
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
if (IS_SOCKET_ERROR(send(d->s, msg, strlen(msg), 0))) {
|
if (rk_IS_SOCKET_ERROR(send(d->s, msg, strlen(msg), 0))) {
|
||||||
kdc_log(context, config, 0, "HTTP write failed: %s: %s",
|
kdc_log(context, config, 0, "HTTP write failed: %s: %s",
|
||||||
d->addr_string, strerror(SOCK_ERRNO));
|
d->addr_string, strerror(rk_SOCK_ERRNO));
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
return -1;
|
return -1;
|
||||||
@@ -740,16 +741,16 @@ handle_http_tcp (krb5_context context,
|
|||||||
"Pragma: no-cache\r\n"
|
"Pragma: no-cache\r\n"
|
||||||
"Content-type: application/octet-stream\r\n"
|
"Content-type: application/octet-stream\r\n"
|
||||||
"Content-transfer-encoding: binary\r\n\r\n";
|
"Content-transfer-encoding: binary\r\n\r\n";
|
||||||
if (IS_SOCKET_ERROR(send(d->s, proto, strlen(proto), 0))) {
|
if (rk_IS_SOCKET_ERROR(send(d->s, proto, strlen(proto), 0))) {
|
||||||
free(data);
|
free(data);
|
||||||
kdc_log(context, config, 0, "HTTP write failed: %s: %s",
|
kdc_log(context, config, 0, "HTTP write failed: %s: %s",
|
||||||
d->addr_string, strerror(SOCK_ERRNO));
|
d->addr_string, strerror(rk_SOCK_ERRNO));
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
if (IS_SOCKET_ERROR(send(d->s, msg, strlen(msg), 0))) {
|
if (rk_IS_SOCKET_ERROR(send(d->s, msg, strlen(msg), 0))) {
|
||||||
free(data);
|
free(data);
|
||||||
kdc_log(context, config, 0, "HTTP write failed: %s: %s",
|
kdc_log(context, config, 0, "HTTP write failed: %s: %s",
|
||||||
d->addr_string, strerror(SOCK_ERRNO));
|
d->addr_string, strerror(rk_SOCK_ERRNO));
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -780,8 +781,8 @@ handle_tcp(krb5_context context,
|
|||||||
}
|
}
|
||||||
|
|
||||||
n = recvfrom(d[idx].s, buf, sizeof(buf), 0, NULL, NULL);
|
n = recvfrom(d[idx].s, buf, sizeof(buf), 0, NULL, NULL);
|
||||||
if(IS_SOCKET_ERROR(n)){
|
if(rk_IS_SOCKET_ERROR(n)){
|
||||||
krb5_warn(context, SOCK_ERRNO, "recvfrom failed from %s to %s/%d",
|
krb5_warn(context, rk_SOCK_ERRNO, "recvfrom failed from %s to %s/%d",
|
||||||
d[idx].addr_string, descr_type(d + idx),
|
d[idx].addr_string, descr_type(d + idx),
|
||||||
ntohs(d[idx].port));
|
ntohs(d[idx].port));
|
||||||
return;
|
return;
|
||||||
@@ -867,7 +868,7 @@ loop(krb5_context context,
|
|||||||
|
|
||||||
FD_ZERO(&fds);
|
FD_ZERO(&fds);
|
||||||
for(i = 0; i < ndescr; i++) {
|
for(i = 0; i < ndescr; i++) {
|
||||||
if(!IS_BAD_SOCKET(d[i].s)){
|
if(!rk_IS_BAD_SOCKET(d[i].s)){
|
||||||
if(d[i].type == SOCK_STREAM &&
|
if(d[i].type == SOCK_STREAM &&
|
||||||
d[i].timeout && d[i].timeout < time(NULL)) {
|
d[i].timeout && d[i].timeout < time(NULL)) {
|
||||||
kdc_log(context, config, 1,
|
kdc_log(context, config, 1,
|
||||||
@@ -909,11 +910,11 @@ loop(krb5_context context,
|
|||||||
break;
|
break;
|
||||||
case -1:
|
case -1:
|
||||||
if (errno != EINTR)
|
if (errno != EINTR)
|
||||||
krb5_warn(context, SOCK_ERRNO, "select");
|
krb5_warn(context, rk_SOCK_ERRNO, "select");
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
for(i = 0; i < ndescr; i++)
|
for(i = 0; i < ndescr; i++)
|
||||||
if(!IS_BAD_SOCKET(d[i].s) && FD_ISSET(d[i].s, &fds)) {
|
if(!rk_IS_BAD_SOCKET(d[i].s) && FD_ISSET(d[i].s, &fds)) {
|
||||||
if(d[i].type == SOCK_DGRAM)
|
if(d[i].type == SOCK_DGRAM)
|
||||||
handle_udp(context, config, &d[i]);
|
handle_udp(context, config, &d[i]);
|
||||||
else if(d[i].type == SOCK_STREAM)
|
else if(d[i].type == SOCK_STREAM)
|
||||||
|
@@ -78,7 +78,7 @@ main(int argc, char **argv)
|
|||||||
krb5_principal c1, c2;
|
krb5_principal c1, c2;
|
||||||
krb5_authenticator authent;
|
krb5_authenticator authent;
|
||||||
krb5_keytab keytab;
|
krb5_keytab keytab;
|
||||||
SOCKET sock = INVALID_SOCKET;
|
krb5_socket_t sock = rk_INVALID_SOCKET;
|
||||||
int close_socket = 0;
|
int close_socket = 0;
|
||||||
HDB *db = NULL;
|
HDB *db = NULL;
|
||||||
int optidx = 0;
|
int optidx = 0;
|
||||||
|
@@ -45,13 +45,13 @@ static int time_before_gone;
|
|||||||
|
|
||||||
const char *master_hostname;
|
const char *master_hostname;
|
||||||
|
|
||||||
static SOCKET
|
static krb5_socket_t
|
||||||
make_signal_socket (krb5_context context)
|
make_signal_socket (krb5_context context)
|
||||||
{
|
{
|
||||||
#ifndef NO_UNIX_SOCKETS
|
#ifndef NO_UNIX_SOCKETS
|
||||||
struct sockaddr_un addr;
|
struct sockaddr_un addr;
|
||||||
const char *fn;
|
const char *fn;
|
||||||
SOCKET fd;
|
krb5_socket_t fd;
|
||||||
|
|
||||||
fn = kadm5_log_signal_socket(context);
|
fn = kadm5_log_signal_socket(context);
|
||||||
|
|
||||||
@@ -67,30 +67,30 @@ make_signal_socket (krb5_context context)
|
|||||||
return fd;
|
return fd;
|
||||||
#else
|
#else
|
||||||
struct addrinfo *ai = NULL;
|
struct addrinfo *ai = NULL;
|
||||||
SOCKET fd;
|
krb5_socket_t fd;
|
||||||
|
|
||||||
kadm5_log_signal_socket_info(context, 1, &ai);
|
kadm5_log_signal_socket_info(context, 1, &ai);
|
||||||
|
|
||||||
fd = socket(ai->ai_family, ai->ai_socktype, ai->ai_protocol);
|
fd = socket(ai->ai_family, ai->ai_socktype, ai->ai_protocol);
|
||||||
if (IS_BAD_SOCKET(fd))
|
if (rk_IS_BAD_SOCKET(fd))
|
||||||
krb5_err (context, 1, SOCK_ERRNO, "socket AF=%d", ai->ai_family);
|
krb5_err (context, 1, rk_SOCK_ERRNO, "socket AF=%d", ai->ai_family);
|
||||||
|
|
||||||
if (IS_SOCKET_ERROR( bind (fd, ai->ai_addr, ai->ai_addrlen) ))
|
if (rk_IS_SOCKET_ERROR( bind (fd, ai->ai_addr, ai->ai_addrlen) ))
|
||||||
krb5_err (context, 1, SOCK_ERRNO, "bind");
|
krb5_err (context, 1, rk_SOCK_ERRNO, "bind");
|
||||||
return fd;
|
return fd;
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
static SOCKET
|
static krb5_socket_t
|
||||||
make_listen_socket (krb5_context context, const char *port_str)
|
make_listen_socket (krb5_context context, const char *port_str)
|
||||||
{
|
{
|
||||||
SOCKET fd;
|
krb5_socket_t fd;
|
||||||
int one = 1;
|
int one = 1;
|
||||||
struct sockaddr_in addr;
|
struct sockaddr_in addr;
|
||||||
|
|
||||||
fd = socket (AF_INET, SOCK_STREAM, 0);
|
fd = socket (AF_INET, SOCK_STREAM, 0);
|
||||||
if (IS_BAD_SOCKET(fd))
|
if (rk_IS_BAD_SOCKET(fd))
|
||||||
krb5_err (context, 1, SOCK_ERRNO, "socket AF_INET");
|
krb5_err (context, 1, rk_SOCK_ERRNO, "socket AF_INET");
|
||||||
setsockopt (fd, SOL_SOCKET, SO_REUSEADDR, (void *)&one, sizeof(one));
|
setsockopt (fd, SOL_SOCKET, SO_REUSEADDR, (void *)&one, sizeof(one));
|
||||||
memset (&addr, 0, sizeof(addr));
|
memset (&addr, 0, sizeof(addr));
|
||||||
addr.sin_family = AF_INET;
|
addr.sin_family = AF_INET;
|
||||||
@@ -120,7 +120,7 @@ make_listen_socket (krb5_context context, const char *port_str)
|
|||||||
}
|
}
|
||||||
|
|
||||||
struct slave {
|
struct slave {
|
||||||
SOCKET fd;
|
krb5_socket_t fd;
|
||||||
struct sockaddr_in addr;
|
struct sockaddr_in addr;
|
||||||
char *name;
|
char *name;
|
||||||
krb5_auth_context ac;
|
krb5_auth_context ac;
|
||||||
@@ -195,9 +195,9 @@ slave_dead(krb5_context context, slave *s)
|
|||||||
{
|
{
|
||||||
krb5_warnx(context, "slave %s dead", s->name);
|
krb5_warnx(context, "slave %s dead", s->name);
|
||||||
|
|
||||||
if (!IS_BAD_SOCKET(s->fd)) {
|
if (!rk_IS_BAD_SOCKET(s->fd)) {
|
||||||
closesocket (s->fd);
|
closesocket (s->fd);
|
||||||
s->fd = INVALID_SOCKET;
|
s->fd = rk_INVALID_SOCKET;
|
||||||
}
|
}
|
||||||
s->flags |= SLAVE_F_DEAD;
|
s->flags |= SLAVE_F_DEAD;
|
||||||
slave_seen(s);
|
slave_seen(s);
|
||||||
@@ -208,7 +208,7 @@ remove_slave (krb5_context context, slave *s, slave **root)
|
|||||||
{
|
{
|
||||||
slave **p;
|
slave **p;
|
||||||
|
|
||||||
if (!IS_BAD_SOCKET(s->fd))
|
if (!rk_IS_BAD_SOCKET(s->fd))
|
||||||
closesocket (s->fd);
|
closesocket (s->fd);
|
||||||
if (s->name)
|
if (s->name)
|
||||||
free (s->name);
|
free (s->name);
|
||||||
@@ -224,7 +224,8 @@ remove_slave (krb5_context context, slave *s, slave **root)
|
|||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
add_slave (krb5_context context, krb5_keytab keytab, slave **root, SOCKET fd)
|
add_slave (krb5_context context, krb5_keytab keytab, slave **root,
|
||||||
|
krb5_socket_t fd)
|
||||||
{
|
{
|
||||||
krb5_principal server;
|
krb5_principal server;
|
||||||
krb5_error_code ret;
|
krb5_error_code ret;
|
||||||
@@ -243,8 +244,8 @@ add_slave (krb5_context context, krb5_keytab keytab, slave **root, SOCKET fd)
|
|||||||
|
|
||||||
addr_len = sizeof(s->addr);
|
addr_len = sizeof(s->addr);
|
||||||
s->fd = accept (fd, (struct sockaddr *)&s->addr, &addr_len);
|
s->fd = accept (fd, (struct sockaddr *)&s->addr, &addr_len);
|
||||||
if (IS_BAD_SOCKET(s->fd)) {
|
if (rk_IS_BAD_SOCKET(s->fd)) {
|
||||||
krb5_warn (context, errno, "accept");
|
krb5_warn (context, rk_SOCK_ERRNO, "accept");
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
if (master_hostname)
|
if (master_hostname)
|
||||||
@@ -309,7 +310,7 @@ error:
|
|||||||
|
|
||||||
struct prop_context {
|
struct prop_context {
|
||||||
krb5_auth_context auth_context;
|
krb5_auth_context auth_context;
|
||||||
SOCKET fd;
|
krb5_socket_t fd;
|
||||||
};
|
};
|
||||||
|
|
||||||
static int
|
static int
|
||||||
@@ -759,7 +760,7 @@ main(int argc, char **argv)
|
|||||||
void *kadm_handle;
|
void *kadm_handle;
|
||||||
kadm5_server_context *server_context;
|
kadm5_server_context *server_context;
|
||||||
kadm5_config_params conf;
|
kadm5_config_params conf;
|
||||||
SOCKET signal_fd, listen_fd;
|
krb5_socket_t signal_fd, listen_fd;
|
||||||
int log_fd;
|
int log_fd;
|
||||||
slave *slaves = NULL;
|
slave *slaves = NULL;
|
||||||
uint32_t current_version = 0, old_version = 0;
|
uint32_t current_version = 0, old_version = 0;
|
||||||
|
@@ -79,7 +79,7 @@ typedef struct kadm5_log_context {
|
|||||||
#else
|
#else
|
||||||
struct addrinfo *socket_info;
|
struct addrinfo *socket_info;
|
||||||
#endif
|
#endif
|
||||||
SOCKET socket_fd;
|
krb5_socket_t socket_fd;
|
||||||
} kadm5_log_context;
|
} kadm5_log_context;
|
||||||
|
|
||||||
typedef struct kadm5_server_context {
|
typedef struct kadm5_server_context {
|
||||||
|
@@ -170,9 +170,9 @@ krb5_auth_con_genaddrs(krb5_context context,
|
|||||||
if(flags & KRB5_AUTH_CONTEXT_GENERATE_LOCAL_ADDR) {
|
if(flags & KRB5_AUTH_CONTEXT_GENERATE_LOCAL_ADDR) {
|
||||||
if (auth_context->local_address == NULL) {
|
if (auth_context->local_address == NULL) {
|
||||||
len = sizeof(ss_local);
|
len = sizeof(ss_local);
|
||||||
if(IS_SOCKET_ERROR(getsockname(fd, local, &len))) {
|
if(rk_IS_SOCKET_ERROR(getsockname(fd, local, &len))) {
|
||||||
char buf[128];
|
char buf[128];
|
||||||
ret = SOCK_ERRNO;
|
ret = rk_SOCK_ERRNO;
|
||||||
strerror_r(ret, buf, sizeof(buf));
|
strerror_r(ret, buf, sizeof(buf));
|
||||||
krb5_set_error_message(context, ret, "getsockname: %s", buf);
|
krb5_set_error_message(context, ret, "getsockname: %s", buf);
|
||||||
goto out;
|
goto out;
|
||||||
@@ -188,9 +188,9 @@ krb5_auth_con_genaddrs(krb5_context context,
|
|||||||
}
|
}
|
||||||
if(flags & KRB5_AUTH_CONTEXT_GENERATE_REMOTE_ADDR) {
|
if(flags & KRB5_AUTH_CONTEXT_GENERATE_REMOTE_ADDR) {
|
||||||
len = sizeof(ss_remote);
|
len = sizeof(ss_remote);
|
||||||
if(IS_SOCKET_ERROR(getpeername(fd, remote, &len))) {
|
if(rk_IS_SOCKET_ERROR(getpeername(fd, remote, &len))) {
|
||||||
char buf[128];
|
char buf[128];
|
||||||
ret = SOCK_ERRNO;
|
ret = rk_SOCK_ERRNO;
|
||||||
strerror_r(ret, buf, sizeof(buf));
|
strerror_r(ret, buf, sizeof(buf));
|
||||||
krb5_set_error_message(context, ret, "getpeername: %s", buf);
|
krb5_set_error_message(context, ret, "getpeername: %s", buf);
|
||||||
goto out;
|
goto out;
|
||||||
|
@@ -363,10 +363,8 @@ krb5_init_context(krb5_context *context)
|
|||||||
if (ret)
|
if (ret)
|
||||||
goto out;
|
goto out;
|
||||||
#endif
|
#endif
|
||||||
#ifdef NEED_SOCK_INIT
|
if (SOCK_INIT())
|
||||||
if (SOCK_INIT)
|
|
||||||
p->flags |= KRB5_CTX_F_SOCKETS_INITIALIZED;
|
p->flags |= KRB5_CTX_F_SOCKETS_INITIALIZED;
|
||||||
#endif
|
|
||||||
|
|
||||||
out:
|
out:
|
||||||
if(ret) {
|
if(ret) {
|
||||||
@@ -535,11 +533,9 @@ krb5_free_context(krb5_context context)
|
|||||||
|
|
||||||
HEIMDAL_MUTEX_destroy(context->mutex);
|
HEIMDAL_MUTEX_destroy(context->mutex);
|
||||||
free(context->mutex);
|
free(context->mutex);
|
||||||
#ifdef NEED_SOCK_INIT
|
|
||||||
if (context->flags & KRB5_CTX_F_SOCKETS_INITIALIZED) {
|
if (context->flags & KRB5_CTX_F_SOCKETS_INITIALIZED) {
|
||||||
SOCK_EXIT;
|
SOCK_EXIT();
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
|
|
||||||
memset(context, 0, sizeof(*context));
|
memset(context, 0, sizeof(*context));
|
||||||
free(context);
|
free(context);
|
||||||
|
@@ -40,20 +40,5 @@ krb5_net_read (krb5_context context,
|
|||||||
size_t len)
|
size_t len)
|
||||||
{
|
{
|
||||||
krb5_socket_t fd = *((krb5_socket_t *)p_fd);
|
krb5_socket_t fd = *((krb5_socket_t *)p_fd);
|
||||||
|
return net_read(fd, buf, len);
|
||||||
#ifdef SOCKET_IS_NOT_AN_FD
|
|
||||||
#ifdef _MSC_VER
|
|
||||||
{
|
|
||||||
HANDLE h = _get_osfhandle(fd);
|
|
||||||
|
|
||||||
if (h != INVALID_HANDLE_VALUE) {
|
|
||||||
return net_read (fd, buf, len);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
#else
|
|
||||||
#error Dont know how to handle socket that may be an fd
|
|
||||||
#endif
|
|
||||||
#endif
|
|
||||||
|
|
||||||
return net_read_s (fd, buf, len);
|
|
||||||
}
|
}
|
||||||
|
@@ -40,24 +40,10 @@ krb5_net_write (krb5_context context,
|
|||||||
size_t len)
|
size_t len)
|
||||||
{
|
{
|
||||||
krb5_socket_t fd = *((krb5_socket_t *)p_fd);
|
krb5_socket_t fd = *((krb5_socket_t *)p_fd);
|
||||||
|
return net_write(fd, buf, len);
|
||||||
#ifdef SOCKET_IS_NOT_AN_FD
|
|
||||||
#ifdef _MSC_VER
|
|
||||||
{
|
|
||||||
HANDLE h = _get_osfhandle(fd);
|
|
||||||
|
|
||||||
if (h != INVALID_HANDLE_VALUE) {
|
|
||||||
return net_write (fd, buf, len);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
#else
|
|
||||||
#error Dont know how to handle SOCKET that may be an fd
|
|
||||||
#endif
|
|
||||||
#endif
|
|
||||||
|
|
||||||
return net_write_s (fd, buf, len);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
KRB5_DEPRECATED
|
||||||
KRB5_LIB_FUNCTION krb5_ssize_t KRB5_LIB_CALL
|
KRB5_LIB_FUNCTION krb5_ssize_t KRB5_LIB_CALL
|
||||||
krb5_net_write_block(krb5_context context,
|
krb5_net_write_block(krb5_context context,
|
||||||
void *p_fd,
|
void *p_fd,
|
||||||
@@ -85,8 +71,8 @@ krb5_net_write_block(krb5_context context,
|
|||||||
tvp = NULL;
|
tvp = NULL;
|
||||||
|
|
||||||
ret = select(fd + 1, NULL, &wfds, NULL, tvp);
|
ret = select(fd + 1, NULL, &wfds, NULL, tvp);
|
||||||
if (IS_SOCKET_ERROR(ret)) {
|
if (rk_IS_SOCKET_ERROR(ret)) {
|
||||||
if (SOCK_ERRNO == EINTR)
|
if (rk_SOCK_ERRNO == EINTR)
|
||||||
continue;
|
continue;
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
@@ -99,7 +85,7 @@ krb5_net_write_block(krb5_context context,
|
|||||||
|
|
||||||
count = send (fd, cbuf, rem, 0);
|
count = send (fd, cbuf, rem, 0);
|
||||||
|
|
||||||
if (IS_SOCKET_ERROR(count)) {
|
if (rk_IS_SOCKET_ERROR(count)) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -266,7 +266,7 @@ send_via_proxy (krb5_context context,
|
|||||||
struct addrinfo hints;
|
struct addrinfo hints;
|
||||||
struct addrinfo *ai, *a;
|
struct addrinfo *ai, *a;
|
||||||
int ret;
|
int ret;
|
||||||
krb5_socket_t s = INVALID_SOCKET;
|
krb5_socket_t s = rk_INVALID_SOCKET;
|
||||||
char portstr[NI_MAXSERV];
|
char portstr[NI_MAXSERV];
|
||||||
|
|
||||||
if (proxy == NULL)
|
if (proxy == NULL)
|
||||||
@@ -416,7 +416,7 @@ krb5_sendto (krb5_context context,
|
|||||||
|
|
||||||
for (a = ai; a != NULL; a = a->ai_next) {
|
for (a = ai; a != NULL; a = a->ai_next) {
|
||||||
fd = socket (a->ai_family, a->ai_socktype | SOCK_CLOEXEC, a->ai_protocol);
|
fd = socket (a->ai_family, a->ai_socktype | SOCK_CLOEXEC, a->ai_protocol);
|
||||||
if (IS_BAD_SOCKET(fd))
|
if (rk_IS_BAD_SOCKET(fd))
|
||||||
continue;
|
continue;
|
||||||
rk_cloexec(fd);
|
rk_cloexec(fd);
|
||||||
if (connect (fd, a->ai_addr, a->ai_addrlen) < 0) {
|
if (connect (fd, a->ai_addr, a->ai_addrlen) < 0) {
|
||||||
|
@@ -91,7 +91,7 @@ krb5_storage_from_fd(krb5_socket_t fd_in)
|
|||||||
krb5_storage *sp;
|
krb5_storage *sp;
|
||||||
int fd;
|
int fd;
|
||||||
|
|
||||||
#ifdef SOCKET_IS_NOT_AN_FD
|
#ifdef _WIN32
|
||||||
#ifdef _MSC_VER
|
#ifdef _MSC_VER
|
||||||
if (_get_osfhandle(fd_in) != -1) {
|
if (_get_osfhandle(fd_in) != -1) {
|
||||||
fd = dup(fd_in);
|
fd = dup(fd_in);
|
||||||
@@ -101,7 +101,7 @@ krb5_storage_from_fd(krb5_socket_t fd_in)
|
|||||||
#else
|
#else
|
||||||
#error Dont know how to deal with fd that may or may not be a socket.
|
#error Dont know how to deal with fd that may or may not be a socket.
|
||||||
#endif
|
#endif
|
||||||
#else /* SOCKET_IS_NOT_AN_FD */
|
#else
|
||||||
fd = dup(fd_in);
|
fd = dup(fd_in);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
@@ -79,7 +79,7 @@ libroken_la_OBJS = \
|
|||||||
$(OBJ)\resolve.obj \
|
$(OBJ)\resolve.obj \
|
||||||
$(OBJ)\roken_gethostby.obj \
|
$(OBJ)\roken_gethostby.obj \
|
||||||
$(OBJ)\rtbl.obj \
|
$(OBJ)\rtbl.obj \
|
||||||
$(OBJ)\sendmsg_w32.obj \
|
$(OBJ)\sendmsg.obj \
|
||||||
$(OBJ)\setenv.obj \
|
$(OBJ)\setenv.obj \
|
||||||
$(OBJ)\setprogname.obj \
|
$(OBJ)\setprogname.obj \
|
||||||
$(OBJ)\simple_exec_w32.obj \
|
$(OBJ)\simple_exec_w32.obj \
|
||||||
|
@@ -80,7 +80,7 @@ main(int argc, char **argv)
|
|||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
if (SOCK_INIT)
|
if (SOCK_INIT)
|
||||||
errx(1, "Couldn't initialize sockets. Err=%d\n", SOCK_ERRNO);
|
errx(1, "Couldn't initialize sockets. Err=%d\n", rk_SOCK_ERRNO);
|
||||||
|
|
||||||
ret = getifaddrs(&addrs);
|
ret = getifaddrs(&addrs);
|
||||||
if (ret != 0)
|
if (ret != 0)
|
||||||
@@ -95,7 +95,7 @@ main(int argc, char **argv)
|
|||||||
freeifaddrs(addrs);
|
freeifaddrs(addrs);
|
||||||
|
|
||||||
if (SOCK_EXIT)
|
if (SOCK_EXIT)
|
||||||
errx(1, "Couldn't uninitialize sockets. Err=%d\n", SOCK_ERRNO);
|
errx(1, "Couldn't uninitialize sockets. Err=%d\n", rk_SOCK_ERRNO);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@@ -41,12 +41,12 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
static void
|
static void
|
||||||
accept_it (SOCKET s, SOCKET *ret_socket)
|
accept_it (rk_socket_t s, rk_socket_t *ret_socket)
|
||||||
{
|
{
|
||||||
SOCKET as;
|
rk_socket_t as;
|
||||||
|
|
||||||
as = accept(s, NULL, NULL);
|
as = accept(s, NULL, NULL);
|
||||||
if(IS_BAD_SOCKET(as))
|
if(rk_IS_BAD_SOCKET(as))
|
||||||
err (1, "accept");
|
err (1, "accept");
|
||||||
|
|
||||||
if (ret_socket) {
|
if (ret_socket) {
|
||||||
@@ -54,20 +54,16 @@ accept_it (SOCKET s, SOCKET *ret_socket)
|
|||||||
*ret_socket = as;
|
*ret_socket = as;
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
int fd = fd_from_socket(as, 0);
|
int fd = socket_to_fd(as, 0);
|
||||||
|
|
||||||
/* We would use _O_RDONLY for the fd_from_socket() call for
|
/* We would use _O_RDONLY for the socket_to_fd() call for
|
||||||
STDIN, but there are instances where we assume that STDIN
|
STDIN, but there are instances where we assume that STDIN
|
||||||
is a r/w socket. */
|
is a r/w socket. */
|
||||||
|
|
||||||
dup2(fd, STDIN_FILENO);
|
dup2(fd, STDIN_FILENO);
|
||||||
dup2(fd, STDOUT_FILENO);
|
dup2(fd, STDOUT_FILENO);
|
||||||
|
|
||||||
#ifdef SOCKET_IS_NOT_AN_FD
|
closesocket(fd);
|
||||||
close(fd);
|
|
||||||
#else
|
|
||||||
closesocket(as);
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -90,14 +86,14 @@ accept_it (SOCKET s, SOCKET *ret_socket)
|
|||||||
* @see mini_inetd()
|
* @see mini_inetd()
|
||||||
*/
|
*/
|
||||||
ROKEN_LIB_FUNCTION void ROKEN_LIB_CALL
|
ROKEN_LIB_FUNCTION void ROKEN_LIB_CALL
|
||||||
mini_inetd_addrinfo (struct addrinfo *ai, SOCKET *ret_socket)
|
mini_inetd_addrinfo (struct addrinfo *ai, rk_socket_t *ret_socket)
|
||||||
{
|
{
|
||||||
int ret;
|
int ret;
|
||||||
struct addrinfo *a;
|
struct addrinfo *a;
|
||||||
int n, nalloc, i;
|
int n, nalloc, i;
|
||||||
SOCKET *fds;
|
rk_socket_t *fds;
|
||||||
fd_set orig_read_set, read_set;
|
fd_set orig_read_set, read_set;
|
||||||
SOCKET max_fd = (SOCKET)-1;
|
rk_socket_t max_fd = (rk_socket_t)-1;
|
||||||
|
|
||||||
for (nalloc = 0, a = ai; a != NULL; a = a->ai_next)
|
for (nalloc = 0, a = ai; a != NULL; a = a->ai_next)
|
||||||
++nalloc;
|
++nalloc;
|
||||||
@@ -112,20 +108,20 @@ mini_inetd_addrinfo (struct addrinfo *ai, SOCKET *ret_socket)
|
|||||||
|
|
||||||
for (i = 0, a = ai; a != NULL; a = a->ai_next) {
|
for (i = 0, a = ai; a != NULL; a = a->ai_next) {
|
||||||
fds[i] = socket (a->ai_family, a->ai_socktype, a->ai_protocol);
|
fds[i] = socket (a->ai_family, a->ai_socktype, a->ai_protocol);
|
||||||
if (IS_BAD_SOCKET(fds[i]))
|
if (rk_IS_BAD_SOCKET(fds[i]))
|
||||||
continue;
|
continue;
|
||||||
socket_set_reuseaddr (fds[i], 1);
|
socket_set_reuseaddr (fds[i], 1);
|
||||||
socket_set_ipv6only(fds[i], 1);
|
socket_set_ipv6only(fds[i], 1);
|
||||||
if (IS_SOCKET_ERROR(bind (fds[i], a->ai_addr, a->ai_addrlen))) {
|
if (rk_IS_SOCKET_ERROR(bind (fds[i], a->ai_addr, a->ai_addrlen))) {
|
||||||
warn ("bind af = %d", a->ai_family);
|
warn ("bind af = %d", a->ai_family);
|
||||||
closesocket(fds[i]);
|
closesocket(fds[i]);
|
||||||
fds[i] = INVALID_SOCKET;
|
fds[i] = rk_INVALID_SOCKET;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (IS_SOCKET_ERROR(listen (fds[i], SOMAXCONN))) {
|
if (rk_IS_SOCKET_ERROR(listen (fds[i], SOMAXCONN))) {
|
||||||
warn ("listen af = %d", a->ai_family);
|
warn ("listen af = %d", a->ai_family);
|
||||||
closesocket(fds[i]);
|
closesocket(fds[i]);
|
||||||
fds[i] = INVALID_SOCKET;
|
fds[i] = rk_INVALID_SOCKET;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
#ifndef NO_LIMIT_FD_SETSIZE
|
#ifndef NO_LIMIT_FD_SETSIZE
|
||||||
@@ -144,7 +140,7 @@ mini_inetd_addrinfo (struct addrinfo *ai, SOCKET *ret_socket)
|
|||||||
read_set = orig_read_set;
|
read_set = orig_read_set;
|
||||||
|
|
||||||
ret = select (max_fd + 1, &read_set, NULL, NULL, NULL);
|
ret = select (max_fd + 1, &read_set, NULL, NULL, NULL);
|
||||||
if (IS_SOCKET_ERROR(ret) && SOCK_ERRNO != EINTR)
|
if (rk_IS_SOCKET_ERROR(ret) && rk_SOCK_ERRNO != EINTR)
|
||||||
err (1, "select");
|
err (1, "select");
|
||||||
} while (ret <= 0);
|
} while (ret <= 0);
|
||||||
|
|
||||||
@@ -177,7 +173,7 @@ mini_inetd_addrinfo (struct addrinfo *ai, SOCKET *ret_socket)
|
|||||||
* @see mini_inetd_addrinfo()
|
* @see mini_inetd_addrinfo()
|
||||||
*/
|
*/
|
||||||
ROKEN_LIB_FUNCTION void ROKEN_LIB_CALL
|
ROKEN_LIB_FUNCTION void ROKEN_LIB_CALL
|
||||||
mini_inetd (int port, SOCKET * ret_socket)
|
mini_inetd (int port, rk_socket_t * ret_socket)
|
||||||
{
|
{
|
||||||
int error;
|
int error;
|
||||||
struct addrinfo *ai, hints;
|
struct addrinfo *ai, hints;
|
||||||
|
@@ -39,8 +39,10 @@
|
|||||||
* Like read but never return partial data.
|
* Like read but never return partial data.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#ifndef _WIN32
|
||||||
|
|
||||||
ROKEN_LIB_FUNCTION ssize_t ROKEN_LIB_CALL
|
ROKEN_LIB_FUNCTION ssize_t ROKEN_LIB_CALL
|
||||||
net_read (int fd, void *buf, size_t nbytes)
|
net_read (rk_socket_t fd, void *buf, size_t nbytes)
|
||||||
{
|
{
|
||||||
char *cbuf = (char *)buf;
|
char *cbuf = (char *)buf;
|
||||||
ssize_t count;
|
ssize_t count;
|
||||||
@@ -62,10 +64,10 @@ net_read (int fd, void *buf, size_t nbytes)
|
|||||||
return nbytes;
|
return nbytes;
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef SOCKET_IS_NOT_AN_FD
|
#else
|
||||||
|
|
||||||
ROKEN_LIB_FUNCTION ssize_t ROKEN_LIB_CALL
|
ROKEN_LIB_FUNCTION ssize_t ROKEN_LIB_CALL
|
||||||
net_read_s (SOCKET sock, void *buf, size_t nbytes)
|
net_read(rk_socket_t sock, void *buf, size_t nbytes)
|
||||||
{
|
{
|
||||||
char *cbuf = (char *)buf;
|
char *cbuf = (char *)buf;
|
||||||
ssize_t count;
|
ssize_t count;
|
||||||
@@ -80,7 +82,7 @@ net_read_s (SOCKET sock, void *buf, size_t nbytes)
|
|||||||
WSACancelBlockingCall(). */
|
WSACancelBlockingCall(). */
|
||||||
|
|
||||||
#ifndef HAVE_WINSOCK
|
#ifndef HAVE_WINSOCK
|
||||||
if (SOCK_ERRNO == EINTR)
|
if (rk_SOCK_ERRNO == EINTR)
|
||||||
continue;
|
continue;
|
||||||
#endif
|
#endif
|
||||||
return count;
|
return count;
|
||||||
|
@@ -39,8 +39,10 @@
|
|||||||
* Like write but never return partial data.
|
* Like write but never return partial data.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#ifndef _WIN32
|
||||||
|
|
||||||
ROKEN_LIB_FUNCTION ssize_t ROKEN_LIB_CALL
|
ROKEN_LIB_FUNCTION ssize_t ROKEN_LIB_CALL
|
||||||
net_write (int fd, const void *buf, size_t nbytes)
|
net_write (rk_socket_t fd, const void *buf, size_t nbytes)
|
||||||
{
|
{
|
||||||
const char *cbuf = (const char *)buf;
|
const char *cbuf = (const char *)buf;
|
||||||
ssize_t count;
|
ssize_t count;
|
||||||
@@ -60,10 +62,10 @@ net_write (int fd, const void *buf, size_t nbytes)
|
|||||||
return nbytes;
|
return nbytes;
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef SOCKET_IS_NOT_AN_FD
|
#else
|
||||||
|
|
||||||
ROKEN_LIB_FUNCTION ssize_t ROKEN_LIB_CALL
|
ROKEN_LIB_FUNCTION ssize_t ROKEN_LIB_CALL
|
||||||
net_write_s (SOCKET sock, const void *buf, size_t nbytes)
|
net_write(rk_socket_t sock, const void *buf, size_t nbytes)
|
||||||
{
|
{
|
||||||
const char *cbuf = (const char *)buf;
|
const char *cbuf = (const char *)buf;
|
||||||
ssize_t count;
|
ssize_t count;
|
||||||
|
@@ -392,30 +392,27 @@ socket_set_port (struct sockaddr *, int);
|
|||||||
|
|
||||||
#define socket_set_portrange rk_socket_set_portrange
|
#define socket_set_portrange rk_socket_set_portrange
|
||||||
ROKEN_LIB_FUNCTION void ROKEN_LIB_CALL
|
ROKEN_LIB_FUNCTION void ROKEN_LIB_CALL
|
||||||
socket_set_portrange (SOCKET, int, int);
|
socket_set_portrange (rk_socket_t, int, int);
|
||||||
|
|
||||||
#define socket_set_debug rk_socket_set_debug
|
#define socket_set_debug rk_socket_set_debug
|
||||||
ROKEN_LIB_FUNCTION void ROKEN_LIB_CALL
|
ROKEN_LIB_FUNCTION void ROKEN_LIB_CALL
|
||||||
socket_set_debug (SOCKET);
|
socket_set_debug (rk_socket_t);
|
||||||
|
|
||||||
#define socket_set_tos rk_socket_set_tos
|
#define socket_set_tos rk_socket_set_tos
|
||||||
ROKEN_LIB_FUNCTION void ROKEN_LIB_CALL
|
ROKEN_LIB_FUNCTION void ROKEN_LIB_CALL
|
||||||
socket_set_tos (SOCKET, int);
|
socket_set_tos (rk_socket_t, int);
|
||||||
|
|
||||||
#define socket_set_reuseaddr rk_socket_set_reuseaddr
|
#define socket_set_reuseaddr rk_socket_set_reuseaddr
|
||||||
ROKEN_LIB_FUNCTION void ROKEN_LIB_CALL
|
ROKEN_LIB_FUNCTION void ROKEN_LIB_CALL
|
||||||
socket_set_reuseaddr (SOCKET, int);
|
socket_set_reuseaddr (rk_socket_t, int);
|
||||||
|
|
||||||
#define socket_set_ipv6only rk_socket_set_ipv6only
|
#define socket_set_ipv6only rk_socket_set_ipv6only
|
||||||
ROKEN_LIB_FUNCTION void ROKEN_LIB_CALL
|
ROKEN_LIB_FUNCTION void ROKEN_LIB_CALL
|
||||||
socket_set_ipv6only (SOCKET, int);
|
socket_set_ipv6only (rk_socket_t, int);
|
||||||
|
|
||||||
#ifdef SOCKET_IS_NOT_AN_FD
|
#define socket_to_fd rk_socket_to_fd
|
||||||
ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL
|
ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL
|
||||||
fd_from_socket(SOCKET, int);
|
socket_to_fd(rk_socket_t, int);
|
||||||
#else
|
|
||||||
#define fd_from_socket(s,f) (s)
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#define vstrcollect rk_vstrcollect
|
#define vstrcollect rk_vstrcollect
|
||||||
ROKEN_LIB_FUNCTION char ** ROKEN_LIB_CALL
|
ROKEN_LIB_FUNCTION char ** ROKEN_LIB_CALL
|
||||||
|
@@ -56,36 +56,36 @@
|
|||||||
|
|
||||||
#include<ws2tcpip.h>
|
#include<ws2tcpip.h>
|
||||||
|
|
||||||
#define IS_BAD_SOCKET(s) ((s) == INVALID_SOCKET)
|
typedef SOCKET rk_socket_t;
|
||||||
#define IS_SOCKET_ERROR(rv) ((rv) == SOCKET_ERROR)
|
|
||||||
#define SOCK_ERRNO WSAGetLastError()
|
#define rk_IS_BAD_SOCKET(s) ((s) == INVALID_SOCKET)
|
||||||
#define SOCK_IOCTL(s,c,a) ioctlsocket((s),(c),(a))
|
#define rk_IS_SOCKET_ERROR(rv) ((rv) == SOCKET_ERROR)
|
||||||
|
#define rk_SOCK_ERRNO WSAGetLastError()
|
||||||
|
#define rk_SOCK_IOCTL(s,c,a) ioctlsocket((s),(c),(a))
|
||||||
|
|
||||||
#define ETIMEDOUT WSAETIMEDOUT
|
#define ETIMEDOUT WSAETIMEDOUT
|
||||||
#define EWOULDBLOCK WSAEWOULDBLOCK
|
#define EWOULDBLOCK WSAEWOULDBLOCK
|
||||||
#define ENOTSOCK WSAENOTSOCK
|
#define ENOTSOCK WSAENOTSOCK
|
||||||
|
|
||||||
#define SOCK_INIT rk_WSAStartup()
|
#define rk_SOCK_INIT rk_WSAStartup()
|
||||||
#define SOCK_EXIT rk_WSACleanup()
|
#define rk_SOCK_EXIT rk_WSACleanup()
|
||||||
#define NEED_SOCK_INIT 1
|
|
||||||
|
|
||||||
ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL rk_WSAStartup(void);
|
ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL rk_WSAStartup(void);
|
||||||
ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL rk_WSACleanup(void);
|
ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL rk_WSACleanup(void);
|
||||||
|
|
||||||
#else /* not WinSock */
|
#else /* not WinSock */
|
||||||
|
|
||||||
typedef int SOCKET;
|
typedef int rk_socket_t;
|
||||||
|
|
||||||
#define closesocket(x) close(x)
|
#define rk_closesocket(x) close(x)
|
||||||
#define SOCK_IOCTL(s,c,a) ioctl((s),(c),(a))
|
#define rk_SOCK_IOCTL(s,c,a) ioctl((s),(c),(a))
|
||||||
#define IS_BAD_SOCKET(s) ((s) < 0)
|
#define rk_IS_BAD_SOCKET(s) ((s) < 0)
|
||||||
#define IS_SOCKET_ERROR(rv) ((rv) < 0)
|
#define rk_IS_SOCKET_ERROR(rv) ((rv) < 0)
|
||||||
#define SOCK_ERRNO errno
|
#define rk_SOCK_ERRNO errno
|
||||||
#define INVALID_SOCKET (-1)
|
#define rk_INVALID_SOCKET (-1)
|
||||||
|
|
||||||
#define SOCK_INIT (0)
|
#define rk_SOCK_INIT 0
|
||||||
#define SOCK_EXIT (0)
|
#define rk_SOCK_EXIT 0
|
||||||
#undef NEED_SOCK_INIT
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@@ -654,24 +654,14 @@ ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL roken_vconcat (char *, size_t, va_list);
|
|||||||
ROKEN_LIB_FUNCTION size_t ROKEN_LIB_CALL
|
ROKEN_LIB_FUNCTION size_t ROKEN_LIB_CALL
|
||||||
roken_vmconcat (char **, size_t, va_list);
|
roken_vmconcat (char **, size_t, va_list);
|
||||||
|
|
||||||
ROKEN_LIB_FUNCTION ssize_t ROKEN_LIB_CALL net_write (int, const void *, size_t);
|
ROKEN_LIB_FUNCTION ssize_t ROKEN_LIB_CALL
|
||||||
|
net_write (rk_socket_t, const void *, size_t);
|
||||||
|
|
||||||
ROKEN_LIB_FUNCTION ssize_t ROKEN_LIB_CALL net_read (int, void *, size_t);
|
ROKEN_LIB_FUNCTION ssize_t ROKEN_LIB_CALL
|
||||||
|
net_read (rk_socket_t, void *, size_t);
|
||||||
|
|
||||||
#ifdef SOCKET_IS_NOT_AN_FD
|
ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL
|
||||||
|
issuid(void);
|
||||||
ROKEN_LIB_FUNCTION ssize_t ROKEN_LIB_CALL net_write_s (SOCKET, const void *, size_t);
|
|
||||||
|
|
||||||
ROKEN_LIB_FUNCTION ssize_t ROKEN_LIB_CALL net_read_s (SOCKET, void *, size_t);
|
|
||||||
|
|
||||||
#else
|
|
||||||
|
|
||||||
#define net_read_s net_read
|
|
||||||
#define net_write_s net_write
|
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|
||||||
ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL issuid(void);
|
|
||||||
|
|
||||||
#ifndef HAVE_STRUCT_WINSIZE
|
#ifndef HAVE_STRUCT_WINSIZE
|
||||||
struct winsize {
|
struct winsize {
|
||||||
@@ -833,9 +823,7 @@ struct msghdr {
|
|||||||
};
|
};
|
||||||
|
|
||||||
ROKEN_LIB_FUNCTION ssize_t ROKEN_LIB_CALL
|
ROKEN_LIB_FUNCTION ssize_t ROKEN_LIB_CALL
|
||||||
sendmsg_w32(SOCKET s, const struct msghdr * msg, int flags);
|
sendmsg(rk_socket_t s, const struct msghdr * msg, int flags);
|
||||||
|
|
||||||
#define sendmsg(s,m,f) sendmsg_w32((s),(m),(f))
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@@ -935,10 +923,10 @@ extern const char *__progname;
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
ROKEN_LIB_FUNCTION void ROKEN_LIB_CALL
|
ROKEN_LIB_FUNCTION void ROKEN_LIB_CALL
|
||||||
mini_inetd_addrinfo (struct addrinfo*, SOCKET *);
|
mini_inetd_addrinfo (struct addrinfo*, rk_socket *);
|
||||||
|
|
||||||
ROKEN_LIB_FUNCTION void ROKEN_LIB_CALL
|
ROKEN_LIB_FUNCTION void ROKEN_LIB_CALL
|
||||||
mini_inetd (int, SOCKET *);
|
mini_inetd (int, rk_socket_t *);
|
||||||
|
|
||||||
#ifndef HAVE_LOCALTIME_R
|
#ifndef HAVE_LOCALTIME_R
|
||||||
#define localtime_r rk_localtime_r
|
#define localtime_r rk_localtime_r
|
||||||
|
@@ -35,8 +35,10 @@
|
|||||||
|
|
||||||
#include "roken.h"
|
#include "roken.h"
|
||||||
|
|
||||||
|
#ifndef _WIN32
|
||||||
|
|
||||||
ROKEN_LIB_FUNCTION ssize_t ROKEN_LIB_CALL
|
ROKEN_LIB_FUNCTION ssize_t ROKEN_LIB_CALL
|
||||||
sendmsg(SOCKET s, const struct msghdr *msg, int flags)
|
sendmsg(rk_socket_t s, const struct msghdr *msg, int flags)
|
||||||
{
|
{
|
||||||
ssize_t ret;
|
ssize_t ret;
|
||||||
size_t tot = 0;
|
size_t tot = 0;
|
||||||
@@ -60,3 +62,87 @@ sendmsg(SOCKET s, const struct msghdr *msg, int flags)
|
|||||||
free (buf);
|
free (buf);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#else /* _WIN32 */
|
||||||
|
|
||||||
|
/***********************************************************************
|
||||||
|
* Copyright (c) 2009, Secure Endpoints Inc.
|
||||||
|
* All rights reserved.
|
||||||
|
*
|
||||||
|
* Redistribution and use in source and binary forms, with or without
|
||||||
|
* modification, are permitted provided that the following conditions
|
||||||
|
* are met:
|
||||||
|
*
|
||||||
|
* - Redistributions of source code must retain the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer.
|
||||||
|
*
|
||||||
|
* - Redistributions in binary form must reproduce the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer in
|
||||||
|
* the documentation and/or other materials provided with the
|
||||||
|
* distribution.
|
||||||
|
*
|
||||||
|
* - Neither the name of Secure Endpoints Inc. nor the names of its
|
||||||
|
* contributors may be used to endorse or promote products derived
|
||||||
|
* from this software without specific prior written permission.
|
||||||
|
*
|
||||||
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||||
|
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||||
|
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||||
|
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||||
|
* COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
|
||||||
|
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||||
|
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||||
|
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||||
|
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
||||||
|
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||||
|
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
|
||||||
|
* OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
*
|
||||||
|
**********************************************************************/
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Implementation of sendmsg() for WIN32
|
||||||
|
*
|
||||||
|
* We are using a contrived definition of msghdr which actually uses
|
||||||
|
* an array of ::_WSABUF structures instead of ::iovec . This allows
|
||||||
|
* us to call WSASend directly using the given ::msghdr instead of
|
||||||
|
* having to allocate another array of ::_WSABUF and copying data for
|
||||||
|
* each call.
|
||||||
|
*
|
||||||
|
* Limitations:
|
||||||
|
*
|
||||||
|
* - msg->msg_name is ignored. So is msg->control.
|
||||||
|
* - WSASend() only supports ::MSG_DONTROUTE, ::MSG_OOB and
|
||||||
|
* ::MSG_PARTIAL.
|
||||||
|
*
|
||||||
|
* @param[in] s The socket to use.
|
||||||
|
* @param[in] msg The message
|
||||||
|
* @param[in] flags Flags. A combination of ::MSG_DONTROUTE,
|
||||||
|
* ::MSG_OOB and ::MSG_PARTIAL
|
||||||
|
*
|
||||||
|
* @return The number of bytes sent, on success. Or -1 on error.
|
||||||
|
*/
|
||||||
|
ROKEN_LIB_FUNCTION ssize_t ROKEN_LIB_CALL
|
||||||
|
sendmsg_w32(rk_socket_t s, const struct msghdr * msg, int flags)
|
||||||
|
{
|
||||||
|
int srv;
|
||||||
|
DWORD num_bytes_sent = 0;
|
||||||
|
|
||||||
|
/* TODO: For _WIN32_WINNT >= 0x0600 we can use WSASendMsg using
|
||||||
|
WSAMSG which is a much more direct analogue to sendmsg(). */
|
||||||
|
|
||||||
|
srv = WSASend(s, msg->msg_iov, msg->msg_iovlen,
|
||||||
|
&num_bytes_sent, flags, NULL, NULL);
|
||||||
|
|
||||||
|
if (srv == 0)
|
||||||
|
return (int) num_bytes_sent;
|
||||||
|
|
||||||
|
/* srv == SOCKET_ERROR and WSAGetLastError() == WSA_IO_PENDING
|
||||||
|
indicates that a non-blocking transfer has been scheduled.
|
||||||
|
We'll have to check for that if we ever support non-blocking
|
||||||
|
I/O. */
|
||||||
|
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif /* !_WIN32 */
|
||||||
|
@@ -1,86 +0,0 @@
|
|||||||
/***********************************************************************
|
|
||||||
* Copyright (c) 2009, Secure Endpoints Inc.
|
|
||||||
* All rights reserved.
|
|
||||||
*
|
|
||||||
* Redistribution and use in source and binary forms, with or without
|
|
||||||
* modification, are permitted provided that the following conditions
|
|
||||||
* are met:
|
|
||||||
*
|
|
||||||
* - Redistributions of source code must retain the above copyright
|
|
||||||
* notice, this list of conditions and the following disclaimer.
|
|
||||||
*
|
|
||||||
* - Redistributions in binary form must reproduce the above copyright
|
|
||||||
* notice, this list of conditions and the following disclaimer in
|
|
||||||
* the documentation and/or other materials provided with the
|
|
||||||
* distribution.
|
|
||||||
*
|
|
||||||
* - Neither the name of Secure Endpoints Inc. nor the names of its
|
|
||||||
* contributors may be used to endorse or promote products derived
|
|
||||||
* from this software without specific prior written permission.
|
|
||||||
*
|
|
||||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
|
||||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
|
||||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
|
||||||
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
|
||||||
* COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
|
|
||||||
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
|
||||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
|
||||||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
|
||||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
|
||||||
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
|
||||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
|
|
||||||
* OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
||||||
*
|
|
||||||
**********************************************************************/
|
|
||||||
|
|
||||||
#ifdef HAVE_CONFIG_H
|
|
||||||
#include <config.h>
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#include <roken.h>
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Implementation of sendmsg() for WIN32
|
|
||||||
*
|
|
||||||
* We are using a contrived definition of msghdr which actually uses
|
|
||||||
* an array of ::_WSABUF structures instead of ::iovec . This allows
|
|
||||||
* us to call WSASend directly using the given ::msghdr instead of
|
|
||||||
* having to allocate another array of ::_WSABUF and copying data for
|
|
||||||
* each call.
|
|
||||||
*
|
|
||||||
* Limitations:
|
|
||||||
*
|
|
||||||
* - msg->msg_name is ignored. So is msg->control.
|
|
||||||
* - WSASend() only supports ::MSG_DONTROUTE, ::MSG_OOB and
|
|
||||||
* ::MSG_PARTIAL.
|
|
||||||
*
|
|
||||||
* @param[in] s The socket to use.
|
|
||||||
* @param[in] msg The message
|
|
||||||
* @param[in] flags Flags. A combination of ::MSG_DONTROUTE,
|
|
||||||
* ::MSG_OOB and ::MSG_PARTIAL
|
|
||||||
*
|
|
||||||
* @return The number of bytes sent, on success. Or -1 on error.
|
|
||||||
*/
|
|
||||||
ROKEN_LIB_FUNCTION ssize_t ROKEN_LIB_CALL
|
|
||||||
sendmsg_w32(SOCKET s, const struct msghdr * msg, int flags)
|
|
||||||
{
|
|
||||||
int srv;
|
|
||||||
DWORD num_bytes_sent = 0;
|
|
||||||
|
|
||||||
/* TODO: For _WIN32_WINNT >= 0x0600 we can use WSASendMsg using
|
|
||||||
WSAMSG which is a much more direct analogue to sendmsg(). */
|
|
||||||
|
|
||||||
srv = WSASend(s, msg->msg_iov, msg->msg_iovlen,
|
|
||||||
&num_bytes_sent, flags, NULL, NULL);
|
|
||||||
|
|
||||||
if (srv == 0)
|
|
||||||
return (int) num_bytes_sent;
|
|
||||||
|
|
||||||
/* srv == SOCKET_ERROR and WSAGetLastError() == WSA_IO_PENDING
|
|
||||||
indicates that a non-blocking transfer has been scheduled.
|
|
||||||
We'll have to check for that if we ever support non-blocking
|
|
||||||
I/O. */
|
|
||||||
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
@@ -222,7 +222,7 @@ socket_set_port (struct sockaddr *sa, int port)
|
|||||||
* Set the range of ports to use when binding with port = 0.
|
* Set the range of ports to use when binding with port = 0.
|
||||||
*/
|
*/
|
||||||
ROKEN_LIB_FUNCTION void ROKEN_LIB_CALL
|
ROKEN_LIB_FUNCTION void ROKEN_LIB_CALL
|
||||||
socket_set_portrange (SOCKET sock, int restr, int af)
|
socket_set_portrange (rk_socket_t sock, int restr, int af)
|
||||||
{
|
{
|
||||||
#if defined(IP_PORTRANGE)
|
#if defined(IP_PORTRANGE)
|
||||||
if (af == AF_INET) {
|
if (af == AF_INET) {
|
||||||
@@ -248,12 +248,12 @@ socket_set_portrange (SOCKET sock, int restr, int af)
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
ROKEN_LIB_FUNCTION void ROKEN_LIB_CALL
|
ROKEN_LIB_FUNCTION void ROKEN_LIB_CALL
|
||||||
socket_set_debug (SOCKET sock)
|
socket_set_debug (rk_socket_t sock)
|
||||||
{
|
{
|
||||||
#if defined(SO_DEBUG) && defined(HAVE_SETSOCKOPT)
|
#if defined(SO_DEBUG) && defined(HAVE_SETSOCKOPT)
|
||||||
int on = 1;
|
int on = 1;
|
||||||
|
|
||||||
if (setsockopt (sock, SOL_SOCKET, SO_DEBUG, (void *) &on, sizeof (on)) < 0)
|
if (setsockopt (sock, SOL_rk_socket_t, SO_DEBUG, (void *) &on, sizeof (on)) < 0)
|
||||||
warn ("setsockopt SO_DEBUG (ignored)");
|
warn ("setsockopt SO_DEBUG (ignored)");
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
@@ -263,7 +263,7 @@ socket_set_debug (SOCKET sock)
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
ROKEN_LIB_FUNCTION void ROKEN_LIB_CALL
|
ROKEN_LIB_FUNCTION void ROKEN_LIB_CALL
|
||||||
socket_set_tos (SOCKET sock, int tos)
|
socket_set_tos (rk_socket_t sock, int tos)
|
||||||
{
|
{
|
||||||
#if defined(IP_TOS) && defined(HAVE_SETSOCKOPT)
|
#if defined(IP_TOS) && defined(HAVE_SETSOCKOPT)
|
||||||
if (setsockopt (sock, IPPROTO_IP, IP_TOS, (void *) &tos, sizeof (int)) < 0)
|
if (setsockopt (sock, IPPROTO_IP, IP_TOS, (void *) &tos, sizeof (int)) < 0)
|
||||||
@@ -277,10 +277,10 @@ socket_set_tos (SOCKET sock, int tos)
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
ROKEN_LIB_FUNCTION void ROKEN_LIB_CALL
|
ROKEN_LIB_FUNCTION void ROKEN_LIB_CALL
|
||||||
socket_set_reuseaddr (SOCKET sock, int val)
|
socket_set_reuseaddr (rk_socket_t sock, int val)
|
||||||
{
|
{
|
||||||
#if defined(SO_REUSEADDR) && defined(HAVE_SETSOCKOPT)
|
#if defined(SO_REUSEADDR) && defined(HAVE_SETSOCKOPT)
|
||||||
if(setsockopt(sock, SOL_SOCKET, SO_REUSEADDR, (void *)&val,
|
if(setsockopt(sock, SOL_rk_socket_t, SO_REUSEADDR, (void *)&val,
|
||||||
sizeof(val)) < 0)
|
sizeof(val)) < 0)
|
||||||
err (1, "setsockopt SO_REUSEADDR");
|
err (1, "setsockopt SO_REUSEADDR");
|
||||||
#endif
|
#endif
|
||||||
@@ -291,28 +291,27 @@ socket_set_reuseaddr (SOCKET sock, int val)
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
ROKEN_LIB_FUNCTION void ROKEN_LIB_CALL
|
ROKEN_LIB_FUNCTION void ROKEN_LIB_CALL
|
||||||
socket_set_ipv6only (SOCKET sock, int val)
|
socket_set_ipv6only (rk_socket_t sock, int val)
|
||||||
{
|
{
|
||||||
#if defined(IPV6_V6ONLY) && defined(HAVE_SETSOCKOPT)
|
#if defined(IPV6_V6ONLY) && defined(HAVE_SETSOCKOPT)
|
||||||
setsockopt(sock, IPPROTO_IPV6, IPV6_V6ONLY, (void *)&val, sizeof(val));
|
setsockopt(sock, IPPROTO_IPV6, IPV6_V6ONLY, (void *)&val, sizeof(val));
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
#ifdef SOCKET_IS_NOT_AN_FD
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a file descriptor from a socket
|
* Create a file descriptor from a socket
|
||||||
*
|
*
|
||||||
* While the socket handle in \a sock can be used with WinSock
|
* While the socket handle in \a sock can be used with WinSock
|
||||||
* functions after calling fd_from_socket(), it should not be closed
|
* functions after calling socket_to_fd(), it should not be closed
|
||||||
* with closesocket(). The socket will be closed when the associated
|
* with closesocket(). The socket will be closed when the associated
|
||||||
* file descriptor is closed.
|
* file descriptor is closed.
|
||||||
*/
|
*/
|
||||||
ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL
|
ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL
|
||||||
fd_from_socket(SOCKET sock, int flags)
|
socket_to_fd(rk_socket_t sock, int flags)
|
||||||
{
|
{
|
||||||
|
#ifndef _WIN32
|
||||||
|
return sock;
|
||||||
|
#else
|
||||||
return _open_osfhandle((intptr_t) sock, flags);
|
return _open_osfhandle((intptr_t) sock, flags);
|
||||||
}
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
}
|
||||||
|
@@ -55,31 +55,30 @@ get_address(int flags, struct addrinfo ** ret)
|
|||||||
ai.ai_protocol = PF_UNSPEC;
|
ai.ai_protocol = PF_UNSPEC;
|
||||||
|
|
||||||
rv = getaddrinfo("127.0.0.1", PORT_S, &ai, ret);
|
rv = getaddrinfo("127.0.0.1", PORT_S, &ai, ret);
|
||||||
if (rv) {
|
if (rv)
|
||||||
fprintf(stderr, "[%s] getaddrinfo: %s", prog, gai_strerror(rv));
|
warnx("getaddrinfo: %s", gai_strerror(rv));
|
||||||
}
|
|
||||||
return rv;
|
return rv;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
get_connected_socket(SOCKET * s_ret)
|
get_connected_socket(rk_socket_t * s_ret)
|
||||||
{
|
{
|
||||||
struct addrinfo * ai = NULL;
|
struct addrinfo * ai = NULL;
|
||||||
int rv = 0;
|
int rv = 0;
|
||||||
SOCKET s = INVALID_SOCKET;
|
rk_socket_t s = rk_INVALID_SOCKET;
|
||||||
|
|
||||||
rv = get_address(0, &ai);
|
rv = get_address(0, &ai);
|
||||||
if (rv)
|
if (rv)
|
||||||
return rv;
|
return rv;
|
||||||
|
|
||||||
s = socket(ai->ai_family, ai->ai_socktype, ai->ai_protocol);
|
s = socket(ai->ai_family, ai->ai_socktype, ai->ai_protocol);
|
||||||
if (IS_BAD_SOCKET(s)) {
|
if (rk_IS_BAD_SOCKET(s)) {
|
||||||
rv = 1;
|
rv = 1;
|
||||||
goto done;
|
goto done;
|
||||||
}
|
}
|
||||||
|
|
||||||
rv = connect(s, ai->ai_addr, ai->ai_addrlen);
|
rv = connect(s, ai->ai_addr, ai->ai_addrlen);
|
||||||
if (IS_SOCKET_ERROR(rv))
|
if (rk_IS_SOCKET_ERROR(rv))
|
||||||
goto done;
|
goto done;
|
||||||
|
|
||||||
*s_ret = s;
|
*s_ret = s;
|
||||||
@@ -87,13 +86,13 @@ get_connected_socket(SOCKET * s_ret)
|
|||||||
rv = 0;
|
rv = 0;
|
||||||
|
|
||||||
done:
|
done:
|
||||||
if (!IS_BAD_SOCKET(s))
|
if (!rk_IS_BAD_SOCKET(s))
|
||||||
closesocket(s);
|
closesocket(s);
|
||||||
|
|
||||||
if (ai)
|
if (ai)
|
||||||
freeaddrinfo(ai);
|
freeaddrinfo(ai);
|
||||||
|
|
||||||
return (rv)?SOCK_ERRNO: 0;
|
return (rv) ? rk_SOCK_ERRNO : 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
const char * test_strings[] = {
|
const char * test_strings[] = {
|
||||||
@@ -106,31 +105,34 @@ const char * test_strings[] = {
|
|||||||
static int
|
static int
|
||||||
test_simple_echo_client(void)
|
test_simple_echo_client(void)
|
||||||
{
|
{
|
||||||
SOCKET s = INVALID_SOCKET;
|
rk_socket_t s = INVALID_SOCKET;
|
||||||
int rv;
|
int rv;
|
||||||
char buf[81];
|
char buf[81];
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
fprintf (stderr, "[%s] Getting connected socket...", prog);
|
fprintf(stderr, "[%s] Getting connected socket...", getprogname());
|
||||||
rv = get_connected_socket(&s);
|
rv = get_connected_socket(&s);
|
||||||
if (rv) {
|
if (rv) {
|
||||||
fprintf(stderr, "\n[%s] get_connected_socket() failed (%s)\n", prog, strerror(SOCK_ERRNO));
|
fprintf(stderr, "\n[%s] get_connected_socket() failed (%s)\n",
|
||||||
|
getprogname(), strerror(rk_SOCK_ERRNO));
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
fprintf (stderr, "[%s] done\n", prog);
|
fprintf(stderr, "[%s] done\n", getprogname());
|
||||||
|
|
||||||
for (i=0; i < sizeof(test_strings)/sizeof(test_strings[0]); i++) {
|
for (i=0; i < sizeof(test_strings)/sizeof(test_strings[0]); i++) {
|
||||||
rv = send(s, test_strings[i], strlen(test_strings[i]), 0);
|
rv = send(s, test_strings[i], strlen(test_strings[i]), 0);
|
||||||
if (IS_SOCKET_ERROR(rv)) {
|
if (rk_IS_SOCKET_ERROR(rv)) {
|
||||||
fprintf (stderr, "[%s] send() failure (%s)\n", prog, strerror(SOCK_ERRNO));
|
fprintf(stderr, "[%s] send() failure (%s)\n",
|
||||||
|
getprogname(), strerror(rk_SOCK_ERRNO));
|
||||||
closesocket(s);
|
closesocket(s);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
rv = recv(s, buf, sizeof(buf), 0);
|
rv = recv(s, buf, sizeof(buf), 0);
|
||||||
if (IS_SOCKET_ERROR(rv)) {
|
if (rk_IS_SOCKET_ERROR(rv)) {
|
||||||
fprintf (stderr, "[%s] recv() failure (%s)\n", prog, strerror(SOCK_ERRNO));
|
fprintf (stderr, "[%s] recv() failure (%s)\n",
|
||||||
|
getprogname(), strerror(rk_SOCK_ERRNO));
|
||||||
closesocket(s);
|
closesocket(s);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
@@ -163,12 +165,13 @@ test_simple_echo_socket(void)
|
|||||||
return test_simple_echo_client();
|
return test_simple_echo_client();
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
SOCKET s = INVALID_SOCKET;
|
rk_socket_t s = INVALID_SOCKET;
|
||||||
|
|
||||||
fprintf (stderr, "[%s] Listening for connections...\n", prog);
|
fprintf (stderr, "[%s] Listening for connections...\n", prog);
|
||||||
mini_inetd(htons(PORT), &s);
|
mini_inetd(htons(PORT), &s);
|
||||||
if (IS_BAD_SOCKET(s)) {
|
if (rk_IS_BAD_SOCKET(s)) {
|
||||||
fprintf (stderr, "[%s] Connect failed (%s)\n", prog, strerror(SOCK_ERRNO));
|
fprintf (stderr, "[%s] Connect failed (%s)\n",
|
||||||
|
getprogname(), strerror(rk_SOCK_ERRNO));
|
||||||
} else {
|
} else {
|
||||||
fprintf (stderr, "[%s] Connected\n", prog);
|
fprintf (stderr, "[%s] Connected\n", prog);
|
||||||
}
|
}
|
||||||
@@ -177,17 +180,19 @@ test_simple_echo_socket(void)
|
|||||||
char buf[81];
|
char buf[81];
|
||||||
int rv, srv;
|
int rv, srv;
|
||||||
|
|
||||||
while ((rv = recv(s, buf, sizeof(buf), 0)) != 0 && !IS_SOCKET_ERROR(rv)) {
|
while ((rv = recv(s, buf, sizeof(buf), 0)) != 0 && !rk_IS_SOCKET_ERROR(rv)) {
|
||||||
buf[rv] = 0;
|
buf[rv] = 0;
|
||||||
fprintf(stderr, "[%s] Received [%s]\n", prog, buf);
|
fprintf(stderr, "[%s] Received [%s]\n", prog, buf);
|
||||||
|
|
||||||
/* simple echo */
|
/* simple echo */
|
||||||
srv = send(s, buf, rv, 0);
|
srv = send(s, buf, rv, 0);
|
||||||
if (srv != rv) {
|
if (srv != rv) {
|
||||||
if (IS_SOCKET_ERROR(srv))
|
if (rk_IS_SOCKET_ERROR(srv))
|
||||||
fprintf(stderr, "[%s] send() error [%s]\n", prog, strerror(SOCK_ERRNO));
|
fprintf(stderr, "[%s] send() error [%s]\n",
|
||||||
|
getprogname(), strerror(rk_SOCK_ERRNO));
|
||||||
else
|
else
|
||||||
fprintf(stderr, "[%s] send() size mismatch %d != %d", prog, srv, rv);
|
fprintf(stderr, "[%s] send() size mismatch %d != %d",
|
||||||
|
getprogname(), srv, rv);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!strcmp(buf, "exit")) {
|
if (!strcmp(buf, "exit")) {
|
||||||
@@ -198,7 +203,9 @@ test_simple_echo_socket(void)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fprintf(stderr, "[%s] recv() failed (%s)\n", prog, strerror(SOCK_ERRNO));
|
fprintf(stderr, "[%s] recv() failed (%s)\n",
|
||||||
|
getprogname(),
|
||||||
|
strerror(rk_SOCK_ERRNO));
|
||||||
}
|
}
|
||||||
|
|
||||||
closesocket(s);
|
closesocket(s);
|
||||||
@@ -346,6 +353,8 @@ do_test(char * path)
|
|||||||
|
|
||||||
int main(int argc, char ** argv)
|
int main(int argc, char ** argv)
|
||||||
{
|
{
|
||||||
|
setprogname(argv[0]);
|
||||||
|
|
||||||
if (argc == 2 && strcmp(argv[1], "--client") == 0)
|
if (argc == 2 && strcmp(argv[1], "--client") == 0)
|
||||||
return do_client();
|
return do_client();
|
||||||
else if (argc == 2 && strcmp(argv[1], "--server") == 0)
|
else if (argc == 2 && strcmp(argv[1], "--server") == 0)
|
||||||
|
Reference in New Issue
Block a user