/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License (the "License").
* You may not use this file except in compliance with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
*/
/* Copyright (c) 1983, 1984, 1985, 1986, 1987, 1988, 1989 AT&T */
/* All Rights Reserved */
/*
* Portions of this source code were derived from Berkeley 4.3 BSD
* under license from the Regents of the University of California.
*/
/*
* XXX This routine should be changed to use
* ND_CHECK_RESERVED_PORT and ND_SET_RESERVED_PORT
* which can be invoked via netdir_options.
*/
#include <stdio.h>
#include <netdb.h>
#include <errno.h>
#include <stropts.h>
#include <string.h>
#include <tiuser.h>
#include <unistd.h>
/*
* The argument is a client handle for a UDP connection.
* Unbind its transport endpoint from the existing port
* and rebind it to a reserved port.
* On failure, the client handle can be unbound even if it
* was previously bound. Callers should destroy the client
* handle after a failure.
*/
int
{
int fd;
int res;
short port;
extern int errno;
/* extern int t_errno; */
int i;
/* make sure it's a UDP connection */
return (-1);
return (0); /* not udp - don't need resv port */
}
return (-1);
}
/* If fd is already bound - unbind it */
/*
* If there is a message queued to this descriptor,
* remove it.
*/
int flags;
flags = 0;
return (-1);
}
return (-1);
}
return (-1);
}
return (-1);
}
/* warning: this sockaddr_in is truncated to 8 bytes */
} else {
}
/*
* Need to find a reserved port in the interval
* STARTPORT - ENDPORT. Choose a random starting
* place in the interval based on the process pid
* and sequentially search the ports for one
* that is available.
*/
for (i = 0; i < NPORTS; i++) {
else
/*
* Try to bind to the requested address. If
* the call to t_bind succeeds, then we need
* to make sure that the address that we bound
* to was the address that we requested. If it
* was, then we are done. If not, we fake an
* EADDRINUSE error by setting res, t_errno,
* and errno to indicate that a bind failure
* occurred. Otherwise, if the t_bind call
* failed, we check to see whether it makes
* sense to continue trying to t_bind requests.
*/
if (res == 0) {
break;
res = -1;
errno = EADDRINUSE;
break;
}
}
return (res);
}