Internet address

Name

Internet address -- Internet address.

Synopsis



GInetAddr*  gnet_inetaddr_new               (const gchar *name,
                                             gint port);
GInetAddr*  gnet_inetaddr_new_any           (void);
GInetAddr*  gnet_inetaddr_new_nonblock      (const gchar *name,
                                             gint port);
GInetAddrNewAsyncID gnet_inetaddr_new_async (const gchar *name,
                                             gint port,
                                             GInetAddrNewAsyncFunc func,
                                             gpointer data);
void        gnet_inetaddr_new_async_cancel  (GInetAddrNewAsyncID id);
typedef     GInetAddrNewAsyncID;
void        (*GInetAddrNewAsyncFunc)        (GInetAddr *inetaddr,
                                             GInetAddrAsyncStatus status,
                                             gpointer data);
enum        GInetAddrAsyncStatus;
GInetAddr*  gnet_inetaddr_clone             (const GInetAddr *ia);
void        gnet_inetaddr_delete            (GInetAddr *ia);
void        gnet_inetaddr_ref               (GInetAddr *ia);
void        gnet_inetaddr_unref             (GInetAddr *ia);
gchar*      gnet_inetaddr_get_name          (GInetAddr *ia);
gchar*      gnet_inetaddr_get_name_nonblock (GInetAddr *ia);
GInetAddrGetNameAsyncID gnet_inetaddr_get_name_async
                                            (GInetAddr *ia,
                                             GInetAddrGetNameAsyncFunc func,
                                             gpointer data);
void        gnet_inetaddr_get_name_async_cancel
                                            (GInetAddrGetNameAsyncID id);
typedef     GInetAddrGetNameAsyncID;
void        (*GInetAddrGetNameAsyncFunc)    (GInetAddr *inetaddr,
                                             GInetAddrAsyncStatus status,
                                             gchar *name,
                                             gpointer data);
gchar*      gnet_inetaddr_get_canonical_name
                                            (const GInetAddr *ia);
gint        gnet_inetaddr_get_port          (const GInetAddr *ia);
void        gnet_inetaddr_set_port          (const GInetAddr *ia,
                                             guint port);
gboolean    gnet_inetaddr_is_canonical      (const gchar *name);
gboolean    gnet_inetaddr_is_internet       (const GInetAddr *inetaddr);
gboolean    gnet_inetaddr_is_private        (const GInetAddr *inetaddr);
gboolean    gnet_inetaddr_is_reserved       (const GInetAddr *inetaddr);
gboolean    gnet_inetaddr_is_loopback       (const GInetAddr *inetaddr);
gboolean    gnet_inetaddr_is_multicast      (const GInetAddr *inetaddr);
gboolean    gnet_inetaddr_is_broadcast      (const GInetAddr *inetaddr);
gchar*      gnet_inetaddr_gethostname       (void);
GInetAddr*  gnet_inetaddr_gethostaddr       (void);
GInetAddr*  gnet_inetaddr_autodetect_internet_interface
                                            (void);
GInetAddr*  gnet_inetaddr_get_interface_to  (const GInetAddr *addr);
GInetAddr*  gnet_inetaddr_get_internet_interface
                                            (void);
gboolean    gnet_inetaddr_is_internet_domainname
                                            (const gchar *name);
GList*      gnet_inetaddr_list_interfaces   (void);
guint       gnet_inetaddr_hash              (gconstpointer p);
gint        gnet_inetaddr_equal             (gconstpointer p1,
                                             gconstpointer p2);
gint        gnet_inetaddr_noport_equal      (gconstpointer p1,
                                             gconstpointer p2);

Description

InetAddr represents an internet address. Currently, only IP version 4 addresses are used (eg, addresses in the form 141.213.8.59).

Details

gnet_inetaddr_new ()

GInetAddr*  gnet_inetaddr_new               (const gchar *name,
                                             gint port);

Create an internet address from a name and port. This function may block.

name : a nice name (eg, mofo.eecs.umich.edu) or a dotted decimal name (eg, 141.213.8.59). You can delete the after the function is called.
port : port number (0 if the port doesn't matter)
Returns : a new GInetAddr, or NULL if there was a failure.


gnet_inetaddr_new_any ()

GInetAddr*  gnet_inetaddr_new_any           (void);

Create a GInetAddr with the address INADDR_ANY and port 0. This is useful for creating default addresses for binding. The address's name will be "<INADDR_ANY>".

Returns : INADDR_ANY GInetAddr.


gnet_inetaddr_new_nonblock ()

GInetAddr*  gnet_inetaddr_new_nonblock      (const gchar *name,
                                             gint port);

Create an internet address from a name and port, but don't block and fail if it would require blocking. This is, if the name is a canonical name or "localhost", it returns the address. Otherwise, it returns NULL.

name : a nice name (eg, mofo.eecs.umich.edu) or a dotted decimal name (eg, 141.213.8.59). You can delete the after the function is called.
port : port number (0 if the port doesn't matter)
Returns : a new GInetAddr, or NULL if there was a failure or it would require blocking.


gnet_inetaddr_new_async ()

GInetAddrNewAsyncID gnet_inetaddr_new_async (const gchar *name,
                                             gint port,
                                             GInetAddrNewAsyncFunc func,
                                             gpointer data);

Create a GInetAddr from a name and port asynchronously. The callback is called once the structure is created or an error occurs during lookup. The callback will not be called during the call to gnet_inetaddr_new_async().

The Unix version creates a pthread thread which does the lookup. If pthreads aren't available, it forks and does the lookup. Forking will be slow or even fail when using operating systems that copy the entire process when forking.

If you need to lookup hundreds of addresses, we recommend calling g_main_iteration(FALSE) between calls. This will help prevent an explosion of threads or processes.

If you need a more robust library for Unix, look at <ulink url="http://www.gnu.org/software/adns/adns.html">GNU ADNS</ulink>. GNU ADNS is under the GNU GPL. This library does not use threads or processes.

The Windows version should work fine. Windows has an asynchronous DNS lookup function.

name : a nice name (eg, mofo.eecs.umich.edu) or a dotted decimal name (eg, 141.213.8.59). You can delete the after the function is called.
port : port number (0 if the port doesn't matter)
func : Callback function.
data : User data passed when callback function is called.
Returns : ID of the lookup which can be used with gnet_inetaddr_new_async_cancel() to cancel it; NULL on failure.


gnet_inetaddr_new_async_cancel ()

void        gnet_inetaddr_new_async_cancel  (GInetAddrNewAsyncID id);

Cancel an asynchronous GInetAddr creation that was started with gnet_inetaddr_new_async().

id : ID of the lookup


GInetAddrNewAsyncID

ID of an asynchronous InetAddr creation started with gnet_inetaddr_new_async(). The creation can be canceled by calling gnet_inetaddr_new_async_cancel() with the ID.


GInetAddrNewAsyncFunc ()

void        (*GInetAddrNewAsyncFunc)        (GInetAddr *inetaddr,
                                             GInetAddrAsyncStatus status,
                                             gpointer data);

Caller owns the address; the callee should copy it if necessary.

Callback for gnet_inetaddr_new_async().

inetaddr : InetAddr that was looked up
status : Status of the lookup
data : User data


enum GInetAddrAsyncStatus

typedef enum {
  GINETADDR_ASYNC_STATUS_OK,
  GINETADDR_ASYNC_STATUS_ERROR
} GInetAddrAsyncStatus;

Status of a asynchronous lookup (from gnet_inetaddr_new_async() or gnet_inetaddr_get_name_async()), passed by GInetAddrNewAsyncFunc or GInetAddrGetNameAsyncFunc. More errors may be added in the future, so it's best to compare against GINETADDR_ASYNC_STATUS_OK.


gnet_inetaddr_clone ()

GInetAddr*  gnet_inetaddr_clone             (const GInetAddr *ia);

Create an internet address from another one.

ia : Address to clone
Returns : a new InetAddr, or NULL if there was a failure.


gnet_inetaddr_delete ()

void        gnet_inetaddr_delete            (GInetAddr *ia);

Delete a GInetAddr.

ia : GInetAddr to delete


gnet_inetaddr_ref ()

void        gnet_inetaddr_ref               (GInetAddr *ia);

Increment the reference counter of the GInetAddr.

ia : GInetAddr to reference


gnet_inetaddr_unref ()

void        gnet_inetaddr_unref             (GInetAddr *ia);

Remove a reference from the GInetAddr. When reference count reaches 0, the address is deleted.

ia : GInetAddr to unreference


gnet_inetaddr_get_name ()

gchar*      gnet_inetaddr_get_name          (GInetAddr *ia);

Get the nice name of the address (eg, "mofo.eecs.umich.edu"). The "nice name" is the domain name if it has one or the canonical name if it does not. Be warned that this call may block since it may need to do a reverse DNS lookup.

ia : Address to get the name of.
Returns : the nice name of the host, or NULL if there was an error. The caller is responsible for deleting the returned string.


gnet_inetaddr_get_name_nonblock ()

gchar*      gnet_inetaddr_get_name_nonblock (GInetAddr *ia);

Get the nice name of the address, but don't block and fail if it would require blocking.

ia : Address to get the name of.
Returns : the nice name of the host, or NULL if there was an error or it would require blocking. The caller is responsible for deleting the returned string.


gnet_inetaddr_get_name_async ()

GInetAddrGetNameAsyncID gnet_inetaddr_get_name_async
                                            (GInetAddr *ia,
                                             GInetAddrGetNameAsyncFunc func,
                                             gpointer data);

Get the nice name of the address (eg, "mofo.eecs.umich.edu"). This function will use the callback once it knows the nice name. The callback will not be called during the call to gnet_inetaddr_new_async().

The Unix uses either pthreads or fork(). See the notes for gnet_inetaddr_new_async().

ia : Address to get the name of.
func : Callback function.
data : User data passed when callback function is called.
Returns : ID of the lookup which can be used with gnet_inetaddrr_get_name_async_cancel() to cancel it; NULL on failure.


gnet_inetaddr_get_name_async_cancel ()

void        gnet_inetaddr_get_name_async_cancel
                                            (GInetAddrGetNameAsyncID id);

Cancel an asynchronous nice name lookup that was started with gnet_inetaddr_get_name_async().

id : ID of the lookup


GInetAddrGetNameAsyncID

ID of an asynchronous InetAddr name lookup started with gnet_inetaddr_get_name_async(). The lookup can be canceled by calling gnet_inetaddr_get_name_async_cancel() with the ID.


GInetAddrGetNameAsyncFunc ()

void        (*GInetAddrGetNameAsyncFunc)    (GInetAddr *inetaddr,
                                             GInetAddrAsyncStatus status,
                                             gchar *name,
                                             gpointer data);

Callback for gnet_inetaddr_get_name_async(). Delete the name when you're done with it. The GInetAddr is the GInetAddr passed to gnet_inetaddr_get_name_async() -- the address is not copied. (FIX: In 1.2.0, don't pass the InetAddr.)

inetaddr : InetAddr whose was looked up
status : Status of the lookup
name : Nice name of the address
data : User data


gnet_inetaddr_get_canonical_name ()

gchar*      gnet_inetaddr_get_canonical_name
                                            (const GInetAddr *ia);

Get the "canonical" name of an address (eg, for IP4 the dotted decimal name 141.213.8.59).

ia : Address to get the canonical name of.
Returns : NULL if there was an error. The caller is responsible for deleting the returned string.


gnet_inetaddr_get_port ()

gint        gnet_inetaddr_get_port          (const GInetAddr *ia);

Get the port number.

ia : Address to get the port number of.
Returns : the port number.


gnet_inetaddr_set_port ()

void        gnet_inetaddr_set_port          (const GInetAddr *ia,
                                             guint port);

Set the port number.

ia : Address to set the port number of.
port : New port number


gnet_inetaddr_is_canonical ()

gboolean    gnet_inetaddr_is_canonical      (const gchar *name);

Check if the domain name is canonical. For IPv4, a canonical name is a dotted decimal name (eg, 141.213.8.59).

name : Name to check
Returns : TRUE if name is canonical; FALSE otherwise.


gnet_inetaddr_is_internet ()

gboolean    gnet_inetaddr_is_internet       (const GInetAddr *inetaddr);

Check if the address is a sensible internet address. This mean it is not private, reserved, loopback, multicast, or broadcast.

Note that private and loopback address are often valid addresses, so this should only be used to check for general Internet connectivity. That is, if the address passes, it is reachable on the Internet.

inetaddr : Address to check
Returns : TRUE if the address is an 'Internet' address; FALSE otherwise.


gnet_inetaddr_is_private ()

gboolean    gnet_inetaddr_is_private        (const GInetAddr *inetaddr);

Check if the address is an address reserved for private networks or something else. This includes:

10.0.0.0 - 10.255.255.255 (10/8 prefix) 172.16.0.0 - 172.31.255.255 (172.16/12 prefix) 192.168.0.0 - 192.168.255.255 (192.168/16 prefix)

(from RFC 1918. See also draft-manning-dsua-02.txt)

inetaddr : Address to check
Returns : TRUE if the address is reserved for private networks; FALSE otherwise.


gnet_inetaddr_is_reserved ()

gboolean    gnet_inetaddr_is_reserved       (const GInetAddr *inetaddr);

Check if the address is reserved for 'something'. This excludes address reserved for private networks.

We check for: 0.0.0.0/16 (top 16 bits are 0's) Class E (top 5 bits are 11110)

inetaddr : Address to check
Returns : TRUE if the address is reserved for something; FALSE otherwise.


gnet_inetaddr_is_loopback ()

gboolean    gnet_inetaddr_is_loopback       (const GInetAddr *inetaddr);

Check if the address is a loopback address. Loopback addresses have the prefix 127.0.0.1/16.

inetaddr : Address to check
Returns : TRUE if the address is a loopback address; FALSE otherwise.


gnet_inetaddr_is_multicast ()

gboolean    gnet_inetaddr_is_multicast      (const GInetAddr *inetaddr);

Check if the address is a multicast address. Multicast address are in the range 224.0.0.1 - 239.255.255.255 (ie, the top four bits are 1110).

inetaddr : Address to check
Returns : TRUE if the address is a multicast address; FALSE otherwise.


gnet_inetaddr_is_broadcast ()

gboolean    gnet_inetaddr_is_broadcast      (const GInetAddr *inetaddr);

Check if the address is a broadcast address. The broadcast address is 255.255.255.255. (Network broadcast address are network dependent.)

inetaddr : Address to check
Returns : TRUE if the address is a broadcast address; FALSE otherwise.


gnet_inetaddr_gethostname ()

gchar*      gnet_inetaddr_gethostname       (void);

Get the primary host's name.

Returns : the name of the host; NULL if there was an error. The caller is responsible for deleting the returned string.


gnet_inetaddr_gethostaddr ()

GInetAddr*  gnet_inetaddr_gethostaddr       (void);

Get the primary host's GInetAddr.

Returns : the GInetAddr of the host; NULL if there was an error. The caller is responsible for deleting the returned GInetAddr.


gnet_inetaddr_autodetect_internet_interface ()

GInetAddr*  gnet_inetaddr_autodetect_internet_interface
                                            (void);

Find an Internet interface. Usually, this interface routes packets to and from the Internet. It can be used to automatically configure simple servers that must advertise their address. This sometimes doesn't work correctly when the user is behind a NAT.

Returns : Address of an Internet interface; NULL if it couldn't find one or there was an error.


gnet_inetaddr_get_interface_to ()

GInetAddr*  gnet_inetaddr_get_interface_to  (const GInetAddr *addr);

Figure out which local interface would be used to send a packet to addr. This works on some systems, but not others. We recommend using gnet_inetaddr_autodetect_internet_interface() to find an Internet interface since it's more likely to work.

addr : address
Returns : Address of an interface used to route packets to addr; NULL if there is no such interface or the system does not support this check.


gnet_inetaddr_get_internet_interface ()

GInetAddr*  gnet_inetaddr_get_internet_interface
                                            (void);

Find an Internet interface. This just calls gnet_inetaddr_list_interfaces() and returns the first one that passes gnet_inetaddr_is_internet(). This works well on some systems, but not so well on others. We recommend using gnet_inetaddr_autodetect_internet_interface() to find an Internet interface since it's more likely to work.

Returns : Address of an Internet interface; NULL if there is no such interface or the system does not support this check.


gnet_inetaddr_is_internet_domainname ()

gboolean    gnet_inetaddr_is_internet_domainname
                                            (const gchar *name);

Check if the domain name is a sensible Internet domain name. This function uses heuristics and does not use DNS (or even block). For example, "localhost" and "10.10.23.42" are not sensible Internet domain names. (10.10.23.42 is a network address, but not accessible to the Internet at large.)

name : Domain name to check
Returns : TRUE if name is a sensible Internet domain name; FALSE otherwise.


gnet_inetaddr_list_interfaces ()

GList*      gnet_inetaddr_list_interfaces   (void);

Get a list of GInetAddr interfaces's on this host. This list includes all "up" Internet interfaces and the loopback interface, if it exists.

Note that the Windows version supports a maximum of 10 interfaces. In Windows NT, Service Pack 4 (or higher) is required.

Returns : A list of GInetAddr's representing available interfaces. The caller should delete the list and the addresses.


gnet_inetaddr_hash ()

guint       gnet_inetaddr_hash              (gconstpointer p);

Hash the address. This is useful for glib containers.

p : Pointer to an GInetAddr.
Returns : hash value.


gnet_inetaddr_equal ()

gint        gnet_inetaddr_equal             (gconstpointer p1,
                                             gconstpointer p2);

Compare two GInetAddr's.

p1 : Pointer to first GInetAddr.
p2 : Pointer to second GInetAddr.
Returns : 1 if they are the same; 0 otherwise.


gnet_inetaddr_noport_equal ()

gint        gnet_inetaddr_noport_equal      (gconstpointer p1,
                                             gconstpointer p2);

Compare two GInetAddr's, but does not compare the port numbers.

p1 : Pointer to first GInetAddr.
p2 : Pointer to second GInetAddr.
Returns : 1 if they are the same; 0 otherwise.