[prev in list] [next in list] [prev in thread] [next in thread]
List: linux-ppp
Subject: Re: Need some help on implementation of PPP under Linux kernel mode
From: <houcheng () turbonetworks ! com ! tw>
Date: 2003-01-06 7:19:19
[Download RAW message or body]
Hi:
Thanks for your reply. I've write a small program to make some
experiments
with /dev/ppp. The little program first create a pppoe socket and then
create
a ppp0 network interface. Any furthur advices to my program is very
appreciate!
Lin Houcheng
[Program Part]
int main(int argc, char ** argv) {
int fd;
char ch;
fd = PPPOEConnectDevice(); // create a fd for end-to-end pppoe session
printf("fd is %d\n", fd);
ppp_dev_fd = open("/dev/ppp", O_RDWR);
if (ppp_dev_fd < 0)
printf("Couldn't open /dev/ppp: %m");
generic_establish_ppp (fd);
while(ch != 'q')
ch = getchar();
}
int generic_establish_ppp (int fd)
{
int x;
/* Open another instance of /dev/ppp and connect the channel to it */
int flags;
printf("call here\n");
if (ioctl(fd, PPPIOCGCHAN, &chindex) == -1) {
printf("Couldn't get channel number: %d\n", chindex);
goto err;
}
ppp_fd = fd;
printf("using channel %d\n", chindex);
// reopen an PPP fd, use to connect ...
fd = open("/dev/ppp", O_RDWR);
if (fd < 0) {
printf("Couldn't reopen /dev/ppp: \n");
goto err;
}
printf("fd is %d\n", fd);
if (ioctl(fd, PPPIOCATTCHAN, &chindex) < 0) {
printf("Couldn't attach to channel %d", chindex);
goto err_close;
}
printf("ioctl ok\n");
flags = fcntl(fd, F_GETFL);
if (flags == -1 || fcntl(fd, F_SETFL, flags | O_NONBLOCK) == -1)
printf("Couldn't set /dev/ppp (channel) to nonblock:\n");
printf("fcntl ok\n");
if (!looped)
ifunit = -1;
/*
* Create a new PPP unit.
*/
if (make_ppp_unit() < 0)
goto err_close;
printf("make ok\n");
if (looped)
set_flags(ppp_dev_fd, get_flags(ppp_dev_fd) & ~SC_LOOP_TRAFFIC);
// if (!multilink) {
// printf("add_fd %d\n", ppp_dev_fd);
// add_fd(ppp_dev_fd);
if (ioctl(ppp_fd, PPPIOCCONNECT, &ifunit) < 0) {
printf("Couldn't attach to PPP unit %d: \n", ifunit);
goto err_close;
}
// }
looped = 0;
return ppp_fd;
err_close:
close(fd);
err:
return -1;
}
static int make_ppp_unit()
{
int x;
printf("errno:%d\n", errno);
ifunit = 0; // req_unit;
x = ioctl(ppp_dev_fd, PPPIOCNEWUNIT, &ifunit);
// if (x < 0 && req_unit >= 0 && errno == EEXIST) {
if (x < 0 && errno == EEXIST) {
printf("Couldn't allocate PPP unit %d as it is already in use\n");
ifunit = -1;
x = ioctl(ppp_dev_fd, PPPIOCNEWUNIT, &ifunit);
}
if (x < 0) {
printf("Couldn't create new ppp unit: by errno %d\n", errno);
}
return x;
}
-
To unsubscribe from this list: send the line "unsubscribe linux-ppp" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic