Skip to content

Instantly share code, notes, and snippets.

@cvsync
Last active December 30, 2015 18:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cvsync/7867768 to your computer and use it in GitHub Desktop.
Save cvsync/7867768 to your computer and use it in GitHub Desktop.
Where is my lovely "/proc/net/arp" ?
/*
* 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