179d7aa93e351e903fea4c02537eb08b525285ff
[senf.git] / Socket / PacketSocketHandle.hh
1 // $Id$
2 //
3 // Copyright (C) 2006 
4 // Fraunhofer Institut fuer offene Kommunikationssysteme (FOKUS)
5 // Kompetenzzentrum fuer Satelitenkommunikation (SatCom)
6 //     Stefan Bund <stefan.bund@fokus.fraunhofer.de>
7 //
8 // This program is free software; you can redistribute it and/or modify
9 // it under the terms of the GNU General Public License as published by
10 // the Free Software Foundation; either version 2 of the License, or
11 // (at your option) any later version.
12 //
13 // This program is distributed in the hope that it will be useful,
14 // but WITHOUT ANY WARRANTY; without even the implied warranty of
15 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16 // GNU General Public License for more details.
17 //
18 // You should have received a copy of the GNU General Public License
19 // along with this program; if not, write to the
20 // Free Software Foundation, Inc.,
21 // 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
22
23 #ifndef HH_PacketSocketHandle_
24 #define HH_PacketSocketHandle_ 1
25
26 // Custom includes
27 #include "SocketPolicy.hh"
28 #include "SocketProtocol.hh"
29 #include "ProtocolClientSocketHandle.hh"
30 #include "LLAddressing.hh"
31 #include "FramingPolicy.hh"
32 #include "CommunicationPolicy.hh"
33 #include "ReadWritePolicy.hh"
34 #include "BufferingPolicy.hh"
35 #include "BSDSocketProtocol.hh"
36
37 //#include "PacketSocketHandle.mpp"
38 #include "PacketSocketHandle.ih"
39 ///////////////////////////////hh.p////////////////////////////////////////
40
41 namespace satcom {
42 namespace lib {
43     
44     typedef MakeSocketPolicy<
45         LLAddressingPolicy,
46         DatagramFramingPolicy,
47         UnconnectedCommunicationPolicy,
48         ReadablePolicy,
49         WriteablePolicy,
50         SocketBufferingPolicy
51         >::policy Packet_Policy;
52
53     class PacketProtocol 
54         : public ConcreteSocketProtocol<Packet_Policy>,
55           public BSDSocketProtocol
56     {
57     public:
58         enum SocketType { RawSocket, DatagramSocket };
59
60         void init_client(SocketType type = RawSocket, int protocol = -1) const;
61
62         std::auto_ptr<SocketProtocol> clone() const;
63
64         enum PromiscMode { Promiscuous, AllMulticast, None };
65
66         void promisc(std::string interface, PromiscMode mode) const;
67         // See LLSocketAddress for a discussion/rationale for
68         // ForwardRange here
69         template <class ForwardRange>
70         void mcAdd(std::string interface, ForwardRange const & address) const;
71         template <class ForwardRange>
72         void mcDrop(std::string interface, ForwardRange const & address) const;
73
74         unsigned available() const;
75         bool eof() const;
76
77     private:
78         template<class ForwardRange>
79         void do_mc(std::string interface, ForwardRange const & address, bool add) const;
80         void do_mc_i(std::string interface, detail::LLAddressCopier const & copier, bool add) const;
81     };
82
83     typedef ProtocolClientSocketHandle<PacketProtocol> PacketSocketHandle;
84
85 }}
86
87 ///////////////////////////////hh.e////////////////////////////////////////
88 //#include "PacketSocketHandle.cci"
89 #include "PacketSocketHandle.ct"
90 #include "PacketSocketHandle.cti"
91 //#include "PacketSocketHandle.mpp"
92 #endif
93
94 \f
95 // Local Variables:
96 // mode: c++
97 // c-file-style: "satcom"
98 // End: