author | William Roberts <williamr@symbian.org> |
Wed, 31 Mar 2010 12:33:34 +0100 | |
branch | Symbian3 |
changeset 4 | 837f303aceeb |
parent 2 | 2fe1408b6811 |
permissions | -rw-r--r-- |
williamr@2 | 1 |
// Copyright (c) 2004-2009 Nokia Corporation and/or its subsidiary(-ies). |
williamr@2 | 2 |
// All rights reserved. |
williamr@2 | 3 |
// This component and the accompanying materials are made available |
williamr@4 | 4 |
// under the terms of "Eclipse Public License v1.0" |
williamr@2 | 5 |
// which accompanies this distribution, and is available |
williamr@4 | 6 |
// at the URL "http://www.eclipse.org/legal/epl-v10.html". |
williamr@2 | 7 |
// |
williamr@2 | 8 |
// Initial Contributors: |
williamr@2 | 9 |
// Nokia Corporation - initial contribution. |
williamr@2 | 10 |
// |
williamr@2 | 11 |
// Contributors: |
williamr@2 | 12 |
// |
williamr@2 | 13 |
// Description: |
williamr@2 | 14 |
// eui_addr.h - modified EUI-xx for IPv6 interface identifiers |
williamr@2 | 15 |
// Modified EUI-xx address structure for IPv6 interface identifiers |
williamr@2 | 16 |
// |
williamr@2 | 17 |
|
williamr@2 | 18 |
|
williamr@2 | 19 |
|
williamr@2 | 20 |
/** |
williamr@2 | 21 |
@file eui_addr.h |
williamr@2 | 22 |
@publishedAll |
williamr@2 | 23 |
@released |
williamr@2 | 24 |
*/ |
williamr@2 | 25 |
|
williamr@2 | 26 |
#ifndef __EUI_ADDR_H__ |
williamr@2 | 27 |
#define __EUI_ADDR_H__ |
williamr@2 | 28 |
|
williamr@2 | 29 |
#include <e32def.h> // TUint* |
williamr@2 | 30 |
#include "es_sock.h" // TSockAddr |
williamr@2 | 31 |
|
williamr@2 | 32 |
/** Address family ID */ |
williamr@4 | 33 |
const TUint KAfEui64 = 0x0F64; //< TODO |
williamr@2 | 34 |
|
williamr@2 | 35 |
/** Panic codes. |
williamr@2 | 36 |
@publishedAll |
williamr@2 | 37 |
@released |
williamr@2 | 38 |
*/ |
williamr@2 | 39 |
enum TEuiPanic |
williamr@2 | 40 |
{ |
williamr@2 | 41 |
EEuiPanicFamilyMismatch, |
williamr@2 | 42 |
EEuiPanicBitIsNotBit, |
williamr@2 | 43 |
EEuiPanicSourceTooLong |
williamr@2 | 44 |
}; |
williamr@2 | 45 |
|
williamr@2 | 46 |
|
williamr@2 | 47 |
// |
williamr@2 | 48 |
// Lots of these functions should be inlined -tom |
williamr@2 | 49 |
// |
williamr@2 | 50 |
|
williamr@2 | 51 |
/** |
williamr@2 | 52 |
* The raw 64 bits of Modified EUI-64 address stored in network byte order. |
williamr@2 | 53 |
* @publishedAll |
williamr@2 | 54 |
* @released |
williamr@2 | 55 |
*/ |
williamr@2 | 56 |
class TE64Addr |
williamr@2 | 57 |
{ |
williamr@2 | 58 |
public: |
williamr@4 | 59 |
IMPORT_C TE64Addr(); //< Constructs an address with zero value |
williamr@4 | 60 |
IMPORT_C TE64Addr(const TE64Addr& aAddr); //< Constructs an address with given value |
williamr@4 | 61 |
IMPORT_C TE64Addr(const TInt64& aAddr); //< Constructs an address with given value |
williamr@4 | 62 |
IMPORT_C TE64Addr(const TUint8* aPtr, TUint aLength); //< Constructs an address with given value |
williamr@2 | 63 |
|
williamr@4 | 64 |
IMPORT_C void SetAddr(const TE64Addr& aAddr); //< Sets the address value |
williamr@4 | 65 |
IMPORT_C void SetAddr(const TInt64& aAddr); //< Sets the address value |
williamr@4 | 66 |
IMPORT_C void SetAddr(const TUint8* aPtr, TUint aLength); //< Sets the address value |
williamr@2 | 67 |
|
williamr@2 | 68 |
|
williamr@4 | 69 |
IMPORT_C void SetAddrZero(); //< Creates a zero address |
williamr@2 | 70 |
|
williamr@2 | 71 |
/** |
williamr@2 | 72 |
* Creates a random address. |
williamr@2 | 73 |
* The Group bit is set to 0. |
williamr@2 | 74 |
* The Universal bit is set to 0. |
williamr@2 | 75 |
*/ |
williamr@2 | 76 |
IMPORT_C void SetAddrRandom(); |
williamr@2 | 77 |
|
williamr@2 | 78 |
/** |
williamr@2 | 79 |
* Creates a random non-zero address. |
williamr@2 | 80 |
* The Group bit is set to 0. |
williamr@2 | 81 |
* The Universal bit is set to 0. |
williamr@2 | 82 |
*/ |
williamr@2 | 83 |
IMPORT_C void SetAddrRandomNZ(); |
williamr@2 | 84 |
|
williamr@2 | 85 |
/** |
williamr@2 | 86 |
* Creates a random non-zero address that does not match the parameter address. |
williamr@2 | 87 |
* The Group bit is set to 0. |
williamr@2 | 88 |
* The Universal bit is set to 0. |
williamr@2 | 89 |
*/ |
williamr@2 | 90 |
IMPORT_C void SetAddrRandomNZButNot(const TE64Addr& aAddr); |
williamr@2 | 91 |
|
williamr@2 | 92 |
// Really should define TE48Addr for this... -tom |
williamr@4 | 93 |
IMPORT_C void SetAddrFromEUI48(const TUint8* aPtr); //< Reads and converts a value from EUI-48 (6 bytes) |
williamr@2 | 94 |
|
williamr@4 | 95 |
IMPORT_C void SetGroupBit(TBool aBit = 1); //< Sets the Group bit to 1 by default |
williamr@4 | 96 |
IMPORT_C void SetUniversalBit(TBool aBit = 1); //< Sets the Universal bit to 1 by default |
williamr@2 | 97 |
|
williamr@4 | 98 |
IMPORT_C TBool Match(const TE64Addr& aAddr) const; //< TRUE if the address matches given address |
williamr@4 | 99 |
IMPORT_C TBool IsZero() const; //< TRUE if the address is a zero address |
williamr@4 | 100 |
IMPORT_C TBool IsGroup() const; //< TRUE if the Group bit is set in the address |
williamr@4 | 101 |
IMPORT_C TBool IsUniversal() const; //< TRUE if the Universal bit is set in the address |
williamr@2 | 102 |
|
williamr@4 | 103 |
// IMPORT_C TInt Input(const TDesC& aBuf); //< Reads a value for the address from a string |
williamr@4 | 104 |
IMPORT_C void Output(TDes& aBuf) const; //< Writes the address into a string |
williamr@2 | 105 |
|
williamr@4 | 106 |
IMPORT_C static TUint AddrLen(); //< Returns the size of raw KAfEui64 content format |
williamr@4 | 107 |
IMPORT_C TUint8* AddrPtr(); //< Returns a pointer to raw KAfEui64 content format |
williamr@4 | 108 |
IMPORT_C const TUint8* AddrPtrC() const; //< Returns a const pointer to raw KAfEui64 content format |
williamr@2 | 109 |
|
williamr@2 | 110 |
private: |
williamr@2 | 111 |
union |
williamr@2 | 112 |
{ |
williamr@2 | 113 |
TUint8 iAddr8[64 / 8]; |
williamr@2 | 114 |
TUint16 iAddr16[64 / 16]; |
williamr@2 | 115 |
TUint32 iAddr32[64 / 32]; |
williamr@2 | 116 |
} u; |
williamr@2 | 117 |
}; |
williamr@2 | 118 |
|
williamr@2 | 119 |
struct SE64Addr { |
williamr@4 | 120 |
TE64Addr iAddr; //< 8 bytes of Modified EUI-64 address (64 bits) |
williamr@2 | 121 |
}; |
williamr@2 | 122 |
|
williamr@2 | 123 |
/** |
williamr@2 | 124 |
* This class specializes the generic socket server address class |
williamr@2 | 125 |
* TSockAddr for the IPv6 Interface Identifier; the Modified EUI-64 |
williamr@2 | 126 |
* address. Value KAfEui64 is used for the protocol family field |
williamr@2 | 127 |
* of the TSockAddr base class. |
williamr@2 | 128 |
* |
williamr@2 | 129 |
* @publishedAll |
williamr@2 | 130 |
* @released |
williamr@2 | 131 |
*/ |
williamr@2 | 132 |
class TEui64Addr : public TSockAddr |
williamr@2 | 133 |
{ |
williamr@2 | 134 |
public: |
williamr@2 | 135 |
/** |
williamr@2 | 136 |
* Constructs a basic IPv6 Interface Identifier. |
williamr@2 | 137 |
* The family is initialized to KafEui64. |
williamr@2 | 138 |
* The port (unused) is initialized to 0. |
williamr@2 | 139 |
* The address is set to zero address. |
williamr@2 | 140 |
*/ |
williamr@2 | 141 |
IMPORT_C TEui64Addr(); |
williamr@2 | 142 |
|
williamr@2 | 143 |
/** |
williamr@2 | 144 |
* Constructs an IPv6 Interface Identifier from TSockAddr. |
williamr@2 | 145 |
* The family of the parameter must be KAfEui64 or 0. |
williamr@2 | 146 |
* The family of the resulting address is KAfEui64. |
williamr@2 | 147 |
* The port (unused) is initialized to 0. |
williamr@2 | 148 |
* The address bytes are copied from the parameter. |
williamr@2 | 149 |
* |
williamr@2 | 150 |
* @param anAddr TSockAddr to be used as initial content. |
williamr@2 | 151 |
*/ |
williamr@2 | 152 |
IMPORT_C TEui64Addr(const TSockAddr& aAddr); |
williamr@2 | 153 |
|
williamr@2 | 154 |
/** |
williamr@2 | 155 |
* Constructs an IPv6 Interface Identifier from TE64Addr. |
williamr@2 | 156 |
* The family is initialized to KAfEui64. |
williamr@2 | 157 |
* The port (unused) is initialized to 0. |
williamr@2 | 158 |
* The address bytes are copied from the parameter. |
williamr@2 | 159 |
* |
williamr@2 | 160 |
* @param aAddr TE64Addr to be used as initial content. |
williamr@2 | 161 |
*/ |
williamr@2 | 162 |
inline TEui64Addr(const TE64Addr& aAddr); |
williamr@2 | 163 |
|
williamr@2 | 164 |
/** |
williamr@2 | 165 |
* Initializes the TSockAddr parts of an IPv6 Interface Identifier. |
williamr@2 | 166 |
* The family is set to KAfEui64. |
williamr@2 | 167 |
* The port (unused) is initialized to 0. |
williamr@2 | 168 |
* The address bytes are not touched. |
williamr@2 | 169 |
*/ |
williamr@2 | 170 |
IMPORT_C void Init(); |
williamr@2 | 171 |
|
williamr@2 | 172 |
/** |
williamr@2 | 173 |
* Sets the address bytes to given value. |
williamr@2 | 174 |
* The other TSockAddr fields are not touched. |
williamr@2 | 175 |
*/ |
williamr@2 | 176 |
IMPORT_C void SetAddress(const TE64Addr& aAddr); |
williamr@4 | 177 |
IMPORT_C TE64Addr& Address() const; //< Accesses the address bytes |
williamr@2 | 178 |
|
williamr@4 | 179 |
IMPORT_C TBool Match(const TEui64Addr& aAddr) const; //< TRUE if the address bytes match the parameter's |
williamr@4 | 180 |
IMPORT_C TBool IsZero() const; //< TRUE if the address bytes are all zeros |
williamr@2 | 181 |
|
williamr@4 | 182 |
IMPORT_C static TEui64Addr& Cast(const TSockAddr& aAddr); //< Unsafely casts a TSockAddr to TEui64Addr |
williamr@4 | 183 |
IMPORT_C static TEui64Addr& Cast(const TSockAddr* aAddr); //< Unsafely casts a TSockAddr to TEui64Addr |
williamr@2 | 184 |
|
williamr@2 | 185 |
protected: |
williamr@4 | 186 |
IMPORT_C SE64Addr* AddrPtr() const; //< Returns a pointer to KAfEui64 content format |
williamr@4 | 187 |
IMPORT_C static TUint AddrLen(); //< Returns the size of the KAfEui64 content format |
williamr@2 | 188 |
}; |
williamr@2 | 189 |
|
williamr@2 | 190 |
inline TEui64Addr::TEui64Addr(const TE64Addr& aAddr) : TSockAddr() |
williamr@2 | 191 |
{ |
williamr@2 | 192 |
Init(); |
williamr@2 | 193 |
SetAddress(aAddr); |
williamr@2 | 194 |
}; |
williamr@2 | 195 |
|
williamr@2 | 196 |
#endif |