+/* entropy available */
+char *
+entropy(const char *null)
+{
+ int entropy = 0;
+ FILE *fp;
+
+ /* open entropy file */
+ if (!(fp = fopen("/proc/sys/kernel/random/entropy_avail", "r"))) {
+ fprintf(stderr, "Could not open entropy file.\n");
+ return smprintf("n/a");
+ }
+
+ /* extract entropy */
+ fscanf(fp, "%d", &entropy);
+
+ /* close entropy file */
+ fclose(fp);
+
+ /* return entropy */
+ return smprintf("%d", entropy);
+}
+
+/* hostname */
+char *
+hostname(const char *null)
+{
+ char *hostname = "";
+ FILE *fp;
+
+ /* open hostname file */
+ if (!(fp = fopen("/proc/sys/kernel/hostname", "r"))) {
+ fprintf(stderr, "Could not open hostname file.\n");
+ return smprintf("n/a");
+ }
+
+ /* extract hostname */
+ fscanf(fp, "%s", hostname);
+
+ /* close hostname file */
+ fclose(fp);
+
+ /* return entropy */
+ return smprintf("%s", hostname);
+}
+
+/* ip address */
+char *
+ip(const char *interface)
+{
+ struct ifaddrs *ifaddr, *ifa;
+ int s;
+ char host[NI_MAXHOST];
+
+ /* check if getting ip address works */
+ if (getifaddrs(&ifaddr) == -1)
+ {
+ fprintf(stderr, "Error getting IP address.");
+ return smprintf("n/a");
+ }
+
+ /* get the ip address */
+ for (ifa = ifaddr; ifa != NULL; ifa = ifa->ifa_next)
+ {
+ if (ifa->ifa_addr == NULL)
+ continue;
+
+ s = getnameinfo(ifa->ifa_addr, sizeof(struct sockaddr_in), host, NI_MAXHOST, NULL, 0, NI_NUMERICHOST);
+
+ if ((strcmp(ifa->ifa_name, interface) == 0) && (ifa->ifa_addr->sa_family == AF_INET))
+ {
+ if (s != 0)
+ {
+ fprintf(stderr, "Error getting IP address.");
+ return smprintf("n/a");
+ }
+ return smprintf("%s", host);
+ }
+ }
+
+ /* free the address */
+ freeifaddrs(ifaddr);
+
+ /* return n/a if nothing works */
+ return smprintf("n/a");
+}
+