Beispiel #1
0
/* simple fn for IP/Ethernet arp the most common */
struct pdu *arp_ie_simple_create(struct frame *framep, uint16_t oper, char *sha, char *spa, char *tha,
			    char *tpa)
{
	uint8_t bsha[6], btha[6];
	uint8_t bspa[4], btpa[4];

	/* convert strings */
	if (!parse_mac_string(sha, bsha)) 
		return NULL;
	if (!parse_mac_string(tha, btha))
		return NULL;
	if (!parse_ip_string(spa, bspa))
		return NULL;
	if (!parse_ip_string(tpa, btpa))
		return NULL;

	/* return results of arp_create */
	return arp_create(framep, ARP_HTYPE_ETHERNET, ETYPE_IP, 6, 4, oper, bsha, bspa,
			  btha, btpa);
}
Beispiel #2
0
int create_fwd_db_entry(char *input)
{
	int pos = 0;
	char *local;
	char *str;
	char *save;
	char *token;
	fwd_db_entry_t *entry = &fwd_db->array[fwd_db->index];

	/* Verify we haven't run out of space */
	if (MAX_DB <= fwd_db->index)
		return -1;

	/* Make a local copy */
	local = malloc(strlen(input) + 1);
	if (NULL == local)
		return -1;
	strcpy(local, input);

	/* Setup for using "strtok_r" to search input string */
	str = local;
	save = NULL;

	/* Parse tokens separated by ':' */
	while (NULL != (token = strtok_r(str, ":", &save))) {
		str = NULL;  /* reset str for subsequent strtok_r calls */

		/* Parse token based on its position */
		switch (pos) {
		case 0:
			parse_ipv4_string(token,
					  &entry->subnet.addr,
					  &entry->subnet.mask);
			break;
		case 1:
			strncpy(entry->oif, token, OIF_LEN - 1);
			entry->oif[OIF_LEN - 1] = 0;
			break;
		case 2:
			parse_mac_string(token, entry->dst_mac);
			break;
		default:
			printf("ERROR: extra token \"%s\" at position %d\n",
			       token, pos);
			break;
		}

		/* Advance to next position */
		pos++;
	}

	/* Verify we parsed exactly the number of tokens we expected */
	if (3 != pos) {
		printf("ERROR: \"%s\" contains %d tokens, expected 3\n",
		       input,
		       pos);
		free(local);
		return -1;
	}

	/* Reset queue to invalid */
	entry->queue = ODP_QUEUE_INVALID;

	/* Add route to the list */
	fwd_db->index++;
	entry->next = fwd_db->list;
	fwd_db->list = entry;

	free(local);
	return 0;
}