?RCS: $Id: d_socket.U,v 3.0.1.2 1997/02/28 15:46:00 ram Exp $
?RCS:
?RCS: Copyright (c) 1991-1993, Raphael Manfredi
?RCS:
?RCS: You may redistribute only under the terms of the Artistic License,
?RCS: as specified in the README file that comes with the distribution.
?RCS: You may reuse parts of this distribution only within the terms of
?RCS: that same Artistic License; a copy of which may be found at the root
?RCS: of the source tree for dist 3.0.
?RCS:
?RCS: $Log: d_socket.U,v $
?RCS: Revision 3.0.1.2  1997/02/28  15:46:00  ram
?RCS: patch61: replaced .a with $_a all over the place
?RCS:
?RCS: Revision 3.0.1.1  1994/01/24  14:08:04  ram
?RCS: patch16: can now safely declare private nm_extract in dependencies
?RCS:
?RCS: Revision 3.0  1993/08/18  12:07:26  ram
?RCS: Baseline for dist 3.0 netwide release.
?RCS:
?MAKE:d_socket d_oldsock d_sockpair socketlib sockethdr \
	d_msg_ctrunc d_msg_dontroute d_msg_oob d_msg_peek d_msg_proxy \
	d_scm_rights d_sockaddr_sa_len d_sockaddr_in6 d_sin6_scope_id \
	d_ip_mreq d_ip_mreq_source d_ipv6_mreq d_ipv6_mreq_source \
	d_sockaddr_storage: \
	contains echo n c ar nm nm_opt nm_extract Inlibc Csym _a \
	Compile cat rm_try Setvar Hasfield sysroot
