Hi Tuan Hoang

Use the ioctl() swiss-army knife with the SIOCGIFADDR command for that
one. You will need to pass a structure of type struct ifreq to this.  You
can call ioctl() on any network socket.  Basically it's:

#include <sys/ioctl.h>
#include <net/if.h>
#include <linux/sockios.h>   /* This is a rush, try to find a more standard file */

struct ifreq ifr;
int socket;
int iresult;

char ip_address[20];

.
.
.

strcpy(ifr.ifr_name, "eth0");    /* assuming it's eth0 you want */

/*
 * Open socket.  Any network-related socket will do
 */
socket = socket(PF_INET, SOCK_RAW, 0);  /* I use (PF_INET, SOCK_PACKET) */      
                                        /* on 2.0, (PF_PACKET, SOCK_RAW) */
                                        /* on 2.2.  Personal preference */

iresult = ioctl(socket, SIOCGIFADDR, &ifr);

/*
 * At this point, the address should be in numeric format in
 * ifr.ifr_addr.  It's of type struct sockaddr.
 */

----------------------------------------------------------------
Gerard Paul R. Java
System Administrator, Mosaic Communications Cebu
primary: [EMAIL PROTECTED]
secondary: [EMAIL PROTECTED]






-
To unsubscribe from this list: send the line "unsubscribe linux-net" in
the body of a message to [EMAIL PROTECTED]

Reply via email to