static Eina_Bool _parser_cb(void *data, Eina_Simple_XML_Type type, const char *content, unsigned offset __UNUSED__, unsigned length) { EMap_Route *route = data; double d; struct tm time; time_t timet; char buf[length+1]; if(type == EINA_SIMPLE_XML_OPEN) { if(!strncmp(GPX_NAME, content, strlen(GPX_NAME))) { route->gpx.xml_is_name = EINA_TRUE; } else if(!strncmp(GPX_ELE, content, strlen(GPX_ELE))) { route->gpx.xml_is_ele = EINA_TRUE; } else if(!strncmp(GPX_TIME, content, strlen(GPX_TIME))) { route->gpx.xml_is_time = EINA_TRUE; } else if(!strncmp(GPX_COORDINATES, content, strlen(GPX_COORDINATES))) { EMap_Route_Node *node = emap_route_node_new(eina_list_count(route->nodes)); route->gpx.xml_current_node = node; emap_route_node_add(route, node); const char *tags = eina_simple_xml_tag_attributes_find(content, length); eina_simple_xml_attributes_parse(tags, length - (tags - content), _parser_attributes_cb, node); } } else if(type == EINA_SIMPLE_XML_DATA) { if(route->gpx.xml_is_name) { eina_stringshare_replace_length(&route->name, content, length); route->gpx.xml_is_name = EINA_FALSE; } else if(route->gpx.xml_is_ele) { sscanf(content, "%lf", &d); emap_route_node_elevation_set(route->gpx.xml_current_node, d); route->gpx.xml_is_ele = EINA_FALSE; } else if(route->gpx.xml_is_time) { snprintf(buf, length + 1, content); strptime(buf, "%Y-%m-%dT%H:%M:%S%Z", &time); timet = mktime(&time); emap_route_node_time_set(route->gpx.xml_current_node, timet); route->gpx.xml_is_time = EINA_FALSE; } } return EINA_TRUE; }
/** * @brief Scan an interface to cache its network addresses * @param net The net object to scan * @return EINA_TRUE on success, EINA_FALSE on failure * Use this function to scan and cache the ip address, netmask, and broadcast * address for an interface. This function will perform a full scan every time * it is called, and IPv6 addresses will be cached if Eeze was compiled with IPv6 * support was enabled at compile time. * @see eeze_net_addr_get() */ Eina_Bool eeze_net_scan(Eeze_Net *net) { char ip[INET_ADDRSTRLEN]; #ifdef HAVE_IPV6 char ip6[INET6_ADDRSTRLEN]; struct sockaddr_in6 *sa6; #endif int sock; int ioctls[3] = {SIOCGIFADDR, SIOCGIFBRDADDR, SIOCGIFNETMASK}, *i = ioctls; struct ifreq ifr; struct sockaddr_in *sa; EINA_SAFETY_ON_NULL_RETURN_VAL(net, EINA_FALSE); /* ensure that we have the right name, mostly for hahas */ if_indextoname((unsigned int)net->index, ifr.ifr_name); ifr.ifr_addr.sa_family = AF_INET; sock = socket(AF_INET, SOCK_DGRAM, 0); if (sock < 0) return EINA_FALSE; if (ioctl(sock, *i++, &ifr) < 0) goto error; sa = (struct sockaddr_in*) & (ifr.ifr_addr); inet_ntop(AF_INET, (struct in_addr*)&sa->sin_addr, ip, INET_ADDRSTRLEN); eina_stringshare_replace_length(&net->ip, ip, INET_ADDRSTRLEN); if (ioctl(sock, *i++, &ifr) < 0) goto error; sa = (struct sockaddr_in*) & (ifr.ifr_broadaddr); inet_ntop(AF_INET, (struct in_addr*)&sa->sin_addr, ip, INET_ADDRSTRLEN); eina_stringshare_replace_length(&net->broadip, ip, INET_ADDRSTRLEN); if (ioctl(sock, *i++, &ifr) < 0) goto error; sa = (struct sockaddr_in*) & (ifr.ifr_netmask); inet_ntop(AF_INET, (struct in_addr*)&sa->sin_addr, ip, INET_ADDRSTRLEN); eina_stringshare_replace_length(&net->netmask, ip, INET_ADDRSTRLEN); close(sock); #ifdef HAVE_IPV6 i = ioctls; ifr.ifr_addr.sa_family = AF_INET6; sock = socket(AF_INET6, SOCK_DGRAM, 0); if (sock < 0) return EINA_FALSE; if (ioctl(sock, *i++, &ifr) < 0) goto error; sa6 = (struct sockaddr_in6*) & (ifr.ifr_addr); inet_ntop(AF_INET6, (struct in6_addr*)&sa6->sin6_addr, ip6, INET6_ADDRSTRLEN); eina_stringshare_replace_length(&net->ip6, ip6, INET6_ADDRSTRLEN); if (ioctl(sock, *i++, &ifr) < 0) goto error; sa6 = (struct sockaddr_in6*) & (ifr.ifr_broadaddr); inet_ntop(AF_INET6, (struct in6_addr*)&sa6->sin6_addr, ip6, INET6_ADDRSTRLEN); eina_stringshare_replace_length(&net->broadip6, ip6, INET6_ADDRSTRLEN); if (ioctl(sock, *i++, &ifr) < 0) goto error; sa6 = (struct sockaddr_in6*) & (ifr.ifr_netmask); inet_ntop(AF_INET6, (struct in6_addr*)&sa6->sin6_addr, ip6, INET6_ADDRSTRLEN); eina_stringshare_replace_length(&net->netmask6, ip6, INET6_ADDRSTRLEN); close(sock); #endif return EINA_TRUE; error: close(sock); return EINA_FALSE; }