1 // Copyright (c) 2004-2009 Nokia Corporation and/or its subsidiary(-ies).
2 // All rights reserved.
3 // This component and the accompanying materials are made available
4 // under the terms of the License "Symbian Foundation License v1.0" to Symbian Foundation members and "Symbian Foundation End User License Agreement v1.0" to non-members
5 // which accompanies this distribution, and is available
6 // at the URL "http://www.symbianfoundation.org/legal/licencesv10.html".
8 // Initial Contributors:
9 // Nokia Corporation - initial contribution.
14 // eui_addr.h - modified EUI-xx for IPv6 interface identifiers
15 // Modified EUI-xx address structure for IPv6 interface identifiers
26 #ifndef __EUI_ADDR_H__
27 #define __EUI_ADDR_H__
29 #include <e32def.h> // TUint*
30 #include "es_sock.h" // TSockAddr
32 /** Address family ID */
33 const TUint KAfEui64 = 0x0F64; ///< TODO
41 EEuiPanicFamilyMismatch,
43 EEuiPanicSourceTooLong
48 // Lots of these functions should be inlined -tom
52 * The raw 64 bits of Modified EUI-64 address stored in network byte order.
59 IMPORT_C TE64Addr(); ///< Constructs an address with zero value
60 IMPORT_C TE64Addr(const TE64Addr& aAddr); ///< Constructs an address with given value
61 IMPORT_C TE64Addr(const TInt64& aAddr); ///< Constructs an address with given value
62 IMPORT_C TE64Addr(const TUint8* aPtr, TUint aLength); ///< Constructs an address with given value
64 IMPORT_C void SetAddr(const TE64Addr& aAddr); ///< Sets the address value
65 IMPORT_C void SetAddr(const TInt64& aAddr); ///< Sets the address value
66 IMPORT_C void SetAddr(const TUint8* aPtr, TUint aLength); ///< Sets the address value
69 IMPORT_C void SetAddrZero(); ///< Creates a zero address
72 * Creates a random address.
73 * The Group bit is set to 0.
74 * The Universal bit is set to 0.
76 IMPORT_C void SetAddrRandom();
79 * Creates a random non-zero address.
80 * The Group bit is set to 0.
81 * The Universal bit is set to 0.
83 IMPORT_C void SetAddrRandomNZ();
86 * Creates a random non-zero address that does not match the parameter address.
87 * The Group bit is set to 0.
88 * The Universal bit is set to 0.
90 IMPORT_C void SetAddrRandomNZButNot(const TE64Addr& aAddr);
92 // Really should define TE48Addr for this... -tom
93 IMPORT_C void SetAddrFromEUI48(const TUint8* aPtr); ///< Reads and converts a value from EUI-48 (6 bytes)
95 IMPORT_C void SetGroupBit(TBool aBit = 1); ///< Sets the Group bit to 1 by default
96 IMPORT_C void SetUniversalBit(TBool aBit = 1); ///< Sets the Universal bit to 1 by default
98 IMPORT_C TBool Match(const TE64Addr& aAddr) const; ///< TRUE if the address matches given address
99 IMPORT_C TBool IsZero() const; ///< TRUE if the address is a zero address
100 IMPORT_C TBool IsGroup() const; ///< TRUE if the Group bit is set in the address
101 IMPORT_C TBool IsUniversal() const; ///< TRUE if the Universal bit is set in the address
103 // IMPORT_C TInt Input(const TDesC& aBuf); ///< Reads a value for the address from a string
104 IMPORT_C void Output(TDes& aBuf) const; ///< Writes the address into a string
106 IMPORT_C static TUint AddrLen(); ///< Returns the size of raw KAfEui64 content format
107 IMPORT_C TUint8* AddrPtr(); ///< Returns a pointer to raw KAfEui64 content format
108 IMPORT_C const TUint8* AddrPtrC() const; ///< Returns a const pointer to raw KAfEui64 content format
113 TUint8 iAddr8[64 / 8];
114 TUint16 iAddr16[64 / 16];
115 TUint32 iAddr32[64 / 32];
120 TE64Addr iAddr; ///< 8 bytes of Modified EUI-64 address (64 bits)
124 * This class specializes the generic socket server address class
125 * TSockAddr for the IPv6 Interface Identifier; the Modified EUI-64
126 * address. Value KAfEui64 is used for the protocol family field
127 * of the TSockAddr base class.
132 class TEui64Addr : public TSockAddr
136 * Constructs a basic IPv6 Interface Identifier.
137 * The family is initialized to KafEui64.
138 * The port (unused) is initialized to 0.
139 * The address is set to zero address.
141 IMPORT_C TEui64Addr();
144 * Constructs an IPv6 Interface Identifier from TSockAddr.
145 * The family of the parameter must be KAfEui64 or 0.
146 * The family of the resulting address is KAfEui64.
147 * The port (unused) is initialized to 0.
148 * The address bytes are copied from the parameter.
150 * @param anAddr TSockAddr to be used as initial content.
152 IMPORT_C TEui64Addr(const TSockAddr& aAddr);
155 * Constructs an IPv6 Interface Identifier from TE64Addr.
156 * The family is initialized to KAfEui64.
157 * The port (unused) is initialized to 0.
158 * The address bytes are copied from the parameter.
160 * @param aAddr TE64Addr to be used as initial content.
162 inline TEui64Addr(const TE64Addr& aAddr);
165 * Initializes the TSockAddr parts of an IPv6 Interface Identifier.
166 * The family is set to KAfEui64.
167 * The port (unused) is initialized to 0.
168 * The address bytes are not touched.
170 IMPORT_C void Init();
173 * Sets the address bytes to given value.
174 * The other TSockAddr fields are not touched.
176 IMPORT_C void SetAddress(const TE64Addr& aAddr);
177 IMPORT_C TE64Addr& Address() const; ///< Accesses the address bytes
179 IMPORT_C TBool Match(const TEui64Addr& aAddr) const; ///< TRUE if the address bytes match the parameter's
180 IMPORT_C TBool IsZero() const; ///< TRUE if the address bytes are all zeros
182 IMPORT_C static TEui64Addr& Cast(const TSockAddr& aAddr); ///< Unsafely casts a TSockAddr to TEui64Addr
183 IMPORT_C static TEui64Addr& Cast(const TSockAddr* aAddr); ///< Unsafely casts a TSockAddr to TEui64Addr
186 IMPORT_C SE64Addr* AddrPtr() const; ///< Returns a pointer to KAfEui64 content format
187 IMPORT_C static TUint AddrLen(); ///< Returns the size of the KAfEui64 content format
190 inline TEui64Addr::TEui64Addr(const TE64Addr& aAddr) : TSockAddr()