author | Claus Gittinger <cg@exept.de> |
Tue, 02 Jun 1998 20:28:20 +0200 | |
changeset 650 | 8c5616f17ed6 |
parent 649 | 1bc56594db85 |
child 653 | 219b89f62113 |
permissions | -rw-r--r-- |
0 | 1 |
" |
4 | 2 |
COPYRIGHT (c) 1992 by Claus Gittinger |
42 | 3 |
All Rights Reserved |
0 | 4 |
|
5 |
This software is furnished under a license and may be used |
|
6 |
only in accordance with the terms of that license and with the |
|
7 |
inclusion of the above copyright notice. This software may not |
|
8 |
be provided or otherwise made available to, or used by, any |
|
9 |
other person. No title to or ownership of the software is |
|
10 |
hereby transferred. |
|
11 |
" |
|
12 |
||
63 | 13 |
NonPositionableExternalStream subclass:#Socket |
206
77166a6b3ee6
For ST80 style socket creation: register socket in Lobby.
Stefan Vogel <sv@exept.de>
parents:
203
diff
changeset
|
14 |
instanceVariableNames:'domain socketType protocol port serviceName peerName' |
77166a6b3ee6
For ST80 style socket creation: register socket in Lobby.
Stefan Vogel <sv@exept.de>
parents:
203
diff
changeset
|
15 |
classVariableNames:'' |
77166a6b3ee6
For ST80 style socket creation: register socket in Lobby.
Stefan Vogel <sv@exept.de>
parents:
203
diff
changeset
|
16 |
poolDictionaries:'' |
77166a6b3ee6
For ST80 style socket creation: register socket in Lobby.
Stefan Vogel <sv@exept.de>
parents:
203
diff
changeset
|
17 |
category:'Streams-External' |
0 | 18 |
! |
19 |
||
126 | 20 |
!Socket primitiveDefinitions! |
21 |
%{ |
|
444 | 22 |
|
23 |
#ifdef LINUX |
|
24 |
# define BUGGY_STDIO_LIB |
|
25 |
#endif |
|
126 | 26 |
|
420 | 27 |
#ifdef WIN32 |
28 |
# undef INT |
|
421 | 29 |
# undef Array |
30 |
# undef Number |
|
31 |
# undef Method |
|
32 |
# undef Point |
|
506
11ef93d12870
support anonymous (OS_specified) ports. (for FTP-protocol)
Claus Gittinger <cg@exept.de>
parents:
486
diff
changeset
|
33 |
# undef Rectangle |
11ef93d12870
support anonymous (OS_specified) ports. (for FTP-protocol)
Claus Gittinger <cg@exept.de>
parents:
486
diff
changeset
|
34 |
# undef Block |
11ef93d12870
support anonymous (OS_specified) ports. (for FTP-protocol)
Claus Gittinger <cg@exept.de>
parents:
486
diff
changeset
|
35 |
# undef Context |
11ef93d12870
support anonymous (OS_specified) ports. (for FTP-protocol)
Claus Gittinger <cg@exept.de>
parents:
486
diff
changeset
|
36 |
# undef String |
11ef93d12870
support anonymous (OS_specified) ports. (for FTP-protocol)
Claus Gittinger <cg@exept.de>
parents:
486
diff
changeset
|
37 |
# undef Message |
463 | 38 |
# undef Object |
420 | 39 |
#endif |
40 |
||
563 | 41 |
#ifdef __openVMS__ |
42 |
# undef __new |
|
43 |
#endif |
|
44 |
||
126 | 45 |
#include <stdio.h> |
46 |
#include <errno.h> |
|
47 |
||
533
ced9950b551f
added query about which protocols are supported
Claus Gittinger <cg@exept.de>
parents:
532
diff
changeset
|
48 |
#define UNIX_LIKE |
ced9950b551f
added query about which protocols are supported
Claus Gittinger <cg@exept.de>
parents:
532
diff
changeset
|
49 |
|
ced9950b551f
added query about which protocols are supported
Claus Gittinger <cg@exept.de>
parents:
532
diff
changeset
|
50 |
#if defined(MSWINDOWS) || defined(OS2) || defined(MSDOS) || defined(WIN32) |
ced9950b551f
added query about which protocols are supported
Claus Gittinger <cg@exept.de>
parents:
532
diff
changeset
|
51 |
# ifndef MSDOS_LIKE |
ced9950b551f
added query about which protocols are supported
Claus Gittinger <cg@exept.de>
parents:
532
diff
changeset
|
52 |
# define MSDOS_LIKE |
ced9950b551f
added query about which protocols are supported
Claus Gittinger <cg@exept.de>
parents:
532
diff
changeset
|
53 |
# endif |
ced9950b551f
added query about which protocols are supported
Claus Gittinger <cg@exept.de>
parents:
532
diff
changeset
|
54 |
# undef UNIX_LIKE |
ced9950b551f
added query about which protocols are supported
Claus Gittinger <cg@exept.de>
parents:
532
diff
changeset
|
55 |
#endif |
ced9950b551f
added query about which protocols are supported
Claus Gittinger <cg@exept.de>
parents:
532
diff
changeset
|
56 |
|
ced9950b551f
added query about which protocols are supported
Claus Gittinger <cg@exept.de>
parents:
532
diff
changeset
|
57 |
#if defined(MSDOS) |
ced9950b551f
added query about which protocols are supported
Claus Gittinger <cg@exept.de>
parents:
532
diff
changeset
|
58 |
# define NO_SOCKET |
ced9950b551f
added query about which protocols are supported
Claus Gittinger <cg@exept.de>
parents:
532
diff
changeset
|
59 |
#endif |
ced9950b551f
added query about which protocols are supported
Claus Gittinger <cg@exept.de>
parents:
532
diff
changeset
|
60 |
|
ced9950b551f
added query about which protocols are supported
Claus Gittinger <cg@exept.de>
parents:
532
diff
changeset
|
61 |
#if defined(transputer) |
ced9950b551f
added query about which protocols are supported
Claus Gittinger <cg@exept.de>
parents:
532
diff
changeset
|
62 |
# undef UNIX_LIKE |
418 | 63 |
# define NO_SOCKET |
64 |
#endif |
|
65 |
||
525 | 66 |
/* |
67 |
* which protocols can we support ? |
|
68 |
*/ |
|
69 |
#ifndef NO_SOCKET |
|
70 |
# define WANT__AF_INET |
|
71 |
#endif |
|
72 |
||
73 |
#ifdef UNIX_LIKE |
|
74 |
# define WANT__AF_UNIX |
|
75 |
#endif |
|
76 |
||
563 | 77 |
#ifdef __VMS__ |
78 |
# undef WANT__AF_UNIX |
|
571 | 79 |
# define WANT_AF_DECnet |
563 | 80 |
#endif |
81 |
||
527 | 82 |
#ifdef LINUX |
83 |
# define WANT__AF_APPLETALK |
|
530
067797c15b77
added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents:
529
diff
changeset
|
84 |
# define WANT__AF_INET6 |
527 | 85 |
#endif |
525 | 86 |
|
126 | 87 |
#ifdef LINUX |
220 | 88 |
/* use inline string macros ... */ |
89 |
# define __STRINGDEFS__ |
|
90 |
# include <linuxIntern.h> |
|
91 |
||
126 | 92 |
/* kludge to avoid some redefines ... */ |
93 |
# define _ARPA_NAMESER_H |
|
94 |
# define _NETINET_TCP_H |
|
95 |
#endif |
|
96 |
||
465 | 97 |
#ifdef WIN32 |
418 | 98 |
# include <WINSOCK.H> |
524
8287da54eccf
more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents:
513
diff
changeset
|
99 |
# undef NO_SOCKET |
527 | 100 |
# define WANT__AF_INET |
421 | 101 |
|
102 |
# ifdef __DEF_Array |
|
103 |
# define Array __DEF_Array |
|
104 |
# endif |
|
105 |
# ifdef __DEF_Number |
|
106 |
# define Number __DEF_Number |
|
107 |
# endif |
|
108 |
# ifdef __DEF_Method |
|
109 |
# define Method __DEF_Method |
|
110 |
# endif |
|
111 |
# ifdef __DEF_Point |
|
112 |
# define Point __DEF_Point |
|
465 | 113 |
# endif |
114 |
# ifdef __DEF_Block |
|
115 |
# define Block __DEF_Block |
|
116 |
# endif |
|
117 |
# ifdef __DEF_Context |
|
118 |
# define Context __DEF_Context |
|
506
11ef93d12870
support anonymous (OS_specified) ports. (for FTP-protocol)
Claus Gittinger <cg@exept.de>
parents:
486
diff
changeset
|
119 |
# endif |
465 | 120 |
# ifdef __DEF_String |
121 |
# define String __DEF_String |
|
506
11ef93d12870
support anonymous (OS_specified) ports. (for FTP-protocol)
Claus Gittinger <cg@exept.de>
parents:
486
diff
changeset
|
122 |
# endif |
465 | 123 |
# ifdef __DEF_Message |
124 |
# define Message __DEF_Message |
|
506
11ef93d12870
support anonymous (OS_specified) ports. (for FTP-protocol)
Claus Gittinger <cg@exept.de>
parents:
486
diff
changeset
|
125 |
# endif |
465 | 126 |
# ifdef __DEF_Object |
127 |
# define Object __DEF_Object |
|
506
11ef93d12870
support anonymous (OS_specified) ports. (for FTP-protocol)
Claus Gittinger <cg@exept.de>
parents:
486
diff
changeset
|
128 |
# endif |
572 | 129 |
# define INT int |
421 | 130 |
|
418 | 131 |
#else |
132 |
||
133 |
# if !defined(NO_SOCKET) |
|
134 |
# include <fcntl.h> |
|
135 |
# include <sys/types.h> |
|
126 | 136 |
|
418 | 137 |
# if defined(IRIS) && !defined(IRIX5) |
138 |
/* no socket.h on 4.0.5h ?!?!? */ |
|
525 | 139 |
# ifndef AF_UNIX |
140 |
# define AF_UNIX 1 |
|
141 |
# endif |
|
142 |
# ifndef AF_INET |
|
143 |
# define AF_INET 2 |
|
144 |
# endif |
|
145 |
# ifndef SOCK_STREAM |
|
146 |
# define SOCK_STREAM 1 |
|
147 |
# endif |
|
148 |
# ifndef SOCK_DGRAM |
|
149 |
# define SOCK_DGRAM 2 |
|
150 |
# endif |
|
151 |
# ifndef SOCK_RAW |
|
152 |
# define SOCK_RAW 3 |
|
153 |
# endif |
|
418 | 154 |
# else |
155 |
# include <sys/socket.h> |
|
156 |
# endif |
|
126 | 157 |
|
418 | 158 |
# ifdef NEXT3 |
159 |
# include <netinet/in_systm.h> |
|
160 |
# endif |
|
126 | 161 |
# endif |
162 |
#endif |
|
163 |
||
525 | 164 |
|
126 | 165 |
/* |
528 | 166 |
* see what we want ... |
126 | 167 |
*/ |
525 | 168 |
#ifdef WANT__AF_UNIX |
169 |
# ifdef AF_UNIX |
|
170 |
# ifndef PF_UNIX |
|
171 |
# define PF_UNIX AF_UNIX |
|
172 |
# endif |
|
126 | 173 |
# endif |
525 | 174 |
#else |
175 |
# undef AF_UNIX |
|
176 |
#endif |
|
177 |
||
178 |
#ifdef WANT__AF_INET |
|
179 |
# ifdef AF_INET |
|
180 |
# ifndef PF_INET |
|
181 |
# define PF_INET AF_INET |
|
182 |
# endif |
|
183 |
# endif |
|
184 |
#else |
|
185 |
# undef AF_INET |
|
126 | 186 |
#endif |
525 | 187 |
|
530
067797c15b77
added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents:
529
diff
changeset
|
188 |
#ifdef WANT__AF_INET6 |
067797c15b77
added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents:
529
diff
changeset
|
189 |
# ifdef AF_INET6 |
067797c15b77
added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents:
529
diff
changeset
|
190 |
# ifndef PF_INET6 |
067797c15b77
added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents:
529
diff
changeset
|
191 |
# define PF_INET6 AF_INET6 |
067797c15b77
added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents:
529
diff
changeset
|
192 |
# endif |
067797c15b77
added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents:
529
diff
changeset
|
193 |
# endif |
067797c15b77
added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents:
529
diff
changeset
|
194 |
#else |
067797c15b77
added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents:
529
diff
changeset
|
195 |
# undef AF_INET6 |
067797c15b77
added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents:
529
diff
changeset
|
196 |
#endif |
067797c15b77
added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents:
529
diff
changeset
|
197 |
|
525 | 198 |
#ifdef WANT__AF_DECnet |
199 |
# ifdef AF_DECnet |
|
200 |
# ifndef PF_DECnet |
|
201 |
# define PF_DECnet AF_DECnet |
|
202 |
# endif |
|
203 |
# endif |
|
204 |
#else |
|
205 |
# undef AF_DECnet |
|
206 |
#endif |
|
207 |
||
208 |
#ifdef WANT__AF_APPLETALK |
|
209 |
# ifdef AF_APPLETALK |
|
210 |
# ifndef PF_APPLETALK |
|
211 |
# define PF_APPLETALK AF_APPLETALK |
|
212 |
# endif |
|
126 | 213 |
# endif |
525 | 214 |
#else |
215 |
# undef AF_APPLETALK |
|
126 | 216 |
#endif |
525 | 217 |
|
533
ced9950b551f
added query about which protocols are supported
Claus Gittinger <cg@exept.de>
parents:
532
diff
changeset
|
218 |
#ifdef WANT__AF_X25 /* X.25 */ |
525 | 219 |
# ifdef AF_X25 |
220 |
# ifndef PF_X25 |
|
221 |
# define PF_X25 AF_X25 |
|
222 |
# endif |
|
223 |
# endif |
|
224 |
#else |
|
225 |
# undef AF_X25 |
|
226 |
#endif |
|
227 |
||
533
ced9950b551f
added query about which protocols are supported
Claus Gittinger <cg@exept.de>
parents:
532
diff
changeset
|
228 |
#ifdef WANT__AF_NS /* Xerox XNS */ |
525 | 229 |
# ifdef AF_NS |
230 |
# ifndef PF_NS |
|
231 |
# define PF_NS AF_NS |
|
232 |
# endif |
|
126 | 233 |
# endif |
525 | 234 |
#else |
235 |
# undef AF_NS |
|
126 | 236 |
#endif |
525 | 237 |
|
533
ced9950b551f
added query about which protocols are supported
Claus Gittinger <cg@exept.de>
parents:
532
diff
changeset
|
238 |
#ifdef WANT__AF_SNA /* IBM SNA */ |
525 | 239 |
# ifdef AF_SNA |
240 |
# ifndef PF_SNA |
|
241 |
# define PF_SNA AF_SNA |
|
242 |
# endif |
|
126 | 243 |
# endif |
525 | 244 |
#else |
245 |
# undef AF_SNA |
|
246 |
#endif |
|
247 |
||
533
ced9950b551f
added query about which protocols are supported
Claus Gittinger <cg@exept.de>
parents:
532
diff
changeset
|
248 |
#ifdef WANT__AF_RAW /* RAW packets */ |
525 | 249 |
# ifdef AF_RAW |
250 |
# ifndef PF_RAW |
|
251 |
# define PF_RAW AF_RAW |
|
252 |
# endif |
|
253 |
# endif |
|
254 |
#else |
|
255 |
# undef AF_RAW |
|
126 | 256 |
#endif |
525 | 257 |
|
533
ced9950b551f
added query about which protocols are supported
Claus Gittinger <cg@exept.de>
parents:
532
diff
changeset
|
258 |
#ifdef WANT__AF_ISO /* ? */ |
525 | 259 |
# ifdef AF_ISO |
260 |
# ifndef PF_ISO |
|
261 |
# define PF_ISO AF_ISO |
|
262 |
# endif |
|
263 |
# endif |
|
264 |
#else |
|
265 |
# undef AF_ISO |
|
266 |
#endif |
|
267 |
||
530
067797c15b77
added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents:
529
diff
changeset
|
268 |
#ifdef WANT__AF_NETBIOS /* ? */ |
525 | 269 |
# ifdef AF_NETBIOS |
270 |
# ifndef PF_NETBIOS |
|
271 |
# define PF_NETBIOS AF_NETBIOS |
|
272 |
# endif |
|
126 | 273 |
# endif |
525 | 274 |
#else |
533
ced9950b551f
added query about which protocols are supported
Claus Gittinger <cg@exept.de>
parents:
532
diff
changeset
|
275 |
# undef AF_NETBIOS |
126 | 276 |
#endif |
525 | 277 |
|
530
067797c15b77
added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents:
529
diff
changeset
|
278 |
#ifdef WANT__AF_CCITT /* ? */ |
525 | 279 |
# if defined(AF_CCITT) && (AF_CCITT != AF_X25) |
280 |
# ifndef PF_CCITT |
|
281 |
# define PF_CCITT AF_CCITT |
|
282 |
# endif |
|
283 |
# endif |
|
284 |
#else |
|
285 |
# undef AF_CCITT |
|
286 |
#endif |
|
287 |
||
530
067797c15b77
added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents:
529
diff
changeset
|
288 |
#ifdef WANT__AF_IPX /* Novell IPX */ |
067797c15b77
added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents:
529
diff
changeset
|
289 |
# ifdef AF_IPX |
067797c15b77
added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents:
529
diff
changeset
|
290 |
# ifndef PF_IPX |
067797c15b77
added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents:
529
diff
changeset
|
291 |
# define PF_IPX AF_IPX |
067797c15b77
added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents:
529
diff
changeset
|
292 |
# endif |
067797c15b77
added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents:
529
diff
changeset
|
293 |
# endif |
067797c15b77
added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents:
529
diff
changeset
|
294 |
#else |
533
ced9950b551f
added query about which protocols are supported
Claus Gittinger <cg@exept.de>
parents:
532
diff
changeset
|
295 |
# undef AF_IPX |
530
067797c15b77
added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents:
529
diff
changeset
|
296 |
#endif |
067797c15b77
added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents:
529
diff
changeset
|
297 |
|
067797c15b77
added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents:
529
diff
changeset
|
298 |
#ifdef WANT__AF_AX25 /* Amateur radio ax25 */ |
067797c15b77
added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents:
529
diff
changeset
|
299 |
# ifdef AF_AX25 |
067797c15b77
added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents:
529
diff
changeset
|
300 |
# ifndef PF_AX25 |
067797c15b77
added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents:
529
diff
changeset
|
301 |
# define PF_AX25 AF_AX25 |
067797c15b77
added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents:
529
diff
changeset
|
302 |
# endif |
067797c15b77
added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents:
529
diff
changeset
|
303 |
# endif |
067797c15b77
added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents:
529
diff
changeset
|
304 |
#else |
533
ced9950b551f
added query about which protocols are supported
Claus Gittinger <cg@exept.de>
parents:
532
diff
changeset
|
305 |
# undef AF_AX25 |
530
067797c15b77
added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents:
529
diff
changeset
|
306 |
#endif |
067797c15b77
added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents:
529
diff
changeset
|
307 |
|
067797c15b77
added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents:
529
diff
changeset
|
308 |
#ifdef WANT__AF_NETROM /* Amateur radio NETROM */ |
067797c15b77
added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents:
529
diff
changeset
|
309 |
# ifdef AF_NETROM |
067797c15b77
added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents:
529
diff
changeset
|
310 |
# ifndef PF_NETROM |
067797c15b77
added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents:
529
diff
changeset
|
311 |
# define PF_NETROM AF_NETROM |
067797c15b77
added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents:
529
diff
changeset
|
312 |
# endif |
067797c15b77
added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents:
529
diff
changeset
|
313 |
# endif |
067797c15b77
added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents:
529
diff
changeset
|
314 |
#else |
533
ced9950b551f
added query about which protocols are supported
Claus Gittinger <cg@exept.de>
parents:
532
diff
changeset
|
315 |
# undef AF_NETROM |
530
067797c15b77
added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents:
529
diff
changeset
|
316 |
#endif |
067797c15b77
added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents:
529
diff
changeset
|
317 |
|
067797c15b77
added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents:
529
diff
changeset
|
318 |
#ifdef WANT__AF_BRIDGE /* multiprotocol bridge */ |
067797c15b77
added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents:
529
diff
changeset
|
319 |
# ifdef AF_BRIDGE |
067797c15b77
added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents:
529
diff
changeset
|
320 |
# ifndef PF_BRIDGE |
067797c15b77
added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents:
529
diff
changeset
|
321 |
# define PF_BRIDGE AF_BRIDGE |
067797c15b77
added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents:
529
diff
changeset
|
322 |
# endif |
067797c15b77
added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents:
529
diff
changeset
|
323 |
# endif |
067797c15b77
added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents:
529
diff
changeset
|
324 |
#else |
533
ced9950b551f
added query about which protocols are supported
Claus Gittinger <cg@exept.de>
parents:
532
diff
changeset
|
325 |
# undef AF_BRIDGE |
530
067797c15b77
added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents:
529
diff
changeset
|
326 |
#endif |
067797c15b77
added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents:
529
diff
changeset
|
327 |
|
571 | 328 |
#ifdef WANT__AF_BSC /* BISYNC 2780/3780 */ |
329 |
# ifdef AF_BSC |
|
330 |
# ifndef PF_BSC |
|
331 |
# define PF_BSC AF_BSC |
|
332 |
# endif |
|
333 |
# endif |
|
334 |
#else |
|
335 |
# undef AF_BSC |
|
336 |
#endif |
|
337 |
||
338 |
||
528 | 339 |
/* |
340 |
* now, include what we have to ... |
|
341 |
*/ |
|
530
067797c15b77
added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents:
529
diff
changeset
|
342 |
#ifndef WIN32 /* win32 has all in winsock.h */ |
067797c15b77
added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents:
529
diff
changeset
|
343 |
|
528 | 344 |
# ifdef AF_INET |
345 |
# include <netdb.h> |
|
346 |
# include <netinet/in.h> |
|
347 |
# if ! (defined(SYSV3) && defined(mc88k)) |
|
348 |
# include <netinet/tcp.h> |
|
349 |
# endif |
|
126 | 350 |
# endif |
528 | 351 |
|
352 |
# ifdef AF_UNIX |
|
353 |
# include <sys/un.h> |
|
465 | 354 |
# endif |
528 | 355 |
|
356 |
# ifdef AF_APPLETALK |
|
357 |
# ifdef LINUX |
|
358 |
# include <linux/atalk.h> |
|
359 |
# endif |
|
360 |
# endif |
|
530
067797c15b77
added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents:
529
diff
changeset
|
361 |
|
648
58e11a70ddaf
gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents:
617
diff
changeset
|
362 |
# if defined(TRY_AGAIN) || defined(HOST_NOT_FOUND) |
58e11a70ddaf
gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents:
617
diff
changeset
|
363 |
# define USE_H_ERRNO |
58e11a70ddaf
gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents:
617
diff
changeset
|
364 |
# endif |
58e11a70ddaf
gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents:
617
diff
changeset
|
365 |
|
528 | 366 |
#endif /* WIN32 */ |
126 | 367 |
|
368 |
/* |
|
369 |
* on some systems errno is a macro ... check for it here |
|
370 |
*/ |
|
371 |
#ifndef errno |
|
372 |
extern errno; |
|
373 |
#endif |
|
374 |
||
648
58e11a70ddaf
gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents:
617
diff
changeset
|
375 |
#ifdef USE_H_ERRNO |
58e11a70ddaf
gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents:
617
diff
changeset
|
376 |
# ifndef h_errno |
58e11a70ddaf
gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents:
617
diff
changeset
|
377 |
extern h_errno; |
58e11a70ddaf
gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents:
617
diff
changeset
|
378 |
# endif |
58e11a70ddaf
gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents:
617
diff
changeset
|
379 |
#endif |
58e11a70ddaf
gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents:
617
diff
changeset
|
380 |
|
58e11a70ddaf
gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents:
617
diff
changeset
|
381 |
/* |
58e11a70ddaf
gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents:
617
diff
changeset
|
382 |
* gethostbyname seems to have trouble |
58e11a70ddaf
gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents:
617
diff
changeset
|
383 |
* sometimes, if interrupted while a request |
58e11a70ddaf
gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents:
617
diff
changeset
|
384 |
* is on its way the name server. |
58e11a70ddaf
gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents:
617
diff
changeset
|
385 |
* (although specified in the man-page, |
58e11a70ddaf
gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents:
617
diff
changeset
|
386 |
* a check on TRY_AGAIN fails on iris) |
58e11a70ddaf
gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents:
617
diff
changeset
|
387 |
*/ |
58e11a70ddaf
gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents:
617
diff
changeset
|
388 |
#ifdef IRIX5_3 |
58e11a70ddaf
gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents:
617
diff
changeset
|
389 |
# define GETHOSTBYNAME(hp, name) \ |
58e11a70ddaf
gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents:
617
diff
changeset
|
390 |
do { \ |
58e11a70ddaf
gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents:
617
diff
changeset
|
391 |
__BEGIN_INTERRUPTABLE__ \ |
58e11a70ddaf
gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents:
617
diff
changeset
|
392 |
hp = gethostbyname((char *) name); \ |
58e11a70ddaf
gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents:
617
diff
changeset
|
393 |
__END_INTERRUPTABLE__ \ |
58e11a70ddaf
gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents:
617
diff
changeset
|
394 |
} while ((hp == NULL) && \ |
58e11a70ddaf
gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents:
617
diff
changeset
|
395 |
((h_errno == TRY_AGAIN) || (errno == ECONNREFUSED))); |
650
8c5616f17ed6
made gethostbyaddr interruptable
Claus Gittinger <cg@exept.de>
parents:
649
diff
changeset
|
396 |
|
8c5616f17ed6
made gethostbyaddr interruptable
Claus Gittinger <cg@exept.de>
parents:
649
diff
changeset
|
397 |
# define GETHOSTBYADDR(hp, addr, alen, af) \ |
8c5616f17ed6
made gethostbyaddr interruptable
Claus Gittinger <cg@exept.de>
parents:
649
diff
changeset
|
398 |
do { \ |
8c5616f17ed6
made gethostbyaddr interruptable
Claus Gittinger <cg@exept.de>
parents:
649
diff
changeset
|
399 |
__BEGIN_INTERRUPTABLE__ \ |
8c5616f17ed6
made gethostbyaddr interruptable
Claus Gittinger <cg@exept.de>
parents:
649
diff
changeset
|
400 |
hp = gethostbyaddr(addr, alen, af); \ |
8c5616f17ed6
made gethostbyaddr interruptable
Claus Gittinger <cg@exept.de>
parents:
649
diff
changeset
|
401 |
__END_INTERRUPTABLE__ \ |
8c5616f17ed6
made gethostbyaddr interruptable
Claus Gittinger <cg@exept.de>
parents:
649
diff
changeset
|
402 |
} while ((hp == NULL) && \ |
8c5616f17ed6
made gethostbyaddr interruptable
Claus Gittinger <cg@exept.de>
parents:
649
diff
changeset
|
403 |
((h_errno == TRY_AGAIN) || (errno == ECONNREFUSED))); |
648
58e11a70ddaf
gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents:
617
diff
changeset
|
404 |
#else |
58e11a70ddaf
gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents:
617
diff
changeset
|
405 |
# ifdef USE_H_ERRNO |
58e11a70ddaf
gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents:
617
diff
changeset
|
406 |
# define GETHOSTBYNAME(hp, name) \ |
58e11a70ddaf
gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents:
617
diff
changeset
|
407 |
do { \ |
58e11a70ddaf
gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents:
617
diff
changeset
|
408 |
__BEGIN_INTERRUPTABLE__ \ |
58e11a70ddaf
gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents:
617
diff
changeset
|
409 |
hp = gethostbyname((char *) name); \ |
58e11a70ddaf
gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents:
617
diff
changeset
|
410 |
__END_INTERRUPTABLE__ \ |
58e11a70ddaf
gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents:
617
diff
changeset
|
411 |
} while ((hp == NULL) && (h_errno == TRY_AGAIN)); |
650
8c5616f17ed6
made gethostbyaddr interruptable
Claus Gittinger <cg@exept.de>
parents:
649
diff
changeset
|
412 |
|
8c5616f17ed6
made gethostbyaddr interruptable
Claus Gittinger <cg@exept.de>
parents:
649
diff
changeset
|
413 |
# define GETHOSTBYADDR(hp, addr, alen, af) \ |
8c5616f17ed6
made gethostbyaddr interruptable
Claus Gittinger <cg@exept.de>
parents:
649
diff
changeset
|
414 |
do { \ |
8c5616f17ed6
made gethostbyaddr interruptable
Claus Gittinger <cg@exept.de>
parents:
649
diff
changeset
|
415 |
__BEGIN_INTERRUPTABLE__ \ |
8c5616f17ed6
made gethostbyaddr interruptable
Claus Gittinger <cg@exept.de>
parents:
649
diff
changeset
|
416 |
hp = gethostbyaddr(addr, alen, af); \ |
8c5616f17ed6
made gethostbyaddr interruptable
Claus Gittinger <cg@exept.de>
parents:
649
diff
changeset
|
417 |
__END_INTERRUPTABLE__ \ |
8c5616f17ed6
made gethostbyaddr interruptable
Claus Gittinger <cg@exept.de>
parents:
649
diff
changeset
|
418 |
} while ((hp == NULL) && (h_errno == TRY_AGAIN)); |
648
58e11a70ddaf
gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents:
617
diff
changeset
|
419 |
# else |
58e11a70ddaf
gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents:
617
diff
changeset
|
420 |
# define GETHOSTBYNAME(hp, name) \ |
58e11a70ddaf
gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents:
617
diff
changeset
|
421 |
__BEGIN_INTERRUPTABLE__ \ |
58e11a70ddaf
gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents:
617
diff
changeset
|
422 |
hp = gethostbyname((char *) name); \ |
58e11a70ddaf
gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents:
617
diff
changeset
|
423 |
__END_INTERRUPTABLE__ |
650
8c5616f17ed6
made gethostbyaddr interruptable
Claus Gittinger <cg@exept.de>
parents:
649
diff
changeset
|
424 |
|
8c5616f17ed6
made gethostbyaddr interruptable
Claus Gittinger <cg@exept.de>
parents:
649
diff
changeset
|
425 |
# define GETHOSTBYADDR(hp, addr, alen, af) \ |
8c5616f17ed6
made gethostbyaddr interruptable
Claus Gittinger <cg@exept.de>
parents:
649
diff
changeset
|
426 |
__BEGIN_INTERRUPTABLE__ \ |
8c5616f17ed6
made gethostbyaddr interruptable
Claus Gittinger <cg@exept.de>
parents:
649
diff
changeset
|
427 |
hp = gethostbyaddr(addr, alen, af); \ |
8c5616f17ed6
made gethostbyaddr interruptable
Claus Gittinger <cg@exept.de>
parents:
649
diff
changeset
|
428 |
__END_INTERRUPTABLE__ |
648
58e11a70ddaf
gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents:
617
diff
changeset
|
429 |
# endif |
58e11a70ddaf
gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents:
617
diff
changeset
|
430 |
#endif |
58e11a70ddaf
gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents:
617
diff
changeset
|
431 |
|
126 | 432 |
#ifdef DEBUG |
433 |
# define DBGPRINTF(x) { if (__debugging__) printf x; } |
|
434 |
#else |
|
435 |
# define DBGPRINTF(x) /* as nothing */ |
|
436 |
#endif |
|
437 |
||
438 |
%} |
|
439 |
! ! |
|
440 |
||
511 | 441 |
!Socket primitiveVariables! |
442 |
%{ |
|
443 |
static int __debugging__ = 0; |
|
444 |
%} |
|
445 |
! ! |
|
446 |
||
464 | 447 |
!Socket class methodsFor:'documentation'! |
25 | 448 |
|
31 | 449 |
copyright |
450 |
" |
|
451 |
COPYRIGHT (c) 1992 by Claus Gittinger |
|
42 | 452 |
All Rights Reserved |
31 | 453 |
|
454 |
This software is furnished under a license and may be used |
|
455 |
only in accordance with the terms of that license and with the |
|
456 |
inclusion of the above copyright notice. This software may not |
|
457 |
be provided or otherwise made available to, or used by, any |
|
458 |
other person. No title to or ownership of the software is |
|
459 |
hereby transferred. |
|
460 |
" |
|
461 |
! |
|
462 |
||
25 | 463 |
documentation |
464 |
" |
|
524
8287da54eccf
more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents:
513
diff
changeset
|
465 |
This class provides access to sockets for interprocess communication. |
25 | 466 |
The message protocol is preliminary, until someone tells me how |
31 | 467 |
other smalltalk's socket interfaces look like. |
25 | 468 |
|
525 | 469 |
Currently, only IP and UNIX domain sockets are supported. |
470 |
Code for appletalk is included, but was never tested ... |
|
471 |
More may be added in the future. |
|
472 |
(the code is prepared for things like SNA or decNet; |
|
473 |
however, right now, this code is empty and needs a little work. |
|
474 |
Implementing those is pretty straight forward, once the address |
|
475 |
data structures are known.) |
|
524
8287da54eccf
more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents:
513
diff
changeset
|
476 |
|
28 | 477 |
Due to historic reasons (I started this class, before I got hold of some |
478 |
code using ST-80 Sockets i.e. RemoteInvocation), there is some old interface |
|
71 | 479 |
still provided. |
524
8287da54eccf
more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents:
513
diff
changeset
|
480 |
This will vanish; use the #family:type: or #newTCPxxx and #newUDPxxx interfaces, |
71 | 481 |
together with the bind/listen and accept calls, |
482 |
which are meant to be compatible to ST-80's UnixSocketAccessor interface. |
|
483 |
||
524
8287da54eccf
more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents:
513
diff
changeset
|
484 |
ST/X does not use IPSocketAddress, UDSocketAddress etc; all addressing |
71 | 485 |
is done by passing appropriate string- or byteArray objects containing |
486 |
the addresses. This may change, too. |
|
487 |
||
488 |
TODO: cleanup historic leftovers, implement other than inet domain stuff. |
|
524
8287da54eccf
more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents:
513
diff
changeset
|
489 |
(mhmh - how can I test those ?) |
532 | 490 |
change to raise more signals on errors. |
529 | 491 |
Help - could someone who has a linux machine connected to an appletalk |
533
ced9950b551f
added query about which protocols are supported
Claus Gittinger <cg@exept.de>
parents:
532
diff
changeset
|
492 |
net please test this (and send bug fixes ...) |
259 | 493 |
|
494 |
[author:] |
|
425 | 495 |
Claus Gittinger |
48 | 496 |
" |
497 |
! |
|
28 | 498 |
|
48 | 499 |
examples |
500 |
" |
|
28 | 501 |
example (get help info from an nntp server): |
648
58e11a70ddaf
gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents:
617
diff
changeset
|
502 |
[exBegin] |
58e11a70ddaf
gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents:
617
diff
changeset
|
503 |
|sock host| |
58e11a70ddaf
gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents:
617
diff
changeset
|
504 |
|
58e11a70ddaf
gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents:
617
diff
changeset
|
505 |
host := OperatingSystem getEnvironment:'NNTPSERVER'. |
58e11a70ddaf
gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents:
617
diff
changeset
|
506 |
|
58e11a70ddaf
gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents:
617
diff
changeset
|
507 |
sock := Socket newTCPclientToHost:host port:'nntp'. |
58e11a70ddaf
gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents:
617
diff
changeset
|
508 |
Transcript showCR:sock nextLine. |
58e11a70ddaf
gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents:
617
diff
changeset
|
509 |
sock buffered:false. |
58e11a70ddaf
gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents:
617
diff
changeset
|
510 |
|
58e11a70ddaf
gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents:
617
diff
changeset
|
511 |
sock nextPutAll:'HELP'; cr. |
58e11a70ddaf
gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents:
617
diff
changeset
|
512 |
[:exit | |
58e11a70ddaf
gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents:
617
diff
changeset
|
513 |
|line| |
58e11a70ddaf
gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents:
617
diff
changeset
|
514 |
|
58e11a70ddaf
gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents:
617
diff
changeset
|
515 |
line := sock nextLine. |
58e11a70ddaf
gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents:
617
diff
changeset
|
516 |
line = '.' ifTrue:[exit value:nil]. |
58e11a70ddaf
gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents:
617
diff
changeset
|
517 |
Transcript showCR:line. |
58e11a70ddaf
gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents:
617
diff
changeset
|
518 |
] loopWithExit. |
58e11a70ddaf
gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents:
617
diff
changeset
|
519 |
sock close |
58e11a70ddaf
gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents:
617
diff
changeset
|
520 |
[exEnd] |
209 | 521 |
|
28 | 522 |
|
209 | 523 |
example (connect to finger daemon, get users entry): |
648
58e11a70ddaf
gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents:
617
diff
changeset
|
524 |
[exBegin] |
58e11a70ddaf
gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents:
617
diff
changeset
|
525 |
|sock host entry| |
58e11a70ddaf
gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents:
617
diff
changeset
|
526 |
|
58e11a70ddaf
gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents:
617
diff
changeset
|
527 |
host := OperatingSystem getHostName. |
58e11a70ddaf
gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents:
617
diff
changeset
|
528 |
|
58e11a70ddaf
gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents:
617
diff
changeset
|
529 |
sock := Socket newTCPclientToHost:host port:'finger'. |
58e11a70ddaf
gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents:
617
diff
changeset
|
530 |
sock isNil ifTrue:[ |
58e11a70ddaf
gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents:
617
diff
changeset
|
531 |
self warn:'no finger daemon is running'. |
58e11a70ddaf
gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents:
617
diff
changeset
|
532 |
^ self |
58e11a70ddaf
gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents:
617
diff
changeset
|
533 |
]. |
58e11a70ddaf
gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents:
617
diff
changeset
|
534 |
sock useCRLF:true. |
58e11a70ddaf
gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents:
617
diff
changeset
|
535 |
sock buffered:false. |
58e11a70ddaf
gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents:
617
diff
changeset
|
536 |
sock isNil ifTrue:[ |
58e11a70ddaf
gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents:
617
diff
changeset
|
537 |
Transcript showCR:'cannot connect to local finger daemon' |
58e11a70ddaf
gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents:
617
diff
changeset
|
538 |
] ifFalse:[ |
58e11a70ddaf
gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents:
617
diff
changeset
|
539 |
sock nextPutAll:(OperatingSystem getLoginName). |
58e11a70ddaf
gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents:
617
diff
changeset
|
540 |
sock cr. |
58e11a70ddaf
gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents:
617
diff
changeset
|
541 |
|
58e11a70ddaf
gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents:
617
diff
changeset
|
542 |
entry := sock nextLine. |
58e11a70ddaf
gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents:
617
diff
changeset
|
543 |
Transcript showCR:entry. |
58e11a70ddaf
gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents:
617
diff
changeset
|
544 |
|
58e11a70ddaf
gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents:
617
diff
changeset
|
545 |
sock close |
58e11a70ddaf
gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents:
617
diff
changeset
|
546 |
] |
58e11a70ddaf
gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents:
617
diff
changeset
|
547 |
[exEnd] |
99
7d016cc30052
fixed & moved pingWalk from SNMPSession to here;
Claus Gittinger <cg@exept.de>
parents:
98
diff
changeset
|
548 |
|
28 | 549 |
example (connect to an ftp server): |
648
58e11a70ddaf
gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents:
617
diff
changeset
|
550 |
[exBegin] |
58e11a70ddaf
gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents:
617
diff
changeset
|
551 |
|sock host| |
58e11a70ddaf
gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents:
617
diff
changeset
|
552 |
|
58e11a70ddaf
gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents:
617
diff
changeset
|
553 |
host := OperatingSystem getHostName. |
58e11a70ddaf
gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents:
617
diff
changeset
|
554 |
sock := Socket newTCPclientToHost:host port:'ftp'. |
58e11a70ddaf
gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents:
617
diff
changeset
|
555 |
|
58e11a70ddaf
gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents:
617
diff
changeset
|
556 |
sock buffered:false. |
58e11a70ddaf
gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents:
617
diff
changeset
|
557 |
Transcript showCR:sock nextLine. |
58e11a70ddaf
gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents:
617
diff
changeset
|
558 |
sock nextPutAll:('USER ' , 'anonymous'); cr. |
58e11a70ddaf
gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents:
617
diff
changeset
|
559 |
Transcript showCR:sock nextLine. |
58e11a70ddaf
gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents:
617
diff
changeset
|
560 |
sock nextPutAll:('PASS ' , 'fooBar'); cr. |
58e11a70ddaf
gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents:
617
diff
changeset
|
561 |
Transcript showCR:sock nextLine. |
58e11a70ddaf
gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents:
617
diff
changeset
|
562 |
sock nextPutAll:'LIST'; cr. |
58e11a70ddaf
gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents:
617
diff
changeset
|
563 |
Transcript showCR:sock nextLine. |
58e11a70ddaf
gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents:
617
diff
changeset
|
564 |
sock close. |
58e11a70ddaf
gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents:
617
diff
changeset
|
565 |
|
58e11a70ddaf
gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents:
617
diff
changeset
|
566 |
'dont know enough of the ftp protocol to continue here ...' |
58e11a70ddaf
gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents:
617
diff
changeset
|
567 |
[exEnd] |
28 | 568 |
|
99
7d016cc30052
fixed & moved pingWalk from SNMPSession to here;
Claus Gittinger <cg@exept.de>
parents:
98
diff
changeset
|
569 |
|
93 | 570 |
example (connect to an snmp server [UDP]): |
648
58e11a70ddaf
gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents:
617
diff
changeset
|
571 |
[exBegin] |
58e11a70ddaf
gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents:
617
diff
changeset
|
572 |
|sock port| |
58e11a70ddaf
gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents:
617
diff
changeset
|
573 |
|
58e11a70ddaf
gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents:
617
diff
changeset
|
574 |
sock := Socket newUDP. |
58e11a70ddaf
gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents:
617
diff
changeset
|
575 |
port := Socket portOfService:'snmp'. |
58e11a70ddaf
gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents:
617
diff
changeset
|
576 |
sock connectTo:(OperatingSystem getHostName) port:port. |
58e11a70ddaf
gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents:
617
diff
changeset
|
577 |
sock buffered:false. |
58e11a70ddaf
gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents:
617
diff
changeset
|
578 |
Transcript showCR:'got it'. |
58e11a70ddaf
gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents:
617
diff
changeset
|
579 |
sock close. |
58e11a70ddaf
gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents:
617
diff
changeset
|
580 |
[exEnd] |
42 | 581 |
|
99
7d016cc30052
fixed & moved pingWalk from SNMPSession to here;
Claus Gittinger <cg@exept.de>
parents:
98
diff
changeset
|
582 |
|
42 | 583 |
example (await connection from a client and read some data): |
648
58e11a70ddaf
gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents:
617
diff
changeset
|
584 |
|connectSock sock| |
58e11a70ddaf
gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents:
617
diff
changeset
|
585 |
|
58e11a70ddaf
gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents:
617
diff
changeset
|
586 |
connectSock := Socket newTCPserverAtPort:9998. |
58e11a70ddaf
gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents:
617
diff
changeset
|
587 |
connectSock isNil ifTrue:[ |
58e11a70ddaf
gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents:
617
diff
changeset
|
588 |
Transcript showCR:'socket setup failed.'. |
58e11a70ddaf
gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents:
617
diff
changeset
|
589 |
] ifFalse:[ |
58e11a70ddaf
gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents:
617
diff
changeset
|
590 |
Transcript showCR:'listen ..'. |
58e11a70ddaf
gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents:
617
diff
changeset
|
591 |
(connectSock listenFor:5) ifFalse:[ |
58e11a70ddaf
gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents:
617
diff
changeset
|
592 |
Transcript showCR:'listen failed.'. |
58e11a70ddaf
gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents:
617
diff
changeset
|
593 |
] ifTrue:[ |
58e11a70ddaf
gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents:
617
diff
changeset
|
594 |
Transcript showCR:'wait'. |
58e11a70ddaf
gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents:
617
diff
changeset
|
595 |
connectSock readWait. |
58e11a70ddaf
gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents:
617
diff
changeset
|
596 |
Transcript showCR:'accept'. |
58e11a70ddaf
gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents:
617
diff
changeset
|
597 |
sock := connectSock accept. |
58e11a70ddaf
gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents:
617
diff
changeset
|
598 |
sock isNil ifTrue:[ |
58e11a70ddaf
gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents:
617
diff
changeset
|
599 |
Transcript showCR:'accept failed.'. |
58e11a70ddaf
gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents:
617
diff
changeset
|
600 |
] ifFalse:[ |
58e11a70ddaf
gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents:
617
diff
changeset
|
601 |
sock buffered:false. |
58e11a70ddaf
gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents:
617
diff
changeset
|
602 |
Transcript showCR:'server: got it'. |
58e11a70ddaf
gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents:
617
diff
changeset
|
603 |
'can now do transfer via sock'. |
58e11a70ddaf
gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents:
617
diff
changeset
|
604 |
Transcript showCR:'read'. |
58e11a70ddaf
gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents:
617
diff
changeset
|
605 |
Transcript showCR:('got: ' , sock nextLine). |
58e11a70ddaf
gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents:
617
diff
changeset
|
606 |
|
58e11a70ddaf
gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents:
617
diff
changeset
|
607 |
Transcript showCR:'close'. |
58e11a70ddaf
gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents:
617
diff
changeset
|
608 |
sock close |
58e11a70ddaf
gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents:
617
diff
changeset
|
609 |
]. |
58e11a70ddaf
gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents:
617
diff
changeset
|
610 |
connectSock close. |
58e11a70ddaf
gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents:
617
diff
changeset
|
611 |
] |
58e11a70ddaf
gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents:
617
diff
changeset
|
612 |
] |
42 | 613 |
|
99
7d016cc30052
fixed & moved pingWalk from SNMPSession to here;
Claus Gittinger <cg@exept.de>
parents:
98
diff
changeset
|
614 |
|
42 | 615 |
example (connect to above server and send some data): |
648
58e11a70ddaf
gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents:
617
diff
changeset
|
616 |
|sock| |
58e11a70ddaf
gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents:
617
diff
changeset
|
617 |
|
58e11a70ddaf
gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents:
617
diff
changeset
|
618 |
sock := Socket newTCPclientToHost:(OperatingSystem getHostName) port:9998. |
58e11a70ddaf
gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents:
617
diff
changeset
|
619 |
sock isNil ifTrue:[ |
58e11a70ddaf
gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents:
617
diff
changeset
|
620 |
Transcript showCR:'nope' |
58e11a70ddaf
gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents:
617
diff
changeset
|
621 |
] ifFalse:[ |
58e11a70ddaf
gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents:
617
diff
changeset
|
622 |
sock buffered:false. |
58e11a70ddaf
gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents:
617
diff
changeset
|
623 |
Transcript showCR:'client: got it'. |
58e11a70ddaf
gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents:
617
diff
changeset
|
624 |
'can now do transfer via sock'. |
58e11a70ddaf
gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents:
617
diff
changeset
|
625 |
Transcript showCR:'sending <hello>'. |
58e11a70ddaf
gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents:
617
diff
changeset
|
626 |
sock nextPutLine:'hello'. |
58e11a70ddaf
gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents:
617
diff
changeset
|
627 |
sock close |
58e11a70ddaf
gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents:
617
diff
changeset
|
628 |
] |
117
03cefad7e40b
UD socket example & interruptable bind
Claus Gittinger <cg@exept.de>
parents:
116
diff
changeset
|
629 |
|
03cefad7e40b
UD socket example & interruptable bind
Claus Gittinger <cg@exept.de>
parents:
116
diff
changeset
|
630 |
example: UNIX domain socket (await connection from a client and read some data): |
03cefad7e40b
UD socket example & interruptable bind
Claus Gittinger <cg@exept.de>
parents:
116
diff
changeset
|
631 |
|
648
58e11a70ddaf
gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents:
617
diff
changeset
|
632 |
|connectSock sock| |
58e11a70ddaf
gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents:
617
diff
changeset
|
633 |
|
58e11a70ddaf
gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents:
617
diff
changeset
|
634 |
'/tmp/ud_socket' asFilename remove. |
58e11a70ddaf
gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents:
617
diff
changeset
|
635 |
connectSock := Socket newUNIXserverAt:'/tmp/ud_socket'. |
58e11a70ddaf
gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents:
617
diff
changeset
|
636 |
connectSock isNil ifTrue:[ |
58e11a70ddaf
gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents:
617
diff
changeset
|
637 |
Transcript showCR:'socket setup failed.'. |
58e11a70ddaf
gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents:
617
diff
changeset
|
638 |
] ifFalse:[ |
58e11a70ddaf
gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents:
617
diff
changeset
|
639 |
Transcript showCR:'listen ..'. |
58e11a70ddaf
gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents:
617
diff
changeset
|
640 |
(connectSock listenFor:5) ifFalse:[ |
58e11a70ddaf
gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents:
617
diff
changeset
|
641 |
Transcript showCR:'listen failed.'. |
58e11a70ddaf
gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents:
617
diff
changeset
|
642 |
] ifTrue:[ |
58e11a70ddaf
gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents:
617
diff
changeset
|
643 |
Transcript showCR:'wait'. |
58e11a70ddaf
gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents:
617
diff
changeset
|
644 |
connectSock buffered:false. |
58e11a70ddaf
gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents:
617
diff
changeset
|
645 |
connectSock readWait. |
58e11a70ddaf
gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents:
617
diff
changeset
|
646 |
Transcript showCR:'accept'. |
58e11a70ddaf
gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents:
617
diff
changeset
|
647 |
sock := connectSock accept. |
58e11a70ddaf
gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents:
617
diff
changeset
|
648 |
sock isNil ifTrue:[ |
58e11a70ddaf
gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents:
617
diff
changeset
|
649 |
Transcript showCR:'accept failed.'. |
58e11a70ddaf
gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents:
617
diff
changeset
|
650 |
] ifFalse:[ |
58e11a70ddaf
gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents:
617
diff
changeset
|
651 |
sock buffered:false. |
58e11a70ddaf
gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents:
617
diff
changeset
|
652 |
Transcript showCR:'server: got it'. |
58e11a70ddaf
gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents:
617
diff
changeset
|
653 |
'can now do transfer via sock'. |
58e11a70ddaf
gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents:
617
diff
changeset
|
654 |
Transcript showCR:'read'. |
58e11a70ddaf
gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents:
617
diff
changeset
|
655 |
Transcript showCR:('got: ' , sock nextLine). |
58e11a70ddaf
gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents:
617
diff
changeset
|
656 |
|
58e11a70ddaf
gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents:
617
diff
changeset
|
657 |
Transcript showCR:'close'. |
58e11a70ddaf
gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents:
617
diff
changeset
|
658 |
sock close |
58e11a70ddaf
gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents:
617
diff
changeset
|
659 |
]. |
58e11a70ddaf
gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents:
617
diff
changeset
|
660 |
connectSock close. |
58e11a70ddaf
gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents:
617
diff
changeset
|
661 |
] |
58e11a70ddaf
gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents:
617
diff
changeset
|
662 |
] |
117
03cefad7e40b
UD socket example & interruptable bind
Claus Gittinger <cg@exept.de>
parents:
116
diff
changeset
|
663 |
|
03cefad7e40b
UD socket example & interruptable bind
Claus Gittinger <cg@exept.de>
parents:
116
diff
changeset
|
664 |
|
118 | 665 |
example (connect to above server and send some data; |
648
58e11a70ddaf
gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents:
617
diff
changeset
|
666 |
Notice, this fails, if above server code is executed in the same ST/X image |
58e11a70ddaf
gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents:
617
diff
changeset
|
667 |
(at least on LINUX), since the OS does not correctly handle |
58e11a70ddaf
gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents:
617
diff
changeset
|
668 |
a connect from within an interrupted accept system call |
58e11a70ddaf
gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents:
617
diff
changeset
|
669 |
On SGI's SVR4, this works ok |
58e11a70ddaf
gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents:
617
diff
changeset
|
670 |
|
58e11a70ddaf
gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents:
617
diff
changeset
|
671 |
|sock| |
58e11a70ddaf
gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents:
617
diff
changeset
|
672 |
|
58e11a70ddaf
gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents:
617
diff
changeset
|
673 |
sock := Socket newUNIXclientTo:'/tmp/ud_socket'. |
58e11a70ddaf
gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents:
617
diff
changeset
|
674 |
sock isNil ifTrue:[ |
58e11a70ddaf
gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents:
617
diff
changeset
|
675 |
Transcript showCR:'nope' |
58e11a70ddaf
gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents:
617
diff
changeset
|
676 |
] ifFalse:[ |
58e11a70ddaf
gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents:
617
diff
changeset
|
677 |
sock buffered:false. |
58e11a70ddaf
gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents:
617
diff
changeset
|
678 |
Transcript showCR:'client: got it'. |
58e11a70ddaf
gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents:
617
diff
changeset
|
679 |
'can now do transfer via sock'. |
58e11a70ddaf
gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents:
617
diff
changeset
|
680 |
Transcript showCR:'sending <hello>'. |
58e11a70ddaf
gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents:
617
diff
changeset
|
681 |
sock nextPutLine:'hello'. |
58e11a70ddaf
gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents:
617
diff
changeset
|
682 |
sock close |
58e11a70ddaf
gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents:
617
diff
changeset
|
683 |
] |
99
7d016cc30052
fixed & moved pingWalk from SNMPSession to here;
Claus Gittinger <cg@exept.de>
parents:
98
diff
changeset
|
684 |
|
7d016cc30052
fixed & moved pingWalk from SNMPSession to here;
Claus Gittinger <cg@exept.de>
parents:
98
diff
changeset
|
685 |
|
7d016cc30052
fixed & moved pingWalk from SNMPSession to here;
Claus Gittinger <cg@exept.de>
parents:
98
diff
changeset
|
686 |
example: pingWalk (try to ping hosts on the local network) |
648
58e11a70ddaf
gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents:
617
diff
changeset
|
687 |
[exBegin] |
58e11a70ddaf
gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents:
617
diff
changeset
|
688 |
|myName myAddress list top hosts walkProcess port| |
58e11a70ddaf
gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents:
617
diff
changeset
|
689 |
|
58e11a70ddaf
gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents:
617
diff
changeset
|
690 |
myName := OperatingSystem getHostName. |
58e11a70ddaf
gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents:
617
diff
changeset
|
691 |
myAddress := Socket ipAddressOfHost:myName. |
58e11a70ddaf
gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents:
617
diff
changeset
|
692 |
|
58e11a70ddaf
gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents:
617
diff
changeset
|
693 |
port := Socket portOfService:'echo'. |
58e11a70ddaf
gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents:
617
diff
changeset
|
694 |
port isNil ifTrue:[ |
58e11a70ddaf
gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents:
617
diff
changeset
|
695 |
self error:'dont know echo port'. |
58e11a70ddaf
gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents:
617
diff
changeset
|
696 |
^ self |
58e11a70ddaf
gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents:
617
diff
changeset
|
697 |
]. |
58e11a70ddaf
gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents:
617
diff
changeset
|
698 |
|
58e11a70ddaf
gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents:
617
diff
changeset
|
699 |
top := StandardSystemView new. |
58e11a70ddaf
gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents:
617
diff
changeset
|
700 |
top label:'PING net walk'. |
58e11a70ddaf
gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents:
617
diff
changeset
|
701 |
|
58e11a70ddaf
gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents:
617
diff
changeset
|
702 |
list := ScrollableView for:ListView in:top. |
58e11a70ddaf
gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents:
617
diff
changeset
|
703 |
list origin:0.0@0.0 corner:1.0@1.0. |
58e11a70ddaf
gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents:
617
diff
changeset
|
704 |
|
58e11a70ddaf
gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents:
617
diff
changeset
|
705 |
top openAndWait. |
58e11a70ddaf
gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents:
617
diff
changeset
|
706 |
|
58e11a70ddaf
gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents:
617
diff
changeset
|
707 |
walkProcess := [ |
58e11a70ddaf
gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents:
617
diff
changeset
|
708 |
|l low hi direction tryHostID dottedName hostName conn addr| |
58e11a70ddaf
gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents:
617
diff
changeset
|
709 |
|
58e11a70ddaf
gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents:
617
diff
changeset
|
710 |
l := SortedCollection new. |
58e11a70ddaf
gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents:
617
diff
changeset
|
711 |
|
58e11a70ddaf
gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents:
617
diff
changeset
|
712 |
' only works with type C-net |
58e11a70ddaf
gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents:
617
diff
changeset
|
713 |
the code below could simply do 1 to:254 do:[:hostID } |
58e11a70ddaf
gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents:
617
diff
changeset
|
714 |
but, to probe likely hosts earlier, the probing is done |
58e11a70ddaf
gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents:
617
diff
changeset
|
715 |
ping-pong like around my ip-address (assuming, that other machines |
58e11a70ddaf
gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents:
617
diff
changeset
|
716 |
have numbers around my own)'. |
58e11a70ddaf
gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents:
617
diff
changeset
|
717 |
|
58e11a70ddaf
gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents:
617
diff
changeset
|
718 |
low := hi := (myAddress at:4). |
58e11a70ddaf
gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents:
617
diff
changeset
|
719 |
direction := 1. |
58e11a70ddaf
gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents:
617
diff
changeset
|
720 |
|
58e11a70ddaf
gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents:
617
diff
changeset
|
721 |
[low > 0 or:[hi < 255]] whileTrue:[ |
58e11a70ddaf
gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents:
617
diff
changeset
|
722 |
direction > 0 ifTrue:[ |
58e11a70ddaf
gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents:
617
diff
changeset
|
723 |
hi := hi + 1. |
58e11a70ddaf
gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents:
617
diff
changeset
|
724 |
tryHostID := hi. |
58e11a70ddaf
gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents:
617
diff
changeset
|
725 |
direction := -1. |
58e11a70ddaf
gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents:
617
diff
changeset
|
726 |
] ifFalse:[ |
58e11a70ddaf
gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents:
617
diff
changeset
|
727 |
low := low - 1. |
58e11a70ddaf
gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents:
617
diff
changeset
|
728 |
tryHostID := low. |
58e11a70ddaf
gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents:
617
diff
changeset
|
729 |
direction := 1. |
58e11a70ddaf
gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents:
617
diff
changeset
|
730 |
]. |
58e11a70ddaf
gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents:
617
diff
changeset
|
731 |
(tryHostID between:1 and:254) ifTrue:[ |
58e11a70ddaf
gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents:
617
diff
changeset
|
732 |
dottedName := (myAddress at:1) printString |
58e11a70ddaf
gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents:
617
diff
changeset
|
733 |
, '.' , (myAddress at:2) printString |
58e11a70ddaf
gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents:
617
diff
changeset
|
734 |
, '.' , (myAddress at:3) printString |
58e11a70ddaf
gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents:
617
diff
changeset
|
735 |
, '.' , tryHostID printString. |
58e11a70ddaf
gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents:
617
diff
changeset
|
736 |
|
58e11a70ddaf
gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents:
617
diff
changeset
|
737 |
top label:'PING net walk - trying ' , dottedName. |
58e11a70ddaf
gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents:
617
diff
changeset
|
738 |
|
58e11a70ddaf
gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents:
617
diff
changeset
|
739 |
top windowGroup withCursor:Cursor wait do:[ |
58e11a70ddaf
gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents:
617
diff
changeset
|
740 |
conn := Socket newTCPclientToHost:dottedName port:port withTimeout:1000. |
58e11a70ddaf
gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents:
617
diff
changeset
|
741 |
conn notNil ifTrue:[ |
58e11a70ddaf
gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents:
617
diff
changeset
|
742 |
addr := Socket ipAddressOfHost:dottedName. |
58e11a70ddaf
gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents:
617
diff
changeset
|
743 |
hostName := Socket hostWithIpAddress:addr. |
58e11a70ddaf
gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents:
617
diff
changeset
|
744 |
hostName isNil ifTrue:[ |
58e11a70ddaf
gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents:
617
diff
changeset
|
745 |
hostName :='?' |
58e11a70ddaf
gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents:
617
diff
changeset
|
746 |
]. |
58e11a70ddaf
gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents:
617
diff
changeset
|
747 |
l add:(dottedName paddedTo:15 with:Character space) |
58e11a70ddaf
gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents:
617
diff
changeset
|
748 |
, ' ' |
58e11a70ddaf
gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents:
617
diff
changeset
|
749 |
, (hostName paddedTo:15 with:Character space) |
58e11a70ddaf
gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents:
617
diff
changeset
|
750 |
, ' up & reachable'. |
58e11a70ddaf
gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents:
617
diff
changeset
|
751 |
list list:l. |
58e11a70ddaf
gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents:
617
diff
changeset
|
752 |
conn close. |
58e11a70ddaf
gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents:
617
diff
changeset
|
753 |
] |
58e11a70ddaf
gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents:
617
diff
changeset
|
754 |
]. |
58e11a70ddaf
gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents:
617
diff
changeset
|
755 |
]. |
58e11a70ddaf
gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents:
617
diff
changeset
|
756 |
]. |
58e11a70ddaf
gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents:
617
diff
changeset
|
757 |
top label:'PING reachable hosts'. |
58e11a70ddaf
gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents:
617
diff
changeset
|
758 |
] forkAt:(Processor userBackgroundPriority). |
58e11a70ddaf
gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents:
617
diff
changeset
|
759 |
walkProcess name:'ping net walker'. |
58e11a70ddaf
gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents:
617
diff
changeset
|
760 |
[exEnd] |
25 | 761 |
" |
762 |
! ! |
|
763 |
||
464 | 764 |
!Socket class methodsFor:'ST80 instance creation'! |
91 | 765 |
|
126 | 766 |
family:domainSymbol type:typeSymbol |
767 |
"create a socket for domain and type - ST80 simply uses a different name. |
|
768 |
Domain must be one of the symbols: #inet, #unix, #ns, #appletalk or #ns; |
|
769 |
Type must be #stream, #datagram or #raw |
|
91 | 770 |
|
126 | 771 |
XXX: currently only the #inet domain is supported" |
91 | 772 |
|
126 | 773 |
^ self domain:domainSymbol type:typeSymbol |
51 | 774 |
|
126 | 775 |
" |
776 |
Socket family:#inet type:#stream |
|
777 |
Socket family:#inet type:#datagram |
|
778 |
Socket family:#unix type:#stream |
|
779 |
" |
|
780 |
! ! |
|
93 | 781 |
|
464 | 782 |
!Socket class methodsFor:'ST80 queries'! |
115 | 783 |
|
617
6ccbaa111a74
added #getHostname (ST80 compatibility)
Claus Gittinger <cg@exept.de>
parents:
604
diff
changeset
|
784 |
getHostname |
6ccbaa111a74
added #getHostname (ST80 compatibility)
Claus Gittinger <cg@exept.de>
parents:
604
diff
changeset
|
785 |
"return the computers hostname string" |
6ccbaa111a74
added #getHostname (ST80 compatibility)
Claus Gittinger <cg@exept.de>
parents:
604
diff
changeset
|
786 |
|
6ccbaa111a74
added #getHostname (ST80 compatibility)
Claus Gittinger <cg@exept.de>
parents:
604
diff
changeset
|
787 |
^ OperatingSystem getHostName |
6ccbaa111a74
added #getHostname (ST80 compatibility)
Claus Gittinger <cg@exept.de>
parents:
604
diff
changeset
|
788 |
|
6ccbaa111a74
added #getHostname (ST80 compatibility)
Claus Gittinger <cg@exept.de>
parents:
604
diff
changeset
|
789 |
"Created: / 27.2.1998 / 02:32:17 / cg" |
6ccbaa111a74
added #getHostname (ST80 compatibility)
Claus Gittinger <cg@exept.de>
parents:
604
diff
changeset
|
790 |
! |
6ccbaa111a74
added #getHostname (ST80 compatibility)
Claus Gittinger <cg@exept.de>
parents:
604
diff
changeset
|
791 |
|
126 | 792 |
sockStream |
793 |
"return the type code for stream sockets" |
|
51 | 794 |
|
126 | 795 |
^ #stream |
44 | 796 |
! ! |
797 |
||
464 | 798 |
!Socket class methodsFor:'Signal constants'! |
21 | 799 |
|
800 |
brokenConnectionSignal |
|
801 |
"return the signal used to tell broken connections. |
|
802 |
Since in unix, this is the same as the broken pipe signal, |
|
803 |
return that one. |
|
804 |
(for other Operatingsystems, this may change ..)" |
|
805 |
||
806 |
^ PipeStream brokenPipeSignal |
|
807 |
! ! |
|
808 |
||
464 | 809 |
!Socket class methodsFor:'debugging'! |
71 | 810 |
|
811 |
debug:aBoolean |
|
812 |
"turn on/off internal debugprints. |
|
813 |
This method is for ST/X debugging only and |
|
814 |
may be removed in later versions" |
|
815 |
||
816 |
%{ /* NOCONTEXT */ |
|
817 |
||
818 |
__debugging__ = (aBoolean == true); |
|
819 |
%} |
|
93 | 820 |
" |
821 |
Socket debug:true |
|
822 |
Socket debug:false |
|
823 |
" |
|
71 | 824 |
! ! |
825 |
||
464 | 826 |
!Socket class methodsFor:'easy tcp/ip instance creation'! |
126 | 827 |
|
828 |
connectTo:service on:host |
|
829 |
"standard & easy client setup: |
|
830 |
create new client tcp socket, bind and connect; |
|
831 |
return the socket. |
|
832 |
The system may block (interruptable), until the connection is |
|
833 |
established." |
|
834 |
||
835 |
^ (self new) for:host port:(self portOfService:service). |
|
836 |
||
837 |
" |
|
838 |
Socket connectTo:9995 on:'clam' |
|
839 |
Socket connectTo:'finger' on:'clam' |
|
840 |
Socket connectTo:'ftp' on:'clam' |
|
841 |
Socket connectTo:'nntp' on:(OperatingSystem getEnvironment:'NNTPSERVER') |
|
842 |
" |
|
843 |
! |
|
844 |
||
845 |
provide:service |
|
846 |
"standard & easy server setup: |
|
847 |
create a new TCP server socket providing a service." |
|
848 |
||
849 |
|newSock| |
|
850 |
||
851 |
newSock := (self new) for:nil port:(self portOfService:service). |
|
852 |
newSock notNil ifTrue:[ |
|
853 |
newSock listenFor:5. |
|
854 |
]. |
|
855 |
^ newSock |
|
856 |
||
857 |
" |
|
858 |
Socket provide:9995 |
|
859 |
(Socket provide:9996) accept |
|
860 |
Socket provide:'nntp' |
|
861 |
" |
|
862 |
! ! |
|
863 |
||
464 | 864 |
!Socket class methodsFor:'general instance creation'! |
126 | 865 |
|
866 |
domain:domainSymbol type:type |
|
867 |
"create a socket for domain and type - |
|
868 |
neither any connect nor binding is done. |
|
869 |
Domain must be one of the symbols: #inet, #unix, #ns, #appletalk or #ns; |
|
870 |
Type must be #stream, #datagram or #raw |
|
871 |
||
872 |
XXX: currently only the #inet domain is supported" |
|
873 |
||
874 |
^ self new domain:domainSymbol type:type |
|
875 |
||
876 |
" |
|
877 |
Socket domain:#inet type:#stream |
|
878 |
Socket domain:#inet type:#datagram |
|
879 |
Socket domain:#unix type:#stream |
|
880 |
Socket domain:#appletalk type:#stream |
|
881 |
Socket domain:#DECnet type:#stream |
|
882 |
" |
|
883 |
! |
|
884 |
||
576 | 885 |
new |
886 |
"create a TCP socket" |
|
887 |
||
888 |
^ super new buffered:false |
|
889 |
! |
|
890 |
||
126 | 891 |
newTCP |
892 |
"create a TCP socket - no binding or other setup is done, |
|
893 |
neither connect nor connect-wait is done." |
|
894 |
||
895 |
^ self new domain:#inet type:#stream |
|
896 |
||
897 |
"Socket newUDP" |
|
898 |
! |
|
899 |
||
900 |
newTCP:aServiceOrNil |
|
901 |
"create a TCP socket for a service - |
|
902 |
neither connect nor connect-wait is done." |
|
903 |
||
904 |
|newSock| |
|
905 |
||
906 |
newSock := self newTCP. |
|
907 |
(newSock notNil and:[aServiceOrNil notNil]) ifTrue:[ |
|
908 |
newSock bindTo:(self portOfService:aServiceOrNil) address:nil |
|
909 |
]. |
|
910 |
^ newSock |
|
911 |
||
912 |
||
913 |
"Socket newTCP:'nntp'" |
|
914 |
"Socket newTCP:9995" |
|
915 |
! |
|
916 |
||
576 | 917 |
newTCPclientToAddress:aHostAddress port:aService |
918 |
"create a new TCP client socket connecting to a service. |
|
919 |
Return a socket instance if ok, nil on failure. |
|
920 |
Block until a connection is established (but only the current thread; |
|
921 |
not the whole smalltalk). |
|
922 |
See also: #newTCPclientToAddress:port:withTimeout:" |
|
923 |
||
924 |
^ self newTCPclientToAddress:aHostAddress port:aService withTimeout:nil |
|
925 |
! |
|
926 |
||
927 |
newTCPclientToAddress:aHostAddress port:aService withTimeout:millis |
|
928 |
"create a new TCP client socket connecting to a service. |
|
929 |
Return a socket instance if ok, nil on failure. |
|
930 |
If the millis arg is nonNil, stop trying to connect after that many milliseconds |
|
931 |
and return nil.." |
|
932 |
||
933 |
^ self newTCPclientToHost:aHostAddress port:aService withTimeout:millis |
|
934 |
! |
|
935 |
||
126 | 936 |
newTCPclientToHost:hostname port:aService |
937 |
"create a new TCP client socket connecting to a service. |
|
938 |
Return a socket instance if ok, nil on failure. |
|
939 |
Block until a connection is established (but only the current thread; |
|
940 |
not the whole smalltalk). |
|
941 |
See also: #newTCPclientToHost:port:withTimeout:" |
|
942 |
||
943 |
^ self newTCPclientToHost:hostname port:aService withTimeout:nil |
|
944 |
||
945 |
" |
|
946 |
Socket newTCPclientToHost:'localhost' port:'nntp' |
|
947 |
" |
|
948 |
||
949 |
"Created: 31.10.1995 / 18:54:11 / cg" |
|
950 |
! |
|
951 |
||
952 |
newTCPclientToHost:hostname port:aService withTimeout:millis |
|
953 |
"create a new TCP client socket connecting to a service. |
|
954 |
Return a socket instance if ok, nil on failure. |
|
955 |
If the millis arg is nonNil, stop trying to connect after that many milliseconds |
|
956 |
and return nil.." |
|
957 |
||
958 |
|newSock| |
|
959 |
||
960 |
newSock := self newTCP. |
|
961 |
newSock notNil ifTrue:[ |
|
648
58e11a70ddaf
gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents:
617
diff
changeset
|
962 |
(newSock connectTo:hostname |
58e11a70ddaf
gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents:
617
diff
changeset
|
963 |
port:(self portOfService:aService protocol:'tcp') |
58e11a70ddaf
gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents:
617
diff
changeset
|
964 |
withTimeout:millis |
58e11a70ddaf
gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents:
617
diff
changeset
|
965 |
) ifFalse:[ |
58e11a70ddaf
gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents:
617
diff
changeset
|
966 |
newSock close. |
58e11a70ddaf
gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents:
617
diff
changeset
|
967 |
^ nil |
58e11a70ddaf
gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents:
617
diff
changeset
|
968 |
] |
126 | 969 |
]. |
970 |
^ newSock |
|
971 |
" |
|
972 |
same as: |
|
973 |
^ (self new) for:hostname port:(self portOfService:aPort). |
|
974 |
" |
|
975 |
" |
|
976 |
Socket newTCPclientToHost:'slsv6bt' port:'nntp' |
|
977 |
Socket newTCPclientToHost:'localhost' port:'nntp' withTimeout:1000 |
|
978 |
" |
|
604 | 979 |
|
980 |
"Modified: / 16.1.1998 / 09:47:06 / stefan" |
|
126 | 981 |
! |
982 |
||
506
11ef93d12870
support anonymous (OS_specified) ports. (for FTP-protocol)
Claus Gittinger <cg@exept.de>
parents:
486
diff
changeset
|
983 |
newTCPserverAtAnonymousPort |
11ef93d12870
support anonymous (OS_specified) ports. (for FTP-protocol)
Claus Gittinger <cg@exept.de>
parents:
486
diff
changeset
|
984 |
"create a new TCP server socket providing service on |
11ef93d12870
support anonymous (OS_specified) ports. (for FTP-protocol)
Claus Gittinger <cg@exept.de>
parents:
486
diff
changeset
|
985 |
a new anonymous port. The portNr is assigned by the OS." |
11ef93d12870
support anonymous (OS_specified) ports. (for FTP-protocol)
Claus Gittinger <cg@exept.de>
parents:
486
diff
changeset
|
986 |
|
11ef93d12870
support anonymous (OS_specified) ports. (for FTP-protocol)
Claus Gittinger <cg@exept.de>
parents:
486
diff
changeset
|
987 |
^ self |
11ef93d12870
support anonymous (OS_specified) ports. (for FTP-protocol)
Claus Gittinger <cg@exept.de>
parents:
486
diff
changeset
|
988 |
newTCPserverAtPort:0 |
11ef93d12870
support anonymous (OS_specified) ports. (for FTP-protocol)
Claus Gittinger <cg@exept.de>
parents:
486
diff
changeset
|
989 |
|
11ef93d12870
support anonymous (OS_specified) ports. (for FTP-protocol)
Claus Gittinger <cg@exept.de>
parents:
486
diff
changeset
|
990 |
! |
11ef93d12870
support anonymous (OS_specified) ports. (for FTP-protocol)
Claus Gittinger <cg@exept.de>
parents:
486
diff
changeset
|
991 |
|
126 | 992 |
newTCPserverAtPort:aService |
993 |
"create a new TCP server socket providing service." |
|
994 |
||
995 |
|newSock| |
|
996 |
||
997 |
newSock := self newTCP. |
|
998 |
newSock notNil ifTrue:[ |
|
999 |
(newSock bindTo:(self portOfService:aService) address:nil) ifFalse:[ |
|
1000 |
^ nil |
|
1001 |
] |
|
1002 |
]. |
|
1003 |
^ newSock |
|
1004 |
" |
|
1005 |
same as: |
|
1006 |
^ (self new) for:nil port:aPort |
|
1007 |
" |
|
1008 |
! |
|
1009 |
||
1010 |
newUDP |
|
1011 |
"create a UDP socket - no binding or other setup is done, |
|
1012 |
neither connect nor connect-wait is done." |
|
1013 |
||
1014 |
^ self new domain:#inet type:#datagram |
|
1015 |
||
1016 |
"Socket newUDP" |
|
1017 |
! |
|
1018 |
||
1019 |
newUDP:aServiceOrNil |
|
1020 |
"create a UDP socket for a service - |
|
1021 |
neither connect nor connect-wait is done." |
|
1022 |
||
1023 |
|newSock| |
|
1024 |
||
1025 |
newSock := self newUDP. |
|
1026 |
(newSock notNil and:[aServiceOrNil notNil]) ifTrue:[ |
|
1027 |
newSock bindTo:(self portOfService:aServiceOrNil) address:nil |
|
1028 |
]. |
|
1029 |
^ newSock |
|
1030 |
||
1031 |
"Socket newUDP:nil" |
|
1032 |
! |
|
1033 |
||
1034 |
newUDPserverAtPort:aService |
|
1035 |
"create a new UDP server socket providing service." |
|
1036 |
||
1037 |
|newSock| |
|
1038 |
||
1039 |
newSock := self newUDP. |
|
1040 |
newSock notNil ifTrue:[ |
|
1041 |
(newSock bindTo:(self portOfService:aService) address:nil) ifFalse:[ |
|
1042 |
^ nil |
|
1043 |
] |
|
1044 |
]. |
|
1045 |
^ newSock |
|
1046 |
" |
|
1047 |
same as: |
|
1048 |
^ (self new) for:nil udpPort:aPort |
|
1049 |
" |
|
1050 |
! |
|
1051 |
||
1052 |
newUNIX |
|
1053 |
"create a UNIX domain socket - no binding or other setup is done, |
|
1054 |
neither connect nor connect-wait is done." |
|
1055 |
||
1056 |
^ self new domain:#unix type:#stream |
|
1057 |
||
1058 |
" |
|
1059 |
Socket newUNIX |
|
1060 |
" |
|
1061 |
! |
|
1062 |
||
1063 |
newUNIXclientTo:pathName |
|
1064 |
"create a new UNIX client socket connecting to a pathname. |
|
1065 |
Return a socket instance if ok, nil on failure. |
|
1066 |
Block until a connection is established (but only the current thread; |
|
1067 |
not the whole smalltalk). |
|
1068 |
See also: #newUNIXclientTo:withTimeout:" |
|
1069 |
||
1070 |
^ self newUNIXclientTo:pathName withTimeout:nil |
|
1071 |
||
1072 |
! |
|
1073 |
||
1074 |
newUNIXclientTo:pathName withTimeout:millis |
|
1075 |
"create a new UNIX client socket connecting to a pathname. |
|
1076 |
Return a socket instance if ok, nil on failure. |
|
1077 |
If the millis arg is nonNil, stop trying to connect after that many milliseconds |
|
1078 |
and return nil.." |
|
1079 |
||
1080 |
|newSock| |
|
1081 |
||
1082 |
newSock := self newUNIX. |
|
1083 |
newSock notNil ifTrue:[ |
|
1084 |
(newSock connectTo:pathName port:nil withTimeout:millis) ifFalse:[ |
|
1085 |
newSock close. |
|
1086 |
^ nil |
|
1087 |
] |
|
1088 |
]. |
|
1089 |
^ newSock |
|
1090 |
||
1091 |
" |
|
1092 |
|s| |
|
1093 |
||
1094 |
s := Socket newUNIXclientTo:'/tmp/foo' |
|
1095 |
" |
|
1096 |
! |
|
1097 |
||
1098 |
newUNIXserverAt:pathName |
|
1099 |
"create a new UNIX server socket providing service at a pathname." |
|
1100 |
||
1101 |
|newSock| |
|
1102 |
||
1103 |
newSock := self newUNIX. |
|
1104 |
newSock notNil ifTrue:[ |
|
1105 |
(newSock bindTo:pathName address:nil) ifFalse:[ |
|
1106 |
^ nil |
|
1107 |
] |
|
1108 |
]. |
|
1109 |
^ newSock |
|
1110 |
||
1111 |
" |
|
1112 |
|s s2| |
|
1113 |
||
1114 |
s := Socket newUNIXserverAt:'/tmp/foo'. |
|
1115 |
s listenFor:5. |
|
1116 |
s2 := s accept. |
|
1117 |
" |
|
1118 |
! ! |
|
1119 |
||
525 | 1120 |
!Socket class methodsFor:'host queries'! |
1121 |
||
1122 |
appletalkAddressOfHost:aHostName |
|
1123 |
"return the APPLETALK address for a hostname as a byteArray, |
|
1124 |
where the network bytes come first followed by the node. |
|
1125 |
If the host is unknown, return nil. |
|
1126 |
This is the reverse operation to #hostWithAppletalkAddress:." |
|
1127 |
||
1128 |
|b1 b2 b3| |
|
1129 |
%{ |
|
526 | 1130 |
#if !defined(NO_SOCKET) && defined(AF_APPLETALK) |
525 | 1131 |
struct sockaddr_at sa ; |
1132 |
struct hostent *hp ; |
|
1133 |
long addr; |
|
1134 |
||
529 | 1135 |
sa.sat_family = -1; |
525 | 1136 |
|
1137 |
if (__isString(aHostName)) { |
|
1138 |
bzero(&sa, sizeof(sa)) ; |
|
1139 |
||
1140 |
/* do we know the host's address? */ |
|
648
58e11a70ddaf
gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents:
617
diff
changeset
|
1141 |
GETHOSTBYNAME(hp, __stringVal(aHostName)) |
537
f413ab8fd1b5
gethostbyname must be executed interruptable;
Claus Gittinger <cg@exept.de>
parents:
533
diff
changeset
|
1142 |
if (hp == NULL) { |
525 | 1143 |
DBGPRINTF(("SOCKET: unknown host: %s\n", __stringVal(aHostName))); |
1144 |
RETURN ( nil ); |
|
1145 |
} |
|
1146 |
bcopy(hp->h_addr, (char *) &sa.sat_addr, hp->h_length) ; |
|
1147 |
sa.sat_family = hp->h_addrtype; |
|
1148 |
} |
|
1149 |
||
1150 |
/* if the addressing family is not AF_APPLETALK, return nil */ |
|
1151 |
if (sa.sat_family != AF_INET) { |
|
1152 |
DBGPRINTF(("SOCKET: not an appletalk host\n")); |
|
1153 |
RETURN ( nil ); |
|
1154 |
} |
|
1155 |
||
1156 |
sa.sat_addr.s_net = ntohs(sa.sat_addr.s_net); |
|
1157 |
b1 = __MKSMALLINT((sa.sat_addr.s_net >> 8) & 0xFF); |
|
1158 |
b2 = __MKSMALLINT((sa.sat_addr.s_net) & 0xFF); |
|
1159 |
b3 = __MKSMALLINT((sa.sat_addr.s_node) & 0xFF); |
|
1160 |
#else |
|
1161 |
RETURN (nil); |
|
1162 |
#endif |
|
1163 |
%}. |
|
1164 |
^ ByteArray with:b1 with:b2 with:b3 |
|
1165 |
||
1166 |
! |
|
1167 |
||
1168 |
hostWithAppletalkAddress:anAddress |
|
1169 |
"return the hostname for an APPLETALK address. |
|
1170 |
The address is supposed to be a byteArray consisting of 3 bytes, |
|
1171 |
the network bytes come first (no matter what the local byteorder is). |
|
1172 |
The last byte is the node number. |
|
1173 |
Nil is returned for an unknown host or if its not an appletalk host. |
|
1174 |
This is is the reverse operation to #appletalkAddressOfHost:." |
|
1175 |
||
1176 |
|b1 b2 b3 b4| |
|
1177 |
||
1178 |
b1 := anAddress at:1. |
|
1179 |
b2 := anAddress at:2. |
|
1180 |
b3 := anAddress at:3. |
|
1181 |
b4 := anAddress at:4. |
|
1182 |
%{ |
|
1183 |
#if !defined(NO_SOCKET) && defined(AF_APPLETALK) |
|
1184 |
struct sockaddr_at sa ; |
|
1185 |
struct hostent *hp ; |
|
1186 |
||
1187 |
sa.sat_family = -1; |
|
1188 |
||
1189 |
if (__bothSmallInteger(b1, b2) && __bothSmallInteger(b3, b4)) { |
|
1190 |
bzero(&sa, sizeof(sa)) ; |
|
1191 |
||
1192 |
sa.sat_addr.s_net = _intVal(b1) & 0xFF; |
|
529 | 1193 |
sa.sat_addr.s_net = (sa.sat_addr.s_net << 8) | (_intVal(b2) & 0xFF); |
1194 |
sa.sat_addr.s_net = htons(sa.sat_addr.s_net); |
|
1195 |
sa.sat_addr.s_node = _intVal(b3) & 0xFF; |
|
1196 |
sa.sat_family = AF_APPLETALK; |
|
1197 |
||
525 | 1198 |
/* do we know the host's address? */ |
650
8c5616f17ed6
made gethostbyaddr interruptable
Claus Gittinger <cg@exept.de>
parents:
649
diff
changeset
|
1199 |
GETHOSTBYADDR(hp, (char *) &sa.sat_addr, sizeof(sa.sat_addr), AF_APPLETALK); |
525 | 1200 |
if (hp != NULL) { |
1201 |
sa.sat_family = hp->h_addrtype; |
|
1202 |
} else { |
|
1203 |
DBGPRINTF(("SOCKET: unknown address: %d.%d.%d.%d\n", |
|
1204 |
_intVal(b1), _intVal(b2), _intVal(b3))); |
|
1205 |
} |
|
1206 |
} |
|
1207 |
||
1208 |
/* if the addressing family is not AF_APPLETALK, return nil */ |
|
1209 |
if (sa.sat_family != AF_APPLETALK) { |
|
1210 |
RETURN ( nil ); |
|
1211 |
} |
|
1212 |
||
1213 |
if (hp != NULL) { |
|
1214 |
RETURN (__MKSTRING(hp->h_name)); |
|
1215 |
} |
|
1216 |
#endif |
|
1217 |
RETURN (nil); |
|
1218 |
%}. |
|
1219 |
" |
|
1220 |
Socket appletalkAddressOfHost:'clam' |
|
1221 |
Socket hostWithAppletalkAddress:#[1 2 3] |
|
1222 |
" |
|
126 | 1223 |
! |
1224 |
||
1225 |
hostWithIpAddress:anAddress |
|
1226 |
"return the hostname for an IP (internet-) address. |
|
1227 |
The address is supposed to be a byteArray consisting of 4 bytes, |
|
1228 |
the network bytes come first (no matter what the local byteorder is). |
|
525 | 1229 |
Nil is returned for an unknown host or if its not an internet host. |
126 | 1230 |
This is the reverse operation to #ipAddressOfHost:." |
1231 |
||
1232 |
|b1 b2 b3 b4| |
|
1233 |
||
1234 |
b1 := anAddress at:1. |
|
1235 |
b2 := anAddress at:2. |
|
1236 |
b3 := anAddress at:3. |
|
1237 |
b4 := anAddress at:4. |
|
1238 |
%{ |
|
525 | 1239 |
#if !defined(NO_SOCKET) && defined(AF_INET) |
126 | 1240 |
struct sockaddr_in sa ; |
1241 |
struct hostent *hp ; |
|
1242 |
||
525 | 1243 |
sa.sin_family = -1; |
126 | 1244 |
if (__bothSmallInteger(b1, b2) && __bothSmallInteger(b3, b4)) { |
1245 |
bzero(&sa, sizeof(sa)) ; |
|
1246 |
sa.sin_addr.s_addr = _intVal(b1) & 0xFF; |
|
1247 |
sa.sin_addr.s_addr = (sa.sin_addr.s_addr << 8) | (_intVal(b2) & 0xFF); |
|
1248 |
sa.sin_addr.s_addr = (sa.sin_addr.s_addr << 8) | (_intVal(b3) & 0xFF); |
|
1249 |
sa.sin_addr.s_addr = (sa.sin_addr.s_addr << 8) | (_intVal(b4) & 0xFF); |
|
1250 |
sa.sin_addr.s_addr = htonl(sa.sin_addr.s_addr); |
|
1251 |
sa.sin_family = AF_INET; |
|
1252 |
/* do we know the host's address? */ |
|
650
8c5616f17ed6
made gethostbyaddr interruptable
Claus Gittinger <cg@exept.de>
parents:
649
diff
changeset
|
1253 |
GETHOSTBYADDR(hp, (char *) &sa.sin_addr.s_addr, sizeof(sa.sin_addr.s_addr), AF_INET); |
126 | 1254 |
if (hp == NULL) { |
1255 |
DBGPRINTF(("SOCKET: unknown address: %d.%d.%d.%d\n", |
|
1256 |
_intVal(b1), _intVal(b2), _intVal(b3), _intVal(b4))); |
|
1257 |
} else { |
|
1258 |
sa.sin_family = hp->h_addrtype; |
|
1259 |
} |
|
1260 |
} |
|
1261 |
||
1262 |
/* if the addressing family is not AF_INET, return nil */ |
|
1263 |
if (sa.sin_family != AF_INET) { |
|
1264 |
RETURN ( nil ); |
|
1265 |
} |
|
525 | 1266 |
|
1267 |
if (hp != NULL) { |
|
448
2203a4bb620d
removed all COMMA_CON / CON_COMMA uses
Claus Gittinger <cg@exept.de>
parents:
444
diff
changeset
|
1268 |
RETURN (__MKSTRING(hp->h_name)); |
525 | 1269 |
} |
1270 |
||
1271 |
/* |
|
1272 |
* return it in dot-notation |
|
1273 |
*/ |
|
448
2203a4bb620d
removed all COMMA_CON / CON_COMMA uses
Claus Gittinger <cg@exept.de>
parents:
444
diff
changeset
|
1274 |
RETURN (__MKSTRING(inet_ntoa(sa.sin_addr))); |
418 | 1275 |
#else |
1276 |
RETURN (nil); |
|
1277 |
#endif |
|
126 | 1278 |
%} |
1279 |
||
1280 |
" |
|
1281 |
Socket ipAddressOfHost:'clam' |
|
1282 |
Socket hostWithIpAddress:(Socket ipAddressOfHost:'clam') |
|
1283 |
Socket ipAddressOfHost:'porty' |
|
1284 |
Socket hostWithIpAddress:(Socket ipAddressOfHost:'porty') |
|
1285 |
Socket hostWithIpAddress:#[1 2 3 4] |
|
1286 |
Socket hostWithIpAddress:(Socket ipAddressOfHost:'1.2.3.4') |
|
1287 |
" |
|
1288 |
! |
|
1289 |
||
6 | 1290 |
ipAddressOfHost:aHostName |
98
5e787ba2cb31
use common byteOrder when representing IP numbers as byteArrays (always network-first)
Claus Gittinger <cg@exept.de>
parents:
96
diff
changeset
|
1291 |
"return the IP (internet-) number for a hostname as a byteArray, |
5e787ba2cb31
use common byteOrder when representing IP numbers as byteArrays (always network-first)
Claus Gittinger <cg@exept.de>
parents:
96
diff
changeset
|
1292 |
where the network bytes come first (no matter what the cpus byteOrder is). |
5e787ba2cb31
use common byteOrder when representing IP numbers as byteArrays (always network-first)
Claus Gittinger <cg@exept.de>
parents:
96
diff
changeset
|
1293 |
If the host is unknown, return nil. |
5e787ba2cb31
use common byteOrder when representing IP numbers as byteArrays (always network-first)
Claus Gittinger <cg@exept.de>
parents:
96
diff
changeset
|
1294 |
This is the reverse operation to #hostWithIpAddress:." |
6 | 1295 |
|
1296 |
|b1 b2 b3 b4| |
|
1297 |
||
1298 |
%{ |
|
525 | 1299 |
#if !defined(NO_SOCKET) && defined(AF_INET) |
6 | 1300 |
struct sockaddr_in sa ; |
1301 |
struct hostent *hp ; |
|
1302 |
long addr; |
|
1303 |
||
525 | 1304 |
sa.sin_family = -1; |
1305 |
||
21 | 1306 |
if (__isString(aHostName)) { |
42 | 1307 |
bzero(&sa, sizeof(sa)) ; |
524
8287da54eccf
more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents:
513
diff
changeset
|
1308 |
if ((addr = inet_addr((char *) __stringVal(aHostName))) != -1) { |
42 | 1309 |
/* is Internet addr in octet notation */ |
1310 |
bcopy(&addr, (char *) &sa.sin_addr, sizeof(addr)); |
|
1311 |
sa.sin_family = AF_INET; |
|
1312 |
} else { |
|
1313 |
/* do we know the host's address? */ |
|
648
58e11a70ddaf
gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents:
617
diff
changeset
|
1314 |
GETHOSTBYNAME(hp, __stringVal(aHostName)) |
537
f413ab8fd1b5
gethostbyname must be executed interruptable;
Claus Gittinger <cg@exept.de>
parents:
533
diff
changeset
|
1315 |
if (hp == NULL) { |
f413ab8fd1b5
gethostbyname must be executed interruptable;
Claus Gittinger <cg@exept.de>
parents:
533
diff
changeset
|
1316 |
DBGPRINTF(("SOCKET: unknown host: %s\n", __stringVal(aHostName))); |
42 | 1317 |
RETURN ( nil ); |
1318 |
} |
|
1319 |
bcopy(hp->h_addr, (char *) &sa.sin_addr, hp->h_length) ; |
|
1320 |
sa.sin_family = hp->h_addrtype; |
|
1321 |
} |
|
6 | 1322 |
} |
525 | 1323 |
|
6 | 1324 |
/* if the addressing family is not AF_INET, return nil */ |
1325 |
if (sa.sin_family != AF_INET) { |
|
525 | 1326 |
DBGPRINTF(("SOCKET: not an internet host\n")); |
42 | 1327 |
RETURN ( nil ); |
6 | 1328 |
} |
98
5e787ba2cb31
use common byteOrder when representing IP numbers as byteArrays (always network-first)
Claus Gittinger <cg@exept.de>
parents:
96
diff
changeset
|
1329 |
|
5e787ba2cb31
use common byteOrder when representing IP numbers as byteArrays (always network-first)
Claus Gittinger <cg@exept.de>
parents:
96
diff
changeset
|
1330 |
sa.sin_addr.s_addr = ntohl(sa.sin_addr.s_addr); |
217 | 1331 |
b1 = __MKSMALLINT((sa.sin_addr.s_addr >> 24) & 0xFF); |
1332 |
b2 = __MKSMALLINT((sa.sin_addr.s_addr >> 16) & 0xFF); |
|
1333 |
b3 = __MKSMALLINT((sa.sin_addr.s_addr >> 8) & 0xFF); |
|
1334 |
b4 = __MKSMALLINT((sa.sin_addr.s_addr >> 0) & 0xFF); |
|
418 | 1335 |
#else |
1336 |
RETURN (nil); |
|
1337 |
#endif |
|
525 | 1338 |
%}. |
6 | 1339 |
^ ByteArray with:b1 with:b2 with:b3 with:b4 |
21 | 1340 |
|
71 | 1341 |
" |
98
5e787ba2cb31
use common byteOrder when representing IP numbers as byteArrays (always network-first)
Claus Gittinger <cg@exept.de>
parents:
96
diff
changeset
|
1342 |
Socket ipAddressOfHost:'clam' |
5e787ba2cb31
use common byteOrder when representing IP numbers as byteArrays (always network-first)
Claus Gittinger <cg@exept.de>
parents:
96
diff
changeset
|
1343 |
Socket ipAddressOfHost:'porty' |
5e787ba2cb31
use common byteOrder when representing IP numbers as byteArrays (always network-first)
Claus Gittinger <cg@exept.de>
parents:
96
diff
changeset
|
1344 |
Socket ipAddressOfHost:'axept' |
5e787ba2cb31
use common byteOrder when representing IP numbers as byteArrays (always network-first)
Claus Gittinger <cg@exept.de>
parents:
96
diff
changeset
|
1345 |
Socket ipAddressOfHost:'axept' |
5e787ba2cb31
use common byteOrder when representing IP numbers as byteArrays (always network-first)
Claus Gittinger <cg@exept.de>
parents:
96
diff
changeset
|
1346 |
Socket ipAddressOfHost:'1.2.3.4' |
5e787ba2cb31
use common byteOrder when representing IP numbers as byteArrays (always network-first)
Claus Gittinger <cg@exept.de>
parents:
96
diff
changeset
|
1347 |
Socket ipAddressOfHost:'193.15.16.17' |
5e787ba2cb31
use common byteOrder when representing IP numbers as byteArrays (always network-first)
Claus Gittinger <cg@exept.de>
parents:
96
diff
changeset
|
1348 |
Socket ipAddressOfHost:'josef' |
5e787ba2cb31
use common byteOrder when representing IP numbers as byteArrays (always network-first)
Claus Gittinger <cg@exept.de>
parents:
96
diff
changeset
|
1349 |
Socket ipAddressOfHost:'styx.com' |
5e787ba2cb31
use common byteOrder when representing IP numbers as byteArrays (always network-first)
Claus Gittinger <cg@exept.de>
parents:
96
diff
changeset
|
1350 |
Socket hostWithIpAddress:(Socket ipAddressOfHost:'localhost') |
5e787ba2cb31
use common byteOrder when representing IP numbers as byteArrays (always network-first)
Claus Gittinger <cg@exept.de>
parents:
96
diff
changeset
|
1351 |
Socket ipAddressOfHost:(Socket hostWithIpAddress:'127.0.0.1') |
71 | 1352 |
" |
531 | 1353 |
! ! |
1354 |
||
1355 |
!Socket class methodsFor:'queries'! |
|
1356 |
||
1357 |
domainOfProtocol:aProtocol |
|
1358 |
"given a protocols name (i.e. tcp, udp etc) return the domain. |
|
1359 |
This method needs more ... - or is there a way to get this from the system ?" |
|
1360 |
||
1361 |
" |
|
1362 |
tcp/ip stuff |
|
1363 |
" |
|
1364 |
(aProtocol = 'tcp') ifTrue:[^ #inet]. |
|
1365 |
(aProtocol = 'udp') ifTrue:[^ #inet]. |
|
1366 |
(aProtocol = 'ip') ifTrue:[^ #inet]. |
|
1367 |
" |
|
1368 |
unix domain |
|
1369 |
" |
|
1370 |
(aProtocol = 'ud') ifTrue:[^ #unix]. |
|
1371 |
||
1372 |
" |
|
1373 |
add x25 stuff (if any) here ... |
|
1374 |
" |
|
1375 |
" |
|
1376 |
add appletalk stuff (if any) here ... |
|
1377 |
" |
|
1378 |
" |
|
1379 |
add other stuff (if any) here ... |
|
1380 |
" |
|
1381 |
^ nil |
|
1382 |
||
1383 |
" |
|
1384 |
Socket domainOfProtocol:'tcp' |
|
1385 |
Socket domainOfProtocol:'ucp' |
|
1386 |
Socket domainOfProtocol:(Socket protocolOfService:'nntp') |
|
1387 |
Socket domainOfProtocol:(Socket protocolOfService:'echo') |
|
1388 |
" |
|
6 | 1389 |
! |
1390 |
||
206
77166a6b3ee6
For ST80 style socket creation: register socket in Lobby.
Stefan Vogel <sv@exept.de>
parents:
203
diff
changeset
|
1391 |
networkLongOrderIsMSB |
77166a6b3ee6
For ST80 style socket creation: register socket in Lobby.
Stefan Vogel <sv@exept.de>
parents:
203
diff
changeset
|
1392 |
"return true, if the network-byte-order of longs is MSB. |
77166a6b3ee6
For ST80 style socket creation: register socket in Lobby.
Stefan Vogel <sv@exept.de>
parents:
203
diff
changeset
|
1393 |
To be used as in: |
77166a6b3ee6
For ST80 style socket creation: register socket in Lobby.
Stefan Vogel <sv@exept.de>
parents:
203
diff
changeset
|
1394 |
'aStream nextPutLong:someValue MSB:(Socket networkLongOrderIsMSB)'." |
77166a6b3ee6
For ST80 style socket creation: register socket in Lobby.
Stefan Vogel <sv@exept.de>
parents:
203
diff
changeset
|
1395 |
|
77166a6b3ee6
For ST80 style socket creation: register socket in Lobby.
Stefan Vogel <sv@exept.de>
parents:
203
diff
changeset
|
1396 |
%{ /* NOCONTEXT */ |
418 | 1397 |
#ifndef NO_SOCKET |
206
77166a6b3ee6
For ST80 style socket creation: register socket in Lobby.
Stefan Vogel <sv@exept.de>
parents:
203
diff
changeset
|
1398 |
/* |
77166a6b3ee6
For ST80 style socket creation: register socket in Lobby.
Stefan Vogel <sv@exept.de>
parents:
203
diff
changeset
|
1399 |
* mhmh - do c-compilers optimize this away ? |
77166a6b3ee6
For ST80 style socket creation: register socket in Lobby.
Stefan Vogel <sv@exept.de>
parents:
203
diff
changeset
|
1400 |
*/ |
77166a6b3ee6
For ST80 style socket creation: register socket in Lobby.
Stefan Vogel <sv@exept.de>
parents:
203
diff
changeset
|
1401 |
if (htonl(0x76543210) == 0x76543210) { |
77166a6b3ee6
For ST80 style socket creation: register socket in Lobby.
Stefan Vogel <sv@exept.de>
parents:
203
diff
changeset
|
1402 |
RETURN (true); |
77166a6b3ee6
For ST80 style socket creation: register socket in Lobby.
Stefan Vogel <sv@exept.de>
parents:
203
diff
changeset
|
1403 |
} |
418 | 1404 |
#endif |
206
77166a6b3ee6
For ST80 style socket creation: register socket in Lobby.
Stefan Vogel <sv@exept.de>
parents:
203
diff
changeset
|
1405 |
%}. |
77166a6b3ee6
For ST80 style socket creation: register socket in Lobby.
Stefan Vogel <sv@exept.de>
parents:
203
diff
changeset
|
1406 |
^ false |
77166a6b3ee6
For ST80 style socket creation: register socket in Lobby.
Stefan Vogel <sv@exept.de>
parents:
203
diff
changeset
|
1407 |
|
77166a6b3ee6
For ST80 style socket creation: register socket in Lobby.
Stefan Vogel <sv@exept.de>
parents:
203
diff
changeset
|
1408 |
" |
77166a6b3ee6
For ST80 style socket creation: register socket in Lobby.
Stefan Vogel <sv@exept.de>
parents:
203
diff
changeset
|
1409 |
Socket networkLongOrderIsMSB |
77166a6b3ee6
For ST80 style socket creation: register socket in Lobby.
Stefan Vogel <sv@exept.de>
parents:
203
diff
changeset
|
1410 |
" |
77166a6b3ee6
For ST80 style socket creation: register socket in Lobby.
Stefan Vogel <sv@exept.de>
parents:
203
diff
changeset
|
1411 |
! |
77166a6b3ee6
For ST80 style socket creation: register socket in Lobby.
Stefan Vogel <sv@exept.de>
parents:
203
diff
changeset
|
1412 |
|
77166a6b3ee6
For ST80 style socket creation: register socket in Lobby.
Stefan Vogel <sv@exept.de>
parents:
203
diff
changeset
|
1413 |
networkShortOrderIsMSB |
77166a6b3ee6
For ST80 style socket creation: register socket in Lobby.
Stefan Vogel <sv@exept.de>
parents:
203
diff
changeset
|
1414 |
"return true, if the network-byte-order of shorts is MSB. |
77166a6b3ee6
For ST80 style socket creation: register socket in Lobby.
Stefan Vogel <sv@exept.de>
parents:
203
diff
changeset
|
1415 |
To be used as in: |
77166a6b3ee6
For ST80 style socket creation: register socket in Lobby.
Stefan Vogel <sv@exept.de>
parents:
203
diff
changeset
|
1416 |
'aStream nextPutShort:someValue MSB:(Socket networkShortOrderIsMSB)'." |
77166a6b3ee6
For ST80 style socket creation: register socket in Lobby.
Stefan Vogel <sv@exept.de>
parents:
203
diff
changeset
|
1417 |
|
77166a6b3ee6
For ST80 style socket creation: register socket in Lobby.
Stefan Vogel <sv@exept.de>
parents:
203
diff
changeset
|
1418 |
%{ /* NOCONTEXT */ |
418 | 1419 |
#ifndef NO_SOCKET |
206
77166a6b3ee6
For ST80 style socket creation: register socket in Lobby.
Stefan Vogel <sv@exept.de>
parents:
203
diff
changeset
|
1420 |
/* |
77166a6b3ee6
For ST80 style socket creation: register socket in Lobby.
Stefan Vogel <sv@exept.de>
parents:
203
diff
changeset
|
1421 |
* mhmh - do c-compilers optimize this away ? |
77166a6b3ee6
For ST80 style socket creation: register socket in Lobby.
Stefan Vogel <sv@exept.de>
parents:
203
diff
changeset
|
1422 |
*/ |
77166a6b3ee6
For ST80 style socket creation: register socket in Lobby.
Stefan Vogel <sv@exept.de>
parents:
203
diff
changeset
|
1423 |
if (htons(0x3210) == 0x3210) { |
77166a6b3ee6
For ST80 style socket creation: register socket in Lobby.
Stefan Vogel <sv@exept.de>
parents:
203
diff
changeset
|
1424 |
RETURN (true); |
77166a6b3ee6
For ST80 style socket creation: register socket in Lobby.
Stefan Vogel <sv@exept.de>
parents:
203
diff
changeset
|
1425 |
} |
418 | 1426 |
#endif |
206
77166a6b3ee6
For ST80 style socket creation: register socket in Lobby.
Stefan Vogel <sv@exept.de>
parents:
203
diff
changeset
|
1427 |
%}. |
77166a6b3ee6
For ST80 style socket creation: register socket in Lobby.
Stefan Vogel <sv@exept.de>
parents:
203
diff
changeset
|
1428 |
^ false |
77166a6b3ee6
For ST80 style socket creation: register socket in Lobby.
Stefan Vogel <sv@exept.de>
parents:
203
diff
changeset
|
1429 |
|
77166a6b3ee6
For ST80 style socket creation: register socket in Lobby.
Stefan Vogel <sv@exept.de>
parents:
203
diff
changeset
|
1430 |
" |
77166a6b3ee6
For ST80 style socket creation: register socket in Lobby.
Stefan Vogel <sv@exept.de>
parents:
203
diff
changeset
|
1431 |
Socket networkShortOrderIsMSB |
77166a6b3ee6
For ST80 style socket creation: register socket in Lobby.
Stefan Vogel <sv@exept.de>
parents:
203
diff
changeset
|
1432 |
" |
77166a6b3ee6
For ST80 style socket creation: register socket in Lobby.
Stefan Vogel <sv@exept.de>
parents:
203
diff
changeset
|
1433 |
! |
77166a6b3ee6
For ST80 style socket creation: register socket in Lobby.
Stefan Vogel <sv@exept.de>
parents:
203
diff
changeset
|
1434 |
|
0 | 1435 |
portOfService:aNameOrNumber |
1436 |
"returns the port-number for a given service |
|
1437 |
or nil if no such service exists; |
|
1438 |
- used to convert service names to portNumbers" |
|
1439 |
||
91 | 1440 |
^ self portOfService:aNameOrNumber protocol:nil |
1441 |
||
28 | 1442 |
" |
1443 |
Socket portOfService:'finger' |
|
74 | 1444 |
Socket portOfService:'nntp' |
1445 |
Socket portOfService:'echo' |
|
1446 |
Socket portOfService:'snmp' |
|
28 | 1447 |
" |
0 | 1448 |
! |
1449 |
||
91 | 1450 |
portOfService:aNameOrNumber protocol:aProtocol |
1451 |
"returns the port-number for a given service |
|
1452 |
or nil if no such service exists; |
|
1453 |
- used to convert service names to portNumbers" |
|
1454 |
||
604 | 1455 |
%{ /* NOCONTEXT */ |
418 | 1456 |
#ifndef NO_SOCKET |
91 | 1457 |
struct servent *servent = NULL; |
1458 |
char *protocol; |
|
1459 |
int tryBoth = 0; |
|
524
8287da54eccf
more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents:
513
diff
changeset
|
1460 |
short portNo; |
91 | 1461 |
|
604 | 1462 |
if (__isSmallInteger(aNameOrNumber)) { |
648
58e11a70ddaf
gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents:
617
diff
changeset
|
1463 |
RETURN ( aNameOrNumber ); |
92 | 1464 |
} |
1465 |
||
604 | 1466 |
if (__isString(aProtocol)) { |
648
58e11a70ddaf
gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents:
617
diff
changeset
|
1467 |
protocol = (char *)__stringVal(aProtocol); |
604 | 1468 |
} else { |
648
58e11a70ddaf
gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents:
617
diff
changeset
|
1469 |
protocol = "tcp"; |
58e11a70ddaf
gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents:
617
diff
changeset
|
1470 |
tryBoth = 1; |
91 | 1471 |
} |
524
8287da54eccf
more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents:
513
diff
changeset
|
1472 |
|
8287da54eccf
more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents:
513
diff
changeset
|
1473 |
if (__isString(aNameOrNumber) || __isSymbol(aNameOrNumber)) { |
648
58e11a70ddaf
gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents:
617
diff
changeset
|
1474 |
servent = getservbyname((char *) __stringVal(aNameOrNumber), protocol); |
58e11a70ddaf
gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents:
617
diff
changeset
|
1475 |
if (servent != NULL) { |
58e11a70ddaf
gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents:
617
diff
changeset
|
1476 |
RETURN ( __MKSMALLINT(ntohs(servent->s_port)) ); |
58e11a70ddaf
gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents:
617
diff
changeset
|
1477 |
} |
58e11a70ddaf
gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents:
617
diff
changeset
|
1478 |
if (tryBoth) { |
58e11a70ddaf
gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents:
617
diff
changeset
|
1479 |
servent = getservbyname((char *) __stringVal(aNameOrNumber), "udp"); |
58e11a70ddaf
gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents:
617
diff
changeset
|
1480 |
if (servent != NULL) { |
58e11a70ddaf
gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents:
617
diff
changeset
|
1481 |
RETURN ( __MKSMALLINT(ntohs(servent->s_port)) ); |
58e11a70ddaf
gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents:
617
diff
changeset
|
1482 |
} |
58e11a70ddaf
gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents:
617
diff
changeset
|
1483 |
} |
58e11a70ddaf
gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents:
617
diff
changeset
|
1484 |
RETURN ( nil ); |
91 | 1485 |
} |
418 | 1486 |
#endif |
91 | 1487 |
RETURN ( nil ); |
1488 |
%} |
|
1489 |
" |
|
1490 |
Socket portOfService:'echo' protocol:'udp' |
|
1491 |
Socket portOfService:'echo' protocol:'tcp' |
|
1492 |
" |
|
1493 |
! |
|
1494 |
||
0 | 1495 |
protocolOfService:aNameOrNumber |
1496 |
"returns the protocol (as string) for a given service |
|
28 | 1497 |
or nil if no such service exists." |
0 | 1498 |
%{ |
418 | 1499 |
#ifndef NO_SOCKET |
0 | 1500 |
struct servent *servent = NULL; |
524
8287da54eccf
more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents:
513
diff
changeset
|
1501 |
short portNo; |
0 | 1502 |
|
58 | 1503 |
if (__isSmallInteger(aNameOrNumber)) { |
524
8287da54eccf
more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents:
513
diff
changeset
|
1504 |
portNo = __intVal(aNameOrNumber); |
8287da54eccf
more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents:
513
diff
changeset
|
1505 |
servent = getservbyport(htons(portNo), "tcp") ; |
42 | 1506 |
if (servent == NULL) { |
524
8287da54eccf
more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents:
513
diff
changeset
|
1507 |
servent = getservbyport(htons(portNo), "udp") ; |
42 | 1508 |
if (servent == NULL) { |
1509 |
RETURN ( nil ); |
|
1510 |
} |
|
1511 |
} |
|
0 | 1512 |
} else { |
42 | 1513 |
if (__isString(aNameOrNumber)) { |
524
8287da54eccf
more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents:
513
diff
changeset
|
1514 |
servent = getservbyname((char *) __stringVal(aNameOrNumber), "tcp"); |
42 | 1515 |
if (servent == NULL) { |
524
8287da54eccf
more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents:
513
diff
changeset
|
1516 |
servent = getservbyname((char *) __stringVal(aNameOrNumber), "udp"); |
42 | 1517 |
if (servent == NULL) { |
1518 |
RETURN ( nil ); |
|
1519 |
} |
|
1520 |
} |
|
1521 |
} |
|
0 | 1522 |
} |
1523 |
if (servent) { |
|
448
2203a4bb620d
removed all COMMA_CON / CON_COMMA uses
Claus Gittinger <cg@exept.de>
parents:
444
diff
changeset
|
1524 |
RETURN ( __MKSTRING(servent->s_proto) ); |
0 | 1525 |
} |
418 | 1526 |
#endif |
0 | 1527 |
RETURN ( nil ); |
1528 |
%} |
|
28 | 1529 |
" |
74 | 1530 |
Socket protocolOfService:'finger' |
1531 |
Socket protocolOfService:'nntp' |
|
28 | 1532 |
Socket protocolOfService:'xxx' |
1533 |
Socket protocolOfService:79 |
|
74 | 1534 |
Socket protocolOfService:'snmp' |
28 | 1535 |
" |
1536 |
! |
|
1537 |
||
532 | 1538 |
supportedProtocolFamilies |
1539 |
"return a collection of supported protocol families. |
|
1540 |
This list specifies what the Socket class supports - |
|
1541 |
socket creation may still fail, if your system was built |
|
1542 |
without it." |
|
1543 |
||
1544 |
|list hasIt| |
|
1545 |
||
1546 |
list := OrderedCollection new. |
|
1547 |
||
1548 |
%{ |
|
1549 |
#ifdef AF_INET |
|
1550 |
hasIt = true; |
|
1551 |
#else |
|
1552 |
hasIt = false; |
|
1553 |
#endif |
|
1554 |
%}. |
|
1555 |
hasIt ifTrue:[list add:#inet]. |
|
1556 |
||
1557 |
%{ |
|
1558 |
#ifdef AF_UNIX |
|
1559 |
hasIt = true; |
|
1560 |
#else |
|
1561 |
hasIt = false; |
|
1562 |
#endif |
|
1563 |
%}. |
|
1564 |
hasIt ifTrue:[list add:#unix]. |
|
1565 |
||
1566 |
%{ |
|
1567 |
#ifdef AF_INET6 |
|
1568 |
hasIt = true; |
|
1569 |
#else |
|
1570 |
hasIt = false; |
|
1571 |
#endif |
|
1572 |
%}. |
|
1573 |
hasIt ifTrue:[list add:#inet6]. |
|
1574 |
||
1575 |
%{ |
|
1576 |
#ifdef AF_APPLETALK |
|
1577 |
hasIt = true; |
|
1578 |
#else |
|
1579 |
hasIt = false; |
|
1580 |
#endif |
|
1581 |
%}. |
|
1582 |
hasIt ifTrue:[list add:#appletalk]. |
|
1583 |
||
1584 |
%{ |
|
1585 |
#ifdef AF_DECnet |
|
1586 |
hasIt = true; |
|
1587 |
#else |
|
1588 |
hasIt = false; |
|
1589 |
#endif |
|
1590 |
%}. |
|
1591 |
hasIt ifTrue:[list add:#decnet]. |
|
1592 |
||
1593 |
%{ |
|
1594 |
#ifdef AF_NS |
|
1595 |
hasIt = true; |
|
1596 |
#else |
|
1597 |
hasIt = false; |
|
1598 |
#endif |
|
1599 |
%}. |
|
1600 |
hasIt ifTrue:[list add:#xns]. |
|
1601 |
||
1602 |
%{ |
|
1603 |
#ifdef AF_X26 |
|
1604 |
hasIt = true; |
|
1605 |
#else |
|
1606 |
hasIt = false; |
|
1607 |
#endif |
|
1608 |
%}. |
|
1609 |
hasIt ifTrue:[list add:#x25]. |
|
1610 |
||
1611 |
%{ |
|
1612 |
#ifdef AF_SNA |
|
1613 |
hasIt = true; |
|
1614 |
#else |
|
1615 |
hasIt = false; |
|
1616 |
#endif |
|
1617 |
%}. |
|
1618 |
hasIt ifTrue:[list add:#sna]. |
|
1619 |
||
1620 |
%{ |
|
1621 |
#ifdef AF_RAW |
|
1622 |
hasIt = true; |
|
1623 |
#else |
|
1624 |
hasIt = false; |
|
1625 |
#endif |
|
1626 |
%}. |
|
1627 |
hasIt ifTrue:[list add:#raw]. |
|
1628 |
||
1629 |
%{ |
|
1630 |
#ifdef AF_ISO |
|
1631 |
hasIt = true; |
|
1632 |
#else |
|
1633 |
hasIt = false; |
|
1634 |
#endif |
|
1635 |
%}. |
|
1636 |
hasIt ifTrue:[list add:#iso]. |
|
1637 |
||
1638 |
%{ |
|
1639 |
#ifdef AF_NETBIOS |
|
1640 |
hasIt = true; |
|
1641 |
#else |
|
1642 |
hasIt = false; |
|
1643 |
#endif |
|
1644 |
%}. |
|
1645 |
hasIt ifTrue:[list add:#netbios]. |
|
1646 |
||
1647 |
%{ |
|
1648 |
#ifdef AF_IPX |
|
1649 |
hasIt = true; |
|
1650 |
#else |
|
1651 |
hasIt = false; |
|
1652 |
#endif |
|
1653 |
%}. |
|
1654 |
hasIt ifTrue:[list add:#ipx]. |
|
1655 |
||
1656 |
%{ |
|
1657 |
#ifdef AF_AX25 |
|
1658 |
hasIt = true; |
|
1659 |
#else |
|
1660 |
hasIt = false; |
|
1661 |
#endif |
|
1662 |
%}. |
|
1663 |
hasIt ifTrue:[list add:#ax25]. |
|
1664 |
||
1665 |
%{ |
|
1666 |
#ifdef AF_NETROM |
|
1667 |
hasIt = true; |
|
1668 |
#else |
|
1669 |
hasIt = false; |
|
1670 |
#endif |
|
1671 |
%}. |
|
1672 |
hasIt ifTrue:[list add:#netrom]. |
|
1673 |
||
1674 |
%{ |
|
1675 |
#ifdef AF_BRIDGE |
|
1676 |
hasIt = true; |
|
1677 |
#else |
|
1678 |
hasIt = false; |
|
1679 |
#endif |
|
1680 |
%}. |
|
1681 |
hasIt ifTrue:[list add:#bridge]. |
|
1682 |
||
571 | 1683 |
%{ |
1684 |
#ifdef AF_BSC |
|
1685 |
hasIt = true; |
|
1686 |
#else |
|
1687 |
hasIt = false; |
|
1688 |
#endif |
|
1689 |
%}. |
|
1690 |
hasIt ifTrue:[list add:#bsc]. |
|
1691 |
||
1692 |
||
532 | 1693 |
^ list |
1694 |
||
1695 |
" |
|
1696 |
Socket supportedProtocolFamilies |
|
1697 |
" |
|
559
61012867ebed
cleanup if #connect is interrupted
Claus Gittinger <cg@exept.de>
parents:
551
diff
changeset
|
1698 |
! |
61012867ebed
cleanup if #connect is interrupted
Claus Gittinger <cg@exept.de>
parents:
551
diff
changeset
|
1699 |
|
61012867ebed
cleanup if #connect is interrupted
Claus Gittinger <cg@exept.de>
parents:
551
diff
changeset
|
1700 |
typeOfProtocol:aProtocol |
61012867ebed
cleanup if #connect is interrupted
Claus Gittinger <cg@exept.de>
parents:
551
diff
changeset
|
1701 |
"given a protocols name (i.e. tcp, udp etc) return the connection type. |
61012867ebed
cleanup if #connect is interrupted
Claus Gittinger <cg@exept.de>
parents:
551
diff
changeset
|
1702 |
This method needs more ... - or is there a way to get this from the system ?" |
61012867ebed
cleanup if #connect is interrupted
Claus Gittinger <cg@exept.de>
parents:
551
diff
changeset
|
1703 |
|
61012867ebed
cleanup if #connect is interrupted
Claus Gittinger <cg@exept.de>
parents:
551
diff
changeset
|
1704 |
(aProtocol = 'tcp') ifTrue:[^ #stream]. |
61012867ebed
cleanup if #connect is interrupted
Claus Gittinger <cg@exept.de>
parents:
551
diff
changeset
|
1705 |
(aProtocol = 'udp') ifTrue:[^ #datagram]. |
61012867ebed
cleanup if #connect is interrupted
Claus Gittinger <cg@exept.de>
parents:
551
diff
changeset
|
1706 |
(aProtocol = 'ip') ifTrue:[^ #raw]. |
61012867ebed
cleanup if #connect is interrupted
Claus Gittinger <cg@exept.de>
parents:
551
diff
changeset
|
1707 |
" |
61012867ebed
cleanup if #connect is interrupted
Claus Gittinger <cg@exept.de>
parents:
551
diff
changeset
|
1708 |
unix domain |
61012867ebed
cleanup if #connect is interrupted
Claus Gittinger <cg@exept.de>
parents:
551
diff
changeset
|
1709 |
" |
61012867ebed
cleanup if #connect is interrupted
Claus Gittinger <cg@exept.de>
parents:
551
diff
changeset
|
1710 |
(aProtocol = 'ud') ifTrue:[^ #stream]. |
61012867ebed
cleanup if #connect is interrupted
Claus Gittinger <cg@exept.de>
parents:
551
diff
changeset
|
1711 |
" |
61012867ebed
cleanup if #connect is interrupted
Claus Gittinger <cg@exept.de>
parents:
551
diff
changeset
|
1712 |
add x25 stuff (if any) here ... |
61012867ebed
cleanup if #connect is interrupted
Claus Gittinger <cg@exept.de>
parents:
551
diff
changeset
|
1713 |
" |
61012867ebed
cleanup if #connect is interrupted
Claus Gittinger <cg@exept.de>
parents:
551
diff
changeset
|
1714 |
" |
61012867ebed
cleanup if #connect is interrupted
Claus Gittinger <cg@exept.de>
parents:
551
diff
changeset
|
1715 |
add appletalk stuff (if any) here ... |
61012867ebed
cleanup if #connect is interrupted
Claus Gittinger <cg@exept.de>
parents:
551
diff
changeset
|
1716 |
" |
61012867ebed
cleanup if #connect is interrupted
Claus Gittinger <cg@exept.de>
parents:
551
diff
changeset
|
1717 |
" |
61012867ebed
cleanup if #connect is interrupted
Claus Gittinger <cg@exept.de>
parents:
551
diff
changeset
|
1718 |
add other stuff (if any) here ... |
61012867ebed
cleanup if #connect is interrupted
Claus Gittinger <cg@exept.de>
parents:
551
diff
changeset
|
1719 |
" |
61012867ebed
cleanup if #connect is interrupted
Claus Gittinger <cg@exept.de>
parents:
551
diff
changeset
|
1720 |
^ nil |
61012867ebed
cleanup if #connect is interrupted
Claus Gittinger <cg@exept.de>
parents:
551
diff
changeset
|
1721 |
|
61012867ebed
cleanup if #connect is interrupted
Claus Gittinger <cg@exept.de>
parents:
551
diff
changeset
|
1722 |
" |
61012867ebed
cleanup if #connect is interrupted
Claus Gittinger <cg@exept.de>
parents:
551
diff
changeset
|
1723 |
Socket typeOfProtocol:'tcp' |
61012867ebed
cleanup if #connect is interrupted
Claus Gittinger <cg@exept.de>
parents:
551
diff
changeset
|
1724 |
Socket typeOfProtocol:'ucp' |
61012867ebed
cleanup if #connect is interrupted
Claus Gittinger <cg@exept.de>
parents:
551
diff
changeset
|
1725 |
Socket typeOfProtocol:(Socket protocolOfService:'nntp') |
61012867ebed
cleanup if #connect is interrupted
Claus Gittinger <cg@exept.de>
parents:
551
diff
changeset
|
1726 |
Socket typeOfProtocol:(Socket protocolOfService:'echo') |
61012867ebed
cleanup if #connect is interrupted
Claus Gittinger <cg@exept.de>
parents:
551
diff
changeset
|
1727 |
" |
28 | 1728 |
! ! |
1729 |
||
126 | 1730 |
!Socket methodsFor:'ST-80 mimicri'! |
28 | 1731 |
|
126 | 1732 |
errorReporter |
1733 |
^ self |
|
28 | 1734 |
! |
1735 |
||
126 | 1736 |
notReadySignal |
1737 |
"for now - this is not yet raised" |
|
71 | 1738 |
|
126 | 1739 |
^ Signal new |
486 | 1740 |
! |
1741 |
||
576 | 1742 |
readAppendStream |
1743 |
"ST-80 compatibility" |
|
1744 |
^ self |
|
1745 |
! |
|
1746 |
||
486 | 1747 |
readStream |
1748 |
"ST-80 mimicry. |
|
1749 |
In ST-80, socket is not a stream, but referes to one. |
|
1750 |
ST-80 code therefore uses 'Socket readStream' to access |
|
1751 |
the actual stream. This method returns the receiver, for transparency" |
|
1752 |
||
1753 |
^ self |
|
1754 |
||
1755 |
"Created: 24.1.1997 / 23:52:57 / cg" |
|
1756 |
! |
|
1757 |
||
576 | 1758 |
shutdown:how |
1759 |
"ST-80 compatibility" |
|
1760 |
||
1761 |
self shutDown |
|
1762 |
! |
|
1763 |
||
486 | 1764 |
writeStream |
1765 |
"ST-80 mimicry. |
|
1766 |
In ST-80, socket is not a stream, but referes to one. |
|
1767 |
ST-80 code therefore uses 'Socket writeStream' to access |
|
1768 |
the actual stream. This method returns the receiver, for transparency" |
|
1769 |
||
1770 |
^ self |
|
1771 |
||
1772 |
"Created: 24.1.1997 / 10:34:35 / cg" |
|
1773 |
"Modified: 24.1.1997 / 23:52:52 / cg" |
|
71 | 1774 |
! ! |
1775 |
||
126 | 1776 |
!Socket methodsFor:'datagram transmission'! |
28 | 1777 |
|
126 | 1778 |
receiveFrom:anAddressBuffer buffer:aDataBuffer |
1779 |
"receive datagramm data - put address of originating host into |
|
1780 |
anAddressBuffer, data into aBuffer. |
|
1781 |
Both must be ByteArray-like. The addressBuffer must |
|
1782 |
provide space for a valid address for my domain (i.e. for inet, a 4-byte byteArray). |
|
1783 |
Return the number of bytes received, or a negative number on error. |
|
1784 |
On error, the unix error code is left in the lastErrorNumber |
|
1785 |
instance variable." |
|
28 | 1786 |
|
126 | 1787 |
^ self receiveFrom:anAddressBuffer buffer:aDataBuffer start:1 for:(aDataBuffer size) |
99
7d016cc30052
fixed & moved pingWalk from SNMPSession to here;
Claus Gittinger <cg@exept.de>
parents:
98
diff
changeset
|
1788 |
! |
7d016cc30052
fixed & moved pingWalk from SNMPSession to here;
Claus Gittinger <cg@exept.de>
parents:
98
diff
changeset
|
1789 |
|
126 | 1790 |
receiveFrom:anAddressBuffer buffer:aDataBuffer start:startIndex for:nBytes |
1791 |
"receive datagramm data - put address of originating host into |
|
1792 |
anAddressBuffer, data into aBuffer. For ST-80 compatibility, |
|
1793 |
the addressBuffer may be a non-ByteArray; then, it must understand |
|
1794 |
the addressBytes-message (i.e. be a SocketAddress instance). |
|
1795 |
Return the number of bytes received, or a negative number on error. |
|
1796 |
On error, the unix error code is left in the lastErrorNumber |
|
513
b8042ff0f82c
udp receive: translate received address according to the domain
Claus Gittinger <cg@exept.de>
parents:
511
diff
changeset
|
1797 |
instance variable. |
b8042ff0f82c
udp receive: translate received address according to the domain
Claus Gittinger <cg@exept.de>
parents:
511
diff
changeset
|
1798 |
The thread blocks until data arrives - you may want to wait before |
b8042ff0f82c
udp receive: translate received address according to the domain
Claus Gittinger <cg@exept.de>
parents:
511
diff
changeset
|
1799 |
receiving, using #readWait or #readWaitWithTimeout:." |
b8042ff0f82c
udp receive: translate received address according to the domain
Claus Gittinger <cg@exept.de>
parents:
511
diff
changeset
|
1800 |
|
126 | 1801 |
|
1802 |
|addrBytes addrLen nReceived| |
|
28 | 1803 |
|
126 | 1804 |
addrBytes := ByteArray new:100. |
1805 |
%{ |
|
418 | 1806 |
#ifndef NO_SOCKET |
513
b8042ff0f82c
udp receive: translate received address according to the domain
Claus Gittinger <cg@exept.de>
parents:
511
diff
changeset
|
1807 |
OBJ oClass, myDomain; |
217 | 1808 |
OBJ fp = __INST(filePointer); |
126 | 1809 |
int nInstVars, nInstBytes, objSize; |
1810 |
int sock; |
|
513
b8042ff0f82c
udp receive: translate received address according to the domain
Claus Gittinger <cg@exept.de>
parents:
511
diff
changeset
|
1811 |
union { |
526 | 1812 |
# ifdef AF_INET |
530
067797c15b77
added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents:
529
diff
changeset
|
1813 |
struct sockaddr_in in; |
067797c15b77
added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents:
529
diff
changeset
|
1814 |
# endif |
067797c15b77
added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents:
529
diff
changeset
|
1815 |
# ifdef AF_INET6 |
067797c15b77
added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents:
529
diff
changeset
|
1816 |
struct sockaddr_in6 in6; |
526 | 1817 |
# endif |
1818 |
# ifdef AF_UNIX |
|
1819 |
struct sockaddr_un un; |
|
1820 |
# endif |
|
1821 |
# ifdef AF_APPLETALK |
|
1822 |
struct sockaddr_at at; |
|
1823 |
# endif |
|
513
b8042ff0f82c
udp receive: translate received address according to the domain
Claus Gittinger <cg@exept.de>
parents:
511
diff
changeset
|
1824 |
} sa; |
126 | 1825 |
int alen; |
1826 |
int n; |
|
1827 |
char *cp; |
|
1828 |
int flags = 0; |
|
1829 |
||
1830 |
if (fp != nil) { |
|
524
8287da54eccf
more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents:
513
diff
changeset
|
1831 |
sock = fileno(__FILEVal(fp)); |
8287da54eccf
more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents:
513
diff
changeset
|
1832 |
|
8287da54eccf
more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents:
513
diff
changeset
|
1833 |
oClass = __Class(aDataBuffer); |
8287da54eccf
more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents:
513
diff
changeset
|
1834 |
switch (_intVal(_ClassInstPtr(oClass)->c_flags) & ARRAYMASK) { |
8287da54eccf
more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents:
513
diff
changeset
|
1835 |
case BYTEARRAY: |
8287da54eccf
more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents:
513
diff
changeset
|
1836 |
case WORDARRAY: |
8287da54eccf
more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents:
513
diff
changeset
|
1837 |
case LONGARRAY: |
8287da54eccf
more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents:
513
diff
changeset
|
1838 |
case FLOATARRAY: |
8287da54eccf
more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents:
513
diff
changeset
|
1839 |
case DOUBLEARRAY: |
8287da54eccf
more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents:
513
diff
changeset
|
1840 |
break; |
8287da54eccf
more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents:
513
diff
changeset
|
1841 |
default: |
8287da54eccf
more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents:
513
diff
changeset
|
1842 |
goto bad; |
8287da54eccf
more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents:
513
diff
changeset
|
1843 |
} |
8287da54eccf
more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents:
513
diff
changeset
|
1844 |
|
8287da54eccf
more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents:
513
diff
changeset
|
1845 |
nInstVars = _intVal(_ClassInstPtr(oClass)->c_ninstvars); |
8287da54eccf
more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents:
513
diff
changeset
|
1846 |
nInstBytes = OHDR_SIZE + nInstVars * sizeof(OBJ); |
8287da54eccf
more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents:
513
diff
changeset
|
1847 |
objSize = _Size(aDataBuffer) - nInstBytes; |
8287da54eccf
more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents:
513
diff
changeset
|
1848 |
cp = (char *)__InstPtr(aDataBuffer) + nInstBytes; |
8287da54eccf
more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents:
513
diff
changeset
|
1849 |
if (__isSmallInteger(startIndex)) { |
8287da54eccf
more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents:
513
diff
changeset
|
1850 |
cp += __intVal(startIndex); |
8287da54eccf
more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents:
513
diff
changeset
|
1851 |
objSize -= __intVal(startIndex); |
8287da54eccf
more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents:
513
diff
changeset
|
1852 |
} |
8287da54eccf
more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents:
513
diff
changeset
|
1853 |
if (__isSmallInteger(nBytes)) { |
8287da54eccf
more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents:
513
diff
changeset
|
1854 |
if (__intVal(nBytes) < objSize) { |
8287da54eccf
more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents:
513
diff
changeset
|
1855 |
objSize = __intVal(nBytes); |
8287da54eccf
more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents:
513
diff
changeset
|
1856 |
} |
8287da54eccf
more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents:
513
diff
changeset
|
1857 |
} |
8287da54eccf
more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents:
513
diff
changeset
|
1858 |
|
8287da54eccf
more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents:
513
diff
changeset
|
1859 |
__BEGIN_INTERRUPTABLE__ |
8287da54eccf
more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents:
513
diff
changeset
|
1860 |
do { |
8287da54eccf
more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents:
513
diff
changeset
|
1861 |
if (addrBytes == nil) { |
8287da54eccf
more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents:
513
diff
changeset
|
1862 |
n = recvfrom(sock, cp, objSize, flags, (struct sockaddr *) 0, 0); |
8287da54eccf
more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents:
513
diff
changeset
|
1863 |
} else { |
8287da54eccf
more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents:
513
diff
changeset
|
1864 |
n = recvfrom(sock, cp, objSize, flags, (struct sockaddr *) &sa, &alen); |
8287da54eccf
more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents:
513
diff
changeset
|
1865 |
} |
8287da54eccf
more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents:
513
diff
changeset
|
1866 |
} while ((n < 0) && (errno == EINTR)); |
8287da54eccf
more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents:
513
diff
changeset
|
1867 |
__END_INTERRUPTABLE__ |
8287da54eccf
more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents:
513
diff
changeset
|
1868 |
|
8287da54eccf
more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents:
513
diff
changeset
|
1869 |
if (n >= 0) { |
8287da54eccf
more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents:
513
diff
changeset
|
1870 |
if (addrBytes != nil) { |
8287da54eccf
more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents:
513
diff
changeset
|
1871 |
oClass = __Class(addrBytes); |
8287da54eccf
more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents:
513
diff
changeset
|
1872 |
if ((_intVal(_ClassInstPtr(oClass)->c_flags) & ARRAYMASK) != BYTEARRAY) |
8287da54eccf
more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents:
513
diff
changeset
|
1873 |
goto bad; |
8287da54eccf
more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents:
513
diff
changeset
|
1874 |
nInstVars = _intVal(_ClassInstPtr(oClass)->c_ninstvars); |
8287da54eccf
more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents:
513
diff
changeset
|
1875 |
nInstBytes = OHDR_SIZE + nInstVars * sizeof(OBJ); |
8287da54eccf
more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents:
513
diff
changeset
|
1876 |
objSize = _Size(addrBytes) - nInstBytes; |
8287da54eccf
more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents:
513
diff
changeset
|
1877 |
cp = (char *)__InstPtr(addrBytes) + nInstBytes; |
8287da54eccf
more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents:
513
diff
changeset
|
1878 |
if (objSize < alen) |
8287da54eccf
more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents:
513
diff
changeset
|
1879 |
goto bad; |
8287da54eccf
more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents:
513
diff
changeset
|
1880 |
|
8287da54eccf
more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents:
513
diff
changeset
|
1881 |
myDomain = __INST(domain); |
525 | 1882 |
|
1883 |
/* |
|
1884 |
* extract the datagrams address |
|
1885 |
*/ |
|
513
b8042ff0f82c
udp receive: translate received address according to the domain
Claus Gittinger <cg@exept.de>
parents:
511
diff
changeset
|
1886 |
# ifdef AF_UNIX |
533
ced9950b551f
added query about which protocols are supported
Claus Gittinger <cg@exept.de>
parents:
532
diff
changeset
|
1887 |
if (myDomain == @symbol(unix)) { |
ced9950b551f
added query about which protocols are supported
Claus Gittinger <cg@exept.de>
parents:
532
diff
changeset
|
1888 |
cp[0] = (sa.in.sin_addr.s_addr >> 24) & 0xFF; |
ced9950b551f
added query about which protocols are supported
Claus Gittinger <cg@exept.de>
parents:
532
diff
changeset
|
1889 |
cp[2] = (sa.in.sin_addr.s_addr >> 16) & 0xFF; |
ced9950b551f
added query about which protocols are supported
Claus Gittinger <cg@exept.de>
parents:
532
diff
changeset
|
1890 |
cp[3] = (sa.in.sin_addr.s_addr >> 8) & 0xFF; |
ced9950b551f
added query about which protocols are supported
Claus Gittinger <cg@exept.de>
parents:
532
diff
changeset
|
1891 |
cp[4] = (sa.in.sin_addr.s_addr >> 0) & 0xFF; |
ced9950b551f
added query about which protocols are supported
Claus Gittinger <cg@exept.de>
parents:
532
diff
changeset
|
1892 |
alen = 4; |
ced9950b551f
added query about which protocols are supported
Claus Gittinger <cg@exept.de>
parents:
532
diff
changeset
|
1893 |
} |
525 | 1894 |
# endif /* AF_UNIX */ |
1895 |
||
524
8287da54eccf
more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents:
513
diff
changeset
|
1896 |
/* |
8287da54eccf
more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents:
513
diff
changeset
|
1897 |
* XXXX add addressing stuff for other domains here ... |
8287da54eccf
more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents:
513
diff
changeset
|
1898 |
*/ |
513
b8042ff0f82c
udp receive: translate received address according to the domain
Claus Gittinger <cg@exept.de>
parents:
511
diff
changeset
|
1899 |
# ifdef AF_X25 |
524
8287da54eccf
more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents:
513
diff
changeset
|
1900 |
if (myDomain == @symbol(x25)) { |
8287da54eccf
more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents:
513
diff
changeset
|
1901 |
} |
513
b8042ff0f82c
udp receive: translate received address according to the domain
Claus Gittinger <cg@exept.de>
parents:
511
diff
changeset
|
1902 |
# endif |
b8042ff0f82c
udp receive: translate received address according to the domain
Claus Gittinger <cg@exept.de>
parents:
511
diff
changeset
|
1903 |
# ifdef AF_NS |
524
8287da54eccf
more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents:
513
diff
changeset
|
1904 |
if (myDomain == @symbol(ns)) { |
8287da54eccf
more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents:
513
diff
changeset
|
1905 |
} |
513
b8042ff0f82c
udp receive: translate received address according to the domain
Claus Gittinger <cg@exept.de>
parents:
511
diff
changeset
|
1906 |
# endif |
b8042ff0f82c
udp receive: translate received address according to the domain
Claus Gittinger <cg@exept.de>
parents:
511
diff
changeset
|
1907 |
# ifdef AF_APPLETALK |
524
8287da54eccf
more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents:
513
diff
changeset
|
1908 |
if (myDomain == @symbol(appletalk)) { |
8287da54eccf
more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents:
513
diff
changeset
|
1909 |
} |
513
b8042ff0f82c
udp receive: translate received address according to the domain
Claus Gittinger <cg@exept.de>
parents:
511
diff
changeset
|
1910 |
# endif |
b8042ff0f82c
udp receive: translate received address according to the domain
Claus Gittinger <cg@exept.de>
parents:
511
diff
changeset
|
1911 |
# ifdef AF_SNA |
524
8287da54eccf
more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents:
513
diff
changeset
|
1912 |
if (myDomain == @symbol(sna)) { |
8287da54eccf
more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents:
513
diff
changeset
|
1913 |
} |
513
b8042ff0f82c
udp receive: translate received address according to the domain
Claus Gittinger <cg@exept.de>
parents:
511
diff
changeset
|
1914 |
# endif |
b8042ff0f82c
udp receive: translate received address according to the domain
Claus Gittinger <cg@exept.de>
parents:
511
diff
changeset
|
1915 |
# ifdef AF_NS |
524
8287da54eccf
more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents:
513
diff
changeset
|
1916 |
if (myDomain == @symbol(xns)) { |
8287da54eccf
more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents:
513
diff
changeset
|
1917 |
} |
513
b8042ff0f82c
udp receive: translate received address according to the domain
Claus Gittinger <cg@exept.de>
parents:
511
diff
changeset
|
1918 |
# endif |
b8042ff0f82c
udp receive: translate received address according to the domain
Claus Gittinger <cg@exept.de>
parents:
511
diff
changeset
|
1919 |
# ifdef AF_RAW |
524
8287da54eccf
more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents:
513
diff
changeset
|
1920 |
if (myDomain == @symbol(raw)) { |
8287da54eccf
more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents:
513
diff
changeset
|
1921 |
} |
8287da54eccf
more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents:
513
diff
changeset
|
1922 |
# endif |
8287da54eccf
more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents:
513
diff
changeset
|
1923 |
# ifdef AF_ISO |
8287da54eccf
more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents:
513
diff
changeset
|
1924 |
if (myDomain == @symbol(iso)) { |
8287da54eccf
more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents:
513
diff
changeset
|
1925 |
} |
8287da54eccf
more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents:
513
diff
changeset
|
1926 |
# endif |
8287da54eccf
more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents:
513
diff
changeset
|
1927 |
# ifdef AF_DECnet |
8287da54eccf
more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents:
513
diff
changeset
|
1928 |
if (myDomain == @symbol(decnet)) { |
8287da54eccf
more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents:
513
diff
changeset
|
1929 |
} |
513
b8042ff0f82c
udp receive: translate received address according to the domain
Claus Gittinger <cg@exept.de>
parents:
511
diff
changeset
|
1930 |
# endif |
524
8287da54eccf
more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents:
513
diff
changeset
|
1931 |
# ifdef AF_NETBIOS |
530
067797c15b77
added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents:
529
diff
changeset
|
1932 |
if (myDomain == @symbol(netbios)) { |
067797c15b77
added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents:
529
diff
changeset
|
1933 |
} |
067797c15b77
added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents:
529
diff
changeset
|
1934 |
# endif |
067797c15b77
added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents:
529
diff
changeset
|
1935 |
# if defined(AF_IPX) |
067797c15b77
added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents:
529
diff
changeset
|
1936 |
if (myDomain == @symbol(ipx)) { |
067797c15b77
added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents:
529
diff
changeset
|
1937 |
} |
067797c15b77
added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents:
529
diff
changeset
|
1938 |
# endif |
067797c15b77
added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents:
529
diff
changeset
|
1939 |
# if defined(AF_BRIDGE) |
067797c15b77
added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents:
529
diff
changeset
|
1940 |
if (myDomain == @symbol(bridge)) { |
524
8287da54eccf
more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents:
513
diff
changeset
|
1941 |
} |
8287da54eccf
more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents:
513
diff
changeset
|
1942 |
# endif |
571 | 1943 |
# if defined(AF_BSC) |
1944 |
if (myDomain == @symbol(bsc)) { |
|
1945 |
} |
|
1946 |
# endif |
|
524
8287da54eccf
more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents:
513
diff
changeset
|
1947 |
# if defined(AF_CCITT) && (AF_CCITT != AF_X25) |
8287da54eccf
more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents:
513
diff
changeset
|
1948 |
if (myDomain == @symbol(ccitt)) { |
8287da54eccf
more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents:
513
diff
changeset
|
1949 |
} |
8287da54eccf
more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents:
513
diff
changeset
|
1950 |
# endif |
8287da54eccf
more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents:
513
diff
changeset
|
1951 |
|
8287da54eccf
more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents:
513
diff
changeset
|
1952 |
addrLen = __MKSMALLINT(alen); |
8287da54eccf
more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents:
513
diff
changeset
|
1953 |
} |
8287da54eccf
more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents:
513
diff
changeset
|
1954 |
} |
8287da54eccf
more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents:
513
diff
changeset
|
1955 |
if (n < 0) { |
8287da54eccf
more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents:
513
diff
changeset
|
1956 |
__INST(lastErrorNumber) = __MKSMALLINT(errno); |
8287da54eccf
more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents:
513
diff
changeset
|
1957 |
} |
8287da54eccf
more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents:
513
diff
changeset
|
1958 |
nReceived = __MKSMALLINT(n); |
126 | 1959 |
} |
418 | 1960 |
#endif |
126 | 1961 |
bad: ; |
1962 |
%}. |
|
1963 |
nReceived notNil ifTrue:[ |
|
524
8287da54eccf
more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents:
513
diff
changeset
|
1964 |
nReceived < 0 ifTrue:[ |
8287da54eccf
more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents:
513
diff
changeset
|
1965 |
'Socket [warning]: ' infoPrint. |
8287da54eccf
more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents:
513
diff
changeset
|
1966 |
(OperatingSystem errorTextForNumber:lastErrorNumber) infoPrintCR. |
8287da54eccf
more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents:
513
diff
changeset
|
1967 |
]. |
8287da54eccf
more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents:
513
diff
changeset
|
1968 |
addrLen notNil ifTrue:[ |
8287da54eccf
more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents:
513
diff
changeset
|
1969 |
anAddressBuffer class isBytes ifTrue:[ |
8287da54eccf
more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents:
513
diff
changeset
|
1970 |
anAddressBuffer replaceFrom:1 to:addrLen with:addrBytes |
8287da54eccf
more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents:
513
diff
changeset
|
1971 |
] ifFalse:[ |
8287da54eccf
more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents:
513
diff
changeset
|
1972 |
"/ can be SocketAddress for ST-80 compatibility |
8287da54eccf
more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents:
513
diff
changeset
|
1973 |
anAddressBuffer hostAddress:(addrBytes copyTo:addrLen) |
8287da54eccf
more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents:
513
diff
changeset
|
1974 |
]. |
8287da54eccf
more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents:
513
diff
changeset
|
1975 |
]. |
8287da54eccf
more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents:
513
diff
changeset
|
1976 |
^ nReceived |
28 | 1977 |
]. |
116
7789fb1c9fa2
more UD socket fixes (at least client side seems to work now)
Claus Gittinger <cg@exept.de>
parents:
115
diff
changeset
|
1978 |
" |
126 | 1979 |
arrive here if you try to receive into an invalid buffer |
1980 |
(i.e. not ByteArray-like), |
|
1981 |
or if the addressBuffer is nonNil AND not a ByteArray/String |
|
1982 |
or if the addressBuffer is nonNil AND too small. |
|
116
7789fb1c9fa2
more UD socket fixes (at least client side seems to work now)
Claus Gittinger <cg@exept.de>
parents:
115
diff
changeset
|
1983 |
" |
126 | 1984 |
self primitiveFailed |
116
7789fb1c9fa2
more UD socket fixes (at least client side seems to work now)
Claus Gittinger <cg@exept.de>
parents:
115
diff
changeset
|
1985 |
! |
7789fb1c9fa2
more UD socket fixes (at least client side seems to work now)
Claus Gittinger <cg@exept.de>
parents:
115
diff
changeset
|
1986 |
|
126 | 1987 |
sendTo:anAddressBuffer buffer:buffer |
1988 |
"send datagramm data - fetch address of destination host from |
|
1989 |
anAddressBuffer, data from aDataBuffer. |
|
1990 |
Both must be ByteArray-like. The bytes in the addressBuffer must |
|
1991 |
be a valid address for my domain (i.e. for inet, a 4-byte byteArray). |
|
1992 |
Return the number of bytes transmitted, or a negative number on error. |
|
1993 |
On error, the unix error code is left in the lastErrorNumber |
|
1994 |
instance variable. |
|
1995 |
Flags is currently ignored; it is there for ST-80 compatibility." |
|
116
7789fb1c9fa2
more UD socket fixes (at least client side seems to work now)
Claus Gittinger <cg@exept.de>
parents:
115
diff
changeset
|
1996 |
|
126 | 1997 |
^ self sendTo:anAddressBuffer buffer:buffer start:1 for:buffer size flags:0 |
116
7789fb1c9fa2
more UD socket fixes (at least client side seems to work now)
Claus Gittinger <cg@exept.de>
parents:
115
diff
changeset
|
1998 |
! |
7789fb1c9fa2
more UD socket fixes (at least client side seems to work now)
Claus Gittinger <cg@exept.de>
parents:
115
diff
changeset
|
1999 |
|
126 | 2000 |
sendTo:anAddressBuffer buffer:aDataBuffer start:startIndex for:count flags:flags |
2001 |
"send datagramm data - fetch address of destination host from |
|
2002 |
anAddressBuffer, data from aDataBuffer starting at startIndex, |
|
2003 |
sending count bytes. |
|
2004 |
Both must be ByteArray-like. The bytes in the addressBuffer must |
|
2005 |
be a valid address for my domain (i.e. for inet, a 4-byte byteArray). |
|
2006 |
Return the number of bytes transmitted, or a negative number on error. |
|
2007 |
On error, the unix error code is left in the lastErrorNumber |
|
2008 |
instance variable." |
|
0 | 2009 |
|
126 | 2010 |
|addrBytes addrLen nReceived portNo| |
93 | 2011 |
|
126 | 2012 |
"/ addressBuffer can be a 6-byte byteArray (last 2 bytes are portNo, msb-first) |
2013 |
"/ or an instance of IPSocketAddress |
|
2014 |
"/ |
|
2015 |
anAddressBuffer class isBytes ifTrue:[ |
|
2016 |
addrBytes := anAddressBuffer copyFrom:1 to:4. |
|
2017 |
portNo := ((anAddressBuffer at:5) bitShift:8) |
|
2018 |
+ (anAddressBuffer at:6). |
|
2019 |
] ifFalse:[ |
|
2020 |
addrBytes := anAddressBuffer hostAddress. |
|
2021 |
portNo := anAddressBuffer port. |
|
28 | 2022 |
]. |
0 | 2023 |
%{ |
418 | 2024 |
#ifndef NO_SOCKET |
126 | 2025 |
OBJ oClass; |
217 | 2026 |
OBJ fp = __INST(filePointer); |
126 | 2027 |
int nInstVars, nInstBytes, objSize; |
2028 |
int sock; |
|
526 | 2029 |
union { |
2030 |
# ifdef AF_INET |
|
530
067797c15b77
added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents:
529
diff
changeset
|
2031 |
struct sockaddr_in in; |
067797c15b77
added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents:
529
diff
changeset
|
2032 |
# endif |
067797c15b77
added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents:
529
diff
changeset
|
2033 |
# ifdef AF_INET6 |
067797c15b77
added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents:
529
diff
changeset
|
2034 |
struct sockaddr_in6 in6; |
526 | 2035 |
# endif |
2036 |
# ifdef AF_UNIX |
|
2037 |
struct sockaddr_un un; |
|
2038 |
# endif |
|
2039 |
# ifdef AF_APPLETALK |
|
2040 |
struct sockaddr_at at; |
|
2041 |
# endif |
|
2042 |
} sa; |
|
126 | 2043 |
struct sockaddr *saPtr = (struct sockaddr *)&sa; |
2044 |
int alen = sizeof(sa); |
|
2045 |
int n; |
|
2046 |
char *cp; |
|
2047 |
int _flags = 0; |
|
2048 |
int offs, nBytes; |
|
2049 |
unsigned long norder; |
|
21 | 2050 |
|
126 | 2051 |
_flags = __longIntVal(flags); |
2052 |
||
2053 |
if ((fp != nil) |
|
2054 |
&& __isSmallInteger(startIndex) |
|
2055 |
&& __isSmallInteger(count)) { |
|
2056 |
sock = fileno(__FILEVal(fp)); |
|
0 | 2057 |
|
525 | 2058 |
if (addrBytes == nil) { |
2059 |
alen = 0; |
|
2060 |
saPtr = (struct sockaddr *)0; |
|
2061 |
} else { |
|
126 | 2062 |
if (! __isByteArray(addrBytes)) goto bad; |
525 | 2063 |
|
551
b2d6e4d86e77
avoid warnings (signed char vs. unsigned char)
Claus Gittinger <cg@exept.de>
parents:
537
diff
changeset
|
2064 |
cp = (char *)__ByteArrayInstPtr(addrBytes)->ba_element; |
126 | 2065 |
n = __byteArraySize(addrBytes); |
2066 |
if (alen < n) n = alen; |
|
526 | 2067 |
#ifdef DGRAM_DEBUG |
2068 |
printf("address is %d bytes ... %d.%d.%d.%d", n, cp[0], cp[1], cp[2], cp[3]); |
|
2069 |
#endif |
|
2070 |
bcopy(cp, &sa.in.sin_addr.s_addr, n); |
|
525 | 2071 |
#ifdef AF_INET |
526 | 2072 |
if (__INST(domain) == @symbol(inet)) { |
533
ced9950b551f
added query about which protocols are supported
Claus Gittinger <cg@exept.de>
parents:
532
diff
changeset
|
2073 |
sa.in.sin_family = AF_INET; |
ced9950b551f
added query about which protocols are supported
Claus Gittinger <cg@exept.de>
parents:
532
diff
changeset
|
2074 |
sa.in.sin_port = htons((u_short) __intVal(portNo)); |
526 | 2075 |
} |
2076 |
#endif |
|
530
067797c15b77
added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents:
529
diff
changeset
|
2077 |
#ifdef AF_INET6 |
533
ced9950b551f
added query about which protocols are supported
Claus Gittinger <cg@exept.de>
parents:
532
diff
changeset
|
2078 |
if (__INST(domain) == @symbol(inet6)) { |
ced9950b551f
added query about which protocols are supported
Claus Gittinger <cg@exept.de>
parents:
532
diff
changeset
|
2079 |
sa.in6.sin6_family = AF_INET; |
ced9950b551f
added query about which protocols are supported
Claus Gittinger <cg@exept.de>
parents:
532
diff
changeset
|
2080 |
sa.in6.sin6_port = htons((u_short) __intVal(portNo)); |
ced9950b551f
added query about which protocols are supported
Claus Gittinger <cg@exept.de>
parents:
532
diff
changeset
|
2081 |
} |
530
067797c15b77
added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents:
529
diff
changeset
|
2082 |
#endif |
526 | 2083 |
#ifdef AF_APPLETALK |
2084 |
if (__INST(domain) == @symbol(appletalk)) { |
|
533
ced9950b551f
added query about which protocols are supported
Claus Gittinger <cg@exept.de>
parents:
532
diff
changeset
|
2085 |
sa.at.sat_family = AF_INET; |
ced9950b551f
added query about which protocols are supported
Claus Gittinger <cg@exept.de>
parents:
532
diff
changeset
|
2086 |
sa.at.sat_port = __intVal(portNo); |
ced9950b551f
added query about which protocols are supported
Claus Gittinger <cg@exept.de>
parents:
532
diff
changeset
|
2087 |
} |
526 | 2088 |
#endif |
93 | 2089 |
} |
6 | 2090 |
|
126 | 2091 |
oClass = __Class(aDataBuffer); |
2092 |
switch (_intVal(_ClassInstPtr(oClass)->c_flags) & ARRAYMASK) { |
|
2093 |
case BYTEARRAY: |
|
2094 |
offs = __intVal(startIndex) - 1; |
|
2095 |
break; |
|
2096 |
case WORDARRAY: |
|
2097 |
offs = (__intVal(startIndex) - 1) * sizeof(short); |
|
2098 |
break; |
|
2099 |
case LONGARRAY: |
|
2100 |
offs = (__intVal(startIndex) - 1) * sizeof(long); |
|
2101 |
break; |
|
2102 |
case FLOATARRAY: |
|
2103 |
offs = (__intVal(startIndex) - 1) * sizeof(float); |
|
2104 |
break; |
|
2105 |
case DOUBLEARRAY: |
|
2106 |
offs = (__intVal(startIndex) - 1) * sizeof(double); |
|
2107 |
#ifdef NEED_DOUBLE_ALIGN |
|
2108 |
offs += sizeof(long); |
|
2109 |
#endif |
|
2110 |
break; |
|
2111 |
default: |
|
2112 |
goto bad; |
|
42 | 2113 |
} |
126 | 2114 |
nBytes = __intVal(count); |
71 | 2115 |
|
126 | 2116 |
nInstVars = _intVal(_ClassInstPtr(oClass)->c_ninstvars); |
2117 |
nInstBytes = OHDR_SIZE + nInstVars * sizeof(OBJ); |
|
2118 |
objSize = __qSize(aDataBuffer) - nInstBytes; |
|
217 | 2119 |
cp = (char *)__InstPtr(aDataBuffer) + nInstBytes; |
126 | 2120 |
cp += offs; |
2121 |
if ((offs + nBytes) > objSize) { |
|
526 | 2122 |
#ifdef DGRAM_DEBUG |
2123 |
printf("cut off ...\n"); |
|
2124 |
#endif |
|
126 | 2125 |
nBytes = objSize - offs; |
2126 |
} |
|
0 | 2127 |
|
526 | 2128 |
norder = htonl(sa.in.sin_addr.s_addr); |
2129 |
#ifdef DGRAM_DEBUG |
|
2130 |
printf("sending %d bytes ... to ", nBytes); |
|
2131 |
printf("%d.%d.%d.%d\n", |
|
126 | 2132 |
(norder >> 24) & 0xFF, |
2133 |
(norder >> 16) & 0xFF, |
|
2134 |
(norder >> 8) & 0xFF, |
|
2135 |
norder & 0xFF); |
|
526 | 2136 |
#endif |
0 | 2137 |
|
81 | 2138 |
__BEGIN_INTERRUPTABLE__ |
126 | 2139 |
do { |
2140 |
n = sendto(sock, cp, nBytes, _flags, saPtr, alen); |
|
2141 |
} while ((n < 0) && (errno == EINTR)); |
|
81 | 2142 |
__END_INTERRUPTABLE__ |
0 | 2143 |
|
126 | 2144 |
if (n < 0) { |
217 | 2145 |
__INST(lastErrorNumber) = __MKSMALLINT(errno); |
42 | 2146 |
} |
217 | 2147 |
RETURN (__MKSMALLINT(n)); |
0 | 2148 |
} |
418 | 2149 |
#endif |
126 | 2150 |
bad: ; |
42 | 2151 |
%}. |
2152 |
" |
|
126 | 2153 |
arrive here if you try to send from an invalid buffer |
2154 |
(i.e. not ByteArray-like), |
|
2155 |
or if the addressBuffer is nonNil AND not a ByteArray/String |
|
2156 |
or if the addressBuffer is nonNil AND too small. |
|
42 | 2157 |
" |
126 | 2158 |
self primitiveFailed |
0 | 2159 |
! ! |
2160 |
||
2161 |
!Socket methodsFor:'low level'! |
|
2162 |
||
126 | 2163 |
accept |
2164 |
"create a new TCP socket from accepting on the receiver. |
|
2165 |
This method will suspend the current process if no connection is waiting. |
|
2166 |
For ST-80 compatibility" |
|
2167 |
||
2168 |
|newSock| |
|
2169 |
||
2170 |
newSock := self class new. |
|
2171 |
(newSock acceptOn:self) ifFalse:[^ nil]. |
|
2172 |
^ newSock |
|
2173 |
||
2174 |
" |
|
2175 |
|sock newSock| |
|
2176 |
||
2177 |
sock := Socket provide:8004. |
|
2178 |
sock listenFor:5. |
|
2179 |
newSock := sock accept. |
|
2180 |
" |
|
2181 |
! |
|
2182 |
||
2183 |
acceptOn:aSocket |
|
2184 |
"accept a connection on a server port (created with:'Socket>>onIPPort:') |
|
2185 |
usage is: (Socket basicNew acceptOn:(Socket onIPPort:9999)). |
|
207
e9f6913dc380
split: #accept is nonBlock; the old accept is not called #blockingAccept
Claus Gittinger <cg@exept.de>
parents:
206
diff
changeset
|
2186 |
This method will suspend the current process if no connection is waiting. |
e9f6913dc380
split: #accept is nonBlock; the old accept is not called #blockingAccept
Claus Gittinger <cg@exept.de>
parents:
206
diff
changeset
|
2187 |
Return the true if ok; false if not." |
e9f6913dc380
split: #accept is nonBlock; the old accept is not called #blockingAccept
Claus Gittinger <cg@exept.de>
parents:
206
diff
changeset
|
2188 |
|
208
c3eca2cc16dc
accept: do not wait for input on non-connected socket.
Stefan Vogel <sv@exept.de>
parents:
207
diff
changeset
|
2189 |
aSocket readWait. |
207
e9f6913dc380
split: #accept is nonBlock; the old accept is not called #blockingAccept
Claus Gittinger <cg@exept.de>
parents:
206
diff
changeset
|
2190 |
^ self blockingAcceptOn:aSocket |
126 | 2191 |
|
208
c3eca2cc16dc
accept: do not wait for input on non-connected socket.
Stefan Vogel <sv@exept.de>
parents:
207
diff
changeset
|
2192 |
"Modified: 11.3.1996 / 14:21:31 / stefan" |
8 | 2193 |
! |
2194 |
||
507 | 2195 |
bindAnonymously |
2196 |
^ self |
|
2197 |
bindTo:0 |
|
2198 |
address:nil |
|
509 | 2199 |
reuseAddress:false |
2200 |
! |
|
2201 |
||
2202 |
bindAnonymouslyToAddress:addressString |
|
2203 |
^ self |
|
2204 |
bindTo:0 |
|
2205 |
address:addressString |
|
2206 |
reuseAddress:false |
|
507 | 2207 |
! |
2208 |
||
71 | 2209 |
bindTo:aSocketAddress |
425 | 2210 |
"ST80 compatible bind, expecting a socketAddress argument. |
2211 |
The socketAddress object (an instance of SocketAddress) |
|
2212 |
is supposed to respond to #portOrName and #address requests." |
|
71 | 2213 |
|
2214 |
^ self bindTo:(aSocketAddress portOrName) |
|
2215 |
address:(aSocketAddress address) |
|
425 | 2216 |
reuseAddress:true |
71 | 2217 |
! |
2218 |
||
425 | 2219 |
bindTo:portNrOrNameString address:addressString |
28 | 2220 |
"low level bind - returns true if ok, false otherwise. |
71 | 2221 |
Currently only non-address binding is supported; |
425 | 2222 |
i.e. the address must always be nil. |
71 | 2223 |
|
2224 |
The interpretation of portNrOrName depends on the domain: |
|
116
7789fb1c9fa2
more UD socket fixes (at least client side seems to work now)
Claus Gittinger <cg@exept.de>
parents:
115
diff
changeset
|
2225 |
inet domain uses (4byte) byteArray like internet numbers, |
7789fb1c9fa2
more UD socket fixes (at least client side seems to work now)
Claus Gittinger <cg@exept.de>
parents:
115
diff
changeset
|
2226 |
unix domain uses pathname strings, |
7789fb1c9fa2
more UD socket fixes (at least client side seems to work now)
Claus Gittinger <cg@exept.de>
parents:
115
diff
changeset
|
2227 |
others use whatever will come up in the future |
7789fb1c9fa2
more UD socket fixes (at least client side seems to work now)
Claus Gittinger <cg@exept.de>
parents:
115
diff
changeset
|
2228 |
" |
7789fb1c9fa2
more UD socket fixes (at least client side seems to work now)
Claus Gittinger <cg@exept.de>
parents:
115
diff
changeset
|
2229 |
|
425 | 2230 |
^ self |
2231 |
bindTo:portNrOrNameString |
|
2232 |
address:addressString |
|
2233 |
reuseAddress:true |
|
116
7789fb1c9fa2
more UD socket fixes (at least client side seems to work now)
Claus Gittinger <cg@exept.de>
parents:
115
diff
changeset
|
2234 |
! |
7789fb1c9fa2
more UD socket fixes (at least client side seems to work now)
Claus Gittinger <cg@exept.de>
parents:
115
diff
changeset
|
2235 |
|
7789fb1c9fa2
more UD socket fixes (at least client side seems to work now)
Claus Gittinger <cg@exept.de>
parents:
115
diff
changeset
|
2236 |
bindTo:portNrOrName address:address reuseAddress:reuse |
7789fb1c9fa2
more UD socket fixes (at least client side seems to work now)
Claus Gittinger <cg@exept.de>
parents:
115
diff
changeset
|
2237 |
"low level bind - returns true if ok, false otherwise. |
7789fb1c9fa2
more UD socket fixes (at least client side seems to work now)
Claus Gittinger <cg@exept.de>
parents:
115
diff
changeset
|
2238 |
Currently only non-address binding is supported; |
7789fb1c9fa2
more UD socket fixes (at least client side seems to work now)
Claus Gittinger <cg@exept.de>
parents:
115
diff
changeset
|
2239 |
i.e. address must always be nil. |
7789fb1c9fa2
more UD socket fixes (at least client side seems to work now)
Claus Gittinger <cg@exept.de>
parents:
115
diff
changeset
|
2240 |
|
7789fb1c9fa2
more UD socket fixes (at least client side seems to work now)
Claus Gittinger <cg@exept.de>
parents:
115
diff
changeset
|
2241 |
The interpretation of portNrOrName depends on the domain: |
524
8287da54eccf
more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents:
513
diff
changeset
|
2242 |
inet domain uses (4byte) byteArray like internet numbers, |
8287da54eccf
more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents:
513
diff
changeset
|
2243 |
unix domain uses pathname strings, |
8287da54eccf
more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents:
513
diff
changeset
|
2244 |
others use whatever will come up in the future |
425 | 2245 |
|
2246 |
The reuse boolean argument controls if the SO_REUSEADDR socket option |
|
2247 |
is to be set (to avoid the 'bind: address in use' error). |
|
2248 |
" |
|
28 | 2249 |
|
2250 |
filePointer isNil ifTrue:[ |
|
524
8287da54eccf
more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents:
513
diff
changeset
|
2251 |
^ self error:'not a valid socket' |
28 | 2252 |
]. |
0 | 2253 |
%{ |
418 | 2254 |
#ifndef NO_SOCKET |
217 | 2255 |
OBJ t = __INST(filePointer); |
71 | 2256 |
OBJ myDomain; |
28 | 2257 |
int sock; |
116
7789fb1c9fa2
more UD socket fixes (at least client side seems to work now)
Claus Gittinger <cg@exept.de>
parents:
115
diff
changeset
|
2258 |
union { |
525 | 2259 |
# ifdef AF_INET |
524
8287da54eccf
more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents:
513
diff
changeset
|
2260 |
struct sockaddr_in in; |
525 | 2261 |
# endif |
530
067797c15b77
added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents:
529
diff
changeset
|
2262 |
# ifdef AF_INET6 |
067797c15b77
added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents:
529
diff
changeset
|
2263 |
struct sockaddr_in6 in6; |
067797c15b77
added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents:
529
diff
changeset
|
2264 |
# endif |
524
8287da54eccf
more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents:
513
diff
changeset
|
2265 |
# ifdef AF_UNIX |
8287da54eccf
more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents:
513
diff
changeset
|
2266 |
struct sockaddr_un un; |
525 | 2267 |
# endif |
2268 |
# ifdef AF_APPLETALK |
|
2269 |
struct sockaddr_at at; |
|
2270 |
# endif |
|
116
7789fb1c9fa2
more UD socket fixes (at least client side seems to work now)
Claus Gittinger <cg@exept.de>
parents:
115
diff
changeset
|
2271 |
} sa; |
7789fb1c9fa2
more UD socket fixes (at least client side seems to work now)
Claus Gittinger <cg@exept.de>
parents:
115
diff
changeset
|
2272 |
int sockaddr_size; |
6 | 2273 |
int ret; |
25 | 2274 |
int on = 1; |
28 | 2275 |
int ok; |
0 | 2276 |
|
217 | 2277 |
if (!__isString(__INST(domain)) && !__isSymbol(__INST(domain))) { |
524
8287da54eccf
more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents:
513
diff
changeset
|
2278 |
DBGPRINTF(("SOCKET: invalid domain arg\n")); |
8287da54eccf
more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents:
513
diff
changeset
|
2279 |
RETURN (false); |
28 | 2280 |
} |
2281 |
||
2282 |
ok = 0; |
|
217 | 2283 |
myDomain = __INST(domain); |
525 | 2284 |
|
506
11ef93d12870
support anonymous (OS_specified) ports. (for FTP-protocol)
Claus Gittinger <cg@exept.de>
parents:
486
diff
changeset
|
2285 |
# ifdef AF_INET |
71 | 2286 |
if (myDomain == @symbol(inet)) { |
524
8287da54eccf
more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents:
513
diff
changeset
|
2287 |
/* |
8287da54eccf
more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents:
513
diff
changeset
|
2288 |
* INET addresses - port must be a smallinteger or nil |
8287da54eccf
more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents:
513
diff
changeset
|
2289 |
*/ |
8287da54eccf
more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents:
513
diff
changeset
|
2290 |
sa.in.sin_family = AF_INET; |
8287da54eccf
more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents:
513
diff
changeset
|
2291 |
|
8287da54eccf
more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents:
513
diff
changeset
|
2292 |
if (portNrOrName == nil) { |
8287da54eccf
more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents:
513
diff
changeset
|
2293 |
sa.in.sin_port = 0; |
8287da54eccf
more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents:
513
diff
changeset
|
2294 |
} else { |
8287da54eccf
more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents:
513
diff
changeset
|
2295 |
if (! __isSmallInteger(portNrOrName)) { |
8287da54eccf
more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents:
513
diff
changeset
|
2296 |
DBGPRINTF(("SOCKET: invalid port arg\n")); |
8287da54eccf
more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents:
513
diff
changeset
|
2297 |
RETURN (false); |
8287da54eccf
more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents:
513
diff
changeset
|
2298 |
} |
8287da54eccf
more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents:
513
diff
changeset
|
2299 |
sa.in.sin_port = htons((u_short) _intVal(portNrOrName)); |
8287da54eccf
more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents:
513
diff
changeset
|
2300 |
} |
8287da54eccf
more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents:
513
diff
changeset
|
2301 |
|
8287da54eccf
more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents:
513
diff
changeset
|
2302 |
/* |
8287da54eccf
more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents:
513
diff
changeset
|
2303 |
* INET addresses - addr must be nil, integer or byteArray |
8287da54eccf
more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents:
513
diff
changeset
|
2304 |
*/ |
8287da54eccf
more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents:
513
diff
changeset
|
2305 |
if (address == nil) { |
8287da54eccf
more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents:
513
diff
changeset
|
2306 |
sa.in.sin_addr.s_addr = htonl(INADDR_ANY); |
8287da54eccf
more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents:
513
diff
changeset
|
2307 |
} else { |
8287da54eccf
more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents:
513
diff
changeset
|
2308 |
if (__isInteger(address)) { |
8287da54eccf
more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents:
513
diff
changeset
|
2309 |
sa.in.sin_addr.s_addr = htonl(__longIntVal(address)); |
8287da54eccf
more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents:
513
diff
changeset
|
2310 |
} else { |
8287da54eccf
more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents:
513
diff
changeset
|
2311 |
if (__isByteArray(address)) { |
8287da54eccf
more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents:
513
diff
changeset
|
2312 |
unsigned char *cp; |
8287da54eccf
more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents:
513
diff
changeset
|
2313 |
int n; |
8287da54eccf
more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents:
513
diff
changeset
|
2314 |
|
8287da54eccf
more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents:
513
diff
changeset
|
2315 |
cp = __ByteArrayInstPtr(address)->ba_element; |
8287da54eccf
more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents:
513
diff
changeset
|
2316 |
n = __byteArraySize(address); |
8287da54eccf
more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents:
513
diff
changeset
|
2317 |
if (n > 4) n = 4; |
8287da54eccf
more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents:
513
diff
changeset
|
2318 |
bcopy(cp, &sa.in.sin_addr.s_addr, n); |
8287da54eccf
more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents:
513
diff
changeset
|
2319 |
} else { |
8287da54eccf
more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents:
513
diff
changeset
|
2320 |
unsigned addr; |
8287da54eccf
more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents:
513
diff
changeset
|
2321 |
struct hostent *hp ; |
8287da54eccf
more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents:
513
diff
changeset
|
2322 |
|
8287da54eccf
more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents:
513
diff
changeset
|
2323 |
if (! __isString(address)) { |
8287da54eccf
more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents:
513
diff
changeset
|
2324 |
DBGPRINTF(("SOCKET: invalid address arg in bind\n")); |
8287da54eccf
more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents:
513
diff
changeset
|
2325 |
RETURN (false); |
8287da54eccf
more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents:
513
diff
changeset
|
2326 |
} |
8287da54eccf
more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents:
513
diff
changeset
|
2327 |
|
537
f413ab8fd1b5
gethostbyname must be executed interruptable;
Claus Gittinger <cg@exept.de>
parents:
533
diff
changeset
|
2328 |
if ((addr = inet_addr(__stringVal(address))) != -1) { |
524
8287da54eccf
more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents:
513
diff
changeset
|
2329 |
/* |
8287da54eccf
more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents:
513
diff
changeset
|
2330 |
* is Internet addr in octet notation |
8287da54eccf
more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents:
513
diff
changeset
|
2331 |
*/ |
8287da54eccf
more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents:
513
diff
changeset
|
2332 |
bcopy(&addr, (char *) &sa.in.sin_addr, sizeof(addr)) ; /* set address */ |
8287da54eccf
more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents:
513
diff
changeset
|
2333 |
} else { |
8287da54eccf
more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents:
513
diff
changeset
|
2334 |
/* |
8287da54eccf
more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents:
513
diff
changeset
|
2335 |
* do we know the host's address? |
8287da54eccf
more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents:
513
diff
changeset
|
2336 |
*/ |
648
58e11a70ddaf
gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents:
617
diff
changeset
|
2337 |
GETHOSTBYNAME(hp, __stringVal(address)) |
537
f413ab8fd1b5
gethostbyname must be executed interruptable;
Claus Gittinger <cg@exept.de>
parents:
533
diff
changeset
|
2338 |
if (hp == NULL) { |
f413ab8fd1b5
gethostbyname must be executed interruptable;
Claus Gittinger <cg@exept.de>
parents:
533
diff
changeset
|
2339 |
DBGPRINTF(("SOCKET: unknown host:%s\n", __stringVal(address))); |
524
8287da54eccf
more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents:
513
diff
changeset
|
2340 |
RETURN (false); |
8287da54eccf
more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents:
513
diff
changeset
|
2341 |
} |
8287da54eccf
more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents:
513
diff
changeset
|
2342 |
bcopy(hp->h_addr, (char *) &sa.in.sin_addr, hp->h_length) ; |
8287da54eccf
more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents:
513
diff
changeset
|
2343 |
sa.in.sin_family = hp->h_addrtype; |
8287da54eccf
more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents:
513
diff
changeset
|
2344 |
} |
8287da54eccf
more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents:
513
diff
changeset
|
2345 |
} |
8287da54eccf
more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents:
513
diff
changeset
|
2346 |
} |
8287da54eccf
more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents:
513
diff
changeset
|
2347 |
} |
8287da54eccf
more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents:
513
diff
changeset
|
2348 |
DBGPRINTF(("SOCKET: bind addr: %x port: %x\n", sa.in.sin_addr.s_addr, sa.in.sin_port)); |
8287da54eccf
more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents:
513
diff
changeset
|
2349 |
sockaddr_size = sizeof(struct sockaddr_in); |
8287da54eccf
more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents:
513
diff
changeset
|
2350 |
ok = 1; |
116
7789fb1c9fa2
more UD socket fixes (at least client side seems to work now)
Claus Gittinger <cg@exept.de>
parents:
115
diff
changeset
|
2351 |
} |
530
067797c15b77
added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents:
529
diff
changeset
|
2352 |
# endif /* AF_INET */ |
067797c15b77
added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents:
529
diff
changeset
|
2353 |
|
067797c15b77
added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents:
529
diff
changeset
|
2354 |
# ifdef AF_INET6 |
067797c15b77
added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents:
529
diff
changeset
|
2355 |
if (myDomain == @symbol(inet6)) { |
067797c15b77
added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents:
529
diff
changeset
|
2356 |
/* |
067797c15b77
added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents:
529
diff
changeset
|
2357 |
* INET6 addresses - port must be a smallinteger or nil |
067797c15b77
added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents:
529
diff
changeset
|
2358 |
*/ |
067797c15b77
added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents:
529
diff
changeset
|
2359 |
sa.in6.sin6_family = AF_INET6; |
067797c15b77
added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents:
529
diff
changeset
|
2360 |
|
067797c15b77
added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents:
529
diff
changeset
|
2361 |
if (portNrOrName == nil) { |
067797c15b77
added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents:
529
diff
changeset
|
2362 |
sa.in6.sin6_port = 0; |
067797c15b77
added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents:
529
diff
changeset
|
2363 |
} else { |
067797c15b77
added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents:
529
diff
changeset
|
2364 |
if (! __isSmallInteger(portNrOrName)) { |
067797c15b77
added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents:
529
diff
changeset
|
2365 |
DBGPRINTF(("SOCKET: invalid port arg\n")); |
067797c15b77
added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents:
529
diff
changeset
|
2366 |
RETURN (false); |
067797c15b77
added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents:
529
diff
changeset
|
2367 |
} |
067797c15b77
added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents:
529
diff
changeset
|
2368 |
sa.in6.sin6_port = htons((u_short) _intVal(portNrOrName)); |
067797c15b77
added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents:
529
diff
changeset
|
2369 |
} |
067797c15b77
added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents:
529
diff
changeset
|
2370 |
|
067797c15b77
added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents:
529
diff
changeset
|
2371 |
/* |
067797c15b77
added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents:
529
diff
changeset
|
2372 |
* INET6 addresses - addr must be nil or byteArray or string |
067797c15b77
added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents:
529
diff
changeset
|
2373 |
*/ |
067797c15b77
added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents:
529
diff
changeset
|
2374 |
if (address == nil) { |
067797c15b77
added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents:
529
diff
changeset
|
2375 |
sa.in6.sin6_addr.s6_addr[0] = 0; |
067797c15b77
added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents:
529
diff
changeset
|
2376 |
sa.in6.sin6_addr.s6_addr[1] = 0; |
067797c15b77
added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents:
529
diff
changeset
|
2377 |
sa.in6.sin6_addr.s6_addr[2] = 0; |
067797c15b77
added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents:
529
diff
changeset
|
2378 |
sa.in6.sin6_addr.s6_addr[3] = 0; |
067797c15b77
added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents:
529
diff
changeset
|
2379 |
sa.in6.sin6_addr.s6_addr[4] = 0; |
067797c15b77
added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents:
529
diff
changeset
|
2380 |
sa.in6.sin6_addr.s6_addr[5] = 0; |
067797c15b77
added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents:
529
diff
changeset
|
2381 |
} else { |
067797c15b77
added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents:
529
diff
changeset
|
2382 |
if (__isByteArray(address)) { |
067797c15b77
added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents:
529
diff
changeset
|
2383 |
unsigned char *cp; |
067797c15b77
added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents:
529
diff
changeset
|
2384 |
int n; |
067797c15b77
added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents:
529
diff
changeset
|
2385 |
|
067797c15b77
added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents:
529
diff
changeset
|
2386 |
cp = __ByteArrayInstPtr(address)->ba_element; |
067797c15b77
added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents:
529
diff
changeset
|
2387 |
n = __byteArraySize(address); |
067797c15b77
added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents:
529
diff
changeset
|
2388 |
if (n > 6) n = 6; |
067797c15b77
added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents:
529
diff
changeset
|
2389 |
bcopy(cp, &sa.in6.sin6_addr.s6_addr, n); |
067797c15b77
added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents:
529
diff
changeset
|
2390 |
} else { |
067797c15b77
added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents:
529
diff
changeset
|
2391 |
unsigned addr; |
067797c15b77
added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents:
529
diff
changeset
|
2392 |
struct hostent *hp ; |
067797c15b77
added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents:
529
diff
changeset
|
2393 |
|
067797c15b77
added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents:
529
diff
changeset
|
2394 |
if (! __isString(address)) { |
067797c15b77
added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents:
529
diff
changeset
|
2395 |
DBGPRINTF(("SOCKET: invalid address arg in bind\n")); |
067797c15b77
added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents:
529
diff
changeset
|
2396 |
RETURN (false); |
067797c15b77
added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents:
529
diff
changeset
|
2397 |
} |
067797c15b77
added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents:
529
diff
changeset
|
2398 |
|
067797c15b77
added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents:
529
diff
changeset
|
2399 |
/* |
067797c15b77
added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents:
529
diff
changeset
|
2400 |
* do we know the host's address? |
067797c15b77
added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents:
529
diff
changeset
|
2401 |
*/ |
648
58e11a70ddaf
gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents:
617
diff
changeset
|
2402 |
GETHOSTBYNAME(hp, __stringVal(address)) |
537
f413ab8fd1b5
gethostbyname must be executed interruptable;
Claus Gittinger <cg@exept.de>
parents:
533
diff
changeset
|
2403 |
if (hp == NULL) { |
f413ab8fd1b5
gethostbyname must be executed interruptable;
Claus Gittinger <cg@exept.de>
parents:
533
diff
changeset
|
2404 |
DBGPRINTF(("SOCKET: unknown host:%s\n", __stringVal(address))); |
530
067797c15b77
added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents:
529
diff
changeset
|
2405 |
RETURN (false); |
067797c15b77
added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents:
529
diff
changeset
|
2406 |
} |
067797c15b77
added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents:
529
diff
changeset
|
2407 |
bcopy(hp->h_addr, (char *) &sa.in6.sin6_addr, hp->h_length) ; |
067797c15b77
added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents:
529
diff
changeset
|
2408 |
sa.in.sin_family = hp->h_addrtype; |
067797c15b77
added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents:
529
diff
changeset
|
2409 |
} |
067797c15b77
added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents:
529
diff
changeset
|
2410 |
} |
067797c15b77
added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents:
529
diff
changeset
|
2411 |
|
067797c15b77
added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents:
529
diff
changeset
|
2412 |
DBGPRINTF(("SOCKET: bind addr: %x.%x.%x.%x.%x.%x port: %x\n", |
067797c15b77
added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents:
529
diff
changeset
|
2413 |
sa.in6.sin6_addr.s6_addr[0], |
067797c15b77
added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents:
529
diff
changeset
|
2414 |
sa.in6.sin6_addr.s6_addr[1], |
067797c15b77
added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents:
529
diff
changeset
|
2415 |
sa.in6.sin6_addr.s6_addr[2], |
067797c15b77
added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents:
529
diff
changeset
|
2416 |
sa.in6.sin6_addr.s6_addr[3], |
067797c15b77
added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents:
529
diff
changeset
|
2417 |
sa.in6.sin6_addr.s6_addr[4], |
067797c15b77
added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents:
529
diff
changeset
|
2418 |
sa.in6.sin6_addr.s6_addr[5], |
067797c15b77
added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents:
529
diff
changeset
|
2419 |
sa.in6.sin6_port)); |
067797c15b77
added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents:
529
diff
changeset
|
2420 |
sockaddr_size = sizeof(struct sockaddr_in6); |
067797c15b77
added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents:
529
diff
changeset
|
2421 |
ok = 1; |
067797c15b77
added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents:
529
diff
changeset
|
2422 |
} |
067797c15b77
added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents:
529
diff
changeset
|
2423 |
# endif /* AF_INET6 */ |
525 | 2424 |
|
506
11ef93d12870
support anonymous (OS_specified) ports. (for FTP-protocol)
Claus Gittinger <cg@exept.de>
parents:
486
diff
changeset
|
2425 |
# ifdef AF_UNIX |
525 | 2426 |
/* |
2427 |
* UNIX domain - port is ignored; address must be a string (path) |
|
2428 |
*/ |
|
116
7789fb1c9fa2
more UD socket fixes (at least client side seems to work now)
Claus Gittinger <cg@exept.de>
parents:
115
diff
changeset
|
2429 |
if (myDomain == @symbol(unix)) { |
524
8287da54eccf
more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents:
513
diff
changeset
|
2430 |
char *pathName; |
8287da54eccf
more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents:
513
diff
changeset
|
2431 |
int l; |
8287da54eccf
more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents:
513
diff
changeset
|
2432 |
|
8287da54eccf
more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents:
513
diff
changeset
|
2433 |
if (! __isString(portNrOrName)) { |
8287da54eccf
more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents:
513
diff
changeset
|
2434 |
DBGPRINTF(("SOCKET: invalid port (pathname) arg\n")); |
8287da54eccf
more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents:
513
diff
changeset
|
2435 |
RETURN (false); |
8287da54eccf
more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents:
513
diff
changeset
|
2436 |
} |
551
b2d6e4d86e77
avoid warnings (signed char vs. unsigned char)
Claus Gittinger <cg@exept.de>
parents:
537
diff
changeset
|
2437 |
pathName = (char *)__stringVal(portNrOrName); |
524
8287da54eccf
more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents:
513
diff
changeset
|
2438 |
l = strlen(pathName); |
8287da54eccf
more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents:
513
diff
changeset
|
2439 |
if ((l + sizeof ( sa.un.sun_family )) > sizeof(struct sockaddr_un)) { |
8287da54eccf
more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents:
513
diff
changeset
|
2440 |
DBGPRINTF(("SOCKET: pathname too long\n")); |
8287da54eccf
more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents:
513
diff
changeset
|
2441 |
RETURN (false); |
8287da54eccf
more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents:
513
diff
changeset
|
2442 |
} |
8287da54eccf
more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents:
513
diff
changeset
|
2443 |
|
8287da54eccf
more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents:
513
diff
changeset
|
2444 |
strcpy(sa.un.sun_path, pathName); |
8287da54eccf
more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents:
513
diff
changeset
|
2445 |
sa.un.sun_family = AF_UNIX; |
8287da54eccf
more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents:
513
diff
changeset
|
2446 |
sockaddr_size = l + sizeof ( sa.un.sun_family ); |
8287da54eccf
more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents:
513
diff
changeset
|
2447 |
ok = 1; |
28 | 2448 |
} |
530
067797c15b77
added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents:
529
diff
changeset
|
2449 |
# endif /* AF_UNIX */ |
525 | 2450 |
|
2451 |
# ifdef AF_APPLETALK |
|
2452 |
/* |
|
2453 |
* this has never been tested .... |
|
2454 |
*/ |
|
2455 |
if (myDomain == @symbol(appletalk)) { |
|
2456 |
/* |
|
2457 |
* APPLETALK addresses - port must be a smallinteger or nil |
|
2458 |
*/ |
|
2459 |
sa.at.sat_family = AF_APPLETALK; |
|
2460 |
||
2461 |
if (portNrOrName == nil) { |
|
2462 |
sa.at.sat_port = 0; |
|
2463 |
} else { |
|
2464 |
if (! __isSmallInteger(portNrOrName)) { |
|
2465 |
DBGPRINTF(("SOCKET: invalid port arg\n")); |
|
2466 |
RETURN (false); |
|
2467 |
} |
|
2468 |
sa.at.sat_port = __intVal(portNrOrName); |
|
2469 |
} |
|
2470 |
||
2471 |
/* |
|
2472 |
* APPLETALK addresses - addr must be nil, integer or byteArray |
|
2473 |
* if integer, the low 8 bits are the node, the next higher 16 |
|
2474 |
* bit are the net. |
|
2475 |
*/ |
|
2476 |
if (address == nil) { |
|
529 | 2477 |
sa.at.sat_addr.s_net = ATADDR_ANYNET; |
2478 |
sa.at.sat_addr.s_node = ATADDR_ANYNODE; |
|
525 | 2479 |
} else { |
2480 |
if (__isInteger(address)) { |
|
2481 |
unsigned a = __longIntVal(address); |
|
529 | 2482 |
sa.at.sat_addr.s_net = htons((a >> 8) & 0xFFFF); |
2483 |
sa.at.sat_addr.s_node = htons(a & 0xFF); |
|
525 | 2484 |
} else { |
2485 |
if (__isByteArray(address)) { |
|
2486 |
unsigned char *cp; |
|
2487 |
int n; |
|
2488 |
||
2489 |
cp = __ByteArrayInstPtr(address)->ba_element; |
|
2490 |
n = __byteArraySize(address); |
|
2491 |
if (n > 3) n = 3; |
|
2492 |
bcopy(cp, &sa.at.sat_addr, n); |
|
2493 |
} else { |
|
2494 |
unsigned addr; |
|
2495 |
struct hostent *hp ; |
|
2496 |
||
2497 |
if (! __isString(address)) { |
|
2498 |
DBGPRINTF(("SOCKET: invalid address arg in bind\n")); |
|
2499 |
RETURN (false); |
|
2500 |
} |
|
2501 |
||
2502 |
/* |
|
2503 |
* do we know the host's address? |
|
2504 |
*/ |
|
648
58e11a70ddaf
gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents:
617
diff
changeset
|
2505 |
GETHOSTBYNAME(hp, __stringVal(address)) |
537
f413ab8fd1b5
gethostbyname must be executed interruptable;
Claus Gittinger <cg@exept.de>
parents:
533
diff
changeset
|
2506 |
if (hp == NULL) { |
f413ab8fd1b5
gethostbyname must be executed interruptable;
Claus Gittinger <cg@exept.de>
parents:
533
diff
changeset
|
2507 |
DBGPRINTF(("SOCKET: unknown host: %s\n", __stringVal(address))); |
525 | 2508 |
RETURN (false); |
2509 |
} |
|
2510 |
if (hp->h_addrtype != AF_APPLETALK) { |
|
537
f413ab8fd1b5
gethostbyname must be executed interruptable;
Claus Gittinger <cg@exept.de>
parents:
533
diff
changeset
|
2511 |
DBGPRINTF(("SOCKET: host:%s is not an appletalk host\n", __stringVal(address))); |
525 | 2512 |
RETURN (false); |
2513 |
} |
|
2514 |
bcopy(hp->h_addr, (char *) &sa.at.sat_addr, hp->h_length) ; |
|
2515 |
sa.at.sat_family = hp->h_addrtype; |
|
2516 |
} |
|
2517 |
} |
|
2518 |
} |
|
2519 |
DBGPRINTF(("SOCKET: bind addr: %x port: %x\n", sa.in.sin_addr.s_addr, sa.in.sin_port)); |
|
2520 |
sockaddr_size = sizeof(struct sockaddr_at); |
|
2521 |
ok = 1; |
|
2522 |
} |
|
530
067797c15b77
added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents:
529
diff
changeset
|
2523 |
# endif /* AF_APPLETALK */ |
525 | 2524 |
|
28 | 2525 |
/* |
2526 |
* XXXX add addressing stuff for other domains here ... |
|
2527 |
*/ |
|
506
11ef93d12870
support anonymous (OS_specified) ports. (for FTP-protocol)
Claus Gittinger <cg@exept.de>
parents:
486
diff
changeset
|
2528 |
# ifdef AF_X25 |
71 | 2529 |
if (myDomain == @symbol(x25)) { |
28 | 2530 |
} |
506
11ef93d12870
support anonymous (OS_specified) ports. (for FTP-protocol)
Claus Gittinger <cg@exept.de>
parents:
486
diff
changeset
|
2531 |
# endif |
11ef93d12870
support anonymous (OS_specified) ports. (for FTP-protocol)
Claus Gittinger <cg@exept.de>
parents:
486
diff
changeset
|
2532 |
# ifdef AF_NS |
71 | 2533 |
if (myDomain == @symbol(ns)) { |
28 | 2534 |
} |
506
11ef93d12870
support anonymous (OS_specified) ports. (for FTP-protocol)
Claus Gittinger <cg@exept.de>
parents:
486
diff
changeset
|
2535 |
# endif |
524
8287da54eccf
more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents:
513
diff
changeset
|
2536 |
# ifdef AF_DECnet |
8287da54eccf
more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents:
513
diff
changeset
|
2537 |
if (myDomain == @symbol(decnet)) { |
8287da54eccf
more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents:
513
diff
changeset
|
2538 |
} |
8287da54eccf
more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents:
513
diff
changeset
|
2539 |
# endif |
506
11ef93d12870
support anonymous (OS_specified) ports. (for FTP-protocol)
Claus Gittinger <cg@exept.de>
parents:
486
diff
changeset
|
2540 |
# ifdef AF_SNA |
93 | 2541 |
if (myDomain == @symbol(sna)) { |
2542 |
} |
|
506
11ef93d12870
support anonymous (OS_specified) ports. (for FTP-protocol)
Claus Gittinger <cg@exept.de>
parents:
486
diff
changeset
|
2543 |
# endif |
11ef93d12870
support anonymous (OS_specified) ports. (for FTP-protocol)
Claus Gittinger <cg@exept.de>
parents:
486
diff
changeset
|
2544 |
# ifdef AF_NS |
93 | 2545 |
if (myDomain == @symbol(xns)) { |
2546 |
} |
|
506
11ef93d12870
support anonymous (OS_specified) ports. (for FTP-protocol)
Claus Gittinger <cg@exept.de>
parents:
486
diff
changeset
|
2547 |
# endif |
11ef93d12870
support anonymous (OS_specified) ports. (for FTP-protocol)
Claus Gittinger <cg@exept.de>
parents:
486
diff
changeset
|
2548 |
# ifdef AF_RAW |
93 | 2549 |
if (myDomain == @symbol(raw)) { |
2550 |
} |
|
506
11ef93d12870
support anonymous (OS_specified) ports. (for FTP-protocol)
Claus Gittinger <cg@exept.de>
parents:
486
diff
changeset
|
2551 |
# endif |
524
8287da54eccf
more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents:
513
diff
changeset
|
2552 |
# ifdef AF_ISO |
8287da54eccf
more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents:
513
diff
changeset
|
2553 |
if (myDomain == @symbol(iso)) { |
8287da54eccf
more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents:
513
diff
changeset
|
2554 |
} |
8287da54eccf
more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents:
513
diff
changeset
|
2555 |
# endif |
8287da54eccf
more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents:
513
diff
changeset
|
2556 |
# ifdef AF_NETBIOS |
530
067797c15b77
added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents:
529
diff
changeset
|
2557 |
if (myDomain == @symbol(netbios)) { |
067797c15b77
added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents:
529
diff
changeset
|
2558 |
} |
067797c15b77
added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents:
529
diff
changeset
|
2559 |
# endif |
067797c15b77
added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents:
529
diff
changeset
|
2560 |
# ifdef AF_IPX |
067797c15b77
added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents:
529
diff
changeset
|
2561 |
if (myDomain == @symbol(ipx)) { |
067797c15b77
added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents:
529
diff
changeset
|
2562 |
} |
067797c15b77
added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents:
529
diff
changeset
|
2563 |
# endif |
067797c15b77
added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents:
529
diff
changeset
|
2564 |
# ifdef AF_BRIDGE |
067797c15b77
added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents:
529
diff
changeset
|
2565 |
if (myDomain == @symbol(bridge)) { |
524
8287da54eccf
more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents:
513
diff
changeset
|
2566 |
} |
8287da54eccf
more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents:
513
diff
changeset
|
2567 |
# endif |
571 | 2568 |
# ifdef AF_BSC |
2569 |
if (myDomain == @symbol(bsc)) { |
|
2570 |
} |
|
2571 |
# endif |
|
524
8287da54eccf
more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents:
513
diff
changeset
|
2572 |
# if defined(AF_CCITT) && (AF_CCITT != AF_X25) |
8287da54eccf
more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents:
513
diff
changeset
|
2573 |
if (myDomain == @symbol(ccitt)) { |
8287da54eccf
more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents:
513
diff
changeset
|
2574 |
} |
8287da54eccf
more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents:
513
diff
changeset
|
2575 |
# endif |
0 | 2576 |
|
28 | 2577 |
if (! ok) { |
524
8287da54eccf
more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents:
513
diff
changeset
|
2578 |
DBGPRINTF(("SOCKET: unsupported domain\n")); |
8287da54eccf
more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents:
513
diff
changeset
|
2579 |
RETURN (false); |
28 | 2580 |
} |
2581 |
||
110
7af19ae8693b
use new FILE* wrapper macros (based on externalAddress)
Claus Gittinger <cg@exept.de>
parents:
106
diff
changeset
|
2582 |
sock = fileno(__FILEVal(t)); |
28 | 2583 |
|
506
11ef93d12870
support anonymous (OS_specified) ports. (for FTP-protocol)
Claus Gittinger <cg@exept.de>
parents:
486
diff
changeset
|
2584 |
# ifdef SO_REUSEADDR |
116
7789fb1c9fa2
more UD socket fixes (at least client side seems to work now)
Claus Gittinger <cg@exept.de>
parents:
115
diff
changeset
|
2585 |
if (reuse == true) { |
524
8287da54eccf
more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents:
513
diff
changeset
|
2586 |
if (setsockopt(sock, SOL_SOCKET, SO_REUSEADDR, (char *) &on, sizeof (on)) < 0) { |
8287da54eccf
more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents:
513
diff
changeset
|
2587 |
DBGPRINTF(("SOCKET: setsockopt - SO_REUSEADDR failed\n")); |
8287da54eccf
more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents:
513
diff
changeset
|
2588 |
} |
28 | 2589 |
} |
506
11ef93d12870
support anonymous (OS_specified) ports. (for FTP-protocol)
Claus Gittinger <cg@exept.de>
parents:
486
diff
changeset
|
2590 |
# endif /* SO_REUSEADDR */ |
28 | 2591 |
|
117
03cefad7e40b
UD socket example & interruptable bind
Claus Gittinger <cg@exept.de>
parents:
116
diff
changeset
|
2592 |
__BEGIN_INTERRUPTABLE__ |
28 | 2593 |
do { |
524
8287da54eccf
more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents:
513
diff
changeset
|
2594 |
ret = bind(sock, (struct sockaddr *)&sa, sockaddr_size); |
28 | 2595 |
} while ((ret < 0) && (errno == EINTR)); |
117
03cefad7e40b
UD socket example & interruptable bind
Claus Gittinger <cg@exept.de>
parents:
116
diff
changeset
|
2596 |
__END_INTERRUPTABLE__ |
28 | 2597 |
|
2598 |
if (ret < 0) { |
|
524
8287da54eccf
more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents:
513
diff
changeset
|
2599 |
DBGPRINTF(("SOCKET: bind failed errno=%d\n", errno)); |
8287da54eccf
more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents:
513
diff
changeset
|
2600 |
__INST(lastErrorNumber) = __MKSMALLINT(errno); |
8287da54eccf
more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents:
513
diff
changeset
|
2601 |
RETURN (false); |
0 | 2602 |
} |
506
11ef93d12870
support anonymous (OS_specified) ports. (for FTP-protocol)
Claus Gittinger <cg@exept.de>
parents:
486
diff
changeset
|
2603 |
|
11ef93d12870
support anonymous (OS_specified) ports. (for FTP-protocol)
Claus Gittinger <cg@exept.de>
parents:
486
diff
changeset
|
2604 |
__INST(port) = portNrOrName; __STORE(self, portNrOrName); |
11ef93d12870
support anonymous (OS_specified) ports. (for FTP-protocol)
Claus Gittinger <cg@exept.de>
parents:
486
diff
changeset
|
2605 |
|
11ef93d12870
support anonymous (OS_specified) ports. (for FTP-protocol)
Claus Gittinger <cg@exept.de>
parents:
486
diff
changeset
|
2606 |
# ifdef AF_INET |
11ef93d12870
support anonymous (OS_specified) ports. (for FTP-protocol)
Claus Gittinger <cg@exept.de>
parents:
486
diff
changeset
|
2607 |
if (myDomain == @symbol(inet)) { |
524
8287da54eccf
more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents:
513
diff
changeset
|
2608 |
if (! __isSmallInteger(portNrOrName) |
8287da54eccf
more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents:
513
diff
changeset
|
2609 |
|| (portNrOrName == __MKSMALLINT(0))) { |
8287da54eccf
more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents:
513
diff
changeset
|
2610 |
int p; |
8287da54eccf
more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents:
513
diff
changeset
|
2611 |
|
8287da54eccf
more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents:
513
diff
changeset
|
2612 |
/* |
8287da54eccf
more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents:
513
diff
changeset
|
2613 |
* INET anonymous port - get the actual portNr |
8287da54eccf
more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents:
513
diff
changeset
|
2614 |
*/ |
8287da54eccf
more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents:
513
diff
changeset
|
2615 |
if (getsockname(sock, (struct sockaddr *)&sa, &sockaddr_size) < 0) { |
8287da54eccf
more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents:
513
diff
changeset
|
2616 |
DBGPRINTF(("SOCKET: cannot get peername\n")); |
8287da54eccf
more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents:
513
diff
changeset
|
2617 |
} else { |
8287da54eccf
more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents:
513
diff
changeset
|
2618 |
DBGPRINTF(("SOCKET: anon port=%x\n", sa.in.sin_port)); |
8287da54eccf
more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents:
513
diff
changeset
|
2619 |
p = ntohs(sa.in.sin_port); |
8287da54eccf
more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents:
513
diff
changeset
|
2620 |
__INST(port) = __MKSMALLINT(p); |
8287da54eccf
more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents:
513
diff
changeset
|
2621 |
} |
8287da54eccf
more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents:
513
diff
changeset
|
2622 |
} |
506
11ef93d12870
support anonymous (OS_specified) ports. (for FTP-protocol)
Claus Gittinger <cg@exept.de>
parents:
486
diff
changeset
|
2623 |
} |
11ef93d12870
support anonymous (OS_specified) ports. (for FTP-protocol)
Claus Gittinger <cg@exept.de>
parents:
486
diff
changeset
|
2624 |
# endif |
530
067797c15b77
added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents:
529
diff
changeset
|
2625 |
# ifdef AF_INET6 |
067797c15b77
added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents:
529
diff
changeset
|
2626 |
if (myDomain == @symbol(inet6)) { |
533
ced9950b551f
added query about which protocols are supported
Claus Gittinger <cg@exept.de>
parents:
532
diff
changeset
|
2627 |
if (! __isSmallInteger(portNrOrName) |
ced9950b551f
added query about which protocols are supported
Claus Gittinger <cg@exept.de>
parents:
532
diff
changeset
|
2628 |
|| (portNrOrName == __MKSMALLINT(0))) { |
ced9950b551f
added query about which protocols are supported
Claus Gittinger <cg@exept.de>
parents:
532
diff
changeset
|
2629 |
int p; |
ced9950b551f
added query about which protocols are supported
Claus Gittinger <cg@exept.de>
parents:
532
diff
changeset
|
2630 |
|
ced9950b551f
added query about which protocols are supported
Claus Gittinger <cg@exept.de>
parents:
532
diff
changeset
|
2631 |
/* |
ced9950b551f
added query about which protocols are supported
Claus Gittinger <cg@exept.de>
parents:
532
diff
changeset
|
2632 |
* INET6 anonymous port - get the actual portNr |
ced9950b551f
added query about which protocols are supported
Claus Gittinger <cg@exept.de>
parents:
532
diff
changeset
|
2633 |
*/ |
ced9950b551f
added query about which protocols are supported
Claus Gittinger <cg@exept.de>
parents:
532
diff
changeset
|
2634 |
if (getsockname(sock, (struct sockaddr *)&sa, &sockaddr_size) < 0) { |
ced9950b551f
added query about which protocols are supported
Claus Gittinger <cg@exept.de>
parents:
532
diff
changeset
|
2635 |
DBGPRINTF(("SOCKET: cannot get peername\n")); |
ced9950b551f
added query about which protocols are supported
Claus Gittinger <cg@exept.de>
parents:
532
diff
changeset
|
2636 |
} else { |
ced9950b551f
added query about which protocols are supported
Claus Gittinger <cg@exept.de>
parents:
532
diff
changeset
|
2637 |
DBGPRINTF(("SOCKET: anon port=%x\n", sa.in.sin_port)); |
ced9950b551f
added query about which protocols are supported
Claus Gittinger <cg@exept.de>
parents:
532
diff
changeset
|
2638 |
p = ntohs(sa.in6.sin6_port); |
ced9950b551f
added query about which protocols are supported
Claus Gittinger <cg@exept.de>
parents:
532
diff
changeset
|
2639 |
__INST(port) = __MKSMALLINT(p); |
ced9950b551f
added query about which protocols are supported
Claus Gittinger <cg@exept.de>
parents:
532
diff
changeset
|
2640 |
} |
ced9950b551f
added query about which protocols are supported
Claus Gittinger <cg@exept.de>
parents:
532
diff
changeset
|
2641 |
} |
530
067797c15b77
added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents:
529
diff
changeset
|
2642 |
} |
067797c15b77
added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents:
529
diff
changeset
|
2643 |
# endif |
067797c15b77
added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents:
529
diff
changeset
|
2644 |
# ifdef AF_APPLETALK |
067797c15b77
added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents:
529
diff
changeset
|
2645 |
if (myDomain == @symbol(appletalk)) { |
533
ced9950b551f
added query about which protocols are supported
Claus Gittinger <cg@exept.de>
parents:
532
diff
changeset
|
2646 |
if (! __isSmallInteger(portNrOrName) |
ced9950b551f
added query about which protocols are supported
Claus Gittinger <cg@exept.de>
parents:
532
diff
changeset
|
2647 |
|| (portNrOrName == __MKSMALLINT(0))) { |
ced9950b551f
added query about which protocols are supported
Claus Gittinger <cg@exept.de>
parents:
532
diff
changeset
|
2648 |
int p; |
ced9950b551f
added query about which protocols are supported
Claus Gittinger <cg@exept.de>
parents:
532
diff
changeset
|
2649 |
|
ced9950b551f
added query about which protocols are supported
Claus Gittinger <cg@exept.de>
parents:
532
diff
changeset
|
2650 |
/* |
ced9950b551f
added query about which protocols are supported
Claus Gittinger <cg@exept.de>
parents:
532
diff
changeset
|
2651 |
* APPLETALK anonymous port - get the actual portNr |
ced9950b551f
added query about which protocols are supported
Claus Gittinger <cg@exept.de>
parents:
532
diff
changeset
|
2652 |
*/ |
ced9950b551f
added query about which protocols are supported
Claus Gittinger <cg@exept.de>
parents:
532
diff
changeset
|
2653 |
if (getsockname(sock, (struct sockaddr *)&sa, &sockaddr_size) < 0) { |
ced9950b551f
added query about which protocols are supported
Claus Gittinger <cg@exept.de>
parents:
532
diff
changeset
|
2654 |
DBGPRINTF(("SOCKET: cannot get peername\n")); |
ced9950b551f
added query about which protocols are supported
Claus Gittinger <cg@exept.de>
parents:
532
diff
changeset
|
2655 |
} else { |
ced9950b551f
added query about which protocols are supported
Claus Gittinger <cg@exept.de>
parents:
532
diff
changeset
|
2656 |
DBGPRINTF(("SOCKET: anon port=%x\n", sa.in.sin_port)); |
ced9950b551f
added query about which protocols are supported
Claus Gittinger <cg@exept.de>
parents:
532
diff
changeset
|
2657 |
p = sa.at.sat_port; |
ced9950b551f
added query about which protocols are supported
Claus Gittinger <cg@exept.de>
parents:
532
diff
changeset
|
2658 |
__INST(port) = __MKSMALLINT(p); |
ced9950b551f
added query about which protocols are supported
Claus Gittinger <cg@exept.de>
parents:
532
diff
changeset
|
2659 |
} |
ced9950b551f
added query about which protocols are supported
Claus Gittinger <cg@exept.de>
parents:
532
diff
changeset
|
2660 |
} |
530
067797c15b77
added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents:
529
diff
changeset
|
2661 |
} |
067797c15b77
added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents:
529
diff
changeset
|
2662 |
# endif |
067797c15b77
added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents:
529
diff
changeset
|
2663 |
|
506
11ef93d12870
support anonymous (OS_specified) ports. (for FTP-protocol)
Claus Gittinger <cg@exept.de>
parents:
486
diff
changeset
|
2664 |
#else /* NO_SOCKET */ |
418 | 2665 |
RETURN (false); |
506
11ef93d12870
support anonymous (OS_specified) ports. (for FTP-protocol)
Claus Gittinger <cg@exept.de>
parents:
486
diff
changeset
|
2666 |
#endif /* NO_SOCKET */ |
42 | 2667 |
%}. |
28 | 2668 |
^ true |
0 | 2669 |
|
28 | 2670 |
" |
2671 |
(Socket domain:#inet type:#stream) |
|
524
8287da54eccf
more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents:
513
diff
changeset
|
2672 |
bindTo:9999 |
8287da54eccf
more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents:
513
diff
changeset
|
2673 |
address:nil |
28 | 2674 |
" |
0 | 2675 |
! |
2676 |
||
208
c3eca2cc16dc
accept: do not wait for input on non-connected socket.
Stefan Vogel <sv@exept.de>
parents:
207
diff
changeset
|
2677 |
blockingAcceptOn:aSocket |
c3eca2cc16dc
accept: do not wait for input on non-connected socket.
Stefan Vogel <sv@exept.de>
parents:
207
diff
changeset
|
2678 |
"accept a connection on a server port (created with:'Socket>>onIPPort:') |
c3eca2cc16dc
accept: do not wait for input on non-connected socket.
Stefan Vogel <sv@exept.de>
parents:
207
diff
changeset
|
2679 |
usage is: (Socket basicNew acceptOn:(Socket onIPPort:9999)). |
c3eca2cc16dc
accept: do not wait for input on non-connected socket.
Stefan Vogel <sv@exept.de>
parents:
207
diff
changeset
|
2680 |
Return the true if ok; false if not. |
c3eca2cc16dc
accept: do not wait for input on non-connected socket.
Stefan Vogel <sv@exept.de>
parents:
207
diff
changeset
|
2681 |
|
c3eca2cc16dc
accept: do not wait for input on non-connected socket.
Stefan Vogel <sv@exept.de>
parents:
207
diff
changeset
|
2682 |
NOTICE: this method will block, if no connection is already pending. |
506
11ef93d12870
support anonymous (OS_specified) ports. (for FTP-protocol)
Claus Gittinger <cg@exept.de>
parents:
486
diff
changeset
|
2683 |
use readWait or Socket>>accept." |
208
c3eca2cc16dc
accept: do not wait for input on non-connected socket.
Stefan Vogel <sv@exept.de>
parents:
207
diff
changeset
|
2684 |
|
c3eca2cc16dc
accept: do not wait for input on non-connected socket.
Stefan Vogel <sv@exept.de>
parents:
207
diff
changeset
|
2685 |
|serverSocketFd| |
c3eca2cc16dc
accept: do not wait for input on non-connected socket.
Stefan Vogel <sv@exept.de>
parents:
207
diff
changeset
|
2686 |
|
c3eca2cc16dc
accept: do not wait for input on non-connected socket.
Stefan Vogel <sv@exept.de>
parents:
207
diff
changeset
|
2687 |
filePointer notNil ifTrue:[ |
506
11ef93d12870
support anonymous (OS_specified) ports. (for FTP-protocol)
Claus Gittinger <cg@exept.de>
parents:
486
diff
changeset
|
2688 |
^ self error:'already connected' |
208
c3eca2cc16dc
accept: do not wait for input on non-connected socket.
Stefan Vogel <sv@exept.de>
parents:
207
diff
changeset
|
2689 |
]. |
c3eca2cc16dc
accept: do not wait for input on non-connected socket.
Stefan Vogel <sv@exept.de>
parents:
207
diff
changeset
|
2690 |
|
c3eca2cc16dc
accept: do not wait for input on non-connected socket.
Stefan Vogel <sv@exept.de>
parents:
207
diff
changeset
|
2691 |
domain := aSocket domain. |
c3eca2cc16dc
accept: do not wait for input on non-connected socket.
Stefan Vogel <sv@exept.de>
parents:
207
diff
changeset
|
2692 |
socketType := aSocket type. |
c3eca2cc16dc
accept: do not wait for input on non-connected socket.
Stefan Vogel <sv@exept.de>
parents:
207
diff
changeset
|
2693 |
serverSocketFd := aSocket fileDescriptor. |
c3eca2cc16dc
accept: do not wait for input on non-connected socket.
Stefan Vogel <sv@exept.de>
parents:
207
diff
changeset
|
2694 |
serverSocketFd isNil ifTrue:[ |
506
11ef93d12870
support anonymous (OS_specified) ports. (for FTP-protocol)
Claus Gittinger <cg@exept.de>
parents:
486
diff
changeset
|
2695 |
^ self error:'invalid server socket' |
208
c3eca2cc16dc
accept: do not wait for input on non-connected socket.
Stefan Vogel <sv@exept.de>
parents:
207
diff
changeset
|
2696 |
]. |
c3eca2cc16dc
accept: do not wait for input on non-connected socket.
Stefan Vogel <sv@exept.de>
parents:
207
diff
changeset
|
2697 |
(serverSocketFd isMemberOf:SmallInteger) ifFalse:[ |
506
11ef93d12870
support anonymous (OS_specified) ports. (for FTP-protocol)
Claus Gittinger <cg@exept.de>
parents:
486
diff
changeset
|
2698 |
^ self error:'invalid server socket' |
208
c3eca2cc16dc
accept: do not wait for input on non-connected socket.
Stefan Vogel <sv@exept.de>
parents:
207
diff
changeset
|
2699 |
]. |
c3eca2cc16dc
accept: do not wait for input on non-connected socket.
Stefan Vogel <sv@exept.de>
parents:
207
diff
changeset
|
2700 |
%{ |
418 | 2701 |
#ifndef NO_SOCKET |
208
c3eca2cc16dc
accept: do not wait for input on non-connected socket.
Stefan Vogel <sv@exept.de>
parents:
207
diff
changeset
|
2702 |
FILE *fp; |
c3eca2cc16dc
accept: do not wait for input on non-connected socket.
Stefan Vogel <sv@exept.de>
parents:
207
diff
changeset
|
2703 |
int flags; |
c3eca2cc16dc
accept: do not wait for input on non-connected socket.
Stefan Vogel <sv@exept.de>
parents:
207
diff
changeset
|
2704 |
int sock, newSock; |
c3eca2cc16dc
accept: do not wait for input on non-connected socket.
Stefan Vogel <sv@exept.de>
parents:
207
diff
changeset
|
2705 |
union { |
525 | 2706 |
#ifdef AF_INET |
2707 |
struct sockaddr_in in; |
|
2708 |
#endif |
|
530
067797c15b77
added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents:
529
diff
changeset
|
2709 |
# ifdef AF_INET6 |
067797c15b77
added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents:
529
diff
changeset
|
2710 |
struct sockaddr_in6 in6; |
067797c15b77
added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents:
529
diff
changeset
|
2711 |
# endif |
524
8287da54eccf
more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents:
513
diff
changeset
|
2712 |
# ifdef AF_UNIX |
525 | 2713 |
struct sockaddr_un un; |
2714 |
# endif |
|
2715 |
# ifdef AF_APPLETALK |
|
2716 |
struct sockaddr_at at; |
|
524
8287da54eccf
more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents:
513
diff
changeset
|
2717 |
# endif |
208
c3eca2cc16dc
accept: do not wait for input on non-connected socket.
Stefan Vogel <sv@exept.de>
parents:
207
diff
changeset
|
2718 |
} sa; |
464 | 2719 |
int alen, alen0; |
208
c3eca2cc16dc
accept: do not wait for input on non-connected socket.
Stefan Vogel <sv@exept.de>
parents:
207
diff
changeset
|
2720 |
struct hostent *he ; |
c3eca2cc16dc
accept: do not wait for input on non-connected socket.
Stefan Vogel <sv@exept.de>
parents:
207
diff
changeset
|
2721 |
char dotted[20] ; |
c3eca2cc16dc
accept: do not wait for input on non-connected socket.
Stefan Vogel <sv@exept.de>
parents:
207
diff
changeset
|
2722 |
|
c3eca2cc16dc
accept: do not wait for input on non-connected socket.
Stefan Vogel <sv@exept.de>
parents:
207
diff
changeset
|
2723 |
sock = _intVal(serverSocketFd); |
c3eca2cc16dc
accept: do not wait for input on non-connected socket.
Stefan Vogel <sv@exept.de>
parents:
207
diff
changeset
|
2724 |
|
c3eca2cc16dc
accept: do not wait for input on non-connected socket.
Stefan Vogel <sv@exept.de>
parents:
207
diff
changeset
|
2725 |
#if defined(O_NDELAY) && defined(SET_NDELAY) |
c3eca2cc16dc
accept: do not wait for input on non-connected socket.
Stefan Vogel <sv@exept.de>
parents:
207
diff
changeset
|
2726 |
flags = ioctl(sock, F_GETFL, 0); |
c3eca2cc16dc
accept: do not wait for input on non-connected socket.
Stefan Vogel <sv@exept.de>
parents:
207
diff
changeset
|
2727 |
ioctl(sock, F_SETFL, flags | O_NDELAY); |
c3eca2cc16dc
accept: do not wait for input on non-connected socket.
Stefan Vogel <sv@exept.de>
parents:
207
diff
changeset
|
2728 |
#endif |
464 | 2729 |
|
2730 |
#ifdef AF_INET |
|
2731 |
if (__INST(domain) == @symbol(inet)) { |
|
506
11ef93d12870
support anonymous (OS_specified) ports. (for FTP-protocol)
Claus Gittinger <cg@exept.de>
parents:
486
diff
changeset
|
2732 |
alen0 = sizeof(sa.in); |
464 | 2733 |
} |
2734 |
#endif |
|
530
067797c15b77
added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents:
529
diff
changeset
|
2735 |
#ifdef AF_INET6 |
067797c15b77
added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents:
529
diff
changeset
|
2736 |
if (__INST(domain) == @symbol(inet6)) { |
533
ced9950b551f
added query about which protocols are supported
Claus Gittinger <cg@exept.de>
parents:
532
diff
changeset
|
2737 |
alen0 = sizeof(sa.in6); |
530
067797c15b77
added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents:
529
diff
changeset
|
2738 |
} |
067797c15b77
added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents:
529
diff
changeset
|
2739 |
#endif |
464 | 2740 |
#ifdef AF_UNIX |
2741 |
if (__INST(domain) == @symbol(unix)) { |
|
506
11ef93d12870
support anonymous (OS_specified) ports. (for FTP-protocol)
Claus Gittinger <cg@exept.de>
parents:
486
diff
changeset
|
2742 |
alen0 = sizeof(sa.un); |
464 | 2743 |
} |
2744 |
#endif |
|
530
067797c15b77
added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents:
529
diff
changeset
|
2745 |
# ifdef AF_APPLETALK |
067797c15b77
added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents:
529
diff
changeset
|
2746 |
if (__INST(domain) == @symbol(appletalk)) { |
067797c15b77
added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents:
529
diff
changeset
|
2747 |
alen0 = sizeof(sa.at); |
067797c15b77
added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents:
529
diff
changeset
|
2748 |
} |
067797c15b77
added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents:
529
diff
changeset
|
2749 |
# endif |
067797c15b77
added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents:
529
diff
changeset
|
2750 |
|
524
8287da54eccf
more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents:
513
diff
changeset
|
2751 |
/* |
8287da54eccf
more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents:
513
diff
changeset
|
2752 |
* XXXX add addressing stuff for other domains here ... |
8287da54eccf
more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents:
513
diff
changeset
|
2753 |
*/ |
8287da54eccf
more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents:
513
diff
changeset
|
2754 |
# ifdef AF_X25 |
8287da54eccf
more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents:
513
diff
changeset
|
2755 |
if (__INST(domain) == @symbol(x25)) { |
8287da54eccf
more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents:
513
diff
changeset
|
2756 |
} |
8287da54eccf
more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents:
513
diff
changeset
|
2757 |
# endif |
8287da54eccf
more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents:
513
diff
changeset
|
2758 |
# ifdef AF_NS |
8287da54eccf
more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents:
513
diff
changeset
|
2759 |
if (__INST(domain) == @symbol(ns)) { |
8287da54eccf
more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents:
513
diff
changeset
|
2760 |
} |
8287da54eccf
more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents:
513
diff
changeset
|
2761 |
# endif |
8287da54eccf
more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents:
513
diff
changeset
|
2762 |
# ifdef AF_DECnet |
8287da54eccf
more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents:
513
diff
changeset
|
2763 |
if (__INST(domain) == @symbol(decnet)) { |
8287da54eccf
more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents:
513
diff
changeset
|
2764 |
} |
8287da54eccf
more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents:
513
diff
changeset
|
2765 |
# endif |
8287da54eccf
more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents:
513
diff
changeset
|
2766 |
# ifdef AF_SNA |
8287da54eccf
more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents:
513
diff
changeset
|
2767 |
if (__INST(domain) == @symbol(sna)) { |
8287da54eccf
more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents:
513
diff
changeset
|
2768 |
} |
8287da54eccf
more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents:
513
diff
changeset
|
2769 |
# endif |
8287da54eccf
more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents:
513
diff
changeset
|
2770 |
# ifdef AF_NS |
8287da54eccf
more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents:
513
diff
changeset
|
2771 |
if (__INST(domain) == @symbol(xns)) { |
8287da54eccf
more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents:
513
diff
changeset
|
2772 |
} |
8287da54eccf
more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents:
513
diff
changeset
|
2773 |
# endif |
8287da54eccf
more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents:
513
diff
changeset
|
2774 |
# ifdef AF_RAW |
8287da54eccf
more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents:
513
diff
changeset
|
2775 |
if (__INST(domain) == @symbol(raw)) { |
8287da54eccf
more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents:
513
diff
changeset
|
2776 |
} |
8287da54eccf
more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents:
513
diff
changeset
|
2777 |
# endif |
8287da54eccf
more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents:
513
diff
changeset
|
2778 |
# ifdef AF_ISO |
8287da54eccf
more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents:
513
diff
changeset
|
2779 |
if (__INST(domain) == @symbol(iso)) { |
8287da54eccf
more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents:
513
diff
changeset
|
2780 |
} |
8287da54eccf
more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents:
513
diff
changeset
|
2781 |
# endif |
8287da54eccf
more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents:
513
diff
changeset
|
2782 |
# ifdef AF_NETBIOS |
530
067797c15b77
added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents:
529
diff
changeset
|
2783 |
if (__INST(domain) == @symbol(netbios)) { |
067797c15b77
added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents:
529
diff
changeset
|
2784 |
} |
067797c15b77
added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents:
529
diff
changeset
|
2785 |
# endif |
067797c15b77
added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents:
529
diff
changeset
|
2786 |
# ifdef AF_IPX |
067797c15b77
added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents:
529
diff
changeset
|
2787 |
if (__INST(domain) == @symbol(ipx)) { |
067797c15b77
added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents:
529
diff
changeset
|
2788 |
} |
067797c15b77
added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents:
529
diff
changeset
|
2789 |
# endif |
067797c15b77
added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents:
529
diff
changeset
|
2790 |
# ifdef AF_BRIDGE |
067797c15b77
added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents:
529
diff
changeset
|
2791 |
if (__INST(domain) == @symbol(bridge)) { |
524
8287da54eccf
more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents:
513
diff
changeset
|
2792 |
} |
8287da54eccf
more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents:
513
diff
changeset
|
2793 |
# endif |
571 | 2794 |
# ifdef AF_BSC |
2795 |
if (__INST(domain) == @symbol(bsc)) { |
|
2796 |
} |
|
2797 |
# endif |
|
524
8287da54eccf
more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents:
513
diff
changeset
|
2798 |
# if defined(AF_CCITT) && (AF_CCITT != AF_X25) |
8287da54eccf
more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents:
513
diff
changeset
|
2799 |
if (__INST(domain) == @symbol(ccitt)) { |
8287da54eccf
more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents:
513
diff
changeset
|
2800 |
} |
8287da54eccf
more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents:
513
diff
changeset
|
2801 |
# endif |
464 | 2802 |
|
208
c3eca2cc16dc
accept: do not wait for input on non-connected socket.
Stefan Vogel <sv@exept.de>
parents:
207
diff
changeset
|
2803 |
__BEGIN_INTERRUPTABLE__ |
c3eca2cc16dc
accept: do not wait for input on non-connected socket.
Stefan Vogel <sv@exept.de>
parents:
207
diff
changeset
|
2804 |
do { |
506
11ef93d12870
support anonymous (OS_specified) ports. (for FTP-protocol)
Claus Gittinger <cg@exept.de>
parents:
486
diff
changeset
|
2805 |
alen = alen0; |
11ef93d12870
support anonymous (OS_specified) ports. (for FTP-protocol)
Claus Gittinger <cg@exept.de>
parents:
486
diff
changeset
|
2806 |
newSock = accept(sock, (struct sockaddr *) &sa, &alen); |
208
c3eca2cc16dc
accept: do not wait for input on non-connected socket.
Stefan Vogel <sv@exept.de>
parents:
207
diff
changeset
|
2807 |
} while ((newSock < 0) && (errno == EINTR)); |
c3eca2cc16dc
accept: do not wait for input on non-connected socket.
Stefan Vogel <sv@exept.de>
parents:
207
diff
changeset
|
2808 |
__END_INTERRUPTABLE__ |
c3eca2cc16dc
accept: do not wait for input on non-connected socket.
Stefan Vogel <sv@exept.de>
parents:
207
diff
changeset
|
2809 |
|
c3eca2cc16dc
accept: do not wait for input on non-connected socket.
Stefan Vogel <sv@exept.de>
parents:
207
diff
changeset
|
2810 |
#if defined(O_NDELAY) && defined(SET_NDELAY) |
c3eca2cc16dc
accept: do not wait for input on non-connected socket.
Stefan Vogel <sv@exept.de>
parents:
207
diff
changeset
|
2811 |
ioctl(sock, F_SETFL, flags); |
c3eca2cc16dc
accept: do not wait for input on non-connected socket.
Stefan Vogel <sv@exept.de>
parents:
207
diff
changeset
|
2812 |
#endif |
c3eca2cc16dc
accept: do not wait for input on non-connected socket.
Stefan Vogel <sv@exept.de>
parents:
207
diff
changeset
|
2813 |
|
c3eca2cc16dc
accept: do not wait for input on non-connected socket.
Stefan Vogel <sv@exept.de>
parents:
207
diff
changeset
|
2814 |
if (newSock < 0) { |
506
11ef93d12870
support anonymous (OS_specified) ports. (for FTP-protocol)
Claus Gittinger <cg@exept.de>
parents:
486
diff
changeset
|
2815 |
DBGPRINTF(("SOCKET: accept call failed errno=%d\n", errno)); |
11ef93d12870
support anonymous (OS_specified) ports. (for FTP-protocol)
Claus Gittinger <cg@exept.de>
parents:
486
diff
changeset
|
2816 |
__INST(lastErrorNumber) = __MKSMALLINT(errno); |
11ef93d12870
support anonymous (OS_specified) ports. (for FTP-protocol)
Claus Gittinger <cg@exept.de>
parents:
486
diff
changeset
|
2817 |
RETURN (false); |
208
c3eca2cc16dc
accept: do not wait for input on non-connected socket.
Stefan Vogel <sv@exept.de>
parents:
207
diff
changeset
|
2818 |
} |
c3eca2cc16dc
accept: do not wait for input on non-connected socket.
Stefan Vogel <sv@exept.de>
parents:
207
diff
changeset
|
2819 |
|
c3eca2cc16dc
accept: do not wait for input on non-connected socket.
Stefan Vogel <sv@exept.de>
parents:
207
diff
changeset
|
2820 |
/* |
c3eca2cc16dc
accept: do not wait for input on non-connected socket.
Stefan Vogel <sv@exept.de>
parents:
207
diff
changeset
|
2821 |
* extract the partners address |
c3eca2cc16dc
accept: do not wait for input on non-connected socket.
Stefan Vogel <sv@exept.de>
parents:
207
diff
changeset
|
2822 |
*/ |
c3eca2cc16dc
accept: do not wait for input on non-connected socket.
Stefan Vogel <sv@exept.de>
parents:
207
diff
changeset
|
2823 |
#ifdef AF_INET |
217 | 2824 |
if (__INST(domain) == @symbol(inet)) { |
650
8c5616f17ed6
made gethostbyaddr interruptable
Claus Gittinger <cg@exept.de>
parents:
649
diff
changeset
|
2825 |
GETHOSTBYADDR(he, (char *) &sa.in.sin_addr.s_addr, alen, AF_INET); |
506
11ef93d12870
support anonymous (OS_specified) ports. (for FTP-protocol)
Claus Gittinger <cg@exept.de>
parents:
486
diff
changeset
|
2826 |
if (! he) { |
11ef93d12870
support anonymous (OS_specified) ports. (for FTP-protocol)
Claus Gittinger <cg@exept.de>
parents:
486
diff
changeset
|
2827 |
unsigned long norder; |
11ef93d12870
support anonymous (OS_specified) ports. (for FTP-protocol)
Claus Gittinger <cg@exept.de>
parents:
486
diff
changeset
|
2828 |
|
11ef93d12870
support anonymous (OS_specified) ports. (for FTP-protocol)
Claus Gittinger <cg@exept.de>
parents:
486
diff
changeset
|
2829 |
norder = htonl(sa.in.sin_addr.s_addr) ; |
11ef93d12870
support anonymous (OS_specified) ports. (for FTP-protocol)
Claus Gittinger <cg@exept.de>
parents:
486
diff
changeset
|
2830 |
sprintf(dotted, "%d.%d.%d.%d", |
11ef93d12870
support anonymous (OS_specified) ports. (for FTP-protocol)
Claus Gittinger <cg@exept.de>
parents:
486
diff
changeset
|
2831 |
(norder >> 24) & 0xFF, |
11ef93d12870
support anonymous (OS_specified) ports. (for FTP-protocol)
Claus Gittinger <cg@exept.de>
parents:
486
diff
changeset
|
2832 |
(norder >> 16) & 0xFF, |
11ef93d12870
support anonymous (OS_specified) ports. (for FTP-protocol)
Claus Gittinger <cg@exept.de>
parents:
486
diff
changeset
|
2833 |
(norder >> 8) & 0xFF, |
11ef93d12870
support anonymous (OS_specified) ports. (for FTP-protocol)
Claus Gittinger <cg@exept.de>
parents:
486
diff
changeset
|
2834 |
norder & 0xFF); |
11ef93d12870
support anonymous (OS_specified) ports. (for FTP-protocol)
Claus Gittinger <cg@exept.de>
parents:
486
diff
changeset
|
2835 |
} |
11ef93d12870
support anonymous (OS_specified) ports. (for FTP-protocol)
Claus Gittinger <cg@exept.de>
parents:
486
diff
changeset
|
2836 |
DBGPRINTF(("SOCKET: accepted connection from host %s\n", (he ? he->h_name : dotted))) ; |
11ef93d12870
support anonymous (OS_specified) ports. (for FTP-protocol)
Claus Gittinger <cg@exept.de>
parents:
486
diff
changeset
|
2837 |
__INST(peerName) = __MKSTRING((he ? he->h_name : dotted)); |
11ef93d12870
support anonymous (OS_specified) ports. (for FTP-protocol)
Claus Gittinger <cg@exept.de>
parents:
486
diff
changeset
|
2838 |
__STORESELF(peerName); |
208
c3eca2cc16dc
accept: do not wait for input on non-connected socket.
Stefan Vogel <sv@exept.de>
parents:
207
diff
changeset
|
2839 |
} |
c3eca2cc16dc
accept: do not wait for input on non-connected socket.
Stefan Vogel <sv@exept.de>
parents:
207
diff
changeset
|
2840 |
#endif |
530
067797c15b77
added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents:
529
diff
changeset
|
2841 |
|
067797c15b77
added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents:
529
diff
changeset
|
2842 |
#ifdef AF_INET6 |
067797c15b77
added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents:
529
diff
changeset
|
2843 |
if (__INST(domain) == @symbol(inet6)) { |
650
8c5616f17ed6
made gethostbyaddr interruptable
Claus Gittinger <cg@exept.de>
parents:
649
diff
changeset
|
2844 |
GETHOSTBYADDR(he, (char *) &sa.in6.sin6_addr.s6_addr, alen, AF_INET6); |
533
ced9950b551f
added query about which protocols are supported
Claus Gittinger <cg@exept.de>
parents:
532
diff
changeset
|
2845 |
if (! he) { |
ced9950b551f
added query about which protocols are supported
Claus Gittinger <cg@exept.de>
parents:
532
diff
changeset
|
2846 |
unsigned long norder; |
530
067797c15b77
added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents:
529
diff
changeset
|
2847 |
|
067797c15b77
added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents:
529
diff
changeset
|
2848 |
/* |
067797c15b77
added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents:
529
diff
changeset
|
2849 |
* XXX: what is inet6's naming convention ? |
067797c15b77
added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents:
529
diff
changeset
|
2850 |
*/ |
533
ced9950b551f
added query about which protocols are supported
Claus Gittinger <cg@exept.de>
parents:
532
diff
changeset
|
2851 |
norder = htonl(sa.in.sin_addr.s_addr) ; |
ced9950b551f
added query about which protocols are supported
Claus Gittinger <cg@exept.de>
parents:
532
diff
changeset
|
2852 |
sprintf(dotted, "%d.%d.%d.%d", |
ced9950b551f
added query about which protocols are supported
Claus Gittinger <cg@exept.de>
parents:
532
diff
changeset
|
2853 |
sa.in6.sin6_addr.s6_addr[0], |
ced9950b551f
added query about which protocols are supported
Claus Gittinger <cg@exept.de>
parents:
532
diff
changeset
|
2854 |
sa.in6.sin6_addr.s6_addr[1], |
ced9950b551f
added query about which protocols are supported
Claus Gittinger <cg@exept.de>
parents:
532
diff
changeset
|
2855 |
sa.in6.sin6_addr.s6_addr[2], |
ced9950b551f
added query about which protocols are supported
Claus Gittinger <cg@exept.de>
parents:
532
diff
changeset
|
2856 |
sa.in6.sin6_addr.s6_addr[3], |
ced9950b551f
added query about which protocols are supported
Claus Gittinger <cg@exept.de>
parents:
532
diff
changeset
|
2857 |
sa.in6.sin6_addr.s6_addr[4], |
ced9950b551f
added query about which protocols are supported
Claus Gittinger <cg@exept.de>
parents:
532
diff
changeset
|
2858 |
sa.in6.sin6_addr.s6_addr[5]); |
ced9950b551f
added query about which protocols are supported
Claus Gittinger <cg@exept.de>
parents:
532
diff
changeset
|
2859 |
} |
ced9950b551f
added query about which protocols are supported
Claus Gittinger <cg@exept.de>
parents:
532
diff
changeset
|
2860 |
DBGPRINTF(("SOCKET: accepted connection from host %s\n", (he ? he->h_name : dotted))) ; |
ced9950b551f
added query about which protocols are supported
Claus Gittinger <cg@exept.de>
parents:
532
diff
changeset
|
2861 |
__INST(peerName) = __MKSTRING((he ? he->h_name : dotted)); |
ced9950b551f
added query about which protocols are supported
Claus Gittinger <cg@exept.de>
parents:
532
diff
changeset
|
2862 |
__STORESELF(peerName); |
530
067797c15b77
added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents:
529
diff
changeset
|
2863 |
} |
067797c15b77
added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents:
529
diff
changeset
|
2864 |
#endif |
067797c15b77
added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents:
529
diff
changeset
|
2865 |
|
208
c3eca2cc16dc
accept: do not wait for input on non-connected socket.
Stefan Vogel <sv@exept.de>
parents:
207
diff
changeset
|
2866 |
#ifdef AF_UNIX |
217 | 2867 |
if (__INST(domain) == @symbol(unix)) { |
506
11ef93d12870
support anonymous (OS_specified) ports. (for FTP-protocol)
Claus Gittinger <cg@exept.de>
parents:
486
diff
changeset
|
2868 |
DBGPRINTF(("SOCKET: accepted connection on unix socket\n")) ; |
11ef93d12870
support anonymous (OS_specified) ports. (for FTP-protocol)
Claus Gittinger <cg@exept.de>
parents:
486
diff
changeset
|
2869 |
/* nothing to be done here */ |
208
c3eca2cc16dc
accept: do not wait for input on non-connected socket.
Stefan Vogel <sv@exept.de>
parents:
207
diff
changeset
|
2870 |
} |
c3eca2cc16dc
accept: do not wait for input on non-connected socket.
Stefan Vogel <sv@exept.de>
parents:
207
diff
changeset
|
2871 |
#endif |
530
067797c15b77
added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents:
529
diff
changeset
|
2872 |
|
067797c15b77
added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents:
529
diff
changeset
|
2873 |
#ifdef AF_APPLETALK |
067797c15b77
added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents:
529
diff
changeset
|
2874 |
if (__INST(domain) == @symbol(appletalk)) { |
650
8c5616f17ed6
made gethostbyaddr interruptable
Claus Gittinger <cg@exept.de>
parents:
649
diff
changeset
|
2875 |
GETHOSTBYADDR(he, (char *) &sa.at.sat_addr, alen, AF_APPLETALK); |
533
ced9950b551f
added query about which protocols are supported
Claus Gittinger <cg@exept.de>
parents:
532
diff
changeset
|
2876 |
if (! he) { |
ced9950b551f
added query about which protocols are supported
Claus Gittinger <cg@exept.de>
parents:
532
diff
changeset
|
2877 |
unsigned net; |
530
067797c15b77
added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents:
529
diff
changeset
|
2878 |
|
067797c15b77
added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents:
529
diff
changeset
|
2879 |
/* |
067797c15b77
added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents:
529
diff
changeset
|
2880 |
* XXX: what is apples naming convention ? |
067797c15b77
added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents:
529
diff
changeset
|
2881 |
*/ |
533
ced9950b551f
added query about which protocols are supported
Claus Gittinger <cg@exept.de>
parents:
532
diff
changeset
|
2882 |
net = htons(sa.at.sat_addr.s_net) ; |
ced9950b551f
added query about which protocols are supported
Claus Gittinger <cg@exept.de>
parents:
532
diff
changeset
|
2883 |
sprintf(dotted, "%d.%d", |
ced9950b551f
added query about which protocols are supported
Claus Gittinger <cg@exept.de>
parents:
532
diff
changeset
|
2884 |
net, |
ced9950b551f
added query about which protocols are supported
Claus Gittinger <cg@exept.de>
parents:
532
diff
changeset
|
2885 |
sa.at.sat_addr.s_node); |
ced9950b551f
added query about which protocols are supported
Claus Gittinger <cg@exept.de>
parents:
532
diff
changeset
|
2886 |
} |
ced9950b551f
added query about which protocols are supported
Claus Gittinger <cg@exept.de>
parents:
532
diff
changeset
|
2887 |
DBGPRINTF(("SOCKET: accepted connection from host %s\n", (he ? he->h_name : dotted))) ; |
ced9950b551f
added query about which protocols are supported
Claus Gittinger <cg@exept.de>
parents:
532
diff
changeset
|
2888 |
__INST(peerName) = __MKSTRING((he ? he->h_name : dotted)); |
ced9950b551f
added query about which protocols are supported
Claus Gittinger <cg@exept.de>
parents:
532
diff
changeset
|
2889 |
__STORESELF(peerName); |
530
067797c15b77
added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents:
529
diff
changeset
|
2890 |
} |
067797c15b77
added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents:
529
diff
changeset
|
2891 |
# endif |
067797c15b77
added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents:
529
diff
changeset
|
2892 |
|
524
8287da54eccf
more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents:
513
diff
changeset
|
2893 |
/* |
8287da54eccf
more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents:
513
diff
changeset
|
2894 |
* XXXX add addressing stuff for other domains here ... |
8287da54eccf
more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents:
513
diff
changeset
|
2895 |
*/ |
8287da54eccf
more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents:
513
diff
changeset
|
2896 |
# ifdef AF_X25 |
8287da54eccf
more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents:
513
diff
changeset
|
2897 |
if (__INST(domain) == @symbol(x25)) { |
8287da54eccf
more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents:
513
diff
changeset
|
2898 |
} |
8287da54eccf
more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents:
513
diff
changeset
|
2899 |
# endif |
8287da54eccf
more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents:
513
diff
changeset
|
2900 |
# ifdef AF_NS |
8287da54eccf
more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents:
513
diff
changeset
|
2901 |
if (__INST(domain) == @symbol(ns)) { |
8287da54eccf
more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents:
513
diff
changeset
|
2902 |
} |
8287da54eccf
more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents:
513
diff
changeset
|
2903 |
# endif |
8287da54eccf
more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents:
513
diff
changeset
|
2904 |
# ifdef AF_DECnet |
8287da54eccf
more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents:
513
diff
changeset
|
2905 |
if (__INST(domain) == @symbol(decnet)) { |
8287da54eccf
more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents:
513
diff
changeset
|
2906 |
} |
8287da54eccf
more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents:
513
diff
changeset
|
2907 |
# endif |
8287da54eccf
more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents:
513
diff
changeset
|
2908 |
# ifdef AF_SNA |
8287da54eccf
more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents:
513
diff
changeset
|
2909 |
if (__INST(domain) == @symbol(sna)) { |
8287da54eccf
more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents:
513
diff
changeset
|
2910 |
} |
8287da54eccf
more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents:
513
diff
changeset
|
2911 |
# endif |
8287da54eccf
more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents:
513
diff
changeset
|
2912 |
# ifdef AF_NS |
8287da54eccf
more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents:
513
diff
changeset
|
2913 |
if (__INST(domain) == @symbol(xns)) { |
8287da54eccf
more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents:
513
diff
changeset
|
2914 |
} |
8287da54eccf
more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents:
513
diff
changeset
|
2915 |
# endif |
8287da54eccf
more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents:
513
diff
changeset
|
2916 |
# ifdef AF_RAW |
8287da54eccf
more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents:
513
diff
changeset
|
2917 |
if (__INST(domain) == @symbol(raw)) { |
8287da54eccf
more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents:
513
diff
changeset
|
2918 |
} |
8287da54eccf
more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents:
513
diff
changeset
|
2919 |
# endif |
8287da54eccf
more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents:
513
diff
changeset
|
2920 |
# ifdef AF_ISO |
8287da54eccf
more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents:
513
diff
changeset
|
2921 |
if (__INST(domain) == @symbol(iso)) { |
8287da54eccf
more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents:
513
diff
changeset
|
2922 |
} |
8287da54eccf
more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents:
513
diff
changeset
|
2923 |
# endif |
8287da54eccf
more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents:
513
diff
changeset
|
2924 |
# ifdef AF_NETBIOS |
530
067797c15b77
added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents:
529
diff
changeset
|
2925 |
if (__INST(domain) == @symbol(netbios)) { |
067797c15b77
added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents:
529
diff
changeset
|
2926 |
} |
067797c15b77
added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents:
529
diff
changeset
|
2927 |
# endif |
067797c15b77
added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents:
529
diff
changeset
|
2928 |
# ifdef AF_IPX |
067797c15b77
added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents:
529
diff
changeset
|
2929 |
if (__INST(domain) == @symbol(ipx)) { |
067797c15b77
added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents:
529
diff
changeset
|
2930 |
} |
067797c15b77
added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents:
529
diff
changeset
|
2931 |
# endif |
067797c15b77
added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents:
529
diff
changeset
|
2932 |
# ifdef AF_BRIDGE |
067797c15b77
added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents:
529
diff
changeset
|
2933 |
if (__INST(domain) == @symbol(bridge)) { |
524
8287da54eccf
more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents:
513
diff
changeset
|
2934 |
} |
8287da54eccf
more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents:
513
diff
changeset
|
2935 |
# endif |
571 | 2936 |
# ifdef AF_BSC |
2937 |
if (__INST(domain) == @symbol(bsc)) { |
|
2938 |
} |
|
2939 |
# endif |
|
524
8287da54eccf
more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents:
513
diff
changeset
|
2940 |
# if defined(AF_CCITT) && (AF_CCITT != AF_X25) |
8287da54eccf
more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents:
513
diff
changeset
|
2941 |
if (__INST(domain) == @symbol(ccitt)) { |
8287da54eccf
more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents:
513
diff
changeset
|
2942 |
} |
8287da54eccf
more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents:
513
diff
changeset
|
2943 |
# endif |
208
c3eca2cc16dc
accept: do not wait for input on non-connected socket.
Stefan Vogel <sv@exept.de>
parents:
207
diff
changeset
|
2944 |
|
c3eca2cc16dc
accept: do not wait for input on non-connected socket.
Stefan Vogel <sv@exept.de>
parents:
207
diff
changeset
|
2945 |
/* |
c3eca2cc16dc
accept: do not wait for input on non-connected socket.
Stefan Vogel <sv@exept.de>
parents:
207
diff
changeset
|
2946 |
* make it a FILE * |
c3eca2cc16dc
accept: do not wait for input on non-connected socket.
Stefan Vogel <sv@exept.de>
parents:
207
diff
changeset
|
2947 |
*/ |
c3eca2cc16dc
accept: do not wait for input on non-connected socket.
Stefan Vogel <sv@exept.de>
parents:
207
diff
changeset
|
2948 |
fp = fdopen(newSock, "r+"); |
c3eca2cc16dc
accept: do not wait for input on non-connected socket.
Stefan Vogel <sv@exept.de>
parents:
207
diff
changeset
|
2949 |
if (! fp) { |
506
11ef93d12870
support anonymous (OS_specified) ports. (for FTP-protocol)
Claus Gittinger <cg@exept.de>
parents:
486
diff
changeset
|
2950 |
DBGPRINTF(("SOCKET: fdopen call failed\n")); |
11ef93d12870
support anonymous (OS_specified) ports. (for FTP-protocol)
Claus Gittinger <cg@exept.de>
parents:
486
diff
changeset
|
2951 |
__INST(lastErrorNumber) = __MKSMALLINT(errno); |
11ef93d12870
support anonymous (OS_specified) ports. (for FTP-protocol)
Claus Gittinger <cg@exept.de>
parents:
486
diff
changeset
|
2952 |
close(newSock); |
11ef93d12870
support anonymous (OS_specified) ports. (for FTP-protocol)
Claus Gittinger <cg@exept.de>
parents:
486
diff
changeset
|
2953 |
RETURN (false); |
208
c3eca2cc16dc
accept: do not wait for input on non-connected socket.
Stefan Vogel <sv@exept.de>
parents:
207
diff
changeset
|
2954 |
} else { |
444 | 2955 |
#ifdef BUGGY_STDIO_LIB |
506
11ef93d12870
support anonymous (OS_specified) ports. (for FTP-protocol)
Claus Gittinger <cg@exept.de>
parents:
486
diff
changeset
|
2956 |
setbuf(fp, NULL); |
11ef93d12870
support anonymous (OS_specified) ports. (for FTP-protocol)
Claus Gittinger <cg@exept.de>
parents:
486
diff
changeset
|
2957 |
__INST(buffered) = false; |
208
c3eca2cc16dc
accept: do not wait for input on non-connected socket.
Stefan Vogel <sv@exept.de>
parents:
207
diff
changeset
|
2958 |
#endif |
506
11ef93d12870
support anonymous (OS_specified) ports. (for FTP-protocol)
Claus Gittinger <cg@exept.de>
parents:
486
diff
changeset
|
2959 |
__INST(filePointer) = __MKOBJ(fp); |
11ef93d12870
support anonymous (OS_specified) ports. (for FTP-protocol)
Claus Gittinger <cg@exept.de>
parents:
486
diff
changeset
|
2960 |
__STORESELF(filePointer); |
208
c3eca2cc16dc
accept: do not wait for input on non-connected socket.
Stefan Vogel <sv@exept.de>
parents:
207
diff
changeset
|
2961 |
} |
418 | 2962 |
#endif |
208
c3eca2cc16dc
accept: do not wait for input on non-connected socket.
Stefan Vogel <sv@exept.de>
parents:
207
diff
changeset
|
2963 |
%}. |
c3eca2cc16dc
accept: do not wait for input on non-connected socket.
Stefan Vogel <sv@exept.de>
parents:
207
diff
changeset
|
2964 |
mode := #readwrite. |
c3eca2cc16dc
accept: do not wait for input on non-connected socket.
Stefan Vogel <sv@exept.de>
parents:
207
diff
changeset
|
2965 |
Lobby register:self. |
c3eca2cc16dc
accept: do not wait for input on non-connected socket.
Stefan Vogel <sv@exept.de>
parents:
207
diff
changeset
|
2966 |
binary := false. |
c3eca2cc16dc
accept: do not wait for input on non-connected socket.
Stefan Vogel <sv@exept.de>
parents:
207
diff
changeset
|
2967 |
port := aSocket port. |
c3eca2cc16dc
accept: do not wait for input on non-connected socket.
Stefan Vogel <sv@exept.de>
parents:
207
diff
changeset
|
2968 |
^ true |
c3eca2cc16dc
accept: do not wait for input on non-connected socket.
Stefan Vogel <sv@exept.de>
parents:
207
diff
changeset
|
2969 |
! |
c3eca2cc16dc
accept: do not wait for input on non-connected socket.
Stefan Vogel <sv@exept.de>
parents:
207
diff
changeset
|
2970 |
|
126 | 2971 |
closeFile |
2972 |
"low level close" |
|
99
7d016cc30052
fixed & moved pingWalk from SNMPSession to here;
Claus Gittinger <cg@exept.de>
parents:
98
diff
changeset
|
2973 |
|
126 | 2974 |
%{ /* NOCONTEXT */ |
418 | 2975 |
#ifndef NO_SOCKET |
126 | 2976 |
|
2977 |
OBJ t; |
|
99
7d016cc30052
fixed & moved pingWalk from SNMPSession to here;
Claus Gittinger <cg@exept.de>
parents:
98
diff
changeset
|
2978 |
|
217 | 2979 |
t = __INST(filePointer); |
126 | 2980 |
if (t != nil) { |
2981 |
FILE *fp; |
|
99
7d016cc30052
fixed & moved pingWalk from SNMPSession to here;
Claus Gittinger <cg@exept.de>
parents:
98
diff
changeset
|
2982 |
|
126 | 2983 |
fp = __FILEVal(t); |
2984 |
fflush(fp); |
|
2985 |
shutdown(fileno(fp), 2); |
|
2986 |
fclose(fp); |
|
217 | 2987 |
__INST(filePointer) = nil; |
126 | 2988 |
} |
418 | 2989 |
#endif |
126 | 2990 |
%} |
99
7d016cc30052
fixed & moved pingWalk from SNMPSession to here;
Claus Gittinger <cg@exept.de>
parents:
98
diff
changeset
|
2991 |
! |
7d016cc30052
fixed & moved pingWalk from SNMPSession to here;
Claus Gittinger <cg@exept.de>
parents:
98
diff
changeset
|
2992 |
|
116
7789fb1c9fa2
more UD socket fixes (at least client side seems to work now)
Claus Gittinger <cg@exept.de>
parents:
115
diff
changeset
|
2993 |
connectTo:hostOrPathName port:portNrOrName |
71 | 2994 |
"low level connect; connect to port, portNrOrName on host, hostName. |
116
7789fb1c9fa2
more UD socket fixes (at least client side seems to work now)
Claus Gittinger <cg@exept.de>
parents:
115
diff
changeset
|
2995 |
For unix-domain sockets, the port argument is ignored and pathName is taken. |
115 | 2996 |
Other sockets are not yet implemented. |
71 | 2997 |
Return true if ok, false otherwise. |
99
7d016cc30052
fixed & moved pingWalk from SNMPSession to here;
Claus Gittinger <cg@exept.de>
parents:
98
diff
changeset
|
2998 |
Hostname must be a string, portNrOrName an integer port number (in inet domain). |
7d016cc30052
fixed & moved pingWalk from SNMPSession to here;
Claus Gittinger <cg@exept.de>
parents:
98
diff
changeset
|
2999 |
The current process will block (but not the whole Smalltalk) until the connection |
116
7789fb1c9fa2
more UD socket fixes (at least client side seems to work now)
Claus Gittinger <cg@exept.de>
parents:
115
diff
changeset
|
3000 |
is established. |
7789fb1c9fa2
more UD socket fixes (at least client side seems to work now)
Claus Gittinger <cg@exept.de>
parents:
115
diff
changeset
|
3001 |
See also: #connectTo:port:withTimeout: for a somewhat nicer interface." |
28 | 3002 |
|
649 | 3003 |
^ self connectTo:hostOrPathName port:portNrOrName blocking:false |
3004 |
! |
|
3005 |
||
3006 |
connectTo:hostOrPathName port:portNrOrName blocking:blocking |
|
3007 |
"low level connect; connect to port, portNrOrName on host, hostName. |
|
3008 |
For unix-domain sockets, the port argument is ignored and pathName is taken. |
|
3009 |
Other sockets are not yet implemented. |
|
3010 |
Return true if ok, false otherwise. |
|
3011 |
Hostname must be a string, portNrOrName an integer port number (in inet domain). |
|
3012 |
The current process will block (but not the whole Smalltalk) until the connection |
|
3013 |
is established. |
|
3014 |
See also: #connectTo:port:withTimeout: for a somewhat nicer interface." |
|
3015 |
||
430
12d736316f69
Fix #connectTo:port: Do not call connect() when we get EINPROGRESS
Stefan Vogel <sv@exept.de>
parents:
429
diff
changeset
|
3016 |
|isAsync| |
12d736316f69
Fix #connectTo:port: Do not call connect() when we get EINPROGRESS
Stefan Vogel <sv@exept.de>
parents:
429
diff
changeset
|
3017 |
|
28 | 3018 |
filePointer isNil ifTrue:[ |
649 | 3019 |
^ self error:'not a valid socket' |
28 | 3020 |
]. |
0 | 3021 |
%{ |
649 | 3022 |
|
418 | 3023 |
#ifndef NO_SOCKET |
217 | 3024 |
OBJ t = __INST(filePointer); |
71 | 3025 |
OBJ myDomain; |
115 | 3026 |
union { |
525 | 3027 |
# ifdef AF_INET |
649 | 3028 |
struct sockaddr_in in ; |
525 | 3029 |
# endif |
530
067797c15b77
added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents:
529
diff
changeset
|
3030 |
# ifdef AF_INET6 |
649 | 3031 |
struct sockaddr_in6 in6; |
530
067797c15b77
added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents:
529
diff
changeset
|
3032 |
# endif |
524
8287da54eccf
more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents:
513
diff
changeset
|
3033 |
# ifdef AF_UNIX |
649 | 3034 |
struct sockaddr_un un; |
524
8287da54eccf
more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents:
513
diff
changeset
|
3035 |
# endif |
525 | 3036 |
# ifdef AF_APPLETALK |
649 | 3037 |
struct sockaddr_at at; |
525 | 3038 |
# endif |
115 | 3039 |
} sa; |
28 | 3040 |
struct hostent *hp ; |
3041 |
int a, sock ; |
|
3042 |
long addr; |
|
3043 |
FILE *fp; |
|
649 | 3044 |
int ret, oldFlags; |
28 | 3045 |
int on = 1; |
3046 |
int ok; |
|
115 | 3047 |
int sockaddr_size; |
28 | 3048 |
|
217 | 3049 |
if (!__isString(__INST(domain)) && !__isSymbol(__INST(domain))) { |
649 | 3050 |
DBGPRINTF(("SOCKET: invalid domain arg\n")); |
3051 |
RETURN (false); |
|
28 | 3052 |
} |
3053 |
||
3054 |
ok = 0; |
|
217 | 3055 |
myDomain = __INST(domain); |
115 | 3056 |
bzero((char *) &sa, sizeof(sa)) ; |
508 | 3057 |
|
28 | 3058 |
#ifdef AF_INET |
71 | 3059 |
if (myDomain == @symbol(inet)) { |
649 | 3060 |
/* |
3061 |
* INET addressing: port must be a smallInteger; |
|
3062 |
* hostOrPathName the name of the host (dot notation allowed) |
|
3063 |
* or a byteArray containing the 4 address bytes. |
|
3064 |
*/ |
|
3065 |
if (! __isSmallInteger(portNrOrName)) { |
|
3066 |
DBGPRINTF(("SOCKET: invalid port arg\n")); |
|
3067 |
RETURN (false); |
|
3068 |
} |
|
3069 |
||
3070 |
sa.in.sin_family = AF_INET; |
|
3071 |
sa.in.sin_port = htons((u_short) _intVal(portNrOrName)) ; |
|
3072 |
||
3073 |
if (__isByteArray(hostOrPathName)) { |
|
3074 |
unsigned char *cp; |
|
3075 |
int n; |
|
3076 |
||
3077 |
cp = __ByteArrayInstPtr(hostOrPathName)->ba_element; |
|
3078 |
n = __byteArraySize(hostOrPathName); |
|
3079 |
if (n > 4) n = 4; |
|
3080 |
bcopy(cp, &sa.in.sin_addr.s_addr, n); |
|
3081 |
} else { |
|
3082 |
if (! __isString(hostOrPathName)) { |
|
3083 |
DBGPRINTF(("SOCKET: invalid hostname arg\n")); |
|
3084 |
RETURN (false); |
|
3085 |
} |
|
3086 |
||
3087 |
if ((addr = inet_addr(__stringVal(hostOrPathName))) != -1) { |
|
3088 |
/* |
|
3089 |
* is Internet addr in octet notation |
|
3090 |
*/ |
|
3091 |
bcopy(&addr, (char *) &sa.in.sin_addr, sizeof(addr)) ; /* set address */ |
|
3092 |
} else { |
|
3093 |
/* |
|
3094 |
* do we know the host's address? |
|
3095 |
*/ |
|
3096 |
GETHOSTBYNAME(hp, __stringVal(hostOrPathName)) |
|
3097 |
if (hp == NULL) { |
|
3098 |
DBGPRINTF(("SOCKET: unknown host:%s\n", __stringVal(hostOrPathName))); |
|
3099 |
RETURN (false); |
|
3100 |
} |
|
3101 |
bcopy(hp->h_addr, (char *) &sa.in.sin_addr, hp->h_length) ; |
|
3102 |
sa.in.sin_family = hp->h_addrtype; |
|
3103 |
} |
|
3104 |
} |
|
3105 |
||
3106 |
DBGPRINTF(("SOCKET: connect addr: %x port: %d\n", sa.in.sin_addr, sa.in.sin_port)); |
|
3107 |
||
3108 |
sockaddr_size = sizeof(struct sockaddr_in); |
|
3109 |
ok = 1; |
|
116
7789fb1c9fa2
more UD socket fixes (at least client side seems to work now)
Claus Gittinger <cg@exept.de>
parents:
115
diff
changeset
|
3110 |
} |
525 | 3111 |
#endif /* AF_INET */ |
3112 |
||
530
067797c15b77
added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents:
529
diff
changeset
|
3113 |
#ifdef AF_INET6 |
067797c15b77
added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents:
529
diff
changeset
|
3114 |
if (myDomain == @symbol(inet6)) { |
649 | 3115 |
/* |
3116 |
* INET6 addressing: port must be a smallInteger; |
|
3117 |
* hostOrPathName the name of the host |
|
3118 |
* or a byteArray containing the 6 address bytes. |
|
3119 |
*/ |
|
3120 |
if (! __isSmallInteger(portNrOrName)) { |
|
3121 |
DBGPRINTF(("SOCKET: invalid port arg\n")); |
|
3122 |
RETURN (false); |
|
3123 |
} |
|
3124 |
||
3125 |
sa.in6.sin6_family = AF_INET6; |
|
3126 |
sa.in6.sin6_port = htons((u_short) _intVal(portNrOrName)) ; |
|
3127 |
||
3128 |
if (__isByteArray(hostOrPathName)) { |
|
3129 |
unsigned char *cp; |
|
3130 |
int n; |
|
3131 |
||
3132 |
cp = __ByteArrayInstPtr(hostOrPathName)->ba_element; |
|
3133 |
n = __byteArraySize(hostOrPathName); |
|
3134 |
if (n > 6) n = 6; |
|
3135 |
bcopy(cp, &sa.in6.sin6_addr.s6_addr, n); |
|
3136 |
} else { |
|
3137 |
if (! __isString(hostOrPathName)) { |
|
3138 |
DBGPRINTF(("SOCKET: invalid hostname arg\n")); |
|
3139 |
RETURN (false); |
|
3140 |
} |
|
3141 |
||
3142 |
/* |
|
3143 |
* do we know the host's address? |
|
3144 |
*/ |
|
3145 |
GETHOSTBYNAME(hp, __stringVal(hostOrPathName)) |
|
3146 |
if (hp == NULL) { |
|
3147 |
DBGPRINTF(("SOCKET: unknown host:%s\n", __stringVal(hostOrPathName))); |
|
3148 |
RETURN (false); |
|
3149 |
} |
|
3150 |
bcopy(hp->h_addr, (char *) &sa.in.sin_addr, hp->h_length) ; |
|
3151 |
sa.in.sin_family = hp->h_addrtype; |
|
3152 |
} |
|
3153 |
||
3154 |
DBGPRINTF(("SOCKET: connect addr: %x.%x.%x.%x.%x.%x port: %d\n", |
|
3155 |
sa.in6.sin6_addr.s6_addr[0], |
|
3156 |
sa.in6.sin6_addr.s6_addr[1], |
|
3157 |
sa.in6.sin6_addr.s6_addr[2], |
|
3158 |
sa.in6.sin6_addr.s6_addr[3], |
|
3159 |
sa.in6.sin6_addr.s6_addr[4], |
|
3160 |
sa.in6.sin6_addr.s6_addr[5], |
|
3161 |
sa.in6.sin6_port)); |
|
3162 |
||
3163 |
sockaddr_size = sizeof(struct sockaddr_in6); |
|
3164 |
ok = 1; |
|
530
067797c15b77
added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents:
529
diff
changeset
|
3165 |
} |
067797c15b77
added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents:
529
diff
changeset
|
3166 |
#endif /* AF_INET6 */ |
067797c15b77
added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents:
529
diff
changeset
|
3167 |
|
116
7789fb1c9fa2
more UD socket fixes (at least client side seems to work now)
Claus Gittinger <cg@exept.de>
parents:
115
diff
changeset
|
3168 |
#ifdef AF_UNIX |
7789fb1c9fa2
more UD socket fixes (at least client side seems to work now)
Claus Gittinger <cg@exept.de>
parents:
115
diff
changeset
|
3169 |
if (myDomain == @symbol(unix)) { |
649 | 3170 |
char *pathName; |
3171 |
int l; |
|
3172 |
||
3173 |
/* |
|
3174 |
* UNIX domain: port is ignored; |
|
3175 |
* hostOrPathName is a pathName |
|
3176 |
*/ |
|
3177 |
if (! __isString(hostOrPathName)) { |
|
3178 |
DBGPRINTF(("SOCKET: invalid port (pathname) arg\n")); |
|
3179 |
RETURN (false); |
|
3180 |
} |
|
3181 |
pathName = (char *) __stringVal(hostOrPathName); |
|
3182 |
l = strlen(pathName); |
|
3183 |
if ((l + sizeof ( sa.un.sun_family )) > sizeof(struct sockaddr_un)) { |
|
3184 |
DBGPRINTF(("SOCKET: pathname too long\n")); |
|
3185 |
RETURN (false); |
|
3186 |
} |
|
3187 |
||
3188 |
strcpy(sa.un.sun_path, pathName); |
|
3189 |
sa.un.sun_family = AF_UNIX; |
|
3190 |
sockaddr_size = l + sizeof ( sa.un.sun_family ); |
|
3191 |
ok = 1; |
|
28 | 3192 |
} |
525 | 3193 |
#endif /* AF_UNIX */ |
3194 |
||
3195 |
#ifdef AF_APPLETALK |
|
3196 |
if (myDomain == @symbol(appletalk)) { |
|
649 | 3197 |
/* |
3198 |
* APPLETALK addressing: port must be a smallInteger; |
|
3199 |
* hostOrPathName the name of the host |
|
3200 |
* or a byteArray containing the 3 address bytes. |
|
3201 |
*/ |
|
3202 |
if (! __isSmallInteger(portNrOrName)) { |
|
3203 |
DBGPRINTF(("SOCKET: invalid port arg\n")); |
|
3204 |
RETURN (false); |
|
3205 |
} |
|
3206 |
||
3207 |
sa.at.sat_family = AF_APPLETALK; |
|
3208 |
sa.at.sat_port = __intVal(portNrOrName); |
|
3209 |
||
3210 |
if (__isByteArray(hostOrPathName)) { |
|
3211 |
unsigned char *cp; |
|
3212 |
int n; |
|
3213 |
||
3214 |
cp = __ByteArrayInstPtr(hostOrPathName)->ba_element; |
|
3215 |
n = __byteArraySize(hostOrPathName); |
|
3216 |
if (n > 3) n = 3; |
|
3217 |
bcopy(cp, &sa.at.sat_addr, n); |
|
3218 |
} else { |
|
3219 |
if (! __isString(hostOrPathName)) { |
|
3220 |
DBGPRINTF(("SOCKET: invalid hostname arg\n")); |
|
3221 |
RETURN (false); |
|
3222 |
} |
|
3223 |
||
3224 |
/* |
|
3225 |
* do we know the host's address? |
|
3226 |
*/ |
|
3227 |
GETHOSTBYNAME(hp, __stringVal(hostOrPathName)) |
|
3228 |
if (hp == NULL) { |
|
3229 |
DBGPRINTF(("SOCKET: unknown host:%s\n", __stringVal(hostOrPathName))); |
|
3230 |
RETURN (false); |
|
3231 |
} |
|
3232 |
if (hp->h_addrtype != AF_APPLETALK) { |
|
3233 |
DBGPRINTF(("SOCKET: host:%s is not an appletalk host\n", __stringVal(hostOrPathName))); |
|
3234 |
RETURN (false); |
|
3235 |
} |
|
3236 |
||
3237 |
bcopy(hp->h_addr, (char *) &sa.at.sat_addr, hp->h_length) ; |
|
3238 |
sa.at.sat_family = hp->h_addrtype; |
|
3239 |
} |
|
3240 |
||
3241 |
DBGPRINTF(("SOCKET: connect addr: %x port: %d\n", sa.in.sin_addr, sa.in.sin_port)); |
|
3242 |
||
3243 |
sockaddr_size = sizeof(struct sockaddr_at); |
|
3244 |
ok = 1; |
|
525 | 3245 |
} |
3246 |
#endif /* APPLETALK */ |
|
3247 |
||
28 | 3248 |
/* |
3249 |
* XXXX add addressing stuff for other domains here ... |
|
3250 |
*/ |
|
3251 |
#ifdef AF_X25 |
|
71 | 3252 |
if (myDomain == @symbol(x25)) { |
28 | 3253 |
} |
3254 |
#endif |
|
3255 |
#ifdef AF_NS |
|
71 | 3256 |
if (myDomain == @symbol(ns)) { |
28 | 3257 |
} |
3258 |
#endif |
|
524
8287da54eccf
more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents:
513
diff
changeset
|
3259 |
# ifdef AF_DECnet |
8287da54eccf
more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents:
513
diff
changeset
|
3260 |
if (myDomain == @symbol(decnet)) { |
8287da54eccf
more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents:
513
diff
changeset
|
3261 |
} |
8287da54eccf
more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents:
513
diff
changeset
|
3262 |
# endif |
93 | 3263 |
#ifdef AF_NS |
3264 |
if (myDomain == @symbol(xns)) { |
|
3265 |
} |
|
3266 |
#endif |
|
3267 |
#ifdef AF_SNA |
|
3268 |
if (myDomain == @symbol(sna)) { |
|
3269 |
} |
|
3270 |
#endif |
|
3271 |
#ifdef AF_RAW |
|
3272 |
if (myDomain == @symbol(raw)) { |
|
3273 |
} |
|
3274 |
#endif |
|
524
8287da54eccf
more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents:
513
diff
changeset
|
3275 |
# ifdef AF_ISO |
8287da54eccf
more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents:
513
diff
changeset
|
3276 |
if (myDomain == @symbol(iso)) { |
8287da54eccf
more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents:
513
diff
changeset
|
3277 |
} |
8287da54eccf
more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents:
513
diff
changeset
|
3278 |
# endif |
8287da54eccf
more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents:
513
diff
changeset
|
3279 |
# ifdef AF_NETBIOS |
530
067797c15b77
added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents:
529
diff
changeset
|
3280 |
if (myDomain == @symbol(netbios)) { |
067797c15b77
added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents:
529
diff
changeset
|
3281 |
} |
067797c15b77
added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents:
529
diff
changeset
|
3282 |
# endif |
067797c15b77
added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents:
529
diff
changeset
|
3283 |
# ifdef AF_IPX |
067797c15b77
added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents:
529
diff
changeset
|
3284 |
if (myDomain == @symbol(ipx)) { |
067797c15b77
added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents:
529
diff
changeset
|
3285 |
} |
067797c15b77
added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents:
529
diff
changeset
|
3286 |
# endif |
067797c15b77
added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents:
529
diff
changeset
|
3287 |
# ifdef AF_BRIDGE |
067797c15b77
added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents:
529
diff
changeset
|
3288 |
if (myDomain == @symbol(bridge)) { |
524
8287da54eccf
more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents:
513
diff
changeset
|
3289 |
} |
8287da54eccf
more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents:
513
diff
changeset
|
3290 |
# endif |
571 | 3291 |
# ifdef AF_BSC |
3292 |
if (myDomain == @symbol(bsc)) { |
|
3293 |
} |
|
3294 |
# endif |
|
524
8287da54eccf
more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents:
513
diff
changeset
|
3295 |
# if defined(AF_CCITT) && (AF_CCITT != AF_X25) |
8287da54eccf
more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents:
513
diff
changeset
|
3296 |
if (myDomain == @symbol(ccitt)) { |
8287da54eccf
more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents:
513
diff
changeset
|
3297 |
} |
8287da54eccf
more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents:
513
diff
changeset
|
3298 |
# endif |
28 | 3299 |
|
3300 |
if (! ok) { |
|
649 | 3301 |
DBGPRINTF(("SOCKET: unsupported domain\n")); |
3302 |
RETURN (false); |
|
28 | 3303 |
} |
3304 |
||
110
7af19ae8693b
use new FILE* wrapper macros (based on externalAddress)
Claus Gittinger <cg@exept.de>
parents:
106
diff
changeset
|
3305 |
sock = fileno(__FILEVal(t)); |
28 | 3306 |
|
649 | 3307 |
#if defined(O_NONBLOCK) |
3308 |
if (blocking != true) { |
|
3309 |
/* |
|
3310 |
* set to non-blocking and wait later |
|
3311 |
*/ |
|
3312 |
oldFlags = fcntl(sock, F_GETFL, 0); |
|
3313 |
/* on SUNOS4.x, would use fcntl(osfd, F_SETFL, flags | FNDELAY); */ |
|
3314 |
fcntl(sock, F_SETFL, oldFlags | O_NONBLOCK); |
|
3315 |
} |
|
3316 |
#endif |
|
3317 |
||
28 | 3318 |
/* |
3319 |
* connect |
|
3320 |
*/ |
|
81 | 3321 |
__BEGIN_INTERRUPTABLE__ |
28 | 3322 |
do { |
649 | 3323 |
ret = connect(sock, (struct sockaddr *)&sa, sockaddr_size); |
116
7789fb1c9fa2
more UD socket fixes (at least client side seems to work now)
Claus Gittinger <cg@exept.de>
parents:
115
diff
changeset
|
3324 |
} while ((ret < 0) |
649 | 3325 |
&& ((errno == EINTR) |
116
7789fb1c9fa2
more UD socket fixes (at least client side seems to work now)
Claus Gittinger <cg@exept.de>
parents:
115
diff
changeset
|
3326 |
#ifdef EAGAIN |
649 | 3327 |
|| (errno == EAGAIN) |
116
7789fb1c9fa2
more UD socket fixes (at least client side seems to work now)
Claus Gittinger <cg@exept.de>
parents:
115
diff
changeset
|
3328 |
#endif |
649 | 3329 |
)); |
81 | 3330 |
__END_INTERRUPTABLE__ |
28 | 3331 |
|
3332 |
if (ret < 0) { |
|
649 | 3333 |
#if defined(EINPROGRESS) || defined(EALREADY) |
3334 |
if (0 |
|
3335 |
# ifdef EINPROGRESS |
|
3336 |
|| (errno == EINPROGRESS) |
|
3337 |
# endif |
|
3338 |
# ifdef EALREADY |
|
3339 |
|| (errno == EALREADY) |
|
3340 |
# endif |
|
3341 |
) { |
|
3342 |
/* |
|
3343 |
* We were interrupted. Do not call connect again |
|
3344 |
* (we will get an EALREADY. |
|
3345 |
* Do a select on write instead. |
|
3346 |
*/ |
|
3347 |
||
3348 |
isAsync = true; |
|
3349 |
} else |
|
3350 |
#endif /* EINPROGRESS or EALREADY */ |
|
3351 |
{ |
|
3352 |
DBGPRINTF(("SOCKET: connect failed errno=%d\n", errno)); |
|
117
03cefad7e40b
UD socket example & interruptable bind
Claus Gittinger <cg@exept.de>
parents:
116
diff
changeset
|
3353 |
#ifdef DUMP_ADDRESS |
649 | 3354 |
{ |
3355 |
char *cp = (char *)(&sa); |
|
3356 |
int i; |
|
3357 |
||
3358 |
printf("address data:\n"); |
|
3359 |
for (i=0; i<sockaddr_size; i++) { |
|
3360 |
printf(" %02x\n", *cp++); |
|
3361 |
} |
|
3362 |
} |
|
117
03cefad7e40b
UD socket example & interruptable bind
Claus Gittinger <cg@exept.de>
parents:
116
diff
changeset
|
3363 |
#endif |
649 | 3364 |
__INST(lastErrorNumber) = __MKSMALLINT(errno); |
3365 |
RETURN (false); |
|
3366 |
} |
|
28 | 3367 |
} |
649 | 3368 |
|
3369 |
#if defined(O_NONBLOCK) |
|
3370 |
if (blocking != true) { |
|
3371 |
fcntl(sock, F_SETFL, oldFlags); |
|
3372 |
} |
|
3373 |
#endif |
|
3374 |
||
430
12d736316f69
Fix #connectTo:port: Do not call connect() when we get EINPROGRESS
Stefan Vogel <sv@exept.de>
parents:
429
diff
changeset
|
3375 |
#else /* NO_SOCKET */ |
418 | 3376 |
RETURN (false); |
430
12d736316f69
Fix #connectTo:port: Do not call connect() when we get EINPROGRESS
Stefan Vogel <sv@exept.de>
parents:
429
diff
changeset
|
3377 |
#endif /* NO_SOCKET */ |
42 | 3378 |
%}. |
430
12d736316f69
Fix #connectTo:port: Do not call connect() when we get EINPROGRESS
Stefan Vogel <sv@exept.de>
parents:
429
diff
changeset
|
3379 |
isAsync == true ifTrue:[ |
649 | 3380 |
self readWriteWait. |
430
12d736316f69
Fix #connectTo:port: Do not call connect() when we get EINPROGRESS
Stefan Vogel <sv@exept.de>
parents:
429
diff
changeset
|
3381 |
]. |
71 | 3382 |
port := portNrOrName. |
116
7789fb1c9fa2
more UD socket fixes (at least client side seems to work now)
Claus Gittinger <cg@exept.de>
parents:
115
diff
changeset
|
3383 |
peerName := hostOrPathName. |
28 | 3384 |
^ true |
3385 |
! |
|
3386 |
||
649 | 3387 |
connectTo:hostOrPathName port:portNrOrName blocking:blocking withTimeout:millis |
126 | 3388 |
"connect to port, portNrOrName on host, hostName. |
3389 |
Or path (UNIX socket), where portNrOrName is ignored. |
|
3390 |
Return true if ok, false otherwise. |
|
3391 |
Hostname must be a string, portNrOrName an integer port number (in inet domain). |
|
3392 |
If a non-nil timeout is given, stop trying after that time and return false as well." |
|
3393 |
||
3394 |
|stopSignal stopMe connection| |
|
3395 |
||
3396 |
millis isNil ifTrue:[ |
|
649 | 3397 |
^ self connectTo:hostOrPathName port:portNrOrName |
126 | 3398 |
]. |
559
61012867ebed
cleanup if #connect is interrupted
Claus Gittinger <cg@exept.de>
parents:
551
diff
changeset
|
3399 |
|
126 | 3400 |
stopSignal := Signal new. |
3401 |
stopMe := [stopSignal raise]. |
|
3402 |
stopSignal handle:[:ex | |
|
3403 |
"/ 'timeout on connect' infoPrintNL. |
|
649 | 3404 |
^ false |
126 | 3405 |
] do:[ |
649 | 3406 |
Processor addTimedBlock:stopMe afterMilliseconds:millis. |
3407 |
[ |
|
3408 |
connection := self connectTo:hostOrPathName port:portNrOrName blocking:blocking. |
|
3409 |
] valueNowOrOnUnwindDo:[ |
|
3410 |
Processor removeTimedBlock:stopMe. |
|
3411 |
] |
|
126 | 3412 |
]. |
3413 |
^ connection |
|
3414 |
||
3415 |
"Created: 31.10.1995 / 18:52:49 / cg" |
|
559
61012867ebed
cleanup if #connect is interrupted
Claus Gittinger <cg@exept.de>
parents:
551
diff
changeset
|
3416 |
"Modified: 16.8.1997 / 02:11:21 / cg" |
126 | 3417 |
! |
3418 |
||
649 | 3419 |
connectTo:hostOrPathName port:portNrOrName withTimeout:millis |
3420 |
"connect to port, portNrOrName on host, hostName. |
|
3421 |
Or path (UNIX socket), where portNrOrName is ignored. |
|
3422 |
Return true if ok, false otherwise. |
|
3423 |
Hostname must be a string, portNrOrName an integer port number (in inet domain). |
|
3424 |
If a non-nil timeout is given, stop trying after that time and return false as well." |
|
3425 |
||
3426 |
^ self connectTo:hostOrPathName port:portNrOrName blocking:false withTimeout:millis |
|
3427 |
! |
|
3428 |
||
126 | 3429 |
listenFor:aNumber |
3430 |
"same as listenWithBacklog: - for ST-80 compatibility" |
|
3431 |
||
3432 |
^ self listenWithBacklog:aNumber |
|
3433 |
! |
|
3434 |
||
28 | 3435 |
listenWithBacklog:aNumber |
3436 |
"start listening; return true if ok, false on error" |
|
3437 |
||
3438 |
filePointer isNil ifTrue:[ |
|
42 | 3439 |
^ self error:'not a valid socket' |
28 | 3440 |
]. |
3441 |
%{ |
|
418 | 3442 |
#ifndef NO_SOCKET |
217 | 3443 |
OBJ fp = __INST(filePointer); |
28 | 3444 |
int sock; |
6 | 3445 |
int ret; |
0 | 3446 |
|
58 | 3447 |
if (! __isSmallInteger(aNumber)) { |
98
5e787ba2cb31
use common byteOrder when representing IP numbers as byteArrays (always network-first)
Claus Gittinger <cg@exept.de>
parents:
96
diff
changeset
|
3448 |
DBGPRINTF(("SOCKET: invalid arg\n")); |
42 | 3449 |
RETURN (false); |
28 | 3450 |
} |
3451 |
||
110
7af19ae8693b
use new FILE* wrapper macros (based on externalAddress)
Claus Gittinger <cg@exept.de>
parents:
106
diff
changeset
|
3452 |
sock = fileno(__FILEVal(fp)); |
28 | 3453 |
|
81 | 3454 |
__BEGIN_INTERRUPTABLE__ |
28 | 3455 |
do { |
42 | 3456 |
ret = listen(sock, _intVal(aNumber)); |
28 | 3457 |
} while ((ret < 0) && (errno == EINTR)); |
81 | 3458 |
__END_INTERRUPTABLE__ |
28 | 3459 |
|
3460 |
if (ret < 0) { |
|
98
5e787ba2cb31
use common byteOrder when representing IP numbers as byteArrays (always network-first)
Claus Gittinger <cg@exept.de>
parents:
96
diff
changeset
|
3461 |
DBGPRINTF(("SOCKET: listen call failed errno=%d\n", errno)); |
217 | 3462 |
__INST(lastErrorNumber) = __MKSMALLINT(errno); |
42 | 3463 |
RETURN (false); |
28 | 3464 |
} |
418 | 3465 |
#else |
3466 |
RETURN (false); |
|
3467 |
#endif |
|
42 | 3468 |
%}. |
28 | 3469 |
^ true |
206
77166a6b3ee6
For ST80 style socket creation: register socket in Lobby.
Stefan Vogel <sv@exept.de>
parents:
203
diff
changeset
|
3470 |
! |
77166a6b3ee6
For ST80 style socket creation: register socket in Lobby.
Stefan Vogel <sv@exept.de>
parents:
203
diff
changeset
|
3471 |
|
77166a6b3ee6
For ST80 style socket creation: register socket in Lobby.
Stefan Vogel <sv@exept.de>
parents:
203
diff
changeset
|
3472 |
shutDown |
77166a6b3ee6
For ST80 style socket creation: register socket in Lobby.
Stefan Vogel <sv@exept.de>
parents:
203
diff
changeset
|
3473 |
"shutDown without flushing " |
77166a6b3ee6
For ST80 style socket creation: register socket in Lobby.
Stefan Vogel <sv@exept.de>
parents:
203
diff
changeset
|
3474 |
|
429
197dee9342a3
when shutting down, also tell the Lobby
Claus Gittinger <cg@exept.de>
parents:
425
diff
changeset
|
3475 |
filePointer isNil ifTrue:[^ self]. |
197dee9342a3
when shutting down, also tell the Lobby
Claus Gittinger <cg@exept.de>
parents:
425
diff
changeset
|
3476 |
Lobby unregister:self. |
197dee9342a3
when shutting down, also tell the Lobby
Claus Gittinger <cg@exept.de>
parents:
425
diff
changeset
|
3477 |
|
197dee9342a3
when shutting down, also tell the Lobby
Claus Gittinger <cg@exept.de>
parents:
425
diff
changeset
|
3478 |
%{ |
418 | 3479 |
#ifndef NO_SOCKET |
206
77166a6b3ee6
For ST80 style socket creation: register socket in Lobby.
Stefan Vogel <sv@exept.de>
parents:
203
diff
changeset
|
3480 |
|
77166a6b3ee6
For ST80 style socket creation: register socket in Lobby.
Stefan Vogel <sv@exept.de>
parents:
203
diff
changeset
|
3481 |
OBJ fp; |
77166a6b3ee6
For ST80 style socket creation: register socket in Lobby.
Stefan Vogel <sv@exept.de>
parents:
203
diff
changeset
|
3482 |
|
217 | 3483 |
fp = __INST(filePointer); |
206
77166a6b3ee6
For ST80 style socket creation: register socket in Lobby.
Stefan Vogel <sv@exept.de>
parents:
203
diff
changeset
|
3484 |
if (fp != nil) { |
506
11ef93d12870
support anonymous (OS_specified) ports. (for FTP-protocol)
Claus Gittinger <cg@exept.de>
parents:
486
diff
changeset
|
3485 |
FILE *f; |
11ef93d12870
support anonymous (OS_specified) ports. (for FTP-protocol)
Claus Gittinger <cg@exept.de>
parents:
486
diff
changeset
|
3486 |
int fd; |
11ef93d12870
support anonymous (OS_specified) ports. (for FTP-protocol)
Claus Gittinger <cg@exept.de>
parents:
486
diff
changeset
|
3487 |
|
11ef93d12870
support anonymous (OS_specified) ports. (for FTP-protocol)
Claus Gittinger <cg@exept.de>
parents:
486
diff
changeset
|
3488 |
__INST(filePointer) = nil; |
11ef93d12870
support anonymous (OS_specified) ports. (for FTP-protocol)
Claus Gittinger <cg@exept.de>
parents:
486
diff
changeset
|
3489 |
f = __FILEVal(fp); |
11ef93d12870
support anonymous (OS_specified) ports. (for FTP-protocol)
Claus Gittinger <cg@exept.de>
parents:
486
diff
changeset
|
3490 |
fd = fileno(f); |
11ef93d12870
support anonymous (OS_specified) ports. (for FTP-protocol)
Claus Gittinger <cg@exept.de>
parents:
486
diff
changeset
|
3491 |
__BEGIN_INTERRUPTABLE__ |
11ef93d12870
support anonymous (OS_specified) ports. (for FTP-protocol)
Claus Gittinger <cg@exept.de>
parents:
486
diff
changeset
|
3492 |
shutdown(fd, 2); |
11ef93d12870
support anonymous (OS_specified) ports. (for FTP-protocol)
Claus Gittinger <cg@exept.de>
parents:
486
diff
changeset
|
3493 |
close(fd); |
11ef93d12870
support anonymous (OS_specified) ports. (for FTP-protocol)
Claus Gittinger <cg@exept.de>
parents:
486
diff
changeset
|
3494 |
__END_INTERRUPTABLE__ |
206
77166a6b3ee6
For ST80 style socket creation: register socket in Lobby.
Stefan Vogel <sv@exept.de>
parents:
203
diff
changeset
|
3495 |
} |
77166a6b3ee6
For ST80 style socket creation: register socket in Lobby.
Stefan Vogel <sv@exept.de>
parents:
203
diff
changeset
|
3496 |
#endif |
77166a6b3ee6
For ST80 style socket creation: register socket in Lobby.
Stefan Vogel <sv@exept.de>
parents:
203
diff
changeset
|
3497 |
%} |
25 | 3498 |
! ! |
3499 |
||
3500 |
!Socket methodsFor:'queries'! |
|
3501 |
||
126 | 3502 |
domain |
3503 |
"return the sockets addressing domain (i.e. #inet, #unix, #x25, #appletalk)" |
|
3504 |
||
3505 |
^ domain |
|
3506 |
! |
|
3507 |
||
3508 |
getName |
|
3509 |
"return the name; here, we return the ports name" |
|
3510 |
||
3511 |
^ port printString |
|
3512 |
! |
|
3513 |
||
102
5dc264007513
added getPeer for ST-80 compatibility
Claus Gittinger <cg@exept.de>
parents:
99
diff
changeset
|
3514 |
getPeer |
5dc264007513
added getPeer for ST-80 compatibility
Claus Gittinger <cg@exept.de>
parents:
99
diff
changeset
|
3515 |
"ST-80 compatibility: return an IPSocketAddress instance representing |
5dc264007513
added getPeer for ST-80 compatibility
Claus Gittinger <cg@exept.de>
parents:
99
diff
changeset
|
3516 |
my hostname/port combination. |
155
fcf846c707b7
interest is written with one 'r' (shame on me)
Claus Gittinger <cg@exept.de>
parents:
126
diff
changeset
|
3517 |
If you are interested in the hostname, use getPeerName directly." |
102
5dc264007513
added getPeer for ST-80 compatibility
Claus Gittinger <cg@exept.de>
parents:
99
diff
changeset
|
3518 |
|
116
7789fb1c9fa2
more UD socket fixes (at least client side seems to work now)
Claus Gittinger <cg@exept.de>
parents:
115
diff
changeset
|
3519 |
domain == #unix ifTrue:[ |
7789fb1c9fa2
more UD socket fixes (at least client side seems to work now)
Claus Gittinger <cg@exept.de>
parents:
115
diff
changeset
|
3520 |
^ UDSocketAddress name:peerName |
7789fb1c9fa2
more UD socket fixes (at least client side seems to work now)
Claus Gittinger <cg@exept.de>
parents:
115
diff
changeset
|
3521 |
]. |
102
5dc264007513
added getPeer for ST-80 compatibility
Claus Gittinger <cg@exept.de>
parents:
99
diff
changeset
|
3522 |
^ IPSocketAddress hostAddress:(self class ipAddressOfHost:peerName) port:port |
5dc264007513
added getPeer for ST-80 compatibility
Claus Gittinger <cg@exept.de>
parents:
99
diff
changeset
|
3523 |
|
5dc264007513
added getPeer for ST-80 compatibility
Claus Gittinger <cg@exept.de>
parents:
99
diff
changeset
|
3524 |
"Created: 2.11.1995 / 11:22:39 / cg" |
5dc264007513
added getPeer for ST-80 compatibility
Claus Gittinger <cg@exept.de>
parents:
99
diff
changeset
|
3525 |
! |
5dc264007513
added getPeer for ST-80 compatibility
Claus Gittinger <cg@exept.de>
parents:
99
diff
changeset
|
3526 |
|
25 | 3527 |
getPeerName |
3528 |
"return the peer name; thats the hostname (or dotted name) of the |
|
3529 |
partners host after an accept." |
|
3530 |
||
3531 |
^ peerName |
|
28 | 3532 |
! |
3533 |
||
126 | 3534 |
isActive |
3535 |
"return true, if the receiver has a connection" |
|
81 | 3536 |
|
126 | 3537 |
^ filePointer notNil |
81 | 3538 |
! |
3539 |
||
71 | 3540 |
port |
3541 |
"return the port number (or name for unix-sockets) to which the socket is bound" |
|
28 | 3542 |
|
506
11ef93d12870
support anonymous (OS_specified) ports. (for FTP-protocol)
Claus Gittinger <cg@exept.de>
parents:
486
diff
changeset
|
3543 |
|p| |
11ef93d12870
support anonymous (OS_specified) ports. (for FTP-protocol)
Claus Gittinger <cg@exept.de>
parents:
486
diff
changeset
|
3544 |
|
11ef93d12870
support anonymous (OS_specified) ports. (for FTP-protocol)
Claus Gittinger <cg@exept.de>
parents:
486
diff
changeset
|
3545 |
port == 0 ifTrue:[ |
524
8287da54eccf
more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents:
513
diff
changeset
|
3546 |
p := self getPort. |
506
11ef93d12870
support anonymous (OS_specified) ports. (for FTP-protocol)
Claus Gittinger <cg@exept.de>
parents:
486
diff
changeset
|
3547 |
p notNil ifTrue:[ |
11ef93d12870
support anonymous (OS_specified) ports. (for FTP-protocol)
Claus Gittinger <cg@exept.de>
parents:
486
diff
changeset
|
3548 |
port := p |
11ef93d12870
support anonymous (OS_specified) ports. (for FTP-protocol)
Claus Gittinger <cg@exept.de>
parents:
486
diff
changeset
|
3549 |
] |
11ef93d12870
support anonymous (OS_specified) ports. (for FTP-protocol)
Claus Gittinger <cg@exept.de>
parents:
486
diff
changeset
|
3550 |
]. |
71 | 3551 |
^ port |
28 | 3552 |
! |
3553 |
||
3554 |
type |
|
3555 |
"return the sockets connection type (i.e. #datagram, #stream etc)" |
|
3556 |
||
3557 |
^ socketType |
|
81 | 3558 |
! ! |
3559 |
||
126 | 3560 |
!Socket methodsFor:'socket setup'! |
3561 |
||
3562 |
domain:domainArg type:typeArg |
|
3563 |
"set up socket with domain and type. |
|
3564 |
This is a low level entry; no binding, listening or connect |
|
3565 |
is done. Both arguments must be symbols from one of |
|
3566 |
#inet,#unix, #appletalk, #x25 .. and #stream, #datagram, #raw resp." |
|
3567 |
||
649 | 3568 |
^ self domain:domainArg type:typeArg protocol:0 reuseAddress:true |
126 | 3569 |
! |
3570 |
||
3571 |
domain:domainArg type:typeArg protocol:protocolNumber |
|
3572 |
"set up socket with domain, type and protocol number. |
|
3573 |
This is a low level entry; no binding, listening or connect |
|
3574 |
is done. Both arguments must be symbols from one of |
|
3575 |
#inet,#unix, #appletalk, #x25 .. and #stream, #datagram, #raw resp." |
|
3576 |
||
649 | 3577 |
^ self domain:domainArg type:typeArg protocol:protocolNumber reuseAddress:true |
3578 |
||
3579 |
" |
|
3580 |
Socket new domain:#inet type:#stream |
|
3581 |
Socket new domain:#unix type:#stream |
|
3582 |
" |
|
3583 |
! |
|
3584 |
||
3585 |
domain:domainArg type:typeArg protocol:protocolNumber reuseAddress:reuse |
|
3586 |
"set up socket with domain, type and protocol number. |
|
3587 |
This is a low level entry; no binding, listening or connect |
|
3588 |
is done. Both arguments must be symbols from one of |
|
3589 |
#inet,#unix, #appletalk, #x25 .. and #stream, #datagram, #raw resp. |
|
3590 |
||
3591 |
The reuse boolean argument controls if the SO_REUSEADDR socket option |
|
3592 |
is to be set (to avoid the 'bind: address in use' error)." |
|
3593 |
||
126 | 3594 |
|errorNr| |
3595 |
||
3596 |
filePointer notNil ifTrue:[ |
|
649 | 3597 |
^ self error:'already created' |
126 | 3598 |
]. |
3599 |
%{ |
|
649 | 3600 |
|
418 | 3601 |
#ifndef NO_SOCKET |
126 | 3602 |
FILE *fp; |
3603 |
int dom, typ, pf, proto = 0, sock; |
|
649 | 3604 |
int on = 1; |
126 | 3605 |
|
3606 |
if (! __isSymbol(domainArg)) { |
|
649 | 3607 |
DBGPRINTF(("SOCKET: bad domain\n")); |
3608 |
RETURN ( nil ); |
|
126 | 3609 |
} |
3610 |
if (! __isSymbol(typeArg)) { |
|
649 | 3611 |
DBGPRINTF(("SOCKET: bad type\n")); |
3612 |
RETURN ( nil ); |
|
126 | 3613 |
} |
3614 |
if (protocolNumber != nil) { |
|
649 | 3615 |
if (!__isSmallInteger(protocolNumber)) { |
3616 |
DBGPRINTF(("SOCKET: bad protocol\n")); |
|
3617 |
RETURN ( nil ); |
|
3618 |
} |
|
3619 |
proto = __intVal(protocolNumber); |
|
126 | 3620 |
} |
3621 |
||
81 | 3622 |
|
126 | 3623 |
/* |
3624 |
* get address and protocol-family |
|
3625 |
*/ |
|
3626 |
#ifdef AF_UNIX |
|
3627 |
if (domainArg == @symbol(unix)) { |
|
649 | 3628 |
dom = AF_UNIX; |
126 | 3629 |
} else |
3630 |
#endif |
|
3631 |
#ifdef AF_INET |
|
3632 |
if (domainArg == @symbol(inet)) { |
|
649 | 3633 |
dom = AF_INET; |
126 | 3634 |
} else |
3635 |
#endif |
|
530
067797c15b77
added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents:
529
diff
changeset
|
3636 |
#ifdef AF_INET6 |
067797c15b77
added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents:
529
diff
changeset
|
3637 |
if (domainArg == @symbol(inet6)) { |
649 | 3638 |
dom = AF_INET6; |
530
067797c15b77
added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents:
529
diff
changeset
|
3639 |
} else |
067797c15b77
added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents:
529
diff
changeset
|
3640 |
#endif |
126 | 3641 |
#ifdef AF_DECnet |
3642 |
if (domainArg == @symbol(DECnet)) { |
|
649 | 3643 |
dom = AF_DECnet; |
126 | 3644 |
} else |
3645 |
#endif |
|
3646 |
#ifdef AF_APPLETALK |
|
3647 |
if (domainArg == @symbol(appletalk)) { |
|
649 | 3648 |
dom = AF_APPLETALK; |
126 | 3649 |
} else |
3650 |
#endif |
|
3651 |
#ifdef AF_X25 |
|
3652 |
if (domainArg == @symbol(x25)) { |
|
649 | 3653 |
dom = AF_X25; |
126 | 3654 |
} else |
3655 |
#endif |
|
3656 |
#ifdef AF_NS |
|
3657 |
if (domainArg == @symbol(xns)) { |
|
649 | 3658 |
dom = AF_NS; |
126 | 3659 |
} else |
3660 |
#endif |
|
3661 |
#ifdef AF_SNA |
|
3662 |
if (domainArg == @symbol(sna)) { |
|
649 | 3663 |
dom = AF_SNA; |
126 | 3664 |
} else |
3665 |
#endif |
|
3666 |
#ifdef AF_RAW |
|
3667 |
if (domainArg == @symbol(raw)) { |
|
649 | 3668 |
dom = AF_RAW; |
126 | 3669 |
} else |
3670 |
#endif |
|
524
8287da54eccf
more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents:
513
diff
changeset
|
3671 |
# ifdef AF_ISO |
8287da54eccf
more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents:
513
diff
changeset
|
3672 |
if (domainArg == @symbol(iso)) { |
649 | 3673 |
dom = AF_ISO; |
524
8287da54eccf
more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents:
513
diff
changeset
|
3674 |
} |
8287da54eccf
more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents:
513
diff
changeset
|
3675 |
# endif |
8287da54eccf
more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents:
513
diff
changeset
|
3676 |
# ifdef AF_NETBIOS |
8287da54eccf
more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents:
513
diff
changeset
|
3677 |
if (domainArg == @symbol(netbios)) { |
649 | 3678 |
dom = AF_NETBIOS; |
524
8287da54eccf
more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents:
513
diff
changeset
|
3679 |
} |
8287da54eccf
more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents:
513
diff
changeset
|
3680 |
# endif |
530
067797c15b77
added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents:
529
diff
changeset
|
3681 |
# ifdef AF_IPX |
067797c15b77
added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents:
529
diff
changeset
|
3682 |
if (domainArg == @symbol(ipx)) { |
649 | 3683 |
dom = AF_IPX; |
530
067797c15b77
added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents:
529
diff
changeset
|
3684 |
} |
067797c15b77
added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents:
529
diff
changeset
|
3685 |
# endif |
067797c15b77
added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents:
529
diff
changeset
|
3686 |
# ifdef AF_BRIDGE |
067797c15b77
added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents:
529
diff
changeset
|
3687 |
if (domainArg == @symbol(bridge)) { |
649 | 3688 |
dom = AF_BRIDGE; |
530
067797c15b77
added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents:
529
diff
changeset
|
3689 |
} |
067797c15b77
added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents:
529
diff
changeset
|
3690 |
# endif |
571 | 3691 |
# ifdef AF_BSC |
3692 |
if (domainArg == @symbol(bsc)) { |
|
649 | 3693 |
dom = AF_BSC; |
571 | 3694 |
} |
3695 |
# endif |
|
524
8287da54eccf
more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents:
513
diff
changeset
|
3696 |
# if defined(AF_CCITT) && (AF_CCITT != AF_X25) |
8287da54eccf
more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents:
513
diff
changeset
|
3697 |
if (domainArg == @symbol(ccitt)) { |
649 | 3698 |
dom = AF_CCITT; |
524
8287da54eccf
more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents:
513
diff
changeset
|
3699 |
} |
8287da54eccf
more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents:
513
diff
changeset
|
3700 |
# endif |
126 | 3701 |
{ |
649 | 3702 |
DBGPRINTF(("SOCKET: unknown domain <%s>\n", __stringVal(domainArg))); |
3703 |
RETURN ( nil ); |
|
126 | 3704 |
} |
3705 |
||
3706 |
#ifdef SOCK_STREAM |
|
3707 |
if (typeArg == @symbol(stream)) { |
|
649 | 3708 |
typ = SOCK_STREAM; |
126 | 3709 |
} else |
3710 |
#endif |
|
3711 |
#ifdef SOCK_DGRAM |
|
3712 |
if (typeArg == @symbol(datagram)) { |
|
649 | 3713 |
typ = SOCK_DGRAM; |
126 | 3714 |
} else |
3715 |
#endif |
|
3716 |
#ifdef SOCK_RAW |
|
3717 |
if (typeArg == @symbol(raw)) |
|
649 | 3718 |
typ = SOCK_RAW; |
126 | 3719 |
else |
3720 |
#endif |
|
3721 |
#ifdef SOCK_SEQPACKET |
|
3722 |
if (typeArg == @symbol(seqPacket)) |
|
649 | 3723 |
typ = SOCK_SEQPACKET; |
126 | 3724 |
else |
3725 |
#endif |
|
3726 |
{ |
|
649 | 3727 |
DBGPRINTF(("SOCKET: bad type <%s>\n", __stringVal(typeArg))); |
3728 |
RETURN ( nil ); |
|
126 | 3729 |
} |
3730 |
||
3731 |
__BEGIN_INTERRUPTABLE__ |
|
3732 |
do { |
|
649 | 3733 |
DBGPRINTF(("SOCKET: opening socket domain=%d type=%d proto=%d\n", dom, typ, proto)); |
3734 |
sock = socket(dom, typ, proto); |
|
126 | 3735 |
#if defined(EPROTONOSUPPORT) /* for SGI */ |
649 | 3736 |
if ((proto != 0) && (sock < 0) && (errno == EPROTONOSUPPORT)) { |
3737 |
DBGPRINTF(("SOCKET: retry with UNSPEC protocol\n")); |
|
3738 |
proto = 0; |
|
3739 |
sock = socket(dom, typ, 0); |
|
3740 |
} |
|
126 | 3741 |
#endif |
3742 |
} while ((sock < 0) && (errno == EINTR)); |
|
3743 |
__END_INTERRUPTABLE__ |
|
3744 |
||
3745 |
if (sock < 0) { |
|
649 | 3746 |
DBGPRINTF(("SOCKET: socket(dom=%d typ=%d proto=%d) call failed errno=%d\n", dom, typ, proto, errno)); |
3747 |
__INST(lastErrorNumber) = __MKSMALLINT(errno); |
|
126 | 3748 |
} else { |
649 | 3749 |
# ifdef SO_REUSEADDR |
3750 |
if (reuse == true) { |
|
3751 |
DBGPRINTF(("SOCKET: setsockopt - SO_REUSEADDR\n")); |
|
3752 |
if (setsockopt(sock, SOL_SOCKET, SO_REUSEADDR, (char *) &on, sizeof (on)) < 0) { |
|
3753 |
DBGPRINTF(("SOCKET: setsockopt - SO_REUSEADDR failed\n")); |
|
3754 |
} |
|
3755 |
} |
|
3756 |
# endif /* SO_REUSEADDR */ |
|
3757 |
/* |
|
3758 |
* make it a FILE * |
|
3759 |
*/ |
|
3760 |
fp = fdopen(sock, "r+"); |
|
3761 |
if (! fp) { |
|
3762 |
DBGPRINTF(("SOCKET: fdopen call failed\n")); |
|
3763 |
__INST(lastErrorNumber) = __MKSMALLINT(errno); |
|
3764 |
__BEGIN_INTERRUPTABLE__ |
|
3765 |
close(sock); |
|
3766 |
__END_INTERRUPTABLE__ |
|
3767 |
} else { |
|
3768 |
__INST(filePointer) = __MKOBJ(fp); |
|
3769 |
__STORESELF(filePointer); |
|
3770 |
} |
|
126 | 3771 |
} |
418 | 3772 |
#endif |
126 | 3773 |
%}. |
3774 |
||
3775 |
"all ok?" |
|
3776 |
filePointer notNil ifTrue:[ |
|
649 | 3777 |
domain := domainArg. |
3778 |
socketType := typeArg. |
|
3779 |
Lobby register:self. |
|
126 | 3780 |
] ifFalse:[ |
649 | 3781 |
^ nil |
126 | 3782 |
]. |
3783 |
||
3784 |
" |
|
3785 |
Socket new domain:#inet type:#stream |
|
3786 |
Socket new domain:#unix type:#stream |
|
3787 |
" |
|
81 | 3788 |
! |
3789 |
||
126 | 3790 |
for:hostName port:portNr |
3791 |
"setup for a TCP socket (i.e. inet domain, stream type) |
|
3792 |
If hostname is nil, a server port is opened, |
|
3793 |
otherwise a client port to the server on host. |
|
3794 |
||
3795 |
HISTORIC LEFTOVER: |
|
3796 |
This method will vanish, as soon as the low level |
|
3797 |
connect/bind works," |
|
3798 |
||
3799 |
self obsoleteMethodWarning. |
|
3800 |
||
3801 |
filePointer notNil ifTrue:[ |
|
3802 |
^ self error:'already created' |
|
3803 |
]. |
|
3804 |
(portNr isMemberOf:SmallInteger) ifFalse:[ |
|
3805 |
^ self error:'invalid portNr' |
|
3806 |
]. |
|
3807 |
%{ |
|
418 | 3808 |
#ifndef NO_SOCKET |
126 | 3809 |
struct sockaddr_in sa ; |
3810 |
struct hostent *hp ; |
|
3811 |
int a, sock ; |
|
3812 |
long addr; |
|
3813 |
FILE *fp; |
|
3814 |
int ret; |
|
3815 |
int on = 1; |
|
3816 |
||
3817 |
bzero((char *) &sa, sizeof(sa)) ; |
|
3818 |
sa.sin_family = AF_INET; |
|
3819 |
sa.sin_addr.s_addr = htonl(INADDR_ANY); |
|
3820 |
||
3821 |
if ((hostName != nil) && __isString(hostName)){ |
|
3822 |
bzero(&sa, sizeof(sa)) ; |
|
524
8287da54eccf
more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents:
513
diff
changeset
|
3823 |
if ((addr = inet_addr((char *) __stringVal(hostName))) != -1) { |
126 | 3824 |
/* |
3825 |
* is Internet addr in octet notation |
|
3826 |
*/ |
|
3827 |
bcopy(&addr, (char *) &sa.sin_addr, sizeof(addr)) ; /* set address */ |
|
3828 |
} else { |
|
3829 |
/* |
|
3830 |
* do we know the host's address? |
|
3831 |
*/ |
|
648
58e11a70ddaf
gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents:
617
diff
changeset
|
3832 |
GETHOSTBYNAME(hp, __stringVal(hostName)) |
537
f413ab8fd1b5
gethostbyname must be executed interruptable;
Claus Gittinger <cg@exept.de>
parents:
533
diff
changeset
|
3833 |
if (hp == NULL) { |
f413ab8fd1b5
gethostbyname must be executed interruptable;
Claus Gittinger <cg@exept.de>
parents:
533
diff
changeset
|
3834 |
DBGPRINTF(("SOCKET: unknown host: %s\n", __stringVal(hostName))); |
126 | 3835 |
RETURN ( nil ); |
3836 |
} |
|
3837 |
bcopy(hp->h_addr, (char *) &sa.sin_addr, hp->h_length) ; |
|
3838 |
sa.sin_family = hp->h_addrtype; |
|
3839 |
} |
|
3840 |
} |
|
3841 |
||
3842 |
/* |
|
3843 |
* create the socket |
|
3844 |
*/ |
|
3845 |
__BEGIN_INTERRUPTABLE__ |
|
3846 |
do { |
|
3847 |
sock = socket(sa.sin_family, SOCK_STREAM, 0); |
|
3848 |
} while ((sock < 0) && (errno == EINTR)); |
|
3849 |
__END_INTERRUPTABLE__ |
|
3850 |
||
3851 |
if (sock < 0) { |
|
3852 |
DBGPRINTF(("SOCKET: socket(dom=%d typ=%d proto=0) call failed errno=%d\n", sa.sin_family, SOCK_STREAM, errno)); |
|
217 | 3853 |
__INST(lastErrorNumber) = __MKSMALLINT(errno); |
126 | 3854 |
} else { |
3855 |
/* |
|
3856 |
* connect/bind |
|
3857 |
*/ |
|
3858 |
sa.sin_port = htons((u_short) _intVal(portNr)) ; |
|
3859 |
||
3860 |
__BEGIN_INTERRUPTABLE__ |
|
3861 |
if (hostName != nil) { |
|
3862 |
do { |
|
3863 |
ret = connect(sock, (struct sockaddr *)&sa, sizeof(sa)); |
|
3864 |
} while ((ret < 0) && (errno == EINTR)); |
|
3865 |
} else { |
|
3866 |
#ifdef SO_REUSEADDR |
|
3867 |
/* |
|
3868 |
* should I also do this for DGRAM sockets ? |
|
3869 |
*/ |
|
3870 |
if (setsockopt(sock, SOL_SOCKET, SO_REUSEADDR, (char *) &on, sizeof (on)) < 0) { |
|
3871 |
DBGPRINTF(("SOCKET: setsockopt - SO_REUSEADDR failed\n")); |
|
3872 |
} |
|
3873 |
#endif /* SO_REUSEADDR */ |
|
3874 |
sa.sin_addr.s_addr = htonl(INADDR_ANY); |
|
3875 |
do { |
|
3876 |
ret = bind(sock, (struct sockaddr *)&sa, sizeof(sa)); |
|
3877 |
} while ((ret < 0) && (errno == EINTR)); |
|
3878 |
} |
|
3879 |
__END_INTERRUPTABLE__ |
|
3880 |
||
3881 |
if (ret < 0) { |
|
3882 |
DBGPRINTF(("SOCKET: bind/connect call failed errno=%d\n", errno)); |
|
217 | 3883 |
__INST(lastErrorNumber) = __MKSMALLINT(errno); |
126 | 3884 |
__BEGIN_INTERRUPTABLE__ |
3885 |
close(sock) ; |
|
3886 |
__END_INTERRUPTABLE__ |
|
3887 |
} else { |
|
3888 |
/* |
|
3889 |
* make it a FILE * |
|
3890 |
*/ |
|
3891 |
fp = fdopen(sock, "r+"); |
|
3892 |
if (! fp) { |
|
3893 |
DBGPRINTF(("SOCKET: fdopen failed\n")); |
|
217 | 3894 |
__INST(lastErrorNumber) = __MKSMALLINT(errno); |
126 | 3895 |
__BEGIN_INTERRUPTABLE__ |
3896 |
close(sock); |
|
3897 |
__END_INTERRUPTABLE__ |
|
3898 |
} else { |
|
444 | 3899 |
#ifdef BUGGY_STDIO_LIB |
126 | 3900 |
setbuf(fp, NULL); |
217 | 3901 |
__INST(buffered) = false; |
126 | 3902 |
#endif |
217 | 3903 |
__INST(filePointer) = __MKOBJ(fp); |
425 | 3904 |
__STORESELF(filePointer); |
126 | 3905 |
} |
3906 |
} |
|
3907 |
} |
|
418 | 3908 |
#endif |
126 | 3909 |
%}. |
3910 |
filePointer isNil ifTrue:[ |
|
3911 |
^ nil |
|
3912 |
]. |
|
3913 |
mode := #readwrite. |
|
169 | 3914 |
Lobby register:self. |
126 | 3915 |
binary := false. |
3916 |
||
3917 |
domain := #inet. |
|
3918 |
socketType := #stream. |
|
3919 |
protocol := portNr. |
|
3920 |
peerName := hostName. |
|
81 | 3921 |
|
126 | 3922 |
" |
3923 |
Socket new for:'clam' port:(Socket portOfService:'echo') |
|
3924 |
||
3925 |
Socket new for:nil port:9999 |
|
3926 |
Socket new for:(OperatingSystem getHostName) port:9999 |
|
3927 |
" |
|
3928 |
! |
|
3929 |
||
3930 |
for:hostName udpPort:portNr |
|
3931 |
"setup for a UDP socket (i.e. inet domain, datagram type) |
|
3932 |
if hostname is nil, a server port is opened; |
|
3933 |
otherwise a client port to the server on host. |
|
3934 |
||
3935 |
HISTORIC LEFTOVER: |
|
3936 |
This method will vanish, as soon as the low level |
|
3937 |
connect/bind works," |
|
3938 |
||
3939 |
self obsoleteMethodWarning. |
|
3940 |
||
3941 |
filePointer notNil ifTrue:[ |
|
3942 |
^ self error:'already created' |
|
3943 |
]. |
|
3944 |
(portNr isMemberOf:SmallInteger) ifFalse:[ |
|
3945 |
^ self error:'invalid portNr' |
|
3946 |
]. |
|
3947 |
%{ |
|
418 | 3948 |
#ifndef NO_SOCKET |
126 | 3949 |
struct sockaddr_in sa ; |
3950 |
struct hostent *hp ; |
|
3951 |
int a, sock ; |
|
3952 |
long addr; |
|
3953 |
FILE *fp; |
|
3954 |
int ret; |
|
3955 |
||
3956 |
if (hostName != nil) { |
|
3957 |
bzero(&sa, sizeof(sa)) ; |
|
524
8287da54eccf
more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents:
513
diff
changeset
|
3958 |
if ((addr = inet_addr((char *) __stringVal(hostName))) != -1) { |
126 | 3959 |
/* |
3960 |
* is Internet addr in octet notation |
|
3961 |
*/ |
|
3962 |
bcopy(&addr, (char *) &sa.sin_addr, sizeof(addr)) ; /* set address */ |
|
3963 |
sa.sin_family = AF_INET ; |
|
3964 |
} else { |
|
3965 |
/* |
|
3966 |
* is hostname - |
|
3967 |
* do we know the host's address? |
|
3968 |
*/ |
|
648
58e11a70ddaf
gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents:
617
diff
changeset
|
3969 |
GETHOSTBYNAME(hp, __stringVal(hostName)) |
537
f413ab8fd1b5
gethostbyname must be executed interruptable;
Claus Gittinger <cg@exept.de>
parents:
533
diff
changeset
|
3970 |
if (hp == NULL) { |
f413ab8fd1b5
gethostbyname must be executed interruptable;
Claus Gittinger <cg@exept.de>
parents:
533
diff
changeset
|
3971 |
DBGPRINTF(("SOCKET: unknown host: %s\n", __stringVal(hostName))); |
126 | 3972 |
RETURN ( nil ); |
3973 |
} |
|
3974 |
bcopy(hp->h_addr, (char *) &sa.sin_addr, hp->h_length) ; |
|
3975 |
sa.sin_family = hp->h_addrtype ; |
|
3976 |
} |
|
526 | 3977 |
} else { |
126 | 3978 |
sa.sin_family = AF_INET; |
526 | 3979 |
} |
126 | 3980 |
|
3981 |
/* |
|
3982 |
* create the socket |
|
3983 |
*/ |
|
3984 |
__BEGIN_INTERRUPTABLE__ |
|
3985 |
do { |
|
3986 |
sock = socket(sa.sin_family, SOCK_DGRAM, 0); |
|
3987 |
} while ((sock < 0) && (errno == EINTR)); |
|
3988 |
__END_INTERRUPTABLE__ |
|
3989 |
||
3990 |
if (sock < 0) { |
|
3991 |
DBGPRINTF(("SOCKET: socket(dom=%d typ=%d proto=0) call failed errno=%d\n", sa.sin_family, SOCK_DGRAM, errno)); |
|
217 | 3992 |
__INST(lastErrorNumber) = __MKSMALLINT(errno); |
126 | 3993 |
} else { |
3994 |
/* |
|
3995 |
* ok, |
|
3996 |
* connect/bind |
|
3997 |
*/ |
|
3998 |
__BEGIN_INTERRUPTABLE__ |
|
3999 |
if (hostName == nil) { |
|
4000 |
sa.sin_addr.s_addr = htonl(INADDR_ANY); |
|
4001 |
do { |
|
4002 |
ret = bind(sock, (struct sockaddr *)&sa, sizeof(sa)); |
|
4003 |
} while ((ret < 0) && (errno == EINTR)); |
|
4004 |
} else { |
|
4005 |
sa.sin_port = htons((u_short) _intVal(portNr)) ; |
|
4006 |
do { |
|
4007 |
ret = connect(sock, (struct sockaddr *)&sa, sizeof(sa)); |
|
4008 |
} while ((ret < 0) && (errno == EINTR)); |
|
4009 |
} |
|
4010 |
__END_INTERRUPTABLE__ |
|
4011 |
||
4012 |
if (ret < 0) { |
|
4013 |
DBGPRINTF(("SOCKET: bind/connect call failed\n")); |
|
217 | 4014 |
__INST(lastErrorNumber) = __MKSMALLINT(errno); |
126 | 4015 |
__BEGIN_INTERRUPTABLE__ |
4016 |
close(sock) ; |
|
4017 |
__END_INTERRUPTABLE__ |
|
4018 |
} else { |
|
4019 |
/* |
|
4020 |
* make it a FILE * |
|
4021 |
*/ |
|
4022 |
fp = fdopen(sock, "r+"); |
|
4023 |
if (! fp) { |
|
4024 |
DBGPRINTF(("SOCKET: fdopen call failed\n")); |
|
217 | 4025 |
__INST(lastErrorNumber) = __MKSMALLINT(errno); |
126 | 4026 |
__BEGIN_INTERRUPTABLE__ |
4027 |
close(sock); |
|
4028 |
__END_INTERRUPTABLE__ |
|
4029 |
} else { |
|
444 | 4030 |
#ifdef BUGGY_STDIO_LIB |
126 | 4031 |
setbuf(fp, NULL); |
217 | 4032 |
__INST(buffered) = false; |
126 | 4033 |
#endif |
217 | 4034 |
__INST(filePointer) = __MKOBJ(fp); |
425 | 4035 |
__STORESELF(filePointer); |
126 | 4036 |
} |
4037 |
} |
|
4038 |
} |
|
418 | 4039 |
#endif |
126 | 4040 |
%}. |
4041 |
filePointer isNil ifTrue:[ |
|
4042 |
^ nil |
|
4043 |
]. |
|
4044 |
||
4045 |
mode := #readwrite. |
|
169 | 4046 |
Lobby register:self. |
126 | 4047 |
binary := false. |
4048 |
||
4049 |
domain := #inet. |
|
4050 |
socketType := #datagram. |
|
4051 |
protocol := portNr. |
|
4052 |
peerName := hostName. |
|
4053 |
||
4054 |
" |
|
4055 |
Socket new for:'clam' udpPort:(Socket portOfService:'echo') |
|
4056 |
" |
|
28 | 4057 |
! ! |
4058 |
||
4059 |
!Socket methodsFor:'specials'! |
|
4060 |
||
4061 |
receiveTimeout:seconds |
|
71 | 4062 |
"set the receive timeout - for special applications only. |
4063 |
Not all operatingSystems offer this functionality |
|
4064 |
(returns false, if unsupported)" |
|
28 | 4065 |
|
4066 |
|millis| |
|
4067 |
||
4068 |
filePointer isNil ifTrue:[ |
|
42 | 4069 |
^ self error:'not a valid socket' |
28 | 4070 |
]. |
4071 |
millis := (seconds * 1000) rounded. |
|
4072 |
%{ |
|
4073 |
#if defined(SO_RCVTIMEO) && defined(SOL_SOCKET) && defined(HZ) |
|
58 | 4074 |
if (__isSmallInteger(millis)) { |
217 | 4075 |
OBJ fp = __INST(filePointer); |
42 | 4076 |
int sock; |
4077 |
int opt; |
|
28 | 4078 |
|
110
7af19ae8693b
use new FILE* wrapper macros (based on externalAddress)
Claus Gittinger <cg@exept.de>
parents:
106
diff
changeset
|
4079 |
sock = fileno(__FILEVal(fp)); |
42 | 4080 |
opt = _intVal(millis) / (1000 / HZ); |
4081 |
setsockopt(sock, SOL_SOCKET, SO_RCVTIMEO, (char *)&opt, sizeof(int)); |
|
4082 |
RETURN(true); |
|
28 | 4083 |
} |
4084 |
#endif |
|
71 | 4085 |
%}. |
28 | 4086 |
^ false |
81 | 4087 |
! |
4088 |
||
126 | 4089 |
sendTimeout:seconds |
4090 |
"set the send timeout - for special applications only. |
|
4091 |
Not all operatingSystems offer this functionality |
|
4092 |
(returns false, if unsupported)" |
|
81 | 4093 |
|
126 | 4094 |
|millis| |
25 | 4095 |
|
126 | 4096 |
filePointer isNil ifTrue:[ |
4097 |
^ self error:'not a valid socket' |
|
4098 |
]. |
|
4099 |
millis := (seconds * 1000) rounded. |
|
4100 |
%{ |
|
4101 |
#if defined(SO_SNDTIMEO) && defined(SOL_SOCKET) && defined(HZ) |
|
4102 |
if (__isSmallInteger(millis)) { |
|
217 | 4103 |
OBJ fp = __INST(filePointer); |
126 | 4104 |
int sock; |
4105 |
int opt; |
|
81 | 4106 |
|
126 | 4107 |
sock = fileno(__FILEVal(fp)); |
4108 |
opt = _intVal(millis) / (1000 / HZ); |
|
4109 |
setsockopt(sock, SOL_SOCKET, SO_SNDTIMEO, (char *)&opt, sizeof(int)); |
|
4110 |
RETURN(true); |
|
4111 |
} |
|
4112 |
#endif |
|
4113 |
%}. |
|
4114 |
^ false |
|
4115 |
! ! |
|
82 | 4116 |
|
464 | 4117 |
!Socket class methodsFor:'documentation'! |
206
77166a6b3ee6
For ST80 style socket creation: register socket in Lobby.
Stefan Vogel <sv@exept.de>
parents:
203
diff
changeset
|
4118 |
|
77166a6b3ee6
For ST80 style socket creation: register socket in Lobby.
Stefan Vogel <sv@exept.de>
parents:
203
diff
changeset
|
4119 |
version |
650
8c5616f17ed6
made gethostbyaddr interruptable
Claus Gittinger <cg@exept.de>
parents:
649
diff
changeset
|
4120 |
^ '$Header: /cvs/stx/stx/libbasic2/Socket.st,v 1.106 1998-06-02 18:28:20 cg Exp $' |
206
77166a6b3ee6
For ST80 style socket creation: register socket in Lobby.
Stefan Vogel <sv@exept.de>
parents:
203
diff
changeset
|
4121 |
! ! |