summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--support/include/rpcmisc.h1
-rw-r--r--support/nfs/rpcmisc.c38
2 files changed, 22 insertions, 17 deletions
diff --git a/support/include/rpcmisc.h b/support/include/rpcmisc.h
index 35c5011..5814a63 100644
--- a/support/include/rpcmisc.h
+++ b/support/include/rpcmisc.h
@@ -42,7 +42,6 @@ struct rpc_dtable {
}
-int makesock(int port, int proto);
void rpc_init(char *name, int prog, int vers,
void (*dispatch)(struct svc_req *, SVCXPRT *),
int defport);
diff --git a/support/nfs/rpcmisc.c b/support/nfs/rpcmisc.c
index 40c2102..bb68203 100644
--- a/support/nfs/rpcmisc.c
+++ b/support/nfs/rpcmisc.c
@@ -39,7 +39,7 @@
#endif
static void closedown(int sig);
-int makesock(int port, int proto);
+static int makesock(int port, int proto);
#define _RPCSVC_CLOSEDOWN 120
int _rpcpmstart = 0;
@@ -166,36 +166,42 @@ int sig;
(void) alarm(_RPCSVC_CLOSEDOWN);
}
-int makesock(int port, int proto)
+/*
+ * Create listener socket for a given port
+ *
+ * Return an open network socket on success; otherwise return -1
+ * if some error occurs.
+ */
+static int
+makesock(int port, int proto)
{
struct sockaddr_in sin;
- int s;
- int sock_type;
- int val;
+ int sock, sock_type, val;
sock_type = (proto == IPPROTO_UDP) ? SOCK_DGRAM : SOCK_STREAM;
- s = socket(AF_INET, sock_type, proto);
- if (s < 0) {
- xlog(L_FATAL, "Could not make a socket: %s\n",
+ sock = socket(AF_INET, sock_type, proto);
+ if (sock < 0) {
+ xlog(L_FATAL, "Could not make a socket: %s",
strerror(errno));
- return (-1);
+ return -1;
}
memset((char *) &sin, 0, sizeof(sin));
sin.sin_family = AF_INET;
- sin.sin_addr.s_addr = INADDR_ANY;
+ sin.sin_addr.s_addr = htonl(INADDR_ANY);
sin.sin_port = htons(port);
val = 1;
if (proto == IPPROTO_TCP)
- if (setsockopt(s, SOL_SOCKET, SO_REUSEADDR,
+ if (setsockopt(sock, SOL_SOCKET, SO_REUSEADDR,
&val, sizeof(val)) < 0)
- xlog(L_ERROR, "setsockopt failed: %s\n",
+ xlog(L_ERROR, "setsockopt failed: %s",
strerror(errno));
- if (bind(s, (struct sockaddr *) &sin, sizeof(sin)) == -1) {
- xlog(L_FATAL, "Could not bind name to socket: %s\n",
+ if (bind(sock, (struct sockaddr *) &sin, sizeof(sin)) == -1) {
+ xlog(L_FATAL, "Could not bind name to socket: %s",
strerror(errno));
- return (-1);
+ return -1;
}
- return (s);
+
+ return sock;
}