Lines Matching defs:pcb

84 void set_udp_pcb_net_group(struct udp_pcb *pcb, struct net_group *group)
86 set_ippcb_net_group((struct ip_pcb *)pcb, group);
89 struct net_group *get_net_group_from_udp_pcb(struct udp_pcb *pcb)
91 return get_net_group_from_ippcb((struct ip_pcb *)pcb);
114 struct udp_pcb *pcb;
121 for (pcb = udp_pcbs; pcb != NULL; pcb = pcb->next) {
122 if (pcb->local_port == udp_port) {
132 /** Common code to see if the current input packet matches the pcb
135 * @param pcb pcb to check
141 udp_input_local_match(struct udp_pcb *pcb, struct netif *inp, u8_t broadcast)
146 LWIP_ASSERT("udp_input_local_match: invalid pcb", pcb != NULL);
150 if ((pcb->netif_idx != NETIF_NO_INDEX) &&
151 (pcb->netif_idx != netif_get_index(ip_data.current_input_netif))) {
156 if (IP_IS_ANY_TYPE_VAL(pcb->local_ip)) {
158 if ((broadcast != 0) && !ip_get_option(pcb, SOF_BROADCAST)) {
166 if (IP_ADDR_PCB_VERSION_MATCH_EXACT(pcb, ip_current_dest_addr())) {
172 if (ip_get_option(pcb, SOF_BROADCAST))
175 if (ip4_addr_isany(ip_2_ip4(&pcb->local_ip)) ||
177 ip4_addr_netcmp(ip_2_ip4(&pcb->local_ip), ip4_current_dest_addr(), netif_ip4_netmask(inp))) {
184 if (ip_addr_isany(&pcb->local_ip) || ip_addr_cmp(&pcb->local_ip, ip_current_dest_addr())) {
197 * recv function. If no pcb is found or the datagram is incorrect, the
208 struct udp_pcb *pcb, *prev;
260 pcb = NULL;
263 /* Iterate through the UDP pcb list for a matching pcb.
265 * preferred. If no perfect match is found, the first unconnected pcb that
267 for (pcb = udp_pcbs; pcb != NULL; pcb = pcb->next) {
269 LWIP_DEBUGF(UDP_DEBUG, ("pcb ("));
270 ip_addr_debug_print_val(UDP_DEBUG, pcb->local_ip);
271 LWIP_DEBUGF(UDP_DEBUG, (", %"U16_F") <-- (", pcb->local_port));
272 ip_addr_debug_print_val(UDP_DEBUG, pcb->remote_ip);
273 LWIP_DEBUGF(UDP_DEBUG, (", %"U16_F")\n", pcb->remote_port));
277 if (inp_net_group == get_net_group_from_udp_pcb(pcb) && (pcb->local_port == dest) &&
279 if ((pcb->local_port == dest) &&
281 (udp_input_local_match(pcb, inp, broadcast) != 0)) {
282 if ((pcb->flags & UDP_FLAGS_CONNECTED) == 0) {
285 uncon_pcb = pcb;
290 /* uncon_pcb does not match the input netif, check this pcb */
291 if (IP_IS_V4_VAL(pcb->local_ip) && ip4_addr_cmp(ip_2_ip4(&pcb->local_ip), netif_ip4_addr(inp))) {
293 uncon_pcb = pcb;
299 else if (!ip_addr_isany(&pcb->local_ip)) {
301 uncon_pcb = pcb;
307 if ((pcb->remote_port == src) &&
308 (ip_addr_isany_val(pcb->remote_ip) ||
309 ip_addr_cmp(&pcb->remote_ip, ip_current_src_addr()))) {
312 /* move the pcb to the front of udp_pcbs so that is
314 prev->next = pcb->next;
315 pcb->next = udp_pcbs;
316 udp_pcbs = pcb;
324 prev = pcb;
326 /* no fully matching pcb found? then look for an unconnected pcb */
327 if (pcb == NULL) {
328 pcb = uncon_pcb;
332 if (pcb != NULL) {
393 if (pcb != NULL) {
396 if (ip_get_option(pcb, SOF_REUSEADDR) &&
403 if (mpcb != pcb && inp_net_group == get_net_group_from_udp_pcb(mpcb)) {
405 if (mpcb != pcb) {
428 if (pcb->recv != NULL) {
430 pcb->recv(pcb->recv_arg, pcb, p, ip_current_src_addr(), src);
476 * @param pcb UDP PCB used to send the data.
480 * stored in pcb. If the pcb is not bound to a port, it will
493 udp_send(struct udp_pcb *pcb, struct pbuf *p)
495 LWIP_ERROR("udp_send: invalid pcb", pcb != NULL, return ERR_ARG);
498 if (IP_IS_ANY_TYPE_VAL(pcb->remote_ip)) {
502 /* send to the packet using remote ip and port stored in the pcb */
503 return udp_sendto(pcb, p, &pcb->remote_ip, pcb->remote_port);
511 udp_send_chksum(struct udp_pcb *pcb, struct pbuf *p,
514 LWIP_ERROR("udp_send_chksum: invalid pcb", pcb != NULL, return ERR_ARG);
517 if (IP_IS_ANY_TYPE_VAL(pcb->remote_ip)) {
521 /* send to the packet using remote ip and port stored in the pcb */
522 return udp_sendto_chksum(pcb, p, &pcb->remote_ip, pcb->remote_port,
531 * @param pcb UDP PCB used to send the data.
536 * dst_ip & dst_port are expected to be in the same byte order as in the pcb.
546 udp_sendto(struct udp_pcb *pcb, struct pbuf *p,
550 return udp_sendto_chksum(pcb, p, dst_ip, dst_port, 0, 0);
556 udp_sendto_chksum(struct udp_pcb *pcb, struct pbuf *p, const ip_addr_t *dst_ip,
562 LWIP_ERROR("udp_sendto: invalid pcb", pcb != NULL, return ERR_ARG);
566 if (!IP_ADDR_PCB_VERSION_MATCH(pcb, dst_ip)) {
573 struct net_group *group = get_net_group_from_udp_pcb(pcb);
576 if (pcb->netif_idx != NETIF_NO_INDEX) {
578 netif = netif_get_by_index(pcb->netif_idx, group);
580 netif = netif_get_by_index(pcb->netif_idx);
592 if (pcb->mcast_ifindex != NETIF_NO_INDEX) {
594 netif = netif_get_by_index(pcb->mcast_ifindex, group);
596 netif = netif_get_by_index(pcb->mcast_ifindex);
608 in pcb->mcast_ip4 that is used for routing. If this routing lookup
610 if (!ip4_addr_isany_val(pcb->mcast_ip4) &&
611 !ip4_addr_cmp(&pcb->mcast_ip4, IP4_ADDR_BROADCAST)) {
613 netif = ip4_route_src(ip_2_ip4(&pcb->local_ip), &pcb->mcast_ip4, group);
615 netif = ip4_route_src(ip_2_ip4(&pcb->local_ip), &pcb->mcast_ip4);
627 netif = ip_route(&pcb->local_ip, dst_ip, group);
629 netif = ip_route(&pcb->local_ip, dst_ip);
643 return udp_sendto_if_chksum(pcb, p, dst_ip, dst_port, netif, have_chksum, chksum);
645 return udp_sendto_if(pcb, p, dst_ip, dst_port, netif);
657 * @param pcb UDP PCB used to send the data.
663 * dst_ip & dst_port are expected to be in the same byte order as in the pcb.
670 udp_sendto_if(struct udp_pcb *pcb, struct pbuf *p,
674 return udp_sendto_if_chksum(pcb, p, dst_ip, dst_port, netif, 0, 0);
679 udp_sendto_if_chksum(struct udp_pcb *pcb, struct pbuf *p, const ip_addr_t *dst_ip,
686 LWIP_ERROR("udp_sendto_if: invalid pcb", pcb != NULL, return ERR_ARG);
691 if (!IP_ADDR_PCB_VERSION_MATCH(pcb, dst_ip)) {
698 if (ip6_addr_isany(ip_2_ip6(&pcb->local_ip)) ||
699 ip6_addr_ismulticast(ip_2_ip6(&pcb->local_ip))) {
707 if (netif_get_ip6_addr_match(netif, ip_2_ip6(&pcb->local_ip)) < 0) {
711 src_ip = &pcb->local_ip;
719 if (ip4_addr_isany(ip_2_ip4(&pcb->local_ip)) ||
720 ip4_addr_ismulticast(ip_2_ip4(&pcb->local_ip))) {
727 if (!ip4_addr_cmp(ip_2_ip4(&(pcb->local_ip)), netif_ip4_addr(netif))) {
732 src_ip = &pcb->local_ip;
736 return udp_sendto_if_src_chksum(pcb, p, dst_ip, dst_port, netif, have_chksum, chksum, src_ip);
738 return udp_sendto_if_src(pcb, p, dst_ip, dst_port, netif, src_ip);
745 udp_sendto_if_src(struct udp_pcb *pcb, struct pbuf *p,
749 return udp_sendto_if_src_chksum(pcb, p, dst_ip, dst_port, netif, 0, 0, src_ip);
754 udp_sendto_if_src_chksum(struct udp_pcb *pcb, struct pbuf *p, const ip_addr_t *dst_ip,
767 LWIP_ERROR("udp_sendto_if_src: invalid pcb", pcb != NULL, return ERR_ARG);
773 if (!IP_ADDR_PCB_VERSION_MATCH(pcb, src_ip) ||
774 !IP_ADDR_PCB_VERSION_MATCH(pcb, dst_ip)) {
780 if (!ip_get_option(pcb, SOF_BROADCAST) &&
786 ("udp_sendto_if: SOF_BROADCAST not enabled on pcb %p\n", (void *)pcb));
792 if (pcb->local_port == 0) {
794 err = udp_bind(pcb, &pcb->local_ip, pcb->local_port);
831 udphdr->src = lwip_htons(pcb->local_port);
838 if (((pcb->flags & UDP_FLAGS_MULTICAST_LOOP) != 0) && ip_addr_ismulticast(dst_ip)) {
847 if (pcb->flags & UDP_FLAGS_UDPLITE) {
851 chklen_hdr = chklen = pcb->chksum_len_tx;
854 LWIP_DEBUGF(UDP_DEBUG, ("udp_send: UDP LITE pcb->chksum_len is illegal: %"U16_F"\n", chklen));
901 if (IP_IS_V6(dst_ip) || (pcb->flags & UDP_FLAGS_NOCHKSUM) == 0) {
930 ttl = (ip_addr_ismulticast(dst_ip) ? udp_get_multicast_ttl(pcb) : pcb->ttl);
932 ttl = pcb->ttl;
938 NETIF_SET_HINTS(netif, &(pcb->netif_hints));
939 err = ip_output_if_src(q, src_ip, dst_ip, ttl, pcb->tos, ip_proto, netif);
961 * @param pcb UDP PCB to be bound with a local address ipaddr and port.
968 * ipaddr & port are expected to be in the same byte order as in the pcb.
978 udp_bind(struct udp_pcb *pcb, const ip_addr_t *ipaddr, u16_t port)
997 LWIP_ERROR("udp_bind: invalid pcb", pcb != NULL, return ERR_ARG);
1004 /* Check for double bind and rebind of the same pcb */
1007 if (pcb == ipcb) {
1036 if (pcb != ipcb && (get_net_group_from_udp_pcb(pcb) == get_net_group_from_udp_pcb(ipcb))) {
1038 if (pcb != ipcb) {
1044 if (!ip_get_option(pcb, SOF_REUSEADDR) ||
1059 ("udp_bind: local port %"U16_F" already bound by another pcb\n", port));
1067 ip_addr_set_ipaddr(&pcb->local_ip, ipaddr);
1069 pcb->local_port = port;
1070 mib2_udp_bind(pcb);
1071 /* pcb not active yet? */
1074 pcb->next = udp_pcbs;
1075 udp_pcbs = pcb;
1078 ip_addr_debug_print_val(UDP_DEBUG | LWIP_DBG_TRACE | LWIP_DBG_STATE, pcb->local_ip);
1079 LWIP_DEBUGF(UDP_DEBUG | LWIP_DBG_TRACE | LWIP_DBG_STATE, (", port %"U16_F")\n", pcb->local_port));
1090 * @param pcb UDP PCB to be bound.
1091 * @param netif netif to bind udp pcb to. Can be NULL.
1096 udp_bind_netif(struct udp_pcb *pcb, const struct netif *netif)
1101 pcb->netif_idx = netif_get_index(netif);
1103 pcb->netif_idx = NETIF_NO_INDEX;
1109 * Sets the remote end of the pcb. This function does not generate any
1110 * network traffic, but only sets the remote address of the pcb.
1112 * @param pcb UDP PCB to be connected with remote address ipaddr and port.
1118 * ipaddr & port are expected to be in the same byte order as in the pcb.
1120 * The udp pcb is bound to a random local port if not already bound.
1125 udp_connect(struct udp_pcb *pcb, const ip_addr_t *ipaddr, u16_t port)
1131 LWIP_ERROR("udp_connect: invalid pcb", pcb != NULL, return ERR_ARG);
1134 if (pcb->local_port == 0) {
1135 err_t err = udp_bind(pcb, &pcb->local_ip, pcb->local_port);
1141 ip_addr_set_ipaddr(&pcb->remote_ip, ipaddr);
1145 if (IP_IS_V6(&pcb->remote_ip) &&
1146 ip6_addr_lacks_zone(ip_2_ip6(&pcb->remote_ip), IP6_UNKNOWN)) {
1147 ip6_addr_select_zone(ip_2_ip6(&pcb->remote_ip), ip_2_ip6(&pcb->local_ip));
1151 pcb->remote_port = port;
1152 pcb->flags |= UDP_FLAGS_CONNECTED;
1156 pcb->remote_ip);
1157 LWIP_DEBUGF(UDP_DEBUG | LWIP_DBG_TRACE | LWIP_DBG_STATE, (", port %"U16_F")\n", pcb->remote_port));
1161 if (pcb == ipcb) {
1167 pcb->next = udp_pcbs;
1168 udp_pcbs = pcb;
1174 * Remove the remote end of the pcb. This function does not generate
1175 * any network traffic, but only removes the remote address of the pcb.
1177 * @param pcb the udp pcb to disconnect.
1180 udp_disconnect(struct udp_pcb *pcb)
1184 LWIP_ERROR("udp_disconnect: invalid pcb", pcb != NULL, return);
1188 if (IP_IS_ANY_TYPE_VAL(pcb->local_ip)) {
1189 ip_addr_copy(pcb->remote_ip, *IP_ANY_TYPE);
1192 ip_addr_set_any(IP_IS_V6_VAL(pcb->remote_ip), &pcb->remote_ip);
1196 pcb->remote_port = 0;
1197 pcb->netif_idx = NETIF_NO_INDEX;
1199 udp_clear_flags(pcb, UDP_FLAGS_CONNECTED);
1205 * This callback will be called when receiving a datagram for the pcb.
1207 * @param pcb the pcb for which to set the recv callback
1212 udp_recv(struct udp_pcb *pcb, udp_recv_fn recv, void *recv_arg)
1216 LWIP_ERROR("udp_recv: invalid pcb", pcb != NULL, return);
1219 pcb->recv = recv;
1220 pcb->recv_arg = recv_arg;
1225 * Removes and deallocates the pcb.
1227 * @param pcb UDP PCB to be removed. The PCB is removed from the list of
1233 udp_remove(struct udp_pcb *pcb)
1239 LWIP_ERROR("udp_remove: invalid pcb", pcb != NULL, return);
1241 mib2_udp_unbind(pcb);
1242 /* pcb to be removed is first in list? */
1243 if (udp_pcbs == pcb) {
1244 /* make list start at 2nd pcb */
1246 /* pcb not 1st in list */
1249 /* find pcb in udp_pcbs list */
1250 if (pcb2->next != NULL && pcb2->next == pcb) {
1251 /* remove pcb from list */
1252 pcb2->next = pcb->next;
1257 memp_free(MEMP_UDP_PCB, pcb);
1262 * Creates a new UDP pcb which can be used for UDP communication. The
1263 * pcb is not active until it has either been bound to a local address
1275 struct udp_pcb *pcb;
1279 pcb = (struct udp_pcb *)memp_malloc(MEMP_UDP_PCB);
1281 if (pcb != NULL) {
1286 memset(pcb, 0, sizeof(struct udp_pcb));
1287 pcb->ttl = UDP_TTL;
1289 udp_set_multicast_ttl(pcb, UDP_TTL);
1292 return pcb;
1298 * The pcb is not active until it has either been bound to a local address
1313 struct udp_pcb *pcb;
1317 pcb = udp_new();
1319 if (pcb != NULL) {
1320 IP_SET_TYPE_VAL(pcb->local_ip, type);
1321 IP_SET_TYPE_VAL(pcb->remote_ip, type);
1326 return pcb;