2 * Copyright 2004 Sun Microsystems, Inc. All rights reserved.
3 * Use is subject to license terms.
6 #pragma ident "%Z%%M% %I% %E% SMI"
9 #include <socket-utils.h>
13 * convert a sockaddr_storage address to a krb5_address
14 * Returns address of krbap if success, NULL if error.
18 cvtkaddr(struct sockaddr_storage
*ss
, krb5_address
*krbap
)
20 switch (ss
->ss_family
) {
22 krbap
->contents
= (krb5_octet
*)
23 malloc(sizeof (ss2sin(ss
)->sin_addr
));
24 if (krbap
->contents
== NULL
)
26 memcpy((char *)krbap
->contents
,
27 (char *)&(ss2sin(ss
)->sin_addr
),
28 sizeof (ss2sin(ss
)->sin_addr
));
29 krbap
->addrtype
= ADDRTYPE_INET
;
30 krbap
->length
= sizeof (ss2sin(ss
)->sin_addr
);
33 if (IN6_IS_ADDR_V4MAPPED(&ss2sin6(ss
)->sin6_addr
)) {
34 /* coerce to IPv4 address */
35 krbap
->contents
= (krb5_octet
*)
36 malloc(IPV4_ADDR_LEN
);
37 if (krbap
->contents
== NULL
)
39 IN6_V4MAPPED_TO_IPADDR(
40 &(ss2sin6(ss
)->sin6_addr
),
41 *(ipaddr_t
*)(krbap
->contents
));
42 krbap
->addrtype
= ADDRTYPE_INET
;
43 krbap
->length
= IPV4_ADDR_LEN
;
45 krbap
->contents
= (krb5_octet
*)
46 malloc(sizeof (ss2sin6(ss
)->sin6_addr
));
47 if (krbap
->contents
== NULL
)
49 memcpy((char *)krbap
->contents
,
50 (char *)&ss2sin6(ss
)->sin6_addr
,
51 sizeof (ss2sin6(ss
)->sin6_addr
));
52 krbap
->addrtype
= ADDRTYPE_INET6
;
53 krbap
->length
= sizeof (ss2sin6(ss
)->sin6_addr
);