Dibbler - a portable DHCPv6  1.0.2RC1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
SocketIPv6.h
Go to the documentation of this file.
1 /*
2  * Dibbler - a portable DHCPv6
3  *
4  * authors: Tomasz Mrugalski <thomson@klub.com.pl>
5  * Marek Senderski <msend@o2.pl>
6  * changes: Krzysztof Wnuk <keczi@poczta.onet.pl>
7  * Micha³ Kowalczuk <michal@kowalczuk.eu>
8  *
9  * released under GNU GPL v2 only licence
10  *
11  * $Id: SocketIPv6.h,v 1.7 2008-08-29 00:07:30 thomson Exp $
12  *
13  */
14 
15 class TIfaceSocket;
16 #ifndef IFACESOCKETIPV6_H
17 #define IFACESOCKETIPV6_H
18 
19 #include <iostream>
20 #include <string>
21 
22 #include "Portable.h"
23 #include "DHCPConst.h"
24 #include "IPv6Addr.h"
25 #include "SmartPtr.h"
26 
27 /*
28  * repesents network socket
29  */
30 class TIfaceSocket {
31  friend std::ostream& operator<<(std::ostream& strum, TIfaceSocket &x);
32  public:
33  TIfaceSocket(char * iface,int ifaceid, int port,
34  SPtr<TIPv6Addr> addr, bool ifaceonly, bool reuse);
35  TIfaceSocket(char * iface,int ifaceid, int port,
36  bool ifaceonly, bool reuse);
37 
38  // ---transmission---
39  int send(char * buf,int len, SPtr<TIPv6Addr> addr,int port);
40  int recv(char * buf,SPtr<TIPv6Addr> addr);
41 
42  // ---get info---
43  inline static int getCount() { return Count; }
44  int getFD();
45  int getPort();
46  int getIfaceID();
48  enum EState getStatus();
49 
50  // ---select() stuff---
51  // FileDescriptors Set, for use with select()
52  // (it's really messed up. fd_set is some really weird macro used
53  // with POSIX select() function. )
54  static fd_set * getFDS();
55  inline static int getMaxFD() { return MaxFD; }
56  inline bool multicast() { return Multicast; }
57 
58  ~TIfaceSocket();
59  private:
60  // adds socket to this interface
61  int createSocket(char * iface, int ifaceid, SPtr<TIPv6Addr> addr,
62  int port, bool ifaceonly, bool reuse);
63  void printError(int error, char * iface, int ifaceid, SPtr<TIPv6Addr> addr, int port);
64 
65  // FileDescriptor
66  int FD;
67 
68  // bounded port
69  int Port;
70 
71  // socket status
72  enum EState Status;
73 
74  // error
75  std::string Error;
76 
77  // interface name, on which this socket has been created
79 
80  // interface ID, on which this socket has been created
81  int IfaceID;
82 
83  // bounded address
85 
86  // true = bounded to this interface only
87  bool IfaceOnly;
88 
89  // true = bounded to multicast socket
90  bool Multicast;
91 
92  // Static element. Class needs to know, when first object is
93  // created. It call FD_SET to zero fd_set
94  static int Count;
95  static int MaxFD; // needed instead of FD_MAXSIZE on Macs
96 };
97 
98 
99 #endif
100 
101