]>
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 { | |
37 | struct sockaddr sa; | |
38 | struct sockaddr_in sin; | |
39 | struct sockaddr_in6 sin6; | |
40 | } sa; | |
41 | unsigned long prefix; | |
42 | }; | |
43 | ||
44 | extern const int niflags; | |
45 | ||
46 | extern int cmpsaddrwop __P((const struct sockaddr *, const struct sockaddr *)); | |
47 | extern int cmpsaddrwild __P((const struct sockaddr *, const struct sockaddr *)); | |
48 | extern int cmpsaddrstrict __P((const struct sockaddr *, const struct sockaddr *)); | |
49 | ||
50 | #ifdef ENABLE_NATT | |
51 | #define CMPSADDR(saddr1, saddr2) cmpsaddrstrict((saddr1), (saddr2)) | |
d1e348cf | 52 | #define CMPSADDR2(saddr1, saddr2) cmpsaddrwild((saddr1), (saddr2)) |
52b7d2ce A |
53 | #else |
54 | #define CMPSADDR(saddr1, saddr2) cmpsaddrwop((saddr1), (saddr2)) | |
d1e348cf | 55 | #define CMPSADDR2(saddr1, saddr2) cmpsaddrwop((saddr1), (saddr2)) |
52b7d2ce A |
56 | #endif |
57 | ||
58 | extern struct sockaddr *getlocaladdr __P((struct sockaddr *)); | |
59 | ||
60 | extern int recvfromto __P((int, void *, size_t, int, | |
61 | struct sockaddr *, socklen_t *, struct sockaddr *, unsigned int *)); | |
62 | extern int sendfromto __P((int, const void *, size_t, | |
63 | struct sockaddr *, struct sockaddr *, int)); | |
64 | ||
65 | extern int setsockopt_bypass __P((int, int)); | |
66 | ||
67 | extern struct sockaddr *newsaddr __P((int)); | |
68 | extern struct sockaddr *dupsaddr __P((struct sockaddr *)); | |
69 | extern char *saddr2str __P((const struct sockaddr *)); | |
70 | extern char *saddrwop2str __P((const struct sockaddr *)); | |
71 | extern char *saddr2str_fromto __P((const char *format, | |
72 | const struct sockaddr *saddr, | |
73 | const struct sockaddr *daddr)); | |
74 | extern struct sockaddr *str2saddr __P((char *, char *)); | |
75 | extern void mask_sockaddr __P((struct sockaddr *, const struct sockaddr *, | |
76 | size_t)); | |
77 | ||
78 | /* struct netaddr functions */ | |
79 | extern char *naddrwop2str __P((const struct netaddr *naddr)); | |
80 | extern char *naddrwop2str_fromto __P((const char *format, const struct netaddr *saddr, | |
81 | const struct netaddr *daddr)); | |
82 | extern int naddr_score(const struct netaddr *naddr, const struct sockaddr *saddr); | |
83 | ||
84 | /* Some usefull functions for sockaddr port manipulations. */ | |
85 | extern u_int16_t extract_port __P((const struct sockaddr *addr)); | |
86 | extern u_int16_t *set_port __P((struct sockaddr *addr, u_int16_t new_port)); | |
87 | extern u_int16_t *get_port_ptr __P((struct sockaddr *addr)); | |
88 | ||
89 | #endif /* _SOCKMISC_H */ |