Théophile Bastian
94f42d08c0
Clean up dramatically the codebase by assuming the server has only a single connection at any time.
30 lines
827 B
C++
30 lines
827 B
C++
#include "VpnPeer.hpp"
|
|
#include "UdpVpn.hpp"
|
|
|
|
#include <cstdint>
|
|
#include <cstring>
|
|
#include <functional>
|
|
|
|
VpnPeer::VpnPeer(UdpVpn* vpn, const sockaddr_in6& ext_addr,
|
|
const in6_addr& int_addr)
|
|
: _vpn(vpn), _ext_addr(ext_addr), _int_addr(int_addr), _next_seqno(0)
|
|
{}
|
|
|
|
void VpnPeer::set_int_addr(const in6_addr& int_addr) {
|
|
memcpy(&_int_addr, &int_addr, sizeof(_int_addr));
|
|
}
|
|
|
|
size_t VpnPeer::write(const char* data, size_t len) {
|
|
ssize_t nsent;
|
|
|
|
nsent = sendto(_vpn->get_socket_fd(), data, len, MSG_CONFIRM,
|
|
(const struct sockaddr*) &_ext_addr, sizeof(_ext_addr));
|
|
if(nsent < 0)
|
|
throw NetError("Could not send UDP packet", errno, true);
|
|
|
|
return (size_t) nsent;
|
|
}
|
|
|
|
size_t VpnPeer::write(const VpnPacket& packet) {
|
|
return write(packet.get_data(), packet.get_data_size());
|
|
}
|