Fix a typo. Port numbers are in network order now, so don't change them.
[become] / src / daemon.c
index 5b5df85..317a7fb 100644 (file)
@@ -1,6 +1,6 @@
 /* -*-c-*-
  *
- * $Id: daemon.c,v 1.5 1997/08/20 16:17:10 mdw Exp $
+ * $Id: daemon.c,v 1.7 1997/09/17 10:23:23 mdw Exp $
  *
  * Running a `become' daemon
  *
 /*----- Revision history --------------------------------------------------*
  *
  * $Log: daemon.c,v $
- * Revision 1.5  1997/08/20 16:17:10  mdw
+ * Revision 1.7  1997/09/17 10:23:23  mdw
+ * Fix a typo.  Port numbers are in network order now, so don't change them.
+ *
+ * Revision 1.6  1997/09/09 18:17:06  mdw
+ * Allow default port to be given as a service name or port number.
+ *
+ * Revision 1.5  1997/08/20  16:17:10  mdw
  * More sensible restart routine: `_reinit' functions replaced by `_end' and
  * `_init' functions.
  *
@@ -319,11 +325,11 @@ void daemon_init(const char *cf, int port)
    * look it up in /etc/services under whatever name I was started as.
    */
 
-  if (daemon__port <= 0) {
+  if (daemon__port == 0) {
     struct servent *se = getservbyname(quis(), "udp");
     if (!se)
       die("no idea which port to use");
-    daemon__port = ntohs(se->s_port);
+    daemon__port = se->s_port;
   }
 
   /* --- Now set up a socket --- */
@@ -334,10 +340,12 @@ void daemon_init(const char *cf, int port)
     if ((s = socket(PF_INET, SOCK_DGRAM, 0)) == -1)
       die("couldn't create socket: %s", strerror(errno));
     sin.sin_family = AF_INET;
-    sin.sin_port = htons(daemon__port);
+    sin.sin_port = daemon__port;
     sin.sin_addr.s_addr = htonl(INADDR_ANY);
-    if (bind(s, (struct sockaddr *)&sin, sizeof(sin)))
-      die("couldn't bind socket to port: %s", strerror(errno));
+    if (bind(s, (struct sockaddr *)&sin, sizeof(sin))) {
+      die("couldn't bind socket to port %i: %s",
+         ntohs(daemon__port), strerror(errno));
+    }
   }
 
   /* --- Fork off into the sunset --- */