1
0
mirror of https://code.semirocket.science/wrapsix synced 2024-11-08 15:21:00 +02:00

Getting MAC address of the interface

Set IPv4 address of WrapSix
This commit is contained in:
Michal Zima 2012-03-31 14:10:35 +02:00
parent d44253f5ed
commit 845f5c541b
2 changed files with 23 additions and 1 deletions

View File

@ -38,11 +38,14 @@
#define INTERFACE "eth0"
#define BUFFER_SIZE 65536
#define PREFIX "::"
#define PREFIX "fd77::"
#define IPV4_ADDR "192.168.0.111"
struct ifreq interface;
struct s_mac_addr mac;
struct s_ipv6_addr ndp_multicast_addr;
struct s_ipv6_addr wrapsix_ipv6_prefix;
struct s_ipv4_addr wrapsix_ipv4_addr;
int process(char *packet);
@ -70,6 +73,20 @@ int main(int argc, char **argv)
return 1;
}
/* get interface's HW address (i.e. MAC) */
if (ioctl(sniff_sock, SIOCGIFHWADDR, &interface) == 0) {
memcpy(&mac, &interface.ifr_hwaddr.sa_data, sizeof(struct s_mac_addr));
/* reinitialize the interface */
if (ioctl(sniff_sock, SIOCGIFINDEX, &interface) == -1) {
fprintf(stderr, "[Error] Unable to reinitialize the interface\n");
return 1;
}
} else {
fprintf(stderr, "[Error] Unable to get the interface's HW address\n");
return 1;
}
/* set the promiscuous mode */
memset(&pmr, 0x0, sizeof(pmr));
pmr.mr_ifindex = interface.ifr_ifindex;
@ -86,6 +103,9 @@ int main(int argc, char **argv)
/* compute binary IPv6 address of WrapSix prefix */
inet_pton(AF_INET6, PREFIX, &wrapsix_ipv6_prefix);
/* compute binary IPv4 address of WrapSix */
inet_pton(AF_INET, IPV4_ADDR, &wrapsix_ipv4_addr);
/* initiate sending socket */
if (transmission_init()) {
fprintf(stderr, "[Error] Unable to initiate sending socket\n");

View File

@ -23,8 +23,10 @@
#include "ipv6.h"
extern struct ifreq interface;
extern struct s_mac_addr mac;
extern struct s_ipv6_addr ndp_multicast_addr;
extern struct s_ipv6_addr wrapsix_ipv6_prefix;
extern struct s_ipv4_addr wrapsix_ipv4_addr;
void ipv6_to_ipv4(struct s_ipv6_addr *ipv6_addr, struct s_ipv4_addr *ipv4_addr);
void ipv4_to_ipv6(struct s_ipv4_addr *ipv4_addr, struct s_ipv6_addr *ipv6_addr);