net-snmp 5.7
system.h
00001 #ifndef SNMP_SYSTEM_H
00002 #define SNMP_SYSTEM_H
00003 
00004 #ifndef NET_SNMP_CONFIG_H
00005 #error "Please include <net-snmp/net-snmp-config.h> before this file"
00006 #endif
00007 
00008 #ifdef __cplusplus
00009 extern          "C" {
00010 #endif
00011 
00012 /* Portions of this file are subject to the following copyrights.  See
00013  * the Net-SNMP's COPYING file for more details and other copyrights
00014  * that may apply:
00015  */
00016 /***********************************************************
00017         Copyright 1993 by Carnegie Mellon University
00018 
00019                       All Rights Reserved
00020 
00021 Permission to use, copy, modify, and distribute this software and its
00022 documentation for any purpose and without fee is hereby granted,
00023 provided that the above copyright notice appear in all copies and that
00024 both that copyright notice and this permission notice appear in
00025 supporting documentation, and that the name of CMU not be
00026 used in advertising or publicity pertaining to distribution of the
00027 software without specific, written prior permission.
00028 
00029 CMU DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
00030 ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
00031 CMU BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
00032 ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
00033 WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
00034 ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
00035 SOFTWARE.
00036 ******************************************************************/
00037 /*
00038  * portions Copyright © 2003 Sun Microsystems, Inc. All rights reserved.
00039  * Use is subject to license terms specified in the COPYING file
00040  * distributed with the Net-SNMP package.
00041  */
00042 
00043 
00044     /*
00045      * function to create a daemon. Will fork and call setsid().
00046      *
00047      * Returns: -1 : fork failed
00048      *           0 : No errors
00049      */
00050     NETSNMP_IMPORT
00051     int netsnmp_daemonize(int quit_immediately, int stderr_log);
00052 
00053     /*
00054      * Definitions for the system dependent library file
00055      *
00056      * Do not define 'struct direct' when MSVC_PERL is defined because a
00057      * structure with that name is also defined in the Perl header
00058      * lib\CORE\dirent.h. Do not declare gettimeofday() either.
00059      */
00060 #ifndef MSVC_PERL
00061 
00062 #ifndef HAVE_READDIR
00063     /*
00064      * structure of a directory entry 
00065      */
00066     typedef struct direct {
00067         long            d_ino;  /* inode number (not used by MS-DOS) */
00068         int             d_namlen;       /* Name length */
00069         char            d_name[257];    /* file name */
00070     } _DIRECT;
00071 
00072     /*
00073      * structure for dir operations 
00074      */
00075     typedef struct _dir_struc {
00076         char           *start;  /* Starting position */
00077         char           *curr;   /* Current position */
00078         long            size;   /* Size of string table */
00079         long            nfiles; /* number if filenames in table */
00080         struct direct   dirstr; /* Directory structure to return */
00081     } DIR;
00082 
00083     NETSNMP_IMPORT
00084     DIR            *opendir(const char *filename);
00085     NETSNMP_IMPORT
00086     struct direct  *readdir(DIR * dirp);
00087     NETSNMP_IMPORT
00088     int             closedir(DIR * dirp);
00089 #endif /* HAVE_READDIR */
00090 
00091 #ifndef HAVE_GETTIMEOFDAY
00092     NETSNMP_IMPORT
00093     int             gettimeofday(struct timeval *, struct timezone *tz);
00094 #endif
00095 
00096 #endif                         /* MSVC_PERL */
00097 
00098 /*
00099  * Note: when compiling Net-SNMP with dmalloc enabled on a system without
00100  * strcasecmp() or strncasecmp(), the macro HAVE_STRNCASECMP is
00101  * not defined but strcasecmp() and strncasecmp() are defined as macros in
00102  * <dmalloc.h>. In order to prevent a compilation error, do not declare
00103  * strcasecmp() or strncasecmp() when the <dmalloc.h> header has been included.
00104  */
00105 #if !defined(HAVE_STRNCASECMP) && !defined(strcasecmp)
00106     NETSNMP_IMPORT
00107     int             strcasecmp(const char *s1, const char *s2);
00108 #endif
00109 #if !defined(HAVE_STRNCASECMP) && !defined(strncasecmp)
00110     NETSNMP_IMPORT
00111     int             strncasecmp(const char *s1, const char *s2, size_t n);
00112 #endif
00113 
00114 #ifdef WIN32
00115     NETSNMP_IMPORT
00116     char           *winsock_startup(void);
00117     NETSNMP_IMPORT
00118     void            winsock_cleanup(void);
00119 #define SOCK_STARTUP winsock_startup()
00120 #define SOCK_CLEANUP winsock_cleanup()
00121 #else                           /* !WIN32 */
00122 #define SOCK_STARTUP
00123 #define SOCK_CLEANUP
00124 #endif                          /* WIN32 */
00125 
00126 #include <net-snmp/types.h>     /* For definition of in_addr_t */
00127 
00128     /* Simply resolve a hostname and return first IPv4 address.
00129      * Returns -1 on error */
00130     NETSNMP_IMPORT
00131     int             netsnmp_gethostbyname_v4(const char* name,
00132                                              in_addr_t *addr_out);
00133 
00135     struct addrinfo; /* forward declare */
00136     NETSNMP_IMPORT
00137     struct hostent *netsnmp_gethostbyname(const char *name);
00138 
00139     NETSNMP_IMPORT
00140     struct hostent *netsnmp_gethostbyaddr(const void *addr, socklen_t len,
00141                                           int type);
00142 
00143     NETSNMP_IMPORT
00144     int             netsnmp_getaddrinfo(const char *name, const char *service,
00145                                         const struct addrinfo *hints,
00146                                         struct addrinfo **res);
00147 
00148     NETSNMP_IMPORT
00149     in_addr_t       get_myaddr(void);
00150     NETSNMP_IMPORT
00151     long            get_uptime(void);
00152 
00153 #ifndef HAVE_STRDUP
00154     char           *strdup(const char *);
00155 #endif
00156 #ifndef HAVE_SETENV
00157     NETSNMP_IMPORT
00158     int             setenv(const char *, const char *, int);
00159 #endif
00160 
00161     NETSNMP_IMPORT
00162     int             calculate_time_diff(const struct timeval *,
00163                                         const struct timeval *);
00164     NETSNMP_IMPORT
00165     u_int           calculate_sectime_diff(const struct timeval *now,
00166                                            const struct timeval *then);
00167 
00168 #ifndef HAVE_STRCASESTR
00169     char           *strcasestr(const char *, const char *);
00170 #endif
00171 #ifndef HAVE_STRTOL
00172     long            strtol(const char *, char **, int);
00173 #endif
00174 #ifndef HAVE_STRTOUL
00175     unsigned long   strtoul(const char *, char **, int);
00176 #endif
00177 #ifndef HAVE_STRTOULL
00178     NETSNMP_IMPORT uint64_t strtoull(const char *, char **, int);
00179 #endif
00180 #ifndef HAVE_STRTOK_R
00181     NETSNMP_IMPORT
00182     char           *strtok_r(char *, const char *, char **);
00183 #endif
00184 #ifndef HAVE_SNPRINTF
00185     int             snprintf(char *, size_t, const char *, ...);
00186 #endif
00187 
00188     NETSNMP_IMPORT
00189     int             mkdirhier(const char *pathname, mode_t mode,
00190                               int skiplast);
00191     NETSNMP_IMPORT
00192     const char     *netsnmp_mktemp(void);
00193 #ifndef HAVE_STRLCPY
00194     NETSNMP_IMPORT
00195     size_t            strlcpy(char *, const char *, size_t);
00196 #endif
00197 
00198     int             netsnmp_os_prematch(const char *ospmname,
00199                                         const char *ospmrelprefix);
00200     int             netsnmp_os_kernel_width(void);
00201 
00202     NETSNMP_IMPORT
00203     int             netsnmp_str_to_uid(const char *useroruid);
00204     NETSNMP_IMPORT
00205     int             netsnmp_str_to_gid(const char *grouporgid);
00206 
00207 #ifdef __cplusplus
00208 }
00209 #endif
00210 #endif                          /* SNMP_SYSTEM_H */