Main Page | Modules | Alphabetical List | Data Structures | File List | Data Fields | Globals | Related Pages

host_addr.h File Reference


Detailed Description

Host address functions.

Author:
Christian Biere
Date:
2005

#include "common.h"
#include "misc.h"

Go to the source code of this file.

Defines

#define host_addr_initialized(x)   TRUE
#define host_addr_net(x)   (((void) (x)), NET_TYPE_IPV4)
#define host_addr_family(x)   (((void) (x)), AF_INET)
#define host_addr_ipv4(x)   (x)
#define host_addr_set_ipv4(x)   (x)
#define host_addr_set_net(x, y)   G_STMT_START { (void) ((x), (y)) } G_STMT_END
#define is_host_addr(x)   (0 != (x))
#define host_addr_equal(a, b)   ((a) == (b))
#define host_addr_cmp(a, b)   (CMP((a), (b)))
#define host_addr_hash(x)   (x)
#define zero_host_addr   0

Typedefs

typedef guint32 host_addr_t
 
Attention:
: Always in host byte order!



Enumerations

enum  net_type { NET_TYPE_NONE = 0, NET_TYPE_IPV4 = 4, NET_TYPE_IPV6 = 6 }

Functions

gboolean host_addr_convert (const host_addr_t from, host_addr_t *to, enum net_type to_net)
gboolean host_addr_6to4_to_ipv4 (const host_addr_t unused_from, host_addr_t *to)
G_GNUC_CONST WARN_UNUSED_RESULT
gboolean 
host_addr_matches (guint32 a, guint32 b, guint8 bits)
guint host_addr_hash_func (gconstpointer key)
gboolean host_addr_eq_func (gconstpointer p, gconstpointer q)
void wfree_host_addr (gpointer key, gpointer unused_data)
gboolean is_private_addr (const host_addr_t addr)
 Checks for RFC1918 private addresses.

gboolean host_addr_is_routable (const host_addr_t addr)
 Check whether host can be reached from the Internet.

gboolean host_addr_is_loopback (const host_addr_t addr)
 Checks whether the given address is 127.0.0.1 or ::1.

const gchar * host_addr_to_string (const host_addr_t addr)
 Prints the host address ``ha'' to a static buffer.

size_t host_addr_to_string_buf (const host_addr_t addr, gchar *, size_t)
 Prints the host address ``ha'' to ``dst''.

host_addr_t string_to_host_addr (const gchar *s, const gchar **endptr)
const gchar * host_addr_port_to_string (const host_addr_t addr, guint16 port)
 Prints the host address ``ha'' followed by ``port'' to a static buffer.

size_t host_addr_port_to_string_buf (const host_addr_t addr, guint16 port, gchar *, size_t)
 Prints the host address ``ha'' followed by ``port'' to ``dst''.

gboolean string_to_host_addr_port (const gchar *str, const gchar **endptr, host_addr_t *addr_ptr, guint16 *port_ptr)
host_addr_t name_to_host_addr (const gchar *host)
 Resolves a hostname to an IP address per DNS.

const gchar * host_addr_to_name (const host_addr_t addr)
 Resolves an IP address to a hostname per DNS.

gboolean string_to_host_or_addr (const char *s, const gchar **endptr, host_addr_t *ha)
 Parses the NUL-terminated string ``s'' for a host address or a hostname.


Define Documentation

#define host_addr_cmp a,
 )     (CMP((a), (b)))
 

#define host_addr_equal a,
 )     ((a) == (b))
 

#define host_addr_family  )     (((void) (x)), AF_INET)
 

#define host_addr_hash  )     (x)
 

#define host_addr_initialized  )     TRUE
 

#define host_addr_ipv4  )     (x)
 

#define host_addr_net  )     (((void) (x)), NET_TYPE_IPV4)
 

#define host_addr_set_ipv4  )     (x)
 

#define host_addr_set_net x,
 )     G_STMT_START { (void) ((x), (y)) } G_STMT_END
 

#define is_host_addr  )     (0 != (x))
 

#define zero_host_addr   0
 


Typedef Documentation

typedef guint32 host_addr_t
 

Attention:
: Always in host byte order!


Enumeration Type Documentation

enum net_type
 

Enumeration values:
NET_TYPE_NONE 
NET_TYPE_IPV4 
NET_TYPE_IPV6 


Function Documentation

gboolean host_addr_6to4_to_ipv4 const host_addr_t  unused_from,
host_addr_t to
[inline, static]
 

