The Assimilation Project  based on Assimilation version
Go to the documentation of this file.
26 #ifndef _NETADDR_H
27 #define _NETADDR_H
28 #include <projectcommon.h>
29 #include <assimobj.h>
30 #ifdef _MSC_VER
31 # include <winsock2.h>
32  typedef int socklen_t;
33 #else
34 # include <netinet/in.h>
35 #endif
36 typedef struct _NetAddr NetAddr;
43 struct _NetAddr {
45  void (*setport)(NetAddr*, guint16);
46  guint16 (*port)(const NetAddr* self);
47  guint16 (*addrtype)(const NetAddr* self);
48  gboolean (*ismcast)(const NetAddr* self);
49  gboolean (*islocal)(const NetAddr* self);
50  gboolean (*isanyaddr)(const NetAddr* self);
51  struct sockaddr_in6(*ipv6sockaddr)(const NetAddr* self);
52  struct sockaddr_in(*ipv4sockaddr)(const NetAddr* self);
53  gboolean (*equal)(const NetAddr*,const NetAddr*);
54  guint (*hash)(const NetAddr*);
55  char * (*canonStr)(const NetAddr*);
56  NetAddr* (*toIPv6)(const NetAddr*);
57  NetAddr* (*toIPv4)(const NetAddr*);
58  gpointer _addrbody;
60  guint16 _addrtype;
61  guint16 _addrlen;
62  guint16 _addrport;
64 };
65 WINEXPORT NetAddr* netaddr_new(gsize objsize, guint16 port, guint16 addrtype, gconstpointer addrbody, guint16 addrlen);
66 WINEXPORT NetAddr* netaddr_sockaddr_new(const struct sockaddr_in6 *, socklen_t);
67 WINEXPORT NetAddr* netaddr_macaddr_new(gconstpointer macbuf, guint16 maclen);
68 WINEXPORT NetAddr* netaddr_mac48_new(gconstpointer macbuf);
69 WINEXPORT NetAddr* netaddr_mac64_new(gconstpointer macbuf);
70 WINEXPORT NetAddr* netaddr_ipv4_new(gconstpointer ipbuf, guint16 port);
71 WINEXPORT NetAddr* netaddr_ipv6_new(gconstpointer ipbuf, guint16 port);
72 WINEXPORT NetAddr* netaddr_string_new(const char* addrstr);
73 WINEXPORT NetAddr* netaddr_dns_new(const char* addrstr);
74 WINEXPORT gboolean netaddr_g_hash_equal(gconstpointer lhs, gconstpointer rhs);
75 WINEXPORT guint netaddr_g_hash_hash(gconstpointer addrptr);
77 #define CONST_IPV6_LOOPBACK {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1}
78 #define CONST_IPV4_LOOPBACK {127,0,0,1}
79 #define CONST_IPV6_IPV4SPACE 0,0,0,0,0,0,0,0,0,0,0xff,0xff
80 #define CONST_IPV6_IPV4START {CONST_IPV6_IPV4SPACE, 0, 0, 0, 0}
81 #define CONST_IPV6_MACSPACE 0xFE, 0x80, 0, 0, 0, 0, 0, 0x02
82 #define CONST_IPV6_MACSTART {CONST_IPV6_MACSPACE, 0, 0, 0, 0, 0, 0, 0, 0}
85 #define CONST_ASSIM_DEFAULT_V4_MCAST {224,0,2,5}
89 #endif /* _NETADDR_H */
gboolean(* isanyaddr)(const NetAddr *self)
Return TRUE if this address is an &#39;ANY&#39; address.
Definition: netaddr.h:50
guint16(* port)(const NetAddr *self)
Return port from this address.
Definition: netaddr.h:46
void(* setport)(NetAddr *, guint16)
Set port for this NetAddr.
Definition: netaddr.h:45
WINEXPORT NetAddr * netaddr_macaddr_new(gconstpointer macbuf, guint16 maclen)
Create new NetAddr from a MAC address.
Definition: netaddr.c:1061
WINEXPORT NetAddr * netaddr_dns_new(const char *addrstr)
Create a NetAddr from a DNS name or an ipv4 or ipv6 constant string.
Definition: netaddr.c:1004
WINEXPORT NetAddr * netaddr_mac64_new(gconstpointer macbuf)
Create new NetAddr from a MAC64 address.
Definition: netaddr.c:1077
AssimObj baseclass
Definition: netaddr.h:44
guint16 _addrport
private: Address port (if applicable)
Definition: netaddr.h:62
WINEXPORT NetAddr * netaddr_ipv4_new(gconstpointer ipbuf, guint16 port)
Create new NetAddr from a IPv4 address.
Definition: netaddr.c:1084
struct sockaddr_in(* ipv4sockaddr)(const NetAddr *self)
Return the ipv4 sockaddr corresponding to this address.
Definition: netaddr.h:52
Definition: projectcommon.h:45
WINEXPORT NetAddr * netaddr_sockaddr_new(const struct sockaddr_in6 *, socklen_t)
Create new NetAddr from a struct sockaddr
Definition: netaddr.c:1103
guint16(* addrtype)(const NetAddr *self)
Return IANA Address Family Numbers address type.
Definition: netaddr.h:47
This file defines our base object class: AssimObj.
WINEXPORT NetAddr * netaddr_mac48_new(gconstpointer macbuf)
Create new NetAddr from a MAC48 address.
Definition: netaddr.c:1070
guint(* hash)(const NetAddr *)
Compute hash of the NetAddr.
Definition: netaddr.h:54
WINEXPORT NetAddr * netaddr_ipv6_new(gconstpointer ipbuf, guint16 port)
Create new NetAddr from a IPv6 address.
Definition: netaddr.c:1092
WINEXPORT gboolean netaddr_g_hash_equal(gconstpointer lhs, gconstpointer rhs)
g_hash_table equal comparator for a NetAddr
Definition: netaddr.c:426
Project common header file.
gboolean(* ismcast)(const NetAddr *self)
Return TRUE if this address is a multicast address.
Definition: netaddr.h:48
The NetAddr class class represents a general network address - whether IP, MAC, or any other type of ...
Definition: netaddr.h:43
gboolean(* equal)(const NetAddr *, const NetAddr *)
Compare NetAddrs.
Definition: netaddr.h:53
WINEXPORT NetAddr * netaddr_new(gsize objsize, guint16 port, guint16 addrtype, gconstpointer addrbody, guint16 addrlen)
Generic NetAddr constructor.
Definition: netaddr.c:543
guint16 _addrlen
private: Length of _addrbody
Definition: netaddr.h:61
WINEXPORT guint netaddr_g_hash_hash(gconstpointer addrptr)
g_hash_table hash function for a NetAddr
Definition: netaddr.c:435
guint16 _addrtype
private: Address type
Definition: netaddr.h:60
WINEXPORT NetAddr * netaddr_string_new(const char *addrstr)
Create a NetAddr from an ipv4, ipv6 or MAC address string.
Definition: netaddr.c:976
gboolean(* islocal)(const NetAddr *self)
Return TRUE if this address is a local address.
Definition: netaddr.h:49
struct sockaddr_in6(* ipv6sockaddr)(const NetAddr *self)
Return the ipv6 sockaddr corresponding to this address.
Definition: netaddr.h:51
gpointer _addrbody
private: Address body
Definition: netaddr.h:59