This repository has been archived by the owner on May 1, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
util.h
64 lines (56 loc) · 2.27 KB
/
util.h
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
/*
* Copyright (c) 2018, 2019 Tim Kuijsten
*
* Permission to use, copy, modify, and distribute this software for any purpose
* with or without fee is hereby granted, provided that the above copyright
* notice and this permission notice appear in all copies.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
* REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
* AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
* INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
* LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
* OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
* PERFORMANCE OF THIS SOFTWARE.
*/
#ifndef UTIL_H
#define UTIL_H
#include <sys/resource.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <stdio.h>
#define EMPTYDIR "/var/empty"
/* ethernet address in hex notation with terminating nul */
#define MAXLINKSTR 18
/* full ipv6 address in hex notation with braces, port and terminating nul */
#define MAXIPSTR 49
#define MAXADDRSTR (MAXIPSTR > MAXLINKSTR ? MAXIPSTR : MAXLINKSTR)
#define MIN(a,b) ((a) < (b) ? (a) : (b))
#define MAX(a,b) ((a) > (b) ? (a) : (b))
int isopenfd(int);
int readhexnomem(uint8_t *, size_t, const char *, size_t);
void hexdump(FILE *, const uint8_t *, size_t , size_t);
void xensurelimit(int, size_t);
int strtoaddr(struct sockaddr_storage *, const char *, const char *, int);
int addrtostr(char *, size_t, const struct sockaddr *, int);
void printopenfds(FILE *, int);
int data2file(const char *, const void *, size_t);
ssize_t writen(int, const void *, size_t);
int getport(const struct sockaddr *);
int resolveuser(uid_t *, gid_t *, const char *);
int resolvegroup(gid_t *, const char *);
int facilitystrtoint(int *, const char *);
int daemonize(void);
int initlog(const char *);
void logexit(int code, const char *, ...);
void logexitx(int code, const char *, ...);
void logwarn(const char *, ...);
void logwarnx(const char *, ...);
void lognotice(const char *, ...);
void lognoticex(const char *, ...);
void loginfo(const char *, ...);
void loginfox(const char *, ...);
void logdebug(const char *, ...);
void logdebugx(const char *, ...);
int isfdsafe(int, mode_t);
#endif /* UTIL_H */