struct uip_conn *uip_tcpactive(struct uip_tcpip_hdr *buf) { struct uip_conn *conn = (struct uip_conn *)g_active_tcp_connections.head; in_addr_t srcipaddr = uip_ip4addr_conv(buf->srcipaddr); while (conn) { /* Find an open connection matching the tcp input */ if (conn->tcpstateflags != UIP_CLOSED && buf->destport == conn->lport && buf->srcport == conn->rport && uip_ipaddr_cmp(srcipaddr, conn->ripaddr)) { /* Matching connection found.. break out of the loop and return a * reference to it. */ break; } /* Look at the next active connection */ conn = (struct uip_conn *)conn->node.flink; } return conn; }
struct uip_conn *uip_tcpaccept(struct uip_tcpip_hdr *buf) { struct uip_conn *conn = uip_tcpalloc(); if (conn) { /* Fill in the necessary fields for the new connection. */ conn->rto = UIP_RTO; conn->timer = UIP_RTO; conn->sa = 0; conn->sv = 4; conn->nrtx = 0; conn->lport = buf->destport; conn->rport = buf->srcport; conn->mss = UIP_TCP_INITIAL_MSS; uip_ipaddr_copy(conn->ripaddr, uip_ip4addr_conv(buf->srcipaddr)); conn->tcpstateflags = UIP_SYN_RCVD; uip_tcpinitsequence(conn->sndseq); conn->unacked = 1; #ifdef CONFIG_NET_TCP_WRITE_BUFFERS conn->expired = 0; conn->isn = 0; conn->sent = 0; #endif /* rcvseq should be the seqno from the incoming packet + 1. */ memcpy(conn->rcvseq, buf->seqno, 4); #ifdef CONFIG_NET_TCP_READAHEAD /* Initialize the list of TCP read-ahead buffers */ sq_init(&conn->readahead); #endif #ifdef CONFIG_NET_TCP_WRITE_BUFFERS /* Initialize the write buffer lists */ sq_init(&conn->write_q); sq_init(&conn->unacked_q); #endif /* And, finally, put the connection structure into the active list. * Interrupts should already be disabled in this context. */ dq_addlast(&conn->node, &g_active_tcp_connections); } return conn; }
static inline void recvfrom_udpsender(struct uip_driver_s *dev, struct recvfrom_s *pstate) { #ifdef CONFIG_NET_IPv6 FAR struct sockaddr_in6 *infrom = pstate->rf_from; #else FAR struct sockaddr_in *infrom = pstate->rf_from; #endif if (infrom) { infrom->sin_family = AF_INET; infrom->sin_port = UDPBUF->srcport; #ifdef CONFIG_NET_IPv6 uip_ipaddr_copy(infrom->sin6_addr.s6_addr, UDPBUF->srcipaddr); #else uip_ipaddr_copy(infrom->sin_addr.s_addr, uip_ip4addr_conv(UDPBUF->srcipaddr)); #endif } }
void arp_update(uint16_t *pipaddr, uint8_t *ethaddr) { struct arp_entry *tabptr = NULL; in_addr_t ipaddr = uip_ip4addr_conv(pipaddr); int i; /* Walk through the ARP mapping table and try to find an entry to * update. If none is found, the IP -> MAC address mapping is * inserted in the ARP table. */ for (i = 0; i < CONFIG_NET_ARPTAB_SIZE; ++i) { tabptr = &g_arptable[i]; /* Only check those entries that are actually in use. */ if (tabptr->at_ipaddr != 0) { /* Check if the source IP address of the incoming packet matches * the IP address in this ARP table entry. */ if (uip_ipaddr_cmp(ipaddr, tabptr->at_ipaddr)) { /* An old entry found, update this and return. */ memcpy(tabptr->at_ethaddr.ether_addr_octet, ethaddr, ETHER_ADDR_LEN); tabptr->at_time = g_arptime; return; } } } /* If we get here, no existing ARP table entry was found, so we create one. */ /* First, we try to find an unused entry in the ARP table. */ for (i = 0; i < CONFIG_NET_ARPTAB_SIZE; ++i) { tabptr = &g_arptable[i]; if (tabptr->at_ipaddr == 0) { break; } } /* If no unused entry is found, we try to find the oldest entry and * throw it away. */ if (i == CONFIG_NET_ARPTAB_SIZE) { uint8_t tmpage = 0; int j = 0; for (i = 0; i < CONFIG_NET_ARPTAB_SIZE; ++i) { tabptr = &g_arptable[i]; if (g_arptime - tabptr->at_time > tmpage) { tmpage = g_arptime - tabptr->at_time; j = i; } } i = j; tabptr = &g_arptable[i]; } /* Now, i is the ARP table entry which we will fill with the new * information. */ tabptr->at_ipaddr = ipaddr; memcpy(tabptr->at_ethaddr.ether_addr_octet, ethaddr, ETHER_ADDR_LEN); tabptr->at_time = g_arptime; }