socket state

Is there any easy method how to get current socket state? For example -
I have a file descriptor and I know, that this file descriptor is a
socket. How can I get state for this socket - LISTEN, TIME_WAIT and so on?

Thanks.