mirror of
https://github.com/markqvist/tncattach.git
synced 2025-07-30 12:32:25 -04:00
Compare commits
4 Commits
0f115a3572
...
ec9f6365d7
Author | SHA1 | Date | |
---|---|---|---|
|
ec9f6365d7 | ||
|
66815f7f1a | ||
|
5546163742 | ||
|
95930680d0 |
30
TAP.c
30
TAP.c
@ -23,10 +23,25 @@ extern char* ipv6_addr;
|
|||||||
extern char* netmask;
|
extern char* netmask;
|
||||||
extern void cleanup();
|
extern void cleanup();
|
||||||
|
|
||||||
|
#include<stdlib.h>
|
||||||
|
|
||||||
|
void localRand(struct in6_addr* ll_a)
|
||||||
|
{
|
||||||
|
for(int i = 2; i < 16; i++)
|
||||||
|
{
|
||||||
|
ll_a->s6_addr[i] = rand();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#include<time.h>
|
||||||
|
|
||||||
// TODO: Allow optional-arg for case where we must also generate the hwaddr
|
// TODO: Allow optional-arg for case where we must also generate the hwaddr
|
||||||
// (this would be the case whereby we are running without `--ethernet`)
|
// (this would be the case whereby we are running without `--ethernet`)
|
||||||
struct in6_addr generateLinkLocal(char* interfaceName)
|
struct in6_addr generateLinkLocal(char* interfaceName)
|
||||||
{
|
{
|
||||||
|
time_t t = time(NULL);
|
||||||
|
srand(t);
|
||||||
|
|
||||||
struct in6_addr ll_a;
|
struct in6_addr ll_a;
|
||||||
memset(&ll_a, 0, sizeof(struct in6_addr));
|
memset(&ll_a, 0, sizeof(struct in6_addr));
|
||||||
ll_a.s6_addr[0] = 0xfe;
|
ll_a.s6_addr[0] = 0xfe;
|
||||||
@ -38,6 +53,11 @@ struct in6_addr generateLinkLocal(char* interfaceName)
|
|||||||
// (TODO, should not matter, link-local is interface scoped)
|
// (TODO, should not matter, link-local is interface scoped)
|
||||||
// TODO: Should tie it to mac address because of uniqueness
|
// TODO: Should tie it to mac address because of uniqueness
|
||||||
// on the lan it shall attach to (over lora)
|
// on the lan it shall attach to (over lora)
|
||||||
|
localRand(&ll_a);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
int dummySock = socket(AF_PACKET, SOCK_PACKET, 0);
|
int dummySock = socket(AF_PACKET, SOCK_PACKET, 0);
|
||||||
if(dummySock < 0)
|
if(dummySock < 0)
|
||||||
@ -325,6 +345,16 @@ int open_tap(void) {
|
|||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Choose stratergy for generating link-local address
|
||||||
|
if(device_type == IF_TAP)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
// Add link-local address
|
// Add link-local address
|
||||||
trySixSet(ifr.ifr_ifindex, generateLinkLocal(if_name), 64);
|
trySixSet(ifr.ifr_ifindex, generateLinkLocal(if_name), 64);
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user