void MovementAdapter::attachToBridge(IMovementBridge* bridge)
{
	if (mBridge != bridge) {
		delete mBridge;
	}
	mBridge = bridge;
	addAdapter();
}
示例#2
0
bool NetworkDevice::init() {
    debugAssert(! initialized);

    logPrintf("Network Startup");
    logPrintf("Starting WinSock networking.\n");
    WSADATA wsda;		    
    WSAStartup(MAKEWORD(G3D_WINSOCK_MAJOR_VERSION, G3D_WINSOCK_MINOR_VERSION), &wsda);
        
    std::string hostname = "localhost";
    {
        char ac[128];
        if (gethostname(ac, sizeof(ac)) == -1) {
            logPrintf("Warning: Error while getting local host name\n");
        } else {
            hostname = gethostbyname(ac)->h_name;
        }
    }
    
    EthernetAdapter a;
    a.hostname = hostname;
    a.name = "";
    a.ip = NetAddress(hostname, 0).ip();

    // TODO: Find subnet on Win32
    a.subnet = 0x0000FFFF;
    
    // TODO: Find broadcast on Win32
    a.broadcast = 0xFFFFFFFF;

    // TODO: find MAC on Win32
    
    addAdapter(a);
    
    std::string machine = localHostName();
    std::string addr    = NetAddress(machine, 0).ipString();
    logPrintf(
              "Network:\n"
              "  Status: %s\n"
              "  Loaded winsock specification version %d (%d is "
              "the highest available)\n"
              "  %d sockets available\n"
              "  Largest UDP datagram packet size is %d bytes\n\n",
              wsda.szDescription,
              wsda.szSystemStatus,
              wsda.wVersion,
              wsda.wHighVersion,
              wsda.iMaxSockets,
              wsda.iMaxUdpDg);
    
    // TODO: WSAIoctl for subnet and broadcast addresses
    // http://msdn.microsoft.com/en-us/library/ms741621(VS.85).aspx
    // 
    // TODO: SIO_GET_INTERFACE_LIST 

    initialized = true;

    return true;
}
示例#3
0
文件: dvb.cpp 项目: ambrosa/test
eDVBResourceManager::eDVBResourceManager()
	:m_releaseCachedChannelTimer(eTimer::create(eApp))
{
	avail = 1;
	busy = 0;
	m_sec = new eDVBSatelliteEquipmentControl(m_frontend, m_simulate_frontend);

	if (!instance)
		instance = this;

		/* search available adapters... */

		// add linux devices

	int num_adapter = 0;
	while (eDVBAdapterLinux::exist(num_adapter))
	{
		addAdapter(new eDVBAdapterLinux(num_adapter));
		num_adapter++;
	}

	int fd = open("/proc/stb/info/model", O_RDONLY);
	char tmp[16];
	int rd = fd >= 0 ? read(fd, tmp, sizeof(tmp)) : 0;
	if (fd >= 0)
		close(fd);

	if (!strncmp(tmp, "dm7025\n", rd))
		m_boxtype = DM7025;
	else if (!strncmp(tmp, "dm8000\n", rd))
		m_boxtype = DM8000;
	else if (!strncmp(tmp, "dm800\n", rd))
		m_boxtype = DM800;
	else if (!strncmp(tmp, "dm500hd\n", rd))
		m_boxtype = DM500HD;
	else if (!strncmp(tmp, "dm800se\n", rd))
		m_boxtype = DM800SE;
	else if (!strncmp(tmp, "dm7020hd\n", rd))
		m_boxtype = DM7020HD;
	else {
		eDebug("boxtype detection via /proc/stb/info not possible... use fallback via demux count!\n");
		if (m_demux.size() == 3)
			m_boxtype = DM800;
		else if (m_demux.size() < 5)
			m_boxtype = DM7025;
		else
			m_boxtype = DM8000;
	}

	eDebug("found %zd adapter, %zd frontends(%zd sim) and %zd demux, boxtype %d",
		m_adapter.size(), m_frontend.size(), m_simulate_frontend.size(), m_demux.size(), m_boxtype);

	CONNECT(m_releaseCachedChannelTimer->timeout, eDVBResourceManager::releaseCachedChannel);
}
示例#4
0
bool NetworkDevice::init() {
    debugAssert(! initialized);

    // Used for combining the MAC and ip information
    typedef Table<std::string, EthernetAdapter> AdapterTable;

    AdapterTable table;

    // Head of a linked list of network interfaces on this machine
    ifaddrs* ifap = NULL;

    int r = getifaddrs(&ifap);

    if (r != 0) {
        logPrintf("ERROR: getifaddrs returned %d\n", r);
        return false;
    }

    ifaddrs* current = ifap;

    if (current == NULL) {
        logPrintf("WARNING: No network interfaces found\n");
        EthernetAdapter a;
        a.name = "fallback";
        a.hostname = "localhost";
        a.ip = (127 << 24) | 1;       
        a.broadcast = 0xFFFFFFFF;
        a.subnet    = 0x000000FF;
        addAdapter(a);

    } else {

        while (current != NULL) {

            bool up = (current->ifa_flags & IFF_UP); 
            bool loopback = (current->ifa_flags & IFF_LOOPBACK);

            if (! up || loopback) {
                // Skip this adapter; it is offline or is a loopback
                current = current->ifa_next;
                continue;
            }

            if (! table.containsKey(current->ifa_name)) {
                EthernetAdapter a;
                a.name = current->ifa_name;
                table.set(a.name, a);
            }

            // This adapter must exist because it was created above
            EthernetAdapter& adapter = table[current->ifa_name];

            const sockaddr_in* interfaceAddress = castToIP4(current->ifa_addr);
            const sockaddr_in* broadcastAddress = castToIP4(current->ifa_dstaddr);
            const sockaddr_in* subnetMask       = castToIP4(current->ifa_netmask);

            uint32 ip = getIP(interfaceAddress);
            uint32 ba = getIP(broadcastAddress);
            uint32 sn = getIP(subnetMask);
            
            if (ip != 0) {
                adapter.ip = ip;
            }

            if (ba != 0) {
                adapter.broadcast = ba;
            }

            if (sn != 0) {
                adapter.subnet = sn;
            }

            uint8_t* MAC = NULL;
            // Extract MAC address
            if ((current->ifa_addr != NULL) && (current->ifa_addr->sa_family == AF_LINK)) {
#               ifdef __linux__
                {
                    // Linux
                    struct ifreq ifr;
                    
                    int fd = socket(AF_INET, SOCK_DGRAM, 0);
                    
                    ifr.ifr_addr.sa_family = AF_INET;
                    strcpy(ifr.ifr_name, current->ifa_name);
                    ioctl(fd, SIOCGIFHWADDR, &ifr);
                    close(fd);
                    
                    MAC = reinterpret_cast<uint8_t*>(ifr.ifr_hwaddr.sa_data);
                }
#               else
                {
                    // The MAC address and the interfaceAddress come in as
                    // different interfaces with the same name.
                    
                    // Posix/FreeBSD/Mac OS
                    sockaddr_dl* sdl = (struct sockaddr_dl *)current->ifa_addr;
                    MAC = reinterpret_cast<uint8_t*>(LLADDR(sdl));
                }
#               endif
                
                // See if there was a MAC address
                if (MAC != NULL) {
                    bool anyNonZero = false;
                    for (int i = 0; i < 6; ++i) {
                        anyNonZero = anyNonZero || (MAC[i] != 0);
                    }
                    if (anyNonZero) {
                        System::memcpy(adapter.mac, MAC, 6);
                    }
                }
            }
     
            current = current->ifa_next;
        }

        freeifaddrs(ifap);
        ifap = NULL;
    }

    // Extract all interesting adapters from the table
    for (AdapterTable::Iterator it = table.begin(); it.isValid(); ++it) {
        const EthernetAdapter& adapter = it->value;
        
        // Only add adapters that have IP addresses
        if (adapter.ip != 0) {
            addAdapter(adapter);
        } else {
            logPrintf("NetworkDevice: Ignored adapter %s because ip = 0\n", adapter.name.c_str());
        }
    }

    initialized = true;

    return true;
}