Skip to content
This repository has been archived by the owner on Apr 19, 2024. It is now read-only.

Commit

Permalink
restore sk_getport
Browse files Browse the repository at this point in the history
  • Loading branch information
FauxFaux committed Feb 26, 2017
1 parent 0e35f86 commit 8ae0114
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
2 changes: 2 additions & 0 deletions network.h
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,8 @@ Socket sk_new(SockAddr addr, int port, int privport, int oobinline,
Socket sk_newlistener(const char *srcaddr, int port, Plug plug,
int local_host_only, int address_family);

int sk_getport(Socket s);

#define sk_plug(s,p) (((*s)->plug) (s, p))
#define sk_close(s) (((*s)->close) (s))
#define sk_write(s,buf,len) (((*s)->write) (s, buf, len))
Expand Down
23 changes: 23 additions & 0 deletions windows/winnet.c
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,9 @@ DECL_WINDOWS_FUNCTION(static, int, WSAIoctl,
(SOCKET, DWORD, LPVOID, DWORD, LPVOID, DWORD,
LPDWORD, LPWSAOVERLAPPED,
LPWSAOVERLAPPED_COMPLETION_ROUTINE));
DECL_WINDOWS_FUNCTION(static, int, getsockname,
(SOCKET, const struct sockaddr FAR *, int FAR *));

#ifndef NO_IPV6
DECL_WINDOWS_FUNCTION(static, int, getaddrinfo,
(const char *nodename, const char *servname,
Expand Down Expand Up @@ -323,6 +326,7 @@ void sk_init(void)
GET_WINDOWS_FUNCTION(winsock_module, getpeername);
GET_WINDOWS_FUNCTION(winsock_module, recv);
GET_WINDOWS_FUNCTION(winsock_module, WSAIoctl);
GET_WINDOWS_FUNCTION(winsock_module, getsockname);

/* Try to get the best WinSock version we can get */
if (!sk_startup(2,2) &&
Expand Down Expand Up @@ -1430,6 +1434,25 @@ Socket sk_newlistener(const char *srcaddr, int port, Plug plug,
return (Socket) ret;
}

int sk_getport(Socket sock)
{
/* I won't even try to get IPv6 working here since it is apparently borken
* in this release of PuTTY */
SOCKADDR_IN a;
socklen_t salen;
int retcode;
Actual_Socket s = (Actual_Socket)sock;

salen = sizeof(a);
retcode = p_getsockname(s->s, (struct sockaddr *) &a, &salen);

if (retcode != 0)
return -1;

return p_ntohs(a.sin_port);
}


static void sk_tcp_close(Socket sock)
{
extern char *do_select(SOCKET skt, int startup);
Expand Down

0 comments on commit 8ae0114

Please sign in to comment.