parse_mac
This commit is contained in:
parent
915b5bf927
commit
ab0bc2708f
2 changed files with 25 additions and 1 deletions
1
.gitignore
vendored
1
.gitignore
vendored
|
|
@ -3,4 +3,5 @@ CMakeFiles
|
||||||
CMakeCache.txt
|
CMakeCache.txt
|
||||||
Makefile
|
Makefile
|
||||||
*.cmake
|
*.cmake
|
||||||
|
build/
|
||||||
arper
|
arper
|
||||||
25
main.c
25
main.c
|
|
@ -1,8 +1,31 @@
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
#include <stdint.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
|
typedef uint8_t mac_t[6];
|
||||||
|
|
||||||
|
void parse_mac(const char* str, mac_t mac)
|
||||||
|
{
|
||||||
|
char* s = strdup(str);
|
||||||
|
char* octet = strtok(s, ":");
|
||||||
|
int i = 0;
|
||||||
|
|
||||||
|
while (octet != NULL && i < 6)
|
||||||
|
{
|
||||||
|
mac[i++] = strtol(octet, NULL, 16);
|
||||||
|
|
||||||
|
octet = strtok(NULL, ":");
|
||||||
|
}
|
||||||
|
|
||||||
|
free(s);
|
||||||
|
}
|
||||||
|
|
||||||
int main()
|
int main()
|
||||||
{
|
{
|
||||||
printf("Test\n");
|
mac_t t;
|
||||||
|
parse_mac("11:22:33:44:55:66", t);
|
||||||
|
printf("%x\n", t[5]);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
Loading…
Add table
Reference in a new issue