31#include <basictypes.h>
33typedef int(PutCharsFunction)(
void *data,
const char *chars,
int len);
43#define PPP_TYPE (0x0021)
44#define EIP_TYPE (0x0800)
45#define EIP6_TYPE (0x86DD)
46#define HARD_ENET (0x0001)
47#define VLAN_TYPE (0x8100)
48#define EARP_TYPE (0x0806)
49#define ARP_REQUEST (0x01)
50#define ARP_RESPONSE (0x02)
55#define MACADDRESS_OCTETS_48 (6)
56#define MACADDRESS_WORDS_48 (3)
57typedef struct _MACADDRESS_48
59 uint8_t octet[MACADDRESS_OCTETS_48];
60} __attribute__((packed)) MACADDRESS_48;
71 beuint16_t phywadr[MACADDRESS_WORDS_48] = {0};
76 inline bool IsNull() {
return ((phywadr[2] == 0) && (phywadr[1] == 0) && (phywadr[0] == 0)); };
86 inline bool IsBroadCast() {
return ((phywadr[0] == 0xFFFF) && (phywadr[1] == 0xFFFF) && (phywadr[2] == 0xFFFF)); };
97 if (n & 1) {
return (phywadr[n / 2] & 0xFF); }
100 return ((phywadr[n / 2] >> 8) & 0xFF);
110 uint8_t *pto = (uint8_t *)phywadr;
111 for (
int i = 0; i < 6; i++)
134 tmp = ret.phywadr[2] + rhs;
136 ret.phywadr[2] = tmp & 0xffff;
138 tmp = phywadr[1] + tmp;
139 ret.phywadr[1] = tmp & 0xffff;
141 tmp = phywadr[0] + tmp;
142 ret.phywadr[0] = tmp & 0xffff;
144 }
while (tmp && ((tmp = ret.phywadr[2] + rhs)));
155 if (i.phywadr[0] != j.phywadr[0])
return FALSE;
156 if (i.phywadr[1] != j.phywadr[1])
return FALSE;
157 if (i.phywadr[2] != j.phywadr[2])
return FALSE;
167 if (i.phywadr[0] != j.phywadr[0])
return TRUE;
168 if (i.phywadr[1] != j.phywadr[1])
return TRUE;
169 if (i.phywadr[2] != j.phywadr[2])
return TRUE;
179 if (i.phywadr[0] > j.phywadr[0])
181 else if (i.phywadr[0] < j.phywadr[0])
184 if (i.phywadr[1] > j.phywadr[1])
186 else if (i.phywadr[1] < j.phywadr[1])
189 if (i.phywadr[2] > j.phywadr[2])
return true;
239 IPADDR4 &operator=(
const uint32_t v)
245 volatile IPADDR4 &operator=(
const uint32_t v)
volatile
251 bool IsEmbeddedIPV4()
const {
return true; };
252 IPADDR4 Extract4()
const {
return *
this; };
253 operator uint32_t()
const {
return (uint32_t)ip_val; };
262 inline bool IsNull()
const {
return ip_val == 0; };
287 inline bool IsLoopBack()
const {
return ((ip_val & 0xFF000000) == 0x7F000000); };
296 inline bool IsMultiCast()
const {
return ((ip_val & 0xF0000000) == 0xE0000000); };
305 inline bool IsmDns() {
return (ip_val==0xE00000FB); };
324 inline bool IsAutoIP() {
return ((ip_val & 0xFFFF0000) == 0xA9FE0000); };
327 IPADDR4(uint32_t v) { ip_val = v; };
328 IPADDR4(uint8_t a, uint8_t b, uint8_t c, uint8_t d) { ip_val = (a << 24) | (b << 16) | (c << 8) | d; }
331 inline MACADR McastMac()
const
333 uint32_t ipDst = ip_val;
336 ma.phywadr[0] = 0x0100;
337 ma.phywadr[1] = 0x5E00 | (uint16_t)((ipDst >> 16) & 0x7F);
338 ma.phywadr[2] = (uint16_t)(ipDst & (0xFFFF));
360 i4.ip_val = 0xFFFFFFFF;
396 int GetPrintLen(
bool compact);
397 int PrintHelper(PutCharsFunction *pf,
void *data,
bool compact);
401 return ((ip_val & mask.ip_val) == (intfIP.ip_val & mask.ip_val)) && ((ip_val & ~mask.ip_val) == (~mask.ip_val));
410 friend bool operator==(
const uint32_t i,
const IPADDR4 j);
411 friend bool operator!=(
const uint32_t i,
const IPADDR4 j);
412 friend bool operator>(
const uint32_t i,
const IPADDR4 j);
413 friend bool operator<(
const uint32_t i,
const IPADDR4 j);
415 friend bool operator==(
const IPADDR4 i,
const uint32_t j);
416 friend bool operator!=(
const IPADDR4 i,
const uint32_t j);
417 friend bool operator>(
const IPADDR4 i,
const uint32_t j);
418 friend bool operator<(
const IPADDR4 i,
const uint32_t j);
420 friend IPADDR4 IPV4FromConst(uint32_t d);
421 friend IPADDR4 IPV4FromConst(beuint32_t d);
430} __attribute__((packed));
435 return i.ip_val == j.ip_val;
439 return i.ip_val != j.ip_val;
443 return i.ip_val > j.ip_val;
447 return i.ip_val < j.ip_val;
452 return i == j.ip_val;
456 return i != j.ip_val;
462inline bool operator<(
const uint32_t i,
const IPADDR4 j)
469 return i.ip_val == j;
473 return i.ip_val != j;
479inline bool operator<(
const IPADDR4 i,
const uint32_t j)
484inline IPADDR4 IPV4FromConst(uint32_t d)
493 return IPV4FromConst(ifip.ip_val | ~(ipmask.ip_val));
522typedef EFRAME *PEFRAME;
534typedef VLEFRAME *PVLEFRAME;
545#define GetNullIP() IPADDR::NullIP()
550#error Got to pick an IP version
553#define GetNullIP() IPADDR4::NullIP()
558#define INADDR_ANY4 IPADDR4::NullIP()
561#define INADDR_ANY IPADDR::NullIP()
563#define INADDR_ANY INADDR_ANY4
Definition config_netobj.h:139
Used to store and manipulate IPv4 addresses in dual stack mode.
Definition nettypes.h:208
void print() const
Print an IPv4 address to the stdout serial port.
static IPADDR4 GlobalBroadCast()
C++ static function for a global broadcast IP address.
Definition nettypes.h:357
bool IsNull() const
Check if the IP address is null.
Definition nettypes.h:262
bool IsLoopBack() const
Check if the IP address is the loopback address for the interface.
Definition nettypes.h:287
bool IsAutoIP()
Check if the IPADDR4 object contains an AutoIP address.
Definition nettypes.h:324
bool IsMultiCast() const
Check if the IPADDR4 object contains a Multicast IP address the interface.
Definition nettypes.h:296
int sprintf(char *cp, int maxl) const
sprintf an IPv4 address to the specified buffer
IPADDR4(const IPADDR4 &v)=default
Constructor to create an IPv4 object initialized to to the specified IPADDR4 IP address.
bool NotNull() const
Check if the IP address is not null.
Definition nettypes.h:271
void fdprint(int fd) const
Print an IPv4 address to the specified file descriptor.
static IPADDR4 NullIP()
C++ static function for a null IP address.
Definition nettypes.h:346
void SetFromAscii(const char *cp)
Set the IPv4 address from a character string.
void SetNull()
Set the IP address to null.
Definition nettypes.h:278
bool IsGlobalBroadCast() const
Check if the IPADDR4 object contains a global broadcast address: 255.255.255.255.
Definition nettypes.h:315
IPADDR4()=default
Constructor to create an IPv4 object initialized to null.
bool IsmDns()
Check if the IPADDR4 object contains a mDNS IP address the interface.
Definition nettypes.h:305
Used to hold and manipulate IPv4 and IPv6 addresses in dual stack mode.
Definition ipv6_addr.h:41
Used to store and manipulate MAC addresses.
Definition nettypes.h:69
void print()
print the MAC to file descriptor 1
Definition nettypes.h:125
void SetFromBytes(const uint8_t *pb)
Set the MAC Address from a pointer to an array of 6 bytes.
Definition nettypes.h:108
bool IsNull()
Checks if MAC is null.
Definition nettypes.h:76
uint8_t GetByte(int n) const
Get the nth byte of the MAC.
Definition nettypes.h:91
bool IsBroadCast()
Checks if MAC is a Broadcast MAC.
Definition nettypes.h:86
void fdprint(int fd)
print the MAC to a file descriptor
bool IsMultiCast()
Checks if MAC is a Multicast MAC.
Definition nettypes.h:81
MACADR operator+(uint32_t rhs)
Definition nettypes.h:130
IPADDR6 IPADDR
IPADDR Object Type (either v4 or v6)
Definition nettypes.h:543
bool operator==(const MACADR &i, const MACADR &j)
Check MAC equality.
Definition nettypes.h:153
bool operator>(const MACADR &i, const MACADR &j)
Check MAC greater than.
Definition nettypes.h:177
class MACADR MACADR
Used to store and manipulate MAC addresses.
bool operator!=(const MACADR &i, const MACADR &j)
Check MAC inequality.
Definition nettypes.h:165