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