From 3f4c9c70f544c562e6df2cb5b62507ffa96bebcb Mon Sep 17 00:00:00 2001 From: Ken Raeburn Date: Thu, 30 Aug 2001 00:31:06 +0000 Subject: [PATCH] move socket util definitions (socklen_t, sa2sin, etc) from k5-int to a new file git-svn-id: svn://anonsvn.mit.edu/krb5/trunk@13689 dc483132-0cff-0310-8789-dd5450dbe970 --- src/include/ChangeLog | 8 +++++ src/include/k5-int.h | 67 +++-------------------------------- src/include/socket-utils.h | 72 ++++++++++++++++++++++++++++++++++++++ 3 files changed, 84 insertions(+), 63 deletions(-) create mode 100644 src/include/socket-utils.h diff --git a/src/include/ChangeLog b/src/include/ChangeLog index ffc8ed424..0f969ec31 100644 --- a/src/include/ChangeLog +++ b/src/include/ChangeLog @@ -1,5 +1,13 @@ 2001-08-29 Ken Raeburn + * socket-utils.h: New file. + * k5-int.h: Include it. + (socklen_t, struct krb5int_sockaddr_storage, sa2sin, sa2sin6, + ss2sa, ss2sin, ss2sin6, socklen): Definitions moved to + socket-utils.h. + (krb5int_get_fq_local_hostname, krb5int_translate_gai_error): New + decls. + * fake-addrinfo.c: New file, split off from fake-addrinfo.h. * fake-addrinfo.h: Don't define implementation functions. (FAI_DEFINED): New macro, used to protect against multiple diff --git a/src/include/k5-int.h b/src/include/k5-int.h index 4f0edca2b..d3386927a 100644 --- a/src/include/k5-int.h +++ b/src/include/k5-int.h @@ -188,69 +188,7 @@ typedef unsigned char u_char; #ifdef NEED_SOCKETS #include "port-sockets.h" - -/* Either size_t or int or unsigned int is probably right. Under - SunOS 4, it looks like int is desired, according to the accept man - page. */ -#ifndef HAVE_SOCKLEN_T -typedef int socklen_t; -#endif - -#ifndef KRB5_USE_INET6 /* XXX should only be done if sockaddr_storage not found */ -struct krb5int_sockaddr_storage { struct sockaddr_in s; }; -#define sockaddr_storage krb5int_sockaddr_storage -#endif - -#if defined (__GNUC__) -/* There's a lot of confusion between pointers to different sockaddr - types, and pointers with different degrees of indirection, as in - the locate_kdc type functions. Use these function to ensure we - don't do something silly like cast a "sockaddr **" to a - "sockaddr_in *". */ -static __inline__ struct sockaddr_in *sa2sin (struct sockaddr *sa) -{ - return (struct sockaddr_in *) sa; -} -#ifdef KRB5_USE_INET6xxNotUsed -static __inline__ struct sockaddr_in6 *sa2sin6 (struct sockaddr *sa) -{ - return (struct sockaddr_in6 *) sa; -} -#endif -static __inline__ struct sockaddr *ss2sa (struct sockaddr_storage *ss) -{ - return (struct sockaddr *) ss; -} -static __inline__ struct sockaddr_in *ss2sin (struct sockaddr_storage *ss) -{ - return (struct sockaddr_in *) ss; -} -static __inline__ struct sockaddr_in6 *ss2sin6 (struct sockaddr_storage *ss) -{ - return (struct sockaddr_in6 *) ss; -} -#else -#define sa2sin(S) ((struct sockaddr_in *)(S)) -#define sa2sin6(S) ((struct sockaddr_in6 *)(S)) -#define ss2sa(S) ((struct sockaddr *)(S)) -#define ss2sin(S) ((struct sockaddr_in *)(S)) -#define ss2sin6(S) ((struct sockaddr_in6 *)(S)) -#endif - -#if !defined (socklen) -/* size_t socklen (struct sockaddr *) */ -/* Should this return socklen_t instead? */ -# ifdef HAVE_SA_LEN -# define socklen(X) ((X)->sa_len) -# else -# ifdef KRB5_USE_INET6 -# define socklen(X) ((X)->sa_family == AF_INET6 ? sizeof (struct sockaddr_in6) : (X)->sa_family == AF_INET ? sizeof (struct sockaddr_in) : sizeof (struct sockaddr)) -# else -# define socklen(X) ((X)->sa_family == AF_INET ? sizeof (struct sockaddr_in) : sizeof (struct sockaddr)) -# endif -# endif -#endif - +#include "socket-utils.h" #else #ifndef SOCK_DGRAM struct sockaddr; @@ -540,6 +478,7 @@ krb5_error_code krb5_free_krbhst (krb5_context, char * const * ); krb5_error_code krb5_create_secure_file (krb5_context, const char * pathname); krb5_error_code krb5_sync_disk_file (krb5_context, FILE *fp); +krb5_error_code krb5int_get_fq_local_hostname (char *, size_t); krb5_error_code krb5_os_init_context (krb5_context); @@ -1678,4 +1617,6 @@ krb5_error_code krb5_rc_register_type extern krb5_rc_ops krb5_rc_dfl_ops; +extern krb5_error_code krb5int_translate_gai_error (int); + #endif /* _KRB5_INT_H */ diff --git a/src/include/socket-utils.h b/src/include/socket-utils.h new file mode 100644 index 000000000..d592f9597 --- /dev/null +++ b/src/include/socket-utils.h @@ -0,0 +1,72 @@ +#ifndef SOCKET_UTILS_H +#define SOCKET_UTILS_H + +/* Some useful stuff cross-platform. */ + +/* for HAVE_SOCKLEN_T, KRB5_USE_INET6, HAVE_SA_LEN */ +#include "krb5/autoconf.h" + +/* Either size_t or int or unsigned int is probably right. Under + SunOS 4, it looks like int is desired, according to the accept man + page. */ +#ifndef HAVE_SOCKLEN_T +typedef int socklen_t; +#endif + +/* XXX should only be done if sockaddr_storage not found */ +#ifndef KRB5_USE_INET6 +struct krb5int_sockaddr_storage { struct sockaddr_in s; }; +#define sockaddr_storage krb5int_sockaddr_storage +#endif + +#if defined (__GNUC__) +/* There's a lot of confusion between pointers to different sockaddr + types, and pointers with different degrees of indirection, as in + the locate_kdc type functions. Use these function to ensure we + don't do something silly like cast a "sockaddr **" to a + "sockaddr_in *". */ +static __inline__ struct sockaddr_in *sa2sin (struct sockaddr *sa) +{ + return (struct sockaddr_in *) sa; +} +#ifdef KRB5_USE_INET6xxNotUsed +static __inline__ struct sockaddr_in6 *sa2sin6 (struct sockaddr *sa) +{ + return (struct sockaddr_in6 *) sa; +} +#endif +static __inline__ struct sockaddr *ss2sa (struct sockaddr_storage *ss) +{ + return (struct sockaddr *) ss; +} +static __inline__ struct sockaddr_in *ss2sin (struct sockaddr_storage *ss) +{ + return (struct sockaddr_in *) ss; +} +static __inline__ struct sockaddr_in6 *ss2sin6 (struct sockaddr_storage *ss) +{ + return (struct sockaddr_in6 *) ss; +} +#else +#define sa2sin(S) ((struct sockaddr_in *)(S)) +#define sa2sin6(S) ((struct sockaddr_in6 *)(S)) +#define ss2sa(S) ((struct sockaddr *)(S)) +#define ss2sin(S) ((struct sockaddr_in *)(S)) +#define ss2sin6(S) ((struct sockaddr_in6 *)(S)) +#endif + +#if !defined (socklen) +/* size_t socklen (struct sockaddr *) */ +/* Should this return socklen_t instead? */ +# ifdef HAVE_SA_LEN +# define socklen(X) ((X)->sa_len) +# else +# ifdef KRB5_USE_INET6 +# define socklen(X) ((X)->sa_family == AF_INET6 ? sizeof (struct sockaddr_in6) : (X)->sa_family == AF_INET ? sizeof (struct sockaddr_in) : sizeof (struct sockaddr)) +# else +# define socklen(X) ((X)->sa_family == AF_INET ? sizeof (struct sockaddr_in) : sizeof (struct sockaddr)) +# endif +# endif +#endif + +#endif /* SOCKET_UTILS_H */ -- 2.26.2