]>
git.ipfire.org Git - people/ms/strongswan.git/blob - src/libfreeswan/addrtypeof.c
2 * extract parts of an ip_address
3 * Copyright (C) 2000 Henry Spencer.
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>.
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.
15 * RCSID $Id: addrtypeof.c,v 1.1 2004/03/15 20:35:25 as Exp $
21 - addrtypeof - get the type of an ip_address
25 const ip_address
*src
;
27 return src
->u
.v4
.sin_family
;
31 - addrbytesptr - get pointer to the address bytes of an ip_address
33 size_t /* 0 for error */
34 addrbytesptr(src
, dstp
)
35 const ip_address
*src
;
36 const unsigned char **dstp
; /* NULL means just a size query */
38 const unsigned char *p
;
41 switch (src
->u
.v4
.sin_family
) {
43 p
= (const unsigned char *)&src
->u
.v4
.sin_addr
.s_addr
;
47 p
= (const unsigned char *)&src
->u
.v6
.sin6_addr
;
61 - addrlenof - get length of the address bytes of an ip_address
63 size_t /* 0 for error */
65 const ip_address
*src
;
67 return addrbytesptr(src
, NULL
);
71 - addrbytesof - get the address bytes of an ip_address
73 size_t /* 0 for error */
74 addrbytesof(src
, dst
, dstlen
)
75 const ip_address
*src
;
79 const unsigned char *p
;
83 n
= addrbytesptr(src
, &p
);
91 memcpy(dst
, p
, ncopy
);