Tor  0.4.7.0-alpha-dev
Macros | Functions
inaddr.h File Reference

Header for inaddr.c. More...

#include "orconfig.h"
#include <stddef.h>

Go to the source code of this file.

Macros

#define INET_NTOA_BUF_LEN   16
 

Functions

int tor_inet_aton (const char *str, struct in_addr *addr)
 
int tor_inet_ntoa (const struct in_addr *in, char *buf, size_t buf_len)
 
const char * tor_inet_ntop (int af, const void *src, char *dst, size_t len)
 
int tor_inet_pton (int af, const char *src, void *dst)
 

Detailed Description

Header for inaddr.c.

Definition in file inaddr.h.

Macro Definition Documentation

◆ INET_NTOA_BUF_LEN

#define INET_NTOA_BUF_LEN   16

Length of a buffer to allocate to hold the results of tor_inet_ntoa.

Definition at line 21 of file inaddr.h.

Function Documentation

◆ tor_inet_aton()

int tor_inet_aton ( const char *  str,
struct in_addr *  addr 
)

Set *addr to the IP address (in dotted-quad notation) stored in *str. Return 1 on success, 0 if *str is badly formatted. (Like inet_aton(str,addr), but works on Windows and Solaris.)

Definition at line 40 of file inaddr.c.

Referenced by router_find_exact_exit_enclave(), tor_addr_parse_PTR_name(), and tor_inet_pton().

◆ tor_inet_ntoa()

int tor_inet_ntoa ( const struct in_addr *  in,
char *  buf,
size_t  buf_len 
)

Given an IPv4 in_addr struct *in (in network order, as usual), write it as a string into the buf_len-byte buffer in buf. Returns a non-negative integer on success. Returns -1 on failure.

Definition at line 79 of file inaddr.c.

Referenced by fmt_addr32(), and tor_inet_ntop().

◆ tor_inet_ntop()

const char* tor_inet_ntop ( int  af,
const void *  src,
char *  dst,
size_t  len 
)

Given af==AF_INET and src a struct in_addr, or af==AF_INET6 and src a struct in6_addr, try to format the address and store it in the len-byte buffer dst. Returns dst on success, NULL on failure.

(Like inet_ntop(af,src,dst,len), but works on platforms that don't have it: Tor sometimes needs to format ipv6 addresses even on platforms without ipv6 support.)

Definition at line 98 of file inaddr.c.

Referenced by tor_addr_to_str(), and tor_dup_ip().

◆ tor_inet_pton()

int tor_inet_pton ( int  af,
const char *  src,
void *  dst 
)

Given af==AF_INET or af==AF_INET6, and a string src encoding an IPv4 address or IPv6 address correspondingly, try to parse the address and store the result in dst (which must have space for a struct in_addr or a struct in6_addr, as appropriate). Return 1 on success, 0 on a bad parse, and -1 on a bad af.

(Like inet_pton(af,src,dst) but works on platforms that don't have it: Tor sometimes needs to format ipv6 addresses even on platforms without ipv6 support.)

Definition at line 187 of file inaddr.c.

Referenced by string_is_valid_ipv4_address(), and string_is_valid_ipv6_address().