ppp programming

Bernd Johannes Wuebben (wuebben@math.cornell.edu)
Tue, 15 Apr 1997 16:40:45 -0400 (EDT)


I have a linux ppp programming question and I hope this is the right
list to ask about this sort of thing. :-).

Assume I just ( and I mean it ) started pppd. Now I would like to get

a) the device, i.e. whether I was given ppp0 or ppp1 etc. Is there an ioctl
way of achieving this, rather than scanning /proc/net/dev before and
after execve'ing pppd ?

b) Now assume I have the device, how do I obtain the local and remote IP
address correctly?

I have tried stuff like:

if ((s = socket(AF_INET, SOCK_DGRAM, 0)) < 0) {
perror("Couldn't create IP socket");
return false;

strcpy(ifr.ifr_name, "ppp0");

// now I found out I need to loop since sometimes I have to wait for
// an ip address different from Is there a way of doing this
// with IFF_UP. If yes how precisely ?


if (ioctl(s, SIOCGIFADDR, &ifr) < 0) {
fprintf(stderr,"Couldn't SIOCGIFADDRE\n");
sinp = (struct sockaddr_in*)&ifr.ifr_addr;

// and even then, once I finally got an ip address, it turns out that
// the address found in ifr.ifr_addr on repeated ioclt(s,SIOCGIFADDR,&iffr)
// is initially the remote address and later the local IP address. ????
// Further more all of the following gives me the same IP address:

sinp = (struct sockaddr_in*)&ifr.ifr_dstaddr;
printf("dstaddr %s\n",inet_ntoa(sinp->sin_addr));

sinp = (struct sockaddr_in*)&ifr.ifr_broadaddr;
printf("broadaddr %s\n",inet_ntoa(sinp->sin_addr));

sinp = (struct sockaddr_in*)&ifr.ifr_hwaddr;
printf("hwaddr %s\n",inet_ntoa(sinp->sin_addr));

What is going on? What is the right way of checking for:

a) which device I was given

b) whether the device is up and therefore that I can start asking
for an IP address ( local and remote )

c) how do I need to ask for the local and remote addresses?

thanks so much for your time :-)


P.S.: Is there some place where I can read about this, or where this
is explained ?