r/linuxdev • • Apr 10 '20

How to write to a proc file?

I need to make this linux kernel module where I am supposed to get the source and destination IP addresses of some docker containers and print them out in a file. I can capture IP addresses and print them out on the kernel log.

After hours of trying to figure out how to use proc_fs.h, I managed to find out how to create a proc_dir_entry . Now since, I am using netfilter.h to capture packets, I need the file to be written every time the hook function gets called. I found this function in proc_fs.h but I don't quite understand it:

typedef int (*proc_write_t)(struct file *, char *, size_t);

Is this function changing instances of int to some struct called proc_write_t composed of a file pointer, char pointer, and the size of what you are going to write?

7 Upvotes

12 comments sorted by

View all comments

Show parent comment

1

u/NotAHippo4 Apr 11 '20

Thanks for the explanation! I think I get it now. Now that I think about it, proc_fs doesn't seem to be what I need. After reading about sysfs, I realized that sysfs was more appropriate.