"Fossies" - the Fresh Open Source Software Archive

Member "snort-2.9.17/src/dynamic-preprocessors/appid/util/common_util.h" (16 Oct 2020, 3446 Bytes) of package /linux/misc/snort-2.9.17.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. For more information about "common_util.h" see the Fossies "Dox" file reference documentation and the latest Fossies "Diffs" side-by-side code changes report: 2.9.16.1_vs_2.9.17.

    1 /*
    2 ** Copyright (C) 2014-2020 Cisco and/or its affiliates. All rights reserved.
    3 ** Copyright (C) 2005-2013 Sourcefire, Inc.
    4 **
    5 ** This program is free software; you can redistribute it and/or modify
    6 ** it under the terms of the GNU General Public License Version 2 as
    7 ** published by the Free Software Foundation.  You may not use, modify or
    8 ** distribute this program under any other version of the GNU General
    9 ** Public License.
   10 **
   11 ** This program is distributed in the hope that it will be useful,
   12 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
   13 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   14 ** GNU General Public License for more details.
   15 **
   16 ** You should have received a copy of the GNU General Public License
   17 ** along with this program; if not, write to the Free Software
   18 ** Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
   19 */
   20 
   21 
   22 #ifndef __COMMON_UTIL_H__
   23 #define __COMMON_UTIL_H__
   24 
   25 #include <ctype.h>
   26 #include <stdio.h>
   27 #include <time.h>
   28 #include <netinet/in.h>
   29 #include <sf_types.h>
   30 #include <sflsq.h>
   31 
   32 typedef struct _FWDebugSessionConstraints
   33 {
   34     struct in6_addr sip;
   35     int sip_flag;
   36     struct in6_addr dip;
   37     int dip_flag;
   38     uint16_t sport;
   39     uint16_t dport;
   40     uint8_t protocol;
   41 } FWDebugSessionConstraints;
   42 
   43 #define FW_DEBUG_SESSION_ID_SIZE    (39+1+5+4+39+1+5+1+3+1+1+1+2+1+10+1+1+1+10+1)
   44 
   45 typedef struct _config_item
   46 {
   47     char *name;                         /* name of the config item */
   48     char *value;                        /* config item value */
   49 } ConfigItem;
   50 
   51 #define MAX_LINE    2048
   52 #define MAX_TOKS    256
   53 
   54 /* This structure should be same as struct define in util.h */
   55 typedef struct _ThrottleInfo
   56 {
   57     time_t lastUpdate;
   58     /*Within this duration (in seconds), maximal one distinct message is logged*/
   59     uint32_t duration_to_log;
   60     uint64_t count;
   61     /*Till the message count reaches to count_to_log, maximal one distinct message is logged*/
   62     uint64_t count_to_log;
   63 }ThrottleInfo;
   64 
   65 extern time_t packetTimeOffset;
   66 extern time_t packetTime;
   67 extern int packetTimeOffsetSet;
   68 #define GetPacketRealTime   packetTime
   69 static inline void SetPacketRealTime(time_t pktTime)
   70 {
   71     if (!packetTimeOffsetSet)
   72     {
   73         time_t tmp = time(NULL);
   74 
   75         packetTimeOffsetSet = 1;
   76         if (pktTime < tmp)
   77             packetTimeOffset = tmp - pktTime;
   78     }
   79     packetTime = pktTime + packetTimeOffset;
   80 }
   81 
   82 static inline void DumpHex(FILE *fp, const uint8_t *data, unsigned len)
   83 {
   84     char str[18];
   85     unsigned i;
   86     unsigned pos;
   87     char c;
   88 
   89     for (i=0, pos=0; i<len; i++, pos++)
   90     {
   91         if (pos == 17)
   92         {
   93             str[pos] = 0;
   94             fprintf(fp, "  %s\n", str);
   95             pos = 0;
   96         }
   97         else if (pos == 8)
   98         {
   99             str[pos] = ' ';
  100             pos++;
  101             fprintf(fp, "%s", " ");
  102         }
  103         c = (char)data[i];
  104         if (isprint(c) && !isspace(c))
  105             str[pos] = c;
  106         else
  107             str[pos] = '.';
  108         fprintf(fp, "%02X ", data[i]);
  109     }
  110     if (pos)
  111     {
  112         str[pos] = 0;
  113         for (; pos < 17; pos++)
  114         {
  115             if (pos == 8)
  116             {
  117                 str[pos] = ' ';
  118                 pos++;
  119                 fprintf(fp, "%s", "    ");
  120             }
  121             else
  122             {
  123                 fprintf(fp, "%s", "   ");
  124             }
  125         }
  126         fprintf(fp, "  %s\n", str);
  127     }
  128 }
  129 
  130 #endif  /* __COMMON_UTIL_H__ */
  131