Exemplo n.º 1
0
int
msa_send_pkt(msa_pkt_t *pkt, int sfd)
{
    byte_t *dt = 0;

    size_t dt_sz = 0;

    dt_sz = SIZEOF_pPKT_F(pkt);
    dt = malloc(dt_sz * sizeof(*dt));
    memset(dt, 0, dt_sz);
#if 0
    printf("sending...\n");
    printf("pkt.st: %d\n", (int) pkt->st);
    printf("pkt.id: %d\n", (int) pkt->id);
    printf("pkt.sz: %d\n", (int) pkt->sz);
    printf("pkt.da: %s\n\n", pkt->da);
#endif

    pack_pkt(pkt, dt);

    msa_send_all(sfd, dt, dt_sz);

    free(dt); dt = 0;
    return dt_sz;
}
Exemplo n.º 2
0
int run_test()
{
	test_assert_ret(setup_test() == 0);

	odp_packet_t pkt_valid_eth_no_ip =
		pack_pkt(pool, valid_eth_src_beef, valid_eth_dst, 0, 0, 64, 0);
	odp_packet_t pkt_valid_eth_valid_ip =
		pack_pkt(pool, valid_eth_src, valid_eth_dst, valid_ip_src, valid_ip_dst, 64, 1);
	odp_packet_t pkt_valid_eth_invalid_ip =
		pack_pkt(pool, valid_eth_src, valid_eth_dst, invalid_ip_src, valid_ip_dst, 64, 1);

	odp_packet_t pkt_invalid_eth_no_ip =
		pack_pkt(pool, invalid_eth_src, valid_eth_dst, 0, 0, 64, 0);
	odp_packet_t pkt_invalid_eth_valid_ip =
		pack_pkt(pool, invalid_eth_src, valid_eth_dst, valid_ip_src, valid_ip_dst, 64, 1);
	odp_packet_t pkt_invalid_eth_invalid_ip =
		pack_pkt(pool, invalid_eth_src, valid_eth_dst, invalid_ip_src, valid_ip_dst, 64, 1);

	send_recv(pkt_valid_eth_no_ip, 10, 10);
	send_recv(pkt_valid_eth_valid_ip, 10, 10);
	send_recv(pkt_valid_eth_invalid_ip, 10, 10);

	send_recv(pkt_invalid_eth_no_ip, 10, 0);
	send_recv(pkt_invalid_eth_valid_ip, 10, 10);
	send_recv(pkt_invalid_eth_invalid_ip, 10, 0);

	test_assert_ret(term_test() == 0);

	return 0;
}
Exemplo n.º 3
0
SAT_returnState tx_ecss(tc_tm_pkt *pkt) {
    int32_t ret = 0;
    uint16_t size = 0;
    SAT_returnState res;

    if(pkt == NULL){
      comms_rf_stats_frame_transmitted(&comms_stats, 0, SATR_ERROR);
      return SATR_ERROR;
    }

    res = pack_pkt(send_buf, pkt, &size);
    if(res != SATR_OK){
      comms_rf_stats_frame_transmitted(&comms_stats, 0, res);
      return ret;
    }

    ret = send_payload(send_buf, (size_t)size, 0,COMMS_DEFAULT_TIMEOUT_MS);
    if(ret < 1){
      return SATR_ERROR;
    }
    free_pkt (pkt);
    return SATR_OK;
}
Exemplo n.º 4
0
int git_pkt_parse_line(
	git_pkt **head, const char *line, const char **out, size_t bufflen)
{
	int ret;
	int32_t len;

	/* Not even enough for the length */
	if (bufflen > 0 && bufflen < PKT_LEN_SIZE)
		return GIT_EBUFS;

	len = parse_len(line);
	if (len < 0) {
		/*
		 * If we fail to parse the length, it might be because the
		 * server is trying to send us the packfile already.
		 */
		if (bufflen >= 4 && !git__prefixcmp(line, "PACK")) {
			giterr_clear();
			*out = line;
			return pack_pkt(head);
		}

		return (int)len;
	}

	/*
	 * If we were given a buffer length, then make sure there is
	 * enough in the buffer to satisfy this line
	 */
	if (bufflen > 0 && bufflen < (size_t)len)
		return GIT_EBUFS;

	/*
	 * The length has to be exactly 0 in case of a flush
	 * packet or greater than PKT_LEN_SIZE, as the decoded
	 * length includes its own encoded length of four bytes.
	 */
	if (len != 0 && len < PKT_LEN_SIZE)
		return GIT_ERROR;

	line += PKT_LEN_SIZE;
	/*
	 * The Git protocol does not specify empty lines as part
	 * of the protocol. Not knowing what to do with an empty
	 * line, we should return an error upon hitting one.
	 */
	if (len == PKT_LEN_SIZE) {
		giterr_set_str(GITERR_NET, "Invalid empty packet");
		return GIT_ERROR;
	}

	if (len == 0) { /* Flush pkt */
		*out = line;
		return flush_pkt(head);
	}

	len -= PKT_LEN_SIZE; /* the encoded length includes its own size */

	if (*line == GIT_SIDE_BAND_DATA)
		ret = data_pkt(head, line, len);
	else if (*line == GIT_SIDE_BAND_PROGRESS)
		ret = sideband_progress_pkt(head, line, len);
	else if (*line == GIT_SIDE_BAND_ERROR)
		ret = sideband_error_pkt(head, line, len);
	else if (!git__prefixcmp(line, "ACK"))
		ret = ack_pkt(head, line, len);
	else if (!git__prefixcmp(line, "NAK"))
		ret = nak_pkt(head);
	else if (!git__prefixcmp(line, "ERR "))
		ret = err_pkt(head, line, len);
	else if (*line == '#')
		ret = comment_pkt(head, line, len);
	else if (!git__prefixcmp(line, "ok"))
		ret = ok_pkt(head, line, len);
	else if (!git__prefixcmp(line, "ng"))
		ret = ng_pkt(head, line, len);
	else if (!git__prefixcmp(line, "unpack"))
		ret = unpack_pkt(head, line, len);
	else
		ret = ref_pkt(head, line, len);

	*out = line + len;

	return ret;
}
Exemplo n.º 5
0
int git_pkt_parse_line(
	git_pkt **head, const char *line, const char **out, size_t bufflen)
{
	int ret;
	int32_t len;

	/* Not even enough for the length */
	if (bufflen > 0 && bufflen < PKT_LEN_SIZE)
		return GIT_EBUFS;

	len = parse_len(line);
	if (len < 0) {
		/*
		 * If we fail to parse the length, it might be because the
		 * server is trying to send us the packfile already.
		 */
		if (bufflen >= 4 && !git__prefixcmp(line, "PACK")) {
			giterr_clear();
			*out = line;
			return pack_pkt(head);
		}

		return (int)len;
	}

	/*
	 * If we were given a buffer length, then make sure there is
	 * enough in the buffer to satisfy this line
	 */
	if (bufflen > 0 && bufflen < (size_t)len)
		return GIT_EBUFS;

	line += PKT_LEN_SIZE;
	/*
	 * TODO: How do we deal with empty lines? Try again? with the next
	 * line?
	 */
	if (len == PKT_LEN_SIZE) {
		*out = line;
		return 0;
	}

	if (len == 0) { /* Flush pkt */
		*out = line;
		return flush_pkt(head);
	}

	len -= PKT_LEN_SIZE; /* the encoded length includes its own size */

	/* Assming the minimal size is actually 4 */
	if (!git__prefixcmp(line, "ACK"))
		ret = ack_pkt(head, line, len);
	else if (!git__prefixcmp(line, "NAK"))
		ret = nak_pkt(head);
	else if (!git__prefixcmp(line, "ERR "))
		ret = err_pkt(head, line, len);
	else if (*line == '#')
		ret = comment_pkt(head, line, len);
	else
		ret = ref_pkt(head, line, len);

	*out = line + len;

	return ret;
}