12 #include <basictypes.h> 22 #define PPP_TYPE (0x0021) 23 #define EIP_TYPE (0x0800) 24 #define EIP6_TYPE (0x86DD) 25 #define HARD_ENET (0x0001) 26 #define EARP_TYPE (0x0806) 27 #define ARP_REQUEST (0x01) 28 #define ARP_RESPONSE (0x02) 33 #define MACADDRESS_OCTETS_48 (6) 34 #define MACADDRESS_WORDS_48 (3) 35 typedef struct _MACADDRESS_48
37 uint8_t octet[MACADDRESS_OCTETS_48];
38 } __attribute__((packed)) MACADDRESS_48;
43 beuint16_t phywadr[MACADDRESS_WORDS_48];
44 inline bool IsNull() {
return ((phywadr[2] == 0) && (phywadr[1] == 0) && (phywadr[0] == 0)); };
45 inline bool IsMultiCast() {
return (phywadr[0] & 0x0100); };
46 inline bool IsBroadCast() {
return ((phywadr[0] == 0xFFFF) && (phywadr[1] == 0xFFFF) && (phywadr[2] == 0xFFFF)); };
47 uint8_t GetByte(
int n)
const 53 if (n & 1) {
return (phywadr[n / 2] & 0xFF); }
56 return ((phywadr[n / 2] >> 8) & 0xFF);
60 inline void SetFromBytes(
const uint8_t *pb)
62 uint8_t *pto = (uint8_t *)phywadr;
63 for (
int i = 0; i < 6; i++)
69 inline void print() { fdprint(1); };
70 } __attribute__((packed)) MACADR;
73 inline bool operator==(
const MACADR &i,
const MACADR &j)
75 if (i.phywadr[0] != j.phywadr[0])
return FALSE;
76 if (i.phywadr[1] != j.phywadr[1])
return FALSE;
77 if (i.phywadr[2] != j.phywadr[2])
return FALSE;
81 inline bool operator!=(
const MACADR &i,
const MACADR &j)
83 if (i.phywadr[0] != j.phywadr[0])
return TRUE;
84 if (i.phywadr[1] != j.phywadr[1])
return TRUE;
85 if (i.phywadr[2] != j.phywadr[2])
return TRUE;
89 inline bool operator>(
const MACADR &i,
const MACADR &j)
91 if (i.phywadr[0] > j.phywadr[0])
93 else if (i.phywadr[0] < j.phywadr[0])
96 if (i.phywadr[1] > j.phywadr[1])
98 else if (i.phywadr[1] < j.phywadr[1])
101 if (i.phywadr[2] > j.phywadr[2])
return true;
106 extern MACADR ENET_BCAST;
107 extern MACADR ENET_ZERO;
119 IPADDR4(
const IPADDR4 &v) =
default;
121 IPADDR4 &operator=(
const IPADDR4 &v)
128 IPADDR4 &operator=(
const uint32_t v)
134 bool IsEmbeddedIPV4() {
return true; };
135 IPADDR4 Extract4()
const {
return *
this; };
136 operator uint32_t()
const {
return (uint32_t)ip_val; };
138 inline bool IsNull()
const {
return ip_val == 0; };
139 inline bool NotNull()
const {
return !IsNull(); };
140 inline void SetNull() { ip_val = 0; };
141 inline bool IsLoopBack()
const {
return ((ip_val & 0xFF000000) == 0x7F000000); };
142 inline bool IsMultiCast()
const {
return ((ip_val & 0xF0000000) == 0xE0000000); };
143 inline bool IsGlobalBroadCast()
const {
return ip_val == 0xffffffff; };
144 inline bool IsAutoIP() {
return ((ip_val & 0xFFFF0000) == 0xA9FE0000); };
147 IPADDR4(uint32_t v) { ip_val = v; };
148 IPADDR4(uint8_t a, uint8_t b, uint8_t c, uint8_t d) { ip_val = (a << 24) | (b << 16) | (c << 8) | d; }
151 inline MACADR McastMac()
const 153 uint32_t ipDst = ip_val;
156 ma.phywadr[0] = 0x0100;
157 ma.phywadr[1] = 0x5E00 | (uint16_t)((ipDst >> 16) & 0x7F);
158 ma.phywadr[2] = (uint16_t)(ipDst & (0xFFFF));
162 inline static IPADDR4 NullIP()
168 inline static IPADDR4 GlobalBroadCast()
171 i4.ip_val = 0xFFFFFFFF;
176 void fdprint(
int fd)
const;
177 int sprintf(
char *cp,
int maxl)
const;
178 void SetFromAscii(
const char *cp);
180 bool IsBcastNetMask(IPADDR4 intfIP, IPADDR4 mask)
const 182 return ((ip_val & mask.ip_val) == (intfIP.ip_val & mask.ip_val)) && ((ip_val & ~mask.ip_val) == (~mask.ip_val));
186 friend bool operator==(
const IPADDR4 i,
const IPADDR4 j);
187 friend bool operator!=(
const IPADDR4 i,
const IPADDR4 j);
188 friend bool operator>(
const IPADDR4 i,
const IPADDR4 j);
189 friend bool operator<(
const IPADDR4 i,
const IPADDR4 j);
191 friend bool operator==(
const uint32_t i,
const IPADDR4 j);
192 friend bool operator!=(
const uint32_t i,
const IPADDR4 j);
193 friend bool operator>(
const uint32_t i,
const IPADDR4 j);
194 friend bool operator<(
const uint32_t i,
const IPADDR4 j);
196 friend bool operator==(
const IPADDR4 i,
const uint32_t j);
197 friend bool operator!=(
const IPADDR4 i,
const uint32_t j);
198 friend bool operator>(
const IPADDR4 i,
const uint32_t j);
199 friend bool operator<(
const IPADDR4 i,
const uint32_t j);
201 friend IPADDR4 IPV4FromConst(uint32_t d);
202 friend IPADDR4 IPV4FromConst(beuint32_t d);
204 friend IPADDR4 LocalBroadCast(IPADDR4 ifip, IPADDR4 ipmask);
206 friend class CUR_IPADDR4;
211 } __attribute__((packed));
214 inline bool operator==(
const IPADDR4 i,
const IPADDR4 j)
216 return i.ip_val == j.ip_val;
218 inline bool operator!=(
const IPADDR4 i,
const IPADDR4 j)
220 return i.ip_val != j.ip_val;
222 inline bool operator>(
const IPADDR4 i,
const IPADDR4 j)
224 return i.ip_val > j.ip_val;
226 inline bool operator<(
const IPADDR4 i,
const IPADDR4 j)
228 return i.ip_val < j.ip_val;
231 inline bool operator==(
const uint32_t i,
const IPADDR4 j)
233 return i == j.ip_val;
235 inline bool operator!=(
const uint32_t i,
const IPADDR4 j)
237 return i != j.ip_val;
239 inline bool operator>(
const uint32_t i,
const IPADDR4 j)
243 inline bool operator<(
const uint32_t i,
const IPADDR4 j)
248 inline bool operator==(
const IPADDR4 i,
const uint32_t j)
250 return i.ip_val == j;
252 inline bool operator!=(
const IPADDR4 i,
const uint32_t j)
254 return i.ip_val != j;
256 inline bool operator>(
const IPADDR4 i,
const uint32_t j)
260 inline bool operator<(
const IPADDR4 i,
const uint32_t j)
265 inline IPADDR4 IPV4FromConst(uint32_t d)
272 inline IPADDR4 LocalBroadCast(IPADDR4 ifip, IPADDR4 ipmask)
274 return IPV4FromConst(ifip.ip_val | ~(ipmask.ip_val));
303 typedef EFRAME *PEFRAME;
318 typedef VLEFRAME *PVLEFRAME;
331 #define GetNullIP() IPADDR6::NullIP() 334 #error Got to pick an IP version 337 #define GetNullIP() IPADDR4::NullIP() 340 #endif // #ifndef NB_NET_TYPES_H
Used to hold and manipulate IPv4 and IPv6 addresses in dual stack mode.
Definition: ipv6_addr.h:28