3 * lib/krb5/os/genaddrs.c
5 * Copyright 1995 by the Massachusetts Institute of Technology.
8 * Export of this software from the United States of America may
9 * require a specific license from the United States Government.
10 * It is the responsibility of any person or organization contemplating
11 * export to obtain such a license before exporting.
13 * WITHIN THAT CONSTRAINT, permission to use, copy, modify, and
14 * distribute this software and its documentation for any purpose and
15 * without fee is hereby granted, provided that the above copyright
16 * notice appear in all copies and that both that copyright notice and
17 * this permission notice appear in supporting documentation, and that
18 * the name of M.I.T. not be used in advertising or publicity pertaining
19 * to distribution of the software without specific, written prior
20 * permission. Furthermore if you modify this software you must label
21 * your software as modified software and not distribute it in such a
22 * fashion that it might be confused with the original M.I.T. software.
23 * M.I.T. makes no representations about the suitability of
24 * this software for any purpose. It is provided "as is" without express
25 * or implied warranty.
28 * Take an IP addr & port and generate a full IP address.
34 #if !defined(_WINSOCKAPI_)
35 #include <netinet/in.h>
38 /* Solaris Kerberos */
43 krb5_address addr
, port
;
46 #define SET(TARG, THING, TYPE) \
47 ((TARG).contents = (krb5_octet *) &(THING), \
48 (TARG).length = sizeof (THING), \
49 (TARG).addrtype = (TYPE))
51 static void *cvtaddr (struct sockaddr_storage
*a
, struct addrpair
*ap
)
53 switch (ss2sa(a
)->sa_family
) {
55 SET (ap
->port
, ss2sin(a
)->sin_port
, ADDRTYPE_IPPORT
);
56 SET (ap
->addr
, ss2sin(a
)->sin_addr
, ADDRTYPE_INET
);
60 SET (ap
->port
, ss2sin6(a
)->sin6_port
, ADDRTYPE_IPPORT
);
61 if (IN6_IS_ADDR_V4MAPPED (&ss2sin6(a
)->sin6_addr
)) {
62 ap
->addr
.addrtype
= ADDRTYPE_INET
;
63 /* Solaris Kerberos */
64 ap
->addr
.contents
= (IPV6_ADDR_LEN
- IPV4_ADDR_LEN
) +
65 (krb5_octet
*) &ss2sin6(a
)->sin6_addr
;
66 ap
->addr
.length
= IPV4_ADDR_LEN
;
68 SET (ap
->addr
, ss2sin6(a
)->sin6_addr
, ADDRTYPE_INET6
);
76 krb5_error_code KRB5_CALLCONV
77 krb5_auth_con_genaddrs(krb5_context context
, krb5_auth_context auth_context
, int infd
, int flags
)
79 krb5_error_code retval
;
84 SOCKET fd
= (SOCKET
) infd
;
85 struct addrpair laddrs
, raddrs
;
87 #ifdef HAVE_NETINET_IN_H
88 struct sockaddr_storage lsaddr
, rsaddr
;
89 GETSOCKNAME_ARG3_TYPE ssize
;
91 ssize
= sizeof(struct sockaddr_storage
);
92 if ((flags
& KRB5_AUTH_CONTEXT_GENERATE_LOCAL_FULL_ADDR
) ||
93 (flags
& KRB5_AUTH_CONTEXT_GENERATE_LOCAL_ADDR
)) {
94 if ((retval
= getsockname(fd
, (GETSOCKNAME_ARG2_TYPE
*) &lsaddr
,
98 if (cvtaddr (&lsaddr
, &laddrs
)) {
100 if (flags
& KRB5_AUTH_CONTEXT_GENERATE_LOCAL_FULL_ADDR
)
101 lport
= &laddrs
.port
;
105 return KRB5_PROG_ATYPE_NOSUPP
;
111 ssize
= sizeof(struct sockaddr_storage
);
112 if ((flags
& KRB5_AUTH_CONTEXT_GENERATE_REMOTE_FULL_ADDR
) ||
113 (flags
& KRB5_AUTH_CONTEXT_GENERATE_REMOTE_ADDR
)) {
114 if ((retval
= getpeername(fd
, (GETPEERNAME_ARG2_TYPE
*) &rsaddr
,
118 if (cvtaddr (&rsaddr
, &raddrs
)) {
119 raddr
= &raddrs
.addr
;
120 if (flags
& KRB5_AUTH_CONTEXT_GENERATE_REMOTE_FULL_ADDR
)
121 rport
= &raddrs
.port
;
125 return KRB5_PROG_ATYPE_NOSUPP
;
131 if (!(retval
= krb5_auth_con_setaddrs(context
, auth_context
, laddr
, raddr
)))
132 return (krb5_auth_con_setports(context
, auth_context
, lport
, rport
));
135 return KRB5_PROG_ATYPE_NOSUPP
;