Forum Navigation
Get IP from Network Device
Posted: 08/29/07 14:03:56I there is no way to get IP from a network device in linux ??
i have this code
#include <string.h>
#include <sys/types.h> #include <sys/socket.h> #include <sys/ioctl.h> #include <netinet/in.h> #include <net/if.h>
char *getIP(char *dev){
int fd; struct ifreq ifr;
fd = socket(AF_INET, SOCK_DGRAM, 0);
ifr.ifr_addr.sa_family = AF_INET;
strncpy(ifr.ifr_name, dev, IFNAMSIZ-1);
ioctl(fd, SIOCGIFADDR, &ifr);
close(fd);
return inet_ntoa(((struct sockaddr_in *)&ifr.ifr_addr)->sin_addr);
}
But i can't port it for D :S Some one can help me please e need this for a project.