version 1.1, 1999/09/26 20:53:38 |
version 1.2, 1999/09/26 22:01:24 |
|
|
if (privileged) |
if (privileged) |
{ |
{ |
struct sockaddr_in sin; |
struct sockaddr_in sin; |
int p; |
int p = IPPORT_RESERVED - 1; |
for (p = 1023; p > 512; p--) |
|
{ |
|
sock = socket(AF_INET, SOCK_STREAM, 0); |
|
if (sock < 0) |
|
fatal("socket: %.100s", strerror(errno)); |
|
|
|
/* Initialize the desired sockaddr_in structure. */ |
|
memset(&sin, 0, sizeof(sin)); |
|
sin.sin_family = AF_INET; |
|
sin.sin_addr.s_addr = INADDR_ANY; |
|
sin.sin_port = htons(p); |
|
|
|
/* Try to bind the socket to the privileged port. */ |
sock = rresvport(&p); |
if (bind(sock, (struct sockaddr *)&sin, sizeof(sin)) >= 0) |
if (sock < 0) |
break; /* Success. */ |
fatal("rresvport: %.100s", strerror(errno)); |
if (errno == EADDRINUSE) |
|
{ |
|
close(sock); |
|
continue; |
|
} |
|
fatal("bind: %.100s", strerror(errno)); |
|
} |
|
debug("Allocated local port %d.", p); |
debug("Allocated local port %d.", p); |
} |
} |
else |
else |