szaydel
11/20/2019 - 9:13 PM

Check number of available entropy bits via an IOCTL - C

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <fcntl.h>
#include <linux/random.h>
#include <sys/ioctl.h>
#include <sys/types.h>
#include <sys/stat.h>

int main(void) {
  int random_fd = -1;
  int current = 0;
  random_fd = open("/dev/random", O_RDWR);
  if (random_fd == -1) {
    perror("open(...)");
    exit(1);
  }
  if (ioctl(random_fd, RNDGETENTCNT, &current) == -1) {
    perror("ioctl(...)");
    exit(1);
  }
  printf("%d\n", current);
}