i know that cdp just shows only the directly connected but i have the case in which the show cdp neighbor command show devices that are not connected directly but through the 3com switch
so what is the problem??
It is due to the difference in processing between Cisco switches and switches from other vendors. CDP uses a special multicast MAC address as its destination layer 2 address. When you send a CDP frame out an interface that is connected to a Cisco switch then the Cisco switch recognizes the destination MAC address as one that it processes and so it processes instead of forwarding the frame. The result is that when connected to Cisco switches you only see directly connected devices.
However when the switch is from another vendor (such as 3com) then it does not recognize the multicast MAC address as one that it processes and it forwards the CDP frame and you get responses from Cisco devices that are more than one hop.