Ejemplo n.º 1
0
status_t
InterfacesListView::_InitList()
{
	BNetworkRoster& roster = BNetworkRoster::Default();
	BNetworkInterface interface;
	uint32 cookie = 0;

	while (roster.GetNextInterface(&cookie, interface) == B_OK) {
		if (strncmp(interface.Name(), "loop", 4) && interface.Name()[0])
			AddItem(new InterfaceListItem(interface.Name()));
	}

	return B_OK;
}
Ejemplo n.º 2
0
void
EthernetSettingsView::_GatherInterfaces()
{
    // iterate over all interfaces and retrieve minimal status

    fInterfaces.MakeEmpty();

    BNetworkRoster& roster = BNetworkRoster::Default();
    BNetworkInterface interface;
    uint32 cookie = 0;

    while (roster.GetNextInterface(&cookie, interface) == B_OK) {
        if (strncmp(interface.Name(), "loop", 4) && interface.Name()[0]) {
            fInterfaces.AddItem(new BString(interface.Name()));
            fSettings.AddItem(new Settings(interface.Name()));
        }
    }
}
Ejemplo n.º 3
0
void
NetworkWindow::_ScanInterfaces()
{
	// Try existing devices first
	BNetworkRoster& roster = BNetworkRoster::Default();
	BNetworkInterface interface;
	uint32 cookie = 0;

	while (roster.GetNextInterface(&cookie, interface) == B_OK) {
		if ((interface.Flags() & IFF_LOOPBACK) != 0)
			continue;

		InterfaceListItem* item = new InterfaceListItem(interface.Name());
		item->SetExpanded(true);

		fInterfaceItemMap.insert(std::pair<BString, InterfaceListItem*>(
			BString(interface.Name()), item));
		fListView->AddItem(item);
	}

	// TODO: Then consider those from the settings (for example, for USB)
}
Ejemplo n.º 4
0
void
NetworkStatusView::_Update(bool force)
{
	BNetworkRoster& roster = BNetworkRoster::Default();
	BNetworkInterface interface;
	uint32 cookie = 0;

	while (roster.GetNextInterface(&cookie, interface) == B_OK) {
		if ((interface.Flags() & IFF_LOOPBACK) == 0) {
			int32 oldStatus = kStatusUnknown;
			if (fInterfaceStatuses.find(interface.Name())
				!= fInterfaceStatuses.end()) {
				oldStatus = fInterfaceStatuses[interface.Name()];
			}
			int32 status = _DetermineInterfaceStatus(interface);
			if (oldStatus != status) {
				BNotification notification(B_INFORMATION_NOTIFICATION);
				notification.SetGroup(B_TRANSLATE("Network Status"));
				notification.SetTitle(interface.Name());
				notification.SetMessageID(interface.Name());
				notification.SetIcon(fNotifyIcons[status]);
				if (status == kStatusConnecting
					|| (status == kStatusReady
						&& oldStatus == kStatusConnecting)
					|| (status == kStatusNoLink
						&& oldStatus == kStatusReady)
					|| (status == kStatusNoLink
						&& oldStatus == kStatusConnecting)) {
					// A significant state change, raise notification.
					notification.SetContent(kStatusDescriptions[status]);
					notification.Send();
				}
				Invalidate();
			}
			fInterfaceStatuses[interface.Name()] = status;
		}
	}
}
Ejemplo n.º 5
0
void
NetPulseView::MouseDown(BPoint where)
{
	int32 buttons;
	int32 clicks;
	if (Window()->CurrentMessage()->FindInt32("buttons", &buttons) != B_OK
		|| Window()->CurrentMessage()->FindInt32("clicks", &clicks) != B_OK) {
		return;
	}

	if (buttons == B_SECONDARY_MOUSE_BUTTON) {	
		BPopUpMenu* popUpMenu = new BPopUpMenu("NetPulseMenu");

		popUpMenu->AddItem(new BMenuItem("Connect",
			new BMessage(kMsgConnect)));
		popUpMenu->AddItem(new BMenuItem("Disconnect",
			new BMessage(kMsgDisconnect)));
		popUpMenu->AddSeparatorItem();

		popUpMenu->AddItem(new BMenuItem("Statistics...",
			new BMessage(kMsgStatistics)));
		popUpMenu->AddSeparatorItem();

		uint32 cookie = 0;
		BNetworkInterface interface;
		BNetworkRoster& roster = BNetworkRoster::Default();
		while (roster.GetNextInterface(&cookie, interface) == B_OK) {
			const char* name = interface.Name();
			if (strncmp(name, "loop", 4) != 0) {
				BMenuItem* menuItem = new BMenuItem(name,
					new BMessage(kMsgChangeInterface + cookie));
				menuItem->SetMarked(cookie == fCookie);
				popUpMenu->AddItem(menuItem);
			}
		}

		popUpMenu->AddSeparatorItem();
		popUpMenu->AddItem(new BMenuItem("Quit", new BMessage(kMsgQuit)));
		popUpMenu->SetTargetForItems(this);

		popUpMenu->FindItem(kMsgConnect)->SetEnabled(!fEnable && fCookie != 0);
		popUpMenu->FindItem(kMsgDisconnect)->SetEnabled(fEnable && fCookie != 0);
		popUpMenu->FindItem(kMsgStatistics)->SetEnabled(fEnable && fCookie != 0);

		popUpMenu->Go(ConvertToScreen(BPoint(0, 0)), true, false, false);
		delete popUpMenu;
	} else if (buttons == B_PRIMARY_MOUSE_BUTTON && clicks == 2)
		be_roster->Launch("application/x-vnd.Haiku-Network");
}
Ejemplo n.º 6
0
static
status_t
show_all()
{
	BNetworkRoster& roster = BNetworkRoster::Default();

	BNetworkInterface interface;
	uint32 cookie = 0;

	while (roster.GetNextInterface(&cookie, interface) == B_OK) {
		BNetworkAddress linkAddress;
		status_t status = interface.GetHardwareAddress(linkAddress);
		if (status == B_OK && linkAddress.LinkLevelType() == IFT_TUN)
			show_interface(interface.Name());
	}
	return B_OK;
}
Ejemplo n.º 7
0
void
list_interfaces(const char* name)
{
	if (name != NULL) {
		list_interface(name);
		return;
	}

	// get a list of all interfaces

	BNetworkRoster& roster = BNetworkRoster::Default();

	BNetworkInterface interface;
	uint32 cookie = 0;

	while (roster.GetNextInterface(&cookie, interface) == B_OK) {
		list_interface(interface.Name());
	}
}
Ejemplo n.º 8
0
status_t
BNetworkRoster::RemoveInterface(const BNetworkInterface& interface)
{
    return RemoveInterface(interface.Name());
}
Ejemplo n.º 9
0
status_t
BNetworkRoster::AddInterface(const BNetworkInterface& interface)
{
    return AddInterface(interface.Name());
}
Ejemplo n.º 10
0
status_t
BGeolocation::LocateSelf(float& latitude, float& longitude)
{
	// Enumerate wifi network and build JSON message
	BNetworkRoster& roster = BNetworkRoster::Default();
	uint32 interfaceCookie = 0;
	BNetworkInterface interface;

	BString query("{\n\t\"wifiAccessPoints\": [");
	int32 count = 0;

	while (roster.GetNextInterface(&interfaceCookie, interface) == B_OK) {
		uint32 networkCookie = 0;
		wireless_network network;

		BNetworkDevice device(interface.Name());
			// TODO is that the correct way to enumerate devices?

		while (device.GetNextNetwork(networkCookie, network) == B_OK) {
			if (count != 0)
				query += ',';

			count++;

			query += "\n\t\t{ \"macAddress\": \"";
			query += network.address.ToString().ToUpper();
			query += "\", \"signalStrength\": ";
			query << (int)network.signal_strength;
			query += ", \"signalToNoiseRatio\": ";
			query << (int)network.noise_level;
			query += " }";
		}

	}

	query += "\n\t]\n}\n";

	// Check that we have enough data (we need at least 2 networks)
	if (count < 2)
		return B_DEVICE_NOT_FOUND;

	class GeolocationListener: public BUrlProtocolListener
	{
		public:
			virtual	~GeolocationListener() {};

			void	DataReceived(BUrlRequest*, const char* data, off_t position,
						ssize_t size) {
				result.WriteAt(position, data, size);
			}
			BMallocIO result;
	};

	GeolocationListener listener;

	// Send Request (POST JSON message)
	BUrlRequest* request = BUrlProtocolRoster::MakeRequest(fService, &listener);
	if (request == NULL)
		return B_BAD_DATA;

	BHttpRequest* http = dynamic_cast<BHttpRequest*>(request);
	if (http == NULL) {
		delete request;
		return B_BAD_DATA;
	}

	http->SetMethod(B_HTTP_POST);
	BMemoryIO* io = new BMemoryIO(query.String(), query.Length());
	http->AdoptInputData(io, query.Length());

	status_t result = http->Run();
	if (result < 0) {
		delete http;
		return result;
	}

	while (http->IsRunning())
		snooze(10000);

	// Parse reply
	const BHttpResult& reply = (const BHttpResult&)http->Result();
	if (reply.StatusCode() != 200) {
		delete http;
		return B_ERROR;
	}

	BMessage data;
	result = BJson::Parse(data, (char*)listener.result.Buffer());
	delete http;
	if (result != B_OK) {
		return result;
	}

	BMessage location;
	result = data.FindMessage("location", &location);
	if (result != B_OK)
		return result;

	double lat, lon;
	result = location.FindDouble("lat", &lat);
	if (result == B_OK)
		result = location.FindDouble("lng", &lon);

	latitude = lat;
	longitude = lon;

	return result;
}