Found some code that supposedly does does this, but have not been able to get it to return the correct address.
Code:
/* eth0 to __u32 IP address */
static inline __u32
getlocalIP(void){
struct net_device *device;
struct in_device *in_dev;
struct in_ifaddr *if_addr;
char dev_name[20];
__u8 *addr;
sprintf(dev_name,"eth%d",0);
device = dev_get_by_name(dev_name);
in_dev = (struct in_device *)device->ip_ptr;
if_addr = in_dev->ifa_list;
addr = (char *)&if_addr->ifa_local;
printk(KERN_ALERT "Eth0 IP: %lu.",
(unsigned int long)addr);
return (__u32)addr;
}