Last active
December 30, 2015 18:29
-
-
Save cvsync/7867768 to your computer and use it in GitHub Desktop.
Where is my lovely "/proc/net/arp" ?
This file contains 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
/* | |
* Where is my lovely "/proc/net/arp" ? by M-Systems, Inc. | |
*/ | |
#include <stdio.h> | |
#include <stdlib.h> | |
#include <errno.h> | |
#include <fcntl.h> | |
#include <pthread.h> | |
#include <unistd.h> | |
static void *thread(void *); | |
int | |
main(void) | |
{ | |
pthread_t thr; | |
int error; | |
error = pthread_create(&thr, NULL, thread, NULL); | |
if (error != 0) { | |
(void)fprintf(stderr, "pthread create error\n"); | |
pthread_exit(NULL); | |
} | |
(void)sleep(5); | |
pthread_exit(NULL); | |
} | |
static void * | |
thread(void *aux) | |
{ | |
int fd, count, error; | |
(void)aux; /* unused */ | |
error = pthread_detach(pthread_self()); | |
if (error != 0) { | |
(void)fprintf(stderr, "pthread detach error\n"); | |
pthread_exit(NULL); | |
} | |
count = 1; | |
while (/* CONSTCOND */ 1) { | |
fd = open("/proc/net/arp", O_RDONLY, 0); | |
if (fd == -1) { | |
(void)fprintf(stderr, "open /proc/net/arp error\n"); | |
break; | |
} | |
if (close(fd) == -1) { | |
(void)fprintf(stderr, "close /proc/net/arp error\n"); | |
break; | |
} | |
(void)printf("Count=%d\n", count++); | |
(void)usleep(200 * 1000); | |
} | |
pthread_exit(NULL); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment