# include <inet.h>
# else
# include <sys/socket.h>
-# ifndef NO_SYS_UN_H
+# if !defined(NO_SYS_UN_H) && defined(AF_UNIX) && !defined(OPENSSL_NO_UNIX_SOCK)
# include <sys/un.h>
# ifndef UNIX_PATH_MAX
# define UNIX_PATH_MAX sizeof(((struct sockaddr_un *)NULL)->sun_path)
# endif
# endif
+/*
+ * Some platforms define AF_UNIX, but don't support it
+ */
+# if !defined(OPENSSL_NO_UNIX_SOCK)
+# if !defined(AF_UNIX) || defined(NO_SYS_UN_H)
+# define OPENSSL_NO_UNIX_SOCK
+# endif
+# endif
+
# define get_last_socket_error() errno
# define clear_socket_error() errno=0