mtcp_setlastpkt
NAME
mtcp_setlastpkt − modifies the last Ethernet frame of a monitoring flow
SYNOPSIS
#include <mos_api.h>
ssize_t mtcp_setlastpkt(mctx_t mctx, int sockid, int side, off_t offset, byte * data, uint16_t datalen, int option);
DESCRIPTION
mtcp_setlastpkt() updates the last Ethernet frame for a given flow observed by the stack. The user can specify the flow and direction with the socket descriptor sockid and the side argument (MOS_SIDE_CLI or MOS_SIDE_SVR) to specify the Ethernet frame of her choosing to be modified.
The option argument can be used to define which action should be performed on the packet. The value of option should be the logical disjunction of action to perform (MOS_DROP or MOS_OVERWRITE), position for modification (MOS_ETH_HDR or MOS_IP_HDR or MOS_TCP_HDR or MOS_TCP_PAYLOAD), and checksum operation to perform (MOS_UPDATE_IP_CHKSUM or MOS_UPDATE_TCP_CHKSUM). It allows modifying the packet contents as long as the overall TCP payload size is not changed.
MOS_DROP |
Drop the last Ethernet frame. This option ignores any other flags in the option parameter. |
||
MOS_OVERWRITE |
Overwrite some data onto the specific header or payload (MOS_ETH_HDR or MOS_IP_HDR or MOS_TCP_HDR or MOS_TCP_PAYLOAD) of the last Ethernet frame. The user can specify the offset from where the data should be written ( offset ), the data buffer that contains the data to be written ( data ), and the bytes in the data buffer ( datalen ). |
Here are some restrictions on the option field: (a) MOS_DROP and MOS_OVERWRITE are mutually exclusive parameters, but one of them should be specified in the option field. (b) MOS_DROP ignores any other flags in the option parameter. (c) MOS_ETH_HDR, MOS_IP_HDR, MOS_TCP_HDR, and MOS_TCP_PAYLOAD are mutually exclusive parameters, but one of them should be specified in the option field.
RETURN VALUE
Returns 0 on success. On all errors, -1 is returned and errno is set appropriately.
ERRORS
EACCES |
The mctx argument is invalid. | ||
EBADF |
The socket descriptor sockid is invalid. | ||
EINVAL |
The buffer management of the monitoring socket with sockid was already disabled. | ||
ESOCKTNOSUPPORT |
The socket referred to by sockid has invalid type | ||
ENOTCONN |
Th socket referred to by sockid is in a TCP state that disallows read operations. | ||
ENODATA |
The socket referred to by sockid does not have any available bytes in its buffer for reading. | ||
EPERM |
The caller is not permitted to access this function. |
AUTHORS
mOS development team <mtcp-user@list.ndsl.kaist.edu>
EXAMPLES
http://mos.kaist.edu/guide/programmer/05_api_example.html#modifying-or-dropping-a-packet
SEE ALSO
mtcp_getlastpkt(),
COLOPHON
This page is part of mOS release 0.3 docs section. A description of the project, and information about reporting bugs, can be found at http://mos.kaist.edu/.