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