packet: Add helper function to create a clone without data
This commit is contained in:
@@ -144,8 +144,10 @@ METHOD(packet_t, destroy, void,
|
|||||||
free(this);
|
free(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
METHOD(packet_t, clone_, packet_t*,
|
/**
|
||||||
private_packet_t *this)
|
* Clone the packet with or without data
|
||||||
|
*/
|
||||||
|
static packet_t *clone_packet(private_packet_t *this, bool skip_data)
|
||||||
{
|
{
|
||||||
private_packet_t *other;
|
private_packet_t *other;
|
||||||
|
|
||||||
@@ -158,15 +160,30 @@ METHOD(packet_t, clone_, packet_t*,
|
|||||||
{
|
{
|
||||||
set_source(other, this->source->clone(this->source));
|
set_source(other, this->source->clone(this->source));
|
||||||
}
|
}
|
||||||
if (this->data.ptr)
|
other->metadata = metadata_set_clone(this->metadata);
|
||||||
|
set_dscp(other, this->dscp);
|
||||||
|
|
||||||
|
if (!skip_data && this->data.ptr)
|
||||||
{
|
{
|
||||||
set_data(other, chunk_clone(this->adjusted_data));
|
set_data(other, chunk_clone(this->adjusted_data));
|
||||||
}
|
}
|
||||||
other->metadata = metadata_set_clone(this->metadata);
|
|
||||||
set_dscp(other, this->dscp);
|
|
||||||
return &other->public;
|
return &other->public;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
METHOD(packet_t, clone_, packet_t*,
|
||||||
|
private_packet_t *this)
|
||||||
|
{
|
||||||
|
return clone_packet(this, FALSE);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Described in header
|
||||||
|
*/
|
||||||
|
packet_t *packet_clone_no_data(packet_t *packet)
|
||||||
|
{
|
||||||
|
return clone_packet((private_packet_t*)packet, TRUE);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Described in header.
|
* Described in header.
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -150,8 +150,16 @@ packet_t *packet_create();
|
|||||||
* @param src source address (gets owned)
|
* @param src source address (gets owned)
|
||||||
* @param dst destination address (gets owned)
|
* @param dst destination address (gets owned)
|
||||||
* @param data packet data (gets owned)
|
* @param data packet data (gets owned)
|
||||||
* @return packet_t object
|
* @return packet_t object
|
||||||
*/
|
*/
|
||||||
packet_t *packet_create_from_data(host_t *src, host_t *dst, chunk_t data);
|
packet_t *packet_create_from_data(host_t *src, host_t *dst, chunk_t data);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create a clone of the given packet but without data
|
||||||
|
*
|
||||||
|
* @param packet packet to clone
|
||||||
|
* @return cloned packet
|
||||||
|
*/
|
||||||
|
packet_t *packet_clone_no_data(packet_t *packet);
|
||||||
|
|
||||||
#endif /** PACKET_H_ @}*/
|
#endif /** PACKET_H_ @}*/
|
||||||
|
|||||||
Reference in New Issue
Block a user