]> git.ipfire.org Git - people/ms/strongswan.git/blob - src/libfreeswan/libfreeswan/subnetof.c
- started to rebuild source layout
[people/ms/strongswan.git] / src / libfreeswan / libfreeswan / subnetof.c
1 /*
2 * minor network-address manipulation utilities
3 * Copyright (C) 1998, 1999 Henry Spencer.
4 *
5 * This library is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU Library General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or (at your
8 * option) any later version. See <http://www.fsf.org/copyleft/lgpl.txt>.
9 *
10 * This library is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
12 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public
13 * License for more details.
14 *
15 * RCSID $Id: subnetof.c,v 1.1 2004/03/15 20:35:26 as Exp $
16 */
17 #include "internal.h"
18 #include "freeswan.h"
19
20 /*
21 - subnetof - given address and mask, return subnet part
22 */
23 struct in_addr
24 subnetof(addr, mask)
25 struct in_addr addr;
26 struct in_addr mask;
27 {
28 struct in_addr result;
29
30 result.s_addr = addr.s_addr & mask.s_addr;
31 return result;
32 }
33
34 /*
35 - hostof - given address and mask, return host part
36 */
37 struct in_addr
38 hostof(addr, mask)
39 struct in_addr addr;
40 struct in_addr mask;
41 {
42 struct in_addr result;
43
44 result.s_addr = addr.s_addr & ~mask.s_addr;
45 return result;
46 }
47
48 /*
49 - broadcastof - given (network) address and mask, return broadcast address
50 */
51 struct in_addr
52 broadcastof(addr, mask)
53 struct in_addr addr;
54 struct in_addr mask;
55 {
56 struct in_addr result;
57
58 result.s_addr = addr.s_addr | ~mask.s_addr;
59 return result;
60 }