Ejemplo n.º 1
0
struct sctp_chunk *sctp_chunks_begin(struct packet *packet,
				     struct sctp_chunks_iterator *iter,
				     char **error)
{
	assert(*error == NULL);
	memset(iter, 0, sizeof(*iter));
	iter->current_chunk = packet_payload(packet);
	iter->packet_end = packet_end(packet);
	return get_current_chunk(iter, error);
}
Ejemplo n.º 2
0
static TypedValue* serialize_vars_helper(ActRec* ar) {
  auto wddxPacket = req::make<WddxPacket>(empty_string_variant_ref,
                                             true, true);
  int start_index = 0;
  for (int i = start_index; i < ar->numArgs(); i++) {
    auto const tv = getArg(ar, i);
    find_var_recursive(tv, wddxPacket);
  }
  Variant packet = wddxPacket->packet_end();
  return arReturn(ar, std::move(packet));
}
Ejemplo n.º 3
0
struct packet *packet_copy(struct packet *old_packet)
{
	int offset;

	/* Allocate a new packet and copy link layer header and IP datagram. */
	const u32 bytes_used = packet_end(old_packet) - old_packet->buffer;
	struct packet *packet = packet_new(bytes_used);
	memcpy(packet->buffer, old_packet->buffer, bytes_used);

	packet->ip_bytes = old_packet->ip_bytes;

	/* Set up layer 3 header pointer. */
	if (old_packet->ipv4 != NULL) {
		offset = (u8 *) old_packet->ipv4 - old_packet->buffer;
		packet->ipv4 = (struct ipv4 *) (packet->buffer + offset);
	} else if (old_packet->ipv6 != NULL) {
		offset = (u8 *) old_packet->ipv6 - old_packet->buffer;
		packet->ipv6 = (struct ipv6 *) (packet->buffer + offset);
	}

	/* Set up layer 4 header pointer. */
	if (old_packet->tcp != NULL) {
		offset = (u8 *)old_packet->tcp - old_packet->buffer;
		packet->tcp = (struct tcp *)(packet->buffer + offset);
	} else if (old_packet->udp != NULL) {
		offset = (u8 *)old_packet->udp - old_packet->buffer;
		packet->udp = (struct udp *)(packet->buffer + offset);
	} else if (old_packet->icmpv4 != NULL) {
		offset = (u8 *)old_packet->icmpv4 - old_packet->buffer;
		packet->icmpv4 = (struct icmpv4 *)(packet->buffer + offset);
	} else if (old_packet->icmpv6 != NULL) {
		offset = (u8 *)old_packet->icmpv6 - old_packet->buffer;
		packet->icmpv6 = (struct icmpv6 *)(packet->buffer + offset);
	}

	return packet;
}
Ejemplo n.º 4
0
/* Make a copy of the given old packet, but in the new copy reserve the
 * given number of bytes of headroom at the start of the packet->buffer.
 * This empty headroom can later be filled with outer packet headers.
 * A slow but simple model.
 */
static struct packet *packet_copy_with_headroom(struct packet *old_packet,
						int bytes_headroom)
{
	/* Allocate a new packet and copy link layer header and IP datagram. */
	const int bytes_used = packet_end(old_packet) - old_packet->buffer;
	assert(bytes_used >= 0);
	assert(bytes_used <= 128*1024);
	struct packet *packet = packet_new(bytes_headroom + bytes_used);
	u8 *old_base = old_packet->buffer;
	u8 *new_base = packet->buffer + bytes_headroom;

	memcpy(new_base, old_base, bytes_used);

	packet->ip_bytes	= old_packet->ip_bytes;
	packet->direction	= old_packet->direction;
	packet->time_usecs	= old_packet->time_usecs;
	packet->flags		= old_packet->flags;
	packet->ecn		= old_packet->ecn;
	packet->socket_script_fd = old_packet->socket_script_fd;

	packet_copy_headers(packet, old_packet, bytes_headroom);

	/* Set up layer 3 header pointer. */
	packet->ipv4	= offset_ptr(old_base, new_base, old_packet->ipv4);
	packet->ipv6	= offset_ptr(old_base, new_base, old_packet->ipv6);
	packet->tcp	= offset_ptr(old_base, new_base, old_packet->tcp);
	packet->udp	= offset_ptr(old_base, new_base, old_packet->udp);
	packet->icmpv4	= offset_ptr(old_base, new_base, old_packet->icmpv4);
	packet->icmpv6	= offset_ptr(old_base, new_base, old_packet->icmpv6);

	packet->tcp_ts_val	= offset_ptr(old_base, new_base,
					     old_packet->tcp_ts_val);
	packet->tcp_ts_ecr	= offset_ptr(old_base, new_base,
					     old_packet->tcp_ts_ecr);

	return packet;
}
Ejemplo n.º 5
0
static String HHVM_FUNCTION(wddx_serialize_value, const Variant& var,
                            const Variant& comment) {
  auto wddxPacket = req::make<WddxPacket>(comment, false, false);
  wddxPacket->serialize_value(var);
  return wddxPacket->packet_end();
}
Ejemplo n.º 6
0
static String HHVM_FUNCTION(wddx_packet_end, const Resource& packet_id) {
  auto wddxPacket = packet_id.getTyped<WddxPacket>();
  std::string packetString = wddxPacket->packet_end();
  return String(packetString);
}