add a tor_dup_addr() function to simplify malloc()+tor_inet_ntoa()

svn:r4838
This commit is contained in:
Roger Dingledine 2005-08-26 07:37:07 +00:00
parent e68bed8782
commit d5e426ab51
3 changed files with 16 additions and 0 deletions

View File

@ -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. */

View File

@ -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

View File

@ -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);