int sendAPPmsg(struct ODRmsg *app, int route) { //Get the index from the routing table, use it to find the right interface; int inter = findInterface(routing_table[route].index); if(inter == -1) { printf("Can't send APPmsg, invalid interface\n"); return -1; } if(sendPacket(*app, inter, route, 1) == 0) return 0; else { printf("sendAPPmsg error\n"); return -1; } }
void BrcmPatchRAM::uploadFirmware() { // signal to timer that firmware already loaded mDevice->setProperty(kFirmwareLoaded, true); if (mDevice->open(this)) { // Print out additional device information printDeviceInfo(); // Set device configuration to composite configuration index 0 // Obtain first interface if (setConfiguration(0) && (mInterface = findInterface()) && mInterface->open(this)) { mInterruptPipe = findPipe(kUSBInterrupt, kUSBIn); mBulkPipe = findPipe(kUSBBulk, kUSBOut); if (mInterruptPipe && mBulkPipe) { if (performUpgrade()) AlwaysLog("[%04x:%04x]: Firmware upgrade completed successfully.\n", mVendorId, mProductId); else AlwaysLog("[%04x:%04x]: Firmware upgrade failed.\n", mVendorId, mProductId); OSSafeReleaseNULL(mReadBuffer); // mReadBuffer is allocated by performUpgrade but not released } mInterface->close(this); } // cleanup if (mInterruptPipe) { mInterruptPipe->Abort(); mInterruptPipe->release(); // retained in findPipe mInterruptPipe = NULL; } if (mBulkPipe) { mBulkPipe->Abort(); mBulkPipe->release(); // retained in findPipe mBulkPipe = NULL; } OSSafeReleaseNULL(mInterface);// retained in findInterface mDevice->close(this); } }
/* * change the interface state to down */ int downInterface(int index) { interface_t *iface; iface = findInterface(index); if (iface == NULL) { error("[downInterface]:: Interface %d not found ..unable to take down ", index); return EXIT_FAILURE; } int status = downThisInterface(iface); if (rconfig.openflow) { openflow_config_update_phy_port( openflow_config_get_of_port_num(index)); } return status; }
interface_t *GNETMakeTapInterface(char *device, uchar *mac_addr, uchar *nw_addr) { vpl_data_t *vcon; interface_t *iface; int iface_id; char tmpbuf[MAX_TMPBUF_LEN]; verbose(2, "[GNETMakeTapInterface]:: making Interface for [%s] with MAC %s and IP %s", device, MAC2Colon(tmpbuf, mac_addr), IP2Dot((tmpbuf+20), nw_addr)); iface_id = gAtoi(device); if (findInterface(iface_id) != NULL) { verbose(1, "[GNETMakeTapInterface]:: device %s already defined.. ", device); return NULL; } else { // setup the interface.. with default MTU of 1500 we cannot set it at this time. iface = newInterfaceStructure(device, device, mac_addr, nw_addr, 1500); /* * try connection (as client). only option here... */ verbose(2, "[GNETMakeTapInterface]:: trying to connect to %s..", device); if ((vcon = tap_connect(device)) == NULL) { verbose(1, "[GNETMakeTapInterface]:: unable to connect to %s", device); return NULL; } // fill in the rest of the interface iface->iface_fd = vcon->data; iface->vpl_data = vcon; upThisInterface(iface); return iface; } }
Reference * Reference::getActiveObject (REFCLSID clsid, const Interface *pInterface) { HRESULT hr; // Retrieve the instance of the object. IUnknownPtr pActive; hr = GetActiveObject(clsid, NULL, &pActive); if (FAILED(hr)) { _com_issue_error(hr); } // If we know it's a custom interface, then query for an interface pointer // to that interface, otherwise query for an IUnknown interface. IUnknown *pUnknown; hr = pActive->QueryInterface( (pInterface == 0) ? IID_IUnknown : pInterface->iid(), reinterpret_cast<void **>(&pUnknown)); if (FAILED(hr)) { _com_issue_error(hr); } if (pInterface == 0) { pInterface = findInterface(pUnknown, clsid); if (pInterface != 0) { // Get a pointer to the derived interface. IUnknown *pNew; hr = pUnknown->QueryInterface( pInterface->iid(), reinterpret_cast<void **>(&pNew)); if (SUCCEEDED(hr)) { pUnknown->Release(); pUnknown = pNew; } } } return new Reference(pUnknown, pInterface, clsid); }
/* * ARGUMENTS: device: e.g. tun2 * mac_addr: hardware address of the interface * nw_addr: network address of the interface (IPv4 by default) * dst_ip: physical IP address of destination mesh station on the MBSS * dst_port: interface number of the destination interface on the destination yRouter * RETURNS: a pointer to the interface on success and NULL on failure */ interface_t *GNETMakeTunInterface(char *device, uchar *mac_addr, uchar *nw_addr, uchar* dst_ip, short int dst_port) { vpl_data_t *vcon; interface_t *iface; int iface_id; char tmpbuf[MAX_TMPBUF_LEN]; verbose(2, "[GNETMakeTunInterface]:: making Interface for [%s] with MAC %s and IP %s", device, MAC2Colon(tmpbuf, mac_addr), IP2Dot((tmpbuf+20), nw_addr)); iface_id = gAtoi(device); if (findInterface(iface_id) != NULL) { verbose(1, "[GNETMakeTunInterface]:: device %s already defined.. ", device); return NULL; } // setup the interface.. iface = newInterfaceStructure(device, device, mac_addr, nw_addr, MAX_MTU); verbose(2, "[GNETMakeTunInterface]:: trying to connect to %s..", device); vcon = tun_connect((short int)(BASEPORTNUM+iface_id+gAtoi(rconfig.router_name)*100), NULL, (short int)(BASEPORTNUM+dst_port+gAtoi(rconfig.router_name)*100), dst_ip); if(vcon == NULL) { verbose(1, "[GNETMakeTunInterface]:: unable to connect to %s", device); return NULL; } iface->iface_fd = vcon->data; iface->vpl_data = vcon; upThisInterface(iface); return iface; }
void *toEthernetDev(void *arg) { gpacket_t *inpkt = (gpacket_t *)arg; interface_t *iface; arp_packet_t *apkt; //ospf_packet_t *ospkt; char tmpbuf[MAX_TMPBUF_LEN]; int pkt_size; verbose(2, "[toEthernetDev]:: entering the function.. "); // find the outgoing interface and device... if ((iface = findInterface(inpkt->frame.dst_interface)) != NULL) { /* send IP packet, ARP reply, or OSPF packet */ if (inpkt->data.header.prot == htons(ARP_PROTOCOL)){ apkt = (arp_packet_t *) inpkt->data.data; COPY_MAC(apkt->src_hw_addr, iface->mac_addr); COPY_IP(apkt->src_ip_addr, gHtonl(tmpbuf, iface->ip_addr)); } else if (inpkt->data.header.prot == htons(IP_PROTOCOL)) { ip_packet_t *ip_pkt = (ip_packet_t *)inpkt->data.data; if(ip_pkt->ip_prot == OSPF_PROTOCOL){ } //RECHECK determine if you're putting MAC address //into the right place } pkt_size = findPacketSize(&(inpkt->data)); verbose(2, "[toEthernetDev]:: vpl_sendto called for interface %d..%d bytes written ", iface->interface_id, pkt_size); int x = vpl_sendto(iface->vpl_data, &(inpkt->data), pkt_size); free(inpkt); // finally destroy the memory allocated to the packet.. } else{ error("[toEthernetDev]:: ERROR!! Could not find outgoing interface ..."); } // this is just a dummy return -- return value not used. return arg; }
int sendRREP(struct ODRmsg RREP, int out_if, int route, int force) { printf("sending RREP\n"); int i, ifi; RREP.type = htons(1); RREP.broadcast_id = htons(broadcast_id); RREP.forced_discovery = force; //This should already be htons strncpy(RREP.app.message, "RREP\0", 5); ifi = findInterface(out_if); if(ifi == -1) { printf("Can't send RREP, invalid interface\n"); return -1; } if(sendPacket(RREP, ifi, route, 0) < 0) { printf("Failed to sendRREP on interface %i\n", out_if); return -1; } return 0; }
void *toEthernetDev(void *arg) { gpacket_t *inpkt = (gpacket_t *)arg; interface_t *iface; arp_packet_t *apkt; char tmpbuf[MAX_TMPBUF_LEN]; int pkt_size; verbose(2, "[toEthernetDev]:: entering the function.. "); // find the outgoing interface and device... if ((iface = findInterface(inpkt->frame.dst_interface)) != NULL) { /* send IP packet or ARP reply */ if (inpkt->data.header.prot == htons(ARP_PROTOCOL)) { apkt = (arp_packet_t *) inpkt->data.data; COPY_MAC(apkt->src_hw_addr, iface->mac_addr); COPY_IP(apkt->src_ip_addr, gHtonl(tmpbuf, iface->ip_addr)); } pkt_size = findPacketSize(&(inpkt->data)); //Printing packet values /* printf("\n=========== OUTGOING PACKET VALUES ================\n"); printf("\n----------HEADER VALUES :"); printf("\nSource MAC Address: %x : %x : %x : %x : %x : %x", inpkt->data.header.src[0], inpkt->data.header.src[1],inpkt->data.header.src[2], inpkt->data.header.src[3],inpkt->data.header.src[4],inpkt->data.header.src[5]); printf("\nDestination MAC Address: %x : %x : %x : %x : %x : %x", inpkt->data.header.dst[0], inpkt->data.header.dst[1],inpkt->data.header.dst[2], inpkt->data.header.dst[3],inpkt->data.header.dst[4],inpkt->data.header.dst[5]); printf("\nSource IP Address: %d.%d.%d.%d", inpkt->frame.src_ip_addr[0], inpkt->frame.src_ip_addr[1],inpkt->frame.src_ip_addr[2], inpkt->frame.src_ip_addr[3]); printf("\nProtocol is : %d",inpkt->data.header.prot); printf("\nDestination Interface is : %d",inpkt->frame.dst_interface); printf("\nARP BDST : %d",inpkt->frame.arp_bcast); printf("\narp_valid : %d",inpkt->frame.arp_valid); printf("\nSource Hardware Address: %d.%d.%d.%d.%d.%d", inpkt->frame.src_hw_addr[0], inpkt->frame.src_hw_addr[1],inpkt->frame.src_hw_addr[2], inpkt->frame.src_hw_addr[3],inpkt->frame.src_hw_addr[4],inpkt->frame.src_hw_addr[5]); printf("\nIngress Port is : %d",inpkt->frame.src_interface); printf("\nNXTH IP Destination: %d.%d.%d.%d", inpkt->frame.nxth_ip_addr[0],inpkt->frame.nxth_ip_addr[1], inpkt->frame.nxth_ip_addr[2],inpkt->frame.nxth_ip_addr[3]); printf("\n --- IP PACKET:"); ip_packet_t *ip_pkt; ip_pkt = (ip_packet_t *) inpkt->data.data; printf("\Destination MAC Address: %x : %x : %x : %x : %x : %x", inpkt->data.header.dst[0], inpkt->data.header.dst[1], inpkt->data.header.dst[2], inpkt->data.header.dst[3],inpkt->data.header.dst[4],inpkt->data.header.dst[5]); printf("\Source MAC Address: %x : %x : %x : %x : %x : %x", inpkt->data.header.src[0], inpkt->data.header.src[1],inpkt->data.header.src[2], inpkt->data.header.src[3],inpkt->data.header.src[4],inpkt->data.header.src[5]); printf("\nIP Source: %d.%d.%d.%d", ip_pkt->ip_src[0],ip_pkt->ip_src[1],ip_pkt->ip_src[2],ip_pkt->ip_src[3]); printf("\nIP Destination: %d.%d.%d.%d", ip_pkt->ip_dst[0],ip_pkt->ip_dst[1],ip_pkt->ip_dst[2],ip_pkt->ip_dst[3]); printf("\nIP Protocol is : %d",ip_pkt->ip_prot); printf("\nIP TOS: %d\n",ip_pkt->ip_tos); printf("\nip_cksum: %d\n",ip_pkt->ip_cksum); printf("\nip_frag_off: %d\n",ip_pkt->ip_frag_off); printf("\nip_hdr_len: %d\n",ip_pkt->ip_hdr_len); printf("\nip_identifier: %d\n",ip_pkt->ip_identifier); printf("\nip_pkt_len: %d\n",ip_pkt->ip_pkt_len); printf("\nip_ttl: %d\n",ip_pkt->ip_ttl); printf("\nip_version: %d\n",ip_pkt->ip_version);*/ verbose(2, "[toEthernetDev]:: vpl_sendto called for interface %d..%d bytes written ", iface->interface_id, pkt_size); vpl_sendto(iface->vpl_data, &(inpkt->data), pkt_size); free(inpkt); // finally destroy the memory allocated to the packet.. } else error("[toEthernetDev]:: ERROR!! Could not find outgoing interface ..."); // this is just a dummy return -- return value not used. return arg; }
static int interpretAddr(struct nlmsghdr *p_hdr, struct ifaddrs **p_resultList, int p_numLinks) { struct ifaddrmsg *l_info = (struct ifaddrmsg *)NLMSG_DATA(p_hdr); struct ifaddrs *l_interface = findInterface(l_info->ifa_index, p_resultList, p_numLinks); if(l_info->ifa_family == AF_PACKET) { return 0; } size_t l_nameSize = 0; size_t l_addrSize = 0; int l_addedNetmask = 0; size_t l_rtaSize = NLMSG_PAYLOAD(p_hdr, sizeof(struct ifaddrmsg)); struct rtattr *l_rta; for(l_rta = IFA_RTA(l_info); RTA_OK(l_rta, l_rtaSize); l_rta = RTA_NEXT(l_rta, l_rtaSize)) { size_t l_rtaDataSize = RTA_PAYLOAD(l_rta); switch(l_rta->rta_type) { case IFA_ADDRESS: case IFA_LOCAL: if((l_info->ifa_family == AF_INET || l_info->ifa_family == AF_INET6) && !l_addedNetmask) { // make room for netmask l_addrSize += NLMSG_ALIGN(calcAddrLen(l_info->ifa_family, l_rtaDataSize)); l_addedNetmask = 1; } case IFA_BROADCAST: l_addrSize += NLMSG_ALIGN(calcAddrLen(l_info->ifa_family, l_rtaDataSize)); break; case IFA_LABEL: l_nameSize += NLMSG_ALIGN(l_rtaSize + 1); break; default: break; } } struct ifaddrs *l_entry = malloc(sizeof(struct ifaddrs) + l_nameSize + l_addrSize); if (l_entry == NULL) { return -1; } memset(l_entry, 0, sizeof(struct ifaddrs)); l_entry->ifa_name = (l_interface ? l_interface->ifa_name : ""); char *l_name = ((char *)l_entry) + sizeof(struct ifaddrs); char *l_addr = l_name + l_nameSize; l_entry->ifa_flags = l_info->ifa_flags; if(l_interface) { l_entry->ifa_flags |= l_interface->ifa_flags; } l_rtaSize = NLMSG_PAYLOAD(p_hdr, sizeof(struct ifaddrmsg)); for(l_rta = IFA_RTA(l_info); RTA_OK(l_rta, l_rtaSize); l_rta = RTA_NEXT(l_rta, l_rtaSize)) { void *l_rtaData = RTA_DATA(l_rta); size_t l_rtaDataSize = RTA_PAYLOAD(l_rta); switch(l_rta->rta_type) { case IFA_ADDRESS: case IFA_BROADCAST: case IFA_LOCAL: { size_t l_addrLen = calcAddrLen(l_info->ifa_family, l_rtaDataSize); makeSockaddr(l_info->ifa_family, (struct sockaddr *)l_addr, l_rtaData, l_rtaDataSize); if(l_info->ifa_family == AF_INET6) { if(IN6_IS_ADDR_LINKLOCAL((struct in6_addr *)l_rtaData) || IN6_IS_ADDR_MC_LINKLOCAL((struct in6_addr *)l_rtaData)) { ((struct sockaddr_in6 *)l_addr)->sin6_scope_id = l_info->ifa_index; } } if(l_rta->rta_type == IFA_ADDRESS) { // apparently in a point-to-point network IFA_ADDRESS contains the dest address and IFA_LOCAL contains the local address if(l_entry->ifa_addr) { l_entry->ifa_dstaddr = (struct sockaddr *)l_addr; } else { l_entry->ifa_addr = (struct sockaddr *)l_addr; } } else if(l_rta->rta_type == IFA_LOCAL) { if(l_entry->ifa_addr) { l_entry->ifa_dstaddr = l_entry->ifa_addr; } l_entry->ifa_addr = (struct sockaddr *)l_addr; } else { l_entry->ifa_broadaddr = (struct sockaddr *)l_addr; } l_addr += NLMSG_ALIGN(l_addrLen); break; } case IFA_LABEL: strncpy(l_name, l_rtaData, l_rtaDataSize); l_name[l_rtaDataSize] = '\0'; l_entry->ifa_name = l_name; break; default: break; } } if(l_entry->ifa_addr && (l_entry->ifa_addr->sa_family == AF_INET || l_entry->ifa_addr->sa_family == AF_INET6)) { unsigned l_maxPrefix = (l_entry->ifa_addr->sa_family == AF_INET ? 32 : 128); unsigned l_prefix = (l_info->ifa_prefixlen > l_maxPrefix ? l_maxPrefix : l_info->ifa_prefixlen); char l_mask[16] = {0}; unsigned i; for(i=0; i<(l_prefix/8); ++i) { l_mask[i] = 0xff; } if(l_prefix % 8) { l_mask[i] = 0xff << (8 - (l_prefix % 8)); } makeSockaddr(l_entry->ifa_addr->sa_family, (struct sockaddr *)l_addr, l_mask, l_maxPrefix / 8); l_entry->ifa_netmask = (struct sockaddr *)l_addr; } addToEnd(p_resultList, l_entry); return 0; }
Reference * Reference::createInstance ( REFCLSID clsid, const Interface *pInterface, DWORD clsCtx, const char *serverHost) { // If we know it's a custom interface, then query for an interface pointer // to that interface, otherwise query for an IUnknown interface. const IID &iid = (pInterface == 0) ? IID_IUnknown : pInterface->iid(); HRESULT hr; IUnknown *pUnknown; // Create an instance of the specified class. #ifdef _WIN32_DCOM if (serverHost == 0 || serverHost[0] == '\0' || strcmp(serverHost, "localhost") == 0 || strcmp(serverHost, "127.0.0.1") == 0) { // When creating an instance on the local machine, call // CoCreateInstance instead of CoCreateInstanceEx with a null pointer // to COSERVERINFO. This works around occasional failures in the RPC // DLL on Windows NT 4.0, even when connecting to a server on the local // machine. hr = CoCreateInstance( clsid, NULL, clsCtx, iid, reinterpret_cast<void **>(&pUnknown)); } else { COSERVERINFO serverInfo; memset(&serverInfo, 0, sizeof(serverInfo)); _bstr_t serverHostBstr(serverHost); serverInfo.pwszName = serverHostBstr; MULTI_QI qi; qi.pIID = &iid; qi.pItf = NULL; qi.hr = 0; hr = CoCreateInstanceEx( clsid, NULL, clsCtx, &serverInfo, 1, &qi); if (SUCCEEDED(hr)) { pUnknown = static_cast<IUnknown *>(qi.pItf); } } #else hr = CoCreateInstance( clsid, NULL, clsCtx, iid, reinterpret_cast<void **>(&pUnknown)); #endif if (FAILED(hr)) { _com_issue_error(hr); } if (pInterface == 0) { pInterface = findInterface(pUnknown, clsid); if (pInterface != 0) { // Get a pointer to the derived interface. IUnknown *pNew; hr = pUnknown->QueryInterface( pInterface->iid(), reinterpret_cast<void **>(&pNew)); if (SUCCEEDED(hr)) { pUnknown->Release(); pUnknown = pNew; } } } return new Reference(pUnknown, pInterface, clsid); }
/* * destroyInterface by Index... */ int destroyInterfaceByIndex(int indx) { return destroyInterface(findInterface(indx)); }
interface_t *GNETMakeEthInterface(char *vsock_name, char *device, uchar *mac_addr, uchar *nw_addr, int iface_mtu, int cforce) { vpl_data_t *vcon; interface_t *iface; int iface_id, thread_stat; char tmpbuf[MAX_TMPBUF_LEN]; vplinfo_t *vi; pthread_t threadid; verbose(2, "[GNETMakeEthInterface]:: making Interface for [%s] with MAC %s and IP %s", device, MAC2Colon(tmpbuf, mac_addr), IP2Dot((tmpbuf+20), nw_addr)); iface_id = gAtoi(device); if (findInterface(iface_id) != NULL) { verbose(1, "[GNETMakeEthInterface]:: device %s already defined.. ", device); return NULL; } else { // setup the interface.. iface = newInterfaceStructure(vsock_name, device, mac_addr, nw_addr, iface_mtu); /* * try connection (as client). if it fails and force client flag * is set, then return NULL. Otherwise, try server connection, * if this fails, print error and return NULL */ verbose(2, "[GNETMakeEthInterface]:: trying to connect to %s..", vsock_name); if ((vcon = vpl_connect(vsock_name)) == NULL) { verbose(2, "[GNETMakeEthInterface]:: connecting as server.. "); // if client mode is forced.. fail here.. cannot do much! if (cforce) { verbose(1, "[GNETMakeEthInterface]:: unable to make network connection..."); return NULL; } // try making a server connection... // now that the client connection has failed if ((vcon = vpl_create_server(vsock_name)) == NULL) { verbose(1, "[GNETMakeEthInterface]:: unable to make server connection.. "); return NULL; } vi = (vplinfo_t *)malloc(sizeof(vplinfo_t)); iface->mode = IFACE_SERVER_MODE; vi->vdata = vcon; vi->iface = iface; thread_stat = pthread_create(&(iface->sdwthread), NULL, (void *)delayedServerCall, (void *)vi); if (thread_stat != 0) return NULL; // return for now.. the thread spawned above will change the // interface state when the remote node makes the connection. return iface; } verbose(2, "[GNETMakeEthInterface]:: VPL connection made as client "); // fill in the rest of the interface iface->iface_fd = vcon->data; iface->vpl_data = vcon; upThisInterface(iface); return iface; } }
std::shared_ptr<Detail::CycleGuard> createCycleGuard() const { return findInterface().createCycleGuard(); }