Exporting extracted payload to a C program

If you are writing P4 programs that run on a software switch like BMv2 or DPDK, then yes, it is possible to write C or C++ code that can be invoked from your P4 program. However, there is no tutorial document describing step by step how to do it.

About the closest thing I know of that exists for the BMv2 software switch is this example of a BMv2 pull request that adds a new P4 extern definition: Demonstration of adding a new extern to BMv2 / behavioral-model

Note that the act of implementing an extern is different from P4 target to P4 target. If you do this for BMv2, and then want to use that extern on an FPGA target device that is P4-programmable, you would need to reimplement the extern for that FPGA target.

For some ASIC target devices, it is not possible to add new functionality in this way. That is, unless you consider the approach of “send the packet to a general purpose CPU nearby, do the desired processing there, and send the packet back to the P4-programmable device”, but then you have the price/power/performance ratios that can be achieved on that general purpose CPU, which are often quite different than the kinds of devices that inspired P4.