c623ed70cfc5c5dcc78b6371b3f0e287c4f9c18d
[senf.git] / Socket / Protocols / INet / RawInetSocketHandle.cc
1 // Copyright (C) 2007 
2 // Fraunhofer Institut fuer offene Kommunikationssysteme (FOKUS)
3 // Kompetenzzentrum NETwork research (NET)
4 //     David Wagner <david.wagner@fokus.fraunhofer.de>
5 //
6 // This program is free software; you can redistribute it and/or modify
7 // it under the terms of the GNU General Public License as published by
8 // the Free Software Foundation; either version 2 of the License, or
9 // (at your option) any later version.
10 //
11 // This program is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 // GNU General Public License for more details.
15 //
16 // You should have received a copy of the GNU General Public License
17 // along with this program; if not, write to the
18 // Free Software Foundation, Inc.,
19 // 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
20
21 #include "RawInetSocketHandle.hh"
22
23 // Custom includes
24 #include <sys/types.h>
25 #include <sys/socket.h>
26 #include <sys/ioctl.h>
27
28 #include "../../../Utils/Exception.hh"
29
30 //#include "UDPSocketHandle.mpp"
31 #define prefix_
32 ///////////////////////////////cc.p////////////////////////////////////////
33
34 ///////////////////////////////////////////////////////////////////////////
35 // senf::RawV4SocketProtocol
36
37 prefix_ void senf::RawV4SocketProtocol::init_client()
38     const
39 {
40     init_client(IPPROTO_RAW);
41 }
42
43 prefix_ void
44 senf::RawV4SocketProtocol::init_client(int const & protocol)
45     const
46 {
47     int sock = ::socket(PF_INET, SOCK_RAW, protocol);
48     if (sock < 0)
49         throwErrno();
50     fd(sock);
51 }
52
53 prefix_ void
54 senf::RawV4SocketProtocol::init_client(int const & protocol, INet4SocketAddress const & address)
55     const
56 {
57     init_client(protocol);
58     bind(address);
59 }
60
61 prefix_ std::auto_ptr<senf::SocketProtocol> senf::RawV4SocketProtocol::clone()
62     const
63 {
64     return std::auto_ptr<SocketProtocol>(new RawV4SocketProtocol());
65 }
66
67 ///////////////////////////////////////////////////////////////////////////
68 // senf::RawV6SocketProtocol::
69
70 prefix_ void senf::RawV6SocketProtocol::init_client()
71     const
72 {
73     init_client(IPPROTO_RAW);
74 }
75
76 prefix_ void senf::RawV6SocketProtocol::init_client(int const & protocol)
77     const
78 {
79     int sock = ::socket(PF_INET6,SOCK_RAW,protocol);
80     if (sock < 0)
81         throwErrno();
82     fd(sock);
83 }
84
85 prefix_ void
86 senf::RawV6SocketProtocol::init_client(int const & protocol, INet6SocketAddress const & address)
87     const
88 {
89     init_client(protocol);
90     bind(address);
91 }
92
93 prefix_ std::auto_ptr<senf::SocketProtocol> senf::RawV6SocketProtocol::clone()
94     const
95 {
96     return std::auto_ptr<SocketProtocol>(new RawV6SocketProtocol());
97 }
98
99 ///////////////////////////////cc.e////////////////////////////////////////
100 #undef prefix_
101 //#include "RawInetSocketHandle.mpp"
102
103 \f
104 // Local Variables:
105 // mode: c++
106 // fill-column: 100
107 // comment-column: 40
108 // c-file-style: "senf"
109 // indent-tabs-mode: nil
110 // ispell-local-dictionary: "american"
111 // compile-command: "scons -u test"
112 // End: