]> git.saurik.com Git - apple/ipsec.git/blame - ipsec-tools/racoon/sockmisc.h
ipsec-317.220.1.tar.gz
[apple/ipsec.git] / ipsec-tools / racoon / sockmisc.h
CommitLineData
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
35struct 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
44extern const int niflags;
45
65c25746 46extern int cmpsaddrwop (const struct sockaddr_storage *, const struct sockaddr_storage *);
85f41bec 47extern int cmpsaddrwop_withprefix(const struct sockaddr_storage *, const struct sockaddr_storage *, int);
65c25746
A
48extern int cmpsaddrwild (const struct sockaddr_storage *, const struct sockaddr_storage *);
49extern int cmpsaddrstrict (const struct sockaddr_storage *, const struct sockaddr_storage *);
85f41bec 50extern 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 60extern struct sockaddr_storage *getlocaladdr (struct sockaddr *);
52b7d2ce 61
65c25746
A
62extern int recvfromto (int, void *, size_t, int,
63 struct sockaddr_storage *, socklen_t *, struct sockaddr_storage *, unsigned int *);
64extern int sendfromto (int, const void *, size_t,
65 struct sockaddr_storage *, struct sockaddr_storage *, int);
52b7d2ce 66
65c25746 67extern int setsockopt_bypass (int, int);
52b7d2ce 68
65c25746
A
69extern struct sockaddr_storage *newsaddr (int);
70extern struct sockaddr_storage *dupsaddr (struct sockaddr_storage *);
71extern char *saddr2str (const struct sockaddr *);
85f41bec 72extern char *saddr2str_with_prefix __P((const struct sockaddr *, int));
65c25746
A
73extern char *saddrwop2str (const struct sockaddr *);
74extern char *saddr2str_fromto (const char *format,
52b7d2ce 75 const struct sockaddr *saddr,
65c25746
A
76 const struct sockaddr *daddr);
77extern struct sockaddr_storage *str2saddr (char *, char *);
78extern void mask_sockaddr (struct sockaddr_storage *, const struct sockaddr_storage *,
79 size_t);
52b7d2ce
A
80
81/* struct netaddr functions */
65c25746
A
82extern char *naddrwop2str (const struct netaddr *naddr);
83extern char *naddrwop2str_fromto (const char *format, const struct netaddr *saddr,
84 const struct netaddr *daddr);
85f41bec 85extern 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
88extern u_int16_t extract_port (const struct sockaddr_storage *addr);
89extern u_int16_t *set_port (struct sockaddr_storage *addr, u_int16_t new_port);
90extern u_int16_t *get_port_ptr (struct sockaddr_storage *addr);
52b7d2ce
A
91
92#endif /* _SOCKMISC_H */