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