This paper presents a method for detecting and preventing wormhole attacks in ad hoc networks using real-time operating system (RTOS) environments. The proposed algorithm identifies suspicious links and employs a verification process to mitigate the risk of such attacks, enhancing the security and efficiency of wireless networks. The research outlines the characteristics of wormhole attacks and provides a detailed implementation strategy that utilizes the optimized link state routing protocol (OLSR).