4 // author: arvin@suse.de
14 #include "wvdialmon.h"
16 #include "wvfdstream.h"
19 WvStream
*pppd_log
= NULL
; // to read messages of pppd
24 int main( int argc
, char ** argv
)
27 char *argv_ppp
[ argc
+10 ];
29 argv_ppp
[argc_ppp
++] = "/usr/sbin/pppd";
31 for( int i
= 1; i
< argc
; i
++ )
32 argv_ppp
[argc_ppp
++] = argv
[i
];
35 // open a pipe to access the messages of pppd
37 if( pipe( pppd_msgfd
) == -1 ) {
38 fprintf( stderr
, "pipe failed: %s\n", strerror(errno
) );
43 sprintf( buffer
, "%d", pppd_msgfd
[1] );
44 argv_ppp
[argc_ppp
++] = "logfd";
45 argv_ppp
[argc_ppp
++] = buffer
;
47 pppd_log
= new WvFDStream( pppd_msgfd
[0] );
49 pppd_mon
.setconnectmsg( "Connected..." );
53 for( int i = 0; i < argc_ppp; i++ )
54 printf( "%s\n", argv_ppp[i] );
61 if( pid
== (pid_t
) 0 ) { // we are the child
62 argv_ppp
[argc_ppp
] = NULL
;
63 execv( argv_ppp
[0], argv_ppp
);
64 fprintf( stderr
, "exec failed: %s\n", strerror(errno
) );
68 if( pid
< (pid_t
) 0 ) { // the fork failed
69 fprintf( stderr
, "error: can't fork child process\n" );
75 ppp_pipe = new WvPipe( argv_ppp[0], argv_ppp, false, false, false );
85 // see if pppd is still alive
90 // now watch for messages and output to stdout
92 if( pppd_log
!= NULL
&& pppd_log
->isok() ) {
98 line
= pppd_log
->blocking_getline( 100 );
100 char *buffer1
= pppd_mon
.analyse_line( line
);
101 if( buffer1
!= NULL
&& buffer1
[0] != '\0' ) {
102 char buffer2
[ strlen( buffer1
) + 10 ];
103 sprintf( buffer2
, "pppd: %s", buffer1
);
104 fprintf( stdout
, "%s", buffer2
);
107 } while( line
!= NULL
);
113 exit( EXIT_SUCCESS
);