2
// generic/raw_protocol.hpp
3
// ~~~~~~~~~~~~~~~~~~~~~~~~
5
// Copyright (c) 2003-2013 Christopher M. Kohlhoff (chris at kohlhoff dot com)
7
// Distributed under the Boost Software License, Version 1.0. (See accompanying
8
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
11
#ifndef BOOST_ASIO_GENERIC_RAW_PROTOCOL_HPP
12
#define BOOST_ASIO_GENERIC_RAW_PROTOCOL_HPP
14
#if defined(_MSC_VER) && (_MSC_VER >= 1200)
16
#endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
18
#include <boost/asio/detail/config.hpp>
21
#include <boost/asio/basic_raw_socket.hpp>
22
#include <boost/asio/detail/socket_types.hpp>
23
#include <boost/asio/detail/throw_exception.hpp>
24
#include <boost/asio/generic/basic_endpoint.hpp>
26
#include <boost/asio/detail/push_options.hpp>
32
/// Encapsulates the flags needed for a generic raw socket.
34
* The boost::asio::generic::raw_protocol class contains flags necessary for
35
* raw sockets of any address family and protocol.
38
* Constructing using a native address family and socket protocol:
39
* @code raw_protocol p(AF_INET, IPPROTO_ICMP); @endcode
40
* Constructing from a specific protocol type:
41
* @code raw_protocol p(boost::asio::ip::icmp::v4()); @endcode
44
* @e Distinct @e objects: Safe.@n
45
* @e Shared @e objects: Safe.
53
/// Construct a protocol object for a specific address family and protocol.
54
raw_protocol(int address_family, int socket_protocol)
55
: family_(address_family),
56
protocol_(socket_protocol)
60
/// Construct a generic protocol object from a specific protocol.
62
* @throws @c bad_cast Thrown if the source protocol is not raw-oriented.
64
template <typename Protocol>
65
raw_protocol(const Protocol& source_protocol)
66
: family_(source_protocol.family()),
67
protocol_(source_protocol.protocol())
69
if (source_protocol.type() != type())
72
boost::asio::detail::throw_exception(ex);
76
/// Obtain an identifier for the type of the protocol.
82
/// Obtain an identifier for the protocol.
88
/// Obtain an identifier for the protocol family.
94
/// Compare two protocols for equality.
95
friend bool operator==(const raw_protocol& p1, const raw_protocol& p2)
97
return p1.family_ == p2.family_ && p1.protocol_ == p2.protocol_;
100
/// Compare two protocols for inequality.
101
friend bool operator!=(const raw_protocol& p1, const raw_protocol& p2)
106
/// The type of an endpoint.
107
typedef basic_endpoint<raw_protocol> endpoint;
109
/// The generic socket type.
110
typedef basic_raw_socket<raw_protocol> socket;
117
} // namespace generic
121
#include <boost/asio/detail/pop_options.hpp>
123
#endif // BOOST_ASIO_GENERIC_RAW_PROTOCOL_HPP