mirror of
https://gitlab.torproject.org/tpo/core/tor.git
synced 2024-11-28 14:23:30 +01:00
add a tor_dup_addr() function to simplify malloc()+tor_inet_ntoa()
svn:r4838
This commit is contained in:
parent
e68bed8782
commit
d5e426ab51
@ -579,6 +579,7 @@ tor_lookup_hostname(const char *name, uint32_t *addr)
|
||||
* something.
|
||||
*/
|
||||
struct in_addr iaddr;
|
||||
tor_assert(name);
|
||||
tor_assert(addr);
|
||||
if (!*name) {
|
||||
/* Empty address is an error. */
|
||||
|
@ -1314,6 +1314,20 @@ tor_inet_ntoa(struct in_addr *in, char *buf, size_t buf_len)
|
||||
(int)(uint8_t)((a )&0xff));
|
||||
}
|
||||
|
||||
/** Given a host-order <b>addr</b>, call tor_inet_ntoa() on it
|
||||
* and return a strdup of the resulting address.
|
||||
*/
|
||||
char *
|
||||
tor_dup_addr(uint32_t addr)
|
||||
{
|
||||
char buf[INET_NTOA_BUF_LEN];
|
||||
struct in_addr in;
|
||||
|
||||
in.s_addr = htonl(addr);
|
||||
tor_inet_ntoa(&in, buf, sizeof(buf));
|
||||
return tor_strdup(buf);
|
||||
}
|
||||
|
||||
/* Return true iff <b>name</b> looks like it might be a hostname or IP
|
||||
* address of some kind. */
|
||||
int
|
||||
|
@ -134,6 +134,7 @@ int parse_addr_and_port_range(const char *s, uint32_t *addr_out,
|
||||
uint16_t *port_max_out);
|
||||
#define INET_NTOA_BUF_LEN 16
|
||||
int tor_inet_ntoa(struct in_addr *in, char *buf, size_t buf_len);
|
||||
char *tor_dup_addr(uint32_t addr);
|
||||
int is_plausible_address(const char *name);
|
||||
int get_interface_address(uint32_t *addr);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user