Do you want sample code in raw socket or You want some other solution to solve your problem?

Actually, I worked in raw sockets I too know the demerits in it.

And we can get the header details in the getsockopt() function.