static void dhcpdInit(void) { uip_ipaddr_t remote_ipaddr; uip_ipaddr(remote_ipaddr, 0,0,0,0); //uip_ipaddr(remote_ipaddr, 192,168,12,2); dhcpd_request_conn = uip_udp_new(&remote_ipaddr, HTONS(68) /* remote port */); if(dhcpd_request_conn != NULL) { uip_udp_bind(dhcpd_request_conn, HTONS(67) /* local port */); printf("BIND OK"); } else { printf("BIND ERROR!"); } uip_ipaddr(remote_ipaddr, 255,255,255,255); //uip_ipaddr(remote_ipaddr, 192,168,12,2); dhcpd_reply_conn = uip_udp_new(&remote_ipaddr, HTONS(68) /* remote port */); if(dhcpd_reply_conn != NULL) { uip_udp_bind(dhcpd_reply_conn, HTONS(67) /* local port */); printf("BIND OK"); } else { printf("BIND ERROR!"); } dhcpd_state = DHCPD_IDLE; }
PROCESS_THREAD(sync_master, ev, data) { static int i=0; static struct uip_udp_conn *udp; PROCESS_BEGIN(); udp = udp_new(NULL, UIP_HTONS(10000), NULL); uip_udp_bind(udp, UIP_HTONS(10000)); uart0_init(1000000); while(1) { PROCESS_YIELD_UNTIL(ev == tcpip_event); int i; for (i = 0; i < 16; i++) uart0_writeb(UDP_HDR->srcipaddr.u8[i]); for (i = 0; i < uip_datalen(); i++) { uart0_writeb(((uint8_t*)uip_appdata)[i]); } } PROCESS_END(); }
///////////////////////////////////////////////////////////////////////////// // Initialize the OSC daemon ///////////////////////////////////////////////////////////////////////////// s32 OSC_SERVER_Init(u32 mode) { // disable send packet osc_send_packet = NULL; // remove open connection if(osc_conn != NULL) { uip_udp_remove(osc_conn); } // create new connection uip_ipaddr_t ripaddr; uip_ipaddr(ripaddr, ((OSC_REMOTE_IP)>>24) & 0xff, ((OSC_REMOTE_IP)>>16) & 0xff, ((OSC_REMOTE_IP)>> 8) & 0xff, ((OSC_REMOTE_IP)>> 0) & 0xff); if( (osc_conn=uip_udp_new(&ripaddr, HTONS(OSC_SERVER_PORT))) != NULL ) { uip_udp_bind(osc_conn, HTONS(OSC_SERVER_PORT)); #if DEBUG_VERBOSE_LEVEL >= 1 MIOS32_MIDI_SendDebugMessage("[OSC_SERVER] listen to %d.%d.%d.%d:%d\n", (osc_conn->ripaddr[0] >> 0) & 0xff, (osc_conn->ripaddr[0] >> 8) & 0xff, (osc_conn->ripaddr[1] >> 0) & 0xff, (osc_conn->ripaddr[1] >> 8) & 0xff, HTONS(osc_conn->rport)); #endif } else {
void dhcp_net_init(void) { #ifdef S0BRIDGE_SUPPORT uint8_t ips = 0; eeprom_restore_int( ip_static, &ips ); if (ips) { dhcp_set_static(); return; } #endif uip_ipaddr_t ip; uip_ipaddr_copy(&ip, all_ones_addr); uip_udp_conn_t *dhcp_conn = uip_udp_new(&ip, HTONS(DHCPC_SERVER_PORT), dhcp_net_main); if(! dhcp_conn) return; /* dammit. */ uip_udp_bind(dhcp_conn, HTONS(DHCPC_CLIENT_PORT)); dhcp_conn->appstate.dhcp.retry_counter = 0; dhcp_conn->appstate.dhcp.retry_timer = 5; dhcp_conn->appstate.dhcp.state = STATE_INITIAL; tick_sec = 0; }
void dhcpc_renew(void) { uip_ipaddr_t addr; #if defined PORT_APP_MAPPER if (dhcpc_running) return; dhcpc_running = 1; #else if (s.state != STATE_CONFIG_RECEIVED) { return; } #endif //sendString("\r\ndhcpc renew called"); // if no server ip then we have to do a full request if (s.serverid[0] == 0) { dhcpc_init(s.mac_addr, s.mac_len); return; } // unicast to dhcp server uip_ipaddr(addr, s.serverid[0], s.serverid[1], s.serverid[2], s.serverid[3]); s.conn = uip_udp_new(&addr, HTONS(DHCPC_SERVER_PORT)); if(s.conn != NULL) { uip_udp_bind(s.conn, HTONS(DHCPC_CLIENT_PORT)); } s.state = STATE_RENEW; PT_INIT(&s.pt); }
/***************************************************************************** 函 数 名 : my_udp8899_init 功能描述 : a uip udp function for local port is 8899 输入参数 : void 输出参数 : 无 返 回 值 : static 调用函数 : 被调函数 : 修改历史 : 1.日 期 : 2017年4月17日 作 者 : QSWWD 修改内容 : 新生成函数 *****************************************************************************/ static void my_udp8899_init(void) { uip_ipaddr_t remote_addr; uip_ipaddr(remote_addr, 192,168,1,8); struct uip_udp_conn *my_udp_con = uip_udp_new(&remote_addr,HTONS(8899)); if(my_udp_con != NULL) { uip_udp_bind(my_udp_con,HTONS(8899)); } }
void artnet_net_init(void) { uip_udp_conn_t *conn; if(! (conn = uip_udp_new(&all_ones_addr, 0, artnet_net_main))) return; /* Couldn't bind socket */ uip_udp_bind(conn, HTONS(artnet_port)); }
// obs³u¿ pakiet void announce_handle_packet(unsigned char* data, unsigned int len) { // wype³nij pakiet (nazwa urz¹dzenia, adres MAC, sygnaturka) len = 0; // skonfigurowana nazwa urz¹dzenia config_t* config_get(); strcpy(config_ram.name, (char*)data+len); len += strlen((char*)data); // ³amanie wiersza memcpy_P(PSTR("\r\n"), data+len, 2); len += 2; // adres MAC (w formacie "human-readable") unsigned char *mac = nic_get_mac(); for (unsigned char i=0; i<6; i++) { data[len++] = dec2hex(mac[i] >> 4); data[len++] = dec2hex(mac[i] & 0x0f); if (i<5) data[len++] = '-'; } // ³amanie wiersza memcpy_P(PSTR("\r\n"), data+len, 2); len += 2; // sygnaturka strcpy_P(RS2ETH_SIGNATURE, (char*)data+len); len += strlen_P(RS2ETH_SIGNATURE); rs_dump(data, len); // utwórz "po³¹czenie" UDP (odpowiedŸ) struct uip_udp_conn* conn; conn = uip_udp_new(&uip_udp_conn->ripaddr, uip_udp_conn->rport); if (!conn) { return; } // wyœlij z portu konfiguracyjnego uip_udp_bind(conn, HTONS(ANNOUNCE_PORT)); // wyœlij uip_udp_send(len + 10); // czekaj na wys³anie nic_wait_for_send(); // zamknij po³¹czenia UDP (przychodz¹cy broadcast i wychodz¹cy unicast) uip_udp_remove(conn); uip_udp_remove(uip_udp_conn); }
void netfind_init(void) { struct uip_udp_conn *local_conn; uip_ipaddr_t ipaddr; uip_ipaddr(&ipaddr, 255, 255, 255, 255); local_conn = uip_udp_new(&ipaddr, HTONS(NETFIND_SERVER_PORT)); uip_udp_bind(local_conn, HTONS(NETFIND_CLIENT_PORT)); netfind_s.state = NETFIND_STATE_IDLE; }
static void dhcpd_address_assigned() { #ifdef USE_UDP if (app_conn) uip_udp_remove(app_conn); printf("setting up app connection "); app_conn = uip_udp_new(&dhcpd_client_ipaddr, HTONS(1208) /* remote port */); if (app_conn != NULL) { uip_udp_bind(app_conn, HTONS(1208) /* local port */); } bc_conn = uip_udp_new(&dhcpd_broadcast_ipaddr, HTONS(1208) /* remote port */); if (bc_conn != NULL) { uip_udp_bind(bc_conn, HTONS(1208) /* local port */); } #else // we can only close the current connection, so we can't do it here; must do it in a poll handler or something //if (app_conn) uip_close(app_conn); printf("setting up app connection "); app_conn = uip_connect(&dhcpd_client_ipaddr, HTONS(1208) /* remote port */); #endif }
/////////////////////////////////////////////////////////////////////////////////// // Exported functions // void Dhcp_Init(const void *mac_addr, int mac_len) { uip_ipaddr_t addr; struct uip_udp_conn *conn = NULL; uip_ipaddr(addr, 255,255,255,255); conn = uip_udp_new(&addr, HTONS(DHCPS_CLIENT_PORT)); if(conn != NULL) { uip_udp_bind(conn, HTONS(DHCPS_SERVER_PORT)); } }
void zbus_raw_net_init(void) { uip_ipaddr_t ip; uip_ipaddr_copy(&ip, all_ones_addr); zbus_raw_conn = uip_udp_new(&ip, 0, zbus_raw_net_main); if(! zbus_raw_conn) return; uip_udp_bind (zbus_raw_conn, HTONS(ZBUS_RAW_UDP_PORT)); }
void uecmd_net_init() { uip_ipaddr_t ip; uip_ipaddr_copy(&ip, all_ones_addr); uip_udp_conn_t *uecmd_conn = uip_udp_new(&ip, 0, uecmd_net_main); if(! uecmd_conn) { debug_printf("ecmd: udp failed\n"); return; } uip_udp_bind (uecmd_conn, HTONS(ECMD_UDP_PORT)); }
void udp_srv_app1_init() { UIP_UDP_CONN *udp_conn=NULL; /* We don't specify a remote address and a remote port, that means we can receive data from any address. */ udp_conn = uip_udp_new(NULL, HTONS(UDP_SRV_APP1_REMOTE_PORT)); if (udp_conn) { /* Bind to local 7682 port. */ uip_udp_bind(udp_conn, HTONS(UDP_SRV_APP1_LOCAL_PORT)); } }
void mdns_sd_net_init(void) { uip_udp_conn_t *conn; uip_ipaddr_t ip; uip_ipaddr_copy(&ip, all_ones_addr); if(! (conn = uip_udp_new(&ip, 0, mdns_sd_net_main))) return; /* Couldn't bind socket */ uip_udp_bind(conn, HTONS(MDNS_PORT)); }
/*---------------------------------------------------------------------------*/ void udpHandler_init(void) { uip_ipaddr_t addr; struct uip_udp_conn *c; uip_ipaddr(&addr, 192,168,0,199); c = uip_udp_new(&addr, HTONS(0)); if(c != NULL) { uip_udp_bind(c, HTONS(1101)); } }
void udpio_net_init (void) { uip_ipaddr_t ip; uip_ipaddr_copy (&ip, all_ones_addr); uip_udp_conn_t *udp_echo_conn = uip_udp_new (&ip, 0, udpio_net_main); if (!udp_echo_conn) return; /* dammit. */ uip_udp_bind (udp_echo_conn, HTONS (UDP_IO_PORT)); }
void network_init(void) { uip_listen(HTONS(NETWORK_PORT_GCODE)); uip_listen(HTONS(NETWORK_PORT_DEBUG)); // Listen on a UDP port uip_ipaddr_t addr; struct uip_udp_conn *c; uip_ipaddr(&addr, 0,0,0,0); c = uip_udp_new(&addr, HTONS(0)); if(c != NULL) uip_udp_bind(c, HTONS(NETWORK_PORT_GCODE)); }
/** * Function to send a packet to a destination host * @param ip ip address of packet destination host * @param port port to use at the destination/local hosts * @param data packet data pointer * @param len packet data length * \return 1 if packet successfully stored, 0 if connection not possible, -1 if packet not sent yet * @note * - The packet is not sent immediately. The information is stored in an * intermediate variable and sent in the next UDP polling event */ int udp_frame_send(uip_ipaddr_t ip, int port, char* data, int len) { int i; struct uip_udp_conn* conn; port = htons(port); if( len < 0 || data == NULL ) return 0; // Check if there is an existing connection for( i = 0; i < UIP_UDP_CONNS; i++ ) { if( uip_udp_conns[i].rport != port || uip_udp_conns[i].lport != port || !uip_ipaddr_cmp( uip_udp_conns[i].ripaddr, ip ) ) continue; if( udp_frame_pi[i].length > 0 ) return 0; udp_frame_pi[i].conn = &uip_udp_conn[i]; udp_frame_pi[i].data = data; udp_frame_pi[i].length = len; udp_frame_pi[i].age = 0; return 1; } // Create new connection conn = uip_udp_new( (uip_ipaddr_t*) ip, port ); if( conn == NULL ) { int oldest = 0; // remove oldest connection to create a new one for( i = 1; i < UIP_UDP_CONNS; i++ ) { if( udp_frame_pi[i].age > udp_frame_pi[oldest].age ) oldest = i; } uip_udp_remove( udp_frame_pi[oldest].conn ); conn = uip_udp_new( (uip_ipaddr_t*) ip, port ); if( conn == NULL ) return 0; } // Update connection ages and data uip_udp_bind( conn, port ); for( i = 0; i < UIP_UDP_CONNS; i++ ) { if( &uip_udp_conns[i] == conn ) { udp_frame_pi[i].conn = conn; udp_frame_pi[i].data = data; udp_frame_pi[i].length = len; udp_frame_pi[i].age = 0; }else{ if( udp_frame_pi[i].conn != NULL && udp_frame_pi[i].age < AGE_MAX ) udp_frame_pi[i].age++; // Update age of connections } } // Store packet information to be sent return 1; }
void dhcp_init(void) { uip_ipaddr_t ipaddr; uip_ipaddr(&ipaddr, 255, 255, 255, 255); dhcp_s.conn = uip_udp_new(&ipaddr, HTONS(DHCP_SERVER_PORT)); uip_udp_bind(dhcp_s.conn, HTONS(DHCP_CLIENT_PORT)); dhcp_s.xid = random(); dhcp_s.dhcp_renew_time = get_clock() + 2 * CLOCK_TICKS_PER_SECOND + (random() % (3 * CLOCK_TICKS_PER_SECOND)); dhcp_s.state = DHCP_STATE_BOOT_WAIT; }
// initialize, start listening on specified port. Returns 1 if successful, 0 if there are no sockets available to use uint8_t UIPUDP::begin(uint16_t port) { if (!_uip_udp_conn) { _uip_udp_conn = uip_udp_new(NULL, 0); } if (_uip_udp_conn) { uip_udp_bind(_uip_udp_conn,htons(port)); _uip_udp_conn->appstate = &appdata; return 1; } return 0; }
void ntp_init(void) { uip_ipaddr_t ipaddr; ntp_gmtoff = erb(EE_IP4_NTPOFFSET); erip(ipaddr, EE_IP4_NTPSERVER); if(ipaddr[0] == 0 && ipaddr[1] == 0) erip(ipaddr, EE_IP4_GATEWAY); ntp_conn = uip_udp_new(&ipaddr, HTONS(NTP_PORT)); if(ntp_conn == NULL) return; uip_udp_bind(ntp_conn, HTONS(NTP_PORT)); //ntp_sendpacket(); }
void bootp_net_init(void) { uip_ipaddr_t ip; uip_ipaddr(&ip, 255,255,255,255); uip_udp_conn_t *bootp_conn = uip_udp_new(&ip, HTONS(BOOTPS_PORT), bootp_net_main); if(! bootp_conn) return; /* dammit. */ uip_udp_bind(bootp_conn, HTONS(BOOTPC_PORT)); bootp_conn->appstate.bootp.retry_timer = 0; }
void udpapp_init(void) { uip_ipaddr_t addr; struct uip_udp_conn *c; uip_ipaddr(&addr, 255, 255, 255, 255); c = uip_udp_new(&addr, HTONS(0)); if(c != NULL) { uip_udp_bind(c, HTONS(2222)); } s.state = STATE_INIT; PT_INIT(&s.pt); }
void udpapp_init(void) { uip_ipaddr_t addr; struct uip_udp_conn *c; uip_ipaddr(&addr, 192,168,1,23); c = uip_udp_new(&addr, HTONS(0)); if(c != NULL) { uip_udp_bind(c, HTONS(12344)); } s.state = STATE_INIT; PT_INIT(&s.pt); }
/** Initialization function for the DHCP server. */ void DHCPServerApp_Init(void) { /* Listen on port 67 for DHCP server connections from hosts */ uip_listen(HTONS(DHCP_SERVER_PORT)); /* Create a new UDP connection to the DHCP server port for the DHCP solicitation */ struct uip_udp_conn* BroadcastConnection = uip_udp_new(&uip_broadcast_addr, HTONS(DHCP_CLIENT_PORT)); /* If the connection was successfully created, bind it to the local DHCP client port */ if (BroadcastConnection != NULL) uip_udp_bind(BroadcastConnection, HTONS(DHCP_SERVER_PORT)); /* Set all IP addresses as unleased */ memset(LeasedIPs, 0x00, sizeof(LeasedIPs)); }
/*---------------------------------------------------------------------------*/ void dhcpc_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 = uip_udp_new(&addr, HTONS(DHCPC_SERVER_PORT)); if(s.conn != NULL) { uip_udp_bind(s.conn, HTONS(DHCPC_CLIENT_PORT)); } PT_INIT(&s.pt); }
void _udp_states_init(void) { debug_printf("UDP_STATES registert states (befor init) %x\n", udp_states_n_registert_states); udp_states_n_registert_states=0; //no states are registert debug_printf("UDP_STATES registert states (after init) %x\n", udp_states_n_registert_states); udp_states_n_registert_callbacks=0; //no callbacks registert uip_ipaddr_t io; uip_ipaddr_copy (&ip, all_ones_addr); uip_udp_conn_t *udp_states_connection = uip_udp_new (&ip, 0, _udp_states_process); //register the protocol if (!udp_states_connection) return; uip_udp_bind (udp_states_connection, HTONS (UDP_STATES_PORT)); //bind the protocol to the Port }
/*---------------------------------------------------------------------*/ PROCESS_THREAD(test_uaodv_process, ev, data) { static uip_ipaddr_t addr; PROCESS_BEGIN(); printf("uIP uAODV test process started\n"); uip_ipaddr(&addr, 0,0,0,0); in_conn = udp_new(&addr, UIP_HTONS(0), NULL); uip_udp_bind(in_conn, UIP_HTONS(COOJA_PORT)); uip_ipaddr(&addr, 10,10,10,4); out_conn = udp_new(&addr, UIP_HTONS(COOJA_PORT), NULL); button_sensor.configure(SENSORS_ACTIVE, 1); while(1) { PROCESS_WAIT_EVENT(); if(ev == sensors_event && data == &button_sensor) { struct uaodv_rt_entry *route; uip_ipaddr(&addr, 10,10,10,4); route = uaodv_rt_lookup_any(&addr); if (route == NULL || route->is_bad) { printf("%d.%d.%d.%d: lookup %d.%d.%d.%d\n", uip_ipaddr_to_quad(&uip_hostaddr), uip_ipaddr_to_quad(&addr)); uaodv_request_route_to(&addr); } else { printf("%d.%d.%d.%d: send to %d.%d.%d.%d\n", uip_ipaddr_to_quad(&uip_hostaddr), uip_ipaddr_to_quad(&addr)); tcpip_poll_udp(out_conn); PROCESS_WAIT_UNTIL(ev == tcpip_event && uip_poll()); uip_send("cooyah COOJA", 12); } } if(ev == tcpip_event && uip_newdata()) { ((char*) uip_appdata)[uip_datalen()] = 0; printf("data received from %d.%d.%d.%d: %s\n", uip_ipaddr_to_quad(&((struct uip_udpip_hdr *)&uip_buf[UIP_LLH_LEN])->srcipaddr), (char *)uip_appdata); leds_toggle(LEDS_ALL); } } PROCESS_END(); }
void i2c_udp_net_init(void) { uip_ipaddr_t ip; uip_ipaddr_copy(&ip, all_ones_addr); uip_udp_conn_t *i2c_conn = uip_udp_new(&ip, 0, i2c_udp_net_main); if(! i2c_conn) return; /* keine udp connection !? */ uip_udp_bind(i2c_conn, HTONS(I2C_PORT)); // Init the I2C Code i2c_udp_init(i2c_conn); }