I want to write a program to find whether the ethernet media is up or not which is connected to the ethernet adapter (language is not decided yet). I want to know about the algorithms and protocols which are used by an ethernet adapter, to identify whether the media is connected or not. I know ethernet adapter contains a solid LED to identify whether the connection is up or not. I want know what is the mechanism behind it. It will be really helpful if you can answer this and provide some references to the information about those algorithms.
Ethernet over twisted pair uses Fast Link Pulses to (auto) negotiate a link: each port advertises its link capabilities, e.g. 1000BASE-T full duplex, 100BASE-TX full duplex, 100BASE-TX half duplex, 10BASE-T full duplex, 10BASE-T half duplex, and when a link partner is detected, the best mutual protocol is selected and the link is established (depending on its subtleties).
Accordingly, its not the media that is detected (e.g. by a mechanical switch in the jack) but the link partner.
FLPs are defined in IEEE 802.3 Clause 28, the actual link process is detailed in each physical-layer variant, e.g. 1000BASE-T in Clause 40.5. You can download the IEEE 802.3 specifications free after registration.