File: nsock.h

package info (click to toggle)
nagios4 4.4.6-4.1
  • links: PTS
  • area: main
  • in suites: sid, trixie
  • size: 22,336 kB
  • sloc: ansic: 97,631; sh: 12,619; javascript: 5,483; perl: 2,624; makefile: 1,265; php: 381; ruby: 95
file content (76 lines) | stat: -rw-r--r-- 2,783 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
#ifndef LIBNAGIOS_NSOCK_H_INCLUDED
#define LIBNAGIOS_NSOCK_H_INCLUDED
#include <errno.h>

/**
 * @file nsock.h
 * @brief Nagios socket helper library
 *
 * This is a pretty stupid library, but since so many addons and
 * now Nagios core itself makes use of sockets, we might as well
 * have some simple wrappers for it that handle the most common
 * cases.
 *
 * @{
 */

#define NSOCK_EBIND    (-1)     /**< failed to bind() */
#define NSOCK_ELISTEN  (-2)     /**< failed to listen() */
#define NSOCK_ESOCKET  (-3)     /**< failed to socket() */
#define NSOCK_EUNLINK  (-4)     /**< failed to unlink() */
#define NSOCK_ECONNECT (-5)     /**< failed to connect() */
#define NSOCK_EFCNTL   (-6)     /**< failed to fcntl() */
#define NSOCK_EINVAL (-EINVAL) /**< -22, normally */

/* flags for the various create calls */
#define NSOCK_TCP     (1 << 0)  /**< use tcp mode */
#define NSOCK_UDP     (1 << 1)  /**< use udp mode */
#define NSOCK_UNLINK  (1 << 2)  /**< unlink existing path (only nsock_unix) */
#define NSOCK_REUSE   (1 << 2)  /**< reuse existing address */
#define NSOCK_CONNECT (1 << 3)  /**< connect rather than create */
#define NSOCK_BLOCK   (1 << 4)  /**< socket should be in blocking mode */

/**
 * Grab an error string relating to nsock_unix()
 * @param code The error code return by the nsock library
 * @return An error string describing the error
 */
extern const char *nsock_strerror(int code);

/**
 * Create or connect to a unix socket
 * To control permissions on sockets when NSOCK_LISTEN is specified,
 * callers will have to modify their umask() before (and possibly
 * after) the nsock_unix() call.
 *
 * @param path The path to connect to or create
 * @param flags Various options controlling the mode of the socket
 * @return An NSOCK_E macro on errors, the created socket on success
 */
extern int nsock_unix(const char *path, unsigned int flags);

/**
 * Write a nul-terminated message to the socket pointed to by sd.
 * This isn't quite the same as dprintf(), which doesn't include
 * the terminating nul byte.
 * @note This function may block, so poll(2) for writability
 * @param sd The socket to write to
 * @param fmt The format string
 * @return Whatever write() returns
 */
extern int nsock_printf_nul(int sd, const char *fmt, ...)
	__attribute__((__format__(__printf__, 2, 3)));

/**
 * Write a printf()-formatted string to the socket pointed to by sd.
 * This is identical to dprintf(), which is unfortunately GNU only.
 * @note This function may block, so poll(2) for writability
 * @param sd The socket to write to
 * @param fmt The format string
 * @return Whatever write() returns
 */
extern int nsock_printf(int sd, const char *fmt, ...)
	__attribute__((__format__(__printf__, 2, 3)));

/** @} */
#endif /* LIBNAGIOS_NSOCK_H_INCLUDED */