On this page
packet.copy_from
Encodes the fields of a struct variable back into the payload using the same layout string.
Syntax
Atlas Script
packet.copy_from(record, layout, offset?)Parameters
record- Struct variable whose fields the layout string names. packet.copy_to fills those fields from the packet; packet.copy_from writes them into the packet.
layout- Layout string listing struct fields in byte order, like "u8 kind; u16 sequence; i16 sticks[4]".
offsetOptional- Byte offset into the packet. Payload-relative for packet.* methods, and absolute (whole IP packet) for the raw_* variants.
Return value
See the remarks for the returned value and runtime behavior.
Remarks
Encodes the fields of a struct variable back into the payload using the same layout string. Array entries write the listed count of elements, using 0 for missing elements. Returns false, leaving the packet unchanged, when the layout is invalid, names a field the struct does not have, or would run past the end of the packet.
Examples
Decode a payload into a struct.atlas
struct Message {
var kind;
var sequence;
var flags;
};
const string LAYOUT = "u8 kind; u16be sequence; u16be flags";
Message message;
event on_start() {
if (!network.capture("udp and udp.DstPort == 9000")) {
system.log("Network capture could not start");
}
}
event on_network_send() {
if (packet.copy_to(message, LAYOUT) && message.kind == 0x02) {
message.flags = math.bit_or(message.flags, 0x0004);
if (!packet.copy_from(message, LAYOUT)) {
system.log("The payload no longer fits the layout");
}
}
}