- if (1) {
- int port;
- int one = 1;
-
- setsockopt(rpc->fd, SOL_SOCKET, SO_REUSEADDR, (char *)&one, sizeof(one));
-
- for (port = 200; port < 500; port++) {
- struct sockaddr_in sin;
-
- memset(&sin, 0, sizeof(sin));
- sin.sin_port = htons(port);
- sin.sin_family = AF_INET;
- sin.sin_addr.s_addr = 0;
-
- if (bind(rpc->fd, (struct sockaddr *)&sin, sizeof(struct sockaddr_in)) != 0 && errno != EACCES) {
- /* we didnt get EACCES, so try again */
- continue;
- }
- break;
+ {
+ struct sockaddr_in sin;
+ static int portOfs = 0;
+ const int firstPort = 512; /* >= 512 according to Sun docs */
+ const int portCount = IPPORT_RESERVED - firstPort;
+ int startOfs, port, rc;
+
+ if (portOfs == 0) {
+ portOfs = time(NULL) % 400;