CGI scripts, for example web applications, operate on the CGI interface of the webserver.
Do I have access to details of the TCP/IP packets associated with a certain connection? For example, I can get “request” details, like the environment, remote host details, etc. But can I also read out, for example, the 16-bit id field of the TCP/IP packets associated with this connect?
No, you’re several layers of abstraction above the raw TCP packets. You can’t access their content directly.
And there is no “TCP packet associated with this connection”. A connection is a stream of packets that run both ways. Packets contents are also not necessarily delivered to user as-is – they can be aggregated or split to fit the receiving buffer.