PEthSocket Class Reference

#include <ethsock.h>

Inheritance diagram for PEthSocket:

PSocket PChannel PObject List of all members.

Information functions

enum  MediumTypes {
  MediumLoop, Medium802_3, MediumWan, MediumUnknown,
  NumMediumTypes
}
 Medium types for the open interface. More...
PBoolean EnumInterfaces (PINDEX idx, PString &name)
PBoolean GetAddress (Address &addr)
PBoolean GetIpAddress (PIPSocket::Address &addr)
PBoolean GetIpAddress (PIPSocket::Address &addr, PIPSocket::Address &netMask)
PBoolean EnumIpAddress (PINDEX idx, PIPSocket::Address &addr, PIPSocket::Address &netMask)
MediumTypes GetMedium ()

Filtering functions

enum  EthTypes {
  TypeAll = 3, TypeIP = 0x800, TypeX25 = 0x805, TypeARP = 0x806,
  TypeAtalk = 0x809B, TypeAARP = 0x80F3, TypeIPX = 0x8137, TypeIPv6 = 0x86DD
}
 Type codes for ethernet frames. More...
enum  FilterMask {
  FilterDirected = 0x01, FilterMulticast = 0x02, FilterAllMulticast = 0x04, FilterBroadcast = 0x08,
  FilterPromiscuous = 0x10
}
 Mask filter bits for GetFilter() function. More...
PBoolean GetFilter (unsigned &mask, WORD &type)
PBoolean SetFilter (unsigned mask, WORD type=TypeAll)

Public Member Functions

Overrides from class PChannel
virtual PBoolean Close ()
virtual PBoolean Read (void *buf, PINDEX len)
virtual PBoolean Write (const void *buf, PINDEX len)
Overrides from class PSocket
virtual PBoolean Connect (const PString &address)
virtual PBoolean Listen (unsigned queueSize=5, WORD port=0, Reusability reuse=AddressIsExclusive)
I/O functions
PBoolean ResetAdaptor ()
PBoolean ReadPacket (PBYTEArray &buffer, Address &dest, Address &src, WORD &type, PINDEX &len, BYTE *&payload)

Protected Member Functions

virtual PBoolean OpenSocket ()
virtual const char * GetProtocolName () const

Protected Attributes

WORD filterType
Address macAddress
MediumTypes medium
unsigned filterMask
PBoolean fakeMacHeader
PBoolean ipppInterface

Classes

union  Address
struct  Frame

Detailed Description

This class describes a type of socket that will communicate using raw ethernet packets.


Member Enumeration Documentation

enum PEthSocket::MediumTypes

Medium types for the open interface.

Enumerator:
MediumLoop  A Loopback Network.
Medium802_3  An ethernet Network Interface Card (10base2, 10baseT etc).
MediumWan  A Wide Area Network (modem etc).
MediumUnknown  Something else.
NumMediumTypes 

enum PEthSocket::EthTypes

Type codes for ethernet frames.

Enumerator:
TypeAll  All frames (3 is value for Linux).
TypeIP  Internet Protocol.
TypeX25  X.25.
TypeARP  Address Resolution Protocol.
TypeAtalk  Appletalk DDP.
TypeAARP  Appletalk AARP.
TypeIPX  Novell IPX.
TypeIPv6  Bluebook IPv6.

enum PEthSocket::FilterMask

Mask filter bits for GetFilter() function.

Enumerator:
FilterDirected  Packets directed at the interface.
FilterMulticast  Multicast packets directed at the interface.
FilterAllMulticast  All multicast packets.
FilterBroadcast  Packets with a broadcast address.
FilterPromiscuous  All packets.


Constructor & Destructor Documentation

PEthSocket::PEthSocket ( PINDEX  nReadBuffers = 8,
PINDEX  nWriteBuffers = 1,
PINDEX  size = 1514 
)

Create a new ethernet packet socket. Some platforms require a set of buffers to be allocated to avoid losing frequent packets.

Parameters:
nReadBuffers  Number of buffers used for reading.
nWriteBuffers  Number of buffers used for writing.
size  Size of each buffer.

PEthSocket::~PEthSocket (  ) 

Close the socket.

PEthSocket::PEthSocket ( PINDEX  nReadBuffers = 8,
PINDEX  nWriteBuffers = 1,
PINDEX  size = 1514 
)

Create a new ethernet packet socket. Some platforms require a set of buffers to be allocated to avoid losing frequent packets.

Parameters:
nReadBuffers  Number of buffers used for reading.
nWriteBuffers  Number of buffers used for writing.
size  Size of each buffer.

PEthSocket::~PEthSocket (  ) 

Close the socket.


Member Function Documentation

virtual PBoolean PEthSocket::Close (  )  [virtual]

Close the channel, shutting down the link to the data source.

Returns:
PTrue if the channel successfully closed.

Reimplemented from PChannel.

virtual PBoolean PEthSocket::Read ( void *  buf,
PINDEX  len 
) [virtual]

Low level read from the channel. This function may block until the requested number of characters were read or the read timeout was reached. The GetLastReadCount() function returns the actual number of bytes read.

The GetErrorCode() function should be consulted after Read() returns PFalse to determine what caused the failure.

Returns:
PTrue indicates that at least one character was read from the channel. PFalse means no bytes were read due to timeout or some other I/O error.
Parameters:
buf  Pointer to a block of memory to receive the read bytes.
len  Maximum number of bytes to read into the buffer.

Reimplemented from PSocket.

virtual PBoolean PEthSocket::Write ( const void *  buf,
PINDEX  len 
) [virtual]

Low level write to the channel. This function will block until the requested number of characters are written or the write timeout is reached. The GetLastWriteCount() function returns the actual number of bytes written.

The GetErrorCode() function should be consulted after Write() returns PFalse to determine what caused the failure.

Returns:
PTrue if at least len bytes were written to the channel.
Parameters:
buf  Pointer to a block of memory to write.
len  Number of bytes to write.

Reimplemented from PChannel.

virtual PBoolean PEthSocket::Connect ( const PString address  )  [virtual]

Connect a socket to an interface. The first form opens an interface by a name as returned by the EnumInterfaces() function. The second opens the interface that has the specified MAC address.

Returns:
PTrue if the channel was successfully connected to the interface.
Parameters:
address  Name of interface to connect to.

Reimplemented from PSocket.

virtual PBoolean PEthSocket::Listen ( unsigned  queueSize = 5,
WORD  port = 0,
Reusability  reuse = AddressIsExclusive 
) [virtual]

This function is illegal and will assert if attempted. You must be connected to an interface using Connect() to do I/O on the socket.

Returns:
PTrue if the channel was successfully opened.
Parameters:
queueSize  Number of pending accepts that may be queued.
port  Port number to use for the connection.
reuse  Can/Cant listen more than once.

Reimplemented from PSocket.

PBoolean PEthSocket::EnumInterfaces ( PINDEX  idx,
PString name 
)

Enumerate all the interfaces that are capable of being accessed at the ethernet level. Begin with index 0, and increment until the function returns PFalse. The name string returned can be passed, unchanged, to the Connect() function.

Note that the driver does not need to be open for this function to work.

Returns:
PTrue if an interface has the index supplied.
Parameters:
idx  Index of interface
name  Interface name

PBoolean PEthSocket::GetAddress ( Address addr  ) 

Get the low level MAC address of the open interface.

Returns:
PTrue if the address is returned, PFalse on error.
Parameters:
addr  Variable to receive the MAC address.

PBoolean PEthSocket::GetIpAddress ( PIPSocket::Address addr  ) 

Get the prime IP number bound to the open interface.

Returns:
PTrue if the address is returned, PFalse on error.
Parameters:
addr  Variable to receive the IP address.

PBoolean PEthSocket::GetIpAddress ( PIPSocket::Address addr,
PIPSocket::Address netMask 
)

Get the prime IP number bound to the open interface. This also returns the net mask associated with the open interface.

Returns:
PTrue if the address is returned, PFalse on error.
Parameters:
addr  Variable to receive the IP address.
netMask  Variable to receive the net mask.

PBoolean PEthSocket::EnumIpAddress ( PINDEX  idx,
PIPSocket::Address addr,
PIPSocket::Address netMask 
)

Enumerate all of the IP addresses and net masks bound to the open interface. This allows all the addresses to be found on multi-homed hosts. Begin with index 0 and increment until the function returns PFalse to enumerate all the addresses.

Returns:
PTrue if the address is returned, PFalse on error or if there are no more addresses bound to the interface.
Parameters:
idx  Index
addr  Variable to receive the IP address.
netMask  Variable to receive the net mask.

MediumTypes PEthSocket::GetMedium (  ) 

Return the type of the interface.

Returns:
Type enum for the interface, or NumMediumTypes if interface not open.

PBoolean PEthSocket::GetFilter ( unsigned &  mask,
WORD &  type 
)

Get the current filtering criteria for receiving packets.

A bit-wise OR of the FilterMask values will filter packets so that they do not appear in the Read() function at all.

The type is be the specific frame type to accept. A value of TypeAll may be used to match all frame types.

Returns:
A bit mask is returned, a value of 0 indicates an error.
Parameters:
mask  Bits for filtering on address
type  Code for filtering on type.

PBoolean PEthSocket::SetFilter ( unsigned  mask,
WORD  type = TypeAll 
)

Set the current filtering criteria for receiving packets. A bit-wise OR of the FilterMask values will filter packets so that they do not appear in the Read() function at all.

The type is be the specific frame type to accept. A value of TypeAll may be used to match all frame types.

A value of zero for the filter mask is useless and will assert.

Returns:
PTrue if the address is returned, PFalse on error.
Parameters:
mask  Bits for filtering on address
type  Code for filtering on type.

PBoolean PEthSocket::ResetAdaptor (  ) 

Reset the interface.

PBoolean PEthSocket::ReadPacket ( PBYTEArray buffer,
Address dest,
Address src,
WORD &  type,
PINDEX &  len,
BYTE *&  payload 
)

Read a packet from the interface and parse out the information specified by the parameters. This will automatically adjust for 802.2 and 802.3 ethernet frames.

Returns:
PTrue if the packet read, PFalse on error.
Parameters:
buffer  Buffer to receive the raw packet
dest  Destination address of packet
src  Source address of packet
type  Packet frame type ID
len  Length of payload
payload  Pointer into buffer# of payload.

virtual PBoolean PEthSocket::OpenSocket (  )  [protected, virtual]

Implements PSocket.

virtual const char* PEthSocket::GetProtocolName (  )  const [protected, virtual]

This function returns the protocol name for the socket type.

Implements PSocket.


Member Data Documentation

WORD PEthSocket::filterType [protected]

Address PEthSocket::macAddress [protected]

MediumTypes PEthSocket::medium [protected]

unsigned PEthSocket::filterMask [protected]

PBoolean PEthSocket::fakeMacHeader [protected]

PBoolean PEthSocket::ipppInterface [protected]


The documentation for this class was generated from the following file:
Generated on Mon Sep 15 01:21:36 2008 for PTLib by  doxygen 1.5.1