On Mon, Mar 22, 1999 at 02:44:08PM -0500, Tuan Hoang wrote:
> Hi,
>
> What is the best way to get the ip address from
> a device, such as ppp0, ppp1, eth0, eth1, etc...?
>
> Are there a few ways? Easiest? Pro's & Con's?
scan /proc/net/dev
pro: easy
con: incompatible, and you have to make sure your program will
accept changes in kernel interface...
use the IOCTL which was made for it...
pro: easiest, compatible, better, stronger, faster...
con: bit more fuss
some untested,not checking for boundaries or error values, snipped:
------------
int fd = socket(...);
struct ifreq ifr;
strcpy(ifr.ifr_name,"ppp0");
ioctl(fd,SIOCGIFADDR,&ifr,sizeof(ifr));
printf("my interface address is %s\n",inet_ntoa(ifr.ifr_addr));
------------
Met vriendelijke groet,
Pauline Middelink
--
PGP Key fingerprint = DE 6B D0 D9 19 AD A7 A0 58 A3 06 9D B6 34 39 E2
For more details look at my website http://www.polyware.nl/~middelin
-
To unsubscribe from this list: send the line "unsubscribe linux-net" in
the body of a message to [EMAIL PROTECTED]