Home | History | Annotate | Download | only in racoon
      1 /*	$NetBSD: sockmisc.h,v 1.7 2006/09/09 16:22:10 manu Exp $	*/
      2 
      3 /* Id: sockmisc.h,v 1.9 2005/10/05 16:55:41 manubsd Exp */
      4 
      5 /*
      6  * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
      7  * All rights reserved.
      8  *
      9  * Redistribution and use in source and binary forms, with or without
     10  * modification, are permitted provided that the following conditions
     11  * are met:
     12  * 1. Redistributions of source code must retain the above copyright
     13  *    notice, this list of conditions and the following disclaimer.
     14  * 2. Redistributions in binary form must reproduce the above copyright
     15  *    notice, this list of conditions and the following disclaimer in the
     16  *    documentation and/or other materials provided with the distribution.
     17  * 3. Neither the name of the project nor the names of its contributors
     18  *    may be used to endorse or promote products derived from this software
     19  *    without specific prior written permission.
     20  *
     21  * THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND
     22  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     23  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     24  * ARE DISCLAIMED.  IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE
     25  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     26  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     27  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     28  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     29  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     30  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     31  * SUCH DAMAGE.
     32  */
     33 
     34 #ifndef _SOCKMISC_H
     35 #define _SOCKMISC_H
     36 
     37 struct netaddr {
     38 	union {
     39 		struct sockaddr sa;
     40 		struct sockaddr_in sin;
     41 		struct sockaddr_in6 sin6;
     42 	} sa;
     43 	unsigned long prefix;
     44 };
     45 
     46 extern const int niflags;
     47 
     48 extern int cmpsaddrwop __P((const struct sockaddr *, const struct sockaddr *));
     49 extern int cmpsaddrwild __P((const struct sockaddr *, const struct sockaddr *));
     50 extern int cmpsaddrstrict __P((const struct sockaddr *, const struct sockaddr *));
     51 
     52 #ifdef ENABLE_NATT
     53 #define CMPSADDR(saddr1, saddr2) cmpsaddrstrict((saddr1), (saddr2))
     54 #else
     55 #define CMPSADDR(saddr1, saddr2) cmpsaddrwop((saddr1), (saddr2))
     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 */
     90