Advertisement
Guest User

asdasdasdasdasdasdasdadasd

a guest
Jan 16th, 2019
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.43 KB | None | 0 0
  1. #include<stdio.h>
  2. #include<stdlib.h>
  3. #include<errno.h>
  4. #include<fcntl.h>
  5. #include<string.h>
  6. #include<unistd.h>
  7. #define BUFFER_LENGTH 256
  8. ///< The buffer length (crude but fine) static char receive[BUFFER_LENGTH];
  9. ///< The receive buffer from the LKM
  10. int main(){
  11. int ret, fd;
  12. char stringToSend[BUFFER_LENGTH];
  13. printf("Starting device test code example...\n");
  14. fd = open("../../../dev/dev1", O_RDWR); // Open the device with read/write access
  15. if (fd < 0){
  16. perror("Failed to open the device...");
  17. return errno;
  18. }
  19. printf("Type in a short string to send to the kernel module:\n");
  20. scanf("%[^\n]%*c", stringToSend); // Read in a string (with spaces)
  21. printf("Writing message to the device [%s].\n", stringToSend);
  22. ret = write(fd, stringToSend, strlen(stringToSend)); // Send the string to the LKM
  23. if (ret < 0){
  24. perror("Failed to write the message to the device.");
  25. return errno;
  26. }
  27. printf("Press ENTER to read back from the device...\n");
  28. getchar();
  29. printf("Reading from the device...\n");
  30. ret = read(fd, receive, BUFFER_LENGTH); // Read the response from the LKM
  31. if (ret < 0){
  32. perror("Failed to read the message from the device.");
  33. return errno;
  34. }
  35. printf("The received message is: [%s]\n", receive);
  36. printf("End of the program\n");
  37. return 0;
  38. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement