class PEthSocket

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

Inheritance:


Public Methods

[more] Constructor
[more] Overrides from class PChannel
[more] Overrides from class PSocket
[more] Information functions
[more] I/O functions

Public Members

[more]union Address
An ethernet MAC Address specification
[more]struct Frame
An ethernet MAC frame
[more] Filtering functions


Inherited from PSocket:

Public Methods

Socket establishment functions

Socket options functions

Port/Service database functions

Integer conversion functions

Public Members

Multiple socket selection functions

Protected Fields

oWORD port

Protected Methods

ovirtual const char* GetProtocolName() const


Inherited from PChannel:

Public Methods

Construction

Overrides from class PObject

Reading functions

Writing functions

Miscellaneous functions

ostatic BOOL ConvertOSError( int libcReturnValue, Errors & lastError, int & osError )

Public Members

Error functions

Protected Fields

oint os_handle
oErrors lastErrorCode[NumErrorGroups+1]
oint lastErrorNumber[NumErrorGroups+1]
oPINDEX lastReadCount
oPINDEX lastWriteCount
oPTimeInterval readTimeout
oPTimeInterval writeTimeout

Protected Methods

ovirtual BOOL ConvertOSError( int libcReturnValue, ErrorGroup group = LastGeneralError )
oBOOL SetErrorValues( Errors errorCode, int osError, ErrorGroup group = LastGeneralError )
oint ReadCharWithTimeout( PTimeInterval & timeout )


Inherited from PObject:

Public Methods

Run Time Type functions

Public Members

Comparison functions


Documentation

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

o 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.

o ~PEthSocket()
Close the socket

ounion Address
An ethernet MAC Address specification
Friends:
ostream & operator<<(ostream & s, const Address & a)

ostruct Frame
An ethernet MAC frame

ovoid Parse( WORD & type, BYTE* & payload, PINDEX & length )
Parse the Ethernet Frame to extract the frame type and the address of the payload. The length should be the original bytes read in the frame and may be altered to information contained in the frame, if available.

o Overrides from class PChannel

ovirtual BOOL Close()
Close the channel, shutting down the link to the data source.

Returns:
TRUE if the channel successfully closed.

ovirtual BOOL Read( void* buf, PINDEX len )
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 FALSE to determine what caused the failure.

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

ovirtual BOOL Write( const void* buf, PINDEX len )
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 FALSE to determine what caused the failure.

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

o Overrides from class PSocket

ovirtual BOOL Connect( const PString & address )
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.

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

ovirtual BOOL Listen( unsigned queueSize = 5, WORD port = 0, Reusability reuse = AddressIsExclusive )
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.

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.
Returns:
TRUE if the channel was successfully opened.

o Information functions

oBOOL 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 FALSE. 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.

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

oBOOL GetAddress( Address & addr )
Get the low level MAC address of the open interface.

Parameters:
- addr Variable to receive the MAC address.
Returns:
TRUE if the address is returned, FALSE on error.

oBOOL GetIpAddress( PIPSocket::Address & addr )
Get the prime IP number bound to the open interface.

Parameters:
- addr Variable to receive the IP address.
Returns:
TRUE if the address is returned, FALSE on error.

oBOOL 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.

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

oBOOL 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 FALSE to enumerate all the addresses.

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

oenum MediumTypes
Medium types for the open interface

o MediumLoop
A Loopback Network

o Medium802_3
An ethernet Network Interface Card (10base2, 10baseT etc)

o MediumWan
A Wide Area Network (modem etc)

o MediumUnknown
Something else

oMediumTypes GetMedium()
Return the type of the interface.

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

o Filtering functions

oenum EthTypes
Type codes for ethernet frames

o TypeAll
All frames (3 is value for Linux)

o TypeIP
Internet Protocol

o TypeX25
X25

o TypeARP
Address Resolution Protocol

o TypeAtalk
Appletalk DDP

o TypeAARP
Appletalk AARP

o TypeIPX
Novell IPX

o TypeIPv6
Bluebook IPv6

oenum FilterMask
Mask filter bits for GetFilter() function

o FilterDirected
Packets directed at the interface

o FilterMulticast
Multicast packets directed at the interface

o FilterAllMulticast
All multicast packets

o FilterBroadcast
Packets with a broadcast address

o FilterPromiscuous
All packets

oBOOL 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.

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

oBOOL 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.

Parameters:
mask - Bits for filtering on address
- type Code for filtering on type.
Returns:
TRUE if the address is returned, FALSE on error.

o I/O functions

oBOOL ResetAdaptor()
Reset the interface

oBOOL 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.

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.
Returns:
TRUE if the packet read, FALSE on error.


This class has no child classes.

Alphabetic index HTML hierarchy of classes or Java



This page was generated with the help of DOC++.