PTLib  Version 2.10.4
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
ethsock.h
Go to the documentation of this file.
1 /*
2  * ethsock.h
3  *
4  * Direct Ethernet socket I/O channel class.
5  *
6  * Portable Windows Library
7  *
8  * Copyright (c) 1993-1998 Equivalence Pty. Ltd.
9  *
10  * The contents of this file are subject to the Mozilla Public License
11  * Version 1.0 (the "License"); you may not use this file except in
12  * compliance with the License. You may obtain a copy of the License at
13  * http://www.mozilla.org/MPL/
14  *
15  * Software distributed under the License is distributed on an "AS IS"
16  * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
17  * the License for the specific language governing rights and limitations
18  * under the License.
19  *
20  * The Original Code is Portable Windows Library.
21  *
22  * The Initial Developer of the Original Code is Equivalence Pty. Ltd.
23  *
24  * Portions are Copyright (C) 1993 Free Software Foundation, Inc.
25  * All Rights Reserved.
26  *
27  * Contributor(s): ______________________________________.
28  *
29  * $Revision: 24177 $
30  * $Author: rjongbloed $
31  * $Date: 2010-04-05 06:52:04 -0500 (Mon, 05 Apr 2010) $
32  */
33 
34 #ifndef PTLIB_ETHSOCKET_H
35 #define PTLIB_ETHSOCKET_H
36 
37 #ifdef P_USE_PRAGMA
38 #pragma interface
39 #endif
40 
41 #include <ptlib/socket.h>
42 
43 #ifdef _WIN32
44 class PWin32PacketDriver;
45 class PWin32SnmpLibrary;
46 class PWin32PacketBuffer;
47 
48 PARRAY(PWin32PackBufArray, PWin32PacketBuffer);
49 #endif
50 
54 class PEthSocket : public PSocket
55 {
56  PCLASSINFO(PEthSocket, PSocket);
57 
58  public:
64  PEthSocket(
65  PINDEX nReadBuffers = 8,
66  PINDEX nWriteBuffers = 1,
67  PINDEX size = 1514
68  );
69 
71  ~PEthSocket();
73 
74 
75  public:
76 #pragma pack(1)
77 
79  union Address {
80  BYTE b[6];
81  WORD w[3];
82  struct {
83  DWORD l;
84  WORD s;
85  } ls;
86 
87  Address();
88  Address(const BYTE * addr);
89  Address(const Address & addr);
90  Address(const PString & str);
91  Address & operator=(const Address & addr);
92  Address & operator=(const PString & str);
93 
94  bool operator==(const BYTE * eth) const;
95  bool operator!=(const BYTE * eth) const;
96  bool operator==(const Address & eth) const { return ls.l == eth.ls.l && ls.s == eth.ls.s; }
97  bool operator!=(const Address & eth) const { return ls.l != eth.ls.l || ls.s != eth.ls.s; }
98 
99  operator PString() const;
100 
101  friend ostream & operator<<(ostream & s, const Address & a)
102  { return s << (PString)a; }
103  };
104 
107  struct Frame {
110  union {
111  struct {
112  WORD type;
113  BYTE payload[1500];
114  } ether;
115  struct {
116  WORD length;
117  BYTE dsap;
118  BYTE ssap;
119  BYTE ctrl;
120  BYTE oui[3];
121  WORD type;
122  BYTE payload[1492];
123  } snap;
124  };
125 
130  void Parse(
131  WORD & type, // Type of frame
132  BYTE * & payload, // Pointer to payload
133  PINDEX & length // Length of payload (on input is full frame length)
134  );
135  };
136 #pragma pack()
137 
145  virtual PBoolean Close();
146 
159  virtual PBoolean Read(
160  void * buf,
161  PINDEX len
162  );
163 
175  virtual PBoolean Write(
176  const void * buf,
177  PINDEX len
178  );
180 
190  virtual PBoolean Connect(
191  const PString & address
192  );
193 
200  virtual PBoolean Listen(
201  unsigned queueSize = 5,
202  WORD port = 0,
204  );
206 
207 
221  PINDEX idx,
222  PString & name
223  );
224 
225 
232  Address & addr
233  );
234 
241  PIPSocket::Address & addr
242  );
243 
251  PIPSocket::Address & addr,
252  PIPSocket::Address & netMask
253  );
254 
265  PINDEX idx,
266  PIPSocket::Address & addr,
267  PIPSocket::Address & netMask
268  );
269 
270 
272  enum MediumTypes {
282  };
290 
291 
294 
295  enum EthTypes {
297  TypeAll = 3,
299  TypeIP = 0x800,
301  TypeX25 = 0x805,
303  TypeARP = 0x806,
305  TypeAtalk = 0x809B,
307  TypeAARP = 0x80F3,
309  TypeIPX = 0x8137,
311  TypeIPv6 = 0x86DD
312  };
313 
315  enum FilterMask {
317  FilterDirected = 0x01,
326  };
327 
340  unsigned & mask,
341  WORD & type
342  );
343 
357  unsigned mask,
358  WORD type = TypeAll
359  );
361 
362 
368 
377  PBYTEArray & buffer,
378  Address & dest,
379  Address & src,
380  WORD & type,
381  PINDEX & len,
382  BYTE * & payload
383  );
385 
386  protected:
387  virtual PBoolean OpenSocket();
388  virtual const char * GetProtocolName() const;
389 
390 
391  WORD filterType; // Remember the set filter frame type
392 
393 
394 // Include platform dependent part of class
395 #ifdef _WIN32
396 #include "msos/ptlib/ethsock.h"
397 #else
398 #include "unix/ptlib/ethsock.h"
399 #endif
400 };
401 
402 
403 #endif // PTLIB_ETHSOCKET_H
404 
405 
406 // End Of File ///////////////////////////////////////////////////////////////