Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

I have a black box program which listens on a particular UDP port. I'd like it to listen to a UDP port of my choosing.

Is there a way to trick the executable into listening on a differen port. I might imagine there exists a library which could be injected with LD_PRELOAD that might incercept the system calls and facilitate this.

A virtual machine of course is the heavy handed option, but that's not an option for me.

share|improve this question
add comment

1 Answer

If you can tell the black-box program to listen only on a specific IP address, you could bind it to an arbitrary loopback address, like 127.0.0.10, and then use netcat, AKA, nc, to pipe between the port on 127.0.0.10 and whatever you like on the outside IP.

There's an article on Netcat in wikipedia with a section about proxying. You'll want to understand that and to know that the -u option lets you use UDP instead of the default, TCP.

In this example, 192.168.200.200 is the outside IP, 12345 is the port you want the black box to listen on. 127.0.0.10 is the IP you told the blackbox to use and 987 is the port the box rudely insists upon using.

mkfifo backpipe
chmod {something sane backpipe}
nc -l -u 192.168.200.200 12345 0<backpipe | nc 127.0.0.10 987 1>backpipe

If you don't have mkfifo on your system, google "mknod pipe"

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.