int packEthDes(PacketEth packSnd, char *trans, char *recv, unsigned short proto, unsigned char buf[ETH_FRAME_LEN-ETH_HLEN], int size) { printf("pack size: %d\n\theader: %d\n\tbody: %d\n", size, ETH_HLEN, size-ETH_HLEN); memset(&packSnd, 0, ETH_FRAME_LEN);//zero out union int i = ETH_HLEN; while(i<size) {//fill out payload (buf) packSnd.buf[i] = buf[i-ETH_HLEN]; i++; } printf("trans: "); getMac(trans, packSnd.macs.h_source); printf("recv: "); getMac(recv, packSnd.macs.h_dest);//fill mac field packSnd.macs.h_proto = proto; printf("proto: %04x\n", htons(packSnd.macs.h_proto)); printf("packet:\n\t"); i = 0; int k = 0;//print buffer while(i<size) { printf("%02X ", packSnd.buf[i]); if(i == ETH_HLEN-1 || k == LINLEN) { printf("\n\t"); k = 0;//break after header } i++; k++; }printf("\n"); return 0; }
mir::EventUPtr mia::Lexicon::translate(droidinput::InputEvent const* android_event) { switch(android_event->getType()) { case AINPUT_EVENT_TYPE_KEY: { auto kev = static_cast<const droidinput::KeyEvent*>(android_event); return mev::make_event(MirInputDeviceId(android_event->getDeviceId()), kev->getEventTime(), kev->getMac(), mia::mir_keyboard_action_from_android(kev->getAction(), kev->getRepeatCount()), kev->getKeyCode(), kev->getScanCode(), mia::mir_modifiers_from_android(kev->getMetaState())); } case AINPUT_EVENT_TYPE_MOTION: { if (mia::android_source_id_is_pointer_device(android_event->getSource())) { auto mev = static_cast<const droidinput::MotionEvent*>(android_event); return mev::make_event(MirInputDeviceId(android_event->getDeviceId()), mev->getEventTime(), mev->getMac(), mia::mir_modifiers_from_android(mev->getMetaState()), mia::mir_pointer_action_from_masked_android(mev->getAction() & AMOTION_EVENT_ACTION_MASK), mia::mir_pointer_buttons_from_android(mev->getButtonState()), mev->getX(0), mev->getY(0), mev->getRawAxisValue(AMOTION_EVENT_AXIS_HSCROLL, 0), mev->getRawAxisValue(AMOTION_EVENT_AXIS_VSCROLL, 0), mev->getRawAxisValue(AMOTION_EVENT_AXIS_RX, 0), mev->getRawAxisValue(AMOTION_EVENT_AXIS_RY, 0)); } else { auto mev = static_cast<const droidinput::MotionEvent*>(android_event); auto ev = mev::make_event(MirInputDeviceId(android_event->getDeviceId()), mev->getEventTime(), mev->getMac(), mia::mir_modifiers_from_android(mev->getMetaState())); auto action = mev->getAction(); size_t index_with_action = (action & AMOTION_EVENT_ACTION_POINTER_INDEX_MASK) >> AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT; auto masked_action = action & AMOTION_EVENT_ACTION_MASK; for (unsigned i = 0; i < mev->getPointerCount(); i++) { auto action = (i == index_with_action) ? mia::mir_touch_action_from_masked_android(masked_action) : mir_touch_action_change; mev::add_touch(*ev, mev->getPointerId(i), action, mia::mir_tool_type_from_android(mev->getToolType(i)), mev->getX(i), mev->getY(i), mev->getPressure(i), mev->getTouchMajor(i), mev->getTouchMinor(i), mev->getSize(i)); } return ev; } } default: BOOST_THROW_EXCEPTION(std::logic_error("Invalid android event")); } }
int main() { quickstartMode = (strcmp(org, "quickstart") == 0); lcd.set_font((unsigned char*) Arial12x12); // Set a nice font for the LCD screen led2 = LED2_OFF; // K64F: turn off the main board LED displayMessage("Connecting"); Thread yellow_thread(flashing_yellow); Thread menu_thread(menu_loop); LOG("***** IBM IoT Client Ethernet Example *****\n"); MQTTEthernet ipstack; ethernetInitialising = false; MQTT::Client<MQTTEthernet, Countdown, MQTT_MAX_PACKET_SIZE> client(ipstack); LOG("Ethernet Initialized\n"); if (quickstartMode) getMac(ipstack.getEth(), id, sizeof(id)); attemptConnect(&client, &ipstack); if (connack_rc == MQTT_NOT_AUTHORIZED || connack_rc == MQTT_BAD_USERNAME_OR_PASSWORD) { red(); while (true) wait(1.0); // Permanent failures - don't retry } if (!quickstartMode) { int rc = 0; if ((rc = client.subscribe("iot-2/cmd/+/fmt/json", MQTT::QOS1, messageArrived)) != 0) WARN("rc from MQTT subscribe is %d\n", rc); } blink_interval = 0; int count = 0; while (true) { if (++count == 100) { // Publish a message every second if (publish(&client, &ipstack) != 0) attemptConnect(&client, &ipstack); // if we have lost the connection count = 0; } if (blink_interval == 0) led2 = LED2_OFF; else if (count % blink_interval == 0) led2 = !led2; client.yield(10); // allow the MQTT client to receive messages } }
void WhisperMessage::verifyMac(int messageVersion, const IdentityKey &senderIdentityKey, const IdentityKey &receiverIdentityKey, const QByteArray &macKey) const { QList<QByteArray> parts = ByteUtil::split(serialized, serialized.size() - MAC_LENGTH, MAC_LENGTH); QByteArray ourMac = getMac(messageVersion, senderIdentityKey, receiverIdentityKey, macKey, parts[0]); QByteArray theirMac = parts[1]; if (ourMac != theirMac) { throw InvalidMessageException("Bad Mac!"); } }
// Return true if we successfully sent an ARP request, false otherwise bool IPv4Handler::resolveMac(SwitchState* state, IPAddressV4 dest) { // need to find out our own IP and MAC addresses so that we can send the // ARP request out. Since the request will be broadcast, there is no need to // worry about which port to send the packet out. // TODO: assume vrf 0 now auto routeTable = state->getRouteTables()->getRouteTableIf(RouterID(0)); if (!routeTable) { throw FbossError("No routing tables found"); } auto route = routeTable->getRibV4()->longestMatch(dest); if (!route || !route->isResolved()) { // No way to reach dest return false; } auto intfs = state->getInterfaces(); auto nhs = route->getForwardInfo().getNexthops(); for (auto nh : nhs) { auto intf = intfs->getInterfaceIf(nh.intf); if (intf) { auto source = intf->getAddressToReach(nh.nexthop)->first.asV4(); auto target = route->isConnected() ? dest : nh.nexthop.asV4(); if (source == target) { // This packet is for us. Don't send ARP requess for our own IP. continue; } auto vlanID = intf->getVlanID(); auto vlan = state->getVlans()->getVlanIf(vlanID); if (vlan) { auto entry = vlan->getArpTable()->getEntryIf(target); if (entry == nullptr) { // No entry in ARP table, send ARP request auto mac = intf->getMac(); ArpHandler::sendArpRequest(sw_, vlanID, mac, source, target); // Notify the updater that we sent an arp request sw_->getNeighborUpdater()->sentArpRequest(vlanID, target); } else { VLOG(4) << "not sending arp for " << target.str() << ", " << ((entry->isPending()) ? "pending " : "") << "entry already exists"; } } } } return true; }
cSqueezeConfig::cSqueezeConfig() { logLevel = 1; lmcHost = strdup("localhost"); lmcPort = 9090; lmcHttpPort = 9000; squeezeCmd = strdup("/usr/local/bin/squeezelite"); playerName = strdup("VDR-squeeze"); audioDevice = strdup(""); alsaOptions = strdup(""); shadeTime = 0; shadeLevel = 40; // in % mac = getMac(); }
int socDes(struct sockaddr_ll sock, char *interface, int mysoc) { iface idx; memset(&idx, 0, sizeof(iface)); memset(&sock, 0, sizeof(struct sockaddr_ll)); strncpy(idx.ifr_name, interface, IFNAMSIZ-1); ioctl(mysoc, SIOCGIFINDEX, &idx); sock.sll_family = AF_PACKET; printf("family: int-%d hex-%X\n", AF_PACKET, AF_PACKET); sock.sll_ifindex = idx.ifr_ifindex; printf("ifndex: int-%d hex-%X\n", idx.ifr_ifindex, idx.ifr_ifindex); sock.sll_protocol = htons(ETH_P_ALL); printf("protocol: int-%d hex-%X\n", htons(ETH_P_ALL), htons(ETH_P_ALL));//defaults to socket protocol sock.sll_halen = ETH_ALEN; printf("halen: int-%d hex-%X\n", sock.sll_halen, sock.sll_halen); getMac(interface, sock.sll_addr);//sll_addr and sl_halen return 0; }
int main(int argc, char *argv[]) { struct sockaddr_ll device; char NetInterface[10]; strcpy(NetInterface, argv[1]); int index = if_nametoindex ((const char*)NetInterface); printf("index is %d\n", index); //get MAC, 要设置初始值 char MAC[18]={0}; char end[] = "0"; getMac(MAC, argv[1]); printf("%s\n", MAC); unsigned char ip[4]; getIp(ip, argv[1]); printf("\n"); return 0; }
WhisperMessage::WhisperMessage(int messageVersion, const QByteArray &macKey, const DjbECPublicKey &senderRatchetKey, uint counter, uint previousCounter, const QByteArray &ciphertext, const IdentityKey &senderIdentityKey, const IdentityKey &receiverIdentityKey) { textsecure::WhisperMessage whisperMessage; QByteArray ratchetKey = senderRatchetKey.serialize(); whisperMessage.set_ratchetkey(ratchetKey.constData(), ratchetKey.size()); whisperMessage.set_counter(counter); whisperMessage.set_previouscounter(previousCounter); whisperMessage.set_ciphertext(ciphertext.constData() ,ciphertext.size()); ::std::string serializedMessage = whisperMessage.SerializeAsString(); QByteArray message = QByteArray(serializedMessage.data(), serializedMessage.length()); message.prepend(ByteUtil::intsToByteHighAndLow(messageVersion, CURRENT_VERSION)); QByteArray mac = getMac(messageVersion, senderIdentityKey, receiverIdentityKey, macKey, message); this->serialized = message; this->serialized.append(mac); this->senderRatchetKey = senderRatchetKey; this->counter = counter; this->previousCounter = previousCounter; this->ciphertext = ciphertext; this->messageVersion = messageVersion; }
bool WifiNetwork::ssidFilter(){ if ( ( ssid.count(QRegExp("[a-fA-F0-9]{6}")) == 1) && ( ssid.startsWith("Thomson") || ssid.startsWith("SpeedTouch") || ssid.startsWith("O2Wireless") || ssid.startsWith("Orange-") || ssid.startsWith("INFINITUM") || ssid.startsWith("BigPond") || ssid.startsWith("Otenet") || ssid.startsWith("Bbox-") || ssid.startsWith("DMAX") || ssid.startsWith("privat") || ssid.startsWith("TN_private_") || ssid.startsWith("Cyta") ) ) { ssidSubpart = ssid.right(6); if ( !mac.isEmpty() ) if ( ssidSubpart == getMac().right(6) ) newThomson = true; type = THOMSON; return true; } if ( ( ssid.count(QRegExp("DLink-[a-fA-F0-9]{6}")) == 1) && ( ssid.size() == 12 ) ) { ssidSubpart = ssid.right(6); type = DLINK; return true; } if ( ssid.count(QRegExp("Discus--?[0-9a-fA-F]{6}")) == 1) { ssidSubpart = ssid.right(6); type = DISCUS; return true; } if ( (ssid.count(QRegExp("eircom[0-7]{4} [0-7]{4}")) == 1 )|| (ssid.count(QRegExp("eircom[0-7]{8}")) == 1)) { if ( ssid.size() == 14 ) ssidSubpart = ssid.right(8); else ssidSubpart = ssid.mid(6,4) + ssid.right(4); if ( mac.isEmpty() ) calcEircomMAC(); type = EIRCOM; return true; } if ( ssid.size() == 5 && ( mac.startsWith("00:1F:90") || mac.startsWith("A8:39:44") || mac.startsWith("00:18:01") || mac.startsWith("00:20:E0") || mac.startsWith("00:0F:B3") || mac.startsWith("00:1E:A7") || mac.startsWith("00:15:05") || mac.startsWith("00:24:7B") || mac.startsWith("00:26:62") || mac.startsWith("00:26:B8") ) ) { ssidSubpart = ssid; type = VERIZON; return true; } if ( ssid.count(QRegExp("TECOM-AH4021-[0-9a-zA-Z]{6}|TECOM-AH4222-[0-9a-zA-Z]{6}")) == 1 ) { ssidSubpart = ssid; type = TECOM; return true; } if ( ( ssid.count(QRegExp("SKY[0-9]{5}"))==1) && (mac.startsWith("C4:3D:C7") || mac.startsWith("E0:46:9A") || mac.startsWith("E0:91:F5") || mac.startsWith("00:09:5B") || mac.startsWith("00:0F:B5") || mac.startsWith("00:14:6C") || mac.startsWith("00:18:4D") || mac.startsWith("00:26:F2") || mac.startsWith("C0:3F:0E") || mac.startsWith("30:46:9A") || mac.startsWith("00:1B:2F") || mac.startsWith("A0:21:B7") || mac.startsWith("00:1E:2A") || mac.startsWith("00:1F:33") || mac.startsWith("00:22:3F") || mac.startsWith("00:24:B2") ) ) { ssidSubpart = ssid.right(5); type = SKY_V1; return true; } if ( ssid.count(QRegExp("InfostradaWiFi-[0-9a-zA-Z]{6}")) == 1 ) { ssidSubpart = ssid; type = INFOSTRADA; return true; } if ( ssid.startsWith("WLAN_") && ssid.length() == 7 && ( mac.startsWith("00:01:38") || mac.startsWith("00:16:38") || mac.startsWith("00:01:13") || mac.startsWith("00:01:1B") || mac.startsWith("00:19:5B") ) ) { ssidSubpart = ssid.right(2); type = WLAN2; return true; } if ( ( ssid.count(QRegExp("WLAN_[0-9a-zA-Z]{4}|JAZZTEL_[0-9a-zA-Z]{4}")) == 1 ) && ( mac.startsWith("00:1F:A4") || mac.startsWith("64:68:0C") || mac.startsWith("00:1D:20") ) ) { ssidSubpart = ssid.right(4); type = WLAN4; return true; } if ( ssid.count(QRegExp("WLAN[0-9a-zA-Z]{6}|WiFi[0-9a-zA-Z]{6}|YaCom[0-9a-zA-Z]{6}")) == 1 ) { ssidSubpart = ssid.right(6); type = WLAN6; return true; } if ( ( ssid.toUpper().startsWith("FASTWEB-1-000827") && ssid.length() == 22 ) || ( ssid.toUpper().startsWith("FASTWEB-1-0013C8") && ssid.length() == 22 ) || ( ssid.toUpper().startsWith("FASTWEB-1-0017C2") && ssid.length() == 22 ) || ( ssid.toUpper().startsWith("FASTWEB-1-00193E") && ssid.length() == 22 ) || ( ssid.toUpper().startsWith("FASTWEB-1-001CA2") && ssid.length() == 22 ) || ( ssid.toUpper().startsWith("FASTWEB-1-001D8B") && ssid.length() == 22 ) || ( ssid.toUpper().startsWith("FASTWEB-1-002233") && ssid.length() == 22 ) || ( ssid.toUpper().startsWith("FASTWEB-1-00238E") && ssid.length() == 22 ) || ( ssid.toUpper().startsWith("FASTWEB-1-002553") && ssid.length() == 22 ) || ( ssid.toUpper().startsWith("FASTWEB-1-00A02F") && ssid.length() == 22 ) || ( ssid.toUpper().startsWith("FASTWEB-1-080018") && ssid.length() == 22 ) || ( ssid.toUpper().startsWith("FASTWEB-1-3039F2") && ssid.length() == 22 ) || ( ssid.toUpper().startsWith("FASTWEB-1-38229D") && ssid.length() == 22 ) || ( ssid.toUpper().startsWith("FASTWEB-1-6487D7") && ssid.length() == 22 )) { ssidSubpart = ssid.right(12); if ( mac == "" ) calcFastwebMAC(); type = PIRELLI; return true; } if ( ssid.count(QRegExp("FASTWEB-[1-2]-002196[0-9a-fA-F]{6}|FASTWEB-[1-2]-00036F[0-9a-fA-F]{6}")) == 1 ) { ssidSubpart = ssid.right(12); if ( mac == "" ) calcFastwebMAC(); type = TELSEY; return true; } /*ssid must be of the form P1XXXXXX0000X or p1XXXXXX0000X*/ if ( ssid.count(QRegExp("[Pp]1[0-9]{6}0{4}[0-9]")) == 1 ) { ssidSubpart = ""; type = ONO_WEP; return true; } if ( ( ssid.count(QRegExp("INFINITUM[0-9a-zA-Z]{4}")) == 1 ) && ( mac.startsWith("00:25:9E") || mac.startsWith("00:25:68") || mac.startsWith("00:22:A1") || mac.startsWith("00:1E:10") || mac.startsWith("00:18:82") || mac.startsWith("00:0F:F2") || mac.startsWith("00:E0:FC") || mac.startsWith("28:6E:D4") || mac.startsWith("54:A5:1B") || mac.startsWith("F4:C7:14") || mac.startsWith("28:5F:DB") || mac.startsWith("30:87:30") || mac.startsWith("4C:54:99") || mac.startsWith("40:4D:8E") || mac.startsWith("64:16:F0") || mac.startsWith("78:1D:BA") || mac.startsWith("84:A8:E4") || mac.startsWith("04:C0:6F") || mac.startsWith("5C:4C:A9") || mac.startsWith("1C:1D:67") || mac.startsWith("CC:96:A0") || mac.startsWith("20:2B:C1") ) ) { if ( ssid.startsWith("INFINITUM") ) ssidSubpart = ssid.right(4); else ssidSubpart = ""; type = HUAWEI; return true; } if ( ssid.count(QRegExp("[aA]lice-[0-9]{8}")) == 1 ) { AliceHandler aliceReader(ssid.left(9)); aliceReader.readFile(":/alice/alice.xml"); ssidSubpart = ssid.right(8); type = ALICE; if( !aliceReader.isSupported() ) return false; supportedAlice = aliceReader.getSupportedAlice(); if ( getMac().size() < 6 ) mac = supportedAlice.at(0)->mac; return true; } return false; }
LUALIB_API int isLic() { int flag=0; int key[6]={1,0,1,0,0,0}; FILE *in = fopen("control/li.lic","r"); char buf[1024]; if(in==NULL) { printf("can not open 1.lic"); flag=0; } else { fgets(buf,1024,in); fclose(in); printf("buf:%s\n",buf); unsigned int resultSize=0; char *buf2=base64Decode(buf,resultSize,true); printf("base64Decode buf2:%s\n",buf2); for(int i=0;i<strlen(buf2);i++) { buf2[i]=buf2[i]^key[i%6]; } printf("buf2^:%s\n",buf2); char type=buf2[0]; printf("type:%c\n",type); char* yearc = new char[11]; char* macc = new char[strlen(buf2)-11]; for(int i=0;i<10;i++) { yearc[i]=buf2[i+1]; } yearc[10]='\0'; for(int i=0;i<strlen(buf2)-11;i++) { macc[i]=buf2[i+11]; } if(type=='0'||type=='3') { flag=2; printf("yearc:%s\n",yearc); int nYear, nMonth, nDay; sscanf_s(yearc, "%d-%d-%d", &nYear, &nMonth, &nDay); nMonth=nMonth-1; nYear=nYear-1900; printf("year:%d,month:%d,day:%d\n",nYear,nMonth,nDay); time_t t = time(0); tm *t1=localtime(&t); printf("tyear:%d,tmonth:%d,tday:%d\n",t1->tm_year,t1->tm_mon,t1->tm_mday); int year =t1->tm_year; if(year<nYear) { flag=1; } else if(year==nYear) { if(t1->tm_mon<nMonth) { flag=1; } else if(t1->tm_mon==nMonth) { if(t1->tm_mday<=nDay) { flag=1; } } } } if(type=='1'||type=='3') { flag=3; printf("macc:%s\n",macc); char* mac=getMac(); printf("mac:%s\n",mac); if(strstr(macc,mac)!=NULL) { flag=1; } } } printf("flag:%d\n",flag); return flag; }
/*****************main func****************/ int main(int argc, char **argv) { char cmdline[16], cmd[16]; char *p; LOGE("This is chengyake's test program...\n"); while(1) { LOGE("\n>>"); memset(&cmdline, 0, sizeof(cmdline)); memset(&cmd, 0, sizeof(cmd)); gets(&cmdline[0]); p=NULL; p = strtok(cmdline, " "); if (p) sprintf(&cmd[0], "%s", p); if(!strcmp(&cmd[0], "open")) { open_ble(); } else if (!strcmp(&cmd[0], "reset")) { reset_ble(); } else if (!strcmp(&cmd[0], "enAccel")) { enAccel(); } else if (!strcmp(&cmd[0], "disAccel")) { disAccel(); } else if (!strcmp(&cmd[0], "enEcomp")) { enEcomp(); } else if (!strcmp(&cmd[0], "disEcomp")) { disEcomp(); } else if (!strcmp(&cmd[0], "enDetect")) { enDetect(); } else if (!strcmp(&cmd[0], "disDetect")) { disDetect(); } else if (!strcmp(&cmd[0], "enStore")) { enStore(); } else if (!strcmp(&cmd[0], "disStore")) { disStore(); } else if (!strcmp(&cmd[0], "setTime")) { setTime(); } else if (!strcmp(&cmd[0], "update")) { update_ble(); } else if (!strcmp(&cmd[0], "getMac")) { getMac(); } else if (!strcmp(&cmd[0], "exit")) { LOGE("chengyake cmd: exit\n"); break; } else { LOGE("----------------------------------------\n"); LOGE("cmd\topen\n"); LOGE("cmd\treset\n"); LOGE("cmd\tenAccel\n"); LOGE("cmd\tdisAccel\n"); LOGE("cmd\tenEcomp\n"); LOGE("cmd\tdisEcomp\n"); LOGE("cmd\tenDetect\n"); LOGE("cmd\tdisDetect\n"); LOGE("cmd\tenStore\n"); LOGE("cmd\tdisStore\n"); LOGE("cmd\tsetTime\n"); LOGE("cmd\tupdate\n"); LOGE("cmd\tgetMac\n"); LOGE("cmd\texit\n"); LOGE("----------------------------------------\n"); } } LOGE("chengyake end\n"); close(fd); return 0; }