?MAKE:	-pick add $@ %<
?S:d_socket:
?S:	This variable conditionally defines HAS_SOCKET, which indicates
?S:	that the BSD socket interface is supported.
?S:.
?S:d_sockpair:
?S:	This variable conditionally defines the HAS_SOCKETPAIR symbol, which
?S:	indicates that the BSD socketpair() is supported.
?S:.
?S:d_oldsock:
?S:	This variable conditionally defines the OLDSOCKET symbol, which
?S:	indicates that the BSD socket interface is based on 4.1c and not 4.2.
?S:.
?S:d_msg_ctrunc:
?S:	This variable conditionally defines the HAS_MSG_CTRUNC symbol,
?S:	which indicates that the MSG_CTRUNC is available.  #ifdef is
?S:	not enough because it may be an enum, glibc has been known to do this.
?S:.
?S:d_msg_dontroute:
?S:	This variable conditionally defines the HAS_MSG_DONTROUTE symbol,
?S:	which indicates that the MSG_DONTROUTE is available.  #ifdef is
?S:	not enough because it may be an enum, glibc has been known to do this.
?S:.
?S:d_msg_oob:
?S:	This variable conditionally defines the HAS_MSG_OOB symbol,
?S:	which indicates that the MSG_OOB is available.  #ifdef is
?S:	not enough because it may be an enum, glibc has been known to do this.
?S:.
?S:d_msg_peek:
?S:	This variable conditionally defines the HAS_MSG_PEEK symbol,
?S:	which indicates that the MSG_PEEK is available.  #ifdef is
?S:	not enough because it may be an enum, glibc has been known to do this.
?S:.
?S:d_msg_proxy:
?S:	This variable conditionally defines the HAS_MSG_PROXY symbol,
?S:	which indicates that the MSG_PROXY is available.  #ifdef is
?S:	not enough because it may be an enum, glibc has been known to do this.
?S:.
?S:d_scm_rights:
?S:	This variable conditionally defines the HAS_SCM_RIGHTS symbol,
?S:	which indicates that the SCM_RIGHTS is available.  #ifdef is
?S:	not enough because it may be an enum, glibc has been known to do this.
?S:.
?S:d_sockaddr_sa_len:
?S:	This variable conditionally defines the HAS_SOCKADDR_SA_LEN symbol,
?S:	which indicates that a struct sockaddr structure has the sa_len
?S:	member.
?S:.
?S:d_sockaddr_in6:
?S:	This variable conditionally defines the HAS_SOCKADDR_IN6 symbol, which
?S:	indicates the availability of a struct sockaddr_in6.
?S:.
?S:d_sockaddr_storage:
?S:	This variable conditionally defines the HAS_SOCKADDR_STORAGE symbol,
?S:	which indicates the availability of a struct sockaddr_storage.
?S:.
?S:d_sin6_scope_id:
?S:	This variable conditionally defines the HAS_SIN6_SCOPE_ID symbol, which
?S:	indicates that a struct sockaddr_in6 structure has the sin6_scope_id
?S:	member.
?S:.
?S:d_ip_mreq:
?S:	This variable conditionally defines the HAS_IP_MREQ symbol, which
?S:	indicates the availability of a struct ip_mreq.
?S:.
?S:d_ip_mreq_source:
?S:	This variable conditionally defines the HAS_IP_MREQ_SOURCE symbol,
?S:	which indicates the availability of a struct ip_mreq_source.
?S:.
?S:d_ipv6_mreq:
?S:	This variable conditionally defines the HAS_IPV6_MREQ symbol, which
?S:	indicates the availability of a struct ipv6_mreq.
?S:.
?S:d_ipv6_mreq_source:
?S:	This variable conditionally defines the HAS_IPV6_MREQ_SOURCE symbol,
?S:	which indicates the availability of a struct ipv6_mreq_source.
?S:.
?S:socketlib:
?S:	This variable has the names of any libraries needed for socket support.
?S:.
?S:sockethdr:
?S:	This variable has any cpp '-I' flags needed for socket support.
?S:.
?C:HAS_SOCKET (SOCKET):
?C:	This symbol, if defined, indicates that the BSD socket interface is
?C:	supported.
?C:.
?C:HAS_SOCKETPAIR (SOCKETPAIR):
?C:	This symbol, if defined, indicates that the BSD socketpair() call is
?C:	supported.
?C:.
?C:USE_OLDSOCKET (OLDSOCKET):
?C:	This symbol, if defined, indicates that the 4.1c BSD socket interface
?C:	is supported instead of the 4.2/4.3 BSD socket interface. For instance,
?C:	there is no setsockopt() call.
?C:.
?C:HAS_MSG_CTRUNC:
?C:	This symbol, if defined, indicates that the MSG_CTRUNC is supported.
?C:	Checking just with #ifdef might not be enough because this symbol
?C:	has been known to be an enum.
?C:.
?C:HAS_MSG_DONTROUTE:
?C:	This symbol, if defined, indicates that the MSG_DONTROUTE is supported.
?C:	Checking just with #ifdef might not be enough because this symbol
?C:	has been known to be an enum.
?C:.
?C:HAS_MSG_OOB:
?C:	This symbol, if defined, indicates that the MSG_OOB is supported.
?C:	Checking just with #ifdef might not be enough because this symbol
?C:	has been known to be an enum.
?C:.
?C:HAS_MSG_PEEK:
?C:	This symbol, if defined, indicates that the MSG_PEEK is supported.
?C:	Checking just with #ifdef might not be enough because this symbol
?C:	has been known to be an enum.
?C:.
?C:HAS_MSG_PROXY:
?C:	This symbol, if defined, indicates that the MSG_PROXY is supported.
?C:	Checking just with #ifdef might not be enough because this symbol
?C:	has been known to be an enum.
?C:.
?C:HAS_SCM_RIGHTS:
?C:	This symbol, if defined, indicates that the SCM_RIGHTS is supported.
?C:	Checking just with #ifdef might not be enough because this symbol
?C:	has been known to be an enum.
?C:.
?C:HAS_SOCKADDR_SA_LEN:
?C:	This symbol, if defined, indicates that the struct sockaddr
?C:	structure has a member called sa_len, indicating the length of
?C:	the structure.
?C:.
?C:HAS_SOCKADDR_IN6:
?C:	This symbol, if defined, indicates the availability of
?C:	struct sockaddr_in6;
?C:.
?C:HAS_SOCKADDR_STORAGE:
?C:	This symbol, if defined, indicates the availability of
?C:	struct sockaddr_storage;
?C:.
?C:HAS_SIN6_SCOPE_ID:
?C:	This symbol, if defined, indicates that the struct sockaddr_in6
?C:	structure has a member called sin6_scope_id.
?C:.
?C:HAS_IP_MREQ:
?C:	This symbol, if defined, indicates the availability of
?C:	struct ip_mreq;
?C:.
?C:HAS_IP_MREQ_SOURCE:
?C:	This symbol, if defined, indicates the availability of
?C:	struct ip_mreq_source;
?C:.
?C:HAS_IPV6_MREQ:
?C:	This symbol, if defined, indicates the availability of
?C:	struct ipv6_mreq;
?C:.
?C:HAS_IPV6_MREQ_SOURCE:
?C:	This symbol, if defined, indicates the availability of
?C:	struct ipv6_mreq_source;
?C:.
?H:#$d_socket	HAS_SOCKET		/**/
?H:#$d_sockpair	HAS_SOCKETPAIR	/**/
?H:#$d_sockaddr_sa_len	HAS_SOCKADDR_SA_LEN	/**/
?H:#$d_oldsock	USE_OLDSOCKET	/**/
?H:#$d_msg_ctrunc	HAS_MSG_CTRUNC	/**/
?H:#$d_msg_dontroute	HAS_MSG_DONTROUTE	/**/
?H:#$d_msg_oob	HAS_MSG_OOB	/**/
?H:#$d_msg_peek	HAS_MSG_PEEK	/**/
?H:#$d_msg_proxy	HAS_MSG_PROXY	/**/
?H:#$d_scm_rights	HAS_SCM_RIGHTS	/**/
?H:#$d_sockaddr_in6	HAS_SOCKADDR_IN6	/**/
?H:#$d_sockaddr_storage	HAS_SOCKADDR_STORAGE	/**/
?H:#$d_sin6_scope_id	HAS_SIN6_SCOPE_ID	/**/
?H:#$d_ip_mreq	HAS_IP_MREQ	/**/
?H:#$d_ip_mreq_source	HAS_IP_MREQ_SOURCE	/**/
?H:#$d_ipv6_mreq	HAS_IPV6_MREQ	/**/
?H:#$d_ipv6_mreq_source	HAS_IPV6_MREQ_SOURCE	/**/
?H:.
?T:val net ENUM enum
?LINT:set d_sockpair d_sockaddr_sa_len
?LINT:set d_msg_ctrunc d_msg_dontroute d_msg_oob d_msg_peek d_msg_proxy
?LINT:set d_scm_rights d_sockaddr_in6 d_sin6_scope_id d_ip_mreq
?LINT:set d_ip_mreq_source d_ipv6_mreq d_ipv6_mreq_source d_sockaddr_storage
: see whether socket exists
socketlib=''
sockethdr=''
echo " "
$echo $n "Hmm... $c" >&4
if set socket val -f d_socket; eval $csym; $val; then
    echo "Looks like you have Berkeley networking support." >&4
    d_socket="$define"
