projects
/
u
/
mdw
/
putty
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
More portability fixes.
[u/mdw/putty]
/
unix
/
uxnet.c
diff --git
a/unix/uxnet.c
b/unix/uxnet.c
index
f4731fd
..
46b619b
100644
(file)
--- a/
unix/uxnet.c
+++ b/
unix/uxnet.c
@@
-26,7
+26,7
@@
struct Socket_tag {
struct socket_function_table *fn;
/* the above variable absolutely *must* be the first in this structure */
struct Socket_tag {
struct socket_function_table *fn;
/* the above variable absolutely *must* be the first in this structure */
- char *error;
+ c
onst c
har *error;
int s;
Plug plug;
void *private_ptr;
int s;
Plug plug;
void *private_ptr;
@@
-56,7
+56,7
@@
struct Socket_tag {
typedef struct Socket_tag *Actual_Socket;
struct SockAddr_tag {
typedef struct Socket_tag *Actual_Socket;
struct SockAddr_tag {
- char *error;
+ c
onst c
har *error;
/*
* Which address family this address belongs to. AF_INET for
* IPv4; AF_INET6 for IPv6; AF_UNSPEC indicates that name
/*
* Which address family this address belongs to. AF_INET for
* IPv4; AF_INET6 for IPv6; AF_UNSPEC indicates that name
@@
-90,7
+90,7
@@
static int cmpfortree(void *av, void *bv)
static int cmpforsearch(void *av, void *bv)
{
Actual_Socket b = (Actual_Socket) bv;
static int cmpforsearch(void *av, void *bv)
{
Actual_Socket b = (Actual_Socket) bv;
- int as =
(int)
av, bs = b->s;
+ int as =
*(int *)
av, bs = b->s;
if (as < bs)
return -1;
if (as > bs)
if (as < bs)
return -1;
if (as > bs)
@@
-115,7
+115,7
@@
void sk_cleanup(void)
}
}
}
}
-char *error_string(int error)
+c
onst c
har *error_string(int error)
{
return strerror(error);
}
{
return strerror(error);
}
@@
-322,7
+322,7
@@
static int sk_tcp_write_oob(Socket s, const char *data, int len);
static void sk_tcp_set_private_ptr(Socket s, void *ptr);
static void *sk_tcp_get_private_ptr(Socket s);
static void sk_tcp_set_frozen(Socket s, int is_frozen);
static void sk_tcp_set_private_ptr(Socket s, void *ptr);
static void *sk_tcp_get_private_ptr(Socket s);
static void sk_tcp_set_frozen(Socket s, int is_frozen);
-static char *sk_tcp_socket_error(Socket s);
+static c
onst c
har *sk_tcp_socket_error(Socket s);
static struct socket_function_table tcp_fn_table = {
sk_tcp_plug,
static struct socket_function_table tcp_fn_table = {
sk_tcp_plug,
@@
-336,7
+336,7
@@
static struct socket_function_table tcp_fn_table = {
sk_tcp_socket_error
};
sk_tcp_socket_error
};
-Socket sk_register(
void *sock
, Plug plug)
+Socket sk_register(
OSSocket sockfd
, Plug plug)
{
Actual_Socket ret;
{
Actual_Socket ret;
@@
-357,7
+357,7
@@
Socket sk_register(void *sock, Plug plug)
ret->oobpending = FALSE;
ret->listener = 0;
ret->oobpending = FALSE;
ret->listener = 0;
- ret->s =
(int)sock
;
+ ret->s =
sockfd
;
if (ret->s < 0) {
ret->error = error_string(errno);
if (ret->s < 0) {
ret->error = error_string(errno);
@@
-383,6
+383,7
@@
Socket sk_new(SockAddr addr, int port, int privport, int oobinline,
int err;
Actual_Socket ret;
short localport;
int err;
Actual_Socket ret;
short localport;
+ int fl;
/*
* Create Socket structure.
/*
* Create Socket structure.
@@
-433,6
+434,11
@@
Socket sk_new(SockAddr addr, int port, int privport, int oobinline,
else
localport = 0; /* just use port 0 (ie kernel picks) */
else
localport = 0; /* just use port 0 (ie kernel picks) */
+ /* BSD IP stacks need sockaddr_in zeroed before filling in */
+ memset(&a,'\0',sizeof(struct sockaddr_in));
+#ifdef IPV6
+ memset(&a6,'\0',sizeof(struct sockaddr_in6));
+#endif
/* Loop round trying to bind */
while (1) {
int retcode;
/* Loop round trying to bind */
while (1) {
int retcode;
@@
-492,10
+498,10
@@
Socket sk_new(SockAddr addr, int port, int privport, int oobinline,
a.sin_addr.s_addr = htonl(addr->address);
a.sin_port = htons((short) port);
#endif
a.sin_addr.s_addr = htonl(addr->address);
a.sin_port = htons((short) port);
#endif
- {
-
int i = 1
;
- ioctl(s, FIONBIO, &i);
- }
+
+
fl = fcntl(s, F_GETFL)
;
+ if (fl != -1)
+ fcntl(s, F_SETFL, fl | O_NONBLOCK);
if ((
#ifdef IPV6
if ((
#ifdef IPV6
@@
-520,6
+526,8
@@
Socket sk_new(SockAddr addr, int port, int privport, int oobinline,
uxsel_tell(ret);
add234(sktree, ret);
uxsel_tell(ret);
add234(sktree, ret);
+ sk_addr_free(addr);
+
return (Socket) ret;
}
return (Socket) ret;
}
@@
-571,7
+579,12
@@
Socket sk_newlistener(char *srcaddr, int port, Plug plug, int local_host_only)
setsockopt(s, SOL_SOCKET, SO_REUSEADDR, (const char *)&on, sizeof(on));
setsockopt(s, SOL_SOCKET, SO_REUSEADDR, (const char *)&on, sizeof(on));
+ /* BSD IP stacks need sockaddr_in zeroed before filling in */
+ memset(&a,'\0',sizeof(struct sockaddr_in));
#ifdef IPV6
#ifdef IPV6
+#if 0
+ memset(&a6,'\0',sizeof(struct sockaddr_in6));
+#endif
hints.ai_flags = AI_NUMERICHOST;
hints.ai_family = AF_UNSPEC;
hints.ai_socktype = 0;
hints.ai_flags = AI_NUMERICHOST;
hints.ai_family = AF_UNSPEC;
hints.ai_socktype = 0;
@@
-773,6
+786,12
@@
static int sk_tcp_write(Socket sock, const char *buf, int len)
if (s->writable)
try_send(s);
if (s->writable)
try_send(s);
+ /*
+ * Update the select() status to correctly reflect whether or
+ * not we should be selecting for write.
+ */
+ uxsel_tell(s);
+
return bufchain_size(&s->output_data);
}
return bufchain_size(&s->output_data);
}
@@
-794,6
+813,12
@@
static int sk_tcp_write_oob(Socket sock, const char *buf, int len)
if (s->writable)
try_send(s);
if (s->writable)
try_send(s);
+ /*
+ * Update the select() status to correctly reflect whether or
+ * not we should be selecting for write.
+ */
+ uxsel_tell(s);
+
return s->sending_oob;
}
return s->sending_oob;
}
@@
-806,7
+831,7
@@
static int net_select_result(int fd, int event)
u_long atmark;
/* Find the Socket structure */
u_long atmark;
/* Find the Socket structure */
- s = find234(sktree,
(void *)
fd, cmpforsearch);
+ s = find234(sktree,
&
fd, cmpforsearch);
if (!s)
return 1; /* boggle */
if (!s)
return 1; /* boggle */
@@
-824,8
+849,8
@@
static int net_select_result(int fd, int event)
ret = recv(s->s, buf, sizeof(buf), MSG_OOB);
noise_ultralight(ret);
if (ret <= 0) {
ret = recv(s->s, buf, sizeof(buf), MSG_OOB);
noise_ultralight(ret);
if (ret <= 0) {
- char *str = (ret == 0 ? "Internal networking trouble" :
- error_string(errno));
+ c
onst c
har *str = (ret == 0 ? "Internal networking trouble" :
+
error_string(errno));
/* We're inside the Unix frontend here, so we know
* that the frontend handle is unnecessary. */
logevent(NULL, str);
/* We're inside the Unix frontend here, so we know
* that the frontend handle is unnecessary. */
logevent(NULL, str);
@@
-856,14
+881,14
@@
static int net_select_result(int fd, int event)
memset(&isa, 0, sizeof(struct sockaddr_in));
err = 0;
memset(&isa, 0, sizeof(struct sockaddr_in));
err = 0;
- t = accept(s->s,(struct sockaddr *)&isa,&addrlen);
+ t = accept(s->s,(struct sockaddr *)&isa,
(socklen_t *)
&addrlen);
if (t < 0) {
break;
}
if (s->localhost_only && !ipv4_is_loopback(isa.sin_addr)) {
close(t); /* someone let nonlocal through?! */
if (t < 0) {
break;
}
if (s->localhost_only && !ipv4_is_loopback(isa.sin_addr)) {
close(t); /* someone let nonlocal through?! */
- } else if (plug_accepting(s->plug,
(void*)
t)) {
+ } else if (plug_accepting(s->plug, t)) {
close(t); /* denied or error */
}
break;
close(t); /* denied or error */
}
break;
@@
-990,11
+1015,11
@@
static void *sk_tcp_get_private_ptr(Socket sock)
* if there's a problem. These functions extract an error message,
* or return NULL if there's no problem.
*/
* if there's a problem. These functions extract an error message,
* or return NULL if there's no problem.
*/
-char *sk_addr_error(SockAddr addr)
+c
onst c
har *sk_addr_error(SockAddr addr)
{
return addr->error;
}
{
return addr->error;
}
-static char *sk_tcp_socket_error(Socket sock)
+static c
onst c
har *sk_tcp_socket_error(Socket sock)
{
Actual_Socket s = (Actual_Socket) sock;
return s->error;
{
Actual_Socket s = (Actual_Socket) sock;
return s->error;