Skip to content
Snippets Groups Projects
Commit 82357e8e authored by Daniel Müller's avatar Daniel Müller :speech_balloon:
Browse files

Wrap everything in namespace

- Put the whole library in namespace netlib
parent 30a82550
No related branches found
No related tags found
No related merge requests found
Pipeline #71639 passed
...@@ -5,6 +5,8 @@ ...@@ -5,6 +5,8 @@
// Include the all-in-one headerfile. This will include all other headers // Include the all-in-one headerfile. This will include all other headers
#include "netlib.hpp" #include "netlib.hpp"
using namespace netlib;
void example_IpAddr() void example_IpAddr()
{ {
// IpAddr takes an address as string and automatically detects if it is // IpAddr takes an address as string and automatically detects if it is
......
...@@ -4,6 +4,10 @@ ...@@ -4,6 +4,10 @@
#include <string> #include <string>
#include <netinet/in.h> #include <netinet/in.h>
namespace netlib
{
/** /**
* @brief The IpAddr class represents an ip address that can either be of type * @brief The IpAddr class represents an ip address that can either be of type
* Ipv4 or of type Ipv6. * Ipv4 or of type Ipv6.
...@@ -129,4 +133,7 @@ public: ...@@ -129,4 +133,7 @@ public:
}; };
} // namespace netlib
#endif // _IPADDR_HPP #endif // _IPADDR_HPP
\ No newline at end of file
...@@ -5,6 +5,10 @@ ...@@ -5,6 +5,10 @@
#include "ipaddr.hpp" #include "ipaddr.hpp"
namespace netlib
{
/** /**
* @brief Provide multiple ways to resolve hostnames to Ipv4 and/or Ipv6 * @brief Provide multiple ways to resolve hostnames to Ipv4 and/or Ipv6
* addresses. * addresses.
...@@ -112,4 +116,6 @@ public: ...@@ -112,4 +116,6 @@ public:
}; };
} // namespace netlib
#endif // _RESOLVER_HPP #endif // _RESOLVER_HPP
\ No newline at end of file
...@@ -6,6 +6,10 @@ ...@@ -6,6 +6,10 @@
#include "ipaddr.hpp" #include "ipaddr.hpp"
namespace netlib
{
/** /**
* @brief SockAddr represents the combination of an ip address and a port number. * @brief SockAddr represents the combination of an ip address and a port number.
* *
...@@ -134,4 +138,7 @@ public: ...@@ -134,4 +138,7 @@ public:
}; };
} // namespace netlib
#endif // _SOCKADDR_HPP #endif // _SOCKADDR_HPP
\ No newline at end of file
...@@ -6,6 +6,10 @@ ...@@ -6,6 +6,10 @@
#include <filesystem> #include <filesystem>
namespace netlib
{
/** /**
* @brief Listen to a local ip address + port and accept incomming connections * @brief Listen to a local ip address + port and accept incomming connections
* as TcpStreams. * as TcpStreams.
...@@ -113,4 +117,7 @@ public: ...@@ -113,4 +117,7 @@ public:
}; };
} // namespace netlib
#endif // _TCPLISTENER_HPP #endif // _TCPLISTENER_HPP
\ No newline at end of file
...@@ -5,6 +5,10 @@ ...@@ -5,6 +5,10 @@
#include "sockaddr.hpp" #include "sockaddr.hpp"
namespace netlib
{
/** /**
* @brief The TcpStream represents tcp a connection with another endpoint and is * @brief The TcpStream represents tcp a connection with another endpoint and is
* used to send and receive data through that connection. * used to send and receive data through that connection.
...@@ -227,4 +231,6 @@ public: ...@@ -227,4 +231,6 @@ public:
}; };
} // namespace netlib
#endif // _TCPSTREAM_HPP #endif // _TCPSTREAM_HPP
\ No newline at end of file
...@@ -3,6 +3,10 @@ ...@@ -3,6 +3,10 @@
#include "sockaddr.hpp" #include "sockaddr.hpp"
namespace netlib
{
/** /**
* @brief The UdpSocket can be used to receive UDP packets from and send UDP * @brief The UdpSocket can be used to receive UDP packets from and send UDP
* packets to any target address. * packets to any target address.
...@@ -209,4 +213,7 @@ public: ...@@ -209,4 +213,7 @@ public:
}; };
} // namespace netlib
#endif // _UDPSOCKET_HPP #endif // _UDPSOCKET_HPP
\ No newline at end of file
...@@ -5,6 +5,8 @@ ...@@ -5,6 +5,8 @@
#include <cstring> #include <cstring>
#include <arpa/inet.h> #include <arpa/inet.h>
using namespace netlib;
IpAddr::IpAddr() IpAddr::IpAddr()
: IpAddr("0.0.0.0") : IpAddr("0.0.0.0")
{ } { }
......
...@@ -8,6 +8,7 @@ ...@@ -8,6 +8,7 @@
#include <netdb.h> #include <netdb.h>
#include <arpa/inet.h> #include <arpa/inet.h>
using namespace netlib;
IpAddr Resolver::resolveHostnameAF(const std::string &hostname, int af) IpAddr Resolver::resolveHostnameAF(const std::string &hostname, int af)
{ {
......
...@@ -5,6 +5,8 @@ ...@@ -5,6 +5,8 @@
#include <arpa/inet.h> #include <arpa/inet.h>
using namespace netlib;
SockAddr::SockAddr() SockAddr::SockAddr()
: SockAddr{IpAddr::V4("0.0.0.0"), 0} : SockAddr{IpAddr::V4("0.0.0.0"), 0}
{ } { }
......
...@@ -5,6 +5,8 @@ ...@@ -5,6 +5,8 @@
#include <unistd.h> #include <unistd.h>
#include <sys/socket.h> #include <sys/socket.h>
using namespace netlib;
// TODO: More and better error handling // TODO: More and better error handling
TcpListener::TcpListener(SockAddr _local) TcpListener::TcpListener(SockAddr _local)
......
...@@ -7,6 +7,8 @@ ...@@ -7,6 +7,8 @@
#include <netinet/in.h> #include <netinet/in.h>
#include <poll.h> #include <poll.h>
using namespace netlib;
TcpStream::TcpStream(SockAddr _remote) TcpStream::TcpStream(SockAddr _remote)
: remote{_remote}, sockfd{0} : remote{_remote}, sockfd{0}
{ } { }
......
...@@ -6,6 +6,7 @@ ...@@ -6,6 +6,7 @@
#include <sys/socket.h> #include <sys/socket.h>
#include <poll.h> #include <poll.h>
using namespace netlib;
UdpSocket::UdpSocket() UdpSocket::UdpSocket()
: UdpSocket{"0.0.0.0", 0} : UdpSocket{"0.0.0.0", 0}
......
...@@ -7,6 +7,7 @@ ...@@ -7,6 +7,7 @@
#include "netlib.hpp" #include "netlib.hpp"
using namespace netlib;
TEST_CASE("Test IpAddr::V4") { TEST_CASE("Test IpAddr::V4") {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment