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