这篇教程C++ HTONS函数代码示例写得很实用,希望能帮到您。
本文整理汇总了C++中HTONS函数的典型用法代码示例。如果您正苦于以下问题:C++ HTONS函数的具体用法?C++ HTONS怎么用?C++ HTONS使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。 在下文中一共展示了HTONS函数的29个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。 示例1: uip_arp_arpin/*-----------------------------------------------------------------------------------*/voiduip_arp_arpin(void){ if(uip_len < sizeof(struct arp_hdr)) { uip_len = 0; return; } uip_len = 0; switch(BUF->opcode) { case HTONS(ARP_HINT): /* Please note this is not a valid ARP type, this is just a * hint to implement prefetch/refresh of ARP mapping */ /* This is a valid hint if we are the source of this request, * the requested ipaddr is in dipaddress */ if(uip_ipaddr_cmp(BUF->sipaddr, uip_hostaddr)) { /* We first try to check for the destination address * in our ARP table */ if(uip_arp_update(BUF->dipaddr, &broadcast_ethaddr)) { /* If the destination address was not in our ARP table, * we send out an ARP request for the same */ memset(BUF->ethhdr.dest.addr, 0xff, 6); BUF->opcode = HTONS(ARP_REQUEST); /* The other ARP fields of incoming hint are * supposed to be same as ARP broadcast except * the opcode field */ uip_len = sizeof(struct arp_hdr); } } break; case HTONS(ARP_REQUEST): /* ARP request. If it asked for our address, we send out a reply. */ if(uip_ipaddr_cmp(BUF->dipaddr, uip_hostaddr)) { /* First, we register the one who made the request in our ARP table, since it is likely that we will do more communication with this host in the future. */ uip_arp_update(BUF->sipaddr, &BUF->shwaddr); BUF->opcode = HTONS(ARP_REPLY); memcpy(BUF->dhwaddr.addr, BUF->shwaddr.addr, 6); memcpy(BUF->shwaddr.addr, uip_ethaddr.addr, 6); memcpy(BUF->ethhdr.src.addr, uip_ethaddr.addr, 6); memcpy(BUF->ethhdr.dest.addr, BUF->dhwaddr.addr, 6); BUF->dipaddr[0] = BUF->sipaddr[0]; BUF->dipaddr[1] = BUF->sipaddr[1]; BUF->sipaddr[0] = uip_hostaddr[0]; BUF->sipaddr[1] = uip_hostaddr[1]; BUF->ethhdr.type = HTONS(UIP_ETHTYPE_ARP); uip_len = sizeof(struct arp_hdr); } break; case HTONS(ARP_REPLY): /* ARP reply. We insert or update the ARP table if it was meant for us. */ if(uip_ipaddr_cmp(BUF->dipaddr, uip_hostaddr)) { uip_arp_update(BUF->sipaddr, &BUF->shwaddr); vmm_completion_complete(&uip_arp_prefetch_done); } break; } return;}
开发者ID:jhludwig,项目名称:xvisor,代码行数:71,
示例2: httpd_appcall// called for http server appvoid httpd_appcall(void){ struct fs_file fsfile; unsigned int i; switch(uip_conn->lport){ case HTONS(80): // app state hs = (struct httpd_state *)(uip_conn->appstate); // closed connection if(uip_closed()){ httpd_state_reset(); uip_close(); return; } // aborted connection or time out occured if(uip_aborted() || uip_timedout()){ httpd_state_reset(); uip_abort(); return; } // if we are pooled if(uip_poll()){ if(hs->count++ >= 100){ httpd_state_reset(); uip_abort(); } return; } // new connection if(uip_connected()){ httpd_state_reset(); return; } // new data in STATE_NONE if(uip_newdata() && hs->state == STATE_NONE){ // GET or POST request? if(uip_appdata[0] == ISO_G && uip_appdata[1] == ISO_E && uip_appdata[2] == ISO_T && (uip_appdata[3] == ISO_space || uip_appdata[3] == ISO_tab)){ hs->state = STATE_FILE_REQUEST; } else if(uip_appdata[0] == ISO_P && uip_appdata[1] == ISO_O && uip_appdata[2] == ISO_S && uip_appdata[3] == ISO_T && (uip_appdata[4] == ISO_space || uip_appdata[4] == ISO_tab)){ hs->state = STATE_UPLOAD_REQUEST; } // anything else -> abort the connection! if(hs->state == STATE_NONE){ httpd_state_reset(); uip_abort(); return; } // get file or firmware upload? if(hs->state == STATE_FILE_REQUEST){ // we are looking for GET file name for(i = 4; i < 30; i++){ if(uip_appdata[i] == ISO_space || uip_appdata[i] == ISO_cr || uip_appdata[i] == ISO_nl || uip_appdata[i] == ISO_tab){ uip_appdata[i] = 0; i = 0; break; } } if(i != 0){ printf("## Error: request file name too long!/n"); httpd_state_reset(); uip_abort(); return; } printf("Request for: "); printf("%s/n", &uip_appdata[4]); // request for / if(uip_appdata[4] == ISO_slash && uip_appdata[5] == 0){ fs_open(file_index_html.name, &fsfile); } else { // check if we have requested file if(!fs_open((const char *)&uip_appdata[4], &fsfile)){ printf("## Error: file not found!/n"); fs_open(file_404_html.name, &fsfile); } } hs->state = STATE_FILE_REQUEST; hs->dataptr = (u8_t *)fsfile.data; hs->upload = fsfile.len; // send first (and maybe the last) chunk of data uip_send(hs->dataptr, (hs->upload > uip_mss() ? uip_mss() : hs->upload)); return; } else if(hs->state == STATE_UPLOAD_REQUEST){//.........这里部分代码省略.........
开发者ID:alemv,项目名称:u-boot,代码行数:101,
示例3: vServoTask// Task for reactivision output processingvoid vServoTask( void){ u16_t ripaddr[2]; portBASE_TYPE xStatus; xTuioQueuePacket xValueRead; xTuioQueuePacket xDistanceValue[6]; // Tracking Variables short sPosX = 0; short sPosY = 0; short sDegreesX = servoMIN_DEGREES; short sDegreesY = (servoMIN_DEGREES+servoMAX_DEGREES)/4; vServo_ConfigurePwm(sDegreesX, sDegreesY); sX = 0; sY = 0; sZ = 0; // Uip connect vTaskDelay(1000); uip_ipaddr(ripaddr, 192,168,0,1); uip_connect(ripaddr, HTONS(3000)); xTuioQueue = xQueueCreate(20, sizeof(xTuioQueuePacket)); vSemaphoreCreateBinary(xControlServo); short sFlightPlanStage = servotaskFLIGHT_PLAN_1; short sGoalPoint; short sGoalCounter; // Servo control loop for (;;) { //Read from TUIO queue. xStatus = xQueueReceive(xTuioQueue, &xValueRead, 10); // Block task for 10ms when waiting for the Queue if (xStatus == pdPASS) { // Process received value // values are between 0 and 1 sPosX = (short) (xValueRead.position_x*100.0f); sPosY = (short) (xValueRead.position_y*100.0f); short sId = xValueRead.class_id-servoFIDUCIAL_SET; // If the middle fiducial marker, track it with the camera if (sId >= 0 && sId <= 5) { // Remember, position is taken from TOP LEFT if (sPosX < servoBOUNDING_BOX_MIN && sDegreesX < servoMAX_DEGREES) { sDegreesX++; } else if (sPosX > servoBOUNDING_BOX_MAX && sDegreesX > servoMIN_DEGREES) { sDegreesX--; } if (sPosY < servoBOUNDING_BOX_MIN && sDegreesY < servoMAX_DEGREES) { sDegreesY++; } else if (sPosY > servoBOUNDING_BOX_MAX && sDegreesY > servoMIN_DEGREES) { sDegreesY--; } // Set the fiducial to being used, and the value to the current packet sDistanceUsed[sId] = 1; xDistanceValue[sId] = xValueRead; // If there is an ID to compare to, calculate distance if (sGetId(sId) != -1 && sTask5) { short sNextId = sGetId(sId); // Print markers used for distancing //debug_printf("markers: %d %d/r/n", xValueRead.class_id, xDistanceValue[sNextId].class_id); // Compute the distance to the fiducial double dD = sApproxSqrt(sPow(sPosX-(short) (xDistanceValue[sNextId].position_x*100.0f),2) + sPow(sPosY-(short) (xDistanceValue[sNextId].position_y*100.0f),2)); dD = (33379*sPow((short) dD,2) - 2288800*dD + 44475000)/10000; //debug_printf(">> Distance: %d/r/n", (short) dD); // Calculate the XYZ coordinates. double dDegX = sDegreesX - servoMIN_DEGREES - (servoMIN_DEGREES+servoMAX_DEGREES)/2; double dDegY = sDegreesY - servoMIN_DEGREES; sX = (short) (dD*(sin((double) (dDegX/180.0f*3.14f)))); sY = (short) (dD*(sin((double) (dDegY/180.0f*3.14f)))); sZ = (short) (dD*(cos((double) (dDegX/180.0f*3.14f)))); //debug_printf(">> Angles: %d %d/r/n", (short) dDegX, (short) dDegY); //debug_printf(">> Point: %d %d %d/r/n", sX, sY, sZ); // On detecting the blimp, set the goal to 1.5m in X and flight plan to 2 if (sId < 3 && sFlightPlanStage == servotaskFLIGHT_PLAN_1) { sGoalPoint = sX + 1500; sGoalCounter = 0; sFlightPlanStage = servotaskFLIGHT_PLAN_2; debug_printf("Starting stage 2/t/t/ Goal: %d/r/n", sGoalPoint);//.........这里部分代码省略.........
开发者ID:merrickheley,项目名称:CSSE3010,代码行数:101,
示例4: PxeBcExtractDiscoverInfo/** Extract the discover information and boot server entry from the cached packets if unspecified. @param[in] Private Pointer to PxeBc private data. @param[in] Type The type of bootstrap to perform. @param[in, out] DiscoverInfo Pointer to EFI_PXE_BASE_CODE_DISCOVER_INFO. @param[out] BootEntry Pointer to PXEBC_BOOT_SVR_ENTRY. @param[out] SrvList Pointer to EFI_PXE_BASE_CODE_SRVLIST. @retval EFI_SUCCESS Successfully extracted the information. @retval EFI_DEVICE_ERROR Failed to extract the information.**/EFI_STATUSPxeBcExtractDiscoverInfo ( IN PXEBC_PRIVATE_DATA *Private, IN UINT16 Type, IN OUT EFI_PXE_BASE_CODE_DISCOVER_INFO **DiscoverInfo, OUT PXEBC_BOOT_SVR_ENTRY **BootEntry, OUT EFI_PXE_BASE_CODE_SRVLIST **SrvList ){ EFI_PXE_BASE_CODE_MODE *Mode; PXEBC_DHCP4_PACKET_CACHE *Cache4; PXEBC_VENDOR_OPTION *VendorOpt; PXEBC_BOOT_SVR_ENTRY *Entry; BOOLEAN IsFound; EFI_PXE_BASE_CODE_DISCOVER_INFO *Info; UINT16 Index; Mode = Private->PxeBc.Mode; Info = *DiscoverInfo; if (Mode->UsingIpv6) { Info->IpCnt = 1; Info->UseUCast = TRUE; Info->SrvList[0].Type = Type; Info->SrvList[0].AcceptAnyResponse = FALSE; // // There is no vendor options specified in DHCPv6, so take BootFileUrl in the last cached packet. // CopyMem (&Info->SrvList[0].IpAddr, &Private->ServerIp, sizeof (EFI_IP_ADDRESS)); *SrvList = Info->SrvList; } else { Entry = NULL; IsFound = FALSE; Cache4 = (Mode->ProxyOfferReceived) ? &Private->ProxyOffer.Dhcp4 : &Private->DhcpAck.Dhcp4; VendorOpt = &Cache4->VendorOpt; if (!Mode->DhcpAckReceived || !IS_VALID_DISCOVER_VENDOR_OPTION (VendorOpt->BitMap)) { // // Address is not acquired or no discovery options. // return EFI_INVALID_PARAMETER; } // // Parse the boot server entry from the vendor option in the last cached packet. // Info->UseMCast = (BOOLEAN) !IS_DISABLE_MCAST_DISCOVER (VendorOpt->DiscoverCtrl); Info->UseBCast = (BOOLEAN) !IS_DISABLE_BCAST_DISCOVER (VendorOpt->DiscoverCtrl); Info->MustUseList = (BOOLEAN) IS_ENABLE_USE_SERVER_LIST (VendorOpt->DiscoverCtrl); Info->UseUCast = (BOOLEAN) IS_VALID_BOOT_SERVERS (VendorOpt->BitMap); if (Info->UseMCast) { // // Get the multicast discover ip address from vendor option if has. // CopyMem (&Info->ServerMCastIp.v4, &VendorOpt->DiscoverMcastIp, sizeof (EFI_IPv4_ADDRESS)); } Info->IpCnt = 0; if (Info->UseUCast) { Entry = VendorOpt->BootSvr; while (((UINT8) (Entry - VendorOpt->BootSvr)) < VendorOpt->BootSvrLen) { if (Entry->Type == HTONS (Type)) { IsFound = TRUE; break; } Entry = GET_NEXT_BOOT_SVR_ENTRY (Entry); } if (!IsFound) { return EFI_DEVICE_ERROR; } Info->IpCnt = Entry->IpCnt; if (Info->IpCnt >= 1) { *DiscoverInfo = AllocatePool (sizeof (*Info) + (Info->IpCnt - 1) * sizeof (**SrvList)); if (*DiscoverInfo == NULL) { return EFI_OUT_OF_RESOURCES; } CopyMem (*DiscoverInfo, Info, sizeof (*Info)); Info = *DiscoverInfo;//.........这里部分代码省略.........
开发者ID:B-Rich,项目名称:edk2,代码行数:101,
示例5: udp_config_handle_packet |