links through cgi-bin program

I am looking for a way to create a link on my page that will:
1. Access a database of URLs
2. Open a socket to that URL
3. Pass the HTML code from that URL (with pictures) onto the client

I would like to do this in C...
I really don't need help with accessing the database but as far as 
opening a socket and passing the HTML onto the client I am clueless. 
Know of any good references for this kind of programing?