xref: /onnv-gate/usr/src/lib/gss_mechs/mech_krb5/include/socket-utils.h (revision 7934:6aeeafc994de)
1781Sgtb /*
2*7934SMark.Phalan@Sun.COM  * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
3781Sgtb  * Use is subject to license terms.
4781Sgtb  */
5781Sgtb 
60Sstevel@tonic-gate 
70Sstevel@tonic-gate /*
8*7934SMark.Phalan@Sun.COM  * Copyright (C) 2001,2005 by the Massachusetts Institute of Technology,
90Sstevel@tonic-gate  * Cambridge, MA, USA.  All Rights Reserved.
100Sstevel@tonic-gate  *
110Sstevel@tonic-gate  * This software is being provided to you, the LICENSEE, by the
120Sstevel@tonic-gate  * Massachusetts Institute of Technology (M.I.T.) under the following
130Sstevel@tonic-gate  * license.  By obtaining, using and/or copying this software, you agree
140Sstevel@tonic-gate  * that you have read, understood, and will comply with these terms and
150Sstevel@tonic-gate  * conditions:
160Sstevel@tonic-gate  *
170Sstevel@tonic-gate  * Export of this software from the United States of America may
180Sstevel@tonic-gate  * require a specific license from the United States Government.
190Sstevel@tonic-gate  * It is the responsibility of any person or organization contemplating
200Sstevel@tonic-gate  * export to obtain such a license before exporting.
210Sstevel@tonic-gate  *
220Sstevel@tonic-gate  * WITHIN THAT CONSTRAINT, permission to use, copy, modify and distribute
230Sstevel@tonic-gate  * this software and its documentation for any purpose and without fee or
240Sstevel@tonic-gate  * royalty is hereby granted, provided that you agree to comply with the
250Sstevel@tonic-gate  * following copyright notice and statements, including the disclaimer, and
260Sstevel@tonic-gate  * that the same appear on ALL copies of the software and documentation,
270Sstevel@tonic-gate  * including modifications that you make for internal use or for
280Sstevel@tonic-gate  * distribution:
290Sstevel@tonic-gate  *
300Sstevel@tonic-gate  * THIS SOFTWARE IS PROVIDED "AS IS", AND M.I.T. MAKES NO REPRESENTATIONS
310Sstevel@tonic-gate  * OR WARRANTIES, EXPRESS OR IMPLIED.  By way of example, but not
320Sstevel@tonic-gate  * limitation, M.I.T. MAKES NO REPRESENTATIONS OR WARRANTIES OF
330Sstevel@tonic-gate  * MERCHANTABILITY OR FITNESS FOR ANY PARTICULAR PURPOSE OR THAT THE USE OF
340Sstevel@tonic-gate  * THE LICENSED SOFTWARE OR DOCUMENTATION WILL NOT INFRINGE ANY THIRD PARTY
350Sstevel@tonic-gate  * PATENTS, COPYRIGHTS, TRADEMARKS OR OTHER RIGHTS.
360Sstevel@tonic-gate  *
370Sstevel@tonic-gate  * The name of the Massachusetts Institute of Technology or M.I.T. may NOT
380Sstevel@tonic-gate  * be used in advertising or publicity pertaining to distribution of the
390Sstevel@tonic-gate  * software.  Title to copyright in this software and any associated
400Sstevel@tonic-gate  * documentation shall at all times remain with M.I.T., and USER agrees to
410Sstevel@tonic-gate  * preserve same.
420Sstevel@tonic-gate  *
430Sstevel@tonic-gate  * Furthermore if you modify this software you must label
440Sstevel@tonic-gate  * your software as modified software and not distribute it in such a
450Sstevel@tonic-gate  * fashion that it might be confused with the original M.I.T. software.
460Sstevel@tonic-gate  */
470Sstevel@tonic-gate 
480Sstevel@tonic-gate #ifndef SOCKET_UTILS_H
490Sstevel@tonic-gate #define SOCKET_UTILS_H
500Sstevel@tonic-gate 
510Sstevel@tonic-gate /* Some useful stuff cross-platform for manipulating socket addresses.
520Sstevel@tonic-gate    We assume at least ipv4 sockaddr_in support.  The sockaddr_storage
530Sstevel@tonic-gate    stuff comes from the ipv6 socket api enhancements; socklen_t is
540Sstevel@tonic-gate    provided on some systems; the rest is just convenience for internal
550Sstevel@tonic-gate    use in the krb5 tree.
560Sstevel@tonic-gate 
570Sstevel@tonic-gate    Do NOT install this file.  */
580Sstevel@tonic-gate 
590Sstevel@tonic-gate /* for HAVE_SOCKLEN_T, KRB5_USE_INET6, etc */
600Sstevel@tonic-gate #include "autoconf.h"
61781Sgtb /* for sockaddr_storage */
62781Sgtb #include "port-sockets.h"
63*7934SMark.Phalan@Sun.COM /* for "inline" if needed */
64*7934SMark.Phalan@Sun.COM #include "k5-platform.h"
650Sstevel@tonic-gate 
660Sstevel@tonic-gate #if defined (__GNUC__)
670Sstevel@tonic-gate /*
680Sstevel@tonic-gate  * There's a lot of confusion between pointers to different sockaddr
690Sstevel@tonic-gate  * types, and pointers with different degrees of indirection, as in
700Sstevel@tonic-gate  * the locate_kdc type functions.  Use these function to ensure we
710Sstevel@tonic-gate  * don't do something silly like cast a "sockaddr **" to a
720Sstevel@tonic-gate  * "sockaddr_in *".
730Sstevel@tonic-gate  *
740Sstevel@tonic-gate  * The casts to (void *) are to get GCC to shut up about alignment
750Sstevel@tonic-gate  * increasing.
760Sstevel@tonic-gate  */
sa2sin(struct sockaddr * sa)770Sstevel@tonic-gate static __inline__ struct sockaddr_in *sa2sin (struct sockaddr *sa)
780Sstevel@tonic-gate {
790Sstevel@tonic-gate     return (struct sockaddr_in *) (void *) sa;
800Sstevel@tonic-gate }
810Sstevel@tonic-gate #ifdef KRB5_USE_INET6
sa2sin6(struct sockaddr * sa)820Sstevel@tonic-gate static __inline__ struct sockaddr_in6 *sa2sin6 (struct sockaddr *sa)
830Sstevel@tonic-gate {
840Sstevel@tonic-gate     return (struct sockaddr_in6 *) (void *) sa;
850Sstevel@tonic-gate }
860Sstevel@tonic-gate #endif
ss2sa(struct sockaddr_storage * ss)870Sstevel@tonic-gate static __inline__ struct sockaddr *ss2sa (struct sockaddr_storage *ss)
880Sstevel@tonic-gate {
890Sstevel@tonic-gate     return (struct sockaddr *) ss;
900Sstevel@tonic-gate }
ss2sin(struct sockaddr_storage * ss)910Sstevel@tonic-gate static __inline__ struct sockaddr_in *ss2sin (struct sockaddr_storage *ss)
920Sstevel@tonic-gate {
930Sstevel@tonic-gate     return (struct sockaddr_in *) ss;
940Sstevel@tonic-gate }
950Sstevel@tonic-gate #ifdef KRB5_USE_INET6
ss2sin6(struct sockaddr_storage * ss)960Sstevel@tonic-gate static __inline__ struct sockaddr_in6 *ss2sin6 (struct sockaddr_storage *ss)
970Sstevel@tonic-gate {
980Sstevel@tonic-gate     return (struct sockaddr_in6 *) ss;
990Sstevel@tonic-gate }
1000Sstevel@tonic-gate #endif
1010Sstevel@tonic-gate #else
1020Sstevel@tonic-gate #define sa2sin(S)	((struct sockaddr_in *)(S))
1030Sstevel@tonic-gate #define sa2sin6(S)	((struct sockaddr_in6 *)(S))
1040Sstevel@tonic-gate #define ss2sa(S)	((struct sockaddr *)(S))
1050Sstevel@tonic-gate #define ss2sin(S)	((struct sockaddr_in *)(S))
1060Sstevel@tonic-gate #define ss2sin6(S)	((struct sockaddr_in6 *)(S))
1070Sstevel@tonic-gate #endif
1080Sstevel@tonic-gate 
1090Sstevel@tonic-gate #if !defined (socklen)
1100Sstevel@tonic-gate /* socklen_t socklen (struct sockaddr *) */
1110Sstevel@tonic-gate #  ifdef HAVE_SA_LEN
1120Sstevel@tonic-gate #    define socklen(X) ((X)->sa_len)
1130Sstevel@tonic-gate #  else
1140Sstevel@tonic-gate #    ifdef KRB5_USE_INET6
1150Sstevel@tonic-gate #      define socklen(X) ((X)->sa_family == AF_INET6 ? (socklen_t) sizeof (struct sockaddr_in6) : (X)->sa_family == AF_INET ? (socklen_t) sizeof (struct sockaddr_in) : (socklen_t) sizeof (struct sockaddr))
1160Sstevel@tonic-gate #    else
1170Sstevel@tonic-gate #      define socklen(X) ((X)->sa_family == AF_INET ? (socklen_t) sizeof (struct sockaddr_in) : (socklen_t) sizeof (struct sockaddr))
1180Sstevel@tonic-gate #    endif
1190Sstevel@tonic-gate #  endif
1200Sstevel@tonic-gate #endif
1210Sstevel@tonic-gate 
1220Sstevel@tonic-gate #endif /* SOCKET_UTILS_H */
123