static int net_match_ipv4(FAR struct net_route_ipv4_s *route, FAR void *arg) { FAR struct route_match_ipv4_s *match = (FAR struct route_match_ipv4_s *)arg; /* To match, the masked target address must be the same, and the masks * must be the same. */ net_ipv4_dumproute("Comparing", route); ninfo("With:\n"); ninfo(" target=%08lx netmask=%08lx\n", htonl(match->target), htonl(match->netmask)); if (net_ipv4addr_maskcmp(route->target, match->target, match->netmask) && net_ipv4addr_cmp(route->netmask, match->netmask)) { /* They match.. a non-zero value to terminate the traversal. The last * value of index is the index to the matching entry. */ return 1; } /* Next time we are here, this will be the routing table index */ match->index++; return 0; }
int netdev_unregister(FAR struct net_driver_s *dev) { struct net_driver_s *prev; struct net_driver_s *curr; if (dev) { net_lock(); /* Find the device in the list of known network devices */ for (prev = NULL, curr = g_netdevices; curr && curr != dev; prev = curr, curr = curr->flink); /* Remove the device to the list of known network devices */ if (curr) { /* Where was the entry */ if (prev) { /* The entry was in the middle or at the end of the list */ prev->flink = curr->flink; } else { /* The entry was at the beginning of the list */ g_netdevices = curr->flink; } curr->flink = NULL; } #ifdef CONFIG_NETDEV_IFINDEX free_ifindex(dev->d_ifindex); #endif net_unlock(); #ifdef CONFIG_NET_ETHERNET ninfo("Unregistered MAC: %02x:%02x:%02x:%02x:%02x:%02x as dev: %s\n", dev->d_mac.ether.ether_addr_octet[0], dev->d_mac.ether.ether_addr_octet[1], dev->d_mac.ether.ether_addr_octet[2], dev->d_mac.ether.ether_addr_octet[3], dev->d_mac.ether.ether_addr_octet[4], dev->d_mac.ether.ether_addr_octet[5], dev->d_ifname); #else ninfo("Unregistered dev: %s\n", dev->d_ifname); #endif return OK; } return -EINVAL; }
void neighbor_add(FAR net_ipv6addr_t ipaddr, FAR struct neighbor_addr_s *addr) { uint8_t oldest_time; int oldest_ndx; int i; ninfo("Add neighbor: %04x:%04x:%04x:%04x:%04x:%04x:%04x:%04x\n", ntohs(ipaddr[0]), ntohs(ipaddr[1]), ntohs(ipaddr[2]), ntohs(ipaddr[3]), ntohs(ipaddr[4]), ntohs(ipaddr[5]), ntohs(ipaddr[6]), ntohs(ipaddr[7])); ninfo(" at: %02x:%02x:%02x:%02x:%02x:%02x\n", addr->na_addr.ether_addr_octet[0], addr->na_addr.ether_addr_octet[1], addr->na_addr.ether_addr_octet[2], addr->na_addr.ether_addr_octet[3], addr->na_addr.ether_addr_octet[4], addr->na_addr.ether_addr_octet[5]); /* Find the first unused entry or the oldest used entry. */ oldest_time = 0; oldest_ndx = 0; for (i = 0; i < CONFIG_NET_IPv6_NCONF_ENTRIES; ++i) { if (g_neighbors[i].ne_time == NEIGHBOR_MAXTIME) { oldest_ndx = i; break; } if (net_ipv6addr_cmp(g_neighbors[i].ne_ipaddr, ipaddr)) { oldest_ndx = i; break; } if (g_neighbors[i].ne_time > oldest_time) { oldest_ndx = i; oldest_time = g_neighbors[i].ne_time; } } /* Use the oldest or first free entry (either pointed to by the * "oldest_ndx" variable). */ g_neighbors[oldest_ndx].ne_time = 0; net_ipv6addr_copy(g_neighbors[oldest_ndx].ne_ipaddr, ipaddr); memcpy(&g_neighbors[oldest_ndx].ne_addr, addr, sizeof(struct neighbor_addr_s)); }
static void icmpv6_setaddresses(FAR struct net_driver_s *dev, const net_ipv6addr_t draddr, const net_ipv6addr_t prefix, unsigned int preflen) { unsigned int i; /* Make sure that the network is down before changing any addresses */ netdev_ifdown(dev); /* Create an address mask from the prefix */ if (preflen > 128) { preflen = 128; } net_ipv6_pref2mask(preflen, dev->d_ipv6netmask); ninfo("preflen=%d netmask=%04x:%04x:%04x:%04x:%04x:%04x:%04x:%04x\n", preflen, dev->d_ipv6netmask[0], dev->d_ipv6netmask[1], dev->d_ipv6netmask[2], dev->d_ipv6netmask[3], dev->d_ipv6netmask[4], dev->d_ipv6netmask[5], dev->d_ipv6netmask[6], dev->d_ipv6netmask[7]); /* Copy prefix to the current IPv6 address, applying the mask */ for (i = 0; i < 7; i++) { dev->d_ipv6addr[i] = (dev->d_ipv6addr[i] & ~dev->d_ipv6netmask[i]) | (prefix[i] & dev->d_ipv6netmask[i]); } ninfo("prefix=%04x:%04x:%04x:%04x:%04x:%04x:%04x:%04x\n", prefix[0], prefix[1], prefix[2], prefix[3], prefix[4], prefix[6], prefix[6], prefix[7]); ninfo("IP address=%04x:%04x:%04x:%04x:%04x:%04x:%04x:%04x\n", dev->d_ipv6addr[0], dev->d_ipv6addr[1], dev->d_ipv6addr[2], dev->d_ipv6addr[3], dev->d_ipv6addr[4], dev->d_ipv6addr[6], dev->d_ipv6addr[6], dev->d_ipv6addr[7]); /* Finally, copy the router address */ net_ipv6addr_copy(dev->d_ipv6draddr, draddr); ninfo("DR address=%04x:%04x:%04x:%04x:%04x:%04x:%04x:%04x\n", dev->d_ipv6draddr[0], dev->d_ipv6draddr[1], dev->d_ipv6draddr[2], dev->d_ipv6draddr[3], dev->d_ipv6draddr[4], dev->d_ipv6draddr[6], dev->d_ipv6draddr[6], dev->d_ipv6draddr[7]); }
void icmpv6_rnotify(FAR struct net_driver_s *dev, const net_ipv6addr_t draddr, const net_ipv6addr_t prefix, unsigned int preflen) { FAR struct icmpv6_rnotify_s *curr; ninfo("Notified\n"); /* Find an entry with the matching device name in the list of waiters */ for (curr = g_icmpv6_rwaiters; curr; curr = curr->rn_flink) { /* Does this entry match? If the result is okay, then we have * already notified this waiter and it has not yet taken the * entry from the list. */ if (curr->rn_result != OK && strncmp(curr->rn_ifname, dev->d_ifname, IFNAMSIZ) == 0) { /* Yes.. Set the new network addresses. */ icmpv6_setaddresses(dev, draddr, prefix, preflen); /* And signal the waiting, returning success */ curr->rn_result = OK; nxsem_post(&curr->rn_sem); break; } } }
void pkt_poll(FAR struct net_driver_s *dev, FAR struct pkt_conn_s *conn) { ninfo("IN\n"); /* Verify that the packet connection is valid */ if (conn) { /* Setup for the application callback */ dev->d_appdata = &dev->d_buf[NET_LL_HDRLEN(dev) + IPv4UDP_HDRLEN]; dev->d_len = 0; dev->d_sndlen = 0; /* Perform the application callback */ (void)pkt_callback(dev, conn, PKT_POLL); /* If the application has data to send, setup the UDP/IP header */ if (dev->d_sndlen > 0) { //devif_pkt_send(dev, conn); return; } } /* Make sure that d_len is zero meaning that there is nothing to be sent */ dev->d_len = 0; }
void arp_dump(FAR struct arp_hdr_s *arp) { ninfo(" HW type: %04x Protocol: %04x\n", arp->ah_hwtype, arp->ah_protocol); ninfo(" HW len: %02x Proto len: %02x Operation: %04x\n", arp->ah_hwlen, arp->ah_protolen, arp->ah_opcode); ninfo(" Sender MAC: %02x:%02x:%02x:%02x:%02x:%02x IP: %d.%d.%d.%d\n", arp->ah_shwaddr[0], arp->ah_shwaddr[1], arp->ah_shwaddr[2], arp->ah_shwaddr[3], arp->ah_shwaddr[4], arp->ah_shwaddr[5], arp->ah_sipaddr[0] & 0xff, arp->ah_sipaddr[0] >> 8, arp->ah_sipaddr[1] & 0xff, arp->ah_sipaddr[1] >> 8); ninfo(" Dest MAC: %02x:%02x:%02x:%02x:%02x:%02x IP: %d.%d.%d.%d\n", arp->ah_dhwaddr[0], arp->ah_dhwaddr[1], arp->ah_dhwaddr[2], arp->ah_dhwaddr[3], arp->ah_dhwaddr[4], arp->ah_dhwaddr[5], arp->ah_dipaddr[0] & 0xff, arp->ah_dipaddr[0] >> 8, arp->ah_dipaddr[1] & 0xff, arp->ah_dipaddr[1] >> 8); }
static void linger_clear_connection(ClientData client_data, struct timeval *nowP) { struct connect_s *conn; ninfo("Clear connection\n"); conn = (struct connect_s *) client_data.p; conn->linger_timer = NULL; really_clear_connection(conn); }
static inline uint16_t net_dataevent(FAR struct net_driver_s *dev, FAR struct udp_conn_s *conn, uint16_t flags) { uint16_t ret; #ifdef CONFIG_NET_UDP_READAHEAD uint8_t *buffer = dev->d_appdata; int buflen = dev->d_len; uint16_t recvlen; #endif ret = (flags & ~UDP_NEWDATA); /* Is there new data? With non-zero length? (Certain connection events * can have zero-length with UDP_NEWDATA set just to cause an ACK). */ ninfo("No receive on connection\n"); #ifdef CONFIG_NET_UDP_READAHEAD /* Save as the packet data as in the read-ahead buffer. NOTE that * partial packets will not be buffered. */ recvlen = udp_datahandler(dev, conn, buffer, buflen); if (recvlen < buflen) #endif { /* There is no handler to receive new data and there are no free * read-ahead buffers to retain the data -- drop the packet. */ ninfo("Dropped %d bytes\n", dev->d_len); #ifdef CONFIG_NET_STATISTICS g_netstats.udp.drop++; #endif } /* In any event, the new data has now been handled */ dev->d_len = 0; return ret; }
static void bcmf_ipv6multicast(FAR struct bcmf_dev_s *priv) { wlinfo("Entry\n"); FAR struct net_driver_s *dev; uint16_t tmp16; uint8_t mac[6]; /* For ICMPv6, we need to add the IPv6 multicast address * * For IPv6 multicast addresses, the Ethernet MAC is derived by * the four low-order octets OR'ed with the MAC 33:33:00:00:00:00, * so for example the IPv6 address FF02:DEAD:BEEF::1:3 would map * to the Ethernet MAC address 33:33:00:01:00:03. * * NOTES: This appears correct for the ICMPv6 Router Solicitation * Message, but the ICMPv6 Neighbor Solicitation message seems to * use 33:33:ff:01:00:03. */ mac[0] = 0x33; mac[1] = 0x33; dev = &priv->bc_dev; tmp16 = dev->d_ipv6addr[6]; mac[2] = 0xff; mac[3] = tmp16 >> 8; tmp16 = dev->d_ipv6addr[7]; mac[4] = tmp16 & 0xff; mac[5] = tmp16 >> 8; ninfo("IPv6 Multicast: %02x:%02x:%02x:%02x:%02x:%02x\n", mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]); (void)bcmf_addmac(dev, mac); #ifdef CONFIG_NET_ICMPv6_AUTOCONF /* Add the IPv6 all link-local nodes Ethernet address. This is the * address that we expect to receive ICMPv6 Router Advertisement * packets. */ (void)bcmf_addmac(dev, g_ipv6_ethallnodes.ether_addr_octet); #endif /* CONFIG_NET_ICMPv6_AUTOCONF */ #ifdef CONFIG_NET_ICMPv6_ROUTER /* Add the IPv6 all link-local routers Ethernet address. This is the * address that we expect to receive ICMPv6 Router Solicitation * packets. */ (void)bcmf_addmac(dev, g_ipv6_ethallrouters.ether_addr_octet); #endif /* CONFIG_NET_ICMPv6_ROUTER */ }
int ftpc_login(SESSION handle, FAR struct ftpc_login_s *login) { FAR struct ftpc_session_s *session = (FAR struct ftpc_session_s *)handle; int errcode; int ret; /* Verify that we are connected to a server */ if (!ftpc_connected(session)) { nerr("ERROR: Not connected\n"); errcode = ENOTCONN; goto errout_with_err; } /* Verify that we are not already logged in to the server */ if (ftpc_loggedin(session)) { nerr("ERROR: Already logged in\n"); errcode = EINVAL; goto errout_with_err; } /* Save the login parameter */ session->uname = ftpc_dequote(login->uname); session->pwd = ftpc_dequote(login->pwd); session->initrdir = ftpc_dequote(login->rdir); /* Is passive mode requested? */ FTPC_CLR_PASSIVE(session); if (login->pasv) { ninfo("Setting passive mode\n"); FTPC_SET_PASSIVE(session); } /* The (Re-)login to the server */ ret = ftpc_relogin(session); if (ret != OK) { nerr("ERROR: login failed: %d\n", errno); goto errout; } return OK; errout_with_err: set_errno(errcode); errout: return ERROR; }
static uint16_t arp_send_eventhandler(FAR struct net_driver_s *dev, FAR void *pvconn, FAR void *priv, uint16_t flags) { FAR struct arp_send_s *state = (FAR struct arp_send_s *)priv; ninfo("flags: %04x sent: %d\n", flags, state->snd_sent); if (state) { /* Check if the network is still up */ if ((flags & NETDEV_DOWN) != 0) { nerr("ERROR: Interface is down\n"); arp_send_terminate(state, -ENETUNREACH); return flags; } /* Check if the outgoing packet is available. It may have been claimed * by a send event handler serving a different thread -OR- if the * output buffer currently contains unprocessed incoming data. In * these cases we will just have to wait for the next polling cycle. */ if (dev->d_sndlen > 0 || (flags & PKT_NEWDATA) != 0) { /* Another thread has beat us sending data or the buffer is busy, * Check for a timeout. If not timed out, wait for the next * polling cycle and check again. */ /* REVISIT: No timeout. Just wait for the next polling cycle */ return flags; } /* It looks like we are good to send the data */ /* Copy the packet data into the device packet buffer and send it */ arp_format(dev, state->snd_ipaddr); /* Make sure no ARP request overwrites this ARP request. This * flag will be cleared in arp_out(). */ IFF_SET_NOARP(dev->d_flags); /* Don't allow any further call backs. */ arp_send_terminate(state, OK); } return flags; }
FAR struct igmp_group_s *igmp_grpalloc(FAR struct net_driver_s *dev, FAR const in_addr_t *addr) { FAR struct igmp_group_s *group; net_lock_t flags; ninfo("addr: %08x dev: %p\n", *addr, dev); if (up_interrupt_context()) { #if CONFIG_PREALLOC_IGMPGROUPS > 0 grpinfo("Use a pre-allocated group entry\n"); group = igmp_grpprealloc(); #else grperr("ERROR: Cannot allocate from interrupt handler\n"); group = NULL; #endif } else { grpinfo("Allocate from the heap\n"); group = igmp_grpheapalloc(); } grpinfo("group: %p\n", group); /* Check if we successfully allocated a group structure */ if (group) { /* Initialize the non-zero elements of the group structure */ net_ipv4addr_copy(group->grpaddr, *addr); sem_init(&group->sem, 0, 0); /* Initialize the group timer (but don't start it yet) */ group->wdog = wd_create(); DEBUGASSERT(group->wdog); /* Interrupts must be disabled in order to modify the group list */ flags = net_lock(); /* Add the group structure to the list in the device structure */ sq_addfirst((FAR sq_entry_t *)group, &dev->grplist); net_unlock(flags); } return group; }
static uint16_t tcp_poll_interrupt(FAR struct net_driver_s *dev, FAR void *conn, FAR void *pvpriv, uint16_t flags) { FAR struct tcp_poll_s *info = (FAR struct tcp_poll_s *)pvpriv; ninfo("flags: %04x\n", flags); DEBUGASSERT(!info || (info->psock && info->fds)); /* 'priv' might be null in some race conditions (?) */ if (info) { pollevent_t eventset = 0; /* Check for data or connection availability events. */ if ((flags & (TCP_NEWDATA | TCP_BACKLOG)) != 0) { eventset |= POLLIN & info->fds->events; } /* A poll is a sign that we are free to send data. */ if ((flags & TCP_POLL) != 0) { eventset |= (POLLOUT & info->fds->events); } /* Check for a loss of connection events. */ if ((flags & TCP_DISCONN_EVENTS) != 0) { /* Mark that the connection has been lost */ net_lostconnection(info->psock, flags); eventset |= (POLLERR | POLLHUP); } /* Awaken the caller of poll() if requested event occurred. */ if (eventset) { info->fds->revents |= eventset; sem_post(info->fds->sem); } } return flags; }
uint16_t ieee802154_callback(FAR struct radio_driver_s *radio, FAR struct ieee802154_conn_s *conn, uint16_t flags) { ninfo("flags: %04x\n", flags); /* Some sanity checking */ if (conn != NULL) { /* Perform the callback */ flags = devif_conn_event(&radio->r_dev, conn, flags, conn->list); } return flags; }
void UnparseFortran_type::unparseReferenceType(SgType* type, SgUnparse_Info& info) { SgReferenceType* ref_type = isSgReferenceType(type); ROSE_ASSERT(ref_type != NULL); /* special cases: ptr to array, int (*p) [10] */ /* ptr to function, int (*p)(int) */ /* ptr to ptr to .. int (**p) (int) */ SgUnparse_Info ninfo(info); if (isSgReferenceType(ref_type->get_base_type()) || isSgPointerType(ref_type->get_base_type()) || isSgArrayType(ref_type->get_base_type()) || isSgFunctionType(ref_type->get_base_type()) || isSgMemberFunctionType(ref_type->get_base_type()) || isSgModifierType(ref_type->get_base_type()) ) { ninfo.set_isReferenceToSomething(); } if (ninfo.isTypeFirstPart()) { unparseType(ref_type->get_base_type(), ninfo); // curprint("& /* reference */ "); curprint("&"); } else { if (ninfo.isTypeSecondPart()) { unparseType(ref_type->get_base_type(), ninfo); } else { SgUnparse_Info ninfo2(ninfo); ninfo2.set_isTypeFirstPart(); unparseType(ref_type, ninfo2); ninfo2.set_isTypeSecondPart(); unparseType(ref_type, ninfo2); } } }
status_t PeepsWindow::CreatePerson(entry_ref *ref) { if(!ref) return B_BAD_VALUE; // Creates a file called "New Person" in the People directory. If one already exists, then // we find it in the people list and show it BFile file; BString filename="/boot/home/people/"; filename+=TRANSLATE("New Person"); status_t status=file.SetTo("/boot/home/people/New Person", B_READ_WRITE | B_CREATE_FILE | B_FAIL_IF_EXISTS); if(status==B_OK) { BNodeInfo ninfo(&file); ninfo.SetType(PERSON_FILE_TYPE); file.Unset(); get_ref_for_path(filename.String(),ref); return B_OK; } switch(status) { case B_BAD_VALUE: printf("B_BAD_VALUE\n"); break; case B_ENTRY_NOT_FOUND: printf("B_ENTRY_NOT_FOUND\n"); break; case B_FILE_EXISTS: return B_FILE_EXISTS; case B_PERMISSION_DENIED: printf("B_PERMISSION_DENIED"); break; case B_NO_MEMORY: printf("B_NO_MEMORY\n"); break; default: printf("Some other error in PeepsWindow::CreatePerson\n"); break; } return status; }
int icmpv6_rwait(FAR struct icmpv6_rnotify_s *notify, FAR struct timespec *timeout) { struct timespec abstime; irqstate_t flags; int ret; ninfo("Waiting...\n"); /* And wait for the Neighbor Advertisement (or a timeout). Interrupts will * be re-enabled while we wait. */ flags = enter_critical_section(); DEBUGVERIFY(clock_gettime(CLOCK_REALTIME, &abstime)); abstime.tv_sec += timeout->tv_sec; abstime.tv_nsec += timeout->tv_nsec; if (abstime.tv_nsec >= 1000000000) { abstime.tv_sec++; abstime.tv_nsec -= 1000000000; } /* REVISIT: If net_timedwait() is awakened with signal, we will return * the wrong error code. */ (void)net_timedwait(¬ify->rn_sem, &abstime); ret = notify->rn_result; /* Remove our wait structure from the list (we may no longer be at the * head of the list). */ (void)icmpv6_rwait_cancel(notify); /* Re-enable interrupts and return the result of the wait */ leave_critical_section(flags); return ret; }
static int misoc_net_ifup(FAR struct net_driver_s *dev) { FAR struct misoc_net_driver_s *priv = (FAR struct misoc_net_driver_s *)dev->d_private; #ifdef CONFIG_NET_IPv4 ninfo("Bringing up: %d.%d.%d.%d\n", dev->d_ipaddr & 0xff, (dev->d_ipaddr >> 8) & 0xff, (dev->d_ipaddr >> 16) & 0xff, dev->d_ipaddr >> 24); #endif #ifdef CONFIG_NET_IPv6 ninfo("Bringing up: %04x:%04x:%04x:%04x:%04x:%04x:%04x:%04x\n", dev->d_ipv6addr[0], dev->d_ipv6addr[1], dev->d_ipv6addr[2], dev->d_ipv6addr[3], dev->d_ipv6addr[4], dev->d_ipv6addr[5], dev->d_ipv6addr[6], dev->d_ipv6addr[7]); #endif /* Initialize PHYs, the Ethernet interface, and setup up Ethernet interrupts */ /* Instantiate the MAC address from priv->misoc_net_dev.d_mac.ether.ether_addr_octet */ #ifdef CONFIG_NET_ICMPv6 /* Set up IPv6 multicast address filtering */ misoc_net_ipv6multicast(priv); #endif /* Set and activate a timer process */ (void)wd_start(priv->misoc_net_txpoll, MISOC_NET_WDDELAY, misoc_net_poll_expiry, 1, (wdparm_t)priv); priv->misoc_net_bifup = true; up_enable_irq(ETHMAC_INTERRUPT); /* Enable the RX Event Handler */ ethmac_sram_writer_ev_enable_write(1); return OK; }
void tiva_ethernetmac(struct ether_addr *ethaddr) { uint32_t user0; uint32_t user1; /* Get the current value of the user registers */ user0 = getreg32(TIVA_FLASH_USERREG0); user1 = getreg32(TIVA_FLASH_USERREG1); ninfo("user: %06x:%06x\n", user1 & 0x00ffffff, user0 & 0x00ffffff); DEBUGASSERT(user0 != 0xffffffff && user1 != 0xffffffff); /* Re-format that MAC address the way that the network expects to see it */ ethaddr->ether_addr_octet[0] = ((user0 >> 0) & 0xff); ethaddr->ether_addr_octet[1] = ((user0 >> 8) & 0xff); ethaddr->ether_addr_octet[2] = ((user0 >> 16) & 0xff); ethaddr->ether_addr_octet[3] = ((user1 >> 0) & 0xff); ethaddr->ether_addr_octet[4] = ((user1 >> 8) & 0xff); ethaddr->ether_addr_octet[5] = ((user1 >> 16) & 0xff); }
static int netdev_imsf_ioctl(FAR struct socket *psock, int cmd, FAR struct ip_msfilter *imsf) { FAR struct net_driver_s *dev; int ret = -EINVAL; ninfo("cmd: %d\n", cmd); /* Execute the command */ switch (cmd) { case SIOCSIPMSFILTER: /* Set source filter content */ { dev = netdev_imsfdev(imsf); if (dev) { if (imsf->imsf_fmode == MCAST_INCLUDE) { ret = igmp_joingroup(dev, &imsf->imsf_multiaddr); } else { DEBUGASSERT(imsf->imsf_fmode == MCAST_EXCLUDE); ret = igmp_leavegroup(dev, &imsf->imsf_multiaddr); } } } break; case SIOCGIPMSFILTER: /* Retrieve source filter addresses */ default: ret = -ENOTTY; break; } return ret; }
static int bcmf_ifup(FAR struct net_driver_s *dev) { wlinfo("Entry\n"); FAR struct bcmf_dev_s *priv = (FAR struct bcmf_dev_s *)dev->d_private; #ifdef CONFIG_NET_IPv4 ninfo("Bringing up: %d.%d.%d.%d\n", dev->d_ipaddr & 0xff, (dev->d_ipaddr >> 8) & 0xff, (dev->d_ipaddr >> 16) & 0xff, dev->d_ipaddr >> 24); #endif #ifdef CONFIG_NET_IPv6 ninfo("Bringing up: %04x:%04x:%04x:%04x:%04x:%04x:%04x:%04x\n", dev->d_ipv6addr[0], dev->d_ipv6addr[1], dev->d_ipv6addr[2], dev->d_ipv6addr[3], dev->d_ipv6addr[4], dev->d_ipv6addr[5], dev->d_ipv6addr[6], dev->d_ipv6addr[7]); #endif /* Initialize PHYs, the Ethernet interface, and setup up Ethernet interrupts */ /* Instantiate the MAC address from priv->bc_dev.d_mac.ether.ether_addr_octet */ #ifdef CONFIG_NET_ICMPv6 /* Set up IPv6 multicast address filtering */ bcmf_ipv6multicast(priv); #endif /* Set and activate a timer process */ (void)wd_start(priv->bc_txpoll, BCMF_WDDELAY, bcmf_poll_expiry, 1, (wdparm_t)priv); /* Enable the hardware interrupt */ priv->bc_bifup = true; return OK; }
uint16_t udp_callback(FAR struct net_driver_s *dev, FAR struct udp_conn_s *conn, uint16_t flags) { ninfo("flags: %04x\n", flags); /* Some sanity checking */ if (conn) { /* Perform the callback */ flags = devif_conn_event(dev, conn, flags, conn->list); if ((flags & UDP_NEWDATA) != 0) { /* Data was not handled.. dispose of it appropriately */ flags = net_dataevent(dev, conn, flags); } } return flags; }
int icmpv6_rwait_cancel(FAR struct icmpv6_rnotify_s *notify) { FAR struct icmpv6_rnotify_s *curr; FAR struct icmpv6_rnotify_s *prev; irqstate_t flags; int ret = -ENOENT; ninfo("Cancelling...\n"); /* Remove our wait structure from the list (we may no longer be at the * head of the list). */ flags = enter_critical_section(); for (prev = NULL, curr = g_icmpv6_rwaiters; curr && curr != notify; prev = curr, curr = curr->rn_flink); DEBUGASSERT(curr && curr == notify); if (curr) { if (prev) { prev->rn_flink = notify->rn_flink; } else { g_icmpv6_rwaiters = notify->rn_flink; } ret = OK; } leave_critical_section(flags); (void)nxsem_destroy(¬ify->rn_sem); return ret; }
void UnparseFortran_type::unparseFunctionType(SgType* type, SgUnparse_Info& info) { SgFunctionType* func_type = isSgFunctionType(type); ROSE_ASSERT (func_type != NULL); SgUnparse_Info ninfo(info); // DQ (1/24/2011): The case of a procedure type in Fortran is quite simple. // Note that test2011_28.f90 demonstrates an example of this. // curprint("procedure()"); curprint("procedure(), pointer"); #if 0 int needParen = 0; if (ninfo.isReferenceToSomething() || ninfo.isPointerToSomething()) { needParen=1; } // DQ (10/8/2004): Skip output of class definition for return type! C++ standard does not permit // a defining declaration within a return type, function parameter, or sizeof expression. ninfo.set_SkipClassDefinition(); if (ninfo.isTypeFirstPart()) { if (needParen) { ninfo.unset_isReferenceToSomething(); ninfo.unset_isPointerToSomething(); unparseType(func_type->get_return_type(), ninfo); curprint("("); } else { unparseType(func_type->get_return_type(), ninfo); } } else { if (ninfo.isTypeSecondPart()) { if (needParen) { curprint(")"); info.unset_isReferenceToSomething(); info.unset_isPointerToSomething(); } // print the arguments SgUnparse_Info ninfo2(info); ninfo2.unset_SkipBaseType(); ninfo2.unset_isTypeSecondPart(); ninfo2.unset_isTypeFirstPart(); curprint("("); SgTypePtrList::iterator p = func_type->get_arguments().begin(); while(p != func_type->get_arguments().end()) { // printf ("Output function argument ... \n"); unparseType(*p, ninfo2); p++; if (p != func_type->get_arguments().end()) { curprint(", "); } } curprint(")"); unparseType(func_type->get_return_type(), info); // catch the 2nd part of the rtype } else { ninfo.set_isTypeFirstPart(); unparseType(func_type, ninfo); ninfo.set_isTypeSecondPart(); unparseType(func_type, ninfo); } } #endif }
void UnparseFortran_type::unparsePointerType(SgType* type, SgUnparse_Info& info, bool printAttrs) { #if 0 // printf ("Inside of UnparserFort::unparsePointerType \n"); // cur << "\n/* Inside of UnparserFort::unparsePointerType */\n"; curprint ("\n! Inside of UnparserFort::unparsePointerType \n"); #endif // DQ (1/16/2011): Note that pointers in fortran are not expressed the same as in C/C++, are are // only a part of the type which is managed more directly using attributes in the variable declaration. // Not clear that we want to do anything here in the unparser... SgPointerType* pointer_type = isSgPointerType(type); ROSE_ASSERT(pointer_type != NULL); #if 0 /* special cases: ptr to array, int (*p) [10] */ /* ptr to function, int (*p)(int) */ /* ptr to ptr to .. int (**p) (int) */ if (isSgReferenceType(pointer_type->get_base_type()) || isSgPointerType(pointer_type->get_base_type()) || isSgArrayType(pointer_type->get_base_type()) || isSgFunctionType(pointer_type->get_base_type()) || isSgMemberFunctionType(pointer_type->get_base_type()) || isSgModifierType(pointer_type->get_base_type()) ) { info.set_isPointerToSomething(); } // If not isTypeFirstPart nor isTypeSecondPart this unparse call // is not controlled from the statement level but from the type level if (info.isTypeFirstPart() == true) { unparseType(pointer_type->get_base_type(), info); // DQ (9/21/2004): Moved this conditional into this branch (to fix test2004_93.C) // DQ (9/21/2004): I think we can assert this, and if so we can simplify the logic below ROSE_ASSERT(info.isTypeSecondPart() == false); curprint("*"); } else { if (info.isTypeSecondPart() == true) { unparseType(pointer_type->get_base_type(), info); } else { SgUnparse_Info ninfo(info); ninfo.set_isTypeFirstPart(); unparseType(pointer_type, ninfo); ninfo.set_isTypeSecondPart(); unparseType(pointer_type, ninfo); } } #else if (info.supressStrippedTypeName() == false) { // DQ (1/16/2011): We only want to output the name of the stripped type once! SgType* stripType = pointer_type->stripType(); unparseType(stripType, info); info.set_supressStrippedTypeName(); } curprint(type->get_isCoArray()? ", COPOINTER": ", POINTER"); // DQ (1/16/2011): Plus unparse the base type...(unless it will just output the stripped types name). if (pointer_type->get_base_type()->containsInternalTypes() == true) { unparseType(pointer_type->get_base_type(), info, printAttrs); } #endif #if 0 // printf ("Leaving of UnparserFort::unparsePointerType \n"); // cur << "\n/* Leaving of UnparserFort::unparsePointerType */\n"; curprint ("\n! Leaving UnparserFort::unparsePointerType \n"); #endif }
static int tcpecho_server(void) { int i, maxi, listenfd, connfd, sockfd; int nready; int ret; ssize_t n; char buf[TCPECHO_MAXLINE]; socklen_t clilen; bool stop = false; struct pollfd client[CONFIG_EXAMPLES_TCPECHO_NCONN]; struct sockaddr_in cliaddr, servaddr; listenfd = socket(AF_INET, SOCK_STREAM, 0); if (listenfd < 0) { perror("ERROR: failed to create socket.\n"); return ERROR; } bzero(&servaddr, sizeof(servaddr)); servaddr.sin_family = AF_INET; servaddr.sin_addr.s_addr = htonl(INADDR_ANY); servaddr.sin_port = htons(CONFIG_EXAMPLES_TCPECHO_PORT); ret = bind(listenfd, (struct sockaddr*)&servaddr, sizeof(servaddr)); if (ret < 0) { perror("ERROR: failed to bind socket.\n"); return ERROR; } ninfo("start listening on port: %d\n", CONFIG_EXAMPLES_TCPECHO_PORT); ret = listen(listenfd, CONFIG_EXAMPLES_TCPECHO_BACKLOG); if (ret < 0) { perror("ERROR: failed to start listening\n"); return ERROR; } client[0].fd = listenfd; client[0].events = POLLRDNORM; for (i = 1; i < CONFIG_EXAMPLES_TCPECHO_NCONN; i++) { client[i].fd = -1; /* -1 indicates available entry */ } maxi = 0; /* max index into client[] array */ while (!stop) { nready = poll(client, maxi+1, TCPECHO_POLLTIMEOUT); if (client[0].revents & POLLRDNORM) { /* new client connection */ clilen = sizeof(cliaddr); connfd = accept(listenfd, (struct sockaddr*)&cliaddr, &clilen); ninfo("new client: %s\n", inet_ntoa(cliaddr.sin_addr)); for (i = 1; i < CONFIG_EXAMPLES_TCPECHO_NCONN; i++) { if (client[i].fd < 0) { client[i].fd = connfd; /* save descriptor */ break; } } if (i == CONFIG_EXAMPLES_TCPECHO_NCONN) { perror("ERROR: too many clients"); return ERROR; } client[i].events = POLLRDNORM; if (i > maxi) { maxi = i; /* max index in client[] array */ } if (--nready <= 0) { continue; /* no more readable descriptors */ } } for (i = 1; i <= maxi; i++) { /* check all clients for data */ if ((sockfd = client[i].fd) < 0) { continue; } if (client[i].revents & (POLLRDNORM | POLLERR)) { if ( (n = read(sockfd, buf, TCPECHO_MAXLINE)) < 0) { if (errno == ECONNRESET) { /* connection reset by client */ nwarn("WARNING: client[%d] aborted connection\n", i); close(sockfd); client[i].fd = -1; } else { perror("ERROR: readline error\n"); close(sockfd); client[i].fd = -1; } } else if (n == 0) { /* connection closed by client */ nwarn("WARNING: client[%d] closed connection\n", i); close(sockfd); client[i].fd = -1; } else { if (strcmp(buf, "exit\r\n") == 0) { nwarn("WARNING: client[%d] closed connection\n", i); close(sockfd); client[i].fd = -1; } else { write(sockfd, buf, n); } } if (--nready <= 0) { break; /* no more readable descriptors */ } } } } for (i = 0; i <= maxi; i++) { if (client[i].fd < 0) { continue; } close(client[i].fd); } return ret; }
FAR struct iob_s *iob_trimtail(FAR struct iob_s *iob, unsigned int trimlen) { FAR struct iob_s *entry; FAR struct iob_s *penultimate; FAR struct iob_s *last; int len; ninfo("iob=%p pktlen=%d trimlen=%d\n", iob, iob->io_pktlen, trimlen); if (iob && trimlen > 0) { len = trimlen; /* Loop until complete the trim */ while (len > 0) { /* Calculate the total length of the data in the I/O buffer * chain and find the last entry in the chain. */ penultimate = NULL; last = NULL; for (entry = iob; entry; entry = entry->io_flink) { /* Remember the last and the next to the last in the chain */ penultimate = last; last = entry; } /* Trim from the last entry in the chain. Do we trim this entire * I/O buffer away? */ ninfo("iob=%p len=%d vs %d\n", last, last->io_len, len); if (last->io_len <= len) { /* Yes.. Consume the entire buffer */ iob->io_pktlen -= last->io_len; len -= last->io_len; last->io_len = 0; /* Free the last, empty buffer in the list */ iob_free(last); /* There should be a buffer before this one */ if (!penultimate) { /* No.. we just freed the head of the chain */ return NULL; } /* Unlink the penultimate from the freed buffer */ penultimate->io_flink = NULL; } else { /* No, then just take what we need from this I/O buffer and * stop the trim. */ iob->io_pktlen -= len; last->io_len -= len; len = 0; } } } return iob; }
static int iob_copyin_internal(FAR struct iob_s *iob, FAR const uint8_t *src, unsigned int len, unsigned int offset, bool throttled, bool can_block) { FAR struct iob_s *head = iob; FAR struct iob_s *next; FAR uint8_t *dest; unsigned int ncopy; unsigned int avail; unsigned int total = len; ninfo("iob=%p len=%u offset=%u\n", iob, len, offset); DEBUGASSERT(iob && src); /* The offset must applied to data that is already in the I/O buffer chain */ if (offset > iob->io_pktlen) { nerr("ERROR: offset is past the end of data: %u > %u\n", offset, iob->io_pktlen); return -ESPIPE; } /* Skip to the I/O buffer containing the data offset */ while (offset > iob->io_len) { offset -= iob->io_len; iob = iob->io_flink; } /* Then loop until all of the I/O data is copied from the user buffer */ while (len > 0) { next = iob->io_flink; /* Get the destination I/O buffer address and the amount of data * available from that address. */ dest = &iob->io_data[iob->io_offset + offset]; avail = iob->io_len - offset; ninfo("iob=%p avail=%u len=%u next=%p\n", iob, avail, len, next); /* Will the rest of the copy fit into this buffer, overwriting * existing data. */ if (len > avail) { /* No.. Is this the last buffer in the chain? */ if (next) { /* No.. clip to size that will overwrite. We cannot * extend the length of an I/O block in mid-chain. */ ncopy = avail; } else { unsigned int maxlen; unsigned int newlen; /* Yes.. We can extend this buffer to the up to the very end. */ maxlen = CONFIG_IOB_BUFSIZE - iob->io_offset; /* This is the new buffer length that we need. Of course, * clipped to the maximum possible size in this buffer. */ newlen = len + offset; if (newlen > maxlen) { newlen = maxlen; } /* Set the new length and increment the packet length */ head->io_pktlen += (newlen - iob->io_len); iob->io_len = newlen; /* Set the new number of bytes to copy */ ncopy = newlen - offset; } } else { /* Yes.. Copy all of the remaining bytes */ ncopy = len; } /* Copy from the user buffer to the I/O buffer. */ memcpy(dest, src, ncopy); ninfo("iob=%p Copy %u bytes new len=%u\n", iob, ncopy, iob->io_len); /* Adjust the total length of the copy and the destination address in * the user buffer. */ len -= ncopy; src += ncopy; /* Skip to the next I/O buffer in the chain. First, check if we * are at the end of the buffer chain. */ if (len > 0 && !next) { /* Yes.. allocate a new buffer. * * Copy as many bytes as possible. If we have successfully copied * any already don't block, otherwise block if we're allowed. */ if (!can_block || len < total) { next = iob_tryalloc(throttled); } else { next = iob_alloc(throttled); } if (next == NULL) { nerr("ERROR: Failed to allocate I/O buffer\n"); return len; } /* Add the new, empty I/O buffer to the end of the buffer chain. */ iob->io_flink = next; ninfo("iob=%p added to the chain\n", iob); } iob = next; offset = 0; } return 0; }
int net_foreachroute_ipv4(route_handler_ipv4_t handler, FAR void *arg) { struct net_route_ipv4_s route; struct file fshandle; ssize_t nread; int ret = 0; /* Open the IPv4 routing table for read-only access */ ret = net_openroute_ipv4(O_RDONLY, &fshandle); if (ret < 0) { /* Special case: the routing table has not yet been created. This is * not an error. We will just want to return successful completion of * the traversal. */ if (ret == -ENOENT) { /* The routing table does not exit.. return successful completion */ ninfo("The IPv4 routing table file does not exist\n"); return OK; } /* Some other error occurred. */ nerr("ERROR: Could not open IPv4 routing table: %d\n", ret); return ret; } /* Read each entry from the routing table */ for (; ; ) { nread = net_readroute_ipv4(&fshandle, &route); if (nread < 0) { /* File read error */ nerr("ERROR: net_readroute_ipv4() failed: %ld\n", (long)nread); ret = (int)nread; break; } else if (nread == 0) { /* End of file */ ret = OK; break; } /* Call the handler. */ ret = handler(&route, arg); if (ret != OK) { /* Terminate early if the handler returns any non-zero value. */ break; } } (void)net_closeroute_ipv4(&fshandle); return ret; }