Home | History | Annotate | Download | only in core

Lines Matching defs:pcb

75  * finds a corresponding UDP PCB and hands over the pbuf to the pcbs
76 * recv function. If no pcb is found or the datagram is incorrect, the
79 * @param p pbuf to be demultiplexed to a UDP PCB.
87 struct udp_pcb *pcb, *prev;
136 pcb = NULL;
138 the dhcp module, no other UDP pcb may use the local UDP port DHCP_CLIENT_PORT */
142 if ((inp->dhcp != NULL) && (inp->dhcp->pcb != NULL)) {
145 - inp->dhcp->pcb->remote == ANY or iphdr->src */
146 if ((ip_addr_isany(&inp->dhcp->pcb->remote_ip) ||
147 ip_addr_cmp(&(inp->dhcp->pcb->remote_ip), &current_iphdr_src))) {
148 pcb = inp->dhcp->pcb;
158 /* Iterate through the UDP pcb list for a matching pcb.
160 * preferred. If no perfect match is found, the first unconnected pcb that
162 for (pcb = udp_pcbs; pcb != NULL; pcb = pcb->next) {
164 /* print the PCB local and remote address */
166 ("pcb (%"U16_F".%"U16_F".%"U16_F".%"U16_F", %"U16_F") --- "
168 ip4_addr1_16(&pcb->local_ip), ip4_addr2_16(&pcb->local_ip),
169 ip4_addr3_16(&pcb->local_ip), ip4_addr4_16(&pcb->local_ip), pcb->local_port,
170 ip4_addr1_16(&pcb->remote_ip), ip4_addr2_16(&pcb->remote_ip),
171 ip4_addr3_16(&pcb->remote_ip), ip4_addr4_16(&pcb->remote_ip), pcb->remote_port));
173 /* compare PCB local addr+port to UDP destination addr+port */
174 if ((pcb->local_port == dest) &&
175 ((!broadcast && ip_addr_isany(&pcb->local_ip)) ||
176 ip_addr_cmp(&(pcb->local_ip), &current_iphdr_dest) ||
181 (broadcast && (pcb->so_options & SOF_BROADCAST)))) {
187 ((pcb->flags & UDP_FLAGS_CONNECTED) == 0)) {
188 /* the first unconnected matching PCB */
189 uncon_pcb = pcb;
192 /* compare PCB remote addr+port to UDP source addr+port */
194 (pcb->remote_port == src) &&
195 (ip_addr_isany(&pcb->remote_ip) ||
196 ip_addr_cmp(&(pcb->remote_ip), &current_iphdr_src))) {
197 /* the first fully matching PCB */
199 /* move the pcb to the front of udp_pcbs so that is
201 prev->next = pcb->next;
202 pcb->next = udp_pcbs;
203 udp_pcbs = pcb;
209 prev = pcb;
211 /* no fully matching pcb found? then look for an unconnected pcb */
212 if (pcb == NULL) {
213 pcb = uncon_pcb;
218 if (pcb != NULL || ip_addr_cmp(&inp->ip_addr, &current_iphdr_dest)) {
277 if (pcb != NULL) {
281 ((pcb->so_options & SOF_REUSEADDR) != 0)) {
287 if (mpcb != pcb) {
288 /* compare PCB local addr+port to UDP destination addr+port */
328 if (pcb->recv != NULL) {
330 pcb->recv(pcb->recv_arg, pcb, p, ip_current_src_addr(), src);
365 * @param pcb UDP PCB used to send the data.
369 * stored in pcb. If the pcb is not bound to a port, it will
381 udp_send(struct udp_pcb *pcb, struct pbuf *p)
383 /* send to the packet using remote ip and port stored in the pcb */
384 return udp_sendto(pcb, p, &pcb->remote_ip, pcb->remote_port);
391 udp_send_chksum(struct udp_pcb *pcb, struct pbuf *p,
394 /* send to the packet using remote ip and port stored in the pcb */
395 return udp_sendto_chksum(pcb, p, &pcb->remote_ip, pcb->remote_port,
403 * @param pcb UDP PCB used to send the data.
408 * dst_ip & dst_port are expected to be in the same byte order as in the pcb.
410 * If the PCB already has a remote address association, it will
418 udp_sendto(struct udp_pcb *pcb, struct pbuf *p,
422 return udp_sendto_chksum(pcb, p, dst_ip, dst_port, 0, 0);
427 udp_sendto_chksum(struct udp_pcb *pcb, struct pbuf *p, ip_addr_t *dst_ip,
437 netif = ip_route((ip_addr_ismulticast(dst_ip))?(&(pcb->multicast_ip)):(dst_ip));
450 return udp_sendto_if_chksum(pcb, p, dst_ip, dst_port, netif, have_chksum, chksum);
452 return udp_sendto_if(pcb, p, dst_ip, dst_port, netif);
463 * @param pcb UDP PCB used to send the data.
469 * dst_ip & dst_port are expected to be in the same byte order as in the pcb.
476 udp_sendto_if(struct udp_pcb *pcb, struct pbuf *p,
480 return udp_sendto_if_chksum(pcb, p, dst_ip, dst_port, netif, 0, 0);
485 udp_sendto_if_chksum(struct udp_pcb *pcb, struct pbuf *p, ip_addr_t *dst_ip,
497 if ( ((pcb->so_options & SOF_BROADCAST) == 0) && ip_addr_isbroadcast(dst_ip, netif) ) {
499 ("udp_sendto_if: SOF_BROADCAST not enabled on pcb %p\n", (void *)pcb));
504 /* if the PCB is not yet bound to a port, bind it here */
505 if (pcb->local_port == 0) {
507 err = udp_bind(pcb, &pcb->local_ip, pcb->local_port);
540 udphdr->src = htons(pcb->local_port);
547 if (ip_addr_ismulticast(dst_ip) && ((pcb->flags & UDP_FLAGS_MULTICAST_LOOP) != 0)) {
553 /* PCB local address is IP_ANY_ADDR? */
554 if (ip_addr_isany(&pcb->local_ip)) {
558 /* check if UDP PCB local IP address is correct
560 if (!ip_addr_cmp(&(pcb->local_ip), &(netif->ip_addr))) {
570 /* use UDP PCB local IP address as source address */
571 src_ip = &(pcb->local_ip);
578 if (pcb->flags & UDP_FLAGS_UDPLITE) {
582 chklen_hdr = chklen = pcb->chksum_len_tx;
585 LWIP_DEBUGF(UDP_DEBUG, ("udp_send: UDP LITE pcb->chksum_len is illegal: %"U16_F"\n", chklen));
620 netif->addr_hint = &(pcb->addr_hint);
622 err = ip_output_if(q, src_ip, dst_ip, pcb->ttl, pcb->tos, IP_PROTO_UDPLITE, netif);
633 if ((pcb->flags & UDP_FLAGS_NOCHKSUM) == 0) {
659 netif->addr_hint = &(pcb->addr_hint);
661 err = ip_output_if(q, src_ip, dst_ip, pcb->ttl, pcb->tos, IP_PROTO_UDP, netif);
682 * Bind an UDP PCB.
684 * @param pcb UDP PCB to be bound with a local address ipaddr and port.
691 * ipaddr & port are expected to be in the same byte order as in the pcb.
696 * another UDP PCB.
701 udp_bind(struct udp_pcb *pcb, ip_addr_t *ipaddr, u16_t port)
711 /* Check for double bind and rebind of the same pcb */
713 /* is this UDP PCB already on active list? */
714 if (pcb == ipcb) {
715 /* pcb may occur at most once in active list */
717 /* pcb already in list, just rebind */
722 PCB is alread bound to, unless *all* PCBs with that port have tha
725 else if (((pcb->so_options & SOF_REUSEADDR) == 0) &&
728 /* port matches that of PCB in list and REUSEADDR not set -> reject */
736 /* other PCB already binds to this local IP and port */
738 ("udp_bind: local port %"U16_F" already bound by another pcb\n", port));
744 ip_addr_set(&pcb->local_ip, ipaddr);
763 /* go on with next udp pcb */
773 pcb->local_port = port;
774 snmp_insert_udpidx_tree(pcb);
775 /* pcb not active yet? */
777 /* place the PCB on the active list if not already there */
778 pcb->next = udp_pcbs;
779 udp_pcbs = pcb;
783 ip4_addr1_16(&pcb->local_ip), ip4_addr2_16(&pcb->local_ip),
784 ip4_addr3_16(&pcb->local_ip), ip4_addr4_16(&pcb->local_ip),
785 pcb->local_port));
789 * Connect an UDP PCB.
791 * This will associate the UDP PCB with the remote address.
793 * @param pcb UDP PCB to be connected with remote address ipaddr and port.
799 * ipaddr & port are expected to be in the same byte order as in the pcb.
801 * The udp pcb is bound to a random local port if not already bound.
806 udp_connect(struct udp_pcb *pcb, ip_addr_t *ipaddr, u16_t port)
810 if (pcb->local_port == 0) {
811 err_t err = udp_bind(pcb, &pcb->local_ip, pcb->local_port);
817 ip_addr_set(&pcb->remote_ip, ipaddr);
818 pcb->remote_port = port;
819 pcb->flags |= UDP_FLAGS_CONNECTED;
823 if (ip_addr_isany(&pcb->local_ip) && !ip_addr_isany(&pcb->remote_ip)) {
826 if ((netif = ip_route(&(pcb->remote_ip))) == NULL) {
827 LWIP_DEBUGF(UDP_DEBUG, ("udp_connect: No route to 0x%lx\n", pcb->remote_ip.addr));
831 /** TODO: this will bind the udp pcb locally, to the interface which
834 pcb->local_ip = netif->ip_addr;
835 } else if (ip_addr_isany(&pcb->remote_ip)) {
836 pcb->local_ip.addr = 0;
841 ip4_addr1_16(&pcb->local_ip), ip4_addr2_16(&pcb->local_ip),
842 ip4_addr3_16(&pcb->local_ip), ip4_addr4_16(&pcb->local_ip),
843 pcb->local_port));
845 /* Insert UDP PCB into the list of active UDP PCBs. */
847 if (pcb == ipcb) {
852 /* PCB not yet on the list, add PCB now */
853 pcb->next = udp_pcbs;
854 udp_pcbs = pcb;
859 * Disconnect a UDP PCB
861 * @param pcb the udp pcb to disconnect.
864 udp_disconnect(struct udp_pcb *pcb)
867 ip_addr_set_any(&pcb->remote_ip);
868 pcb->remote_port = 0;
869 /* mark PCB as unconnected */
870 pcb->flags &= ~UDP_FLAGS_CONNECTED;
874 * Set a receive callback for a UDP PCB
876 * This callback will be called when receiving a datagram for the pcb.
878 * @param pcb the pcb for wich to set the recv callback
883 udp_recv(struct udp_pcb *pcb, udp_recv_fn recv, void *recv_arg)
886 pcb->recv = recv;
887 pcb->recv_arg = recv_arg;
891 * Remove an UDP PCB.
893 * @param pcb UDP PCB to be removed. The PCB is removed from the list of
894 * UDP PCB's and the data structure is freed from memory.
899 udp_remove(struct udp_pcb *pcb)
903 snmp_delete_udpidx_tree(pcb);
904 /* pcb to be removed is first in list? */
905 if (udp_pcbs == pcb) {
906 /* make list start at 2nd pcb */
908 /* pcb not 1st in list */
911 /* find pcb in udp_pcbs list */
912 if (pcb2->next != NULL && pcb2->next == pcb) {
913 /* remove pcb from list */
914 pcb2->next = pcb->next;
918 memp_free(MEMP_UDP_PCB, pcb);
922 * Create a UDP PCB.
924 * @return The UDP PCB which was created. NULL if the PCB data structure
932 struct udp_pcb *pcb;
933 pcb = (struct udp_pcb *)memp_malloc(MEMP_UDP_PCB);
934 /* could allocate UDP PCB? */
935 if (pcb != NULL) {
939 /* initialize PCB to all zeroes */
940 memset(pcb, 0, sizeof(struct udp_pcb));
941 pcb->ttl = UDP_TTL;
943 return pcb;