Skip to content

Commit

Permalink
Implemented network interface listing on Windows.
Browse files Browse the repository at this point in the history
  • Loading branch information
codebutler committed Oct 22, 2010
1 parent aa14feb commit a076295
Show file tree
Hide file tree
Showing 6 changed files with 71 additions and 23 deletions.
24 changes: 22 additions & 2 deletions backend/src/windows_platform.cpp
Expand Up @@ -20,10 +20,11 @@
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.

#include <iostream>
#include <stdbool.h>
#include "windows_platform.hpp"
#include "interface_info.hpp"

#include "pcap.h"
using namespace std;

WindowsPlatform::WindowsPlatform(vector<string>)
Expand Down Expand Up @@ -55,6 +56,25 @@ bool WindowsPlatform::run_privileged() {
vector<InterfaceInfo> WindowsPlatform::interfaces()
{
vector<InterfaceInfo> results;
// FIXME

pcap_if_t *alldevs;
pcap_if_t *d;
char errbuf[PCAP_ERRBUF_SIZE+1];

if (pcap_findalldevs(&alldevs, errbuf) == -1) {
throw runtime_error(str(boost::format("Error in pcap_findalldevs: %s") % errbuf));
}

for (d = alldevs; d; d = d->next) {
string id(d->name);
boost::replace_all(id, "\\", "\\\\");
boost::replace_all(id, "{", "\\{");
boost::replace_all(id, "}", "\\}");
InterfaceInfo info(id, (string(d->description)), "ethernet");
results.push_back(info);
}

pcap_freealldevs(alldevs);

return results;
}
4 changes: 2 additions & 2 deletions configure.ac
Expand Up @@ -52,11 +52,11 @@ AC_ARG_WITH([xulrunner-sdk],
[xulrunner_sdk="$withval"],
[xulrunner_sdk=""])

if test "x$TARGET" = "xWIN32"; then
if test x$TARGET = xWIN32; then
xulrunner_sdk=`readlink -f $xulrunner_sdk`
fi

AS_IF([test -d $xulrunner_sdk], [], [AC_MSG_FAILURE([Specify --with-xulrunner-sdk=<path>.])])
AS_IF([test -d "$xulrunner_sdk"], [], [AC_MSG_FAILURE([Specify --with-xulrunner-sdk=<path>.])])

MOZ_SDK=$xulrunner_sdk
AC_SUBST(MOZ_SDK)
Expand Down
43 changes: 31 additions & 12 deletions xpi/chrome/content/preferences/capturePane.js
Expand Up @@ -24,19 +24,38 @@ Components.utils.import('resource://firesheep/Firesheep.js');
Components.utils.import('resource://firesheep/util/Utils.js');

function loadInterfaces () {
var prefs = Cc["@mozilla.org/preferences-service;1"].getService(Ci.nsIPrefBranch);
var currentId = prefs.getCharPref('firesheep.capture_interface');

var list = document.getElementById('captureInterfaceMenuList');
try {
var currentId = null;

var prefs = Cc["@mozilla.org/preferences-service;1"].getService(Ci.nsIPrefBranch);
if (prefs.prefHasUserValue('firesheep.capture_interface')) {
currentId = prefs.getCharPref('firesheep.capture_interface');
}

var ifaces = Firesheep.networkInterfaces;
for (var id in ifaces) {
var item = document.createElement('menuitem');
item.setAttribute('label', ifaces[id].name + ' (' + id + ')');
item.setAttribute('value', id);
list.menupopup.appendChild(item);
var list = document.getElementById('captureInterfaceMenuList');

if (id == currentId)
list.selectedItem = item;
var ifaces = Firesheep.networkInterfaces;
for (var id in ifaces) {
var name = ifaces[id].name;
var label = (id.length > 4) ? name : (name + ' (' + id + ')');

var item = document.createElement('menuitem');
item.setAttribute('label', label);
item.setAttribute('value', id);
list.menupopup.appendChild(item);

if (id == currentId)
list.selectedItem = item;
}
} catch (e) {
alert(e);
}
}

function setInterface () {
var list = document.getElementById('captureInterfaceMenuList');
var id = list.selectedItem.value;

var prefs = Cc["@mozilla.org/preferences-service;1"].getService(Ci.nsIPrefBranch);
prefs.setCharPref('firesheep.capture_interface', id);
}
4 changes: 2 additions & 2 deletions xpi/chrome/content/preferences/capturePane.xul
Expand Up @@ -29,9 +29,9 @@
<preferences>
<preference id="pref-interface" name="firesheep.capture_interface" type="string" />
</preferences>
<hbox flex="1" align="center">
<hbox align="center">
<label control="capture_interface" value="Interface:" />
<menulist id="captureInterfaceMenuList" preference="pref-interface">
<menulist id="captureInterfaceMenuList" preference="pref-interface" oncommand="setInterface()">
<menupopup />
</menulist>
</hbox>
Expand Down
6 changes: 1 addition & 5 deletions xpi/defaults/preferences/prefs.js
Expand Up @@ -20,11 +20,7 @@
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.


// FIXME: This isn't good enough.
pref("firesheep.capture_interface", "en1");

pref("firesheep.promiscuous_mode", true);
pref("firesheep.capture_interface", "");
pref("firesheep.capture_filter", "tcp port 80");

// https://developer.mozilla.org/en/Localizing_extension_descriptions
Expand Down
13 changes: 13 additions & 0 deletions xpi/modules/Firesheep.js
Expand Up @@ -43,6 +43,19 @@ var Firesheep = {
this.config.load();

this.clearSession();

var prefs = Cc["@mozilla.org/preferences-service;1"].getService(Ci.nsIPrefBranch);
if (!prefs.prefHasUserValue('firesheep.capture_interface')) {
var osString = Cc["@mozilla.org/xre/app-info;1"].getService(Ci.nsIXULRuntime).OS;
if (osString == 'Darwin') {
prefs.setCharPref('firesheep.capture_interface', 'en1');
} else {
for (var id in this.networkInterfaces) {
prefs.setCharPref('firesheep.capture_interface', id);
break;
}
}
}

this._loaded = true;

Expand Down

0 comments on commit a076295

Please sign in to comment.