mywiki:linux:ip_kernel
Differences
This shows you the differences between two versions of the page.
| Next revision | Previous revision | ||
| mywiki:linux:ip_kernel [2014/09/12 14:09] – created shaoguoh | mywiki:linux:ip_kernel [2022/04/02 17:30] (current) – external edit 127.0.0.1 | ||
|---|---|---|---|
| Line 1: | Line 1: | ||
| Get Interface IP adderss in Linux Kernel | Get Interface IP adderss in Linux Kernel | ||
| + | |||
| + | ====== Method ====== | ||
| + | |||
| + | <file > | ||
| + | struct net_device { | ||
| + | ... | ||
| + | | ||
| + | | ||
| + | ... | ||
| + | } | ||
| + | </ | ||
| + | |||
| + | ====== Example 1====== | ||
| + | |||
| <file c get_ip.c> | <file c get_ip.c> | ||
| #include < | #include < | ||
| Line 47: | Line 61: | ||
| module_init(test_startup); | module_init(test_startup); | ||
| module_exit(test_exit); | module_exit(test_exit); | ||
| + | </ | ||
| + | |||
| + | ====== Example 2 ====== | ||
| + | <file get_ip2.c> | ||
| + | int get_ifaddr_by_name(const char *ifname, __u32 * addr) | ||
| + | { | ||
| + | | ||
| + | | ||
| + | | ||
| + | |||
| + | | ||
| + | #if LINUX_VERSION_CODE < KERNEL_VERSION(2, | ||
| + | | ||
| + | #else | ||
| + | | ||
| + | #endif | ||
| + | while (pnet_device != NULL) | ||
| + | { | ||
| + | if ((netif_running(pnet_device)) | ||
| + | && | ||
| + | && | ||
| + | { | ||
| + | | ||
| + | | ||
| + | | ||
| + | | ||
| + | { | ||
| + | | ||
| + | | ||
| + | } | ||
| + | /* ifa_local: ifa_address is the remote point in ppp */ | ||
| + | *addr = (inet_ifaddr-ifa_local); | ||
| + | | ||
| + | | ||
| + | } | ||
| + | #if LINUX_VERSION_CODE < KERNEL_VERSION(2, | ||
| + | | ||
| + | #else | ||
| + | | ||
| + | #endif | ||
| + | |||
| + | } | ||
| + | |||
| + | | ||
| + | | ||
| + | } | ||
| + | |||
| </ | </ | ||
mywiki/linux/ip_kernel.1410502142.txt.gz · Last modified: (external edit)
