Last active
March 18, 2020 18:20
Example for get_option
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 <linux/module.h> | |
#include <linux/kernel.h> | |
#include<linux/sched.h> | |
int pint=-1; | |
static __init int getargs(char *str){ | |
int ret; | |
ret=get_option(&str,&pint); | |
if(ret==0) | |
printk(KERN_INFO "no arguments passed\n\n"); | |
else if(ret==1) | |
printk(KERN_INFO "Found the argument %d\n\n",pint); | |
else if(ret==2) | |
printk(KERN_INFO "Found the argument %d with ,\n\n",pint); | |
else if(ret==3){ | |
printk(KERN_INFO"Found range %d%s\n\n",pint,str); | |
} | |
return 0; | |
} | |
static __init int proc_init (void) { | |
getargs("NULL"); | |
getargs("10"); | |
getargs("20,"); | |
getargs("30-40"); | |
return 0; | |
} | |
void proc_cleanup(void) { | |
} | |
MODULE_LICENSE("GPL"); | |
module_init(proc_init); | |
module_exit(proc_cleanup); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment