mirror of
https://github.com/Waujito/youtubeUnblock.git
synced 2024-12-23 06:42:38 +00:00
822266b74b
Such setup is better for cross compilation. Also changed Makefile to properly make the project with these libraries.
53 lines
1.1 KiB
C
53 lines
1.1 KiB
C
/* simple test for index to interface name API */
|
|
|
|
#include <stdio.h>
|
|
#include <stdlib.h>
|
|
#include <string.h>
|
|
#include <errno.h>
|
|
#include <net/if.h>
|
|
|
|
#include <libnfnetlink/libnfnetlink.h>
|
|
|
|
int main(int argc, char *argv[])
|
|
{
|
|
int idx;
|
|
struct nlif_handle *h;
|
|
char name[IFNAMSIZ];
|
|
unsigned int flags;
|
|
|
|
if (argc != 2) {
|
|
fprintf(stderr, "Usage: %s <interface>\n", argv[0]);
|
|
exit(EXIT_FAILURE);
|
|
}
|
|
|
|
h = nlif_open();
|
|
if (h == NULL) {
|
|
perror("nlif_open");
|
|
exit(EXIT_FAILURE);
|
|
}
|
|
|
|
if (nlif_query(h) == -1) {
|
|
fprintf(stderr, "failed query to retrieve interfaces: %s\n",
|
|
strerror(errno));
|
|
exit(EXIT_FAILURE);
|
|
}
|
|
|
|
idx = if_nametoindex(argv[1]);
|
|
|
|
/* Superfluous: just to make sure nlif_index2name is working fine */
|
|
if (nlif_index2name(h, idx, name) == -1)
|
|
fprintf(stderr, "Cannot translate device idx=%u\n", idx);
|
|
|
|
if (nlif_get_ifflags(h, idx, &flags) == -1) {
|
|
fprintf(stderr, "Cannot get flags for device `%s'\n", argv[1]);
|
|
exit(EXIT_FAILURE);
|
|
}
|
|
|
|
printf("index (%d) is %s (%s) (%s)\n", idx, argv[1],
|
|
flags & IFF_RUNNING ? "RUNNING" : "NOT RUNNING",
|
|
flags & IFF_UP ? "UP" : "DOWN");
|
|
|
|
nlif_close(h);
|
|
return EXIT_SUCCESS;
|
|
}
|