1
0
mirror of https://github.com/mfontanini/libtins synced 2026-01-23 02:35:57 +01:00

Merge pull request #448 from FlukeCorp/link-local-uses-interface

IPv6 use interface when sending to link-local dest
This commit is contained in:
Matias Fontanini
2021-07-22 19:23:51 -07:00
committed by GitHub
2 changed files with 9 additions and 2 deletions

View File

@@ -65,7 +65,9 @@ class PDU;
* - Those that don't contain a link layer PDU. In this case, the
* kernel will be responsible for picking the appropriate network interface
* based on the destination address.
*
* - Exception: <a href="https://datatracker.ietf.org/doc/html/rfc2553#section-3.3">RFC2553</a>
* requires IPv6 link-scope address have a interface defined.
* .
* \par Note for Windows users:
* Sending layer 3 PDUs (without a link layer protocol) is very restricted
* on Windows (<a href="https://msdn.microsoft.com/en-us/library/windows/desktop/ms740548(v=vs.85).aspx">link</a>).

View File

@@ -366,11 +366,16 @@ void IPv6::write_serialization(uint8_t* buffer, uint32_t total_sz) {
}
#ifndef BSD
void IPv6::send(PacketSender& sender, const NetworkInterface &) {
void IPv6::send(PacketSender& sender, const NetworkInterface& interface) {
sockaddr_in6 link_addr;
const PacketSender::SocketType type = PacketSender::IPV6_SOCKET;
link_addr.sin6_family = AF_INET6;
link_addr.sin6_port = 0;
// Required to set sin6_scope_id to interface index as stated in RFC2553.
// https://datatracker.ietf.org/doc/html/rfc2553#section-3.3
if (IPv6Address(header_.dst_addr).is_local_unicast()) {
link_addr.sin6_scope_id = interface.id();
}
memcpy((uint8_t*)&link_addr.sin6_addr, header_.dst_addr, address_type::address_size);
sender.send_l3(*this, (struct sockaddr*)&link_addr, sizeof(link_addr), type);
}