Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

correct way to select an unused udp port #1

Open
darksilkmaster opened this issue Oct 31, 2017 · 1 comment
Open

correct way to select an unused udp port #1

darksilkmaster opened this issue Oct 31, 2017 · 1 comment

Comments

@darksilkmaster
Copy link

let temp_outgoing_addr = format!("0.0.0.0:{}", 1024 + rand::random::<u16>());

if you generate a random u16 and add 1024 to it, the result might be larger than 65535

actually, there's a very simple way to do it right, just the port 0 and the os will take care of the rest

@mqudsi
Copy link
Member

mqudsi commented Jan 24, 2018

Hey @darksilkmaster, thanks for filing. I thought I replied to this via email, but either I'm misremembering or GitHub didn't like something about my message and never replied.

Thanks for catching the bug, that's kind of embarrassing. I imagine rust may have caught that overflow if the port were cast to u16 after the addition and prior to the conversion?

In all cases, I've been meaning to revisit the codebase and move it over to an event loop via tokiors to boost performance and lower resource requirements. The complementary tcpproxy project has already been ported: mqudsi/tcpproxy@6265119

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants