mirror of https://github.com/ipxe/ipxe.git
[tcp] Randomise local TCP port
Signed-off-by: Guo-Fu Tseng <cooldavid@cooldavid.org> Modified-by: Michael Brown <mcb30@ipxe.org> Signed-off-by: Michael Brown <mcb30@ipxe.org>pull/1/head
parent
73e3672468
commit
1e7e4c9a61
|
@ -174,11 +174,13 @@ tcp_dump_flags ( struct tcp_connection *tcp, unsigned int flags ) {
|
||||||
*/
|
*/
|
||||||
static int tcp_bind ( struct tcp_connection *tcp, unsigned int port ) {
|
static int tcp_bind ( struct tcp_connection *tcp, unsigned int port ) {
|
||||||
struct tcp_connection *existing;
|
struct tcp_connection *existing;
|
||||||
static uint16_t try_port = 1023;
|
uint16_t try_port;
|
||||||
|
unsigned int i;
|
||||||
|
|
||||||
/* If no port specified, find the first available port */
|
/* If no port is specified, find an available port */
|
||||||
if ( ! port ) {
|
if ( ! port ) {
|
||||||
while ( try_port ) {
|
try_port = random();
|
||||||
|
for ( i = 0 ; i < 65536 ; i++ ) {
|
||||||
try_port++;
|
try_port++;
|
||||||
if ( try_port < 1024 )
|
if ( try_port < 1024 )
|
||||||
continue;
|
continue;
|
||||||
|
|
Loading…
Reference in New Issue