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