Skip to content

Commit

Permalink
Merge PR #999 (core.packet: add clone_to_memory) into max-next
Browse files Browse the repository at this point in the history
  • Loading branch information
eugeneia committed Aug 24, 2016
2 parents 28ca600 + ee57dae commit 2a6fea9
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
6 changes: 5 additions & 1 deletion src/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -387,7 +387,7 @@ or equal to `length` of *packet*.

— Function **packet.shiftright** *packet*, *length*

Move *packet* payload to the right by *length* bytes, growing *packet* by
Moves *packet* payload to the right by *length* bytes, growing *packet* by
*length*. The sum of *length* and `length` of *packet* must be less than or
equal to `packet.max_payload`.

Expand All @@ -399,6 +399,10 @@ Allocate packet and fill it with *length* bytes from *pointer*.

Allocate packet and fill it with the contents of *string*.

— Function **packet.clone_to_memory* *pointer* *packet*

Creates an exact copy of at memory pointed to by *pointer*. *Pointer* must
point to a `packet.packet_t`.

## Memory (core.memory)

Expand Down
11 changes: 8 additions & 3 deletions src/core/packet.lua
Original file line number Diff line number Diff line change
Expand Up @@ -71,12 +71,17 @@ function new_packet ()
return p
end

-- Create an exact copy of srcp at memory pointed to by dstp.
function clone_to_memory(dstp, srcp)
ffi.copy(dstp, srcp, srcp.length)
dstp.length = srcp.length
return dstp
end

-- Create an exact copy of a packet.
function clone (p)
local p2 = allocate()
ffi.copy(p2, p, p.length)
p2.length = p.length
return p2
return clone_to_memory(p2, p)
end

-- Append data to the end of a packet.
Expand Down

0 comments on commit 2a6fea9

Please sign in to comment.