![]() |
Home |
|
Function cb_packetin_taskThis callback is called by the RTIP-32 internal IP task before an incoming data packet is processed: int cb_packetin_task(int interface, byte * data, int length, int buffer_size); ParametersinterfaceInterface number (as returned by xn_interface_open or xn_interface_open_config) on which the new packet came in. dataPointer to the packet's data. lengthNumber of bytes pointed to by parameter data. buffer_sizeNumber of bytes the buffer pointed to by data can hold. buffer_size will always be >= length. return valueNumber of bytes RTIP-32 should process at *data. If 0 is returned, RTIP-32 will discard this packet. This callback can be used to intercept incoming packets. The callback function may modify the data pointed to by parameter data, if designed. It must return the number of bytes RTIP-32 should process. If the packet data is not modified and RTIP-32 should continue normal processing, return parameter length. To discard the data, return 0. This callback can be used to implement a simple firewall. The example below filters out all packets addressed at the Microsoft RPC (Remote Procedure Call) service: #define SWAPPED(w) ((word)((w >> 8) | (w << 8))) int cb_packetin_task(int iface, byte * data, int length, int buffer_size) { // poor man's firewall: // filter out all RPC packets (TCP, port 135) if (*(word*)(data+0x0C) == SWAPPED(0x0800) && // IP data[0x17] == 0x06 && // TCP *(word*)(data+0x24) == SWAPPED(135)) // destination port { return 0; // discard } return length; } ... int main(void) { ... xn_callbacks()->cb_packetin_task = cb_packetin_task; Result = xn_rtip_init(); ...
|