The Assimilation Project
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
netaddr.h
Go to the documentation of this file.
1 
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;
37 
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  gpointer _addrbody;
59  guint16 _addrtype;
60  guint16 _addrlen;
61  guint16 _addrport;
62 
63 };
64 WINEXPORT NetAddr* netaddr_new(gsize objsize, guint16 port, guint16 addrtype, gconstpointer addrbody, guint16 addrlen);
65 WINEXPORT NetAddr* netaddr_sockaddr_new(const struct sockaddr_in6 *, socklen_t);
66 WINEXPORT NetAddr* netaddr_macaddr_new(gconstpointer macbuf, guint16 maclen);
67 WINEXPORT NetAddr* netaddr_mac48_new(gconstpointer macbuf);
68 WINEXPORT NetAddr* netaddr_mac64_new(gconstpointer macbuf);
69 WINEXPORT NetAddr* netaddr_ipv4_new(gconstpointer ipbuf, guint16 port);
70 WINEXPORT NetAddr* netaddr_ipv6_new(gconstpointer ipbuf, guint16 port);
71 WINEXPORT NetAddr* netaddr_string_new(const char* addrstr);
72 WINEXPORT NetAddr* netaddr_dns_new(const char* addrstr);
73 WINEXPORT gboolean netaddr_g_hash_equal(gconstpointer lhs, gconstpointer rhs);
74 WINEXPORT guint netaddr_g_hash_hash(gconstpointer addrptr);
75 
76 #define CONST_IPV6_LOOPBACK {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1}
77 #define CONST_IPV4_LOOPBACK {127,0,0,1}
78 #define CONST_IPV6_IPV4SPACE 0,0,0,0,0,0,0,0,0,0,0xff,0xff
79 #define CONST_IPV6_IPV4START {CONST_IPV6_IPV4SPACE, 0, 0, 0, 0}
80 #define CONST_IPV6_MACSPACE 0xFE, 0x80, 0, 0, 0, 0, 0, 0x02
81 #define CONST_IPV6_MACSTART {CONST_IPV6_MACSPACE, 0, 0, 0, 0, 0, 0, 0, 0}
82 
83 
84 #define CONST_ASSIM_DEFAULT_V4_MCAST {224,0,2,5}
85 
86 
88 #endif /* _NETADDR_H */
guint16(* port)(const NetAddr *self)
Return port from this address.
Definition: netaddr.h:46
guint16(* addrtype)(const NetAddr *self)
Return IANA Address Family Numbers address type.
Definition: netaddr.h:47
WINEXPORT NetAddr * netaddr_macaddr_new(gconstpointer macbuf, guint16 maclen)
Create new NetAddr from a MAC address.
Definition: netaddr.c:1000
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:943
WINEXPORT NetAddr * netaddr_mac64_new(gconstpointer macbuf)
Create new NetAddr from a MAC64 address.
Definition: netaddr.c:1017
struct sockaddr_in(* ipv4sockaddr)(const NetAddr *self)
Return the ipv4 sockaddr corresponding to this address.
Definition: netaddr.h:52
AssimObj baseclass
Definition: netaddr.h:44
guint16 _addrport
private: Address port (if applicable)
Definition: netaddr.h:61
WINEXPORT NetAddr * netaddr_ipv4_new(gconstpointer ipbuf, guint16 port)
Create new NetAddr from a IPv4 address.
Definition: netaddr.c:1024
#define WINEXPORT
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:1043
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:1010
gboolean(* isanyaddr)(const NetAddr *self)
Return TRUE if this address is an 'ANY' address.
Definition: netaddr.h:50
void(* setport)(NetAddr *, guint16)
Set port for this NetAddr.
Definition: netaddr.h:45
gboolean(* ismcast)(const NetAddr *self)
Return TRUE if this address is a multicast address.
Definition: netaddr.h:48
WINEXPORT NetAddr * netaddr_ipv6_new(gconstpointer ipbuf, guint16 port)
Create new NetAddr from a IPv6 address.
Definition: netaddr.c:1032
WINEXPORT gboolean netaddr_g_hash_equal(gconstpointer lhs, gconstpointer rhs)
g_hash_table equal comparator for a NetAddr
Definition: netaddr.c:388
Project common header file.
gboolean(* equal)(const NetAddr *, const NetAddr *)
Compare NetAddrs.
Definition: netaddr.h:53
gboolean(* islocal)(const NetAddr *self)
Return TRUE if this address is a local address.
Definition: netaddr.h:49
The NetAddr class class represents a general network address - whether IP, MAC, or any other type of ...
Definition: netaddr.h:43
WINEXPORT NetAddr * netaddr_new(gsize objsize, guint16 port, guint16 addrtype, gconstpointer addrbody, guint16 addrlen)
Generic NetAddr constructor.
Definition: netaddr.c:501
guint16 _addrlen
private: Length of _addrbody
Definition: netaddr.h:60
WINEXPORT guint netaddr_g_hash_hash(gconstpointer addrptr)
g_hash_table hash function for a NetAddr
Definition: netaddr.c:397
guint(* hash)(const NetAddr *)
Compute hash of the NetAddr.
Definition: netaddr.h:54
struct sockaddr_in6(* ipv6sockaddr)(const NetAddr *self)
Return the ipv6 sockaddr corresponding to this address.
Definition: netaddr.h:51
guint16 _addrtype
private: Address type
Definition: netaddr.h:59
WINEXPORT NetAddr * netaddr_string_new(const char *addrstr)
Create a NetAddr from an ipv4, ipv6 or MAC address string.
Definition: netaddr.c:915
gpointer _addrbody
private: Address body
Definition: netaddr.h:58