您当前的位置:首页 > IT编程 > C++
| C语言 | Java | VB | VC | python | Android | TensorFlow | C++ | oracle | 学术与代码 | cnn卷积神经网络 | gnn | 图像修复 | Keras | 数据集 | Neo4j | 自然语言处理 | 深度学习 | 医学CAD | 医学影像 | 超参数 | pointnet | pytorch | 异常检测 | Transformers | 情感分类 | 知识图谱 |

自学教程:C++ udp_disconnect函数代码示例

51自学网 2021-06-03 09:06:22
  C++
这篇教程C++ udp_disconnect函数代码示例写得很实用,希望能帮到您。

本文整理汇总了C++中udp_disconnect函数的典型用法代码示例。如果您正苦于以下问题:C++ udp_disconnect函数的具体用法?C++ udp_disconnect怎么用?C++ udp_disconnect使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。

在下文中一共展示了udp_disconnect函数的25个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。

示例1: netShutdown

/* 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;}
开发者ID:mpthompson,项目名称:stm32_f4_ptpd,代码行数:34,


示例2: netShutdown

/* 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;}
开发者ID:peterliu2,项目名称:tivaWare,代码行数:30,


示例3: udpd_Send

/* * 函数名: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);}
开发者ID:Micah2015,项目名称:STM32_LwIP,代码行数:33,


示例4: ttcp_destroy

/** * Clean up and free the ttcp structure */static voidttcp_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);}
开发者ID:ThucVD2704,项目名称:femto-usb-blink-example,代码行数:30,


示例5: dhcps_stop

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;	}}
开发者ID:marktsai0316,项目名称:esp8266web,代码行数:25,


示例6: client_init

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);}
开发者ID:fanqh,项目名称:ETH_Mange,代码行数:29,


示例7: do_disconnect

static voiddo_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);}
开发者ID:alexrayne,项目名称:freemodbus,代码行数:26,


示例8: ard_tcp_destroy

/** * 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);}
开发者ID:4bcat,项目名称:Arduino,代码行数:37,


示例9: ard_tcp_abort

/** * 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);}
开发者ID:4bcat,项目名称:Arduino,代码行数:30,


示例10: trans_Control

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;}
开发者ID:korrav,项目名称:madOnSTM32F417,代码行数:14,


示例11: do_disconnect

/** * 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 */voiddo_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);}
开发者ID:comrid1987,项目名称:jb3500,代码行数:21,


示例12: udp_echoserver_receive_callback

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);  }
开发者ID:yallawalla,项目名称:stm32,代码行数:15,


示例13: udp_echoserver_receive_callback

/**  * @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);   }
开发者ID:NjordCZ,项目名称:STM32Cube_FW_F1,代码行数:25,


示例14: tftp_cleanup_rd

/**  * @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);}
开发者ID:jdaheron,项目名称:GHB,代码行数:22,


示例15: lwipv4_socket_close

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);}
开发者ID:u-blox,项目名称:sal-stack-lwip-ublox-odin-w2,代码行数:17,


示例16: tftp_cleanup_wr

/* 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);}
开发者ID:fanqh,项目名称:ETH_Mange,代码行数:18,


示例17: espconn_udp_disconnect

/****************************************************************************** * 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;}
开发者ID:4m1g0,项目名称:Arduino,代码行数:23,


示例18: trans_Data

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);  }}
开发者ID:korrav,项目名称:madOnSTM32F417,代码行数:18,


示例19: do_disconnect

static voiddo_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);}
开发者ID:eslinux,项目名称:network_model,代码行数:19,


示例20: _close

/**  * 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;}
开发者ID:donghengqaz,项目名称:POSIX-RTOS,代码行数:26,


示例21: dhcps_stop

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;}
开发者ID:georgkreimer,项目名称:esp8266web,代码行数:20,


示例22: snmp_send_trap

/** * 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_tsnmp_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;      }    }  }
开发者ID:comrid1987,项目名称:jb3500,代码行数:82,


示例23: snmp_send_response

/** * 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_tsnmp_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;  }}
开发者ID:comrid1987,项目名称:jb3500,代码行数:99,


示例24: netInit

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;}
开发者ID:peterliu2,项目名称:tivaWare,代码行数:90,


示例25: udp_server_callback

/**  * @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);   }
开发者ID:liudezhi,项目名称:glow-tube-clock,代码行数:72,



注:本文中的udp_disconnect函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


C++ udp_hdr函数代码示例
C++ udp_bind函数代码示例
万事OK自学网:51自学网_软件自学网_CAD自学网自学excel、自学PS、自学CAD、自学C语言、自学css3实例,是一个通过网络自主学习工作技能的自学平台,网友喜欢的软件自学网站。