]>
Commit | Line | Data |
---|---|---|
52b7d2ce A |
1 | /* $Id: sockmisc.h,v 1.5.10.4 2005/10/04 09:54:27 manubsd Exp $ */ |
2 | ||
3 | /* | |
4 | * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project. | |
5 | * All rights reserved. | |
6 | * | |
7 | * Redistribution and use in source and binary forms, with or without | |
8 | * modification, are permitted provided that the following conditions | |
9 | * are met: | |
10 | * 1. Redistributions of source code must retain the above copyright | |
11 | * notice, this list of conditions and the following disclaimer. | |
12 | * 2. Redistributions in binary form must reproduce the above copyright | |
13 | * notice, this list of conditions and the following disclaimer in the | |
14 | * documentation and/or other materials provided with the distribution. | |
15 | * 3. Neither the name of the project nor the names of its contributors | |
16 | * may be used to endorse or promote products derived from this software | |
17 | * without specific prior written permission. | |
18 | * | |
19 | * THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND | |
20 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | |
21 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | |
22 | * ARE DISCLAIMED. IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE | |
23 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | |
24 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | |
25 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | |
26 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | |
27 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | |
28 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | |
29 | * SUCH DAMAGE. | |
30 | */ | |
31 | ||
32 | #ifndef _SOCKMISC_H | |
33 | #define _SOCKMISC_H | |
34 | ||
35 | struct netaddr { | |
36 | union { | |
85f41bec | 37 | struct sockaddr_storage sa; |
52b7d2ce A |
38 | struct sockaddr_in sin; |
39 | struct sockaddr_in6 sin6; | |
40 | } sa; | |
41 | unsigned long prefix; | |
42 | }; | |
43 | ||
44 | extern const int niflags; | |
45 | ||
65c25746 | 46 | extern int cmpsaddrwop (const struct sockaddr_storage *, const struct sockaddr_storage *); |
85f41bec | 47 | extern int cmpsaddrwop_withprefix(const struct sockaddr_storage *, const struct sockaddr_storage *, int); |
65c25746 A |
48 | extern int cmpsaddrwild (const struct sockaddr_storage *, const struct sockaddr_storage *); |
49 | extern int cmpsaddrstrict (const struct sockaddr_storage *, const struct sockaddr_storage *); | |
85f41bec | 50 | extern int cmpsaddrstrict_withprefix(const struct sockaddr_storage *, const struct sockaddr_storage *, int); |
52b7d2ce A |
51 | |
52 | #ifdef ENABLE_NATT | |
53 | #define CMPSADDR(saddr1, saddr2) cmpsaddrstrict((saddr1), (saddr2)) | |
d1e348cf | 54 | #define CMPSADDR2(saddr1, saddr2) cmpsaddrwild((saddr1), (saddr2)) |
52b7d2ce A |
55 | #else |
56 | #define CMPSADDR(saddr1, saddr2) cmpsaddrwop((saddr1), (saddr2)) | |
d1e348cf | 57 | #define CMPSADDR2(saddr1, saddr2) cmpsaddrwop((saddr1), (saddr2)) |
52b7d2ce A |
58 | #endif |
59 | ||
65c25746 | 60 | extern struct sockaddr_storage *getlocaladdr (struct sockaddr *); |
52b7d2ce | 61 | |
65c25746 A |
62 | extern int recvfromto (int, void *, size_t, int, |
63 | struct sockaddr_storage *, socklen_t *, struct sockaddr_storage *, unsigned int *); | |
64 | extern int sendfromto (int, const void *, size_t, | |
65 | struct sockaddr_storage *, struct sockaddr_storage *, int); | |
52b7d2ce | 66 | |
65c25746 | 67 | extern int setsockopt_bypass (int, int); |
52b7d2ce | 68 | |
65c25746 A |
69 | extern struct sockaddr_storage *newsaddr (int); |
70 | extern struct sockaddr_storage *dupsaddr (struct sockaddr_storage *); | |
71 | extern char *saddr2str (const struct sockaddr *); | |
85f41bec | 72 | extern char *saddr2str_with_prefix __P((const struct sockaddr *, int)); |
65c25746 A |
73 | extern char *saddrwop2str (const struct sockaddr *); |
74 | extern char *saddr2str_fromto (const char *format, | |
52b7d2ce | 75 | const struct sockaddr *saddr, |
65c25746 A |
76 | const struct sockaddr *daddr); |
77 | extern struct sockaddr_storage *str2saddr (char *, char *); | |
78 | extern void mask_sockaddr (struct sockaddr_storage *, const struct sockaddr_storage *, | |
79 | size_t); | |
52b7d2ce A |
80 | |
81 | /* struct netaddr functions */ | |
65c25746 A |
82 | extern char *naddrwop2str (const struct netaddr *naddr); |
83 | extern char *naddrwop2str_fromto (const char *format, const struct netaddr *saddr, | |
84 | const struct netaddr *daddr); | |
85f41bec | 85 | extern int naddr_score(const struct netaddr *naddr, const struct sockaddr_storage *saddr); |
52b7d2ce A |
86 | |
87 | /* Some usefull functions for sockaddr port manipulations. */ | |
65c25746 A |
88 | extern u_int16_t extract_port (const struct sockaddr_storage *addr); |
89 | extern u_int16_t *set_port (struct sockaddr_storage *addr, u_int16_t new_port); | |
90 | extern u_int16_t *get_port_ptr (struct sockaddr_storage *addr); | |
52b7d2ce A |
91 | |
92 | #endif /* _SOCKMISC_H */ |