Esempio n. 1
0
void InterfaceStore::print()
{
        Mutex::AutoLocker l(mutex);
	InterfaceStore::iterator it = begin();

	printf("====== Interfaces ======\n");
	printf("<type> <identifier> <name> <flags> <age> <refcount> <parent interface>\n");
	printf("\t<addresses>\n");
	printf("------------------------------\n");
	
	while (it != end()) {
		InterfaceRecord *ir = *it;
		
		ir->iface.lock();
		InterfaceRef iface = ir->iface;
		
                printf("%s %s %s %s %s %lu %s\n", 
                       iface->getTypeStr(),
                       iface->getIdentifierStr(),
                       iface->getName(),
		       iface->getFlagsStr(),
                       ir->cip ? ir->cip->ageStr() : "undefined",
                       ir->iface.refcount(),
                       ir->parent ? ir->parent->getIdentifierStr() : "\'no parent\'");

		const Addresses *addrs = iface->getAddresses();
		
		for (Addresses::const_iterator itt = addrs->begin(); itt != addrs->end(); itt++) {
			const Address *addr = *itt;
			printf("\t%s\n", addr->getURI());
		}
		
		ir->iface.unlock();
		it++;
	}
		
	printf("==============================\n");
}
Esempio n. 2
0
UUExperimentSetup::UUExperimentSetup()
{
	InterfaceRefList iflist;
	InterfaceRef ethIface = NULL;

	// Get all local interfaces, even the ones which are not 'up'
	if (getLocalInterfaceList(iflist, false) < 0) {
		fprintf(stderr, "Could not find any local interfaces\n");
		return;
	}

	// Find the first one returned, it should be the interface we use 
	// for the experiments
	for (InterfaceRefList::iterator it = iflist.begin(); it != iflist.end(); it++) {
		ethIface = *it;

		if (ethIface->getType() == IFTYPE_ETHERNET || ethIface->getType() == IFTYPE_WIFI)
			break;
	}

	if (!ethIface) {
		fprintf(stderr, "No valid local interface to configure\n");
		return;
	}
#if 0
	HRESULT res = S_OK;
	HANDLE hConnMgrReady = ConnMgrApiReadyEvent();

	DWORD retval = WaitForSingleObject(hConnMgrReady, 5000);

	if (retval == WAIT_TIMEOUT) {
		fprintf(stderr, "Connection manager is not ready...\n");
	} else if (retval == WAIT_FAILED) {
		fprintf(stderr, "Wait for Connection manager failed!\n");
	} else {
		for (int i = 0; res == S_OK; i++) {
			CONNMGR_DESTINATION_INFO network_info;

			res = ConnMgrEnumDestinations(i, &network_info);

			if (res == S_OK) {
				printf("Network name %S\n", network_info.szDescription);
			}
		}
	}

	CloseHandle(hConnMgrReady);
#endif
	struct interface_config *ic = get_interface_config(ethIface->getIdentifier());

	if (!ic) {
		fprintf(stderr, "Could not find matching configuration for interface %s\n", 
			ethIface->getIdentifierStr());
		return;
	}

	printf("Configuring interface %s\n", ethIface->getIdentifierStr());

	unsigned long ifindex = 0;
	
	if (!WindowsWiFiUtils::getDeviceIndex(ethIface->getName(), &ifindex)) {
		fprintf(stderr, "Could not get interface index\n");
		return;
	}

	if (!WindowsWiFiUtils::setNetworkMode(ifindex, Ndis802_11IBSS)) {
		fprintf(stderr, "Could not set ad hoc mode\n");
		return;
	}

	if (!WindowsWiFiUtils::setWiFiSSID(ifindex, EXPERIMENT_SSID)) {
		fprintf(stderr, "Could not set WiFi SSID\n");
		return;
	}

	if (!WindowsWiFiUtils::setChannel(ifindex, EXPERIMENT_CHANNEL)) {
		fprintf(stderr, "Could not set WiFi channel to %u\n", EXPERIMENT_CHANNEL);
		return;
	}

	// Add the IPv4 address.
	/*
	if (!WindowsWiFiUtils::addIPv4Address(ifindex, ic->ip, ic->mask)) {
		fprintf(stderr, "Could not set IP address %s/%s\n", ic->ip, ic->mask);
		return false;;
	}
	*/
	printf("Interface %s with mac=%s was configured with ip=%s/%s and SSID=%s on channel=%u\n",
		ethIface->getName(), ethIface->getIdentifierStr(), ic->ip, ic->mask, 
		EXPERIMENT_SSID, EXPERIMENT_CHANNEL);
}