Copying a struct from kernel(module) to userland using /proc, how?
I'm trying to copy a struct from the a kernel module to userland. I can copy a struct from userland to the module doing this in the user program:
and this in the kernel(note, theres a function called automatically when the proc file is written to):
void write_procfile() /* Test for struct copy */
if((fp = fopen("/proc/nf_lb", "wb")) == NULL)
printf("Error opening /proc/nf_lb for writing.\n");
} /* open /proc/nf_lb for writing */
if((fwrite(&input, sizeof (struct user_input), 1, fp)) != 1)
printf("An error has occured. Please make sure to specify correct options.\n");
fclose(fp); /* close the file */
But, I do not know how to send a struct from the module to userland...
/* write data to the buffer*/
if (copy_from_user((char *) &input, buffer, sizeof(struct user_input)))
Any ideas? I suppose I'm looking for a function like userlands fwrite().
Thanks for any help,