2010-12-23 11 views
1

デバイスをモニタモードに設定しようとしています。モニタモードで「iwconfig wlan0モードモニタ」を動作させることができ、コードを実行してどこからでもパケットをキャプチャできます。pcap_set_rfmonは機能しませんか?

問題は、libpcapでは、私のデバイスを(上記のコマンドラインを入力しなくても)モードを監視するように設定することができません。アクセスポイントに手動で接続するまで、パケットをキャプチャできません。

 pcap_t *handler = pcap_create("wlan0",errbuff); 
     if(pcap_set_rfmon(handler,1)==0) 
     { 
      std::cout << "monitor mode enabled" << std::endl; 
     } 
     handler=pcap_open_live ("wlan0", 2048,0,512,errbuff); 
     int status = pcap_activate(handler); //it returns 0 here. 

ので、これはコードの問題である、またはpcapライブラリの問題?誰が正常にコマンドラインを使用せずにモードを監視するために、自分のデバイスを設定する?私はところでRealtek2500を使用しています。

答えて

11

あなたは同じコードでpcap_open_livepcap_create/pcap_activateを使用することになっていません。試してみてください

pcap_t *handler = pcap_create("wlan0",errbuff); 
if (handler == NULL) 
{ 
    std::cerr << "pcap_create failed: " << errbuf << std::endl; 
    return; // or exit or return an error code or something 
} 
if(pcap_set_rfmon(handler,1)==0) 
{ 
    std::cout << "monitor mode enabled" << std::endl; 
} 
pcap_set_snaplen(handler, 2048); // Set the snapshot length to 2048 
pcap_set_promisc(handler, 0); // Turn promiscuous mode off 
pcap_set_timeout(handler, 512); // Set the timeout to 512 milliseconds 
int status = pcap_activate(handler); 

statusの値を確認してください。

+0

卿、私は私が与えるまでより多くの票を持っていたいです。ありがとう。 – csexton

0

ガイ・ハリスの回答に追加されました。 pcap_open_liveを使用してデバイスを開くと、デバイスがアクティブになります。 PCAP_ERROR_ACTIVATED -4、pcap_set_rfmonに電話をかけてください。

/* the operation can't be performed on already activated captures */  
#define  PCAP_ERROR_ACTIVATED -4 

ので、ハンドルを開き、rfmonを設定し、それをアクティブにするpcap_activateを呼び出すためにpcap_createを使用しています。

+0

これは、この質問に答えて、 'pcap_open_live()'のチェックを追加したために失敗したためです。元のポスターが質問したときに、そのチェックは行われなかった。 –

0

注意:pcap_set_rfmon()ので、このコードが正しい
...成功すると0を返します。

pcap_t *handler = pcap_create("wlan0",errbuff); 
    **if(pcap_set_rfmon(handler,1))** 
    { 
     std::cout << "monitor mode enabled" << std::endl; 
    } 
関連する問題