How to make recvmsg failed in Linux system

302 Views Asked by At

Is there any way how to makes to recvmsg that listen to UDP to return value that smaller than 0?

I can't run code on the system, only send UDP packet.

Edit:

I have tried the @Ben Voigt offer , sending to this port ICMP Port Unreachable packet to this port and that may trigger ECONNRESET or ECONNREFUSED So I tried this code

from scapy.all import *
send(IP(dst=dst_ip)/UDP(sport=src_port,dport=dst_port))
[here is PCAP file][1] , when I run that code the `recvmsg` has been called(not return -1 of-course) 

So no I tried to send ICMP Port Unreachable to that port and hope that recvmsg will fail

from scapy.all import *
send(IP(dst=dst_ip)/ICMP(type=3,code=3)/IP(dst=dst_ip)/UDP(sport=src_port,dport=dst_port))

enter image description here

here is PCAP file but the recvmsg not even called

1

There are 1 best solutions below

1
Maxim Egorushkin On

If you want recvmsg return -1 for testing, implement your own recvmsg in a shared library and inject it in your program with LD_PRELOAD. See The LD_PRELOAD trick for more details.