mirror of
https://git.tartarus.org/simon/putty.git
synced 2025-03-22 06:38:37 -05:00
windows/network.c: refactor addr family in sk_newlistener.
Most of the previous large sk_newlistener function is now an inner function whose address-family parameter is a platform AF_FOO constant rather than one of our own ADDRTYPE_FOO. sk_newlistener itself is a trivial wrapper on that, which just does the initial translation from the input ADDRTYPE_FOO into an AF_FOO. This will make it possible to drop in alternative wrapper functions which won't have to make up a pointless ADDRTYPE.
This commit is contained in:
parent
04cc999b50
commit
3d15342fe8
@ -1128,8 +1128,8 @@ Socket *sk_new(SockAddr *addr, int port, bool privport, bool oobinline,
|
|||||||
return &ret->sock;
|
return &ret->sock;
|
||||||
}
|
}
|
||||||
|
|
||||||
Socket *sk_newlistener(const char *srcaddr, int port, Plug *plug,
|
Socket *sk_newlistener_internal(const char *srcaddr, int port, Plug *plug,
|
||||||
bool local_host_only, int orig_address_family)
|
bool local_host_only, int orig_address_family)
|
||||||
{
|
{
|
||||||
SOCKET s;
|
SOCKET s;
|
||||||
#ifndef NO_IPV6
|
#ifndef NO_IPV6
|
||||||
@ -1144,7 +1144,7 @@ Socket *sk_newlistener(const char *srcaddr, int port, Plug *plug,
|
|||||||
NetSocket *ret;
|
NetSocket *ret;
|
||||||
int retcode;
|
int retcode;
|
||||||
|
|
||||||
int address_family;
|
int address_family = orig_address_family;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Create NetSocket structure.
|
* Create NetSocket structure.
|
||||||
@ -1164,16 +1164,6 @@ Socket *sk_newlistener(const char *srcaddr, int port, Plug *plug,
|
|||||||
ret->parent = ret->child = NULL;
|
ret->parent = ret->child = NULL;
|
||||||
ret->addr = NULL;
|
ret->addr = NULL;
|
||||||
|
|
||||||
/*
|
|
||||||
* Translate address_family from platform-independent constants
|
|
||||||
* into local reality.
|
|
||||||
*/
|
|
||||||
address_family = (orig_address_family == ADDRTYPE_IPV4 ? AF_INET :
|
|
||||||
#ifndef NO_IPV6
|
|
||||||
orig_address_family == ADDRTYPE_IPV6 ? AF_INET6 :
|
|
||||||
#endif
|
|
||||||
AF_UNSPEC);
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Our default, if passed the `don't care' value
|
* Our default, if passed the `don't care' value
|
||||||
* ADDRTYPE_UNSPEC, is to listen on IPv4. If IPv6 is supported,
|
* ADDRTYPE_UNSPEC, is to listen on IPv4. If IPv6 is supported,
|
||||||
@ -1311,9 +1301,9 @@ Socket *sk_newlistener(const char *srcaddr, int port, Plug *plug,
|
|||||||
* If we were given ADDRTYPE_UNSPEC, we must also create an
|
* If we were given ADDRTYPE_UNSPEC, we must also create an
|
||||||
* IPv6 listening socket and link it to this one.
|
* IPv6 listening socket and link it to this one.
|
||||||
*/
|
*/
|
||||||
if (address_family == AF_INET && orig_address_family == ADDRTYPE_UNSPEC) {
|
if (address_family == AF_INET && orig_address_family == AF_UNSPEC) {
|
||||||
Socket *other = sk_newlistener(srcaddr, port, plug,
|
Socket *other = sk_newlistener_internal(srcaddr, port, plug,
|
||||||
local_host_only, ADDRTYPE_IPV6);
|
local_host_only, AF_INET6);
|
||||||
|
|
||||||
if (other) {
|
if (other) {
|
||||||
NetSocket *ns = container_of(other, NetSocket, sock);
|
NetSocket *ns = container_of(other, NetSocket, sock);
|
||||||
@ -1330,6 +1320,23 @@ Socket *sk_newlistener(const char *srcaddr, int port, Plug *plug,
|
|||||||
return &ret->sock;
|
return &ret->sock;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Socket *sk_newlistener(const char *srcaddr, int port, Plug *plug,
|
||||||
|
bool local_host_only, int orig_address_family)
|
||||||
|
{
|
||||||
|
/*
|
||||||
|
* Translate address_family from platform-independent constants
|
||||||
|
* into local reality.
|
||||||
|
*/
|
||||||
|
int address_family = (orig_address_family == ADDRTYPE_IPV4 ? AF_INET :
|
||||||
|
#ifndef NO_IPV6
|
||||||
|
orig_address_family == ADDRTYPE_IPV6 ? AF_INET6 :
|
||||||
|
#endif
|
||||||
|
AF_UNSPEC);
|
||||||
|
|
||||||
|
return sk_newlistener_internal(srcaddr, port, plug, local_host_only,
|
||||||
|
address_family);
|
||||||
|
}
|
||||||
|
|
||||||
static void sk_net_close(Socket *sock)
|
static void sk_net_close(Socket *sock)
|
||||||
{
|
{
|
||||||
NetSocket *s = container_of(sock, NetSocket, sock);
|
NetSocket *s = container_of(sock, NetSocket, sock);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user