Created
November 6, 2014 15:32
-
-
Save javiermon/ab025e273521e21244ed to your computer and use it in GitHub Desktop.
Substract Mac addresses
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdint.h> | |
#include <stdio.h> | |
#define ETH_ALEN 6 | |
int main(void) | |
{ | |
uint8_t mac1[ETH_ALEN] = {0x00, 0x00, 0x00, 0x00, 0x00, 0xFF}; | |
uint8_t mac2[ETH_ALEN] = {0x00, 0x00, 0x00, 0x00, 0x01, 0x00}; | |
uint64_t a = (uint64_t)mac1[5] + | |
((uint64_t)mac1[4] << 8) + | |
((uint64_t)mac1[3] << 16) + | |
((uint64_t)mac1[2] << 24) + | |
((uint64_t)mac1[1] << 32) + | |
((uint64_t)mac1[0] << 40); | |
uint64_t b = (uint64_t)mac2[5] + | |
((uint64_t)mac2[4] << 8) + | |
((uint64_t)mac2[3] << 16) + | |
((uint64_t)mac2[2] << 24) + | |
((uint64_t)mac2[1] << 32) + | |
((uint64_t)mac2[0] << 40); | |
printf("%lu\n", b - a); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment