Created
February 17, 2022 13:51
-
-
Save kanokkorn/6fa5ef67f46c7aa0419d7e61fd89f116 to your computer and use it in GitHub Desktop.
Jimmy devices scanner
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
#include <stdio.h> | |
#include <stdlib.h> | |
#include <fcntl.h> | |
#include <dirent.h> | |
int count_usb(char**); | |
char* arr[50] = {}; | |
char **ptr = arr; | |
int main(int argc, char** argv) { | |
int x, devices; | |
argc > 1 ? devices = count_usb(argv[1]) : exit(0); | |
if (devices < 1) { | |
printf("Can't find devices in used!\n"); | |
return EXIT_FAILURE; | |
} | |
printf("devices count: %d\n", devices); | |
for (x = 0; x < devices; x++) { | |
if (ptr[x] != NULL) printf("string %d : %s\n", x+1, ptr[x]); | |
} | |
return EXIT_SUCCESS; | |
} | |
int count_usb(char** target) { | |
DIR *d; | |
struct dirent *dir; | |
unsigned int returnSize = 0; | |
d = opendir("/dev/"); | |
if (d) { | |
while ((dir = readdir(d)) != NULL) { | |
char *check; | |
check = strstr(dir->d_name, target); | |
ptr[returnSize] = check; | |
check != NULL ? puts(check), returnSize++ : returnSize+0; | |
} | |
return returnSize; | |
} else { | |
puts("found nothing"); | |
return -1; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment