"Fossies" - the Fresh Open Source Software Archive

Member "gvm-libs-11.0.1/base/hosts.h" (12 May 2020, 4585 Bytes) of package /linux/misc/openvas/gvm-libs-11.0.1.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 "hosts.h" see the Fossies "Dox" file reference documentation and the last Fossies "Diffs" side-by-side code changes report: 10.0.1_vs_11.0.0.

    1 /* Copyright (C) 2013-2019 Greenbone Networks GmbH
    2  *
    3  * SPDX-License-Identifier: GPL-2.0-or-later
    4  *
    5  * This program is free software; you can redistribute it and/or
    6  * modify it under the terms of the GNU General Public License
    7  * as published by the Free Software Foundation; either version 2
    8  * of the License, or (at your option) any later version.
    9  *
   10  * This program is distributed in the hope that it will be useful,
   11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
   12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   13  * GNU General Public License for more details.
   14  *
   15  * You should have received a copy of the GNU General Public License
   16  * along with this program; if not, write to the Free Software
   17  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
   18  */
   19 
   20 /**
   21  * @file
   22  * @brief Protos and data structures for Hosts collections and single hosts
   23  * objects.
   24  *
   25  * This file contains the protos for \ref hosts.c
   26  */
   27 
   28 #ifndef _GVM_HOSTS_H
   29 #define _GVM_HOSTS_H
   30 
   31 #include <glib.h>       /* for gchar, GList */
   32 #include <netinet/in.h> /* for in6_addr, in_addr */
   33 
   34 /* Static values */
   35 
   36 enum host_type
   37 {
   38   HOST_TYPE_NAME = 0,     /* Hostname eg. foo */
   39   HOST_TYPE_IPV4,         /* eg. 192.168.1.1 */
   40   HOST_TYPE_CIDR_BLOCK,   /* eg. 192.168.15.0/24 */
   41   HOST_TYPE_RANGE_SHORT,  /* eg. 192.168.15.10-20 */
   42   HOST_TYPE_RANGE_LONG,   /* eg. 192.168.15.10-192.168.18.3 */
   43   HOST_TYPE_IPV6,         /* eg. ::1 */
   44   HOST_TYPE_CIDR6_BLOCK,  /* eg. ::ffee/120 */
   45   HOST_TYPE_RANGE6_LONG,  /* eg. ::1:200:7-::1:205:500 */
   46   HOST_TYPE_RANGE6_SHORT, /* eg. ::1-fe10 */
   47   HOST_TYPE_MAX           /* Boundary checking. */
   48 };
   49 
   50 /* Typedefs */
   51 typedef struct gvm_host gvm_host_t;
   52 typedef struct gvm_vhost gvm_vhost_t;
   53 typedef struct gvm_hosts gvm_hosts_t;
   54 
   55 /* Data structures. */
   56 
   57 /**
   58  * @brief The structure for a single host object.
   59  *
   60  * The elements of this structure should never be accessed directly.
   61  * Only the functions corresponding to this module should be used.
   62  */
   63 struct gvm_host
   64 {
   65   union
   66   {
   67     gchar *name;           /**< Hostname. */
   68     struct in_addr addr;   /**< IPv4 address */
   69     struct in6_addr addr6; /**< IPv6 address */
   70   };
   71   enum host_type type; /**< HOST_TYPE_NAME, HOST_TYPE_IPV4 or HOST_TYPE_IPV6. */
   72   GSList *vhosts;      /**< List of hostnames/vhosts attached to this host. */
   73 };
   74 
   75 /**
   76  * @brief The structure for a single vhost object.
   77  */
   78 struct gvm_vhost
   79 {
   80   char *value;  /**< Hostname string. */
   81   char *source; /**< Source of the value eg. DNS-Resolution. */
   82 };
   83 
   84 /**
   85  * @brief The structure for Hosts collection.
   86  *
   87  * The elements of this structure should never be accessed directly.
   88  * Only the functions corresponding to this module should be used.
   89  */
   90 struct gvm_hosts
   91 {
   92   gchar *orig_str;    /**< Original hosts definition string. */
   93   gvm_host_t **hosts; /**< Hosts objects list. */
   94   size_t max_size;    /**< Current max size of hosts array entries. */
   95   size_t current;     /**< Current host index in iteration. */
   96   size_t count;       /**< Number of single host objects in hosts list. */
   97   size_t removed;     /**< Number of duplicate/excluded values. */
   98 };
   99 
  100 /* Function prototypes. */
  101 
  102 /* gvm_hosts_t related */
  103 gvm_hosts_t *
  104 gvm_hosts_new (const gchar *);
  105 
  106 gvm_hosts_t *
  107 gvm_hosts_new_with_max (const gchar *, unsigned int);
  108 
  109 gvm_host_t *
  110 gvm_hosts_next (gvm_hosts_t *);
  111 
  112 void
  113 gvm_hosts_free (gvm_hosts_t *);
  114 
  115 void
  116 gvm_hosts_shuffle (gvm_hosts_t *);
  117 
  118 void
  119 gvm_hosts_reverse (gvm_hosts_t *);
  120 
  121 GSList *
  122 gvm_hosts_resolve (gvm_hosts_t *);
  123 
  124 int
  125 gvm_hosts_exclude (gvm_hosts_t *, const char *);
  126 
  127 int
  128 gvm_vhosts_exclude (gvm_host_t *, const char *);
  129 
  130 int
  131 gvm_hosts_exclude_with_max (gvm_hosts_t *, const char *, unsigned int);
  132 
  133 char *
  134 gvm_host_reverse_lookup (gvm_host_t *);
  135 
  136 int
  137 gvm_hosts_reverse_lookup_only (gvm_hosts_t *);
  138 
  139 int
  140 gvm_hosts_reverse_lookup_unify (gvm_hosts_t *);
  141 
  142 unsigned int
  143 gvm_hosts_count (const gvm_hosts_t *);
  144 
  145 unsigned int
  146 gvm_hosts_removed (const gvm_hosts_t *);
  147 
  148 /* gvm_host_t related */
  149 
  150 int
  151 gvm_host_in_hosts (const gvm_host_t *, const struct in6_addr *,
  152                    const gvm_hosts_t *);
  153 
  154 gchar *
  155 gvm_host_type_str (const gvm_host_t *);
  156 
  157 enum host_type
  158 gvm_host_type (const gvm_host_t *);
  159 
  160 gchar *
  161 gvm_host_value_str (const gvm_host_t *);
  162 
  163 int
  164 gvm_host_resolve (const gvm_host_t *, void *, int);
  165 
  166 int
  167 gvm_host_get_addr6 (const gvm_host_t *, struct in6_addr *);
  168 
  169 void
  170 gvm_host_add_reverse_lookup (gvm_host_t *);
  171 
  172 /* Miscellaneous functions */
  173 
  174 gvm_vhost_t *
  175 gvm_vhost_new (char *, char *);
  176 
  177 int
  178 gvm_get_host_type (const gchar *);
  179 
  180 #endif /* not _GVM_HOSTS_H */