Problem : I have an issue with a sample program to get the ip address which is working fine when I am compiling it with FreeBSD built in gcc. But when I am using cross compiler clang version 3.7.1 , I am getting invalid argument error in ioctl call.
Here is the sample program --
Here is the sample program --
C:
#include <stdio.h>
#include <unistd.h>
#include <string.h> /* for strncpy */
#include <sys/types.h>
#include <sys/socket.h>
#include <sys/ioctl.h>
#include <netinet/in.h>
#include <net/if.h>
#include <arpa/inet.h>
#include <errno.h>
int
main()
{
int fd;
struct ifreq ifr;
fd = socket(AF_INET, SOCK_DGRAM, 0);
/* I want to get an IPv4 IP address */
ifr.ifr_addr.sa_family = AF_INET;
/* I want IP address attached to "eth0"/em0 */
strncpy(ifr.ifr_name, "em0", IFNAMSIZ-1);
ioctl(fd, SIOCGIFADDR, &ifr);
printf("\n ioctl retrun : %d",errno);
close(fd);
/* display result */
printf("\n%s\n", inet_ntoa(((struct sockaddr_in *)&ifr.ifr_addr)->sin_addr));
return 0;
}