epoc32/include/eui_addr.h
author William Roberts <williamr@symbian.org>
Wed, 31 Mar 2010 12:33:34 +0100
branchSymbian3
changeset 4 837f303aceeb
parent 2 2fe1408b6811
permissions -rw-r--r--
Current Symbian^3 public API header files (from PDK 3.0.h)
This is the epoc32/include tree with the "platform" subtrees removed, and
all but a selected few mbg and rsg files removed.
     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 "Eclipse Public License v1.0"
     5 // which accompanies this distribution, and is available
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
     7 //
     8 // Initial Contributors:
     9 // Nokia Corporation - initial contribution.
    10 //
    11 // Contributors:
    12 //
    13 // Description:
    14 // eui_addr.h - modified EUI-xx for IPv6 interface identifiers
    15 // Modified EUI-xx address structure for IPv6 interface identifiers
    16 //
    17 
    18 
    19 
    20 /**
    21  @file eui_addr.h
    22  @publishedAll
    23  @released
    24 */
    25 
    26 #ifndef __EUI_ADDR_H__
    27 #define __EUI_ADDR_H__
    28 
    29 #include <e32def.h>		// TUint*
    30 #include "es_sock.h"	// TSockAddr
    31 
    32 /**  Address family ID */
    33 const TUint KAfEui64	= 0x0F64;	//< TODO
    34 
    35 /**  Panic codes.
    36 @publishedAll
    37 @released
    38 */
    39 enum TEuiPanic
    40 {
    41 	EEuiPanicFamilyMismatch,
    42 	EEuiPanicBitIsNotBit,
    43 	EEuiPanicSourceTooLong
    44 };
    45 
    46 
    47 //
    48 // Lots of these functions should be inlined -tom
    49 //
    50 
    51 /**
    52  * The raw 64 bits of Modified EUI-64 address stored in network byte order.
    53  * @publishedAll
    54  * @released
    55  */
    56 class TE64Addr
    57 {
    58  public:
    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
    63 
    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
    67 
    68 
    69 	IMPORT_C void SetAddrZero();	//< Creates a zero address
    70 
    71 	/**
    72 	 * Creates a random address.
    73 	 * The Group bit is set to 0.
    74 	 * The Universal bit is set to 0.
    75 	 */
    76 	IMPORT_C void SetAddrRandom();
    77 
    78 	/**
    79 	 * Creates a random non-zero address.
    80 	 * The Group bit is set to 0.
    81 	 * The Universal bit is set to 0.
    82 	 */
    83 	IMPORT_C void SetAddrRandomNZ();
    84 
    85 	/**
    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.
    89 	 */
    90 	IMPORT_C void SetAddrRandomNZButNot(const TE64Addr& aAddr);
    91 
    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)
    94 
    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
    97 
    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
   102 
   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
   105 	
   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
   109 
   110  private:
   111 	union
   112 	{
   113 		TUint8 iAddr8[64 / 8];
   114 		TUint16 iAddr16[64 / 16];
   115 		TUint32 iAddr32[64 / 32];
   116 	} u;
   117 };
   118 
   119 struct SE64Addr {
   120 	TE64Addr iAddr;		//< 8 bytes of Modified EUI-64 address (64 bits)
   121 };
   122 
   123 /**
   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.
   128  *
   129  * @publishedAll
   130  * @released
   131  */
   132 class TEui64Addr : public TSockAddr
   133 {
   134  public:
   135 	/**
   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.
   140 	 */
   141 	IMPORT_C TEui64Addr();
   142 
   143 	/**
   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.
   149 	 *
   150 	 * @param anAddr TSockAddr to be used as initial content.
   151 	 */
   152 	IMPORT_C TEui64Addr(const TSockAddr& aAddr);
   153 
   154 	/**
   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.
   159 	 *
   160 	 * @param aAddr TE64Addr to be used as initial content.
   161 	 */
   162 	inline TEui64Addr(const TE64Addr& aAddr);
   163 
   164 	/**
   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.
   169 	 */
   170 	IMPORT_C void Init();
   171 
   172 	/**
   173 	 * Sets the address bytes to given value.
   174 	 * The other TSockAddr fields are not touched.
   175 	 */
   176 	IMPORT_C void SetAddress(const TE64Addr& aAddr);
   177 	IMPORT_C TE64Addr& Address() const;	//< Accesses the address bytes
   178 
   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
   181 
   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
   184 
   185  protected:
   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
   188 };
   189 
   190 inline TEui64Addr::TEui64Addr(const TE64Addr& aAddr) : TSockAddr()
   191 {
   192 	Init();
   193 	SetAddress(aAddr);
   194 };
   195 
   196 #endif