generate_packets.py: Context manager for header wrapping
As an added bonus, this patch adds multiple inclusion protection to common/packets_gen.h, which was lacking that up until now. (This was not an issue, since packets_gen.h is only included from common/networking/packets.h, which is itself multiple-inclusion-protected.)
Part of #43927. Split from #43932. Provide a context manager for wrapping header files in multiple-inclusion-protection, as well as extern "C" wrapping for C++ contexts.