这篇教程C++ udp_bind函数代码示例写得很实用,希望能帮到您。
本文整理汇总了C++中udp_bind函数的典型用法代码示例。如果您正苦于以下问题:C++ udp_bind函数的具体用法?C++ udp_bind怎么用?C++ udp_bind使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。 在下文中一共展示了udp_bind函数的30个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。 示例1: dhcpc_init/*---------------------------------------------------------------------------*/voiddhcpc_init(const void *mac_addr, int mac_len){ uip_ipaddr_t addr; s.mac_addr = mac_addr; s.mac_len = mac_len; s.state = STATE_INITIAL; uip_ipaddr(&addr, 255,255,255,255); s.conn = udp_new(&addr, UIP_HTONS(DHCPC_SERVER_PORT), NULL); if(s.conn != NULL) { udp_bind(s.conn, UIP_HTONS(DHCPC_CLIENT_PORT)); } PT_INIT(&s.pt);}
开发者ID:aiss83,项目名称:nucbit,代码行数:18,
示例2: PROCESS_THREAD PROCESS_THREAD(raven_relay_process, ev, data) { uip_ipaddr_t ipaddr; PROCESS_POLLHANDLER(pollhandler()); PROCESS_EXITHANDLER(exithandler()); // see: http://senstools.gforge.inria.fr/doku.php?id=contiki:examples PROCESS_BEGIN(); PRINTF("Relay process startup./r/n"); // wait 3 second, in order to have the IP addresses well configured etimer_set(&udp_periodic_timer, CLOCK_CONF_SECOND*3); // wait until the timer has expired PROCESS_WAIT_EVENT_UNTIL(ev == PROCESS_EVENT_TIMER); // Define Address of the server that receives our heartbeats. // TODO: Make this dynamic#ifdef UDP_ADDR_A uip_ip6addr(&ipaddr, UDP_ADDR_A,UDP_ADDR_B,UDP_ADDR_C,UDP_ADDR_D, UDP_ADDR_E,UDP_ADDR_F,UDP_ADDR_G,UDP_ADDR_H);#else /* UDP_ADDR_A */ uip_ip6addr(&ipaddr,0xbbbb,0,0,0,0xd69a,0x20ff,0xfe07,0x7664);#endif /* UDP_ADDR_A */ udpconn = udp_new(NULL, HTONS(0), NULL); //udpconn = udp_new(&ipaddr, HTONS(0xF0B0+1), NULL); udp_bind(udpconn, HTONS(0xF0B0)); // udp_attach(udpconn, NULL); PRINTF("Created connection with remote peer "); PRINT6ADDR(&udpconn->ripaddr); PRINTF("/r/nlocal/remote port %u/%u/r/n", HTONS(udpconn->lport),HTONS(udpconn->rport)); print_local_addresses(); etimer_set(&udp_periodic_timer, 60*CLOCK_SECOND); while(1){ PRINTF("--- Relay: Waiting for events./r/n"); // tcpip_poll_udp(udpconn); PROCESS_WAIT_EVENT(); // PROCESS_YIELD(); udphandler(ev, data); } PROCESS_END(); }
开发者ID:gonium,项目名称:octobus,代码行数:46,
示例3: PROCESS_THREADPROCESS_THREAD(udp_server_process, ev, data){ PROCESS_BEGIN(); PRINTF("UDP server started/n"); server_conn = udp_new(NULL, UIP_HTONS(3001), NULL); udp_bind(server_conn, UIP_HTONS(3000)); while(1) { PROCESS_YIELD(); if(ev == tcpip_event) { tcpip_handler(); } } PROCESS_END();}
开发者ID:denghongcai,项目名称:6lbr,代码行数:17,
示例4: PROCESS_THREAD/*---------------------------------------------------------------------------*/PROCESS_THREAD(viztool_process, ev, data){ PROCESS_BEGIN(); server_conn = udp_new(NULL, UIP_HTONS(0), NULL); udp_bind(server_conn, UIP_HTONS(VIZTOOL_UDP_PORT)); while(1) { PROCESS_YIELD(); if(ev == tcpip_event) { tcpip_handler(); } } PROCESS_END();}
开发者ID:GDanii,项目名称:contiki-mirror-MICAz-IPv6,代码行数:18,
示例5: PROCESS_THREAD/*---------------------------------------------------------------------------*/PROCESS_THREAD(udp_server_process, ev, data){#if (CONTIKI_TARGET_SENSINODE && BUTTON_SENSOR_ON) static struct sensors_sensor *b1; static struct sensors_sensor *b2;#endif PROCESS_BEGIN(); putstring("Starting UDP server/n");#if (CONTIKI_TARGET_SENSINODE && BUTTON_SENSOR_ON) putstring("Button 1: Print RIME stats/n"); putstring("Button 2: Reboot/n");#endif#if SERVER_RPL_ROOT create_dag();#endif server_conn = udp_new(NULL, UIP_HTONS(0), NULL); udp_bind(server_conn, UIP_HTONS(3000)); PRINTF("Listen port: 3000, TTL=%u/n", server_conn->ttl);#if (CONTIKI_TARGET_SENSINODE && BUTTON_SENSOR_ON) b1 = sensors_find(BUTTON_1_SENSOR); b2 = sensors_find(BUTTON_2_SENSOR);#endif while(1) { PROCESS_YIELD(); if(ev == tcpip_event) { tcpip_handler();#if (CONTIKI_TARGET_SENSINODE && BUTTON_SENSOR_ON) } else if(ev == sensors_event && data != NULL) { if(data == b1) { print_stats(); } else if(data == b2) { watchdog_reboot(); }#endif /* (CONTIKI_TARGET_SENSINODE && BUTTON_SENSOR_ON) */ } } PROCESS_END();}
开发者ID:jdurrant,项目名称:contiki-mirror,代码行数:47,
示例6: udp_broadcast_new/*---------------------------------------------------------------------------*/struct uip_udp_conn *udp_broadcast_new(uint16_t port, void *appstate){ uip_ipaddr_t addr; struct uip_udp_conn *conn;#if NETSTACK_CONF_WITH_IPV6 uip_create_linklocal_allnodes_mcast(&addr);#else uip_ipaddr(&addr, 255,255,255,255);#endif /* NETSTACK_CONF_WITH_IPV6 */ conn = udp_new(&addr, port, appstate); if(conn != NULL) { udp_bind(conn, port); } return conn;}
开发者ID:1847123212,项目名称:ampm_contiki_wisun,代码行数:18,
示例7: dhcp_select/** * Select a DHCP server offer out of all offers. * * Simply select the first offer received, ignore others */static err_t dhcp_select(struct dhcp_state *state){ err_t result; u32_t msecs; DEBUGF(DHCP_DEBUG, ("dhcp_select()/n")); // create and initialize the DHCP message header result = dhcp_create_request(state); if (result == ERR_OK) { dhcp_option(state, DHCP_OPTION_MESSAGE_TYPE, DHCP_OPTION_MESSAGE_TYPE_LEN); dhcp_option_byte(state, DHCP_REQUEST); dhcp_option(state, DHCP_OPTION_MAX_MSG_SIZE, DHCP_OPTION_MAX_MSG_SIZE_LEN); dhcp_option_short(state, 576); /* MUST request the offered IP address */ dhcp_option(state, DHCP_OPTION_REQUESTED_IP, 4); dhcp_option_long(state, ntohl(state->offered_ip_addr.addr)); dhcp_option(state, DHCP_OPTION_SERVER_ID, 4); dhcp_option_long(state, ntohl(state->server_ip_addr.addr)); dhcp_option(state, DHCP_OPTION_PARAMETER_REQUEST_LIST, 3); dhcp_option_byte(state, DHCP_OPTION_SUBNET_MASK); dhcp_option_byte(state, DHCP_OPTION_ROUTER); dhcp_option_byte(state, DHCP_OPTION_BROADCAST); dhcp_option_trailer(state); pbuf_realloc(state->p_out, sizeof(struct dhcp_msg) - DHCP_OPTIONS_LEN + state->options_out_len); udp_bind(state->pcb, IP_ADDR_ANY, DHCP_CLIENT_PORT); udp_connect(state->pcb, IP_ADDR_BROADCAST, DHCP_SERVER_PORT); udp_send(state->pcb, state->p_out); // reconnect to any (or to server here?!) udp_connect(state->pcb, IP_ADDR_ANY, DHCP_SERVER_PORT); dhcp_delete_request(state); } state->tries++; msecs = state->tries < 4 ? state->tries * 1000 : 4 * 1000; state->request_timeout = (msecs + DHCP_FINE_TIMER_MSECS - 1) / DHCP_FINE_TIMER_MSECS; DEBUGF(DHCP_DEBUG, ("dhcp_select(): request timeout %u msecs/n", msecs)); dhcp_set_state(state, DHCP_REQUESTING); return result;}
开发者ID:dafyddcrosby,项目名称:L4OS,代码行数:51,
示例8: serial_initstruct serial *serial_init(void){ static struct serial serial; serial.fUpcb = udp_new(); if (!serial.fUpcb) assert("udp_new"); u16_t port = AOS06_PORT; if (udp_bind(serial.fUpcb, &netif_default->ip_addr, port)) assert(!"udp_bind"); if (udp_connect(serial.fUpcb, &netif_default->gw, port)) assert(!"udp_connect"); udp_recv(serial.fUpcb, &serial_recv_handler, &serial); return &serial;}
开发者ID:gz,项目名称:aos10,代码行数:17,
示例9: tftpd_init/** * @brief Initializes the udp pcb for TFTP * @param None * @retval None */void tftpd_init(unsigned short port){ err_t err; /* create a new UDP PCB structure */ UDPpcb = udp_new(); if (UDPpcb) { /* Bind this PCB to port 69 */ err = udp_bind(UDPpcb, IP_ADDR_ANY, port); if (err == ERR_OK) { /* TFTP server start */ udp_recv(UDPpcb, recv_callback_tftp, NULL); } }}
开发者ID:MorgothCreator,项目名称:mSdk,代码行数:22,
示例10: PROCESS_THREAD/*---------------------------------------------------------------------------*/PROCESS_THREAD(ledsUDPServer_process, ev, data){ static struct uip_udp_conn *localconn; PROCESS_BEGIN(); /* Create a local connection structure : * - Remote IP: 0.0.0.0 (all accepted). * - Remote port: 0 (all accepted). */ localconn = udp_new(&uip_all_zeroes_addr, 0, NULL); /* Bind to the local port. */ udp_bind(localconn,uip_htons(local_port)); PRINTF("I listen the UDP port %u/n",uip_ntohs(localconn->lport)); while (1) { PRINTF("I wait a new request/n"); PROCESS_WAIT_EVENT_UNTIL(ev == tcpip_event); /* Here, a new TCP/IP event occurred ! */ /* A good packet is : * - With data. * - With at least "preambleSize + 1" bytes. * - Packet start with the good preamble. */ if(uip_newdata() && uip_datalen() >= (preambleSize + 1) && !strncmp(uip_appdata,preamble,preambleSize)) { PRINTF("I received a LED toggling request./n"); { char *data = (char *)uip_appdata; int led = 0; switch (data[4]) { case '1': led = LEDS_BLUE; break; case '2': led = LEDS_GREEN; break; case '3': led = LEDS_RED; break; default : PRINTF("I can't find the good LED.../n"); continue; } leds_toggle(led); } } } PROCESS_END();}
开发者ID:DIYzzuzpb,项目名称:wismote,代码行数:46,
示例11: NetworkSocket_StartListeningbool NetworkSocket_StartListening(NetworkSocket * networkSocket){ bool result = false; if (networkSocket) { if ((networkSocket->SocketType & NetworkSocketType_UDP) == NetworkSocketType_UDP) { networkSocket->Socket = udp_new(NULL, 0, NULL); if (networkSocket->Socket) { udp_bind(networkSocket->Socket, uip_htons(networkSocket->Port)); result = true; } } } return result;}
开发者ID:FlowM2M,项目名称:AwaLWM2M,代码行数:18,
示例12: udp_bind_connectint udp_bind_connect(char *src, int sport, char *dest, int dport, struct sockaddr_in *serv){ int sock; sock = udp_bind(src, sport); if (sock < 0) return sock; fill_sockaddr(serv, dest, dport); if (connect(sock, (struct sockaddr *) serv, sizeof(*serv)) < 0) { LOGL(0, "udp_bind_connect: failed: bind(): %s", strerror(errno)); return -1; } LOG("New UDP socket %d connected to %s:%d", sock, inet_ntoa(serv->sin_addr), ntohs(serv->sin_port)); return sock;}
开发者ID:Korjo,项目名称:minisatip,代码行数:18,
示例13: lwipv4_socket_bindstatic socket_error_t lwipv4_socket_bind(struct socket *sock, const struct socket_addr *address, const uint16_t port){ err_t err = ERR_OK; ip_addr_t a; switch (sock->family){ case SOCKET_DGRAM: a.addr = socket_addr_get_ipv4_addr(address); err = udp_bind((struct udp_pcb *)sock->impl, &a, port); break; case SOCKET_STREAM: a.addr = socket_addr_get_ipv4_addr(address); err = tcp_bind((struct tcp_pcb *)sock->impl, &a, port); break; default: return SOCKET_ERROR_BAD_FAMILY; } return lwipv4_socket_error_remap(err);}
开发者ID:u-blox,项目名称:sal-stack-lwip-ublox-odin-w2,代码行数:18,
示例14: snmp_info/* * Log a debug message by sending it within a UDP message. */void snmp_info(char* format, ...){ static struct uip_udp_conn *udp_con = NULL; if (udp_con == NULL) { udp_con = udp_new(NULL, UIP_HTONS(LOGGING_PORT), NULL); uip_ip6addr(&udp_con->ripaddr, 0xaaaa, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0001); udp_bind(udp_con, UIP_HTONS(3000)); } va_list args; va_start(args, format); static char buf[BUF_LEN]; memset(buf, 0, BUF_LEN); vsprintf(buf, format, args); va_end(args); uip_udp_packet_send(udp_con, buf, strlen(buf));}
开发者ID:EmuxEvans,项目名称:contiki-snmp,代码行数:21,
示例15: initer_slavestatic void initer_slave() { err_t err; struct ip_addr ipSend; //lwip_init(); pUdpConnection = udp_new(); IP4_ADDR(&ipSend, 255, 255, 255, 255); pUdpConnection->multicast_ip = ipSend; pUdpConnection->remote_ip = ipSend; pUdpConnection->remote_port = 8000; if(pUdpConnection == NULL) { os_printf("/nCould not create new udp socket... /n"); } err = udp_bind(pUdpConnection, IPADDR_ANY, 8000); udp_recv(pUdpConnection, handle_udp_recv_slave, pUdpConnection); led_init("01");}
开发者ID:eeijcea,项目名称:ESP8266,代码行数:18,
示例16: dhcp_renewerr_t dhcp_renew(struct dhcp_state *state){ err_t result; u16_t msecs; DEBUGF(DHCP_DEBUG, ("dhcp_renew()/n")); dhcp_set_state(state, DHCP_RENEWING); // create and initialize the DHCP message header result = dhcp_create_request(state); if (result == ERR_OK) { dhcp_option(state, DHCP_OPTION_MESSAGE_TYPE, DHCP_OPTION_MESSAGE_TYPE_LEN); dhcp_option_byte(state, DHCP_REQUEST); dhcp_option(state, DHCP_OPTION_MAX_MSG_SIZE, DHCP_OPTION_MAX_MSG_SIZE_LEN); dhcp_option_short(state, 576);#if 0 dhcp_option(state, DHCP_OPTION_REQUESTED_IP, 4); dhcp_option_long(state, ntohl(state->offered_ip_addr.addr));#endif#if 0 dhcp_option(state, DHCP_OPTION_SERVER_ID, 4); dhcp_option_long(state, ntohl(state->server_ip_addr.addr));#endif dhcp_option_trailer(state); pbuf_realloc(state->p_out, sizeof(struct dhcp_msg) - DHCP_OPTIONS_LEN + state->options_out_len); udp_bind(state->pcb, IP_ADDR_ANY, DHCP_CLIENT_PORT); udp_connect(state->pcb, &state->server_ip_addr, DHCP_SERVER_PORT); udp_send(state->pcb, state->p_out); dhcp_delete_request(state); } state->tries++; // back-off on retries, but to a maximum of 20 seconds msecs = state->tries < 10 ? state->tries * 2000 : 20 * 1000; state->request_timeout = (msecs + DHCP_FINE_TIMER_MSECS - 1) / DHCP_FINE_TIMER_MSECS; DEBUGF(DHCP_DEBUG, ("dhcp_renew(): request timeout %u msecs/n", msecs)); return result;}
开发者ID:dafyddcrosby,项目名称:L4OS,代码行数:44,
示例17: serverstatic void server(int port) { int i, s; Octstr *ping, *pong, *from; s = udp_bind(port,"0.0.0.0"); pong = octstr_create(PONG); if (s == -1) panic(0, "Couldn't set up client socket."); for (i = 0; i < TIMES; ++i) { if (udp_recvfrom(s, &ping, &from) == -1) panic(0, "Couldn't receive ping"); info(0, "Got <%s> from <%s:%d>", octstr_get_cstr(ping), octstr_get_cstr(udp_get_ip(from)), udp_get_port(from)); if (udp_sendto(s, pong, from) == -1) panic(0, "Couldn't send pong."); }}
开发者ID:frese,项目名称:mbuni,代码行数:19,
示例18: UDP_Testvoid UDP_Test(void) { struct udp_pcb *UdpPcb; struct ip_addr ipaddr; struct pbuf *p; p = pbuf_alloc(PBUF_RAW,sizeof(UDPData),PBUF_RAM); if(p==NULL) return; p->payload=(void *)UDPData; UdpPcb=udp_new(); /* 建立UDP 通信的控制块(pcb) */ udp_bind(UdpPcb,IP_ADDR_ANY,8080); /* 绑定本地IP 地址 */ IP4_ADDR(&ipaddr,192, 168, 10, 100); udp_sendto(UdpPcb,p,&ipaddr,8080); /* 将收到的数据再发送出去 */ udp_recv(UdpPcb,UDP_Receive,NULL); /* 设置数据接收时的回调函数 */ LED1(1); LED2(1); LED3(1);}
开发者ID:xiaoyeqiannian,项目名称:githubck,代码行数:19,
示例19: init_value_broadcastvoid init_value_broadcast(void){ syslog(LOG_INFO, "Value Broadcast init"); // this wrapper macro is needed to expand HXB_GROUP_RAW before uip_ip6addr, which is a macro // it's ugly as day, but it's the least ugly solution i found #define PARSER_WRAP(addr, ...) uip_ip6addr(addr, __VA_ARGS__) PARSER_WRAP(&server_ipaddr, HXB_GROUP_RAW); #undef PARSER_WRAP print_local_addresses(); /* new connection with remote host */ client_conn = udp_new(NULL, UIP_HTONS(HXB_PORT), NULL); uip_ipaddr_copy(&client_conn->ripaddr, &server_ipaddr); udp_bind(client_conn, UIP_HTONS(HXB_PORT)); syslog(LOG_DEBUG, "Created a connection " LOG_6ADDR_FMT ", local/remote port %u/%u", LOG_6ADDR_VAL(client_conn->ripaddr), UIP_HTONS(client_conn->lport), UIP_HTONS(client_conn->rport));}
开发者ID:ChristianKniep,项目名称:hexabus,代码行数:19,
示例20: UDP_Configvoid UDP_Config(void){ if(ETH_BSP_Config() == ETH_ERROR) CriticalError(ERR_ETH_CONFIG); LwIP_Init(); delay(500); IP4_ADDR(&ip_addr_tx,192,9,206,251); if((pudp_pcb = udp_new()) == NULL) CriticalError(ERR_UDP_NEW); if((udp_bind(pudp_pcb,IP_ADDR_ANY,RX_PORT) != ERR_OK)) CriticalError(ERR_UDP_BIND); udp_recv(pudp_pcb,&udp_rx_handler,NULL); if(!(pOut = pbuf_alloc(PBUF_TRANSPORT,sizeof(tx_udp_msg),PBUF_RAM))) CriticalError(ERR_POUT_NEW);}
开发者ID:TSURKOVSERGEY,项目名称:meteo,代码行数:19,
示例21: udp_openstatic int udp_open (PAL_HANDLE *hdl, const char * type, const char * uri, int access, int share, int create, int options){ char buf[PAL_SOCKADDR_SIZE]; int len = strlen(uri); if (len >= PAL_SOCKADDR_SIZE) return -PAL_ERROR_TOOLONG; memcpy(buf, uri, len + 1); if (!memcmp(type, "udp.srv:", 8)) return udp_bind(hdl, buf, create); if (!memcmp(type, "udp:", 4)) return udp_connect(hdl, buf); return -PAL_ERROR_NOTSUPPORT;}
开发者ID:gsmadhusudan,项目名称:graphene,代码行数:19,
示例22: init_udpvoid init_udp() { err_t err; struct ip_addr ipSend; lwip_init(); pUdpConnection = udp_new(); IP4_ADDR(&ipSend, 255, 255, 255, 255); pUdpConnection->multicast_ip = ipSend; pUdpConnection->remote_ip = ipSend; pUdpConnection->remote_port = port; if(pUdpConnection == NULL) { os_printf("/nCould not create new udp socket... /n"); } err = udp_bind(pUdpConnection, IP_ADDR_ANY, port); udp_recv(pUdpConnection, handle_udp_recv, pUdpConnection); os_timer_disarm(&waitTimer);}
开发者ID:houzhenggang,项目名称:esp8266-firmwares,代码行数:19,
示例23: PROCESS_THREAD/*---------------------------------------------------------------------------*/PROCESS_THREAD(ipv6_process, ev, data){ PROCESS_BEGIN(); // Set the local address uip_ip6addr(&my_addr, 0, 0, 0, 0, 0, 0, 0, 0); uip_ds6_set_addr_iid(&my_addr, &uip_lladdr); uip_ds6_addr_add(&my_addr, 0, ADDR_MANUAL); // Setup the destination address uiplib_ipaddrconv(RECEIVER_ADDR, &dest_addr); // Add a "neighbor" for our custom route // Setup the default broadcast route uiplib_ipaddrconv(ADDR_ALL_ROUTERS, &bcast_ipaddr); uip_ds6_nbr_add(&bcast_ipaddr, &bcast_lladdr, 0, NBR_REACHABLE); uip_ds6_route_add(&dest_addr, 128, &bcast_ipaddr); // Setup a udp "connection" client_conn = udp_new(&dest_addr, UIP_HTONS(RECEIVER_PORT), NULL); if (client_conn == NULL) { // Too many udp connections // not sure how to exit...stupid contiki } udp_bind(client_conn, UIP_HTONS(3001)); etimer_set(&periodic_timer, 10*CLOCK_SECOND); while(1) { PROCESS_YIELD(); if (etimer_expired(&periodic_timer)) { send_handler(ev, data); etimer_restart(&periodic_timer); } else if (ev == tcpip_event) { recv_handler(); } } PROCESS_END();}
开发者ID:kevinxusz,项目名称:monjolo,代码行数:44,
示例24: PROCESS_THREADPROCESS_THREAD(sender_process, ev, data){ static struct etimer periodic; static struct ctimer backoff_timer; PROCESS_BEGIN();// PROCESS_PAUSE(); set_global_address(); PRINTF("The sender process begins./n"); print_local_addresses(); /* new connection with remote host */ sender_conn = udp_new(NULL, UIP_HTONS(UDP_SINK_PORT), NULL); if(sender_conn == NULL) { PRINTF("No UDP connection available, exiting the process!/n"); PROCESS_EXIT(); } udp_bind(sender_conn, UIP_HTONS(UDP_SENDER_PORT)); PRINTF("Created a connection with the server "); PRINT6ADDR(&sender_conn->ripaddr); PRINTF(" local/remote port %u/%u/n", UIP_HTONS(sender_conn->lport), UIP_HTONS(sender_conn->rport)); etimer_set(&periodic, SEND_INTERVAL * CLOCK_SECOND); while(1) { PROCESS_YIELD(); if(ev == tcpip_event) tcpip_handler(); if(etimer_expired(&periodic)) { etimer_reset(&periodic); ctimer_set(&backoff_timer, RANDWAIT * CLOCK_SECOND, send_packet, NULL); } } PROCESS_END();}
开发者ID:RanHuang,项目名称:nick-project-contiki,代码行数:43,
示例25: PROCESS_THREAD/*---------------------------------------------------------------------------*/PROCESS_THREAD(trickle_protocol_process, ev, data){ PROCESS_BEGIN(); PRINTF("Trickle protocol started/n"); uip_create_linklocal_allnodes_mcast(&ipaddr); /* Store for later */ trickle_conn = udp_new(NULL, UIP_HTONS(TRICKLE_PROTO_PORT), NULL); udp_bind(trickle_conn, UIP_HTONS(TRICKLE_PROTO_PORT)); PRINTF("Connection: local/remote port %u/%u/n", UIP_HTONS(trickle_conn->lport), UIP_HTONS(trickle_conn->rport)); token = 0; trickle_timer_config(&tt, IMIN, IMAX, REDUNDANCY_CONST); trickle_timer_set(&tt, trickle_tx, &tt); /* * At this point trickle is started and is running the first interval. All * nodes 'agree' that token == 0. This will change when one of them randomly * decides to generate a new one */ etimer_set(&et, NEW_TOKEN_INTERVAL); while(1) { PROCESS_YIELD(); if(ev == tcpip_event) { tcpip_handler(); } else if(etimer_expired(&et)) { /* Periodically (and randomly) generate a new token. This will trigger * a trickle inconsistency */ if((random_rand() % NEW_TOKEN_PROB) == 0) { token++; PRINTF("At %lu: Generating a new token 0x%02x/n", (unsigned long)clock_time(), token); trickle_timer_reset_event(&tt); } etimer_set(&et, NEW_TOKEN_INTERVAL); } } PROCESS_END();}
开发者ID:13416795,项目名称:contiki,代码行数:44,
示例26: PROCESS_THREAD/*---------------------------------------------------------------------------*/PROCESS_THREAD(udp_client_process, ev, data){ static struct etimer et; uip_ipaddr_t ipaddr; PROCESS_BEGIN(); PRINTF("UDP client process started/n");#if UIP_CONF_ROUTER set_global_address();#endif print_local_addresses(); set_connection_address(&ipaddr); /* new connection with remote host */ client_conn = udp_new(&ipaddr, UIP_HTONS(3000), NULL); udp_bind(client_conn, UIP_HTONS(3001)); PRINTF("Created a connection with the server "); PRINT6ADDR(&client_conn->ripaddr); PRINTF(" local/remote port %u/%u/n", UIP_HTONS(client_conn->lport), UIP_HTONS(client_conn->rport)); etimer_set(&et, SEND_INTERVAL); while(1) { PROCESS_YIELD(); if(etimer_expired(&et)) { timeout_handler(); etimer_restart(&et); } else if(ev == tcpip_event) { tcpip_handler(); } } PROCESS_END();}
开发者ID:anhquang,项目名称:contiki,代码行数:43,
示例27: snmp_init/** * Starts SNMP Agent. * Allocates UDP pcb and binds it to IP_ADDR_ANY port 161. */voidsnmp_init(void){ struct snmp_msg_pstat *msg_ps; u8_t i; ip_addr_t *ip_addr_any4; #if LWIP_IPV6 ip_addr_any4 = ((ip_addr_t *)&ip6_addr_any); snmp1_pcb = udp_new_ip6();#else ip_addr_any4 = IP_ADDR_ANY; snmp1_pcb = udp_new();#endif if (snmp1_pcb != NULL) { udp_recv(snmp1_pcb, snmp_recv, (void *)SNMP_IN_PORT); udp_bind(snmp1_pcb, ip_addr_any4, SNMP_IN_PORT); } msg_ps = &msg_input_list[0]; for (i=0; i<SNMP_CONCURRENT_REQUESTS; i++) { msg_ps->state = SNMP_MSG_EMPTY; msg_ps->error_index = 0; msg_ps->error_status = SNMP_ES_NOERROR; msg_ps++; } trap_msg.pcb = snmp1_pcb;#ifdef SNMP_PRIVATE_MIB_INIT /* If defined, rhis must be a function-like define to initialize the * private MIB after the stack has been initialized. * The private MIB can also be initialized in tcpip_callback (or after * the stack is initialized), this define is only for convenience. */ SNMP_PRIVATE_MIB_INIT();#endif /* SNMP_PRIVATE_MIB_INIT */ /* The coldstart trap will only be output if our outgoing interface is up & configured */ snmp_coldstart_trap();}
开发者ID:singhshobhit,项目名称:RPL_Node,代码行数:46,
示例28: udp_newint TftpClient::get(char *rem_file, char *loc_file){ struct udp_pcb * pcb = udp_new(); err = udp_bind(pcb, IP_ADDR_ANY, loc_port); if(err != ERR_OK){ error(lwip_strerr(err), false); return -1; } fd = open(loc_file, O_WRONLY); blkno = 1; // Craft the initial get request with appropriate mode int bufsize = strlen(rem_file) + 4 + (mode == MODE_NETASCII ? strlen("netascii") : strlen("octet")); char *pkt = (char *)safe_malloc(bufsize); memset(pkt, 0, bufsize); u16_t *opcode = (u16_t *) pkt; *opcode = htons(1); memcpy(pkt+2, rem_file, strlen(rem_file)+1); if(mode == MODE_NETASCII) memcpy(pkt+3+strlen(rem_file), "netascii", strlen("netascii")); else memcpy(pkt+3+strlen(rem_file), "octet", strlen("octet")); // Set the packet recv handler udp_recv(pcb, hndl_pkt, this); // Send the packet struct pbuf *p = pbuf_alloc(PBUF_TRANSPORT, bufsize, PBUF_ROM); p->payload = pkt; udp_sendto(pcb, p, &rem_host, rem_port); // Block the thread until the request is satisfied sys_sem_new(&get_wait, 0); sys_arch_sem_wait(&get_wait, 0); sys_sem_free(&get_wait); udp_remove(pcb); //pbuf_free(p);}
开发者ID:wlanslovenija,项目名称:ImageFlasher,代码行数:42,
示例29: discover_bulbsvoid ICACHE_FLASH_ATTRdiscover_bulbs(void) { struct udp_pcb *pcb; uint8_t buff[36]; struct pbuf *p; err_t ret; LED_ON(); // Using the RAW interface to LWIP // the socket and netconn interfaces didn't receive broadcast packets pcb = udp_new(); ret = udp_bind(pcb, IP_ADDR_ANY, BROADCAST_PORT); if (ret != ERR_OK) { os_printf("[discover] Error bind %d/r/n", ret); return; } udp_recv(pcb, my_udp_recv, NULL); // Create pbuf for a new outgoing packet p = pbuf_alloc(PBUF_TRANSPORT, 36, PBUF_RAM); if (p == NULL) { os_printf("[discover] error pbuf_alloc %d/r/n", ret); return; } getBroadcastPkt((uint8_t *)p->payload, 36); ret = udp_sendto(pcb, p, IP_ADDR_BROADCAST, BROADCAST_PORT); if (ret != ERR_OK) { os_printf("[discover] Error sending %d/r/n", ret); pbuf_free(p); return; } os_printf("[discover] Broadcast sent/r/n"); pbuf_free(p); // MUST wait a given timeout for messages to be received before // tearing down the connection - udp_remove() will disable the callback vTaskDelay(500/portTICK_RATE_MS); LED_OFF(); vTaskDelay(2000/portTICK_RATE_MS); udp_remove(pcb);}
开发者ID:HappyWheels,项目名称:esp8266_lifx,代码行数:42,
示例30: UDP_broadcastvoid UDP_broadcast(void) { struct udp_pcb *UdpPcb; struct ip_addr ipaddr; struct pbuf *p; p = pbuf_alloc(PBUF_RAW,sizeof(UDPData),PBUF_RAM); printf("/nUDP broadcast/n"); if(p==NULL) return; p->payload=(void *)UDPData; ///给pbuf初始化 UdpPcb=udp_new(); // 建立UDP 通信的控制块(pcb) udp_bind(UdpPcb,IP_ADDR_ANY,8080); // 绑定本地IP 地址 IP4_ADDR(&ipaddr,255, 255, 255, 255); udp_sendto(UdpPcb,p,&ipaddr,8080); // 将收到的数据再发送出去 // udp_sendto(UdpPcb,p,&ipaddr,8080); udp_sendto(UdpPcb,p,&ipaddr,8080); udp_recv(UdpPcb,UDP_Receive,NULL); // 设置数据接收时的回调函数 //}
开发者ID:Cholly-Tse,项目名称:STM32F407_8686_WIFI,代码行数:20,
注:本文中的udp_bind函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 C++ udp_disconnect函数代码示例 C++ udi_cdc_ctrl_state_change函数代码示例 |