scclib
Stable Cloud Computing C++ Library
unix.h
Go to the documentation of this file.
1 /*
2 BSD 3-Clause License
3 
4 Copyright (c) 2022, Stable Cloud Computing, Inc.
5 
6 Redistribution and use in source and binary forms, with or without
7 modification, are permitted provided that the following conditions are met:
8 
9 1. Redistributions of source code must retain the above copyright notice, this
10  list of conditions and the following disclaimer.
11 
12 2. Redistributions in binary form must reproduce the above copyright notice,
13  this list of conditions and the following disclaimer in the documentation
14  and/or other materials provided with the distribution.
15 
16 3. Neither the name of the copyright holder nor the names of its
17  contributors may be used to endorse or promote products derived from
18  this software without specific prior written permission.
19 
20 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
23 DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
24 FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25 DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
26 SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
27 CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
28 OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
29 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30 */
31 #ifndef _NET_UNIX_H
32 #define _NET_UNIX_H
33 
34 #include <string>
35 #include <cstdint>
36 #include <net/socket.h>
37 
38 struct sockaddr_un;
39 
40 namespace scc::net {
41 
58 class UnixAddr : public SockaddrBase
59 {
60  sockaddr_un* m_addr;
61 
62  void init();
63 
64 public:
65  UnixAddr();
66  virtual ~UnixAddr();
67  UnixAddr(const std::string&);
69  UnixAddr(const sockaddr*);
71  UnixAddr(const UnixAddr&);
73  UnixAddr& operator=(const UnixAddr&);
75  UnixAddr(UnixAddr&&);
78 
80  virtual operator const sockaddr*() const;
82  virtual operator sockaddr*();
84  virtual unsigned len() const;
86  virtual std::string str() const;
88  virtual std::string host() const;
89 
91  void host(const std::string&);
92 };
93 
96 class UnixTcpSock : public TcpSocket
97 {
98  explicit UnixTcpSock(int);
99 
100 public:
101  UnixTcpSock();
102 
106  virtual void reset();
107 
111  UnixAddr get_addr();
112 
129 };
130 
133 class UnixUdpSock : public UdpSocket
134 {
135 public:
136  UnixUdpSock();
137 
141  virtual void reset();
142 
146  UnixAddr get_addr();
147 };
148 
152 } // namespace
153 
154 std::ostream& operator<<(std::ostream&, const scc::net::UnixAddr&); // streaming helper
155 
156 #endif
Socket address base class.
Definition: socket.h:60
Tcp socket base class.
Definition: socket.h:291
Udp socket base class.
Definition: socket.h:349
A unix domain address, which is a file of type "socket.".
Definition: unix.h:59
UnixAddr()
IPv6 SocketBase address, initialized with "any" address.
Definition: unix.cc:56
virtual std::string host() const
Get host name.
Definition: unix.cc:136
virtual std::string str() const
Descriptive string for socket address.
Definition: unix.cc:146
UnixAddr & operator=(const UnixAddr &)
Copy assign.
Definition: unix.cc:84
virtual unsigned len() const
Length of socket address.
Definition: unix.cc:113
Unix domain tcp (stream) socket.
Definition: unix.h:97
UnixTcpSock accept()
Accept a connection from an anonymous peer.
Definition: unix.cc:169
virtual void reset()
Reset the socket.
Definition: unix.cc:157
UnixAddr get_addr()
Get the socket address.
Definition: unix.cc:162
Unix domain udp (datagram) socket.
Definition: unix.h:134
virtual void reset()
Reset the socket.
Definition: unix.cc:197
UnixAddr get_addr()
Get the socket address.
Definition: unix.cc:202
std::ostream & operator<<(std::ostream &, const scc::net::InetAddr &)
Print the socket address details to an output stream.
Definition: inet.cc:320
Low-level tcp and udp sockets.