/* Shut down the UDP and network stuff */ bool netShutdown(NetPath *netPath) { struct ip_addr multicastAaddr; DBG("netShutdown\n"); /* leave multicast group */ multicastAaddr.addr = netPath->multicastAddr; igmp_leavegroup(IP_ADDR_ANY, &multicastAaddr); /* Disconnect and close the Event UDP interface */ if (netPath->eventPcb) { udp_disconnect(netPath->eventPcb); udp_remove(netPath->eventPcb); netPath->eventPcb = NULL; } /* Disconnect and close the General UDP interface */ if (netPath->generalPcb) { udp_disconnect(netPath->generalPcb); udp_remove(netPath->generalPcb); netPath->generalPcb = NULL; } /* Clear the network addresses. */ netPath->multicastAddr = 0; netPath->unicastAddr = 0; /* Return a success code. */ return TRUE; }
/* shut down the UDP stuff */ Boolean netShutdown(NetPath *netPath) { /* Disconnect and close the Event UDP interface */ if(netPath->eventPcb) { udp_disconnect(netPath->eventPcb); udp_remove(netPath->eventPcb); } /* Disconnect and close the General UDP interface */ if(netPath->generalPcb) { udp_disconnect(netPath->generalPcb); udp_remove(netPath->generalPcb); } /* Free up the Event and General Tx PBUFs. */ if(netPath->eventTxBuf) { pbuf_free(netPath->eventTxBuf); } if(netPath->generalTxBuf) { pbuf_free(netPath->generalTxBuf); } /* Clear the network addresses. */ netPath->multicastAddr = 0; netPath->unicastAddr = 0; /* Return a success code. */ return TRUE; }
/* * 函数名:updd_Send * 描述 :发送udp数据包 * 输入 :无 * 输出 : 无 * 调用 :外部调用 */ void udpd_Send(void) { struct udp_pcb *UdpPcb; struct ip_addr ipaddr; struct pbuf *p; err_t err = ERR_Mine; //测试用 p = pbuf_alloc(PBUF_RAW,sizeof(UDPData),PBUF_RAM); p->payload=(void *)UDPData; UdpPcb = udp_new(); udp_bind(UdpPcb,IP_ADDR_ANY,6000); /* 绑定本地IP 地址 */ IP4_ADDR(&ipaddr,192,168,1,122); err = udp_connect(UdpPcb,&ipaddr,6001); /* 连接远程主机 */ if(err == ERR_OK) { err = ERR_Mine; //测试用 err = udp_send(UdpPcb, p); } udp_disconnect(UdpPcb); pbuf_free(p); udp_remove(UdpPcb); }
/** * Clean up and free the ttcp structure */ static void ttcp_destroy(struct ttcp* ttcp) { if (ttcp->tpcb) { tcp_arg(ttcp->tpcb, NULL); tcp_sent(ttcp->tpcb, NULL); tcp_recv(ttcp->tpcb, NULL); tcp_err(ttcp->tpcb, NULL); tcp_close(ttcp->tpcb); } if (ttcp->lpcb) { tcp_arg(ttcp->lpcb, NULL); tcp_accept(ttcp->lpcb, NULL); tcp_close(ttcp->lpcb); } if (ttcp->upcb) { udp_disconnect(ttcp->upcb); udp_remove(ttcp->upcb); } if (ttcp->payload) free(ttcp->payload); timer_cancel_timeout(ttcp->tid); free(ttcp); }
void ICACHE_FLASH_ATTR dhcps_stop(void) { struct netif * apnetif = (struct netif *)eagle_lwip_getif(0x01); udp_disconnect(pcb_dhcps); dhcps_lease_flag = true; if(apnetif->dhcps_pcb != NULL) { udp_remove(apnetif->dhcps_pcb); apnetif->dhcps_pcb = NULL; } //udp_remove(pcb_dhcps); list_node *pnode = NULL; list_node *pback_node = NULL; pnode = plist; while (pnode != NULL) { pback_node = pnode; pnode = pback_node->pnext; node_remove_from_list(&plist, pback_node); os_free(pback_node->pnode); pback_node->pnode = NULL; os_free(pback_node); pback_node = NULL; } }
void client_init(void) { struct udp_pcb *upcb; struct pbuf *p; SET_IP4_ADDR(&ip_udp_server,UDP_SERVER_IP); /* Create a new UDP control block */ upcb = udp_new(); p = pbuf_alloc(PBUF_TRANSPORT, sizeof(Sent), PBUF_RAM); p->payload = (void*)Sent; upcb->local_port = 5; udp_connect(upcb, &ip_udp_server, UDP_SERVER_PORT); udp_send(upcb, p); /* Reset the upcb */ udp_disconnect(upcb); /* Bind the upcb to any IP address and the UDP_PORT port*/ udp_bind(upcb, IP_ADDR_ANY, 5); udp_recv(upcb, udp_client_callback, NULL); /* Free the p buffer */ pbuf_free(p); }
static void do_disconnect(struct api_msg_msg *msg) { switch (msg->conn->type) { #if LWIP_RAW case NETCONN_RAW: /* Do nothing as connecting is only a helper for upper lwip layers */ break; #endif #if LWIP_UDP case NETCONN_UDPLITE: /* FALLTHROUGH */ case NETCONN_UDPNOCHKSUM: /* FALLTHROUGH */ case NETCONN_UDP: udp_disconnect(msg->conn->pcb.udp); break; #endif case NETCONN_TCP: break; default: LWIP_ASSERT( "do_newconn: msg->conn->type unknown\n", 0 ); } sys_mbox_post(msg->conn->mbox, NULL); }
/** * Clean up and free the ttcp structure */ static void ard_tcp_destroy(struct ttcp* ttcp) { err_t err = ERR_OK; DUMP_TCP_STATE(ttcp); if (getSock(ttcp)==-1) WARN("ttcp already deallocated!\n"); if (ttcp->tpcb) { tcp_arg(ttcp->tpcb, NULL); tcp_sent(ttcp->tpcb, NULL); tcp_recv(ttcp->tpcb, NULL); tcp_err(ttcp->tpcb, NULL); //TEMPORAQARY //err = tcp_close(ttcp->tpcb); INFO_TCP("Closing tpcb: state:0x%x err:%d\n", ttcp->tpcb->state, err); } if (ttcp->lpcb) { tcp_arg(ttcp->lpcb, NULL); tcp_accept(ttcp->lpcb, NULL); err = tcp_close(ttcp->lpcb); INFO_TCP("Closing lpcb: state:0x%x err:%d\n", ttcp->lpcb->state, err); } if (ttcp->upcb) { udp_disconnect(ttcp->upcb); udp_remove(ttcp->upcb); } if (ttcp->payload) free(ttcp->payload); free(ttcp); }
/** * Clean up and free the ttcp structure */ static void ard_tcp_abort(struct ttcp* ttcp) { INFO_TCP("Abort ttcb:%p tpcb:%p lpcb:%p\n", ttcp, ttcp->tpcb, ttcp->lpcb); if (ttcp->tpcb) { tcp_arg(ttcp->tpcb, NULL); tcp_sent(ttcp->tpcb, NULL); tcp_recv(ttcp->tpcb, NULL); tcp_err(ttcp->tpcb, NULL); tcp_abort(ttcp->tpcb); } if (ttcp->lpcb) { tcp_arg(ttcp->lpcb, NULL); tcp_accept(ttcp->lpcb, NULL); tcp_abort(ttcp->lpcb); } if (ttcp->upcb) { udp_disconnect(ttcp->upcb); udp_remove(ttcp->upcb); } if (ttcp->payload) free(ttcp->payload); free(ttcp); }
/** * Connect a pcb contained inside a netconn * Only used for UDP netconns. * Called from netconn_disconnect. * * @param msg the api_msg_msg pointing to the connection to disconnect */ void do_disconnect(struct api_msg_msg *msg) { #if LWIP_UDP if (NETCONNTYPE_GROUP(msg->conn->type) == NETCONN_UDP) { udp_disconnect(msg->conn->pcb.udp); } #endif /* LWIP_UDP */ TCPIP_APIMSG_ACK(msg); }
void trans_Control(void* buf, size_t len) { struct pbuf *p; p = pbuf_alloc(PBUF_TRANSPORT, len, PBUF_POOL); if (p != NULL) { pbuf_take(p, buf, len); /* send udp data */ udp_connect(upcb_c, &BagAddr.BagIPaddr, BagAddr.port_c); udp_send(upcb_c, p); udp_disconnect(upcb_c); /* free pbuf */ pbuf_free(p); } return; }
/** * Connect a pcb contained inside a netconn * Only used for UDP netconns. * Called from netconn_disconnect. * * @param msg the api_msg_msg pointing to the connection to disconnect */ void do_disconnect(struct api_msg_msg *msg) { #if LWIP_UDP if (NETCONNTYPE_GROUP(msg->conn->type) == NETCONN_UDP) { udp_disconnect(msg->conn->pcb.udp); msg->err = ERR_OK; } else #endif /* LWIP_UDP */ { msg->err = ERR_VAL; } TCPIP_APIMSG_ACK(msg); }
void udp_echoserver_receive_callback(void *arg, struct udp_pcb *upcb, struct pbuf *p, struct ip_addr *addr, u16_t port) { char c[64]; union {int i;char c[4];} ipaddr; ipaddr.i=(int)netif_default->ip_addr.addr; pbuf_free(p); sprintf(c,"LwIP %d.%d.%d.%d",ipaddr.c[0],ipaddr.c[1],ipaddr.c[2],ipaddr.c[3]); p = pbuf_alloc(PBUF_TRANSPORT, strlen(c) , PBUF_POOL); pbuf_take(p,c,strlen(c)); udp_connect(upcb, addr, port); udp_send(upcb, p); udp_disconnect(upcb); pbuf_free(p); }
/** * @brief disconnect and close the connection * @param upcb: pointer on udp_pcb structure * @param args: pointer on tftp_connection arguments * @retval None */ static void IAP_tftp_cleanup_wr(struct udp_pcb *upcb, tftp_connection_args *args) { /* Free the tftp_connection_args structure */ mem_free(args); /* Disconnect the udp_pcb */ udp_disconnect(upcb); /* close the connection */ udp_remove(upcb); /* reset the callback function */ udp_recv(UDPpcb, IAP_tftp_recv_callback, NULL); }
/** * @brief This function is called when an UDP datagrm has been received on the port UDP_PORT. * @param arg user supplied argument (udp_pcb.recv_arg) * @param pcb the udp_pcb which received data * @param p the packet buffer that was received * @param addr the remote IP address from which the packet was received * @param port the remote port from which the packet was received * @retval None */ void udp_echoserver_receive_callback(void *arg, struct udp_pcb *upcb, struct pbuf *p, struct ip_addr *addr, u16_t port) { /* Connect to the remote client */ udp_connect(upcb, addr, UDP_CLIENT_PORT); /* Tell the client that we have accepted it */ udp_send(upcb, p); /* free the UDP connection, so we can accept new clients */ udp_disconnect(upcb); /* Free the p buffer */ pbuf_free(p); }
/** * @brief Cleanup after end of TFTP read operation * @param upcb: pointer on udp pcb * @param args: pointer on a structure of type tftp_connection_args * @retval None */ void tftp_cleanup_rd(struct udp_pcb *upcb, tftp_connection_args *args) { /* close the filesystem */ f_close(&file_SD); f_mount(NULL, NULL, 0); /* Free the tftp_connection_args structure reserverd for */ mem_free(args); /* Disconnect the udp_pcb*/ udp_disconnect(upcb); /* close the connection */ udp_remove(upcb); udp_recv(UDPpcb, recv_callback_tftp, NULL); }
static socket_error_t lwipv4_socket_close(struct socket *sock) { err_t err = ERR_OK; if (sock == NULL || sock->impl == NULL) return SOCKET_ERROR_NULL_PTR; switch (sock->family) { case SOCKET_DGRAM: udp_disconnect((struct udp_pcb *)sock->impl); break; case SOCKET_STREAM: err = tcp_close((struct tcp_pcb *)sock->impl); break; default: return SOCKET_ERROR_BAD_FAMILY; } return lwipv4_socket_error_remap(err); }
/* close the file writen, disconnect and close the connection */ void tftp_cleanup_wr(struct udp_pcb *upcb, tftp_connection_args *args) { /* close the filesystem */ file_fclose(&file_CR); fs_umount(&efs2.myFs); /* Free the tftp_connection_args structure reserverd for */ mem_free(args); /* Disconnect the udp_pcb*/ udp_disconnect(upcb); /* close the connection */ udp_remove(upcb); /* reset the callback function */ udp_recv(UDPpcb, recv_callback_tftp, NULL); }
/****************************************************************************** * FunctionName : espconn_udp_disconnect * Description : A new incoming connection has been disconnected. * Parameters : espconn -- the espconn used to disconnect with host * Returns : none *******************************************************************************/ void ICACHE_FLASH_ATTR espconn_udp_disconnect(espconn_msg *pdiscon) { if (pdiscon == NULL) { return; } struct udp_pcb *upcb = pdiscon->pcommon.pcb; udp_disconnect(upcb); udp_remove(upcb); espconn_list_delete(&plink_active, pdiscon); os_free(pdiscon); pdiscon = NULL; }
void trans_Data(short* buf_ch1, short* buf_ch2, unsigned short num) { int i = 0; struct pbuf *p; for(; i < num; i++) { memcpy(&packData.sampl[4 * i], &buf_ch1[2 * i], 2 * sizeof(short)); memcpy(&packData.sampl[4 * i + 2], &buf_ch2[2 * i], 2 * sizeof(short)); } p = pbuf_alloc(PBUF_TRANSPORT, sizeof(packData), PBUF_POOL); if (p != NULL) { pbuf_take(p, &packData, sizeof(packData)); /* send udp data */ udp_connect(upcb_d, &BagAddr.BagIPaddr, BagAddr.port_d); udp_send(upcb_d, p); udp_disconnect(upcb_d); /* free pbuf */ pbuf_free(p); } }
static void do_disconnect(struct api_msg_msg *msg) { switch (msg->conn->type) { #if LWIP_UDP case NETCONN_UDPLITE: /* FALLTHROUGH */ case NETCONN_UDPNOCHKSUM: /* FALLTHROUGH */ case NETCONN_UDP: udp_disconnect(msg->conn->pcb.udp); break; #endif case NETCONN_TCP: break; } sys_mbox_post(msg->conn->mbox, NULL); }
/** * close - the function will close the file * * @param fd the file handle * * @return the result */ int _close(int fd) { struct socket *socket = (struct socket *)fd; int ret = -1; if (SOCK_STREAM == socket->type) { ret = tcp_close(socket->pcb); } else if (SOCK_PACKET == socket->type) { udp_disconnect(socket->pcb); ret = 0; } free(socket); return ret; }
void ICACHE_FLASH_ATTR dhcps_stop(void) { // struct netif * nif = eagle_lwip_getif(1); udp_disconnect(pcb_dhcps); udp_remove(pcb_dhcps); // nif->dhcp = NULL; list_node *pnode = NULL; list_node *pback_node = NULL; pnode = plist; while (pnode != NULL) { pback_node = pnode; pnode = pback_node->pnext; node_remove_from_list(&plist, pback_node); os_free(pback_node->pnode); pback_node->pnode = NULL; os_free(pback_node); pback_node = NULL; } dhcps_lease_flag = true; }
/** * Sends an generic or enterprise specific trap message. * * @param generic_trap is the trap code * @param eoid points to enterprise object identifier * @param specific_trap used for enterprise traps when generic_trap == 6 * @return ERR_OK when success, ERR_MEM if we're out of memory * * @note the caller is responsible for filling in outvb in the trap_msg * @note the use of the enterpise identifier field * is per RFC1215. * Use .iso.org.dod.internet.mgmt.mib-2.snmp for generic traps * and .iso.org.dod.internet.private.enterprises.yourenterprise * (sysObjectID) for specific traps. */ err_t snmp_send_trap(s8_t generic_trap, struct snmp_obj_id *eoid, s32_t specific_trap) { struct snmp_trap_dst *td; struct netif *dst_if; struct ip_addr dst_ip; struct pbuf *p; u16_t i,tot_len; for (i=0, td = &trap_dst[0]; i<SNMP_TRAP_DESTINATIONS; i++, td++) { if ((td->enable != 0) && (td->dip.addr != 0)) { /* network order trap destination */ trap_msg.dip.addr = td->dip.addr; /* lookup current source address for this dst */ dst_if = ip_route(&td->dip); dst_ip.addr = ntohl(dst_if->ip_addr.addr); trap_msg.sip_raw[0] = dst_ip.addr >> 24; trap_msg.sip_raw[1] = dst_ip.addr >> 16; trap_msg.sip_raw[2] = dst_ip.addr >> 8; trap_msg.sip_raw[3] = dst_ip.addr; trap_msg.gen_trap = generic_trap; trap_msg.spc_trap = specific_trap; if (generic_trap == SNMP_GENTRAP_ENTERPRISESPC) { /* enterprise-Specific trap */ trap_msg.enterprise = eoid; } else { /* generic (MIB-II) trap */ snmp_get_snmpgrpid_ptr(&trap_msg.enterprise); } snmp_get_sysuptime(&trap_msg.ts); /* pass 0, calculate length fields */ tot_len = snmp_varbind_list_sum(&trap_msg.outvb); tot_len = snmp_trap_header_sum(&trap_msg, tot_len); /* allocate pbuf(s) */ p = pbuf_alloc(PBUF_TRANSPORT, tot_len, PBUF_POOL); if (p != NULL) { u16_t ofs; /* pass 1, encode packet ino the pbuf(s) */ ofs = snmp_trap_header_enc(&trap_msg, p); snmp_varbind_list_enc(&trap_msg.outvb, p, ofs); snmp_inc_snmpouttraps(); snmp_inc_snmpoutpkts(); /** connect to the TRAP destination */ udp_connect(trap_msg.pcb, &trap_msg.dip, SNMP_TRAP_PORT); udp_send(trap_msg.pcb, p); /** disassociate remote address and port with this pcb */ udp_disconnect(trap_msg.pcb); pbuf_free(p); } else { return ERR_MEM; } } }
/** * Sends a 'getresponse' message to the request originator. * * @param m_stat points to the current message request state source * @return ERR_OK when success, ERR_MEM if we're out of memory * * @note the caller is responsible for filling in outvb in the m_stat * and provide error-status and index (except for tooBig errors) ... */ err_t snmp_send_response(struct snmp_msg_pstat *m_stat) { struct snmp_varbind_root emptyvb = {NULL, NULL, 0, 0, 0}; struct pbuf *p; u16_t tot_len; err_t err; /* pass 0, calculate length fields */ tot_len = snmp_varbind_list_sum(&m_stat->outvb); tot_len = snmp_resp_header_sum(m_stat, tot_len); /* try allocating pbuf(s) for complete response */ p = pbuf_alloc(PBUF_TRANSPORT, tot_len, PBUF_POOL); if (p == NULL) { LWIP_DEBUGF(SNMP_MSG_DEBUG, ("snmp_snd_response() tooBig\n")); /* can't construct reply, return error-status tooBig */ m_stat->error_status = SNMP_ES_TOOBIG; m_stat->error_index = 0; /* pass 0, recalculate lengths, for empty varbind-list */ tot_len = snmp_varbind_list_sum(&emptyvb); tot_len = snmp_resp_header_sum(m_stat, tot_len); /* retry allocation once for header and empty varbind-list */ p = pbuf_alloc(PBUF_TRANSPORT, tot_len, PBUF_POOL); } if (p != NULL) { /* first pbuf alloc try or retry alloc success */ u16_t ofs; LWIP_DEBUGF(SNMP_MSG_DEBUG, ("snmp_snd_response() p != NULL\n")); /* pass 1, size error, encode packet ino the pbuf(s) */ ofs = snmp_resp_header_enc(m_stat, p); if (m_stat->error_status == SNMP_ES_TOOBIG) { snmp_varbind_list_enc(&emptyvb, p, ofs); } else { snmp_varbind_list_enc(&m_stat->outvb, p, ofs); } switch (m_stat->error_status) { case SNMP_ES_TOOBIG: snmp_inc_snmpouttoobigs(); break; case SNMP_ES_NOSUCHNAME: snmp_inc_snmpoutnosuchnames(); break; case SNMP_ES_BADVALUE: snmp_inc_snmpoutbadvalues(); break; case SNMP_ES_GENERROR: snmp_inc_snmpoutgenerrs(); break; } snmp_inc_snmpoutgetresponses(); snmp_inc_snmpoutpkts(); /** @todo do we need separate rx and tx pcbs for threaded case? */ /** connect to the originating source */ udp_connect(m_stat->pcb, &m_stat->sip, m_stat->sp); err = udp_send(m_stat->pcb, p); if (err == ERR_MEM) { /** @todo release some memory, retry and return tooBig? tooMuchHassle? */ err = ERR_MEM; } else { err = ERR_OK; } /** disassociate remote address and port with this pcb */ udp_disconnect(m_stat->pcb); pbuf_free(p); LWIP_DEBUGF(SNMP_MSG_DEBUG, ("snmp_snd_response() done\n")); return err; } else { /* first pbuf alloc try or retry alloc failed very low on memory, couldn't return tooBig */ return ERR_MEM; } }
Boolean netInit(NetPath *netPath, RunTimeOpts *rtOpts, PtpClock *ptpClock) { int i; struct in_addr netAddr; char addrStr[NET_ADDRESS_LENGTH]; DBG("netInit\n"); /* Allocate tx buffer for the event port. */ netPath->eventTxBuf = pbuf_alloc(PBUF_TRANSPORT, PACKET_SIZE, PBUF_RAM); if(netPath->eventTxBuf == NULL) { PERROR("Failed to allocate Event Tx Buffer\n"); return FALSE; } /* Allocate tx buffer for the general port. */ netPath->generalTxBuf = pbuf_alloc(PBUF_TRANSPORT, PACKET_SIZE, PBUF_RAM); if(netPath->generalTxBuf == NULL) { PERROR("Failed to allocate Event Tx Buffer\n"); pbuf_free(netPath->eventTxBuf); return FALSE; } /* Open lwIP raw udp interfaces for the event port. */ netPath->eventPcb = udp_new(); if(netPath->eventPcb == NULL) { PERROR("Failed to open Event UDP PCB\n"); pbuf_free(netPath->eventTxBuf); pbuf_free(netPath->generalTxBuf); return FALSE; } /* Open lwIP raw udp interfaces for the general port. */ netPath->generalPcb = udp_new(); if(netPath->generalPcb == NULL) { PERROR("Failed to open General UDP PCB\n"); udp_remove(netPath->eventPcb); pbuf_free(netPath->eventTxBuf); pbuf_free(netPath->generalTxBuf); return FALSE; } /* Initialize the buffer queues. */ netQInit(&netPath->eventQ); netQInit(&netPath->generalQ); /* Configure network (broadcast/unicast) addresses. */ netPath->unicastAddr = 0; if(!lookupSubdomainAddress(rtOpts->subdomainName, addrStr)) { udp_disconnect(netPath->eventPcb); udp_disconnect(netPath->generalPcb); udp_remove(netPath->eventPcb); udp_remove(netPath->generalPcb); pbuf_free(netPath->eventTxBuf); pbuf_free(netPath->generalTxBuf); return FALSE; } if(!inet_aton(addrStr, &netAddr)) { ERROR("failed to encode multi-cast address: %s\n", addrStr); udp_disconnect(netPath->eventPcb); udp_disconnect(netPath->generalPcb); udp_remove(netPath->eventPcb); udp_remove(netPath->generalPcb); pbuf_free(netPath->eventTxBuf); pbuf_free(netPath->generalTxBuf); return FALSE; } netPath->multicastAddr = netAddr.s_addr; /* Setup subdomain address string. */ for(i = 0; i < SUBDOMAIN_ADDRESS_LENGTH; ++i) { ptpClock->subdomain_address[i] = (netAddr.s_addr >> (i * 8)) & 0xff; } /* Establish the appropriate UDP bindings/connections for events. */ udp_recv(netPath->eventPcb, eventRecv, netPath); udp_bind(netPath->eventPcb, IP_ADDR_ANY, PTP_EVENT_PORT); // udp_connect(netPath->eventPcb, IP_ADDR_ANY, PTP_EVENT_PORT); *(Integer16*)ptpClock->event_port_address = PTP_EVENT_PORT; /* Establish the appropriate UDP bindings/connections for general. */ udp_recv(netPath->generalPcb, generalRecv, netPath); udp_bind(netPath->generalPcb, IP_ADDR_ANY, PTP_GENERAL_PORT); // udp_connect(netPath->generalPcb, IP_ADDR_ANY, PTP_GENERAL_PORT); *(Integer16*)ptpClock->general_port_address = PTP_GENERAL_PORT; /* Return a success code. */ return TRUE; }
/** * @brief This function is called when an UDP datagrm has been received on the port UDP_PORT. * @param arg user supplied argument (udp_pcb.recv_arg) * @param pcb the udp_pcb which received data * @param p the packet buffer that was received * @param addr the remote IP address from which the packet was received * @param port the remote port from which the packet was received * @retval None */ void udp_server_callback(void *arg, struct udp_pcb *upcb, struct pbuf *p, struct ip_addr *addr, u16_t port) { struct tcp_pcb *pcb; uint8_t iptab[4]; uint8_t iptxt[20]; /* We have received the UDP Echo from a client */ /* read its IP address */ iptab[0] = (uint8_t)((uint32_t)(addr->addr) >> 24); iptab[1] = (uint8_t)((uint32_t)(addr->addr) >> 16); iptab[2] = (uint8_t)((uint32_t)(addr->addr) >> 8); iptab[3] = (uint8_t)((uint32_t)(addr->addr)); sprintf((char*)iptxt, "is: %d.%d.%d.%d ", iptab[3], iptab[2], iptab[1], iptab[0]); printf( "is: %d.%d.%d.%d ", iptab[3], iptab[2], iptab[1], iptab[0]); /* Connect to the remote client */ udp_connect(upcb, addr, UDP_CLIENT_PORT); /* Tell the client that we have accepted it */ udp_send(upcb,p); /* free the UDP connection, so we can accept new clients */ udp_disconnect(upcb); /* Bind the upcb to IP_ADDR_ANY address and the UDP_PORT port*/ /* Be ready to get a new request from another client */ udp_bind(upcb, IP_ADDR_ANY, UDP_SERVER_PORT); /* Set a receive callback for the upcb */ udp_recv(upcb, udp_server_callback, NULL); /* Create a new TCP control block */ pcb = tcp_new(); if(pcb !=NULL) { err_t err; /* Assign to the new pcb a local IP address and a port number */ err = tcp_bind(pcb, addr, TCP_SERVER_PORT); if(err != ERR_USE) { /* Set the connection to the LISTEN state */ pcb = tcp_listen(pcb); /* Specify the function to be called when a connection is established */ tcp_accept(pcb, tcp_server_accept); } else { /* We enter here if a conection to the addr IP address already exists */ /* so we don't need to establish a new one */ tcp_close(pcb); } } /* Free the p buffer */ pbuf_free(p); }