libcppwrap
A collection of C++ wrappers for native APIs
Loading...
Searching...
No Matches
Classes | Namespaces | Functions
sockets.hpp File Reference
#include <cstddef>
#include <cstdint>
#include <cstring>
#include <stdexcept>
#include <ifaddrs.h>
#include <netinet/ip6.h>
#include <sys/socket.h>
#include <sys/types.h>
#include <sys/un.h>
#include <w/handle.hpp>
#include <w/iterators.hpp>
#include <w/posix.hpp>
Include dependency graph for sockets.hpp:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  w::ipv4_address
 Wraps struct sockaddr_in, adding constructors for convenient initialization. More...
 
struct  w::ipv6_address
 Wraps struct sockaddr_in6, adding constructors for convenient initialization. More...
 
struct  w::unix_domain_address
 Wraps struct sockaddr_in, adding constructors for convenient initialization. More...
 

Namespaces

namespace  w
 

Functions

w::fd w::accept (int sockfd, struct sockaddr *addr, socklen_t *addrlen)
 Accepts a connection on a socket. More...
 
template<typename Address >
w::fd w::accept (int sockfd, Address &addr)
 Accepts a connection on a socket. More...
 
void w::bind (int sockfd, const struct sockaddr *addr, socklen_t addrlen)
 Binds a socket to an address. More...
 
template<typename Address >
void w::bind (int sockfd, const Address &addr)
 Binds a socket. More...
 
void w::connect (int sockfd, const struct sockaddr *addr, socklen_t addrlen)
 Connects a socket. More...
 
template<typename Address >
void w::connect (int sockfd, const Address &addr)
 Connects a socket. More...
 
w::handle< struct ifaddrs *, nullptr, ::freeifaddrs > w::getifaddrs ()
 Gets a pointer to the head of a linked list of the system's network interfaces. More...
 
int w::getsockopt (int sockfd, int level, int optname, void *optval=nullptr, socklen_t *optlen=nullptr)
 Gets an option on a socket. More...
 
template<typename Value >
Value w::getsockopt (int sockfd, int level, int optname)
 Gets an option on a socket. More...
 
unsigned w::if_nametoindex (const char *ifname)
 Returns the index of the specified network interface. More...
 
char * w::inet_ntop (int af, const void *src, char *dst, socklen_t size)
 Converts an IPv4 or IPv6 address to a string. More...
 
void * w::inet_pton (int af, const char *src, void *dst)
 Converts an IPv4 or IPv6 address from a string to a binary value. More...
 
template<typename Address >
Address & w::inet_pton (int af, const char *src, Address &dst)
 Converts an IPv4 or IPv6 address from a string to a binary value. More...
 
void w::listen (int sockfd, int backlog)
 Puts a socket in a listening state. More...
 
std::size_t w::recv (int sockfd, void *buf, std::size_t len, int flags=0)
 Receives a message from a socket. More...
 
std::size_t w::recvmsg (int sockfd, struct msghdr *msg, int flags=0)
 Receives a message from a socket. More...
 
std::size_t w::recvfrom (int sockfd, void *buf, std::size_t len, int flags, struct sockaddr *src_addr=nullptr, socklen_t *addrlen=nullptr)
 Receives a message from a socket. More...
 
template<typename Address >
std::size_t w::recvfrom (int sockfd, void *buf, std::size_t len, int flags, Address &src_addr)
 Receives a message from a socket. More...
 
std::size_t w::send (int sockfd, const void *buf, std::size_t len, int flags=0)
 Sends a message on a socket. More...
 
std::size_t w::sendmsg (int sockfd, const struct msghdr *msg, int flags=0)
 Sends a message on a socket. More...
 
std::size_t w::sendto (int sockfd, const void *buf, std::size_t len, int flags, const struct sockaddr *dest_addr, socklen_t addrlen)
 Sends a message on a socket. More...
 
template<typename Address >
std::size_t w::sendto (int sockfd, const void *buf, std::size_t len, int flags, const Address &dest_addr)
 Sends a message on a socket. More...
 
int w::setsockopt (int sockfd, int level, int optname, const void *optval=nullptr, socklen_t optlen=0)
 Sets an option on a socket. More...
 
template<typename Value >
void w::setsockopt (int sockfd, int level, int optname, const Value &optval)
 Sets an option on a socket. More...
 
void w::shutdown (int sockfd, int how)
 Shuts down part of a full-duplex connection. More...
 
w::fd w::socket (int domain, int type, int protocol=0)
 Creates a socket. More...
 
auto begin (const struct ifaddrs *ptr) noexcept
 Returns an input iterator pointing to the struct ifaddrs entry ptr. More...
 
auto end (const struct ifaddrs *ptr) noexcept
 Returns an input iterator pointing to the end of a struct ifaddrs array. More...
 
bool operator== (const in6_addr &a, const in6_addr &b) noexcept
 Compares two IPv6 addresses. More...
 
bool operator!= (const in6_addr &a, const in6_addr &b) noexcept
 Compares two IPv6 addresses. More...
 
bool operator< (const in6_addr &a, const in6_addr &b) noexcept
 Compares two IPv6 addresses. More...
 

Function Documentation

◆ begin()

auto begin ( const struct ifaddrs *  ptr)
inlinenoexcept

Returns an input iterator pointing to the struct ifaddrs entry ptr.

Parameters
ptrThe struct ifaddrs entry to point to.
Returns
An input iterator.

◆ end()

auto end ( const struct ifaddrs *  ptr)
inlinenoexcept

Returns an input iterator pointing to the end of a struct ifaddrs array.

Parameters
ptrThe struct ifaddrs array to point to the end of.
Returns
An input iterator.

◆ operator!=()

bool operator!= ( const in6_addr &  a,
const in6_addr &  b 
)
inlinenoexcept

Compares two IPv6 addresses.

Parameters
aThe first address to compare.
bThe second address to compare.
Returns
true if a and b are different addresses.

◆ operator<()

bool operator< ( const in6_addr &  a,
const in6_addr &  b 
)
inlinenoexcept

Compares two IPv6 addresses.

Parameters
aThe first address to compare.
bThe second address to compare.
Returns
true if a is a lower address than b.

◆ operator==()

bool operator== ( const in6_addr &  a,
const in6_addr &  b 
)
inlinenoexcept

Compares two IPv6 addresses.

Parameters
aThe first address to compare.
bThe second address to compare.
Returns
true if a and b are the same address.