Allow default port to be given as a service name or port number.
[become] / src / parser.y
index 0a8462f..b36ecdb 100644 (file)
@@ -1,13 +1,13 @@
 /* -*-c-*-
  *
- * $Id: parser.y,v 1.1 1997/07/21 13:47:45 mdw Exp $
+ * $Id: parser.y,v 1.3 1997/09/09 18:17:06 mdw Exp $
  *
  * Parser for `become.conf' files
  *
  * (c) 1997 EBI
  */
 
-/*----- Licencing notice --------------------------------------------------*
+/*----- Licensing notice --------------------------------------------------*
  *
  * This file is part of `become'
  *
  * GNU General Public License for more details.
  *
  * You should have received a copy of the GNU General Public License
- * along with `become'; if not, write to the Free Software
- * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ * along with `become'; if not, write to the Free Software Foundation,
+ * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  */
 
 /*----- Revision history --------------------------------------------------*
  *
  * $Log: parser.y,v $
- * Revision 1.1  1997/07/21 13:47:45  mdw
+ * Revision 1.3  1997/09/09 18:17:06  mdw
+ * Allow default port to be given as a service name or port number.
+ *
+ * Revision 1.2  1997/08/04 10:24:24  mdw
+ * Sources placed under CVS control.
+ *
+ * Revision 1.1  1997/07/21  13:47:45  mdw
  * Initial revision
  *
  */
 /* --- Unix headers --- */
 
 #include <sys/types.h>
+#include <sys/socket.h>
+
+#include <netinet/in.h>
+
+#include <arpa/inet.h>
 
+#include <netdb.h>
 #include <pwd.h>
 #include <unistd.h>
 
@@ -187,7 +199,16 @@ host_spec  : HOST name '=' host_class ';' {
                        }
                ;
 
-port_spec      : PORT INT ';' { daemon_usePort($2); }
+port_spec      : PORT STRING ';' {
+                         struct servent *s = getservbyname($2, "udp");
+                         if (!s) {
+                           moan("unknown service `%s' at line %i",
+                                $2, lex_line);
+                           YYERROR;
+                         }
+                         daemon_usePort(s->s_port);
+                       }
+               | PORT INT ';' { daemon_usePort(htons($2)); }
                ;
 
 key_spec       : KEYFILE STRING ';' { daemon_readKey($2); }