1//
2// RawSocketImpl.cpp
3//
4// Library: Net
5// Package: Sockets
6// Module: RawSocketImpl
7//
8// Copyright (c) 2006, Applied Informatics Software Engineering GmbH.
9// and Contributors.
10//
11// SPDX-License-Identifier: BSL-1.0
12//
13
14
15#include "Poco/Net/RawSocketImpl.h"
16#include "Poco/Net/NetException.h"
17
18
19using Poco::InvalidArgumentException;
20
21
22namespace Poco {
23namespace Net {
24
25
26RawSocketImpl::RawSocketImpl()
27{
28 init(AF_INET);
29}
30
31
32RawSocketImpl::RawSocketImpl(SocketAddress::Family family, int proto)
33{
34 if (family == SocketAddress::IPv4)
35 init2(AF_INET, proto);
36#if defined(POCO_HAVE_IPv6)
37 else if (family == SocketAddress::IPv6)
38 init2(AF_INET6, proto);
39#endif
40 else throw InvalidArgumentException("Invalid or unsupported address family passed to RawSocketImpl");
41
42}
43
44
45RawSocketImpl::RawSocketImpl(poco_socket_t sockfd):
46 SocketImpl(sockfd)
47{
48}
49
50
51RawSocketImpl::~RawSocketImpl()
52{
53}
54
55
56void RawSocketImpl::init(int af)
57{
58 init2(af, IPPROTO_RAW);
59}
60
61
62void RawSocketImpl::init2(int af, int proto)
63{
64 initSocket(af, SOCK_RAW, proto);
65 setOption(IPPROTO_IP, IP_HDRINCL, 0);
66}
67
68
69} } // namespace Poco::Net
70