struct sockaddr_in sin; int s;  sin.sin_family = AF_INET; sin.sin_addr.s_addr = INADDR_ANY; s = __socket(AF_INET, SOCK_STREAM, 0); if (s < 0) return -1; for (;;) { sin.sin_port = htons((u_short)*alport); if (bind(s, (struct sockaddr *)&sin, sizeof(sin)) >= 0) return s; if (errno != EADDRINUSE) { (void)__close(s); return -1; } (*alport)--; if (*alport == IPPORT_RESERVED/2) { (void)__close(s); __set_errno (EAGAIN);		 return -1; } }
return rresvport_af(alport, AF_INET);
rresvport(alport)	int *alport;{	struct sockaddr_in sin;	int s;	sin.sin_family = AF_INET;	sin.sin_addr.s_addr = INADDR_ANY;	s = __socket(AF_INET, SOCK_STREAM, 0);	if (s < 0)		return -1;	for (;;) {		sin.sin_port = htons((u_short)*alport);		if (bind(s, (struct sockaddr *)&sin, sizeof(sin)) >= 0)			return s;		if (errno != EADDRINUSE) {			(void)__close(s);			return -1;		}		(*alport)--;		if (*alport == IPPORT_RESERVED/2) {			(void)__close(s);			__set_errno (EAGAIN);		/* close */			return -1;		}	}}