Changeset 109 for trunk/src


Ignore:
Timestamp:
Jun 18, 2007, 9:29:51 PM (17 years ago)
Author:
rainer
Message:

More graceful connection teardown in portcheck.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/sh_portcheck.c

    r80 r109  
    3939#include <errno.h>
    4040#include <unistd.h>
     41#include <fcntl.h>
    4142
    4243#define PORTCHK_VERSION "1.0"
     
    110111#include "sh_error.h"
    111112#include "sh_mem.h"
     113#include "sh_calls.h"
    112114#include "sh_utils.h"
    113115#include "sh_modules.h"
     
    676678  /* struct in_addr     haddr; */
    677679  int                retval;
     680  int                flags;
    678681  char             * p;
    679682#ifndef TEST_ONLY
     
    728731        fprintf(stderr, _("check port: %5d on %15s open %s\n"),
    729732                port, inet_ntoa(haddr), p);
     733
     734#if !defined(O_NONBLOCK)
     735#if defined(O_NDELAY)
     736#define O_NONBLOCK  O_NDELAY
     737#else
     738#define O_NONBLOCK  0
     739#endif
     740#endif
     741
     742      /* prepare to close connection gracefully
     743       */
     744      if      (port == 22)  /* ssh */
     745        {
     746          flags = retry_fcntl(FIL__, __LINE__, fd, F_GETFL, 0);
     747          retry_fcntl(FIL__, __LINE__, fd, F_SETFL, flags | O_NONBLOCK);
     748          write (fd, _("SSH-2.0-Foobar"), 14);
     749          write (fd, "\r\n", 2);
     750        }
     751      else if (port == 25)  /* smtp */
     752        {
     753          flags = retry_fcntl(FIL__, __LINE__, fd, F_GETFL, 0);
     754          retry_fcntl(FIL__, __LINE__, fd, F_SETFL, flags | O_NONBLOCK);
     755          write (fd, _("QUIT"), 4);
     756          write (fd, "\r\n", 2);
     757        }
     758      else if (port == 79)  /* finger */
     759        {
     760          flags = retry_fcntl(FIL__, __LINE__, fd, F_GETFL, 0);
     761          retry_fcntl(FIL__, __LINE__, fd, F_SETFL, flags | O_NONBLOCK);
     762          write (fd, "\r\n", 2);
     763        }
     764      else if (port == 110) /* pop3 */
     765        {
     766          flags = retry_fcntl(FIL__, __LINE__, fd, F_GETFL, 0);
     767          retry_fcntl(FIL__, __LINE__, fd, F_SETFL, flags | O_NONBLOCK);
     768          write (fd, _("QUIT"), 4);
     769          write (fd, "\r\n", 2);
     770        }
     771      else if (port == 143) /* imap */
     772        {
     773          flags = retry_fcntl(FIL__, __LINE__, fd, F_GETFL, 0);
     774          retry_fcntl(FIL__, __LINE__, fd, F_SETFL, flags | O_NONBLOCK);
     775          write (fd, _("A01 LOGOUT"), 10);
     776          write (fd, "\r\n", 2);
     777        }
    730778     }
    731779  close (fd);
Note: See TracChangeset for help on using the changeset viewer.