7 #include <sys/socket.h>
8 #include <netinet/in.h>
12 #define START_PORT 600
13 #define END_PORT (IPPORT_RESERVED - 1)
14 #define NUM_PORTS (END_PORT - START_PORT)
16 int bindresvport(int sd, struct sockaddr_in *sin)
18 struct sockaddr_in me;
25 memset(sin, 0, sizeof(me));
26 sin->sin_port = AF_INET;
28 else if (sin->sin_family != AF_INET) {
35 port = START_PORT + (getpid() % NUM_PORTS);
38 for (i = 0; i < NUM_PORTS; i++, port++) {
39 sin->sin_port = htons(port);
40 if ((ret = bind(sd, sin, sizeof(*sin))) != -1)