ethsock.h
Go to the documentation of this file.
/*
* ethsock.h
*
* Direct Ethernet socket I/O channel class.
*
* Portable Windows Library
*
* Copyright (c) 1993-1998 Equivalence Pty. Ltd.
*
* The contents of this file are subject to the Mozilla Public License
* Version 1.0 (the "License"); you may not use this file except in
* compliance with the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS"
* basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
* the License for the specific language governing rights and limitations
* under the License.
*
* The Original Code is Portable Windows Library.
*
* The Initial Developer of the Original Code is Equivalence Pty. Ltd.
*
* Portions are Copyright (C) 1993 Free Software Foundation, Inc.
* All Rights Reserved.
*
* Contributor(s): ______________________________________.
*
* $Revision: 24177 $
* $Author: rjongbloed $
* $Date: 2010-04-05 06:52:04 -0500 (Mon, 05 Apr 2010) $
*/
#ifndef PTLIB_ETHSOCKET_H
#define PTLIB_ETHSOCKET_H
#ifdef P_USE_PRAGMA
#pragma interface
#endif
#include <ptlib/socket.h>
#ifdef _WIN32
class PWin32PacketDriver;
class PWin32SnmpLibrary;
class PWin32PacketBuffer;
PARRAY(PWin32PackBufArray, PWin32PacketBuffer);
#endif
class PEthSocket : public PSocket
{
PCLASSINFO(PEthSocket, PSocket);
public:
PEthSocket(
PINDEX nReadBuffers = 8,
PINDEX nWriteBuffers = 1,
PINDEX size = 1514
);
~PEthSocket();
public:
#pragma pack(1)
union Address {
BYTE b[6];
WORD w[3];
struct {
DWORD l;
WORD s;
} ls;
Address();
Address(const BYTE * addr);
Address(const Address & addr);
Address(const PString & str);
Address & operator=(const Address & addr);
Address & operator=(const PString & str);
bool operator==(const BYTE * eth) const;
bool operator!=(const BYTE * eth) const;
bool operator==(const Address & eth) const { return ls.l == eth.ls.l && ls.s == eth.ls.s; }
bool operator!=(const Address & eth) const { return ls.l != eth.ls.l || ls.s != eth.ls.s; }
operator PString() const;
friend ostream & operator<<(ostream & s, const Address & a)
{ return s << (PString)a; }
};
struct Frame {
Address dst_addr;
Address src_addr;
union {
struct {
WORD type;
BYTE payload[1500];
} ether;
struct {
WORD length;
BYTE dsap;
BYTE ssap;
BYTE ctrl;
BYTE oui[3];
WORD type;
BYTE payload[1492];
} snap;
};
void Parse(
WORD & type, // Type of frame
BYTE * & payload, // Pointer to payload
PINDEX & length // Length of payload (on input is full frame length)
);
};
#pragma pack()
virtual PBoolean Close();
virtual PBoolean Read(
void * buf,
PINDEX len
);
virtual PBoolean Write(
const void * buf,
PINDEX len
);
virtual PBoolean Connect(
const PString & address
);
virtual PBoolean Listen(
unsigned queueSize = 5,
WORD port = 0,
Reusability reuse = AddressIsExclusive
);
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
);
enum MediumTypes {
MediumLoop,
Medium802_3,
MediumWan,
MediumUnknown,
NumMediumTypes
};
MediumTypes GetMedium();
enum EthTypes {
TypeAll = 3,
TypeIP = 0x800,
TypeX25 = 0x805,
TypeARP = 0x806,
TypeAtalk = 0x809B,
TypeAARP = 0x80F3,
TypeIPX = 0x8137,
TypeIPv6 = 0x86DD
};
enum FilterMask {
FilterDirected = 0x01,
FilterMulticast = 0x02,
FilterAllMulticast = 0x04,
FilterBroadcast = 0x08,
FilterPromiscuous = 0x10
};
PBoolean GetFilter(
unsigned & mask,
WORD & type
);
PBoolean SetFilter(
unsigned mask,
WORD type = TypeAll
);
PBoolean ResetAdaptor();
PBoolean ReadPacket(
PBYTEArray & buffer,
Address & dest,
Address & src,
WORD & type,
PINDEX & len,
BYTE * & payload
);
protected:
virtual PBoolean OpenSocket();
virtual const char * GetProtocolName() const;
WORD filterType; // Remember the set filter frame type
// Include platform dependent part of class
#ifdef _WIN32
#include "msos/ptlib/ethsock.h"
#else
#include "unix/ptlib/ethsock.h"
#endif
};
#endif // PTLIB_ETHSOCKET_H
// End Of File ///////////////////////////////////////////////////////////////
PEthSocket::FilterDirected
Packets directed at the interface.
Definition: ethsock.h:317
PEthSocket::Address::b
BYTE b[6]
Definition: ethsock.h:80
PSocket::AddressIsExclusive
Definition: socket.h:86
PEthSocket::Frame::ctrl
BYTE ctrl
Definition: ethsock.h:119
PEthSocket::GetProtocolName
virtual const char * GetProtocolName() const
This function returns the protocol name for the socket type.
PEthSocket::FilterBroadcast
Packets with a broadcast address.
Definition: ethsock.h:323
PEthSocket::Address::s
WORD s
Definition: ethsock.h:84
PEthSocket::Frame::ssap
BYTE ssap
Definition: ethsock.h:118
PEthSocket::~PEthSocket
~PEthSocket()
Close the socket.
PEthSocket::TypeAtalk
Appletalk DDP.
Definition: ethsock.h:305
PEthSocket::Address::ls
struct PEthSocket::Address::@0 ls
PEthSocket::Address::operator==
bool operator==(const Address &eth) const
Definition: ethsock.h:96
PEthSocket::OpenSocket
virtual PBoolean OpenSocket()
PEthSocket::GetMedium
MediumTypes GetMedium()
Return the type of the interface.
PEthSocket::Address::w
WORD w[3]
Definition: ethsock.h:81
PEthSocket::MediumTypes
MediumTypes
Medium types for the open interface.
Definition: ethsock.h:272
PEthSocket::FilterMulticast
Multicast packets directed at the interface.
Definition: ethsock.h:319
PEthSocket::Address::operator<<
friend ostream & operator<<(ostream &s, const Address &a)
Definition: ethsock.h:101
PEthSocket::Frame::length
WORD length
Definition: ethsock.h:116
PEthSocket::GetFilter
PBoolean GetFilter(unsigned &mask, WORD &type)
Get the current filtering criteria for receiving packets.
PEthSocket::Address
An ethernet MAC Address specification.
Definition: ethsock.h:79
PEthSocket::SetFilter
PBoolean SetFilter(unsigned mask, WORD type=TypeAll)
Set the current filtering criteria for receiving packets.
PEthSocket::ReadPacket
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.
PEthSocket::Close
virtual PBoolean Close()
Close the channel, shutting down the link to the data source.
PEthSocket::Address::operator!=
bool operator!=(const Address &eth) const
Definition: ethsock.h:97
PEthSocket::ResetAdaptor
PBoolean ResetAdaptor()
Reset the interface.
PSocket::port
WORD port
Port to be used by the socket when opening the channel.
Definition: socket.h:444
PEthSocket::MediumWan
A Wide Area Network (modem etc)
Definition: ethsock.h:278
PEthSocket::TypeX25
X.25.
Definition: ethsock.h:301
PEthSocket::FilterMask
FilterMask
Mask filter bits for GetFilter() function.
Definition: ethsock.h:315
PEthSocket::Address::operator==
bool operator==(const BYTE *eth) const
PBoolean
BOOL PBoolean
Definition: object.h:102
PEthSocket::TypeAll
All frames (3 is value for Linux)
Definition: ethsock.h:297
PEthSocket::TypeIPv6
Bluebook IPv6.
Definition: ethsock.h:311
PBYTEArray
Array of unsigned characters.
Definition: array.h:670
PEthSocket::Medium802_3
An ethernet Network Interface Card (10base2, 10baseT etc)
Definition: ethsock.h:276
PEthSocket::TypeARP
Address Resolution Protocol.
Definition: ethsock.h:303
PEthSocket::MediumUnknown
Something else.
Definition: ethsock.h:280
PARRAY
#define PARRAY(cls, T)
Declare an array to a specific type of object.
Definition: array.h:1084
PString
The character string class.
Definition: pstring.h:108
PEthSocket::GetAddress
PBoolean GetAddress(Address &addr)
Get the low level MAC address of the open interface.
PEthSocket::EthTypes
EthTypes
Type codes for ethernet frames.
Definition: ethsock.h:295
PEthSocket::TypeIP
Internet Protocol.
Definition: ethsock.h:299
PEthSocket::GetIpAddress
PBoolean GetIpAddress(PIPSocket::Address &addr)
Get the prime IP number bound to the open interface.
PEthSocket::Frame::src_addr
Address src_addr
Definition: ethsock.h:109
PEthSocket::NumMediumTypes
Definition: ethsock.h:281
PEthSocket::Frame::type
WORD type
Definition: ethsock.h:112
PEthSocket::filterType
WORD filterType
Definition: ethsock.h:391
PEthSocket::Frame
An ethernet MAC frame.
Definition: ethsock.h:107
PEthSocket::TypeAARP
Appletalk AARP.
Definition: ethsock.h:307
PEthSocket::Address::operator!=
bool operator!=(const BYTE *eth) const
PEthSocket::PEthSocket
PEthSocket(PINDEX nReadBuffers=8, PINDEX nWriteBuffers=1, PINDEX size=1514)
Create a new ethernet packet socket.
PEthSocket::Connect
virtual PBoolean Connect(const PString &address)
Connect a socket to an interface.
PEthSocket::Write
virtual PBoolean Write(const void *buf, PINDEX len)
Low level write to the channel.
PIPSocket::Address
A class describing an IP address.
Definition: ipsock.h:75
PEthSocket::Address::l
DWORD l
Definition: ethsock.h:83
PEthSocket::EnumIpAddress
PBoolean EnumIpAddress(PINDEX idx, PIPSocket::Address &addr, PIPSocket::Address &netMask)
Enumerate all of the IP addresses and net masks bound to the open interface.
PEthSocket::Frame::dst_addr
Address dst_addr
Definition: ethsock.h:108
PSocket
A network communications channel.
Definition: socket.h:58
PEthSocket::FilterAllMulticast
All multicast packets.
Definition: ethsock.h:321
PEthSocket::EnumInterfaces
PBoolean EnumInterfaces(PINDEX idx, PString &name)
Enumerate all the interfaces that are capable of being accessed at the ethernet level.
socket.h
PEthSocket::FilterPromiscuous
All packets.
Definition: ethsock.h:325
PEthSocket::Read
virtual PBoolean Read(void *buf, PINDEX len)
Low level read from the channel.
PEthSocket::Listen
virtual PBoolean Listen(unsigned queueSize=5, WORD port=0, Reusability reuse=AddressIsExclusive)
This function is illegal and will assert if attempted.
PSocket::Reusability
Reusability
Flags to reuse of port numbers in Listen() function.
Definition: socket.h:84
PEthSocket::TypeIPX
Novell IPX.
Definition: ethsock.h:309
PEthSocket
This class describes a type of socket that will communicate using raw ethernet packets.
Definition: ethsock.h:54
PEthSocket::Frame::dsap
BYTE dsap
Definition: ethsock.h:117
PEthSocket::Address::Address
Address()
PEthSocket::MediumLoop
A Loopback Network.
Definition: ethsock.h:274
PEthSocket::Address::operator=
Address & operator=(const Address &addr)