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