lclend->sin_family = AF_INET;
doconnect(rad, rp, lad, lp)	struct in_addr     *rad;	u_short  rp;	struct in_addr     *lad;	u_short  lp;{	int nnetfd = 0;	int rr;	int     x, y;	errno = 0;	/* grab a socket; set opts */	while (nnetfd == 0) {		if (o_udpmode)			nnetfd = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP);		else			nnetfd = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);		if (nnetfd < 0)			nlog(1, "Can't get socket");	}	x = 1;	rr = setsockopt(nnetfd, SOL_SOCKET, SO_REUSEADDR, &x, sizeof(x));	if (rr == -1)		nlog(1, NULL);	/* fill in all the right sockaddr crud */	lclend->sin_family = AF_INET;	/* fill in all the right sockaddr crud */	lclend->sin_family = AF_INET;	remend->sin_family = AF_INET;	/* if lad/lp, do appropriate binding */	if (lad)		memcpy(&lclend->sin_addr.s_addr, lad, sizeof(struct in_addr));	if (lp)		lclend->sin_port = htons(lp);	rr = 0;	if (lad || lp) {		x = (int) lp;		/* try a few times for the local bind, a la ftp-data-port... */		for (y = 4; y > 0; y--) {			rr = bind(nnetfd, (struct sockaddr *) lclend,			    sizeof(struct sockaddr_in));			if (rr == 0)				break;			if (errno != EADDRINUSE)				break;			else {				nlog(0, "retrying local %s:%d", inet_ntoa(lclend->sin_addr), lp);				sleep(2);				errno = 0;	/* clear from sleep */			}		}	}	if (rr)		nlog(1, "Can't grab %s:%d with bind",		    inet_ntoa(lclend->sin_addr), lp);	if (o_listen)		return (nnetfd);/* thanks, that's all for today */	memcpy(&remend->sin_addr.s_addr, rad, sizeof(struct in_addr));	remend->sin_port = htons(rp);	/* wrap connect inside a timer, and hit it */	arm(1, o_wait);	if (setjmp(jbuf) == 0) {		rr = connect(nnetfd, (struct sockaddr *) remend, 						sizeof(struct sockaddr));	} else {		rr = -1;		errno = ETIMEDOUT;	}	arm(0, 0);	if (rr == 0)		return (nnetfd);	close(nnetfd);	return (-1);}