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