1 /* grecs - Gray's Extensible Configuration System -*- c -*-
2    Copyright (C) 2007-2017 Sergey Poznyakoff
3 
4    Grecs is free software; you can redistribute it and/or modify it
5    under the terms of the GNU General Public License as published by the
6    Free Software Foundation; either version 3 of the License, or (at your
7    option) any later version.
8 
9    Grecs is distributed in the hope that it will be useful,
10    but WITHOUT ANY WARRANTY; without even the implied warranty of
11    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12    GNU General Public License for more details.
13 
14    You should have received a copy of the GNU General Public License along
15    with Grecs. If not, see <http://www.gnu.org/licenses/>. */
16 
17 #ifndef _GRECS_SOCKADDR_H
18 #define _GRECS_SOCKADDR_H
19 
20 struct grecs_sockaddr {
21 #if GRECS_SOCKADDR_LIST
22 	struct grecs_sockaddr *next;
23 	char *str;
24 #endif
25 	int len;
26 	struct sockaddr *sa;
27 };
28 
29 #if GRECS_SOCKADDR_LIST
30 
31 #define GRECS_AH_PASSIVE 0x01
32 #define GRECS_HINT_SERVICE 0x02
33 #define GRECS_HINT_PORT 0x04
34 
35 struct grecs_sockaddr_hints {
36 	int flags;
37 	char *service;
38 	unsigned short port;
39 };
40 
41 extern struct grecs_sockaddr_hints *grecs_sockaddr_hints;
42 
43 struct grecs_sockaddr *grecs_sockaddr_new(size_t s);
44 void grecs_sockaddr_free(struct grecs_sockaddr *p);
45 
46 int grecs_str_to_sockaddr(struct grecs_sockaddr **sap,
47 			  const char *arg, struct grecs_sockaddr_hints *gh,
48 			  grecs_locus_t const *locus);
49 char const *grecs_sockaddr_str(struct grecs_sockaddr *);
50 #endif
51 
52 #define GRECS_INADDR_BYTES 16
53 
54 struct grecs_cidr
55 {
56     int family;
57     int len;
58     unsigned char address[GRECS_INADDR_BYTES];
59     unsigned char netmask[GRECS_INADDR_BYTES];
60 };
61 
62 int grecs_str_to_cidr(struct grecs_cidr *pcidr, const char *str,
63 		      grecs_locus_t const *locus);
64 
65 int grecs_sockaddr_to_cidr(struct grecs_cidr *cidr, const struct sockaddr *sa);
66 int grecs_sockadd_cidr_match(struct sockaddr *sa, struct grecs_cidr *cidr);
67 
68 #endif
69