?X: now check for advanced features
    if set setsockopt val -f; eval $csym; $val; then
	d_oldsock="$undef"
    else
	echo "...but it uses the old BSD 4.1c interface, rather than 4.2." >&4
	d_oldsock="$define"
    fi
else
?X: HP-UX, for one, puts all the socket stuff in socklib.o. Note that if we
?X: come here on HP-UX, then we must have used nm to get symbols, or we really
?X: don't have sockets anyway...
    if $contains socklib libc.list >/dev/null 2>&1; then
	echo "Looks like you have Berkeley networking support." >&4
	d_socket="$define"
	: we will have to assume that it supports the 4.2 BSD interface
	d_oldsock="$undef"
    else
	echo "You don't have Berkeley networking in libc$_a..." >&4
?X: look for optional networking libraries
	if test "X$d_socket" = "X$define"; then
	    echo "...but you seem to believe that you have sockets." >&4
	else
	    for net in net socket
	    do
		if test -f $sysroot/usr/lib/lib$net$_a; then
?X: space between two  '(' needed for ksh
		    ( ($nm $nm_opt $sysroot/usr/lib/lib$net$_a | eval $nm_extract) ||  \
		    $ar t $sysroot/usr/lib/lib$net$_a) 2>/dev/null >> libc.list
		    if $contains socket libc.list >/dev/null 2>&1; then
			d_socket="$define"
			socketlib="-l$net"
			case "$net" in
			net)
			    echo "...but the Wollongong group seems to have hacked it in." >&4
			    sockethdr="-I$sysroot/usr/netinclude"
			    ;;
			esac
			echo "Found Berkeley sockets interface in lib$net." >&4
?X: now check for advanced features
			if $contains setsockopt libc.list >/dev/null 2>&1; then
			    d_oldsock="$undef"
			else
			    echo "...using the old BSD 4.1c interface, rather than 4.2." >&4
			    d_oldsock="$define"
			fi
			break
		    fi
		fi
	    done
	    if test "X$d_socket" != "X$define"; then
	       echo "or anywhere else I see." >&4
	       d_socket="$undef"
	       d_oldsock="$undef"
	    fi
	fi
    fi
fi

@if HAS_SOCKETPAIR || d_sockpair
: see if socketpair exists
set socketpair d_sockpair
eval $inlibc

@end

echo "Checking the availability sa_len in the sock struct ..." >&4
$cat >try.c <<EOF
#include <sys/types.h>
#include <sys/socket.h>
int main() {
struct sockaddr sa;
return (sa.sa_len);
}
EOF
val="$undef"
set try; if eval $compile; then
    val="$define"
fi
set d_sockaddr_sa_len; eval $setvar
$rm_try

echo "Checking the availability struct sockaddr_in6 ..." >&4
$cat >try.c <<EOF
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
int main() {
struct sockaddr_in6 sin6;
return (sin6.sin6_family);
}
EOF
val="$undef"
set try; if eval $compile; then
    val="$define"
fi
set d_sockaddr_in6; eval $setvar
$rm_try

echo "Checking the availability struct sockaddr_storage ..." >&4
$cat >try.c <<EOF
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
int main() {
struct sockaddr_storage sastor;
return (sastor.ss_family);
}
EOF
val="$undef"
set try; if eval $compile; then
    val="$define"
fi
set d_sockaddr_storage; eval $setvar
$rm_try

echo "Checking the availability sin6_scope_id in struct sockaddr_in6 ..." >&4
$cat >try.c <<EOF
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
int main() {
struct sockaddr_in6 sin6;
return (sin6.sin6_scope_id);
}
EOF
val="$undef"
set try; if eval $compile; then
    val="$define"
fi
set d_sin6_scope_id; eval $setvar
$rm_try

echo "Checking the availability struct ip_mreq ..." >&4
$cat >try.c <<EOF
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
int main() {
struct ip_mreq mreq;
return (mreq.imr_multiaddr.s_addr);
}
EOF
val="$undef"
set try; if eval $compile; then
       val="$define"
fi
set d_ip_mreq; eval $setvar
$rm_try

echo "Checking the availability struct ip_mreq_source ..." >&4
$cat >try.c <<EOF
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
int main() {
struct ip_mreq_source mreq;
return (mreq.imr_multiaddr.s_addr);
}
EOF
val="$undef"
set try; if eval $compile; then
       val="$define"
fi
set d_ip_mreq_source; eval $setvar
$rm_try

echo "Checking the availability struct ipv6_mreq ..." >&4
$cat >try.c <<EOF
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
int main() {
struct ipv6_mreq mreq;
return (mreq.ipv6mr_interface);
}
EOF
val="$undef"
set try; if eval $compile; then
    val="$define"
fi
set d_ipv6_mreq; eval $setvar
$rm_try

echo "Checking the availability struct ipv6_mreq_source ..." >&4
$cat >try.c <<EOF
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
int main() {
struct ipv6_mreq_source mreq;
return (mreq.imr_multiaddr.s_addr);
}
EOF
val="$undef"
set try; if eval $compile; then
       val="$define"
fi
set d_ipv6_mreq_source; eval $setvar
$rm_try

?X: these constants are known to be troublesomely defined as enums
?X: so that ifdef will not work for detecting their presence.
echo "Checking the availability of certain socket constants..." >&4
for ENUM in MSG_CTRUNC MSG_DONTROUTE MSG_OOB MSG_PEEK MSG_PROXY SCM_RIGHTS; do
    enum=`$echo $ENUM|./tr '[A-Z]' '[a-z]'`
    $cat >try.c <<EOF
#include <sys/types.h>
#include <sys/socket.h>
int main() {
    int i = $ENUM;
}
EOF
    val="$undef"
    set try; if eval $compile; then
	val="$define"
    fi
    set d_${enum}; eval $setvar
    $rm_try
done

