/usr/include/Poco/Net/SocketAddressImpl.h is in libpoco-dev 1.8.0.1-1ubuntu4.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 | //
// SocketAddressImpl.h
//
// Library: Net
// Package: NetCore
// Module: SocketAddressImpl
//
// Definition of the SocketAddressImpl class.
//
// Copyright (c) 2005-2006, Applied Informatics Software Engineering GmbH.
// and Contributors.
//
// SPDX-License-Identifier: BSL-1.0
//
#ifndef Net_SocketAddressImpl_INCLUDED
#define Net_SocketAddressImpl_INCLUDED
#include "Poco/Net/Net.h"
#include "Poco/Net/SocketDefs.h"
#include "Poco/Net/IPAddress.h"
#include "Poco/RefCountedObject.h"
namespace Poco {
namespace Net {
namespace Impl {
class Net_API SocketAddressImpl : public Poco::RefCountedObject
{
public:
typedef AddressFamily::Family Family;
virtual ~SocketAddressImpl();
virtual IPAddress host() const = 0;
virtual UInt16 port() const = 0;
virtual poco_socklen_t length() const = 0;
virtual const struct sockaddr* addr() const = 0;
virtual int af() const = 0;
virtual Family family() const = 0;
virtual std::string toString() const = 0;
protected:
SocketAddressImpl();
private:
SocketAddressImpl(const SocketAddressImpl&);
SocketAddressImpl& operator = (const SocketAddressImpl&);
};
class Net_API IPv4SocketAddressImpl: public SocketAddressImpl
{
public:
IPv4SocketAddressImpl();
IPv4SocketAddressImpl(const struct sockaddr_in* addr);
IPv4SocketAddressImpl(const void* addr, UInt16 port);
IPAddress host() const;
UInt16 port() const;
poco_socklen_t length() const;
const struct sockaddr* addr() const;
int af() const;
Family family() const;
std::string toString() const;
private:
struct sockaddr_in _addr;
};
//
// inlines
//
inline IPAddress IPv4SocketAddressImpl::host() const
{
return IPAddress(&_addr.sin_addr, sizeof(_addr.sin_addr));
}
inline UInt16 IPv4SocketAddressImpl::port() const
{
return _addr.sin_port;
}
inline poco_socklen_t IPv4SocketAddressImpl::length() const
{
return sizeof(_addr);
}
inline const struct sockaddr* IPv4SocketAddressImpl::addr() const
{
return reinterpret_cast<const struct sockaddr*>(&_addr);
}
inline int IPv4SocketAddressImpl::af() const
{
return _addr.sin_family;
}
inline SocketAddressImpl::Family IPv4SocketAddressImpl::family() const
{
return AddressFamily::IPv4;
}
#if defined(POCO_HAVE_IPv6)
class Net_API IPv6SocketAddressImpl: public SocketAddressImpl
{
public:
IPv6SocketAddressImpl(const struct sockaddr_in6* addr);
IPv6SocketAddressImpl(const void* addr, UInt16 port);
IPv6SocketAddressImpl(const void* addr, UInt16 port, UInt32 scope);
IPAddress host() const;
UInt16 port() const;
poco_socklen_t length() const;
const struct sockaddr* addr() const;
int af() const;
Family family() const;
std::string toString() const;
private:
struct sockaddr_in6 _addr;
};
//
// inlines
//
inline IPAddress IPv6SocketAddressImpl::host() const
{
return IPAddress(&_addr.sin6_addr, sizeof(_addr.sin6_addr), _addr.sin6_scope_id);
}
inline UInt16 IPv6SocketAddressImpl::port() const
{
return _addr.sin6_port;
}
inline poco_socklen_t IPv6SocketAddressImpl::length() const
{
return sizeof(_addr);
}
inline const struct sockaddr* IPv6SocketAddressImpl::addr() const
{
return reinterpret_cast<const struct sockaddr*>(&_addr);
}
inline int IPv6SocketAddressImpl::af() const
{
return _addr.sin6_family;
}
inline SocketAddressImpl::Family IPv6SocketAddressImpl::family() const
{
return AddressFamily::IPv6;
}
#endif // POCO_HAVE_IPv6
#if defined(POCO_OS_FAMILY_UNIX)
class Net_API LocalSocketAddressImpl: public SocketAddressImpl
{
public:
LocalSocketAddressImpl(const struct sockaddr_un* addr);
LocalSocketAddressImpl(const char* path);
~LocalSocketAddressImpl();
IPAddress host() const;
UInt16 port() const;
poco_socklen_t length() const;
const struct sockaddr* addr() const;
int af() const;
Family family() const;
const char* path() const;
std::string toString() const;
private:
struct sockaddr_un* _pAddr;
// Note: We allocate struct sockaddr_un on the heap, otherwise we would
// waste a lot of memory due to small object optimization in SocketAddress.
};
//
// inlines
//
inline IPAddress LocalSocketAddressImpl::host() const
{
throw Poco::InvalidAccessException("local socket address does not have host IP address");
}
inline UInt16 LocalSocketAddressImpl::port() const
{
throw Poco::InvalidAccessException("local socket address does not have port number");
}
inline poco_socklen_t LocalSocketAddressImpl::length() const
{
return sizeof(struct sockaddr_un);
}
inline const struct sockaddr* LocalSocketAddressImpl::addr() const
{
return reinterpret_cast<const struct sockaddr*>(_pAddr);
}
inline int LocalSocketAddressImpl::af() const
{
return _pAddr->sun_family;
}
inline SocketAddressImpl::Family LocalSocketAddressImpl::family() const
{
return AddressFamily::UNIX_LOCAL;
}
inline const char* LocalSocketAddressImpl::path() const
{
return _pAddr->sun_path;
}
#endif // POCO_OS_FAMILY_UNIX
} } } // namespace Poco::Net::Impl
#endif // Net_SocketAddressImpl_INCLUDED
|