Monday, January 31, 2022

[SOLVED] method to change __be32 ip address into char in kernel space

Issue

I am making a module where I need to change the __be 32 format of address into char, which function could I use and under which header file it comes (I know to convert char to __be32 we use in_aton).


Solution

For kernels older than 2.6.26(if not mistaken) you need to use the NIPQUAD macro, like:

pritk("%d.%d.%d.%d\n", NIPQUAD(your_b32_address));

For newer kernels a switch to printk was added:

printk("%pI4\n", your_b32_address);

Have a look here: http://www.kernel.org/doc/htmldocs/kernel-hacking/common-routines.html



Answered By - Fred
Answer Checked By - Cary Denson (WPSolving Admin)