use |-operator to calc solicited-node address (draft)
geändert: lib/libtins geändert: src/ArpToNdpPacketHandler.cpp geändert: src/Main.cpp
This commit is contained in:
Submodule lib/libtins updated: a61a361eb1...c9dea75243
@@ -1,4 +1,5 @@
|
||||
#include "ArpToNdpPacketHandler.h"
|
||||
#include <regex>
|
||||
#include <tins/ethernetII.h>
|
||||
#include <tins/arp.h>
|
||||
#include <tins/icmpv6.h>
|
||||
@@ -34,17 +35,13 @@ bool ArpToNdpPacketHandler::handle(IN const Tins::PDU & pdu, IN IPacketHandler *
|
||||
}
|
||||
|
||||
// convert ipv4 addresses to ipv6 addresses
|
||||
uint32_t ndpMaskField = *ndpMask;
|
||||
uint32_t targetMaskield = arpPdu->target_ip_addr();
|
||||
uint32_t foo = ndpMaskField | targetMaskield;
|
||||
|
||||
UPtrIPv6Address srcIp6Address = std::make_unique<Tins::IPv6Address>(*prefix);
|
||||
UPtrIPv6Address dstIp6Address = std::make_unique<Tins::IPv6Address>(*ndpPrefix);
|
||||
UPtrIPv6Address targetIp6Address = std::make_unique<Tins::IPv6Address>(*prefix);
|
||||
IpAddressTranslator::toIpv6Address(arpPdu->sender_ip_addr(), *srcIp6Address);
|
||||
IpAddressTranslator::toIpv6Address(Tins::IPv4Address(foo), *dstIp6Address);
|
||||
|
||||
IpAddressTranslator::toIpv6Address(arpPdu->target_ip_addr(), *targetIp6Address);
|
||||
// create ip4 pdu
|
||||
std::unique_ptr<const Tins::IPv6> ipv6Pdu = std::make_unique<const Tins::IPv6>(*dstIp6Address,*srcIp6Address);
|
||||
std::unique_ptr<const Tins::IPv6> ipv6Pdu = std::make_unique<const Tins::IPv6>((*targetIp6Address)|(*ndpPrefix),*srcIp6Address);
|
||||
std::unique_ptr<Tins::ICMPv6> ndpPdu;
|
||||
|
||||
switch (arpPdu->opcode())
|
||||
@@ -70,13 +67,16 @@ bool ArpToNdpPacketHandler::handle(IN const Tins::PDU & pdu, IN IPacketHandler *
|
||||
{
|
||||
// @todo to set multicast
|
||||
forwardEthPdu.src_addr(ethPdu->src_addr());
|
||||
forwardEthPdu.dst_addr(ethPdu->dst_addr());
|
||||
Tins::IPv4Address foo =arpPdu->target_ip_addr();
|
||||
std::string string("hello $name");
|
||||
Tins::EthernetII::address_type ethernatMask = std::regex_replace("00:00:" + foo.to_string(), std::regex("."), ":");
|
||||
Tins::EthernetII::address_type ethernatMask2 = "33:33:FF:00:00:00";
|
||||
forwardEthPdu.dst_addr(ethernatMask | ethernatMask2);
|
||||
}
|
||||
|
||||
forwardEthPdu /= *ipv6Pdu;
|
||||
forwardEthPdu /= *ndpPdu;
|
||||
|
||||
|
||||
// forward frame
|
||||
return callBackHandler->handle(forwardEthPdu, this);
|
||||
}
|
||||
|
||||
95
src/Main.cpp
95
src/Main.cpp
@@ -1,8 +1,93 @@
|
||||
#include <stdio.h>
|
||||
#include <iostream>
|
||||
#include <vector>
|
||||
#include <string>
|
||||
#include <tuple>
|
||||
|
||||
int main(void)
|
||||
void tprintf(const char* format) // base function
|
||||
{
|
||||
printf("Hello, Worliaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaad\n");
|
||||
|
||||
return 0;
|
||||
std::cout << format;
|
||||
}
|
||||
|
||||
template<typename T, typename... Targs>
|
||||
void tprintf(const char* format, T value, Targs... Fargs) // recursive variadic function
|
||||
{
|
||||
for ( ; *format != '\0'; format++ ) {
|
||||
if ( *format == '%' ) {
|
||||
std::cout << value;
|
||||
tprintf(format+1, Fargs...); // recursive call
|
||||
return;
|
||||
}
|
||||
std::cout << *format;
|
||||
}
|
||||
}
|
||||
|
||||
template<typename... Ts> void func(Ts... args){
|
||||
const int size = sizeof...(Ts);
|
||||
/* int res[size] = {1,args...,2};
|
||||
// since initializer lists guarantee sequencing, this can be used to
|
||||
// call a function on each element of a pack, in order*/
|
||||
std::vector<int> dummy = { (args, args)... };
|
||||
int size2 = dummy.size();
|
||||
size2++;
|
||||
}
|
||||
|
||||
struct foo{
|
||||
int bar = 0;
|
||||
float bla = 3.12;
|
||||
std::string blub = "blub";
|
||||
};
|
||||
|
||||
template<typename... Ts>
|
||||
class varicdclass{
|
||||
public:
|
||||
|
||||
explicit varicdclass(Ts*... mixins)
|
||||
{
|
||||
fillList(mixins...);
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
void fillList(T * arg){
|
||||
dummy.push_back(arg == nullptr ? new T() : arg);
|
||||
}
|
||||
|
||||
template<typename T,typename... Us>
|
||||
void fillList(T * arg, Us*... args){
|
||||
dummy.push_back(arg == nullptr ? new T() : arg);
|
||||
fillList(args...);
|
||||
}
|
||||
std::vector<void*> dummy;
|
||||
|
||||
template<typename T>
|
||||
int bar (T i) {return 0;}
|
||||
template<typename T>
|
||||
int bar (int i) {return 1;}
|
||||
template<typename T>
|
||||
int bar (float f) {return 2;}
|
||||
};
|
||||
|
||||
class dervaricdclass : public varicdclass<int, double, foo>
|
||||
{
|
||||
public:
|
||||
dervaricdclass() : varicdclass(nullptr,nullptr,nullptr)
|
||||
{
|
||||
}
|
||||
};
|
||||
|
||||
int main()
|
||||
{
|
||||
tprintf("% world% %\n","Hello",'!',123);
|
||||
func<int,int,int, int>(0,0,1,0);
|
||||
int i = 1;
|
||||
double d = 3.21;
|
||||
foo f;
|
||||
varicdclass<foo, int, double> dvc(&f,&i, &d);
|
||||
varicdclass<int, double, foo> dvc2(nullptr,nullptr,nullptr);
|
||||
dervaricdclass dvc3;
|
||||
i++;
|
||||
|
||||
int l = dvc3.bar(1);
|
||||
int j = dvc3.bar(1.0);
|
||||
int k = dvc3.bar('1');
|
||||
i++;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user