* as is, with no warranty expressed or implied.
*/
-#include "config.h"
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
#include <sys/types.h>
#include <sys/ioctl.h>
asize = sizeof(saddr);
sock = 0;
- if (getsockname(0, (struct sockaddr *) &saddr, &asize) == 0) {
+ if (getsockname(0, (struct sockaddr *) &saddr, &asize) == 0
+ && saddr.sin_family == AF_INET) {
int ssize = sizeof (int);
- _rpcfdtype = 0;
- if (saddr.sin_family != AF_INET)
- xlog(L_FATAL, "init: stdin is bound to non-inet addr");
+ int fdtype = 0;
if (getsockopt(0, SOL_SOCKET, SO_TYPE,
- (char *)&_rpcfdtype, &ssize) == -1)
+ (char *)&fdtype, &ssize) == -1)
xlog(L_FATAL, "getsockopt failed: %s", strerror(errno));
- _rpcpmstart = 1;
- } else {
+ /* inetd passes a UDP socket or a listening TCP socket.
+ * listen will fail on a connected TCP socket(passed by rsh).
+ */
+ if (!(fdtype == SOCK_STREAM && listen(0,5) == -1)) {
+ _rpcfdtype = fdtype;
+ _rpcpmstart = 1;
+ }
+ }
+ if (!_rpcpmstart) {
pmap_unset(prog, vers);
sock = RPC_ANYSOCK;
}
if ((_rpcfdtype == 0) || (_rpcfdtype == SOCK_DGRAM)) {
static SVCXPRT *last_transp = NULL;
- if (_rpcfdtype == 0) {
+ if (_rpcpmstart == 0) {
if (last_transp
&& (!defport || defport == last_transp->xp_port)) {
transp = last_transp;
if ((_rpcfdtype == 0) || (_rpcfdtype == SOCK_STREAM)) {
static SVCXPRT *last_transp = NULL;
- if (_rpcfdtype == 0) {
+ if (_rpcpmstart == 0) {
if (last_transp
&& (!defport || defport == last_transp->xp_port)) {
transp = last_transp;