This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Populate metaconfig branch.
[metaconfig.git] / U / modified / d_socket.U
1 ?RCS: $Id: d_socket.U,v 3.0.1.2 1997/02/28 15:46:00 ram Exp $
2 ?RCS:
3 ?RCS: Copyright (c) 1991-1993, Raphael Manfredi
4 ?RCS: 
5 ?RCS: You may redistribute only under the terms of the Artistic Licence,
6 ?RCS: as specified in the README file that comes with the distribution.
7 ?RCS: You may reuse parts of this distribution only within the terms of
8 ?RCS: that same Artistic Licence; a copy of which may be found at the root
9 ?RCS: of the source tree for dist 3.0.
10 ?RCS:
11 ?RCS: $Log: d_socket.U,v $
12 ?RCS: Revision 3.0.1.2  1997/02/28  15:46:00  ram
13 ?RCS: patch61: replaced .a with $_a all over the place
14 ?RCS:
15 ?RCS: Revision 3.0.1.1  1994/01/24  14:08:04  ram
16 ?RCS: patch16: can now safely declare private nm_extract in dependencies
17 ?RCS:
18 ?RCS: Revision 3.0  1993/08/18  12:07:26  ram
19 ?RCS: Baseline for dist 3.0 netwide release.
20 ?RCS:
21 ?MAKE:d_socket d_oldsock d_sockpair socketlib sockethdr \
22         d_msg_ctrunc d_msg_dontroute d_msg_oob d_msg_peek d_msg_proxy \
23         d_scm_rights d_sendmsg d_recvmsg d_msghdr_s d_cmsghdr_s: \
24         contains libc echo n c ar nm nm_opt nm_extract Inlibc Csym _a \
25         Compile cat rm Setvar Hasfield i_sysuio
26 ?MAKE:  -pick add $@ %<
27 ?S:d_socket:
28 ?S:     This variable conditionally defines HAS_SOCKET, which indicates
29 ?S:     that the BSD socket interface is supported.
30 ?S:.
31 ?S:d_sockpair:
32 ?S:     This variable conditionally defines the HAS_SOCKETPAIR symbol, which
33 ?S:     indicates that the BSD socketpair() is supported.
34 ?S:.
35 ?S:d_oldsock:
36 ?S:     This variable conditionally defines the OLDSOCKET symbol, which
37 ?S:     indicates that the BSD socket interface is based on 4.1c and not 4.2.
38 ?S:.
39 ?S:d_msg_ctrunc:
40 ?S:     This variable conditionally defines the HAS_MSG_CTRUNC symbol,
41 ?S:     which indicates that the MSG_CTRUNC is available.  #ifdef is
42 ?S:     not enough because it may be an enum, glibc has been known to do this.
43 ?S:.
44 ?S:d_msg_dontroute:
45 ?S:     This variable conditionally defines the HAS_MSG_DONTROUTE symbol,
46 ?S:     which indicates that the MSG_DONTROUTE is available.  #ifdef is
47 ?S:     not enough because it may be an enum, glibc has been known to do this.
48 ?S:.
49 ?S:d_msg_oob:
50 ?S:     This variable conditionally defines the HAS_MSG_OOB symbol,
51 ?S:     which indicates that the MSG_OOB is available.  #ifdef is
52 ?S:     not enough because it may be an enum, glibc has been known to do this.
53 ?S:.
54 ?S:d_msg_peek:
55 ?S:     This variable conditionally defines the HAS_MSG_PEEK symbol,
56 ?S:     which indicates that the MSG_PEEK is available.  #ifdef is
57 ?S:     not enough because it may be an enum, glibc has been known to do this.
58 ?S:.
59 ?S:d_msg_proxy:
60 ?S:     This variable conditionally defines the HAS_MSG_PROXY symbol,
61 ?S:     which indicates that the MSG_PROXY is available.  #ifdef is
62 ?S:     not enough because it may be an enum, glibc has been known to do this.
63 ?S:.
64 ?S:d_scm_rights:
65 ?S:     This variable conditionally defines the HAS_SCM_RIGHTS symbol,
66 ?S:     which indicates that the SCM_RIGHTS is available.  #ifdef is
67 ?S:     not enough because it may be an enum, glibc has been known to do this.
68 ?S:.
69 ?S:d_sendmsg:
70 ?S:     This variable conditionally defines the HAS_SENDMSG symbol,
71 ?S:     which indicates that the sendmsg is supported.
72 ?S:.
73 ?S:d_recvmsg:
74 ?S:     This variable conditionally defines the HAS_RECVMSG symbol,
75 ?S:     which indicates that the recvmsg is supported.
76 ?S:.
77 ?S:d_msghdr_s:
78 ?S:     This variable conditionally defines the HAS_STRUCT_MSGHDR symbol,
79 ?S:     which indicates that the struct msghdr is supported.
80 ?S:.
81 ?S:d_cmsghdr_s:
82 ?S:     This variable conditionally defines the HAS_STRUCT_CMSGHDR symbol,
83 ?S:     which indicates that the the struct cmsghdr is supported.
84 ?S:.
85 ?S:socketlib:
86 ?S:     This variable has the names of any libraries needed for socket support.
87 ?S:.
88 ?S:sockethdr:
89 ?S:     This variable has any cpp '-I' flags needed for socket support.
90 ?S:.
91 ?C:HAS_SOCKET (SOCKET):
92 ?C:     This symbol, if defined, indicates that the BSD socket interface is
93 ?C:     supported.
94 ?C:.
95 ?C:HAS_SOCKETPAIR (SOCKETPAIR):
96 ?C:     This symbol, if defined, indicates that the BSD socketpair() call is
97 ?C:     supported.
98 ?C:.
99 ?C:USE_OLDSOCKET (OLDSOCKET):
100 ?C:     This symbol, if defined, indicates that the 4.1c BSD socket interface
101 ?C:     is supported instead of the 4.2/4.3 BSD socket interface. For instance,
102 ?C:     there is no setsockopt() call.
103 ?C:.
104 ?C:HAS_MSG_CTRUNC:
105 ?C:     This symbol, if defined, indicates that the MSG_CTRUNC is supported.
106 ?C:     Checking just with #ifdef might not be enough because this symbol
107 ?C:     has been known to be an enum.
108 ?C:.
109 ?C:HAS_MSG_DONTROUTE:
110 ?C:     This symbol, if defined, indicates that the MSG_DONTROUTE is supported.
111 ?C:     Checking just with #ifdef might not be enough because this symbol
112 ?C:     has been known to be an enum.
113 ?C:.
114 ?C:HAS_MSG_OOB:
115 ?C:     This symbol, if defined, indicates that the MSG_OOB is supported.
116 ?C:     Checking just with #ifdef might not be enough because this symbol
117 ?C:     has been known to be an enum.
118 ?C:.
119 ?C:HAS_MSG_PEEK:
120 ?C:     This symbol, if defined, indicates that the MSG_PEEK is supported.
121 ?C:     Checking just with #ifdef might not be enough because this symbol
122 ?C:     has been known to be an enum.
123 ?C:.
124 ?C:HAS_MSG_PROXY:
125 ?C:     This symbol, if defined, indicates that the MSG_PROXY is supported.
126 ?C:     Checking just with #ifdef might not be enough because this symbol
127 ?C:     has been known to be an enum.
128 ?C:.
129 ?C:HAS_SCM_RIGHTS:
130 ?C:     This symbol, if defined, indicates that the SCM_RIGHTS is supported.
131 ?C:     Checking just with #ifdef might not be enough because this symbol
132 ?C:     has been known to be an enum.
133 ?C:.
134 ?C:HAS_SENDMSG:
135 ?C:     This symbol, if defined, indicates that the sendmsg is supported
136 ?C:     to send messages between sockets.  You will also need struct
137 ?C:     iovec from <sys/uio.h>, HAS_STRUCT_IOVEC and I_SYSUIO.
138 ?C:.
139 ?C:HAS_RECVMSG:
140 ?C:     This symbol, if defined, indicates that the recvmsg is supported
141 ?C:     to send messages between sockets.  You will also need struct
142 ?C:     iovec from <sys/uio.h>, HAS_STRUCT_IOVEC and I_SYSUIO.
143 ?C:.
144 ?C:HAS_STRUCT_MSGHDR:
145 ?C:     This symbol, if defined, indicates that the struct msghdr
146 ?C:     (BSD 4.3 or 4.4) is supported.  You will also need struct
147 ?C:     iovec from <sys/uio.h>, HAS_STRUCT_IOVEC and I_SYSUIO.
148 ?C:.
149 ?C:HAS_STRUCT_CMSGHDR:
150 ?C:     This symbol, if defined, indicates that the struct cmsghdr
151 ?C:     (BSD 4.4) is supported.  You will also need struct
152 ?C:     iovec from <sys/uio.h>, HAS_STRUCT_IOVEC and I_SYSUIO.
153 ?C:.
154 ?H:#$d_socket   HAS_SOCKET              /**/
155 ?H:#$d_sockpair HAS_SOCKETPAIR  /**/
156 ?H:#$d_oldsock  USE_OLDSOCKET   /**/
157 ?H:#$d_msg_ctrunc       HAS_MSG_CTRUNC  /**/
158 ?H:#$d_msg_dontroute    HAS_MSG_DONTROUTE       /**/
159 ?H:#$d_msg_oob  HAS_MSG_OOB     /**/
160 ?H:#$d_msg_peek HAS_MSG_PEEK    /**/
161 ?H:#$d_msg_proxy        HAS_MSG_PROXY   /**/
162 ?H:#$d_scm_rights       HAS_SCM_RIGHTS  /**/
163 ?H:#$d_sendmsg  HAS_SENDMSG     /**/
164 ?H:#$d_recvmsg  HAS_RECVMSG     /**/
165 ?H:#$d_msghdr_s HAS_STRUCT_MSGHDR       /**/
166 ?H:#$d_cmsghdr_s        HAS_STRUCT_CMSGHDR      /**/
167 ?H:.
168 ?T:val net ENUM enum
169 ?F:try.c
170 ?LINT:set d_sockpair
171 ?LINT:set d_msg_ctrunc d_msg_dontroute d_msg_oob d_msg_peek d_msg_proxy
172 ?LINT:set d_scm_rights d_sendmsg d_recvmsg d_msghdr_s d_cmsghdr_s
173 socketlib=''
174 sockethdr=''
175 : see whether socket exists
176 echo " "
177 $echo $n "Hmm... $c" >&4
178 if set socket val -f d_socket; eval $csym; $val; then
179         echo "Looks like you have Berkeley networking support." >&4
180         d_socket="$define"
181 ?X: now check for advanced features
182         if set setsockopt val -f; eval $csym; $val; then
183                 d_oldsock="$undef"
184         else
185                 echo "...but it uses the old BSD 4.1c interface, rather than 4.2." >&4
186                 d_oldsock="$define"
187         fi
188 else
189 ?X: HP-UX, for one, puts all the socket stuff in socklib.o. Note that if we
190 ?X: come here on HP-UX, then we must have used nm to get symbols, or we really
191 ?X: don't have sockets anyway...
192         if $contains socklib libc.list >/dev/null 2>&1; then
193                 echo "Looks like you have Berkeley networking support." >&4
194                 d_socket="$define"
195                 : we will have to assume that it supports the 4.2 BSD interface
196                 d_oldsock="$undef"
197         else
198                 echo "You don't have Berkeley networking in libc$_a..." >&4
199 ?X: look for optional networking libraries
200                 if test "X$d_socket" = "X$define"; then
201                    echo "...but you seem to believe that you have sockets." >&4
202                 else
203                         for net in net socket
204                         do
205                                 if test -f /usr/lib/lib$net$_a; then
206 ?X: space between two  '(' needed for ksh
207                                         ( ($nm $nm_opt /usr/lib/lib$net$_a | eval $nm_extract) ||  \
208                                         $ar t /usr/lib/lib$net$_a) 2>/dev/null >> libc.list
209                                         if $contains socket libc.list >/dev/null 2>&1; then
210                                                 d_socket="$define"
211                                                 socketlib="-l$net"
212                                                 case "$net" in
213                                                 net)
214                                                         echo "...but the Wollongong group seems to have hacked it in." >&4
215                                                         sockethdr="-I/usr/netinclude"
216                                                         ;;
217                                                 esac
218                                                 echo "Found Berkeley sockets interface in lib$net." >& 4 
219 ?X: now check for advanced features
220                                                 if $contains setsockopt libc.list >/dev/null 2>&1; then
221                                                         d_oldsock="$undef"
222                                                 else
223                                                         echo "...using the old BSD 4.1c interface, rather than 4.2." >&4
224                                                         d_oldsock="$define"
225                                                 fi
226                                                 break
227                                         fi
228                                 fi
229                         done
230                         if test "X$d_socket" != "X$define"; then
231                            echo "or anywhere else I see." >&4
232                            d_socket="$undef"
233                            d_oldsock="$undef"
234                         fi
235                 fi
236         fi
237 fi
238
239 @if HAS_SOCKETPAIR || d_sockpair
240 : see if socketpair exists
241 set socketpair d_sockpair
242 eval $inlibc
243
244 @end
245
246 echo " "
247 ?X: these constants are known to be troublesomely defined as enums
248 ?X: so that ifdef will not work for detecting their presence.
249 echo "Checking the availability of certain socket constants..." >& 4
250 for ENUM in MSG_CTRUNC MSG_DONTROUTE MSG_OOB MSG_PEEK MSG_PROXY SCM_RIGHTS; do
251         enum=`$echo $ENUM|./tr '[A-Z]' '[a-z]'`
252         $cat >try.c <<EOF
253 #include <sys/types.h>
254 #include <sys/socket.h>
255 int main() {
256     int i = $ENUM;
257 }
258 EOF
259         val="$undef"
260         set try; if eval $compile; then
261                 val="$define"
262         fi
263         set d_${enum}; eval $setvar
264         $rm -f try.c try
265 done
266
267 set sendmsg d_sendmsg
268 eval $inlibc
269
270 set recvmsg d_recvmsg
271 eval $inlibc
272
273 echo " "
274 $echo $n "Checking to see if your system supports struct msghdr...$c" >&4
275 set d_msghdr_s msghdr msg_name define sys/types.h $d_socket sys/socket.h $i_sysuio sys/uio.h
276 eval $hasfield
277 case "$d_msghdr_s" in
278 "$define")      echo "Yup, it does." >&4
279                 ;;
280 *)              echo "Nope, it doesn't." >&4
281                 ;;
282 esac
283
284 $echo $n "Checking to see if your system supports struct cmsghdr...$c" >&4
285 set d_cmsghdr_s cmsghdr cmsg_len define sys/types.h $d_socket sys/socket.h $i_sysuio sys/uio.h
286 eval $hasfield
287 case "$d_cmsghdr_s" in
288 "$define")      echo "Yup, it does." >&4
289                 ;;
290 *)              echo "Nope, it doesn't." >&4
291                 ;;
292 esac
293