rendered paste bodyint set_monitor( char *interface, int fd_raw, int cardnum )
{
char s[32];
int pid, status, channel;
struct iwreq wrq;
channel = (G.channel[0] == 0 ) ? 10 : G.channel[0];
if( strcmp(interface,"prism0") == 0 )
{
if( ( pid = fork() ) == 0 )
{
close( 0 ); close( 1 ); close( 2 ); chdir( "/" );
execl( G.wl, "wl", "monitor", "1", NULL);
exit( 1 );
}
waitpid( pid, &status, 0 );
if( WIFEXITED(status) )
return( WEXITSTATUS(status) );
return( 1 );
}
else if (strncmp(interface, "rtap", 4) == 0 )
{
return 0;
}
else
{
if( G.is_wlanng[cardnum] )
{
snprintf( s, sizeof( s ) - 1, "channel=%d", channel );
if( ( pid = fork() ) == 0 )
{
close( 0 ); close( 1 ); close( 2 ); chdir( "/" );
execl( G.wlanctlng, "wlanctl-ng", interface,
"lnxreq_wlansniff", "enable=true",
"prismheader=true", "wlanheader=false",
"stripfcs=true", "keepwepflags=true",
s, NULL );
exit( 1 );
}
waitpid( pid, &status, 0 );
if( WIFEXITED(status) )
return( WEXITSTATUS(status) );
return( 1 );
}
/* FIXME */
if( ( pid = fork() ) == 0 )
{
close( 0 ); close( 1 ); close( 2 ); chdir( "/" );
execlp("ifconfig", "ifconfig", interface, "down");
exit( 1 );
}
waitpid( pid, &status, 0 );
memset( &wrq, 0, sizeof( struct iwreq ) );
strncpy( wrq.ifr_name, interface, IFNAMSIZ );
wrq.u.mode = IW_MODE_MONITOR;
if( ioctl( fd_raw, SIOCSIWMODE, &wrq ) < 0 )
{
perror( "ioctl(SIOCSIWMODE) failed" );
return( 1 );
}
/* FIXME */
if( ( pid = fork() ) == 0 )
{
close( 0 ); close( 1 ); close( 2 ); chdir( "/" );
execlp("ifconfig", "ifconfig", interface, "up");
exit( 1 );
}
waitpid( pid, &status, 0 );
}
/* Check later if it's really usefull to set channel here */
set_channel( interface, fd_raw, (G.channel[cardnum] == 0 ) ? 10 : G.channel[cardnum], cardnum);
return( 0 );
}