mirror of
https://github.com/mfontanini/libtins
synced 2026-01-28 12:44:25 +01:00
Add helper function to create StreamIdentifier from const Stream& (#152)
This commit is contained in:
committed by
Matias Fontanini
parent
8afc784956
commit
1552e33c67
@@ -45,6 +45,8 @@ class IPv6Address;
|
||||
|
||||
namespace TCPIP {
|
||||
|
||||
class Stream;
|
||||
|
||||
/**
|
||||
* \brief Uniquely identifies a stream.
|
||||
*
|
||||
@@ -92,6 +94,7 @@ struct StreamIdentifier {
|
||||
uint16_t max_address_port;
|
||||
|
||||
static StreamIdentifier make_identifier(const PDU& packet);
|
||||
static StreamIdentifier make_identifier(const Stream& stream);
|
||||
static address_type serialize(IPv4Address address);
|
||||
static address_type serialize(const IPv6Address& address);
|
||||
};
|
||||
|
||||
@@ -39,6 +39,7 @@
|
||||
#include "ip.h"
|
||||
#include "ipv6.h"
|
||||
#include "exceptions.h"
|
||||
#include "tcp_ip/stream.h"
|
||||
|
||||
using std::swap;
|
||||
using std::tie;
|
||||
@@ -109,6 +110,16 @@ StreamIdentifier StreamIdentifier::make_identifier(const PDU& packet) {
|
||||
}
|
||||
}
|
||||
|
||||
StreamIdentifier StreamIdentifier::make_identifier(const Stream& stream) {
|
||||
if (stream.is_v6()) {
|
||||
return StreamIdentifier(serialize(stream.client_addr_v6()), stream.client_port(),
|
||||
serialize(stream.server_addr_v6()), stream.server_port());
|
||||
} else {
|
||||
return StreamIdentifier(serialize(stream.client_addr_v4()), stream.client_port(),
|
||||
serialize(stream.server_addr_v4()), stream.server_port());
|
||||
}
|
||||
}
|
||||
|
||||
StreamIdentifier::address_type StreamIdentifier::serialize(IPv4Address address) {
|
||||
address_type addr;
|
||||
OutputMemoryStream output(addr.data(), addr.size());
|
||||
|
||||
Reference in New Issue
Block a user