Search the code of getting all OpenGL states

I need a sample code that get all the OpenGL states of a RC,so I can save the values in a system memory,or write them into a file for feature use.Is it possible to implement?Where can I find these code?