xref: /freebsd/contrib/bsnmp/lib/support.h (revision d2ba5111c125104b09aa1acd1bfe8af2a24c79cc)
1 /*
2  * Copyright (C) 2004-2005
3  *	Hartmut Brandt.
4  *	All rights reserved.
5  *
6  * Author: Harti Brandt <harti@freebsd.org>
7  *
8  * Redistribution and use in source and binary forms, with or without
9  * modification, are permitted provided that the following conditions
10  * are met:
11  * 1. Redistributions of source code must retain the above copyright
12  *    notice, this list of conditions and the following disclaimer.
13  * 2. Redistributions in binary form must reproduce the above copyright
14  *    notice, this list of conditions and the following disclaimer in the
15  *    documentation and/or other materials provided with the distribution.
16  *
17  * THIS SOFTWARE IS PROVIDED BY AUTHOR AND CONTRIBUTORS ``AS IS'' AND
18  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20  * ARE DISCLAIMED.  IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS BE LIABLE
21  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27  * SUCH DAMAGE.
28  *
29  * $Begemot: bsnmp/lib/support.h,v 1.2 2005/10/06 07:14:59 brandt_h Exp $
30  *
31  * Functions that are missing on certain systems. This header file is not
32  * to be installed.
33  */
34 #ifndef bsnmp_support_h_
35 #define bsnmp_support_h_
36 
37 #include <sys/cdefs.h>
38 
39 #ifndef HAVE_ERR_H
40 void err(int, const char *, ...) __printflike(2, 3) __dead2;
41 void errx(int, const char *, ...) __printflike(2, 3) __dead2;
42 
43 void warn(const char *, ...) __printflike(1, 2);
44 void warnx(const char *, ...) __printflike(1, 2);
45 #endif
46 
47 #ifndef HAVE_STRLCPY
48 size_t strlcpy(char *, const char *, size_t);
49 #endif
50 
51 #ifndef HAVE_GETADDRINFO
52 
53 struct addrinfo {
54 	u_int	ai_flags;
55 	int	ai_family;
56 	int	ai_socktype;
57 	int	ai_protocol;
58 	struct sockaddr *ai_addr;
59 	int	ai_addrlen;
60 	struct addrinfo *ai_next;
61 };
62 #define	AI_CANONNAME	0x0001
63 
64 int getaddrinfo(const char *, const char *, const struct addrinfo *,
65     struct addrinfo **);
66 const char *gai_strerror(int);
67 void freeaddrinfo(struct addrinfo *);
68 
69 #endif
70 
71 /*
72  * For systems with missing stdint.h or inttypes.h
73  */
74 #if !defined(INT32_MIN)
75 #define	INT32_MIN	(-0x7fffffff-1)
76 #endif
77 #if !defined(INT32_MAX)
78 #define	INT32_MAX	(0x7fffffff)
79 #endif
80 #if !defined(UINT32_MAX)
81 #define	UINT32_MAX	(0xffffffff)
82 #endif
83 
84 /*
85  * Systems missing SA_SIZE(). Taken from FreeBSD net/route.h:1.63
86  */
87 #ifndef SA_SIZE
88 
89 #define SA_SIZE(sa)						\
90     (  (!(sa) || ((struct sockaddr *)(sa))->sa_len == 0) ?	\
91 	sizeof(long)		:				\
92 	1 + ( (((struct sockaddr *)(sa))->sa_len - 1) | (sizeof(long) - 1) ) )
93 
94 #endif
95 
96 #endif
97