mirror of
https://gitlab.torproject.org/tpo/core/tor.git
synced 2024-11-13 14:43:46 +01:00
Add a new tor_addr_from_getsockname()
We use this pattern all over, and this should simplify matters a bit. Part of 18105.
This commit is contained in:
parent
7a74b3663f
commit
2a7bfec364
@ -1392,6 +1392,24 @@ tor_getsockname,(tor_socket_t sock, struct sockaddr *address,
|
|||||||
return getsockname(sock, address, address_len);
|
return getsockname(sock, address, address_len);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Find the local address associated with the socket <b>sock</b>, and
|
||||||
|
* place it in *<b>addr_out</b>. Return 0 on success, -1 on failure.
|
||||||
|
*
|
||||||
|
* (As tor_getsockname, but instead places the result in a tor_addr_t.) */
|
||||||
|
int
|
||||||
|
tor_addr_from_getsockname(tor_addr_t *addr_out, tor_socket_t sock)
|
||||||
|
{
|
||||||
|
struct sockaddr_storage ss;
|
||||||
|
socklen_t ss_len = sizeof(ss);
|
||||||
|
memset(ss, 0, sizeof(ss));
|
||||||
|
|
||||||
|
if (tor_getsockname(sock, (struct sockaddr *) &ss, &ss_len) < 0)
|
||||||
|
return -1;
|
||||||
|
|
||||||
|
return tor_addr_from_sockaddr(addr_out, (struct sockaddr *)&ss, NULL);
|
||||||
|
}
|
||||||
|
|
||||||
/** Turn <b>socket</b> into a nonblocking socket. Return 0 on success, -1
|
/** Turn <b>socket</b> into a nonblocking socket. Return 0 on success, -1
|
||||||
* on failure.
|
* on failure.
|
||||||
*/
|
*/
|
||||||
|
@ -510,6 +510,8 @@ int get_n_open_sockets(void);
|
|||||||
MOCK_DECL(int,
|
MOCK_DECL(int,
|
||||||
tor_getsockname,(tor_socket_t socket, struct sockaddr *address,
|
tor_getsockname,(tor_socket_t socket, struct sockaddr *address,
|
||||||
socklen_t *address_len));
|
socklen_t *address_len));
|
||||||
|
struct tor_addr_t;
|
||||||
|
int tor_addr_from_getsockname(struct tor_addr_t *addr_out, tor_socket_t sock);
|
||||||
|
|
||||||
#define tor_socket_send(s, buf, len, flags) send(s, buf, len, flags)
|
#define tor_socket_send(s, buf, len, flags) send(s, buf, len, flags)
|
||||||
#define tor_socket_recv(s, buf, len, flags) recv(s, buf, len, flags)
|
#define tor_socket_recv(s, buf, len, flags) recv(s, buf, len, flags)
|
||||||
|
Loading…
Reference in New Issue
Block a user