gboolean host_addr_convert const host_addr_t  from,
host_addr_t to,
enum net_type  to_net
[inline, static]
 

gboolean host_addr_eq_func gconstpointer  p,
gconstpointer  q
 

guint host_addr_hash_func gconstpointer  key  ) 
 

gboolean host_addr_is_loopback const host_addr_t  addr  ) 
 

Checks whether the given address is 127.0.0.1 or ::1.

gboolean host_addr_is_routable const host_addr_t  addr  ) 
 

Check whether host can be reached from the Internet.

We rule out IPs of private networks, plus some other invalid combinations.

G_GNUC_CONST WARN_UNUSED_RESULT gboolean host_addr_matches guint32  a,
guint32  b,
guint8  bits
[inline, static]
 

const gchar* host_addr_port_to_string const host_addr_t  ha,
guint16  port
 

Prints the host address ``ha'' followed by ``port'' to a static buffer.

Parameters:
ha the host address.
port the port number.
Returns:
a pointer to a static buffer holding a NUL-terminated string representing the given host address and port.

size_t host_addr_port_to_string_buf const host_addr_t  ha,
guint16  port,
gchar *  dst,
size_t  size
 

Prints the host address ``ha'' followed by ``port'' to ``dst''.

The string written to ``dst'' is always NUL-terminated unless ``size'' is zero. If ``size'' is too small, the string will be truncated.

Parameters:
dst the destination buffer; may be NULL iff ``size'' is zero.
ha the host address.
port the port number.
size the size of ``dst'' in bytes.
Returns:
The length of the resulting string assuming ``size'' is sufficient.

const gchar* host_addr_to_name const host_addr_t  addr  ) 
 

Resolves an IP address to a hostname per DNS.

Todo:
TODO: Use getnameinfo() if available.
Parameters:
ha The host address to resolve.
Returns:
On success, the hostname is returned. Otherwise, NULL is returned. The resulting string points to a static buffer.

const gchar* host_addr_to_string const host_addr_t  ha  ) 
 

Prints the host address ``ha'' to a static buffer.

Parameters:
ha the host address.
Returns:
a pointer to a static buffer holding a NUL-terminated string representing the given host address.

size_t host_addr_to_string_buf const host_addr_t  ha,
gchar *  dst,
size_t  size
 

Prints the host address ``ha'' to ``dst''.

The string written to ``dst'' is always NUL-terminated unless ``size'' is zero. If ``size'' is too small, the string will be truncated.

Parameters:
dst the destination buffer; may be NULL iff ``size'' is zero.
ha the host address.
size the size of ``dst'' in bytes.
Returns:
The length of the resulting string assuming ``size'' is sufficient.

gboolean is_private_addr const host_addr_t  ha  ) 
 

Checks for RFC1918 private addresses.

Returns:
TRUE if is a private address.

host_addr_t name_to_host_addr const gchar *  host  ) 
 

Resolves a hostname to an IP address per DNS.

Todo:
TODO: This should return all resolved address not just the first and it should be possible to request only IPv4 or IPv6 addresses.
Parameters:
host A NUL-terminated string holding the hostname to resolve.
Returns:
On success, the first address IPv4 or IPv6 address is returned. On failure, zero_host_addr is returned.

host_addr_t string_to_host_addr const gchar *  s,
const gchar **  endptr
 

gboolean string_to_host_addr_port const gchar *  str,
const gchar **  endptr,
host_addr_t addr_ptr,
guint16 *  port_ptr
 

gboolean string_to_host_or_addr const char *  s,
const gchar **  endptr,
host_addr_t ha
 

Parses the NUL-terminated string ``s'' for a host address or a hostname.

If ``s'' points to a parsable address, ``*ha'' will be set to it. Otherwise, ``*ha'' is set to ``zero_host_addr''. If the string is a possible hostname the function returns TRUE nonetheless and ``*endptr'' will point to the first character after hostname. If IPv6 support is disabled, "[::]" will be considered a hostname rather than a host address.

Parameters:
s the string to parse.
endptr if not NULL, it will point the first character after the parsed host address or hostname.
ha if not NULL, it is set to the parsed host address or ``zero_host_addr'' on failure.
Returns:
TRUE if the string points to host address or is a possible hostname.

void wfree_host_addr gpointer  key,
gpointer  unused_data
 


Generated on Sun Feb 12 10:50:03 2006 for Gtk-Gnutella by doxygen 1.3.6