Lines Matching refs:pcb

102   struct udp_pcb *pcb;
109 for(pcb = udp_pcbs; pcb != NULL; pcb = pcb->next) {
110 if (pcb->local_port == udp_port) {
127 /* go on with next udp pcb */
143 * recv function. If no pcb is found or the datagram is incorrect, the
154 struct udp_pcb *pcb, *prev;
203 pcb = NULL;
205 the dhcp module, no other UDP pcb may use the local UDP port DHCP_CLIENT_PORT */
209 if ((inp->dhcp != NULL) && (inp->dhcp->pcb != NULL)) {
212 - inp->dhcp->pcb->remote == ANY or iphdr->src */
213 if ((ip_addr_isany(&inp->dhcp->pcb->remote_ip) ||
214 ip_addr_cmp(&(inp->dhcp->pcb->remote_ip), &current_iphdr_src))) {
215 pcb = inp->dhcp->pcb;
225 /* Iterate through the UDP pcb list for a matching pcb.
227 * preferred. If no perfect match is found, the first unconnected pcb that
229 for (pcb = udp_pcbs; pcb != NULL; pcb = pcb->next) {
233 ("pcb (%"U16_F".%"U16_F".%"U16_F".%"U16_F", %"U16_F") --- "
235 ip4_addr1_16(&pcb->local_ip), ip4_addr2_16(&pcb->local_ip),
236 ip4_addr3_16(&pcb->local_ip), ip4_addr4_16(&pcb->local_ip), pcb->local_port,
237 ip4_addr1_16(&pcb->remote_ip), ip4_addr2_16(&pcb->remote_ip),
238 ip4_addr3_16(&pcb->remote_ip), ip4_addr4_16(&pcb->remote_ip), pcb->remote_port));
241 if (pcb->local_port == dest) {
243 (!broadcast && ip_addr_isany(&pcb->local_ip)) ||
244 ip_addr_cmp(&(pcb->local_ip), &current_iphdr_dest) ||
249 (broadcast && ip_get_option(pcb, SOF_BROADCAST) &&
250 (ip_addr_isany(&pcb->local_ip) ||
251 ip_addr_netcmp(&pcb->local_ip, ip_current_dest_addr(), &inp->netmask)))) {
254 (ip_addr_isany(&pcb->local_ip) ||
255 ip_addr_netcmp(&pcb->local_ip, ip_current_dest_addr(), &inp->netmask)))) {
259 ((pcb->flags & UDP_FLAGS_CONNECTED) == 0)) {
261 uncon_pcb = pcb;
267 (pcb->remote_port == src) &&
268 (ip_addr_isany(&pcb->remote_ip) ||
269 ip_addr_cmp(&(pcb->remote_ip), &current_iphdr_src))) {
272 /* move the pcb to the front of udp_pcbs so that is
274 prev->next = pcb->next;
275 pcb->next = udp_pcbs;
276 udp_pcbs = pcb;
282 prev = pcb;
284 /* no fully matching pcb found? then look for an unconnected pcb */
285 if (pcb == NULL) {
286 pcb = uncon_pcb;
291 if (pcb != NULL || ip_addr_cmp(&inp->ip_addr, &current_iphdr_dest)) {
350 if (pcb != NULL) {
354 ip_get_option(pcb, SOF_REUSEADDR)) {
360 if (mpcb != pcb) {
401 if (pcb->recv != NULL) {
403 pcb->recv(pcb->recv_arg, pcb, p, ip_current_src_addr(), src);
438 * @param pcb UDP PCB used to send the data.
442 * stored in pcb. If the pcb is not bound to a port, it will
454 udp_send(struct udp_pcb *pcb, struct pbuf *p)
456 /* send to the packet using remote ip and port stored in the pcb */
457 return udp_sendto(pcb, p, &pcb->remote_ip, pcb->remote_port);
464 udp_send_chksum(struct udp_pcb *pcb, struct pbuf *p,
467 /* send to the packet using remote ip and port stored in the pcb */
468 return udp_sendto_chksum(pcb, p, &pcb->remote_ip, pcb->remote_port,
476 * @param pcb UDP PCB used to send the data.
481 * dst_ip & dst_port are expected to be in the same byte order as in the pcb.
491 udp_sendto(struct udp_pcb *pcb, struct pbuf *p,
495 return udp_sendto_chksum(pcb, p, dst_ip, dst_port, 0, 0);
500 udp_sendto_chksum(struct udp_pcb *pcb, struct pbuf *p, ip_addr_t *dst_ip,
510 netif = ip_route((ip_addr_ismulticast(dst_ip))?(&(pcb->multicast_ip)):(dst_ip));
523 return udp_sendto_if_chksum(pcb, p, dst_ip, dst_port, netif, have_chksum, chksum);
525 return udp_sendto_if(pcb, p, dst_ip, dst_port, netif);
536 * @param pcb UDP PCB used to send the data.
542 * dst_ip & dst_port are expected to be in the same byte order as in the pcb.
549 udp_sendto_if(struct udp_pcb *pcb, struct pbuf *p,
553 return udp_sendto_if_chksum(pcb, p, dst_ip, dst_port, netif, 0, 0);
558 udp_sendto_if_chksum(struct udp_pcb *pcb, struct pbuf *p, ip_addr_t *dst_ip,
570 if (!ip_get_option(pcb, SOF_BROADCAST) && ip_addr_isbroadcast(dst_ip, netif)) {
572 ("udp_sendto_if: SOF_BROADCAST not enabled on pcb %p\n", (void *)pcb));
578 if (pcb->local_port == 0) {
580 err = udp_bind(pcb, &pcb->local_ip, pcb->local_port);
613 udphdr->src = htons(pcb->local_port);
620 if (ip_addr_ismulticast(dst_ip) && ((pcb->flags & UDP_FLAGS_MULTICAST_LOOP) != 0)) {
627 if (ip_addr_isany(&pcb->local_ip)) {
633 if (!ip_addr_cmp(&(pcb->local_ip), &(netif->ip_addr))) {
644 src_ip = &(pcb->local_ip);
651 if (pcb->flags & UDP_FLAGS_UDPLITE) {
655 chklen_hdr = chklen = pcb->chksum_len_tx;
658 LWIP_DEBUGF(UDP_DEBUG, ("udp_send: UDP LITE pcb->chksum_len is illegal: %"U16_F"\n", chklen));
692 NETIF_SET_HWADDRHINT(netif, &pcb->addr_hint);
693 err = ip_output_if(q, src_ip, dst_ip, pcb->ttl, pcb->tos, IP_PROTO_UDPLITE, netif);
702 if ((pcb->flags & UDP_FLAGS_NOCHKSUM) == 0) {
727 NETIF_SET_HWADDRHINT(netif, &pcb->addr_hint);
728 err = ip_output_if(q, src_ip, dst_ip, pcb->ttl, pcb->tos, IP_PROTO_UDP, netif);
749 * @param pcb UDP PCB to be bound with a local address ipaddr and port.
756 * ipaddr & port are expected to be in the same byte order as in the pcb.
766 udp_bind(struct udp_pcb *pcb, ip_addr_t *ipaddr, u16_t port)
776 /* Check for double bind and rebind of the same pcb */
779 if (pcb == ipcb) {
780 /* pcb may occur at most once in active list */
782 /* pcb already in list, just rebind */
790 else if (!ip_get_option(pcb, SOF_REUSEADDR) &&
803 ("udp_bind: local port %"U16_F" already bound by another pcb\n", port));
809 ip_addr_set(&pcb->local_ip, ipaddr);
820 pcb->local_port = port;
821 snmp_insert_udpidx_tree(pcb);
822 /* pcb not active yet? */
825 pcb->next = udp_pcbs;
826 udp_pcbs = pcb;
830 ip4_addr1_16(&pcb->local_ip), ip4_addr2_16(&pcb->local_ip),
831 ip4_addr3_16(&pcb->local_ip), ip4_addr4_16(&pcb->local_ip),
832 pcb->local_port));
840 * @param pcb UDP PCB to be connected with remote address ipaddr and port.
846 * ipaddr & port are expected to be in the same byte order as in the pcb.
848 * The udp pcb is bound to a random local port if not already bound.
853 udp_connect(struct udp_pcb *pcb, ip_addr_t *ipaddr, u16_t port)
857 if (pcb->local_port == 0) {
858 err_t err = udp_bind(pcb, &pcb->local_ip, pcb->local_port);
864 ip_addr_set(&pcb->remote_ip, ipaddr);
865 pcb->remote_port = port;
866 pcb->flags |= UDP_FLAGS_CONNECTED;
870 if (ip_addr_isany(&pcb->local_ip) && !ip_addr_isany(&pcb->remote_ip)) {
873 if ((netif = ip_route(&(pcb->remote_ip))) == NULL) {
874 LWIP_DEBUGF(UDP_DEBUG, ("udp_connect: No route to 0x%lx\n", pcb->remote_ip.addr));
878 /** TODO: this will bind the udp pcb locally, to the interface which
881 pcb->local_ip = netif->ip_addr;
882 } else if (ip_addr_isany(&pcb->remote_ip)) {
883 pcb->local_ip.addr = 0;
888 ip4_addr1_16(&pcb->local_ip), ip4_addr2_16(&pcb->local_ip),
889 ip4_addr3_16(&pcb->local_ip), ip4_addr4_16(&pcb->local_ip),
890 pcb->local_port));
894 if (pcb == ipcb) {
900 pcb->next = udp_pcbs;
901 udp_pcbs = pcb;
908 * @param pcb the udp pcb to disconnect.
911 udp_disconnect(struct udp_pcb *pcb)
914 ip_addr_set_any(&pcb->remote_ip);
915 pcb->remote_port = 0;
917 pcb->flags &= ~UDP_FLAGS_CONNECTED;
923 * This callback will be called when receiving a datagram for the pcb.
925 * @param pcb the pcb for wich to set the recv callback
930 udp_recv(struct udp_pcb *pcb, udp_recv_fn recv, void *recv_arg)
933 pcb->recv = recv;
934 pcb->recv_arg = recv_arg;
940 * @param pcb UDP PCB to be removed. The PCB is removed from the list of
946 udp_remove(struct udp_pcb *pcb)
950 snmp_delete_udpidx_tree(pcb);
951 /* pcb to be removed is first in list? */
952 if (udp_pcbs == pcb) {
953 /* make list start at 2nd pcb */
955 /* pcb not 1st in list */
958 /* find pcb in udp_pcbs list */
959 if (pcb2->next != NULL && pcb2->next == pcb) {
960 /* remove pcb from list */
961 pcb2->next = pcb->next;
965 memp_free(MEMP_UDP_PCB, pcb);
979 struct udp_pcb *pcb;
980 pcb = (struct udp_pcb *)memp_malloc(MEMP_UDP_PCB);
982 if (pcb != NULL) {
987 memset(pcb, 0, sizeof(struct udp_pcb));
988 pcb->ttl = UDP_TTL;
990 return pcb;