示例#1
0
static struct router_info *router_image_router_add(struct router_image *router_image,
						   char *router_desc)
{
	struct list *list;
	struct router_info *router_info;

	router_info = router_image_router_get(router_image, router_desc);
	if (router_info)
		goto out;

	router_info = malloc(sizeof(struct router_info));
	if (!router_info)
		goto out;

	list = malloc(sizeof(struct list));
	if (!list)
		goto free_router;

	memset(list, 0, sizeof(struct list));
	memset(router_info, 0, sizeof(struct router_info));
	strcpy(router_info->router_name, router_desc);
	list->data = router_info;
	list->next = NULL;
	list_prepend(&router_image->router_list, list);
	goto out;

free_router:
	free(router_info);
	router_info = NULL;
out:
	return router_info;
}
示例#2
0
int router_types_detect_main(struct node *node, char *packet_buff, int packet_buff_len)
{
	const struct router_type **router_type;
	struct router_info *router_info;
	void *priv = node + 1;
	int ret = 0;

	for (router_type = router_types; *router_type; ++router_type) {
		if (!(*router_type)->detect_main)
			goto next;

		ret = (*router_type)->detect_main(priv, packet_buff, packet_buff_len);
		if (ret != 1)
			goto next;

		/* we detected a router that we have no image for */
		if ((*router_type)->image->file_size < 1) {
			fprintf(stderr, "[%02x:%02x:%02x:%02x:%02x:%02x]: is of type '%s' that we have no image for\n",
				node->his_mac_addr[0], node->his_mac_addr[1], node->his_mac_addr[2],
				node->his_mac_addr[3], node->his_mac_addr[4], node->his_mac_addr[5],
				(*router_type)->desc);

			node->status = NODE_STATUS_NO_FLASH;
			ret = 0;
			break;
		}

		if ((*router_type)->image->type == IMAGE_TYPE_CE) {
			router_info = router_image_router_get((*router_type)->image,
							      (char *)(*router_type)->desc);
			if (!router_info) {
				fprintf(stderr, "[%02x:%02x:%02x:%02x:%02x:%02x]: is of type '%s' that we have no image for\n",
					node->his_mac_addr[0], node->his_mac_addr[1], node->his_mac_addr[2],
					node->his_mac_addr[3], node->his_mac_addr[4], node->his_mac_addr[5],
					(*router_type)->desc);

				node->status = NODE_STATUS_NO_FLASH;
				ret = 0;
				break;
			}
		}

		our_mac_set(node);
		node->router_type = (struct router_type *)(*router_type);
		node->router_priv = priv;

#if defined(CLEAR_SCREEN)
#if defined(LINUX)
		if (num_nodes_flashed > 0)
			ret = system("clear");
#elif defined(WIN32)
		if (num_nodes_flashed > 0)
			ret = system("cls");
#else
#error CLEAR_SCREEN is not supported on your OS
#endif
		/* keep gcc happy by retrieving the return value of the system() call */
		ret = 1;
#endif

		fprintf(stderr, "[%02x:%02x:%02x:%02x:%02x:%02x]: type '%s router' detected\n",
			node->his_mac_addr[0], node->his_mac_addr[1], node->his_mac_addr[2],
			node->his_mac_addr[3], node->his_mac_addr[4], node->his_mac_addr[5],
			node->router_type->desc);

		if (!(*router_type)->detect_post)
			break;

		(*router_type)->detect_post(node, packet_buff, packet_buff_len);
		break;

next:
		priv = (char *)priv + (*router_type)->priv_size;
	}

	return ret;
}