PTLib
Version 2.10.10
|
This class describes a type of socket that will communicate using raw ethernet packets. More...
#include <ethsock.h>
Classes | |
union | Address |
An ethernet MAC Address specification. More... | |
struct | Frame |
An ethernet MAC frame. More... |
Public Member Functions | |
Constructor | |
PEthSocket (PINDEX nReadBuffers=8, PINDEX nWriteBuffers=1, PINDEX size=1514) | |
Create a new ethernet packet socket. | |
~PEthSocket () | |
Close the socket. | |
Overrides from class PChannel | |
virtual PBoolean | Close () |
Close the channel, shutting down the link to the data source. | |
virtual PBoolean | Read (void *buf, PINDEX len) |
Low level read from the channel. | |
virtual PBoolean | Write (const void *buf, PINDEX len) |
Low level write to the channel. | |
Overrides from class PSocket | |
virtual PBoolean | Connect (const PString &address) |
Connect a socket to an interface. | |
virtual PBoolean | Listen (unsigned queueSize=5, WORD port=0, Reusability reuse=AddressIsExclusive) |
This function is illegal and will assert if attempted. | |
I/O functions | |
PBoolean | ResetAdaptor () |
Reset the interface. | |
PBoolean | 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. | |
![]() | |
~PSocket () | |
PBoolean | SetOption (int option, int value, int level=SOL_SOCKET) |
Set options on the socket. | |
PBoolean | SetOption (int option, const void *valuePtr, PINDEX valueSize, int level=SOL_SOCKET) |
Set options on the socket. | |
PBoolean | GetOption (int option, int &value, int level=SOL_SOCKET) |
Get options on the socket. | |
PBoolean | GetOption (int option, void *valuePtr, PINDEX valueSize, int level=SOL_SOCKET) |
Get options on the socket. | |
virtual PBoolean | Accept (PSocket &socket) |
Open a socket to a remote host on the specified port number. | |
virtual PBoolean | Shutdown (ShutdownValue option) |
Close one or both of the data streams associated with a socket. | |
virtual WORD | GetPortByService (const PString &service) const |
Get the port number for the specified service name. | |
virtual PString | GetServiceByPort (WORD port) const |
Get the service name from the port number. | |
void | SetPort (WORD port) |
Set the port number for the channel. | |
void | SetPort (const PString &service) |
Set the port number for the channel. | |
WORD | GetPort () const |
Get the port the TCP socket channel object instance is using. | |
PString | GetService () const |
Get a service name for the port number the TCP socket channel object instance is using. | |
![]() | |
PBoolean | SetErrorValues (Errors errorCode, int osError, ErrorGroup group=LastGeneralError) |
Set error values to those specified. | |
PChannel () | |
Create the channel. | |
~PChannel () | |
Close down the channel. | |
virtual Comparison | Compare (const PObject &obj) const |
Get the relative rank of the two strings. | |
virtual PINDEX | HashFunction () const |
Calculate a hash value for use in sets and dictionaries. | |
virtual PBoolean | IsOpen () const |
Determine if the channel is currently open. | |
virtual PString | GetName () const |
Get the platform and I/O channel type name of the channel. | |
int | GetHandle () const |
Get the integer operating system handle for the channel. | |
virtual PChannel * | GetBaseReadChannel () const |
Get the base channel of channel indirection using PIndirectChannel. | |
virtual PChannel * | GetBaseWriteChannel () const |
Get the base channel of channel indirection using PIndirectChannel. | |
void | SetReadTimeout (const PTimeInterval &time) |
Set the timeout for read operations. | |
PTimeInterval | GetReadTimeout () const |
Get the timeout for read operations. | |
virtual PINDEX | GetLastReadCount () const |
Get the number of bytes read by the last Read() call. | |
virtual int | ReadChar () |
Read a single 8 bit byte from the channel. | |
PBoolean | ReadBlock (void *buf, PINDEX len) |
Read len bytes into the buffer from the channel. | |
PString | ReadString (PINDEX len) |
Read len character into a string from the channel. | |
virtual PBoolean | ReadAsync (void *buf, PINDEX len) |
Begin an asynchronous read from channel. | |
virtual void | OnReadComplete (void *buf, PINDEX len) |
User callback function for when a ReadAsync() call has completed or timed out. | |
void | SetWriteTimeout (const PTimeInterval &time) |
Set the timeout for write operations to complete. | |
PTimeInterval | GetWriteTimeout () const |
Get the timeout for write operations to complete. | |
virtual PBoolean | Write (const void *buf, PINDEX len, const void *mark) |
Low level write to the channel with marker. | |
virtual PINDEX | GetLastWriteCount () const |
Get the number of bytes written by the last Write() call. | |
PBoolean | WriteChar (int c) |
Write a single character to the channel. | |
PBoolean | WriteString (const PString &str) |
Write a string to the channel. | |
virtual PBoolean | WriteAsync (const void *buf, PINDEX len) |
Begin an asynchronous write from channel. | |
virtual void | OnWriteComplete (const void *buf, PINDEX len) |
User callback function for when a WriteAsync() call has completed or timed out. | |
virtual bool | SetLocalEcho (bool localEcho) |
Set local echo mode. | |
virtual bool | FlowControl (const void *flowData) |
Flow Control information Pass data to the channel for flowControl determination. | |
PBoolean | SetBufferSize (PINDEX newSize) |
Set the iostream buffer size for reads and writes. | |
PBoolean | SendCommandString (const PString &command) |
Send a command meta-string. | |
void | AbortCommandString () |
Abort a command string that is in progress. | |
Errors | GetErrorCode (ErrorGroup group=NumErrorGroups) const |
Get normalised error code. | |
int | GetErrorNumber (ErrorGroup group=NumErrorGroups) const |
Get OS errro code. | |
virtual PString | GetErrorText (ErrorGroup group=NumErrorGroups) const |
Get error message description. | |
virtual PBoolean | Read (const VectorOfSlice &slices) |
Low level scattered read from the channel. | |
virtual PBoolean | Write (const VectorOfSlice &slices) |
Low level scattered write to the channel. | |
![]() | |
virtual | ~PObject () |
virtual PObject * | Clone () const |
Create a copy of the class on the heap. | |
virtual Comparison | CompareObjectMemoryDirect (const PObject &obj) const |
Determine the byte wise comparison of two objects. | |
bool | operator== (const PObject &obj) const |
Compare the two objects. | |
bool | operator!= (const PObject &obj) const |
Compare the two objects. | |
bool | operator< (const PObject &obj) const |
Compare the two objects. | |
bool | operator> (const PObject &obj) const |
Compare the two objects. | |
bool | operator<= (const PObject &obj) const |
Compare the two objects. | |
bool | operator>= (const PObject &obj) const |
Compare the two objects. | |
virtual const char * | GetClass (unsigned ancestor=0) const |
Get the current dynamic type of the object instance. | |
PBoolean | IsClass (const char *cls) const |
virtual PBoolean | InternalIsDescendant (const char *clsName) const |
Determine if the dynamic type of the current instance is a descendent of the specified class. | |
virtual void | PrintOn (ostream &strm) const |
Output the contents of the object to the stream. | |
virtual void | ReadFrom (istream &strm) |
Input the contents of the object from the stream. |
Protected Member Functions | |
virtual PBoolean | OpenSocket () |
virtual const char * | GetProtocolName () const |
This function returns the protocol name for the socket type. | |
![]() | |
PSocket () | |
int | os_close () |
int | os_socket (int af, int type, int proto) |
PBoolean | os_connect (struct sockaddr *sin, PINDEX size) |
PBoolean | os_recvfrom (void *buf, PINDEX len, int flags, struct sockaddr *from, PINDEX *fromlen) |
PBoolean | os_sendto (const void *buf, PINDEX len, int flags, struct sockaddr *to, PINDEX tolen) |
PBoolean | os_accept (PSocket &listener, struct sockaddr *addr, PINDEX *size) |
![]() | |
PChannel (const PChannel &) | |
PChannel & | operator= (const PChannel &) |
virtual PBoolean | ConvertOSError (int libcReturnValue, ErrorGroup group=LastGeneralError) |
Convert an operating system error into platform independent error. | |
int | ReadCharWithTimeout (PTimeInterval &timeout) |
Read a character with specified timeout. | |
PBoolean | ReceiveCommandString (int nextChar, const PString &reply, PINDEX &pos, PINDEX start) |
PBoolean | PXSetIOBlock (PXBlockType type, const PTimeInterval &timeout) |
int | PXClose () |
![]() | |
PObject () | |
Constructor for PObject, made protected so cannot ever create one on its own. |
Protected Attributes | |
WORD | filterType |
Address | macAddress |
MediumTypes | medium |
unsigned | filterMask |
PBoolean | fakeMacHeader |
PBoolean | ipppInterface |
![]() | |
WORD | port |
Port to be used by the socket when opening the channel. | |
![]() | |
int | os_handle |
The operating system file handle return by standard open() function. | |
Errors | lastErrorCode [NumErrorGroups+1] |
The platform independant error code. | |
int | lastErrorNumber [NumErrorGroups+1] |
The operating system error number (eg as returned by errno). | |
PINDEX | lastReadCount |
Number of byte last read by the Read() function. | |
PINDEX | lastWriteCount |
Number of byte last written by the Write() function. | |
PTimeInterval | readTimeout |
Timeout for read operations. | |
PTimeInterval | writeTimeout |
Timeout for write operations. | |
PString | channelName |
PMutex | px_threadMutex |
PXBlockType | px_lastBlockType |
PThread * | px_readThread |
PThread * | px_writeThread |
PMutex | px_writeMutex |
PThread * | px_selectThread [3] |
PMutex | px_selectMutex [3] |
Information functions | |
enum | MediumTypes { MediumLoop, Medium802_3, MediumWan, MediumUnknown, NumMediumTypes } |
Medium types for the open interface. More... | |
PBoolean | EnumInterfaces (PINDEX idx, PString &name) |
Enumerate all the interfaces that are capable of being accessed at the ethernet level. | |
PBoolean | GetAddress (Address &addr) |
Get the low level MAC address of the open interface. | |
PBoolean | GetIpAddress (PIPSocket::Address &addr) |
Get the prime IP number bound to the open interface. | |
PBoolean | GetIpAddress (PIPSocket::Address &addr, PIPSocket::Address &netMask) |
Get the prime IP number bound to the open interface. | |
PBoolean | EnumIpAddress (PINDEX idx, PIPSocket::Address &addr, PIPSocket::Address &netMask) |
Enumerate all of the IP addresses and net masks bound to the open interface. | |
MediumTypes | GetMedium () |
Return the type of the interface. |
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) |
Get the current filtering criteria for receiving packets. | |
PBoolean | SetFilter (unsigned mask, WORD type=TypeAll) |
Set the current filtering criteria for receiving packets. |
Additional Inherited Members | |
![]() | |
enum | Reusability { CanReuseAddress, AddressIsExclusive } |
Flags to reuse of port numbers in Listen() function. More... | |
![]() | |
enum | PXBlockType { PXReadBlock, PXWriteBlock, PXAcceptBlock, PXConnectBlock } |
enum | ShutdownValue { ShutdownRead = 0, ShutdownWrite = 1, ShutdownReadAndWrite = 2 } |
enum | Errors { NoError, NotFound, FileExists, DiskFull, AccessDenied, DeviceInUse, BadParameter, NoMemory, NotOpen, Timeout, Interrupted, BufferTooSmall, Miscellaneous, ProtocolFailure, NumNormalisedErrors } |
Normalised error codes. More... | |
enum | ErrorGroup { LastReadError, LastWriteError, LastGeneralError, NumErrorGroups } |
Error groups. More... | |
typedef std::vector< Slice > | VectorOfSlice |
![]() | |
static int | Select (PSocket &sock1, PSocket &sock2) |
Select a socket with available data. | |
static int | Select (PSocket &sock1, PSocket &sock2, const PTimeInterval &timeout) |
Select a socket with available data. | |
static Errors | Select (SelectList &read) |
Select a socket with available data. | |
static Errors | Select (SelectList &read, const PTimeInterval &timeout) |
Select a socket with available data. | |
static Errors | Select (SelectList &read, SelectList &write) |
Select a socket with available data. | |
static Errors | Select (SelectList &read, SelectList &write, const PTimeInterval &timeout) |
Select a socket with available data. | |
static Errors | Select (SelectList &read, SelectList &write, SelectList &except) |
Select a socket with available data. | |
static Errors | Select (SelectList &read, SelectList &write, SelectList &except, const PTimeInterval &timeout) |
Select a socket with available data. | |
static WORD | Host2Net (WORD v) |
Convert from host to network byte order. | |
static DWORD | Host2Net (DWORD v) |
Convert from host to network byte order. | |
static WORD | Net2Host (WORD v) |
Convert from network to host byte order. | |
static DWORD | Net2Host (DWORD v) |
Convert from network to host byte order. | |
static WORD | GetProtocolByName (const PString &name) |
Get the number of the protocol associated with the specified name. | |
static PString | GetNameByProtocol (WORD proto) |
Get the name of the protocol number specified. | |
static WORD | GetPortByService (const char *protocol, const PString &service) |
Get the port number for the specified service name. | |
static PString | GetServiceByPort (const char *protocol, WORD port) |
Get the service name from the port number. | |
![]() |
This class describes a type of socket that will communicate using raw ethernet packets.
enum PEthSocket::EthTypes |
Type codes for ethernet frames.
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. |
Mask filter bits for GetFilter() function.
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.
nReadBuffers | Number of buffers used for reading. |
nWriteBuffers | Number of buffers used for writing. |
size | Size of each buffer. |
PEthSocket::~PEthSocket | ( | ) |
Close the socket.
|
virtual |
Close the channel, shutting down the link to the data source.
Reimplemented from PChannel.
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.
address | Name of interface to connect to. |
Reimplemented from PSocket.
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.
idx | Index of interface |
name | Interface name |
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 false to enumerate all the addresses.
idx | Index |
addr | Variable to receive the IP address. |
netMask | Variable to receive the net mask. |
Get the low level MAC address of the open interface.
addr | Variable to receive the MAC address. |
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.
mask | Bits for filtering on address |
type | Code for filtering on type. |
PBoolean PEthSocket::GetIpAddress | ( | PIPSocket::Address & | addr | ) |
Get the prime IP number bound to the open interface.
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.
addr | Variable to receive the IP address. |
netMask | Variable to receive the net mask. |
MediumTypes PEthSocket::GetMedium | ( | ) |
Return the type of the interface.
|
protectedvirtual |
This function returns the protocol name for the socket type.
Implements PSocket.
|
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.
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.
|
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 false to determine what caused the failure.
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.
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.
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. |
PBoolean PEthSocket::ResetAdaptor | ( | ) |
Reset the interface.
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.
mask | Bits for filtering on address |
type | Code for filtering on type. |
|
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 false to determine what caused the failure.
buf | Pointer to a block of memory to write. |
len | Number of bytes to write. |
Reimplemented from PChannel.
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |