syslogd option to listen on a single address

From: Dr Douglas J. Chappell (d.chappell@mmb.usyd.edu.au)
Date: Thu Sep 05 2002 - 06:36:13 CEST

  • Next message: Chad Foreman: "sysklogd-sql compile error"

    Hi,

    Here is code for an additional syslogd option which I have found useful. It
    allows syslogd to listen on only 1 address if desired. In our setup it only
    listens on our private net. The changes were made on the syslogd.c in the
    redhat 7.3 sysklogd-1.4.1-8.src.rpm package.

    Here are the diffs on syslogd.c:

    --- syslogd.c.orig Thu Aug 16 03:16:05 2001
    +++ syslogd.c Sun Aug 4 21:32:45 2002
    @@ -727,4 +727,6 @@
      int finet = -1; /* Internet datagram socket */
      int LogPort; /* port number for INET connections */
    +struct in_addr ListenAddr; /* ip address to listen on - Doug */
    +int wildcard = 1; /* bool for wildcard address - or not - Doug */
      int Initialized = 0; /* set when we have initialized ourselves */
      int MarkInterval = 20 * 60; /* interval between marks in seconds */
    @@ -831,5 +833,5 @@
              }
     
    - while ((ch = getopt(argc, argv, "a:dhf:l:m:np:rs:vx")) != EOF)
    + while ((ch = getopt(argc, argv, "a:dhf:i:l:m:np:rs:vx")) != EOF)
                      switch((char)ch) {
                      case 'a':
    @@ -848,4 +850,11 @@
                              NoHops = 0;
                              break;
    + case 'i': /* Doug */
    + if ( ! inet_aton(optarg, &ListenAddr) )
    + fprintf (stderr, "Invalid IP for listen address," \
    + "using wildcard address.\n");
    + else
    + wildcard = 0;
    + break;
                      case 'l':
                              if (LocalHosts) {
    @@ -1231,4 +1240,11 @@
              sin.sin_family = AF_INET;
              sin.sin_port = LogPort;
    +
    + /* Doug */
    + if ( ! wildcard )
    + sin.sin_addr.s_addr = ListenAddr.s_addr;
    + else
    + sin.sin_addr.s_addr = htonl(INADDR_ANY);
    +
              if (setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, \
                             (char *) &on, sizeof(on)) < 0 ) {

    As you can see it adds an -i ip address option (only makes sense with the -r
    option) which alows you to choose 1 address to listen on.

    If the ip address given is malformed, inet_aton fails and syslogd
    will default to listening on all interfaces. If a non-local ip is
    given bind will fail and
    syslogd will not listen on any address.

    Apologies for the /* Doug */ comments - these were to mark where I
    had been poking around.

    Here is the patch to the man page:

    --- sysklogd.8.orig Sun Aug 4 21:42:29 2002
    +++ sysklogd.8 Sun Aug 4 21:43:56 2002
    @@ -16,4 +16,7 @@
      ]
      .RB [ " \-h " ]
    +.RB [ " \-i "
    +.I ip address
    +]
      .RB [ " \-l "
      .I hostlist
    @@ -105,4 +108,9 @@
      forward any remote messages it receives to forwarding hosts which have been
      defined.
    +.TP
    +.BI "\-i " "ip address"
    +Specify an ip address to listen on. Otherwise syslogd will use the
    +wildcard address.
    +.TP
      .BI "\-l " "hostlist"
      Specify a hostname that should be logged only with its simple hostname

    Doug
    |-----------------------------------------------|
    | Dr Doug Chappell |
    | Computer Support |
    | School of Molecular and Microbial Biosciences |
    | The University of Sydney, 2006 NSW AUSTRALIA |
    | d.chappell@mmb.usyd.edu.au |
    |-----------------------------------------------|
    | Phone: 61 2 9351 2511 | Fax: 61 2 9351 4726 |
    |-----------------------------------------------|



    This archive was generated by hypermail 2.1.4 : Thu Sep 05 2002 - 06:36:24 CEST