ftpiiu_plugin/include/sockAddr.h

117 lines
3.1 KiB
C
Raw Permalink Normal View History

2020-04-05 21:16:16 +02:00
// ftpd is a server implementation based on the following:
// - RFC 959 (https://tools.ietf.org/html/rfc959)
// - RFC 3659 (https://tools.ietf.org/html/rfc3659)
// - suggested implementation details from https://cr.yp.to/ftp/filesystem.html
//
// Copyright (C) 2020 Michael Theall
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.
#pragma once
#include <netinet/in.h>
#include <sys/socket.h>
#include <cstdint>
2020-04-17 22:32:39 +02:00
#ifdef NDS
struct sockaddr_storage
{
unsigned short ss_family;
char ss_data[sizeof (struct sockaddr_in) - sizeof (unsigned short)];
};
#endif
2020-04-06 07:36:03 +02:00
/// \brief Socket address
2020-04-05 21:16:16 +02:00
class SockAddr
{
public:
~SockAddr ();
SockAddr ();
2020-04-06 07:36:03 +02:00
/// \brief Copy constructor
/// \param that_ Object to copy
2020-04-05 21:16:16 +02:00
SockAddr (SockAddr const &that_);
2020-04-06 07:36:03 +02:00
/// \brief Move constructor
/// \param that_ Object to move from
2020-04-05 21:16:16 +02:00
SockAddr (SockAddr &&that_);
2020-04-06 07:36:03 +02:00
/// \brief Copy assignment
/// \param that_ Object to copy
2020-04-05 21:16:16 +02:00
SockAddr &operator= (SockAddr const &that_);
2020-04-06 07:36:03 +02:00
/// \brief Move assignment
/// \param that_ Object to move from
2020-04-05 21:16:16 +02:00
SockAddr &operator= (SockAddr &&that_);
2020-04-06 07:36:03 +02:00
/// \param Parameterized constructor
/// \param addr_ Address
2020-04-05 21:16:16 +02:00
SockAddr (struct sockaddr const &addr_);
2020-04-06 07:36:03 +02:00
/// \param Parameterized constructor
/// \param addr_ Address
2020-04-05 21:16:16 +02:00
SockAddr (struct sockaddr_in const &addr_);
2022-03-31 18:53:47 +02:00
#ifndef __3DS__
2020-04-06 07:36:03 +02:00
/// \param Parameterized constructor
/// \param addr_ Address
2020-04-05 21:16:16 +02:00
SockAddr (struct sockaddr_in6 const &addr_);
#endif
2020-04-06 07:36:03 +02:00
/// \param Parameterized constructor
/// \param addr_ Address
2020-04-05 21:16:16 +02:00
SockAddr (struct sockaddr_storage const &addr_);
2020-04-06 07:36:03 +02:00
/// \param sockaddr_in cast operator
2020-04-05 21:16:16 +02:00
operator struct sockaddr_in const & () const;
2022-03-31 18:53:47 +02:00
#ifndef __3DS__
2020-04-06 07:36:03 +02:00
/// \param sockaddr_in6 cast operator
2020-04-05 21:16:16 +02:00
operator struct sockaddr_in6 const & () const;
#endif
2020-04-06 07:36:03 +02:00
/// \param sockaddr_storage cast operator
2020-04-05 21:16:16 +02:00
operator struct sockaddr_storage const & () const;
2020-04-06 07:36:03 +02:00
/// \param sockaddr* cast operator
2020-04-05 21:16:16 +02:00
operator struct sockaddr * ();
2020-04-06 07:36:03 +02:00
/// \param sockaddr const* cast operator
2020-04-05 21:16:16 +02:00
operator struct sockaddr const * () const;
2020-04-06 07:36:03 +02:00
/// \brief Address port
2020-04-05 21:16:16 +02:00
std::uint16_t port () const;
2020-04-06 07:36:03 +02:00
2020-12-12 02:15:33 +01:00
/// \brief Set address port
/// \param port_ Port to set
bool setPort (std::uint16_t port_);
2020-04-06 07:36:03 +02:00
/// \brief Address name
2020-12-12 02:15:33 +01:00
/// \param buffer_ Buffer to hold name
2020-04-06 07:36:03 +02:00
/// \param size_ Size of buffer_
/// \retval buffer_ success
/// \retval nullptr failure
2020-04-05 21:16:16 +02:00
char const *name (char *buffer_, std::size_t size_) const;
2020-04-06 07:36:03 +02:00
/// \brief Address name
/// \retval nullptr failure
/// \note This function is not reentrant
2020-04-05 21:16:16 +02:00
char const *name () const;
private:
2020-04-06 07:36:03 +02:00
/// \brief Address storage
2020-04-05 21:16:16 +02:00
struct sockaddr_storage m_addr = {};
};