I am coding a webserver, and I would like to be able to detect what kind of file I am sending to the client, but I do not know of a good function for this, so if anyone could point me towards one, I would be very grateful.

By file type I mean files such as JPG, PNG, HTML etc, so I can include the correct data in the header.

I am coding pure C in a Unix environment.