Socket.st
author Claus Gittinger <cg@exept.de>
Wed, 11 Aug 1999 16:42:44 +0200
changeset 790 6f58d65fac5e
parent 789 3c8cac1a92f5
child 796 c9f6b3b667fb
permissions -rw-r--r--
*** empty log message ***
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
0
1cf8d1747859 Initial revision
claus
parents:
diff changeset
     1
"
4
1f66800df351 *** empty log message ***
claus
parents: 3
diff changeset
     2
 COPYRIGHT (c) 1992 by Claus Gittinger
42
506596f9a1a8 *** empty log message ***
claus
parents: 38
diff changeset
     3
	      All Rights Reserved
0
1cf8d1747859 Initial revision
claus
parents:
diff changeset
     4
1cf8d1747859 Initial revision
claus
parents:
diff changeset
     5
 This software is furnished under a license and may be used
1cf8d1747859 Initial revision
claus
parents:
diff changeset
     6
 only in accordance with the terms of that license and with the
1cf8d1747859 Initial revision
claus
parents:
diff changeset
     7
 inclusion of the above copyright notice.   This software may not
1cf8d1747859 Initial revision
claus
parents:
diff changeset
     8
 be provided or otherwise made available to, or used by, any
1cf8d1747859 Initial revision
claus
parents:
diff changeset
     9
 other person.  No title to or ownership of the software is
1cf8d1747859 Initial revision
claus
parents:
diff changeset
    10
 hereby transferred.
1cf8d1747859 Initial revision
claus
parents:
diff changeset
    11
"
1cf8d1747859 Initial revision
claus
parents:
diff changeset
    12
63
7dd3d5b7877e *** empty log message ***
claus
parents: 58
diff changeset
    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
1cf8d1747859 Initial revision
claus
parents:
diff changeset
    18
!
1cf8d1747859 Initial revision
claus
parents:
diff changeset
    19
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
    20
!Socket primitiveDefinitions!
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
    21
%{
444
9ba31a1fba38 always unbuffered on linux
Claus Gittinger <cg@exept.de>
parents: 430
diff changeset
    22
9ba31a1fba38 always unbuffered on linux
Claus Gittinger <cg@exept.de>
parents: 430
diff changeset
    23
#ifdef LINUX
9ba31a1fba38 always unbuffered on linux
Claus Gittinger <cg@exept.de>
parents: 430
diff changeset
    24
# define BUGGY_STDIO_LIB
9ba31a1fba38 always unbuffered on linux
Claus Gittinger <cg@exept.de>
parents: 430
diff changeset
    25
#endif
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
    26
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
    27
#include <stdio.h>
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
    28
#include <errno.h>
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
    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
317e55c6c281 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 403
diff changeset
    34
# define NO_SOCKET
317e55c6c281 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 403
diff changeset
    35
#endif
317e55c6c281 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 403
diff changeset
    36
525
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
    37
/*
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
    38
 * which protocols can we support ?
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
    39
 */
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
    40
#ifndef NO_SOCKET
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
    41
# define WANT__AF_INET
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
    42
#endif
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
    43
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
    44
#ifdef UNIX_LIKE
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
    45
# define WANT__AF_UNIX
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
    46
#endif
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
    47
563
23a6b265bdd0 VMS stuff
Claus Gittinger <cg@exept.de>
parents: 559
diff changeset
    48
#ifdef __VMS__
23a6b265bdd0 VMS stuff
Claus Gittinger <cg@exept.de>
parents: 559
diff changeset
    49
# undef WANT__AF_UNIX
571
191b37534643 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 563
diff changeset
    50
# define WANT_AF_DECnet
563
23a6b265bdd0 VMS stuff
Claus Gittinger <cg@exept.de>
parents: 559
diff changeset
    51
#endif
23a6b265bdd0 VMS stuff
Claus Gittinger <cg@exept.de>
parents: 559
diff changeset
    52
527
f48fd11817e2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 526
diff changeset
    53
#ifdef LINUX
f48fd11817e2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 526
diff changeset
    54
# define WANT__AF_APPLETALK
741
380592a59a17 removed AF_INET6 - temporarily
ah
parents: 739
diff changeset
    55
/* # define WANT__AF_INET6 */
527
f48fd11817e2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 526
diff changeset
    56
#endif
525
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
    57
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
    58
#ifdef LINUX
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
    59
/* kludge to avoid some redefines ... */
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
    60
# define _ARPA_NAMESER_H
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
    61
# define _NETINET_TCP_H
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
    62
#endif
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
    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
789
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
    77
739
eb3878300c3b removed WIN32 ifdef's - win32 uses Socket_win32.st anyway.
Claus Gittinger <cg@exept.de>
parents: 726
diff changeset
    78
#  ifndef SOCK_STREAM
eb3878300c3b removed WIN32 ifdef's - win32 uses Socket_win32.st anyway.
Claus Gittinger <cg@exept.de>
parents: 726
diff changeset
    79
#   define SOCK_STREAM 1
eb3878300c3b removed WIN32 ifdef's - win32 uses Socket_win32.st anyway.
Claus Gittinger <cg@exept.de>
parents: 726
diff changeset
    80
#  endif
eb3878300c3b removed WIN32 ifdef's - win32 uses Socket_win32.st anyway.
Claus Gittinger <cg@exept.de>
parents: 726
diff changeset
    81
#  ifndef SOCK_DGRAM
eb3878300c3b removed WIN32 ifdef's - win32 uses Socket_win32.st anyway.
Claus Gittinger <cg@exept.de>
parents: 726
diff changeset
    82
#   define SOCK_DGRAM  2
eb3878300c3b removed WIN32 ifdef's - win32 uses Socket_win32.st anyway.
Claus Gittinger <cg@exept.de>
parents: 726
diff changeset
    83
#  endif
eb3878300c3b removed WIN32 ifdef's - win32 uses Socket_win32.st anyway.
Claus Gittinger <cg@exept.de>
parents: 726
diff changeset
    84
#  ifndef SOCK_RAW
eb3878300c3b removed WIN32 ifdef's - win32 uses Socket_win32.st anyway.
Claus Gittinger <cg@exept.de>
parents: 726
diff changeset
    85
#   define SOCK_RAW    3
eb3878300c3b removed WIN32 ifdef's - win32 uses Socket_win32.st anyway.
Claus Gittinger <cg@exept.de>
parents: 726
diff changeset
    86
#  endif
656
fcd2139d83a5 borland-C support
Claus Gittinger <cg@exept.de>
parents: 653
diff changeset
    87
# else
739
eb3878300c3b removed WIN32 ifdef's - win32 uses Socket_win32.st anyway.
Claus Gittinger <cg@exept.de>
parents: 726
diff changeset
    88
#  include <sys/socket.h>
506
11ef93d12870 support anonymous (OS_specified) ports. (for FTP-protocol)
Claus Gittinger <cg@exept.de>
parents: 486
diff changeset
    89
# endif
739
eb3878300c3b removed WIN32 ifdef's - win32 uses Socket_win32.st anyway.
Claus Gittinger <cg@exept.de>
parents: 726
diff changeset
    90
eb3878300c3b removed WIN32 ifdef's - win32 uses Socket_win32.st anyway.
Claus Gittinger <cg@exept.de>
parents: 726
diff changeset
    91
# ifdef NEXT3
eb3878300c3b removed WIN32 ifdef's - win32 uses Socket_win32.st anyway.
Claus Gittinger <cg@exept.de>
parents: 726
diff changeset
    92
#  include <netinet/in_systm.h>
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
    93
# endif
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
    94
#endif
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
    95
525
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
    96
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
    97
/*
528
928f68d9c080 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 527
diff changeset
    98
 * see what we want ...
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
    99
 */
525
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
   100
#ifdef WANT__AF_UNIX
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
   101
# ifdef AF_UNIX
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
   102
#  ifndef PF_UNIX
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
   103
#   define PF_UNIX AF_UNIX
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
   104
#  endif
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   105
# endif
525
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
   106
#else
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
   107
# undef AF_UNIX
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
   108
#endif
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
   109
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
   110
#ifdef WANT__AF_INET
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
   111
# ifdef AF_INET
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
   112
#  ifndef PF_INET
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
   113
#   define PF_INET AF_INET
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
   114
#  endif
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
   115
# endif
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
   116
#else
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
   117
# undef AF_INET
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   118
#endif
525
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
   119
530
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
   120
#ifdef WANT__AF_INET6
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
   121
# ifdef AF_INET6
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
   122
#  ifndef PF_INET6
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
   123
#   define PF_INET6 AF_INET6
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
# endif
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
   126
#else
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
   127
# undef AF_INET6
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
   128
#endif
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
   129
525
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
   130
#ifdef WANT__AF_DECnet
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
   131
# ifdef AF_DECnet
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
   132
#  ifndef PF_DECnet
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
   133
#   define PF_DECnet AF_DECnet
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
   134
#  endif
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
   135
# endif
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
   136
#else
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
   137
# undef AF_DECnet
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
   138
#endif
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
   139
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
   140
#ifdef WANT__AF_APPLETALK
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
   141
# ifdef AF_APPLETALK
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
   142
#  ifndef PF_APPLETALK
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
   143
#   define PF_APPLETALK AF_APPLETALK
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
   144
#  endif
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   145
# endif
525
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
   146
#else
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
   147
# undef AF_APPLETALK
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   148
#endif
525
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
   149
533
ced9950b551f added query about which protocols are supported
Claus Gittinger <cg@exept.de>
parents: 532
diff changeset
   150
#ifdef WANT__AF_X25     /* X.25 */
525
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
   151
# ifdef AF_X25
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
   152
#  ifndef PF_X25
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
   153
#   define PF_X25 AF_X25
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
   154
#  endif
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
   155
# endif
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
   156
#else
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
   157
# undef AF_X25
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
   158
#endif
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
   159
533
ced9950b551f added query about which protocols are supported
Claus Gittinger <cg@exept.de>
parents: 532
diff changeset
   160
#ifdef WANT__AF_NS      /* Xerox XNS */
525
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
   161
# ifdef AF_NS
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
   162
#  ifndef PF_NS
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
   163
#   define PF_NS AF_NS
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
   164
#  endif
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   165
# endif
525
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
   166
#else
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
   167
# undef AF_NS
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   168
#endif
525
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
   169
533
ced9950b551f added query about which protocols are supported
Claus Gittinger <cg@exept.de>
parents: 532
diff changeset
   170
#ifdef WANT__AF_SNA     /* IBM SNA */
525
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
   171
# ifdef AF_SNA
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
   172
#  ifndef PF_SNA
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
   173
#   define PF_SNA AF_SNA
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
   174
#  endif
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   175
# endif
525
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
   176
#else
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
   177
# undef AF_SNA
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
   178
#endif
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
   179
533
ced9950b551f added query about which protocols are supported
Claus Gittinger <cg@exept.de>
parents: 532
diff changeset
   180
#ifdef WANT__AF_RAW     /* RAW packets */
525
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
   181
# ifdef AF_RAW
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
   182
#  ifndef PF_RAW
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
   183
#   define PF_RAW AF_RAW
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
   184
#  endif
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
   185
# endif
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
   186
#else
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
   187
# undef AF_RAW
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   188
#endif
525
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
   189
533
ced9950b551f added query about which protocols are supported
Claus Gittinger <cg@exept.de>
parents: 532
diff changeset
   190
#ifdef WANT__AF_ISO     /* ? */
525
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
   191
# ifdef AF_ISO
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
   192
#  ifndef PF_ISO
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
   193
#   define PF_ISO AF_ISO
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
   194
#  endif
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
   195
# endif
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
   196
#else
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
   197
# undef AF_ISO
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
   198
#endif
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
   199
530
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
   200
#ifdef WANT__AF_NETBIOS /* ? */
525
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
   201
# ifdef AF_NETBIOS
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
   202
#  ifndef PF_NETBIOS
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
   203
#   define PF_NETBIOS AF_NETBIOS
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
   204
#  endif
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   205
# endif
525
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
   206
#else
533
ced9950b551f added query about which protocols are supported
Claus Gittinger <cg@exept.de>
parents: 532
diff changeset
   207
# undef AF_NETBIOS
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   208
#endif
525
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
   209
530
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
   210
#ifdef WANT__AF_CCITT /* ? */
525
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
   211
# if defined(AF_CCITT) && (AF_CCITT != AF_X25)
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
   212
#  ifndef PF_CCITT
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
   213
#   define PF_CCITT AF_CCITT
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
   214
#  endif
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
   215
# endif
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
   216
#else
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
   217
# undef AF_CCITT
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
   218
#endif
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
   219
530
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
   220
#ifdef WANT__AF_IPX /* Novell IPX */
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
   221
# ifdef AF_IPX
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
   222
#  ifndef PF_IPX
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
   223
#   define PF_IPX AF_IPX
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
# endif
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
   226
#else
533
ced9950b551f added query about which protocols are supported
Claus Gittinger <cg@exept.de>
parents: 532
diff changeset
   227
# undef AF_IPX
530
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
   228
#endif
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
   229
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
   230
#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
   231
# ifdef AF_AX25
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
   232
#  ifndef PF_AX25
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
   233
#   define PF_AX25 AF_AX25
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
# endif
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
   236
#else
533
ced9950b551f added query about which protocols are supported
Claus Gittinger <cg@exept.de>
parents: 532
diff changeset
   237
# undef AF_AX25
530
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
   238
#endif
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
   239
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
   240
#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
   241
# ifdef AF_NETROM
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
   242
#  ifndef PF_NETROM
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
   243
#   define PF_NETROM AF_NETROM
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
# endif
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
   246
#else
533
ced9950b551f added query about which protocols are supported
Claus Gittinger <cg@exept.de>
parents: 532
diff changeset
   247
# undef AF_NETROM
530
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
   248
#endif
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
   249
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
   250
#ifdef WANT__AF_BRIDGE /* multiprotocol bridge */
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
   251
# ifdef AF_BRIDGE
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
   252
#  ifndef PF_BRIDGE
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
   253
#   define PF_BRIDGE AF_BRIDGE
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
# endif
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
   256
#else
533
ced9950b551f added query about which protocols are supported
Claus Gittinger <cg@exept.de>
parents: 532
diff changeset
   257
# undef AF_BRIDGE
530
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
   258
#endif
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
   259
571
191b37534643 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 563
diff changeset
   260
#ifdef WANT__AF_BSC /* BISYNC 2780/3780 */
191b37534643 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 563
diff changeset
   261
# ifdef AF_BSC
191b37534643 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 563
diff changeset
   262
#  ifndef PF_BSC
191b37534643 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 563
diff changeset
   263
#   define PF_BSC AF_BSC
191b37534643 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 563
diff changeset
   264
#  endif
191b37534643 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 563
diff changeset
   265
# endif
191b37534643 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 563
diff changeset
   266
#else
191b37534643 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 563
diff changeset
   267
# undef AF_BSC
191b37534643 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 563
diff changeset
   268
#endif
191b37534643 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 563
diff changeset
   269
191b37534643 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 563
diff changeset
   270
528
928f68d9c080 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 527
diff changeset
   271
/*
928f68d9c080 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 527
diff changeset
   272
 * now, include what we have to ...
928f68d9c080 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 527
diff changeset
   273
 */
739
eb3878300c3b removed WIN32 ifdef's - win32 uses Socket_win32.st anyway.
Claus Gittinger <cg@exept.de>
parents: 726
diff changeset
   274
eb3878300c3b removed WIN32 ifdef's - win32 uses Socket_win32.st anyway.
Claus Gittinger <cg@exept.de>
parents: 726
diff changeset
   275
#ifdef AF_INET
eb3878300c3b removed WIN32 ifdef's - win32 uses Socket_win32.st anyway.
Claus Gittinger <cg@exept.de>
parents: 726
diff changeset
   276
# include <netdb.h>
eb3878300c3b removed WIN32 ifdef's - win32 uses Socket_win32.st anyway.
Claus Gittinger <cg@exept.de>
parents: 726
diff changeset
   277
# 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
   278
#  include <linux/in.h>
eb3878300c3b removed WIN32 ifdef's - win32 uses Socket_win32.st anyway.
Claus Gittinger <cg@exept.de>
parents: 726
diff changeset
   279
# else
eb3878300c3b removed WIN32 ifdef's - win32 uses Socket_win32.st anyway.
Claus Gittinger <cg@exept.de>
parents: 726
diff changeset
   280
#  include <netinet/in.h>
eb3878300c3b removed WIN32 ifdef's - win32 uses Socket_win32.st anyway.
Claus Gittinger <cg@exept.de>
parents: 726
diff changeset
   281
# endif
eb3878300c3b removed WIN32 ifdef's - win32 uses Socket_win32.st anyway.
Claus Gittinger <cg@exept.de>
parents: 726
diff changeset
   282
# 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
   283
#  include <netinet/tcp.h>
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
#endif
eb3878300c3b removed WIN32 ifdef's - win32 uses Socket_win32.st anyway.
Claus Gittinger <cg@exept.de>
parents: 726
diff changeset
   286
eb3878300c3b removed WIN32 ifdef's - win32 uses Socket_win32.st anyway.
Claus Gittinger <cg@exept.de>
parents: 726
diff changeset
   287
#ifdef AF_INET6
eb3878300c3b removed WIN32 ifdef's - win32 uses Socket_win32.st anyway.
Claus Gittinger <cg@exept.de>
parents: 726
diff changeset
   288
# ifdef __GLIBC__
eb3878300c3b removed WIN32 ifdef's - win32 uses Socket_win32.st anyway.
Claus Gittinger <cg@exept.de>
parents: 726
diff changeset
   289
#  include <linux/in6.h>
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   290
# endif
739
eb3878300c3b removed WIN32 ifdef's - win32 uses Socket_win32.st anyway.
Claus Gittinger <cg@exept.de>
parents: 726
diff changeset
   291
#endif
eb3878300c3b removed WIN32 ifdef's - win32 uses Socket_win32.st anyway.
Claus Gittinger <cg@exept.de>
parents: 726
diff changeset
   292
eb3878300c3b removed WIN32 ifdef's - win32 uses Socket_win32.st anyway.
Claus Gittinger <cg@exept.de>
parents: 726
diff changeset
   293
#ifdef AF_UNIX
eb3878300c3b removed WIN32 ifdef's - win32 uses Socket_win32.st anyway.
Claus Gittinger <cg@exept.de>
parents: 726
diff changeset
   294
# include <sys/un.h>
eb3878300c3b removed WIN32 ifdef's - win32 uses Socket_win32.st anyway.
Claus Gittinger <cg@exept.de>
parents: 726
diff changeset
   295
#endif
eb3878300c3b removed WIN32 ifdef's - win32 uses Socket_win32.st anyway.
Claus Gittinger <cg@exept.de>
parents: 726
diff changeset
   296
eb3878300c3b removed WIN32 ifdef's - win32 uses Socket_win32.st anyway.
Claus Gittinger <cg@exept.de>
parents: 726
diff changeset
   297
#ifdef AF_APPLETALK
eb3878300c3b removed WIN32 ifdef's - win32 uses Socket_win32.st anyway.
Claus Gittinger <cg@exept.de>
parents: 726
diff changeset
   298
# ifdef LINUX
eb3878300c3b removed WIN32 ifdef's - win32 uses Socket_win32.st anyway.
Claus Gittinger <cg@exept.de>
parents: 726
diff changeset
   299
#  include <asm/types.h>
eb3878300c3b removed WIN32 ifdef's - win32 uses Socket_win32.st anyway.
Claus Gittinger <cg@exept.de>
parents: 726
diff changeset
   300
#  include <linux/atalk.h>
465
3673e44dbd2f remove windows ^M characters
Claus Gittinger <cg@exept.de>
parents: 464
diff changeset
   301
# endif
739
eb3878300c3b removed WIN32 ifdef's - win32 uses Socket_win32.st anyway.
Claus Gittinger <cg@exept.de>
parents: 726
diff changeset
   302
#endif
eb3878300c3b removed WIN32 ifdef's - win32 uses Socket_win32.st anyway.
Claus Gittinger <cg@exept.de>
parents: 726
diff changeset
   303
eb3878300c3b removed WIN32 ifdef's - win32 uses Socket_win32.st anyway.
Claus Gittinger <cg@exept.de>
parents: 726
diff changeset
   304
#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
   305
# define USE_H_ERRNO
eb3878300c3b removed WIN32 ifdef's - win32 uses Socket_win32.st anyway.
Claus Gittinger <cg@exept.de>
parents: 726
diff changeset
   306
#endif
eb3878300c3b removed WIN32 ifdef's - win32 uses Socket_win32.st anyway.
Claus Gittinger <cg@exept.de>
parents: 726
diff changeset
   307
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   308
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   309
/*
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   310
 * on some systems errno is a macro ... check for it here
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   311
 */
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   312
#ifndef errno
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   313
 extern errno;
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   314
#endif
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   315
648
58e11a70ddaf gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents: 617
diff changeset
   316
#ifdef USE_H_ERRNO
58e11a70ddaf gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents: 617
diff changeset
   317
# ifndef h_errno
58e11a70ddaf gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents: 617
diff changeset
   318
 extern h_errno;
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
#endif
58e11a70ddaf gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents: 617
diff changeset
   321
720
967fad20a8f1 newest stdio uses __new
Claus Gittinger <cg@exept.de>
parents: 711
diff changeset
   322
#ifdef xxLINUX
967fad20a8f1 newest stdio uses __new
Claus Gittinger <cg@exept.de>
parents: 711
diff changeset
   323
/* use inline string macros ... */
967fad20a8f1 newest stdio uses __new
Claus Gittinger <cg@exept.de>
parents: 711
diff changeset
   324
# define __STRINGDEFS__
967fad20a8f1 newest stdio uses __new
Claus Gittinger <cg@exept.de>
parents: 711
diff changeset
   325
# include <linuxIntern.h>
967fad20a8f1 newest stdio uses __new
Claus Gittinger <cg@exept.de>
parents: 711
diff changeset
   326
#endif
967fad20a8f1 newest stdio uses __new
Claus Gittinger <cg@exept.de>
parents: 711
diff changeset
   327
648
58e11a70ddaf gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents: 617
diff changeset
   328
/*
58e11a70ddaf gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents: 617
diff changeset
   329
 * 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
   330
 * 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
   331
 * 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
   332
 * (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
   333
 * 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
   334
 */
692
85d64f84be0c oops - do not make gethostbyaddr / byname interruptable;
Claus Gittinger <cg@exept.de>
parents: 672
diff changeset
   335
#ifdef LINUX
85d64f84be0c oops - do not make gethostbyaddr / byname interruptable;
Claus Gittinger <cg@exept.de>
parents: 672
diff changeset
   336
85d64f84be0c oops - do not make gethostbyaddr / byname interruptable;
Claus Gittinger <cg@exept.de>
parents: 672
diff changeset
   337
# define GETHOSTBYNAME(hp, name) \
85d64f84be0c oops - do not make gethostbyaddr / byname interruptable;
Claus Gittinger <cg@exept.de>
parents: 672
diff changeset
   338
	hp = gethostbyname((char *) name);
85d64f84be0c oops - do not make gethostbyaddr / byname interruptable;
Claus Gittinger <cg@exept.de>
parents: 672
diff changeset
   339
85d64f84be0c oops - do not make gethostbyaddr / byname interruptable;
Claus Gittinger <cg@exept.de>
parents: 672
diff changeset
   340
# define GETHOSTBYADDR(hp, addr, alen, af) \
85d64f84be0c oops - do not make gethostbyaddr / byname interruptable;
Claus Gittinger <cg@exept.de>
parents: 672
diff changeset
   341
	hp = gethostbyaddr(addr, alen, af);
85d64f84be0c oops - do not make gethostbyaddr / byname interruptable;
Claus Gittinger <cg@exept.de>
parents: 672
diff changeset
   342
85d64f84be0c oops - do not make gethostbyaddr / byname interruptable;
Claus Gittinger <cg@exept.de>
parents: 672
diff changeset
   343
#else
85d64f84be0c oops - do not make gethostbyaddr / byname interruptable;
Claus Gittinger <cg@exept.de>
parents: 672
diff changeset
   344
693
c7a1bf49dcf5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 692
diff changeset
   345
# ifdef IRIX5_3
c7a1bf49dcf5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 692
diff changeset
   346
#  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
   347
	do { \
58e11a70ddaf gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents: 617
diff changeset
   348
	    __BEGIN_INTERRUPTABLE__  \
58e11a70ddaf gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents: 617
diff changeset
   349
	    hp = gethostbyname((char *) name); \
58e11a70ddaf gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents: 617
diff changeset
   350
	    __END_INTERRUPTABLE__ \
58e11a70ddaf gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents: 617
diff changeset
   351
	} while ((hp == NULL) && \
58e11a70ddaf gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents: 617
diff changeset
   352
		 ((h_errno == TRY_AGAIN) || (errno == ECONNREFUSED)));
650
8c5616f17ed6 made gethostbyaddr interruptable
Claus Gittinger <cg@exept.de>
parents: 649
diff changeset
   353
693
c7a1bf49dcf5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 692
diff changeset
   354
#  define GETHOSTBYADDR(hp, addr, alen, af) \
789
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
   355
	do { \
650
8c5616f17ed6 made gethostbyaddr interruptable
Claus Gittinger <cg@exept.de>
parents: 649
diff changeset
   356
	    __BEGIN_INTERRUPTABLE__ \
8c5616f17ed6 made gethostbyaddr interruptable
Claus Gittinger <cg@exept.de>
parents: 649
diff changeset
   357
	    hp = gethostbyaddr(addr, alen, af); \
8c5616f17ed6 made gethostbyaddr interruptable
Claus Gittinger <cg@exept.de>
parents: 649
diff changeset
   358
	    __END_INTERRUPTABLE__ \
8c5616f17ed6 made gethostbyaddr interruptable
Claus Gittinger <cg@exept.de>
parents: 649
diff changeset
   359
	} while ((hp == NULL) && \
8c5616f17ed6 made gethostbyaddr interruptable
Claus Gittinger <cg@exept.de>
parents: 649
diff changeset
   360
		((h_errno == TRY_AGAIN) || (errno == ECONNREFUSED)));
693
c7a1bf49dcf5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 692
diff changeset
   361
# else
c7a1bf49dcf5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 692
diff changeset
   362
#  ifdef USE_H_ERRNO
c7a1bf49dcf5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 692
diff changeset
   363
#   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
   364
	do { \
58e11a70ddaf gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents: 617
diff changeset
   365
	    __BEGIN_INTERRUPTABLE__  \
58e11a70ddaf gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents: 617
diff changeset
   366
	    hp = gethostbyname((char *) name); \
58e11a70ddaf gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents: 617
diff changeset
   367
	    __END_INTERRUPTABLE__ \
58e11a70ddaf gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents: 617
diff changeset
   368
	} while ((hp == NULL) && (h_errno == TRY_AGAIN));
650
8c5616f17ed6 made gethostbyaddr interruptable
Claus Gittinger <cg@exept.de>
parents: 649
diff changeset
   369
693
c7a1bf49dcf5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 692
diff changeset
   370
#   define GETHOSTBYADDR(hp, addr, alen, af) \
650
8c5616f17ed6 made gethostbyaddr interruptable
Claus Gittinger <cg@exept.de>
parents: 649
diff changeset
   371
	do { \
8c5616f17ed6 made gethostbyaddr interruptable
Claus Gittinger <cg@exept.de>
parents: 649
diff changeset
   372
	    __BEGIN_INTERRUPTABLE__  \
8c5616f17ed6 made gethostbyaddr interruptable
Claus Gittinger <cg@exept.de>
parents: 649
diff changeset
   373
	    hp = gethostbyaddr(addr, alen, af); \
8c5616f17ed6 made gethostbyaddr interruptable
Claus Gittinger <cg@exept.de>
parents: 649
diff changeset
   374
	    __END_INTERRUPTABLE__ \
8c5616f17ed6 made gethostbyaddr interruptable
Claus Gittinger <cg@exept.de>
parents: 649
diff changeset
   375
	} while ((hp == NULL) && (h_errno == TRY_AGAIN));
693
c7a1bf49dcf5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 692
diff changeset
   376
#  else
c7a1bf49dcf5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 692
diff changeset
   377
#   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
   378
	__BEGIN_INTERRUPTABLE__  \
58e11a70ddaf gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents: 617
diff changeset
   379
	hp = gethostbyname((char *) name); \
58e11a70ddaf gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents: 617
diff changeset
   380
	__END_INTERRUPTABLE__ 
650
8c5616f17ed6 made gethostbyaddr interruptable
Claus Gittinger <cg@exept.de>
parents: 649
diff changeset
   381
693
c7a1bf49dcf5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 692
diff changeset
   382
#   define GETHOSTBYADDR(hp, addr, alen, af) \
650
8c5616f17ed6 made gethostbyaddr interruptable
Claus Gittinger <cg@exept.de>
parents: 649
diff changeset
   383
	__BEGIN_INTERRUPTABLE__ \
8c5616f17ed6 made gethostbyaddr interruptable
Claus Gittinger <cg@exept.de>
parents: 649
diff changeset
   384
	hp = gethostbyaddr(addr, alen, af); \
8c5616f17ed6 made gethostbyaddr interruptable
Claus Gittinger <cg@exept.de>
parents: 649
diff changeset
   385
	__END_INTERRUPTABLE__
693
c7a1bf49dcf5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 692
diff changeset
   386
#  endif
648
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
#endif
58e11a70ddaf gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents: 617
diff changeset
   389
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   390
#ifdef DEBUG
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   391
# define DBGPRINTF(x)    { if (__debugging__) printf x; }
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   392
#else
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   393
# define DBGPRINTF(x)    /* as nothing */
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   394
#endif
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   395
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   396
%}
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   397
! !
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   398
511
c071e228cb24 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 510
diff changeset
   399
!Socket primitiveVariables!
c071e228cb24 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 510
diff changeset
   400
%{
c071e228cb24 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 510
diff changeset
   401
static int __debugging__ = 0;
c071e228cb24 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 510
diff changeset
   402
%}
c071e228cb24 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 510
diff changeset
   403
! !
c071e228cb24 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 510
diff changeset
   404
464
600b101a7035 alen in accept
Claus Gittinger <cg@exept.de>
parents: 463
diff changeset
   405
!Socket class methodsFor:'documentation'!
25
996051271ce9 *** empty log message ***
claus
parents: 21
diff changeset
   406
31
e223f3cf2995 *** empty log message ***
claus
parents: 28
diff changeset
   407
copyright
e223f3cf2995 *** empty log message ***
claus
parents: 28
diff changeset
   408
"
e223f3cf2995 *** empty log message ***
claus
parents: 28
diff changeset
   409
 COPYRIGHT (c) 1992 by Claus Gittinger
42
506596f9a1a8 *** empty log message ***
claus
parents: 38
diff changeset
   410
	      All Rights Reserved
31
e223f3cf2995 *** empty log message ***
claus
parents: 28
diff changeset
   411
e223f3cf2995 *** empty log message ***
claus
parents: 28
diff changeset
   412
 This software is furnished under a license and may be used
e223f3cf2995 *** empty log message ***
claus
parents: 28
diff changeset
   413
 only in accordance with the terms of that license and with the
e223f3cf2995 *** empty log message ***
claus
parents: 28
diff changeset
   414
 inclusion of the above copyright notice.   This software may not
e223f3cf2995 *** empty log message ***
claus
parents: 28
diff changeset
   415
 be provided or otherwise made available to, or used by, any
e223f3cf2995 *** empty log message ***
claus
parents: 28
diff changeset
   416
 other person.  No title to or ownership of the software is
e223f3cf2995 *** empty log message ***
claus
parents: 28
diff changeset
   417
 hereby transferred.
e223f3cf2995 *** empty log message ***
claus
parents: 28
diff changeset
   418
"
e223f3cf2995 *** empty log message ***
claus
parents: 28
diff changeset
   419
!
e223f3cf2995 *** empty log message ***
claus
parents: 28
diff changeset
   420
25
996051271ce9 *** empty log message ***
claus
parents: 21
diff changeset
   421
documentation
996051271ce9 *** empty log message ***
claus
parents: 21
diff changeset
   422
"
524
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
   423
    This class provides access to sockets for interprocess communication.
25
996051271ce9 *** empty log message ***
claus
parents: 21
diff changeset
   424
    The message protocol is preliminary, until someone tells me how
31
e223f3cf2995 *** empty log message ***
claus
parents: 28
diff changeset
   425
    other smalltalk's socket interfaces look like.
25
996051271ce9 *** empty log message ***
claus
parents: 21
diff changeset
   426
525
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
   427
    Currently, only IP and UNIX domain sockets are supported.
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
   428
    Code for appletalk is included, but was never tested ...
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
   429
    More may be added in the future.
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
   430
    (the code is prepared for things like SNA or decNet;
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
   431
     however, right now, this code is empty and needs a little work.
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
   432
     Implementing those is pretty straight forward, once the address
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
   433
     data structures are known.)
524
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
   434
28
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
   435
    Due to historic reasons (I started this class, before I got hold of some
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
   436
    code using ST-80 Sockets i.e. RemoteInvocation), there is some old interface
71
claus
parents: 63
diff changeset
   437
    still provided. 
524
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
   438
    This will vanish; use the #family:type: or #newTCPxxx and #newUDPxxx interfaces,
71
claus
parents: 63
diff changeset
   439
    together with the bind/listen and accept calls,
claus
parents: 63
diff changeset
   440
    which are meant to be compatible to ST-80's UnixSocketAccessor interface.
claus
parents: 63
diff changeset
   441
524
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
   442
    ST/X does not use IPSocketAddress, UDSocketAddress etc; all addressing
71
claus
parents: 63
diff changeset
   443
    is done by passing appropriate string- or byteArray objects containing
claus
parents: 63
diff changeset
   444
    the addresses. This may change, too.
claus
parents: 63
diff changeset
   445
claus
parents: 63
diff changeset
   446
    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
   447
	  (mhmh - how can I test those ?)
532
f997c3873602 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 531
diff changeset
   448
	  change to raise more signals on errors.
529
fc7ec265717b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   449
	  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
   450
		 net please test this (and send bug fixes ...)
259
6d36f3ac42a2 documentation
Claus Gittinger <cg@exept.de>
parents: 220
diff changeset
   451
6d36f3ac42a2 documentation
Claus Gittinger <cg@exept.de>
parents: 220
diff changeset
   452
    [author:]
425
eb8198e9f1b0 comment
Claus Gittinger <cg@exept.de>
parents: 421
diff changeset
   453
	Claus Gittinger
48
18b9353c9d07 *** empty log message ***
claus
parents: 44
diff changeset
   454
"
18b9353c9d07 *** empty log message ***
claus
parents: 44
diff changeset
   455
!
28
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
   456
48
18b9353c9d07 *** empty log message ***
claus
parents: 44
diff changeset
   457
examples
18b9353c9d07 *** empty log message ***
claus
parents: 44
diff changeset
   458
"
28
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
   459
    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
   460
									[exBegin]
58e11a70ddaf gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents: 617
diff changeset
   461
	|sock host|
58e11a70ddaf gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents: 617
diff changeset
   462
58e11a70ddaf gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents: 617
diff changeset
   463
	host := OperatingSystem getEnvironment:'NNTPSERVER'.
58e11a70ddaf gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents: 617
diff changeset
   464
58e11a70ddaf gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents: 617
diff changeset
   465
	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
   466
	Transcript showCR:sock nextLine.
58e11a70ddaf gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents: 617
diff changeset
   467
	sock buffered:false.
58e11a70ddaf gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents: 617
diff changeset
   468
58e11a70ddaf gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents: 617
diff changeset
   469
	sock nextPutAll:'HELP'; cr.
58e11a70ddaf gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents: 617
diff changeset
   470
	[:exit |
58e11a70ddaf gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents: 617
diff changeset
   471
	    |line|
58e11a70ddaf gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents: 617
diff changeset
   472
58e11a70ddaf gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents: 617
diff changeset
   473
	    line := sock nextLine.
58e11a70ddaf gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents: 617
diff changeset
   474
	    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
   475
	    Transcript showCR:line.
58e11a70ddaf gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents: 617
diff changeset
   476
	] loopWithExit.
58e11a70ddaf gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents: 617
diff changeset
   477
	sock close
58e11a70ddaf gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents: 617
diff changeset
   478
									[exEnd]
209
2152fceba563 finger example
Claus Gittinger <cg@exept.de>
parents: 208
diff changeset
   479
28
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
   480
209
2152fceba563 finger example
Claus Gittinger <cg@exept.de>
parents: 208
diff changeset
   481
    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
   482
									[exBegin]
58e11a70ddaf gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents: 617
diff changeset
   483
	|sock host entry|
58e11a70ddaf gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents: 617
diff changeset
   484
58e11a70ddaf gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents: 617
diff changeset
   485
	host := OperatingSystem getHostName.
58e11a70ddaf gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents: 617
diff changeset
   486
58e11a70ddaf gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents: 617
diff changeset
   487
	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
   488
	sock isNil ifTrue:[
58e11a70ddaf gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents: 617
diff changeset
   489
	    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
   490
	    ^ self
58e11a70ddaf gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents: 617
diff changeset
   491
	].
58e11a70ddaf gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents: 617
diff changeset
   492
	sock useCRLF:true.
58e11a70ddaf gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents: 617
diff changeset
   493
	sock buffered:false.
58e11a70ddaf gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents: 617
diff changeset
   494
	sock isNil ifTrue:[
58e11a70ddaf gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents: 617
diff changeset
   495
	    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
   496
	] ifFalse:[
58e11a70ddaf gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents: 617
diff changeset
   497
	    sock nextPutAll:(OperatingSystem getLoginName).
58e11a70ddaf gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents: 617
diff changeset
   498
	    sock cr.
58e11a70ddaf gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents: 617
diff changeset
   499
58e11a70ddaf gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents: 617
diff changeset
   500
	    entry := sock nextLine.
58e11a70ddaf gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents: 617
diff changeset
   501
	    Transcript showCR:entry.
58e11a70ddaf gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents: 617
diff changeset
   502
58e11a70ddaf gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents: 617
diff changeset
   503
	    sock close
58e11a70ddaf gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents: 617
diff changeset
   504
	]
58e11a70ddaf gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents: 617
diff changeset
   505
									[exEnd]
99
7d016cc30052 fixed & moved pingWalk from SNMPSession to here;
Claus Gittinger <cg@exept.de>
parents: 98
diff changeset
   506
28
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
   507
    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
   508
									[exBegin]
58e11a70ddaf gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents: 617
diff changeset
   509
	|sock host|
58e11a70ddaf gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents: 617
diff changeset
   510
58e11a70ddaf gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents: 617
diff changeset
   511
	host := OperatingSystem getHostName.
58e11a70ddaf gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents: 617
diff changeset
   512
	sock := Socket newTCPclientToHost:host port:'ftp'.
58e11a70ddaf gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents: 617
diff changeset
   513
58e11a70ddaf gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents: 617
diff changeset
   514
	sock buffered:false.
58e11a70ddaf gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents: 617
diff changeset
   515
	Transcript showCR:sock nextLine.
58e11a70ddaf gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents: 617
diff changeset
   516
	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
   517
	Transcript showCR:sock nextLine.
58e11a70ddaf gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents: 617
diff changeset
   518
	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
   519
	Transcript showCR:sock nextLine.
58e11a70ddaf gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents: 617
diff changeset
   520
	sock nextPutAll:'LIST'; cr.
58e11a70ddaf gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents: 617
diff changeset
   521
	Transcript showCR:sock nextLine.
58e11a70ddaf gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents: 617
diff changeset
   522
	sock close.
58e11a70ddaf gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents: 617
diff changeset
   523
58e11a70ddaf gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents: 617
diff changeset
   524
	'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
   525
									[exEnd]
28
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
   526
99
7d016cc30052 fixed & moved pingWalk from SNMPSession to here;
Claus Gittinger <cg@exept.de>
parents: 98
diff changeset
   527
93
Claus Gittinger <cg@exept.de>
parents: 92
diff changeset
   528
    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
   529
									[exBegin]
58e11a70ddaf gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents: 617
diff changeset
   530
	|sock port|
58e11a70ddaf gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents: 617
diff changeset
   531
58e11a70ddaf gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents: 617
diff changeset
   532
	sock := Socket newUDP.
58e11a70ddaf gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents: 617
diff changeset
   533
	port := Socket portOfService:'snmp'.
58e11a70ddaf gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents: 617
diff changeset
   534
	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
   535
	sock buffered:false.
58e11a70ddaf gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents: 617
diff changeset
   536
	Transcript showCR:'got it'.
58e11a70ddaf gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents: 617
diff changeset
   537
	sock close.
58e11a70ddaf gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents: 617
diff changeset
   538
									[exEnd]
42
506596f9a1a8 *** empty log message ***
claus
parents: 38
diff changeset
   539
99
7d016cc30052 fixed & moved pingWalk from SNMPSession to here;
Claus Gittinger <cg@exept.de>
parents: 98
diff changeset
   540
42
506596f9a1a8 *** empty log message ***
claus
parents: 38
diff changeset
   541
    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
   542
	|connectSock sock|
58e11a70ddaf gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents: 617
diff changeset
   543
58e11a70ddaf gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents: 617
diff changeset
   544
	connectSock := Socket newTCPserverAtPort:9998.  
58e11a70ddaf gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents: 617
diff changeset
   545
	connectSock isNil ifTrue:[
58e11a70ddaf gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents: 617
diff changeset
   546
	    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
   547
	] ifFalse:[
58e11a70ddaf gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents: 617
diff changeset
   548
	    Transcript showCR:'listen ..'.
58e11a70ddaf gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents: 617
diff changeset
   549
	    (connectSock listenFor:5) ifFalse:[
58e11a70ddaf gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents: 617
diff changeset
   550
		Transcript showCR:'listen failed.'.
58e11a70ddaf gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents: 617
diff changeset
   551
	    ] ifTrue:[
58e11a70ddaf gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents: 617
diff changeset
   552
		Transcript showCR:'wait'.
58e11a70ddaf gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents: 617
diff changeset
   553
		connectSock readWait.  
58e11a70ddaf gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents: 617
diff changeset
   554
		Transcript showCR:'accept'.
58e11a70ddaf gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents: 617
diff changeset
   555
		sock := connectSock accept.
58e11a70ddaf gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents: 617
diff changeset
   556
		sock isNil ifTrue:[
58e11a70ddaf gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents: 617
diff changeset
   557
		    Transcript showCR:'accept failed.'.
58e11a70ddaf gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents: 617
diff changeset
   558
		] ifFalse:[
58e11a70ddaf gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents: 617
diff changeset
   559
		    sock buffered:false.
58e11a70ddaf gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents: 617
diff changeset
   560
		    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
   561
		    '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
   562
		    Transcript showCR:'read'.
58e11a70ddaf gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents: 617
diff changeset
   563
		    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
   564
58e11a70ddaf gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents: 617
diff changeset
   565
		    Transcript showCR:'close'.
58e11a70ddaf gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents: 617
diff changeset
   566
		    sock close
58e11a70ddaf gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents: 617
diff changeset
   567
		].
58e11a70ddaf gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents: 617
diff changeset
   568
		connectSock close.
58e11a70ddaf gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents: 617
diff changeset
   569
	    ]
58e11a70ddaf gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents: 617
diff changeset
   570
	]
42
506596f9a1a8 *** empty log message ***
claus
parents: 38
diff changeset
   571
99
7d016cc30052 fixed & moved pingWalk from SNMPSession to here;
Claus Gittinger <cg@exept.de>
parents: 98
diff changeset
   572
42
506596f9a1a8 *** empty log message ***
claus
parents: 38
diff changeset
   573
    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
   574
	|sock|
58e11a70ddaf gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents: 617
diff changeset
   575
58e11a70ddaf gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents: 617
diff changeset
   576
	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
   577
	sock isNil ifTrue:[
58e11a70ddaf gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents: 617
diff changeset
   578
	    Transcript showCR:'nope'
58e11a70ddaf gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents: 617
diff changeset
   579
	] ifFalse:[
58e11a70ddaf gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents: 617
diff changeset
   580
	    sock buffered:false.
58e11a70ddaf gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents: 617
diff changeset
   581
	    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
   582
	    '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
   583
	    Transcript showCR:'sending <hello>'.
58e11a70ddaf gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents: 617
diff changeset
   584
	    sock nextPutLine:'hello'.
58e11a70ddaf gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents: 617
diff changeset
   585
	    sock close
58e11a70ddaf gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents: 617
diff changeset
   586
	]
117
03cefad7e40b UD socket example & interruptable bind
Claus Gittinger <cg@exept.de>
parents: 116
diff changeset
   587
03cefad7e40b UD socket example & interruptable bind
Claus Gittinger <cg@exept.de>
parents: 116
diff changeset
   588
    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
   589
648
58e11a70ddaf gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents: 617
diff changeset
   590
	|connectSock sock|
58e11a70ddaf gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents: 617
diff changeset
   591
58e11a70ddaf gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents: 617
diff changeset
   592
	'/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
   593
	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
   594
	connectSock isNil ifTrue:[
58e11a70ddaf gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents: 617
diff changeset
   595
	    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
   596
	] ifFalse:[
58e11a70ddaf gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents: 617
diff changeset
   597
	    Transcript showCR:'listen ..'.
58e11a70ddaf gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents: 617
diff changeset
   598
	    (connectSock listenFor:5) ifFalse:[
58e11a70ddaf gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents: 617
diff changeset
   599
		Transcript showCR:'listen failed.'.
58e11a70ddaf gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents: 617
diff changeset
   600
	    ] ifTrue:[
58e11a70ddaf gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents: 617
diff changeset
   601
		Transcript showCR:'wait'.
58e11a70ddaf gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents: 617
diff changeset
   602
		connectSock buffered:false.
58e11a70ddaf gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents: 617
diff changeset
   603
		connectSock readWait.  
58e11a70ddaf gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents: 617
diff changeset
   604
		Transcript showCR:'accept'.
58e11a70ddaf gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents: 617
diff changeset
   605
		sock := connectSock accept.
58e11a70ddaf gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents: 617
diff changeset
   606
		sock isNil ifTrue:[
58e11a70ddaf gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents: 617
diff changeset
   607
		    Transcript showCR:'accept failed.'.
58e11a70ddaf gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents: 617
diff changeset
   608
		] ifFalse:[
58e11a70ddaf gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents: 617
diff changeset
   609
		    sock buffered:false.
58e11a70ddaf gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents: 617
diff changeset
   610
		    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
   611
		    '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
   612
		    Transcript showCR:'read'.
58e11a70ddaf gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents: 617
diff changeset
   613
		    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
   614
58e11a70ddaf gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents: 617
diff changeset
   615
		    Transcript showCR:'close'.
58e11a70ddaf gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents: 617
diff changeset
   616
		    sock close
58e11a70ddaf gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents: 617
diff changeset
   617
		].
58e11a70ddaf gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents: 617
diff changeset
   618
		connectSock close.
58e11a70ddaf gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents: 617
diff changeset
   619
	    ]
58e11a70ddaf gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents: 617
diff changeset
   620
	]
117
03cefad7e40b UD socket example & interruptable bind
Claus Gittinger <cg@exept.de>
parents: 116
diff changeset
   621
03cefad7e40b UD socket example & interruptable bind
Claus Gittinger <cg@exept.de>
parents: 116
diff changeset
   622
118
142d5c273454 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 117
diff changeset
   623
    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
   624
	     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
   625
		     (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
   626
		     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
   627
		     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
   628
58e11a70ddaf gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents: 617
diff changeset
   629
	|sock|
58e11a70ddaf gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents: 617
diff changeset
   630
58e11a70ddaf gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents: 617
diff changeset
   631
	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
   632
	sock isNil ifTrue:[
58e11a70ddaf gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents: 617
diff changeset
   633
	    Transcript showCR:'nope'
58e11a70ddaf gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents: 617
diff changeset
   634
	] ifFalse:[
58e11a70ddaf gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents: 617
diff changeset
   635
	    sock buffered:false.
58e11a70ddaf gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents: 617
diff changeset
   636
	    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
   637
	    '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
   638
	    Transcript showCR:'sending <hello>'.
58e11a70ddaf gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents: 617
diff changeset
   639
	    sock nextPutLine:'hello'.
58e11a70ddaf gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents: 617
diff changeset
   640
	    sock close
58e11a70ddaf gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents: 617
diff changeset
   641
	]
99
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
7d016cc30052 fixed & moved pingWalk from SNMPSession to here;
Claus Gittinger <cg@exept.de>
parents: 98
diff changeset
   644
    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
   645
									[exBegin]
58e11a70ddaf gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents: 617
diff changeset
   646
	|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
   647
58e11a70ddaf gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents: 617
diff changeset
   648
	myName := OperatingSystem getHostName.
58e11a70ddaf gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents: 617
diff changeset
   649
	myAddress := Socket ipAddressOfHost:myName.
58e11a70ddaf gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents: 617
diff changeset
   650
58e11a70ddaf gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents: 617
diff changeset
   651
	port := Socket portOfService:'echo'.
58e11a70ddaf gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents: 617
diff changeset
   652
	port isNil ifTrue:[
58e11a70ddaf gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents: 617
diff changeset
   653
	    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
   654
	    ^ self
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
58e11a70ddaf gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents: 617
diff changeset
   657
	top := StandardSystemView new.
58e11a70ddaf gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents: 617
diff changeset
   658
	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
   659
58e11a70ddaf gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents: 617
diff changeset
   660
	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
   661
	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
   662
58e11a70ddaf gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents: 617
diff changeset
   663
	top openAndWait.
58e11a70ddaf gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents: 617
diff changeset
   664
58e11a70ddaf gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents: 617
diff changeset
   665
	walkProcess := [
58e11a70ddaf gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents: 617
diff changeset
   666
	    |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
   667
58e11a70ddaf gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents: 617
diff changeset
   668
	    l := SortedCollection new.
58e11a70ddaf gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents: 617
diff changeset
   669
58e11a70ddaf gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents: 617
diff changeset
   670
	    ' 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
   671
	      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
   672
	      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
   673
	      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
   674
	      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
   675
58e11a70ddaf gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents: 617
diff changeset
   676
	    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
   677
	    direction := 1.
58e11a70ddaf gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents: 617
diff changeset
   678
58e11a70ddaf gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents: 617
diff changeset
   679
	    [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
   680
		direction > 0 ifTrue:[
58e11a70ddaf gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents: 617
diff changeset
   681
		    hi := hi + 1.
58e11a70ddaf gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents: 617
diff changeset
   682
		    tryHostID := hi.
58e11a70ddaf gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents: 617
diff changeset
   683
		    direction := -1.
58e11a70ddaf gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents: 617
diff changeset
   684
		] ifFalse:[
58e11a70ddaf gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents: 617
diff changeset
   685
		    low := low - 1.
58e11a70ddaf gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents: 617
diff changeset
   686
		    tryHostID := low.
58e11a70ddaf gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents: 617
diff changeset
   687
		    direction := 1.
58e11a70ddaf gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents: 617
diff changeset
   688
		].
58e11a70ddaf gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents: 617
diff changeset
   689
		(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
   690
		    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
   691
				  , '.' , (myAddress at:2) printString
58e11a70ddaf gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents: 617
diff changeset
   692
				  , '.' , (myAddress at:3) printString
58e11a70ddaf gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents: 617
diff changeset
   693
				  , '.' , tryHostID printString.
58e11a70ddaf gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents: 617
diff changeset
   694
58e11a70ddaf gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents: 617
diff changeset
   695
		    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
   696
58e11a70ddaf gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents: 617
diff changeset
   697
		    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
   698
			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
   699
			conn notNil ifTrue:[
58e11a70ddaf gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents: 617
diff changeset
   700
			    addr := Socket ipAddressOfHost:dottedName.
58e11a70ddaf gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents: 617
diff changeset
   701
			    hostName := Socket hostWithIpAddress:addr.
58e11a70ddaf gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents: 617
diff changeset
   702
			    hostName isNil ifTrue:[
58e11a70ddaf gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents: 617
diff changeset
   703
				hostName :='?'
58e11a70ddaf gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents: 617
diff changeset
   704
			    ].
58e11a70ddaf gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents: 617
diff changeset
   705
			    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
   706
				   , ' ' 
58e11a70ddaf gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents: 617
diff changeset
   707
				   , (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
   708
				   , ' up & reachable'.
58e11a70ddaf gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents: 617
diff changeset
   709
			    list list:l.
58e11a70ddaf gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents: 617
diff changeset
   710
			    conn close.
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
	    ].
58e11a70ddaf gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents: 617
diff changeset
   715
	    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
   716
	] forkAt:(Processor userBackgroundPriority).
58e11a70ddaf gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents: 617
diff changeset
   717
	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
   718
									[exEnd]
25
996051271ce9 *** empty log message ***
claus
parents: 21
diff changeset
   719
"
996051271ce9 *** empty log message ***
claus
parents: 21
diff changeset
   720
! !
996051271ce9 *** empty log message ***
claus
parents: 21
diff changeset
   721
464
600b101a7035 alen in accept
Claus Gittinger <cg@exept.de>
parents: 463
diff changeset
   722
!Socket class methodsFor:'ST80 instance creation'!
91
Claus Gittinger <cg@exept.de>
parents: 85
diff changeset
   723
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   724
family:domainSymbol type:typeSymbol
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   725
    "create a socket for domain and type - ST80 simply uses a different name.
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   726
     Domain must be one of the symbols: #inet, #unix, #ns, #appletalk or #ns;
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   727
     Type must be #stream, #datagram or #raw
91
Claus Gittinger <cg@exept.de>
parents: 85
diff changeset
   728
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   729
     XXX: currently only the #inet domain is supported"
91
Claus Gittinger <cg@exept.de>
parents: 85
diff changeset
   730
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   731
    ^ self domain:domainSymbol type:typeSymbol
51
24f978f1d849 *** empty log message ***
claus
parents: 48
diff changeset
   732
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   733
    "
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   734
     Socket family:#inet type:#stream
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   735
     Socket family:#inet type:#datagram
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   736
     Socket family:#unix type:#stream
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   737
    "
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   738
! !
93
Claus Gittinger <cg@exept.de>
parents: 92
diff changeset
   739
464
600b101a7035 alen in accept
Claus Gittinger <cg@exept.de>
parents: 463
diff changeset
   740
!Socket class methodsFor:'ST80 queries'!
115
a9d85df931c4 added Unix domain support
Claus Gittinger <cg@exept.de>
parents: 112
diff changeset
   741
617
6ccbaa111a74 added #getHostname (ST80 compatibility)
Claus Gittinger <cg@exept.de>
parents: 604
diff changeset
   742
getHostname
6ccbaa111a74 added #getHostname (ST80 compatibility)
Claus Gittinger <cg@exept.de>
parents: 604
diff changeset
   743
    "return the computers hostname string"
6ccbaa111a74 added #getHostname (ST80 compatibility)
Claus Gittinger <cg@exept.de>
parents: 604
diff changeset
   744
6ccbaa111a74 added #getHostname (ST80 compatibility)
Claus Gittinger <cg@exept.de>
parents: 604
diff changeset
   745
    ^ OperatingSystem getHostName
6ccbaa111a74 added #getHostname (ST80 compatibility)
Claus Gittinger <cg@exept.de>
parents: 604
diff changeset
   746
6ccbaa111a74 added #getHostname (ST80 compatibility)
Claus Gittinger <cg@exept.de>
parents: 604
diff changeset
   747
    "Created: / 27.2.1998 / 02:32:17 / cg"
6ccbaa111a74 added #getHostname (ST80 compatibility)
Claus Gittinger <cg@exept.de>
parents: 604
diff changeset
   748
!
6ccbaa111a74 added #getHostname (ST80 compatibility)
Claus Gittinger <cg@exept.de>
parents: 604
diff changeset
   749
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   750
sockStream
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   751
    "return the type code for stream sockets"
51
24f978f1d849 *** empty log message ***
claus
parents: 48
diff changeset
   752
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   753
    ^ #stream
44
b4db396f9255 EINTR stuff
claus
parents: 42
diff changeset
   754
! !
b4db396f9255 EINTR stuff
claus
parents: 42
diff changeset
   755
464
600b101a7035 alen in accept
Claus Gittinger <cg@exept.de>
parents: 463
diff changeset
   756
!Socket class methodsFor:'Signal constants'!
21
33eb5ffad09d *** empty log message ***
claus
parents: 8
diff changeset
   757
33eb5ffad09d *** empty log message ***
claus
parents: 8
diff changeset
   758
brokenConnectionSignal
33eb5ffad09d *** empty log message ***
claus
parents: 8
diff changeset
   759
    "return the signal used to tell broken connections.
33eb5ffad09d *** empty log message ***
claus
parents: 8
diff changeset
   760
     Since in unix, this is the same as the broken pipe signal,
33eb5ffad09d *** empty log message ***
claus
parents: 8
diff changeset
   761
     return that one.
33eb5ffad09d *** empty log message ***
claus
parents: 8
diff changeset
   762
     (for other Operatingsystems, this may change ..)"
33eb5ffad09d *** empty log message ***
claus
parents: 8
diff changeset
   763
33eb5ffad09d *** empty log message ***
claus
parents: 8
diff changeset
   764
    ^ PipeStream brokenPipeSignal
33eb5ffad09d *** empty log message ***
claus
parents: 8
diff changeset
   765
! !
33eb5ffad09d *** empty log message ***
claus
parents: 8
diff changeset
   766
464
600b101a7035 alen in accept
Claus Gittinger <cg@exept.de>
parents: 463
diff changeset
   767
!Socket class methodsFor:'debugging'!
71
claus
parents: 63
diff changeset
   768
claus
parents: 63
diff changeset
   769
debug:aBoolean
claus
parents: 63
diff changeset
   770
    "turn on/off internal debugprints.
claus
parents: 63
diff changeset
   771
     This method is for ST/X debugging only and
claus
parents: 63
diff changeset
   772
     may  be removed in later versions"
claus
parents: 63
diff changeset
   773
claus
parents: 63
diff changeset
   774
%{  /* NOCONTEXT */
claus
parents: 63
diff changeset
   775
claus
parents: 63
diff changeset
   776
    __debugging__ = (aBoolean == true);
claus
parents: 63
diff changeset
   777
%}
93
Claus Gittinger <cg@exept.de>
parents: 92
diff changeset
   778
    "
Claus Gittinger <cg@exept.de>
parents: 92
diff changeset
   779
     Socket debug:true
Claus Gittinger <cg@exept.de>
parents: 92
diff changeset
   780
     Socket debug:false
Claus Gittinger <cg@exept.de>
parents: 92
diff changeset
   781
    "
71
claus
parents: 63
diff changeset
   782
! !
claus
parents: 63
diff changeset
   783
464
600b101a7035 alen in accept
Claus Gittinger <cg@exept.de>
parents: 463
diff changeset
   784
!Socket class methodsFor:'easy tcp/ip instance creation'!
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   785
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   786
connectTo:service on:host
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   787
    "standard & easy client setup: 
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   788
	create new client tcp socket, bind and connect; 
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   789
	return the socket.
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   790
     The system may block (interruptable), until the connection is 
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   791
     established."
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   792
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   793
    ^ (self new) for:host port:(self portOfService:service).
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   794
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   795
    "
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   796
     Socket connectTo:9995 on:'clam'
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   797
     Socket connectTo:'finger' on:'clam'
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   798
     Socket connectTo:'ftp' on:'clam'
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   799
     Socket connectTo:'nntp' on:(OperatingSystem getEnvironment:'NNTPSERVER')
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   800
    "
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   801
!
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   802
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   803
provide:service
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   804
    "standard & easy server setup: 
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   805
	create a new TCP server socket providing a service."
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   806
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   807
    |newSock|
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   808
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   809
    newSock := (self new) for:nil port:(self portOfService:service).
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   810
    newSock notNil ifTrue:[
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   811
	newSock listenFor:5.
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   812
    ].
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   813
    ^ newSock
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   814
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   815
    "
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   816
     Socket provide:9995
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   817
     (Socket provide:9996) accept
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   818
     Socket provide:'nntp'
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   819
    "
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   820
! !
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   821
464
600b101a7035 alen in accept
Claus Gittinger <cg@exept.de>
parents: 463
diff changeset
   822
!Socket class methodsFor:'general instance creation'!
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   823
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   824
domain:domainSymbol type:type
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   825
    "create a socket for domain and type -
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   826
     neither any connect nor binding is done.
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   827
     Domain must be one of the symbols: #inet, #unix, #ns, #appletalk or #ns;
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   828
     Type must be #stream, #datagram or #raw
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   829
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   830
     XXX: currently only the #inet domain is supported"
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   831
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   832
    ^ self new domain:domainSymbol type:type
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   833
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   834
    "
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   835
     Socket domain:#inet type:#stream
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   836
     Socket domain:#inet type:#datagram
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   837
     Socket domain:#unix type:#stream
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   838
     Socket domain:#appletalk type:#stream
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   839
     Socket domain:#DECnet type:#stream
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   840
    "
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   841
!
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   842
576
13acab81fad0 more ST80 compatibility
ca
parents: 572
diff changeset
   843
new
13acab81fad0 more ST80 compatibility
ca
parents: 572
diff changeset
   844
    "create a TCP socket"
13acab81fad0 more ST80 compatibility
ca
parents: 572
diff changeset
   845
13acab81fad0 more ST80 compatibility
ca
parents: 572
diff changeset
   846
    ^ super new buffered:false 
13acab81fad0 more ST80 compatibility
ca
parents: 572
diff changeset
   847
!
13acab81fad0 more ST80 compatibility
ca
parents: 572
diff changeset
   848
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   849
newTCP
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   850
    "create a TCP socket - no binding or other setup is done,
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   851
     neither connect nor connect-wait is done."
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   852
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   853
    ^ self new domain:#inet type:#stream 
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   854
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   855
    "Socket newUDP"
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   856
!
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   857
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   858
newTCP:aServiceOrNil
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   859
    "create a TCP socket for a service -
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   860
     neither connect nor connect-wait is done."
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   861
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   862
    |newSock|
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   863
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   864
    newSock := self newTCP.
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   865
    (newSock notNil and:[aServiceOrNil notNil]) ifTrue:[
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   866
	newSock bindTo:(self portOfService:aServiceOrNil) address:nil
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   867
    ].
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   868
    ^ newSock
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   869
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   870
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   871
    "Socket newTCP:'nntp'"
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   872
    "Socket newTCP:9995"
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   873
!
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   874
576
13acab81fad0 more ST80 compatibility
ca
parents: 572
diff changeset
   875
newTCPclientToAddress:aHostAddress port:aService
13acab81fad0 more ST80 compatibility
ca
parents: 572
diff changeset
   876
    "create a new TCP client socket connecting to a service.
13acab81fad0 more ST80 compatibility
ca
parents: 572
diff changeset
   877
     Return a socket instance if ok, nil on failure.
13acab81fad0 more ST80 compatibility
ca
parents: 572
diff changeset
   878
     Block until a connection is established (but only the current thread;
13acab81fad0 more ST80 compatibility
ca
parents: 572
diff changeset
   879
     not the whole smalltalk). 
13acab81fad0 more ST80 compatibility
ca
parents: 572
diff changeset
   880
     See also: #newTCPclientToAddress:port:withTimeout:"
13acab81fad0 more ST80 compatibility
ca
parents: 572
diff changeset
   881
13acab81fad0 more ST80 compatibility
ca
parents: 572
diff changeset
   882
    ^ self newTCPclientToAddress:aHostAddress port:aService withTimeout:nil
13acab81fad0 more ST80 compatibility
ca
parents: 572
diff changeset
   883
!
13acab81fad0 more ST80 compatibility
ca
parents: 572
diff changeset
   884
13acab81fad0 more ST80 compatibility
ca
parents: 572
diff changeset
   885
newTCPclientToAddress:aHostAddress port:aService withTimeout:millis
13acab81fad0 more ST80 compatibility
ca
parents: 572
diff changeset
   886
    "create a new TCP client socket connecting to a service.
13acab81fad0 more ST80 compatibility
ca
parents: 572
diff changeset
   887
     Return a socket instance if ok, nil on failure.
13acab81fad0 more ST80 compatibility
ca
parents: 572
diff changeset
   888
     If the millis arg is nonNil, stop trying to connect after that many milliseconds
13acab81fad0 more ST80 compatibility
ca
parents: 572
diff changeset
   889
     and return nil.."
13acab81fad0 more ST80 compatibility
ca
parents: 572
diff changeset
   890
13acab81fad0 more ST80 compatibility
ca
parents: 572
diff changeset
   891
    ^ self newTCPclientToHost:aHostAddress port:aService withTimeout:millis
13acab81fad0 more ST80 compatibility
ca
parents: 572
diff changeset
   892
!
13acab81fad0 more ST80 compatibility
ca
parents: 572
diff changeset
   893
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   894
newTCPclientToHost:hostname port:aService
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   895
    "create a new TCP client socket connecting to a service.
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   896
     Return a socket instance if ok, nil on failure.
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   897
     Block until a connection is established (but only the current thread;
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   898
     not the whole smalltalk). 
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   899
     See also: #newTCPclientToHost:port:withTimeout:"
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   900
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   901
    ^ self newTCPclientToHost:hostname port:aService withTimeout:nil
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   902
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   903
    "
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   904
      Socket newTCPclientToHost:'localhost' port:'nntp'
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   905
    "
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   906
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   907
    "Created: 31.10.1995 / 18:54:11 / cg"
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   908
!
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   909
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   910
newTCPclientToHost:hostname port:aService withTimeout:millis
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   911
    "create a new TCP client socket connecting to a service.
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   912
     Return a socket instance if ok, nil on failure.
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   913
     If the millis arg is nonNil, stop trying to connect after that many milliseconds
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   914
     and return nil.."
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   915
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   916
    |newSock|
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   917
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   918
    newSock := self newTCP.
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   919
    newSock notNil ifTrue:[
648
58e11a70ddaf gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents: 617
diff changeset
   920
	(newSock connectTo:hostname 
58e11a70ddaf gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents: 617
diff changeset
   921
		 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
   922
		 withTimeout:millis
58e11a70ddaf gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents: 617
diff changeset
   923
	) ifFalse:[
58e11a70ddaf gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents: 617
diff changeset
   924
	    newSock close.
58e11a70ddaf gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents: 617
diff changeset
   925
	    ^ nil
58e11a70ddaf gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents: 617
diff changeset
   926
	]
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   927
    ].
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   928
    ^ newSock
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   929
"
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   930
same as:
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   931
    ^ (self new) for:hostname port:(self portOfService:aPort).
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   932
"
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   933
    "
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   934
      Socket newTCPclientToHost:'slsv6bt' port:'nntp'
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   935
      Socket newTCPclientToHost:'localhost' port:'nntp' withTimeout:1000
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   936
    "
604
b302a21afece Remove redundant code.
Stefan Vogel <sv@exept.de>
parents: 589
diff changeset
   937
b302a21afece Remove redundant code.
Stefan Vogel <sv@exept.de>
parents: 589
diff changeset
   938
    "Modified: / 16.1.1998 / 09:47:06 / stefan"
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   939
!
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   940
506
11ef93d12870 support anonymous (OS_specified) ports. (for FTP-protocol)
Claus Gittinger <cg@exept.de>
parents: 486
diff changeset
   941
newTCPserverAtAnonymousPort
11ef93d12870 support anonymous (OS_specified) ports. (for FTP-protocol)
Claus Gittinger <cg@exept.de>
parents: 486
diff changeset
   942
    "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
   943
     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
   944
11ef93d12870 support anonymous (OS_specified) ports. (for FTP-protocol)
Claus Gittinger <cg@exept.de>
parents: 486
diff changeset
   945
    ^ self
11ef93d12870 support anonymous (OS_specified) ports. (for FTP-protocol)
Claus Gittinger <cg@exept.de>
parents: 486
diff changeset
   946
	newTCPserverAtPort:0
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
!
11ef93d12870 support anonymous (OS_specified) ports. (for FTP-protocol)
Claus Gittinger <cg@exept.de>
parents: 486
diff changeset
   949
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   950
newTCPserverAtPort:aService
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   951
    "create a new TCP server socket providing service."
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   952
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   953
    |newSock|
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   954
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   955
    newSock := self newTCP.
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   956
    newSock notNil ifTrue:[
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   957
	(newSock bindTo:(self portOfService:aService) address:nil) ifFalse:[
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   958
	    ^ nil
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   959
	]
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   960
    ].
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   961
    ^ newSock
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   962
"
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   963
same as:
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   964
    ^ (self new) for:nil port:aPort
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   965
"
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   966
!
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   967
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   968
newUDP
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   969
    "create a UDP socket - no binding or other setup is done,
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   970
     neither connect nor connect-wait is done."
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   971
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   972
    ^ self new domain:#inet type:#datagram
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   973
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   974
    "Socket newUDP"
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   975
!
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   976
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   977
newUDP:aServiceOrNil
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   978
    "create a UDP socket for a service -
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   979
     neither connect nor connect-wait is done."
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   980
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   981
    |newSock|
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   982
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   983
    newSock := self newUDP.
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   984
    (newSock notNil and:[aServiceOrNil notNil]) ifTrue:[
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   985
	newSock bindTo:(self portOfService:aServiceOrNil) address:nil
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   986
    ].
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   987
    ^ newSock
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   988
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   989
    "Socket newUDP:nil"
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   990
!
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   991
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   992
newUDPserverAtPort:aService
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   993
    "create a new UDP server socket providing service."
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   994
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   995
    |newSock|
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   996
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   997
    newSock := self newUDP.
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   998
    newSock notNil ifTrue:[
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   999
	(newSock bindTo:(self portOfService:aService) address:nil) ifFalse:[
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1000
	    ^ nil
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1001
	]
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1002
    ].
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1003
    ^ newSock
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1004
"
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1005
same as:
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1006
    ^ (self new) for:nil udpPort:aPort
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1007
"
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1008
!
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1009
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1010
newUNIX
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1011
    "create a UNIX domain socket - no binding or other setup is done,
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1012
     neither connect nor connect-wait is done."
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1013
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1014
    ^ self new domain:#unix type:#stream 
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1015
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1016
    "
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1017
     Socket newUNIX
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1018
    "
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1019
!
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1020
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1021
newUNIXclientTo:pathName 
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1022
    "create a new UNIX client socket connecting to a pathname.
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1023
     Return a socket instance if ok, nil on failure.
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1024
     Block until a connection is established (but only the current thread;
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1025
     not the whole smalltalk). 
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1026
     See also: #newUNIXclientTo:withTimeout:"
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1027
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1028
    ^ self newUNIXclientTo:pathName withTimeout:nil
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1029
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1030
!
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1031
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1032
newUNIXclientTo:pathName withTimeout:millis
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1033
    "create a new UNIX client socket connecting to a pathname.
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1034
     Return a socket instance if ok, nil on failure.
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1035
     If the millis arg is nonNil, stop trying to connect after that many milliseconds
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1036
     and return nil.."
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1037
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1038
    |newSock|
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1039
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1040
    newSock := self newUNIX.
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1041
    newSock notNil ifTrue:[
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1042
	(newSock connectTo:pathName port:nil withTimeout:millis) ifFalse:[
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1043
	    newSock close.
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1044
	    ^ nil
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1045
	]
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1046
    ].
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1047
    ^ newSock
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1048
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1049
    "
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1050
     |s|
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1051
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1052
     s := Socket newUNIXclientTo:'/tmp/foo'
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1053
    "
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1054
!
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1055
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1056
newUNIXserverAt:pathName
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1057
    "create a new UNIX server socket providing service at a pathname."
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1058
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1059
    |newSock|
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1060
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1061
    newSock := self newUNIX.
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1062
    newSock notNil ifTrue:[
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1063
	(newSock bindTo:pathName address:nil) ifFalse:[
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1064
	    ^ nil
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1065
	]
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1066
    ].
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1067
    ^ newSock
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1068
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1069
    "
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1070
     |s s2|
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1071
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1072
     s := Socket newUNIXserverAt:'/tmp/foo'.
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1073
     s listenFor:5.
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1074
     s2 := s accept.
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1075
    "
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1076
! !
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1077
525
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  1078
!Socket class methodsFor:'host queries'!
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  1079
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  1080
appletalkAddressOfHost:aHostName
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  1081
    "return the APPLETALK address for a hostname as a byteArray,
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  1082
     where the network bytes come first followed by the node.
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  1083
     If the host is unknown, return nil.
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  1084
     This is the reverse operation to #hostWithAppletalkAddress:."
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  1085
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  1086
%{
526
1748ab3892a3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 525
diff changeset
  1087
#if !defined(NO_SOCKET) && defined(AF_APPLETALK)
525
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  1088
    struct sockaddr_at sa ;
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  1089
    struct hostent *hp ;
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  1090
    long addr;
653
219b89f62113 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 650
diff changeset
  1091
    OBJ rslt;
525
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  1092
529
fc7ec265717b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
  1093
    sa.sat_family = -1;
525
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  1094
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  1095
    if (__isString(aHostName)) {
789
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  1096
	bzero(&sa, sizeof(sa)) ;
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  1097
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  1098
	/* do we know the host's address? */
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  1099
	GETHOSTBYNAME(hp, __stringVal(aHostName))
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  1100
	if (hp == NULL) {
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  1101
	    DBGPRINTF(("SOCKET: unknown host: %s\n", __stringVal(aHostName)));
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  1102
	    RETURN ( nil );
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  1103
	}
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  1104
	bcopy(hp->h_addr, (char *) &sa.sat_addr, hp->h_length) ;
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  1105
	sa.sat_family = hp->h_addrtype;
525
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  1106
    }
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  1107
752
c4176e236d83 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 741
diff changeset
  1108
    /* if the addressing family is not AF_APPLETALK, Return nil */
525
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  1109
    if (sa.sat_family != AF_INET) {
789
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  1110
	DBGPRINTF(("SOCKET: not an appletalk host\n"));
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  1111
	RETURN ( nil );
525
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  1112
    }
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  1113
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  1114
    sa.sat_addr.s_net = ntohs(sa.sat_addr.s_net);    
653
219b89f62113 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 650
diff changeset
  1115
    rslt = __BYTEARRAY_NEW_INT(3);
219b89f62113 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 650
diff changeset
  1116
    if (rslt != nil) {
789
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  1117
	__ByteArrayInstPtr(rslt)->ba_element[0] = (sa.sat_addr.s_net >> 8) & 0xFF;
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  1118
	__ByteArrayInstPtr(rslt)->ba_element[1] = (sa.sat_addr.s_net) & 0xFF;
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  1119
	__ByteArrayInstPtr(rslt)->ba_element[2] = (sa.sat_addr.s_node) & 0xFF;
653
219b89f62113 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 650
diff changeset
  1120
       RETURN (rslt);
219b89f62113 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 650
diff changeset
  1121
    }
525
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  1122
#endif
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  1123
%}.
653
219b89f62113 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 650
diff changeset
  1124
    ^ nil
525
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  1125
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  1126
!
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  1127
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  1128
hostWithAppletalkAddress:anAddress
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  1129
    "return the hostname for an APPLETALK address.
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  1130
     The address is supposed to be a byteArray consisting of 3 bytes,
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  1131
     the network bytes come first (no matter what the local byteorder is).
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  1132
     The last byte is the node number.
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  1133
     Nil is returned for an unknown host or if its not an appletalk host.
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  1134
     This is is the reverse operation to #appletalkAddressOfHost:."
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  1135
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  1136
    |b1 b2 b3 b4|
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  1137
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  1138
    b1 := anAddress at:1.
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  1139
    b2 := anAddress at:2.
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  1140
    b3 := anAddress at:3.
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  1141
    b4 := anAddress at:4.
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  1142
%{
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  1143
#if !defined(NO_SOCKET) && defined(AF_APPLETALK)
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  1144
    struct sockaddr_at sa ;
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  1145
    struct hostent *hp ;
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  1146
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  1147
    sa.sat_family = -1;
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  1148
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  1149
    if (__bothSmallInteger(b1, b2) && __bothSmallInteger(b3, b4)) {
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  1150
	bzero(&sa, sizeof(sa)) ;
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  1151
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  1152
	sa.sat_addr.s_net = _intVal(b1) & 0xFF;
529
fc7ec265717b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
  1153
	sa.sat_addr.s_net = (sa.sat_addr.s_net << 8) | (_intVal(b2) & 0xFF);
fc7ec265717b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
  1154
	sa.sat_addr.s_net = htons(sa.sat_addr.s_net);    
fc7ec265717b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
  1155
	sa.sat_addr.s_node = _intVal(b3) & 0xFF;
fc7ec265717b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
  1156
	sa.sat_family = AF_APPLETALK;
fc7ec265717b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
  1157
525
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  1158
	/* do we know the host's address? */
650
8c5616f17ed6 made gethostbyaddr interruptable
Claus Gittinger <cg@exept.de>
parents: 649
diff changeset
  1159
	GETHOSTBYADDR(hp, (char *) &sa.sat_addr, sizeof(sa.sat_addr), AF_APPLETALK);
525
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  1160
	if (hp != NULL) {
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  1161
	    sa.sat_family = hp->h_addrtype;
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  1162
	} else {
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  1163
	    DBGPRINTF(("SOCKET: unknown address: %d.%d.%d.%d\n", 
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  1164
		       _intVal(b1), _intVal(b2), _intVal(b3)));
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  1165
	}
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  1166
    }
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  1167
752
c4176e236d83 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 741
diff changeset
  1168
    /* if the addressing family is not AF_APPLETALK, Return nil */
525
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  1169
    if (sa.sat_family != AF_APPLETALK) {
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  1170
	RETURN ( nil );
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  1171
    }
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  1172
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  1173
    if (hp != NULL) {
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  1174
	RETURN (__MKSTRING(hp->h_name));
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  1175
    }
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  1176
#endif
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  1177
    RETURN (nil);
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  1178
%}.
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  1179
    "
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  1180
     Socket appletalkAddressOfHost:'clam'
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  1181
     Socket hostWithAppletalkAddress:#[1 2 3]  
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  1182
     "
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1183
!
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1184
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1185
hostWithIpAddress:anAddress
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1186
    "return the hostname for an IP (internet-) address.
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1187
     The address is supposed to be a byteArray consisting of 4 bytes,
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1188
     the network bytes come first (no matter what the local byteorder is).
525
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  1189
     Nil is returned for an unknown host or if its not an internet host.
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1190
     This is the reverse operation to #ipAddressOfHost:."
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1191
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1192
    |b1 b2 b3 b4|
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1193
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1194
    b1 := anAddress at:1.
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1195
    b2 := anAddress at:2.
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1196
    b3 := anAddress at:3.
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1197
    b4 := anAddress at:4.
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1198
%{
525
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  1199
#if !defined(NO_SOCKET) && defined(AF_INET)
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1200
    struct sockaddr_in sa ;
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1201
    struct hostent *hp ;
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1202
525
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  1203
    sa.sin_family = -1;
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1204
    if (__bothSmallInteger(b1, b2) && __bothSmallInteger(b3, b4)) {
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1205
	bzero(&sa, sizeof(sa)) ;
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1206
	sa.sin_addr.s_addr = _intVal(b1) & 0xFF;
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1207
	sa.sin_addr.s_addr = (sa.sin_addr.s_addr << 8) | (_intVal(b2) & 0xFF);
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1208
	sa.sin_addr.s_addr = (sa.sin_addr.s_addr << 8) | (_intVal(b3) & 0xFF);
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1209
	sa.sin_addr.s_addr = (sa.sin_addr.s_addr << 8) | (_intVal(b4) & 0xFF);
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1210
	sa.sin_addr.s_addr = htonl(sa.sin_addr.s_addr);    
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1211
	sa.sin_family = AF_INET;
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1212
	/* do we know the host's address? */
650
8c5616f17ed6 made gethostbyaddr interruptable
Claus Gittinger <cg@exept.de>
parents: 649
diff changeset
  1213
	GETHOSTBYADDR(hp, (char *) &sa.sin_addr.s_addr, sizeof(sa.sin_addr.s_addr), AF_INET);
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1214
	if (hp == NULL) {
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1215
	    DBGPRINTF(("SOCKET: unknown address: %d.%d.%d.%d\n", 
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1216
		       _intVal(b1), _intVal(b2), _intVal(b3), _intVal(b4)));
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1217
	} else {
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1218
	    sa.sin_family = hp->h_addrtype;
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1219
	}
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1220
    }
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1221
752
c4176e236d83 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 741
diff changeset
  1222
    /* if the addressing family is not AF_INET, Return nil */
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1223
    if (sa.sin_family != AF_INET) {
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1224
	RETURN ( nil );
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1225
    }
525
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  1226
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  1227
    if (hp != NULL) {
448
2203a4bb620d removed all COMMA_CON / CON_COMMA uses
Claus Gittinger <cg@exept.de>
parents: 444
diff changeset
  1228
	RETURN (__MKSTRING(hp->h_name));
525
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  1229
    }
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  1230
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  1231
    /*
752
c4176e236d83 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 741
diff changeset
  1232
     * Return it in dot-notation
525
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  1233
     */
448
2203a4bb620d removed all COMMA_CON / CON_COMMA uses
Claus Gittinger <cg@exept.de>
parents: 444
diff changeset
  1234
    RETURN (__MKSTRING(inet_ntoa(sa.sin_addr)));
418
317e55c6c281 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 403
diff changeset
  1235
#else
317e55c6c281 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 403
diff changeset
  1236
    RETURN (nil);
317e55c6c281 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 403
diff changeset
  1237
#endif
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1238
%}
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1239
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1240
    "
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1241
     Socket ipAddressOfHost:'clam'
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1242
     Socket hostWithIpAddress:(Socket ipAddressOfHost:'clam') 
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1243
     Socket ipAddressOfHost:'porty'
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1244
     Socket hostWithIpAddress:(Socket ipAddressOfHost:'porty') 
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1245
     Socket hostWithIpAddress:#[1 2 3 4]  
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1246
     Socket hostWithIpAddress:(Socket ipAddressOfHost:'1.2.3.4')  
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1247
     "
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1248
!
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1249
6
claus
parents: 4
diff changeset
  1250
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
  1251
    "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
  1252
     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
  1253
     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
  1254
     This is the reverse operation to #hostWithIpAddress:."
6
claus
parents: 4
diff changeset
  1255
claus
parents: 4
diff changeset
  1256
%{
525
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  1257
#if !defined(NO_SOCKET) && defined(AF_INET)
6
claus
parents: 4
diff changeset
  1258
    struct sockaddr_in sa ;
claus
parents: 4
diff changeset
  1259
    struct hostent *hp ;
claus
parents: 4
diff changeset
  1260
    long addr;
653
219b89f62113 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 650
diff changeset
  1261
    OBJ rslt;
6
claus
parents: 4
diff changeset
  1262
525
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  1263
    sa.sin_family = -1;
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  1264
21
33eb5ffad09d *** empty log message ***
claus
parents: 8
diff changeset
  1265
    if (__isString(aHostName)) {
789
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  1266
	bzero(&sa, sizeof(sa)) ;
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  1267
	if ((addr = inet_addr((char *) __stringVal(aHostName))) != -1) {
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  1268
	    /* is Internet addr in octet notation */
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  1269
	    bcopy(&addr, (char *) &sa.sin_addr, sizeof(addr)); 
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  1270
	    sa.sin_family = AF_INET;
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  1271
	} else {
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  1272
	    /* do we know the host's address? */
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  1273
	    GETHOSTBYNAME(hp, __stringVal(aHostName))
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  1274
	    if (hp == NULL) {
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  1275
		DBGPRINTF(("SOCKET: unknown host: %s\n", __stringVal(aHostName)));
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  1276
		RETURN ( nil );
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  1277
	    }
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  1278
	    bcopy(hp->h_addr, (char *) &sa.sin_addr, hp->h_length) ;
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  1279
	    sa.sin_family = hp->h_addrtype;
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  1280
	}
6
claus
parents: 4
diff changeset
  1281
    }
525
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  1282
752
c4176e236d83 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 741
diff changeset
  1283
    /* if the addressing family is not AF_INET, Return nil */
6
claus
parents: 4
diff changeset
  1284
    if (sa.sin_family != AF_INET) {
789
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  1285
	DBGPRINTF(("SOCKET: not an internet host\n"));
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  1286
	RETURN ( nil );
6
claus
parents: 4
diff changeset
  1287
    }
98
5e787ba2cb31 use common byteOrder when representing IP numbers as byteArrays (always network-first)
Claus Gittinger <cg@exept.de>
parents: 96
diff changeset
  1288
5e787ba2cb31 use common byteOrder when representing IP numbers as byteArrays (always network-first)
Claus Gittinger <cg@exept.de>
parents: 96
diff changeset
  1289
    sa.sin_addr.s_addr = ntohl(sa.sin_addr.s_addr);    
653
219b89f62113 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 650
diff changeset
  1290
    rslt = __BYTEARRAY_NEW_INT(4);
219b89f62113 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 650
diff changeset
  1291
    if (rslt != nil) {
789
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  1292
	__ByteArrayInstPtr(rslt)->ba_element[0] = (sa.sin_addr.s_addr >> 24) & 0xFF;
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  1293
	__ByteArrayInstPtr(rslt)->ba_element[1] = (sa.sin_addr.s_addr >> 16) & 0xFF;
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  1294
	__ByteArrayInstPtr(rslt)->ba_element[2] = (sa.sin_addr.s_addr >> 8) & 0xFF;
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  1295
	__ByteArrayInstPtr(rslt)->ba_element[3] = (sa.sin_addr.s_addr >> 0) & 0xFF;
653
219b89f62113 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 650
diff changeset
  1296
       RETURN (rslt);
219b89f62113 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 650
diff changeset
  1297
    }
418
317e55c6c281 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 403
diff changeset
  1298
#endif
525
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  1299
%}.
653
219b89f62113 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 650
diff changeset
  1300
    ^ nil
21
33eb5ffad09d *** empty log message ***
claus
parents: 8
diff changeset
  1301
71
claus
parents: 63
diff changeset
  1302
    "
98
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:'clam' 
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:'porty'    
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:'axept'    
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:'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
  1308
     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
  1309
     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
  1310
     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
  1311
     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
  1312
     Socket ipAddressOfHost:(Socket hostWithIpAddress:'127.0.0.1') 
71
claus
parents: 63
diff changeset
  1313
    "
531
ca4c73813531 category changes
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1314
! !
ca4c73813531 category changes
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1315
ca4c73813531 category changes
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1316
!Socket class methodsFor:'queries'!
ca4c73813531 category changes
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1317
ca4c73813531 category changes
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1318
domainOfProtocol:aProtocol
ca4c73813531 category changes
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1319
    "given a protocols name (i.e. tcp, udp etc) return the domain.
ca4c73813531 category changes
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1320
     This method needs more ... - or is there a way to get this from the system ?"
ca4c73813531 category changes
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1321
ca4c73813531 category changes
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1322
    "
ca4c73813531 category changes
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1323
     tcp/ip stuff
ca4c73813531 category changes
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1324
    "
ca4c73813531 category changes
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1325
    (aProtocol = 'tcp') ifTrue:[^ #inet].
ca4c73813531 category changes
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1326
    (aProtocol = 'udp') ifTrue:[^ #inet].
ca4c73813531 category changes
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1327
    (aProtocol = 'ip')  ifTrue:[^ #inet].
ca4c73813531 category changes
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1328
    "
ca4c73813531 category changes
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1329
     unix domain
ca4c73813531 category changes
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1330
    "
ca4c73813531 category changes
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1331
    (aProtocol = 'ud')  ifTrue:[^ #unix].
ca4c73813531 category changes
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1332
ca4c73813531 category changes
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1333
    "
ca4c73813531 category changes
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1334
     add x25 stuff (if any) here ...
ca4c73813531 category changes
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1335
    "
ca4c73813531 category changes
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1336
    "
ca4c73813531 category changes
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1337
     add appletalk stuff (if any) here ...
ca4c73813531 category changes
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1338
    "
ca4c73813531 category changes
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1339
    "
ca4c73813531 category changes
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1340
     add other stuff (if any) here ...
ca4c73813531 category changes
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1341
    "
ca4c73813531 category changes
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1342
    ^ nil
ca4c73813531 category changes
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1343
ca4c73813531 category changes
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1344
    "
ca4c73813531 category changes
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1345
     Socket domainOfProtocol:'tcp'
ca4c73813531 category changes
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1346
     Socket domainOfProtocol:'ucp'
ca4c73813531 category changes
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1347
     Socket domainOfProtocol:(Socket protocolOfService:'nntp')
ca4c73813531 category changes
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1348
     Socket domainOfProtocol:(Socket protocolOfService:'echo')
ca4c73813531 category changes
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1349
    "
6
claus
parents: 4
diff changeset
  1350
!
claus
parents: 4
diff changeset
  1351
206
77166a6b3ee6 For ST80 style socket creation: register socket in Lobby.
Stefan Vogel <sv@exept.de>
parents: 203
diff changeset
  1352
networkLongOrderIsMSB
77166a6b3ee6 For ST80 style socket creation: register socket in Lobby.
Stefan Vogel <sv@exept.de>
parents: 203
diff changeset
  1353
    "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
  1354
     To be used as in:
77166a6b3ee6 For ST80 style socket creation: register socket in Lobby.
Stefan Vogel <sv@exept.de>
parents: 203
diff changeset
  1355
	'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
  1356
77166a6b3ee6 For ST80 style socket creation: register socket in Lobby.
Stefan Vogel <sv@exept.de>
parents: 203
diff changeset
  1357
%{  /* NOCONTEXT */
418
317e55c6c281 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 403
diff changeset
  1358
#ifndef NO_SOCKET
206
77166a6b3ee6 For ST80 style socket creation: register socket in Lobby.
Stefan Vogel <sv@exept.de>
parents: 203
diff changeset
  1359
    /*
77166a6b3ee6 For ST80 style socket creation: register socket in Lobby.
Stefan Vogel <sv@exept.de>
parents: 203
diff changeset
  1360
     * 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
  1361
     */
77166a6b3ee6 For ST80 style socket creation: register socket in Lobby.
Stefan Vogel <sv@exept.de>
parents: 203
diff changeset
  1362
    if (htonl(0x76543210) == 0x76543210) {
77166a6b3ee6 For ST80 style socket creation: register socket in Lobby.
Stefan Vogel <sv@exept.de>
parents: 203
diff changeset
  1363
	RETURN (true);
77166a6b3ee6 For ST80 style socket creation: register socket in Lobby.
Stefan Vogel <sv@exept.de>
parents: 203
diff changeset
  1364
    }
418
317e55c6c281 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 403
diff changeset
  1365
#endif
206
77166a6b3ee6 For ST80 style socket creation: register socket in Lobby.
Stefan Vogel <sv@exept.de>
parents: 203
diff changeset
  1366
%}.
77166a6b3ee6 For ST80 style socket creation: register socket in Lobby.
Stefan Vogel <sv@exept.de>
parents: 203
diff changeset
  1367
    ^ false
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
    "
77166a6b3ee6 For ST80 style socket creation: register socket in Lobby.
Stefan Vogel <sv@exept.de>
parents: 203
diff changeset
  1370
     Socket networkLongOrderIsMSB
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
77166a6b3ee6 For ST80 style socket creation: register socket in Lobby.
Stefan Vogel <sv@exept.de>
parents: 203
diff changeset
  1374
networkShortOrderIsMSB
77166a6b3ee6 For ST80 style socket creation: register socket in Lobby.
Stefan Vogel <sv@exept.de>
parents: 203
diff changeset
  1375
    "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
  1376
     To be used as in:
77166a6b3ee6 For ST80 style socket creation: register socket in Lobby.
Stefan Vogel <sv@exept.de>
parents: 203
diff changeset
  1377
	'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
  1378
77166a6b3ee6 For ST80 style socket creation: register socket in Lobby.
Stefan Vogel <sv@exept.de>
parents: 203
diff changeset
  1379
%{  /* NOCONTEXT */
418
317e55c6c281 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 403
diff changeset
  1380
#ifndef NO_SOCKET
206
77166a6b3ee6 For ST80 style socket creation: register socket in Lobby.
Stefan Vogel <sv@exept.de>
parents: 203
diff changeset
  1381
    /*
77166a6b3ee6 For ST80 style socket creation: register socket in Lobby.
Stefan Vogel <sv@exept.de>
parents: 203
diff changeset
  1382
     * 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
  1383
     */
77166a6b3ee6 For ST80 style socket creation: register socket in Lobby.
Stefan Vogel <sv@exept.de>
parents: 203
diff changeset
  1384
    if (htons(0x3210) == 0x3210) {
77166a6b3ee6 For ST80 style socket creation: register socket in Lobby.
Stefan Vogel <sv@exept.de>
parents: 203
diff changeset
  1385
	RETURN (true);
77166a6b3ee6 For ST80 style socket creation: register socket in Lobby.
Stefan Vogel <sv@exept.de>
parents: 203
diff changeset
  1386
    }
418
317e55c6c281 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 403
diff changeset
  1387
#endif
206
77166a6b3ee6 For ST80 style socket creation: register socket in Lobby.
Stefan Vogel <sv@exept.de>
parents: 203
diff changeset
  1388
%}.
77166a6b3ee6 For ST80 style socket creation: register socket in Lobby.
Stefan Vogel <sv@exept.de>
parents: 203
diff changeset
  1389
    ^ false
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
    "
77166a6b3ee6 For ST80 style socket creation: register socket in Lobby.
Stefan Vogel <sv@exept.de>
parents: 203
diff changeset
  1392
     Socket networkShortOrderIsMSB
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
!
77166a6b3ee6 For ST80 style socket creation: register socket in Lobby.
Stefan Vogel <sv@exept.de>
parents: 203
diff changeset
  1395
0
1cf8d1747859 Initial revision
claus
parents:
diff changeset
  1396
portOfService:aNameOrNumber
1cf8d1747859 Initial revision
claus
parents:
diff changeset
  1397
    "returns the port-number for a given service
1cf8d1747859 Initial revision
claus
parents:
diff changeset
  1398
     or nil if no such service exists;
1cf8d1747859 Initial revision
claus
parents:
diff changeset
  1399
     - used to convert service names to portNumbers"
1cf8d1747859 Initial revision
claus
parents:
diff changeset
  1400
91
Claus Gittinger <cg@exept.de>
parents: 85
diff changeset
  1401
    ^ self portOfService:aNameOrNumber protocol:nil
Claus Gittinger <cg@exept.de>
parents: 85
diff changeset
  1402
28
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  1403
    "
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  1404
     Socket portOfService:'finger'
74
claus
parents: 71
diff changeset
  1405
     Socket portOfService:'nntp'  
claus
parents: 71
diff changeset
  1406
     Socket portOfService:'echo' 
claus
parents: 71
diff changeset
  1407
     Socket portOfService:'snmp' 
28
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  1408
    "
0
1cf8d1747859 Initial revision
claus
parents:
diff changeset
  1409
!
1cf8d1747859 Initial revision
claus
parents:
diff changeset
  1410
91
Claus Gittinger <cg@exept.de>
parents: 85
diff changeset
  1411
portOfService:aNameOrNumber protocol:aProtocol
Claus Gittinger <cg@exept.de>
parents: 85
diff changeset
  1412
    "returns the port-number for a given service
Claus Gittinger <cg@exept.de>
parents: 85
diff changeset
  1413
     or nil if no such service exists;
Claus Gittinger <cg@exept.de>
parents: 85
diff changeset
  1414
     - used to convert service names to portNumbers"
Claus Gittinger <cg@exept.de>
parents: 85
diff changeset
  1415
604
b302a21afece Remove redundant code.
Stefan Vogel <sv@exept.de>
parents: 589
diff changeset
  1416
%{ /* NOCONTEXT */
418
317e55c6c281 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 403
diff changeset
  1417
#ifndef NO_SOCKET
91
Claus Gittinger <cg@exept.de>
parents: 85
diff changeset
  1418
    struct servent *servent = NULL;
Claus Gittinger <cg@exept.de>
parents: 85
diff changeset
  1419
    char *protocol;
Claus Gittinger <cg@exept.de>
parents: 85
diff changeset
  1420
    int tryBoth = 0;
524
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  1421
    short portNo;
91
Claus Gittinger <cg@exept.de>
parents: 85
diff changeset
  1422
604
b302a21afece Remove redundant code.
Stefan Vogel <sv@exept.de>
parents: 589
diff changeset
  1423
    if (__isSmallInteger(aNameOrNumber)) {
648
58e11a70ddaf gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents: 617
diff changeset
  1424
	RETURN ( aNameOrNumber );
92
Claus Gittinger <cg@exept.de>
parents: 91
diff changeset
  1425
    }
Claus Gittinger <cg@exept.de>
parents: 91
diff changeset
  1426
604
b302a21afece Remove redundant code.
Stefan Vogel <sv@exept.de>
parents: 589
diff changeset
  1427
    if (__isString(aProtocol)) {
648
58e11a70ddaf gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents: 617
diff changeset
  1428
	protocol = (char *)__stringVal(aProtocol);
604
b302a21afece Remove redundant code.
Stefan Vogel <sv@exept.de>
parents: 589
diff changeset
  1429
    } else {
648
58e11a70ddaf gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents: 617
diff changeset
  1430
	protocol = "tcp";
58e11a70ddaf gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents: 617
diff changeset
  1431
	tryBoth = 1;
91
Claus Gittinger <cg@exept.de>
parents: 85
diff changeset
  1432
    }
524
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  1433
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  1434
    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
  1435
	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
  1436
	if (servent != NULL) {
58e11a70ddaf gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents: 617
diff changeset
  1437
	    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
  1438
	}
58e11a70ddaf gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents: 617
diff changeset
  1439
	if (tryBoth) {
58e11a70ddaf gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents: 617
diff changeset
  1440
	    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
  1441
	    if (servent != NULL) {
58e11a70ddaf gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents: 617
diff changeset
  1442
		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
  1443
	    }
58e11a70ddaf gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents: 617
diff changeset
  1444
	}
58e11a70ddaf gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents: 617
diff changeset
  1445
	RETURN ( nil );
91
Claus Gittinger <cg@exept.de>
parents: 85
diff changeset
  1446
    }
418
317e55c6c281 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 403
diff changeset
  1447
#endif
91
Claus Gittinger <cg@exept.de>
parents: 85
diff changeset
  1448
    RETURN ( nil );
Claus Gittinger <cg@exept.de>
parents: 85
diff changeset
  1449
%}
Claus Gittinger <cg@exept.de>
parents: 85
diff changeset
  1450
    "
Claus Gittinger <cg@exept.de>
parents: 85
diff changeset
  1451
     Socket portOfService:'echo' protocol:'udp'
Claus Gittinger <cg@exept.de>
parents: 85
diff changeset
  1452
     Socket portOfService:'echo' protocol:'tcp'
Claus Gittinger <cg@exept.de>
parents: 85
diff changeset
  1453
    "
Claus Gittinger <cg@exept.de>
parents: 85
diff changeset
  1454
!
Claus Gittinger <cg@exept.de>
parents: 85
diff changeset
  1455
0
1cf8d1747859 Initial revision
claus
parents:
diff changeset
  1456
protocolOfService:aNameOrNumber
1cf8d1747859 Initial revision
claus
parents:
diff changeset
  1457
    "returns the protocol (as string) for a given service
28
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  1458
     or nil if no such service exists."
0
1cf8d1747859 Initial revision
claus
parents:
diff changeset
  1459
%{
418
317e55c6c281 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 403
diff changeset
  1460
#ifndef NO_SOCKET
0
1cf8d1747859 Initial revision
claus
parents:
diff changeset
  1461
    struct servent *servent = NULL;
524
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  1462
    short portNo;
0
1cf8d1747859 Initial revision
claus
parents:
diff changeset
  1463
58
bd6753bf0401 *** empty log message ***
claus
parents: 51
diff changeset
  1464
    if (__isSmallInteger(aNameOrNumber)) {
524
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  1465
	portNo = __intVal(aNameOrNumber);
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  1466
	servent = getservbyport(htons(portNo), "tcp") ;
42
506596f9a1a8 *** empty log message ***
claus
parents: 38
diff changeset
  1467
	if (servent == NULL) {
524
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  1468
	    servent = getservbyport(htons(portNo), "udp") ;
42
506596f9a1a8 *** empty log message ***
claus
parents: 38
diff changeset
  1469
	    if (servent == NULL) {
506596f9a1a8 *** empty log message ***
claus
parents: 38
diff changeset
  1470
		RETURN ( nil );
506596f9a1a8 *** empty log message ***
claus
parents: 38
diff changeset
  1471
	    }
506596f9a1a8 *** empty log message ***
claus
parents: 38
diff changeset
  1472
	}
0
1cf8d1747859 Initial revision
claus
parents:
diff changeset
  1473
    } else {
42
506596f9a1a8 *** empty log message ***
claus
parents: 38
diff changeset
  1474
	if (__isString(aNameOrNumber)) {
524
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  1475
	    servent = getservbyname((char *) __stringVal(aNameOrNumber), "tcp");
42
506596f9a1a8 *** empty log message ***
claus
parents: 38
diff changeset
  1476
	    if (servent == NULL) {
524
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  1477
		servent = getservbyname((char *) __stringVal(aNameOrNumber), "udp");
42
506596f9a1a8 *** empty log message ***
claus
parents: 38
diff changeset
  1478
		if (servent == NULL) {
506596f9a1a8 *** empty log message ***
claus
parents: 38
diff changeset
  1479
		    RETURN ( nil );
506596f9a1a8 *** empty log message ***
claus
parents: 38
diff changeset
  1480
		}
506596f9a1a8 *** empty log message ***
claus
parents: 38
diff changeset
  1481
	    }
506596f9a1a8 *** empty log message ***
claus
parents: 38
diff changeset
  1482
	}
0
1cf8d1747859 Initial revision
claus
parents:
diff changeset
  1483
    }
1cf8d1747859 Initial revision
claus
parents:
diff changeset
  1484
    if (servent) {
448
2203a4bb620d removed all COMMA_CON / CON_COMMA uses
Claus Gittinger <cg@exept.de>
parents: 444
diff changeset
  1485
	RETURN ( __MKSTRING(servent->s_proto) );
0
1cf8d1747859 Initial revision
claus
parents:
diff changeset
  1486
    }
418
317e55c6c281 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 403
diff changeset
  1487
#endif
0
1cf8d1747859 Initial revision
claus
parents:
diff changeset
  1488
    RETURN ( nil );
1cf8d1747859 Initial revision
claus
parents:
diff changeset
  1489
%}
28
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  1490
    "
74
claus
parents: 71
diff changeset
  1491
     Socket protocolOfService:'finger' 
claus
parents: 71
diff changeset
  1492
     Socket protocolOfService:'nntp'  
28
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  1493
     Socket protocolOfService:'xxx'
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  1494
     Socket protocolOfService:79
74
claus
parents: 71
diff changeset
  1495
     Socket protocolOfService:'snmp' 
28
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  1496
    "
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  1497
!
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  1498
532
f997c3873602 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 531
diff changeset
  1499
supportedProtocolFamilies
f997c3873602 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 531
diff changeset
  1500
    "return a collection of supported protocol families.
f997c3873602 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 531
diff changeset
  1501
     This list specifies what the Socket class supports -
f997c3873602 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 531
diff changeset
  1502
     socket creation may still fail, if your system was built
f997c3873602 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 531
diff changeset
  1503
     without it."
f997c3873602 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 531
diff changeset
  1504
f997c3873602 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 531
diff changeset
  1505
    |list hasIt|
f997c3873602 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 531
diff changeset
  1506
f997c3873602 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 531
diff changeset
  1507
    list := OrderedCollection new.
f997c3873602 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 531
diff changeset
  1508
f997c3873602 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 531
diff changeset
  1509
%{
f997c3873602 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 531
diff changeset
  1510
#ifdef AF_INET
f997c3873602 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 531
diff changeset
  1511
    hasIt = true;
f997c3873602 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 531
diff changeset
  1512
#else
f997c3873602 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 531
diff changeset
  1513
    hasIt = false;
f997c3873602 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 531
diff changeset
  1514
#endif
f997c3873602 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 531
diff changeset
  1515
%}.
f997c3873602 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 531
diff changeset
  1516
    hasIt ifTrue:[list add:#inet].
f997c3873602 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 531
diff changeset
  1517
f997c3873602 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 531
diff changeset
  1518
%{
f997c3873602 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 531
diff changeset
  1519
#ifdef AF_UNIX
f997c3873602 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 531
diff changeset
  1520
    hasIt = true;
f997c3873602 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 531
diff changeset
  1521
#else
f997c3873602 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 531
diff changeset
  1522
    hasIt = false;
f997c3873602 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 531
diff changeset
  1523
#endif
f997c3873602 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 531
diff changeset
  1524
%}.
f997c3873602 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 531
diff changeset
  1525
    hasIt ifTrue:[list add:#unix].
f997c3873602 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 531
diff changeset
  1526
f997c3873602 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 531
diff changeset
  1527
%{
f997c3873602 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 531
diff changeset
  1528
#ifdef AF_INET6
f997c3873602 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 531
diff changeset
  1529
    hasIt = true;
f997c3873602 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 531
diff changeset
  1530
#else
f997c3873602 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 531
diff changeset
  1531
    hasIt = false;
f997c3873602 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 531
diff changeset
  1532
#endif
f997c3873602 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 531
diff changeset
  1533
%}.
f997c3873602 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 531
diff changeset
  1534
    hasIt ifTrue:[list add:#inet6].
f997c3873602 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 531
diff changeset
  1535
f997c3873602 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 531
diff changeset
  1536
%{
f997c3873602 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 531
diff changeset
  1537
#ifdef AF_APPLETALK
f997c3873602 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 531
diff changeset
  1538
    hasIt = true;
f997c3873602 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 531
diff changeset
  1539
#else
f997c3873602 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 531
diff changeset
  1540
    hasIt = false;
f997c3873602 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 531
diff changeset
  1541
#endif
f997c3873602 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 531
diff changeset
  1542
%}.
f997c3873602 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 531
diff changeset
  1543
    hasIt ifTrue:[list add:#appletalk].
f997c3873602 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 531
diff changeset
  1544
f997c3873602 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 531
diff changeset
  1545
%{
f997c3873602 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 531
diff changeset
  1546
#ifdef AF_DECnet
f997c3873602 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 531
diff changeset
  1547
    hasIt = true;
f997c3873602 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 531
diff changeset
  1548
#else
f997c3873602 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 531
diff changeset
  1549
    hasIt = false;
f997c3873602 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 531
diff changeset
  1550
#endif
f997c3873602 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 531
diff changeset
  1551
%}.
f997c3873602 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 531
diff changeset
  1552
    hasIt ifTrue:[list add:#decnet].
f997c3873602 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 531
diff changeset
  1553
f997c3873602 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 531
diff changeset
  1554
%{
f997c3873602 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 531
diff changeset
  1555
#ifdef AF_NS
f997c3873602 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 531
diff changeset
  1556
    hasIt = true;
f997c3873602 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 531
diff changeset
  1557
#else
f997c3873602 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 531
diff changeset
  1558
    hasIt = false;
f997c3873602 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 531
diff changeset
  1559
#endif
f997c3873602 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 531
diff changeset
  1560
%}.
f997c3873602 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 531
diff changeset
  1561
    hasIt ifTrue:[list add:#xns].
f997c3873602 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 531
diff changeset
  1562
f997c3873602 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 531
diff changeset
  1563
%{
f997c3873602 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 531
diff changeset
  1564
#ifdef AF_X26
f997c3873602 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 531
diff changeset
  1565
    hasIt = true;
f997c3873602 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 531
diff changeset
  1566
#else
f997c3873602 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 531
diff changeset
  1567
    hasIt = false;
f997c3873602 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 531
diff changeset
  1568
#endif
f997c3873602 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 531
diff changeset
  1569
%}.
f997c3873602 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 531
diff changeset
  1570
    hasIt ifTrue:[list add:#x25].
f997c3873602 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 531
diff changeset
  1571
f997c3873602 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 531
diff changeset
  1572
%{
f997c3873602 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 531
diff changeset
  1573
#ifdef AF_SNA
f997c3873602 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 531
diff changeset
  1574
    hasIt = true;
f997c3873602 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 531
diff changeset
  1575
#else
f997c3873602 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 531
diff changeset
  1576
    hasIt = false;
f997c3873602 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 531
diff changeset
  1577
#endif
f997c3873602 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 531
diff changeset
  1578
%}.
f997c3873602 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 531
diff changeset
  1579
    hasIt ifTrue:[list add:#sna].
f997c3873602 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 531
diff changeset
  1580
f997c3873602 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 531
diff changeset
  1581
%{
f997c3873602 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 531
diff changeset
  1582
#ifdef AF_RAW
f997c3873602 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 531
diff changeset
  1583
    hasIt = true;
f997c3873602 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 531
diff changeset
  1584
#else
f997c3873602 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 531
diff changeset
  1585
    hasIt = false;
f997c3873602 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 531
diff changeset
  1586
#endif
f997c3873602 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 531
diff changeset
  1587
%}.
f997c3873602 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 531
diff changeset
  1588
    hasIt ifTrue:[list add:#raw].
f997c3873602 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 531
diff changeset
  1589
f997c3873602 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 531
diff changeset
  1590
%{
f997c3873602 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 531
diff changeset
  1591
#ifdef AF_ISO
f997c3873602 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 531
diff changeset
  1592
    hasIt = true;
f997c3873602 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 531
diff changeset
  1593
#else
f997c3873602 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 531
diff changeset
  1594
    hasIt = false;
f997c3873602 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 531
diff changeset
  1595
#endif
f997c3873602 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 531
diff changeset
  1596
%}.
f997c3873602 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 531
diff changeset
  1597
    hasIt ifTrue:[list add:#iso].
f997c3873602 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 531
diff changeset
  1598
f997c3873602 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 531
diff changeset
  1599
%{
f997c3873602 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 531
diff changeset
  1600
#ifdef AF_NETBIOS
f997c3873602 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 531
diff changeset
  1601
    hasIt = true;
f997c3873602 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 531
diff changeset
  1602
#else
f997c3873602 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 531
diff changeset
  1603
    hasIt = false;
f997c3873602 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 531
diff changeset
  1604
#endif
f997c3873602 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 531
diff changeset
  1605
%}.
f997c3873602 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 531
diff changeset
  1606
    hasIt ifTrue:[list add:#netbios].
f997c3873602 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 531
diff changeset
  1607
f997c3873602 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 531
diff changeset
  1608
%{
f997c3873602 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 531
diff changeset
  1609
#ifdef AF_IPX
f997c3873602 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 531
diff changeset
  1610
    hasIt = true;
f997c3873602 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 531
diff changeset
  1611
#else
f997c3873602 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 531
diff changeset
  1612
    hasIt = false;
f997c3873602 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 531
diff changeset
  1613
#endif
f997c3873602 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 531
diff changeset
  1614
%}.
f997c3873602 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 531
diff changeset
  1615
    hasIt ifTrue:[list add:#ipx].
f997c3873602 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 531
diff changeset
  1616
f997c3873602 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 531
diff changeset
  1617
%{
f997c3873602 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 531
diff changeset
  1618
#ifdef AF_AX25
f997c3873602 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 531
diff changeset
  1619
    hasIt = true;
f997c3873602 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 531
diff changeset
  1620
#else
f997c3873602 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 531
diff changeset
  1621
    hasIt = false;
f997c3873602 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 531
diff changeset
  1622
#endif
f997c3873602 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 531
diff changeset
  1623
%}.
f997c3873602 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 531
diff changeset
  1624
    hasIt ifTrue:[list add:#ax25].
f997c3873602 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 531
diff changeset
  1625
f997c3873602 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 531
diff changeset
  1626
%{
f997c3873602 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 531
diff changeset
  1627
#ifdef AF_NETROM
f997c3873602 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 531
diff changeset
  1628
    hasIt = true;
f997c3873602 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 531
diff changeset
  1629
#else
f997c3873602 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 531
diff changeset
  1630
    hasIt = false;
f997c3873602 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 531
diff changeset
  1631
#endif
f997c3873602 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 531
diff changeset
  1632
%}.
f997c3873602 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 531
diff changeset
  1633
    hasIt ifTrue:[list add:#netrom].
f997c3873602 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 531
diff changeset
  1634
f997c3873602 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 531
diff changeset
  1635
%{
f997c3873602 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 531
diff changeset
  1636
#ifdef AF_BRIDGE
f997c3873602 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 531
diff changeset
  1637
    hasIt = true;
f997c3873602 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 531
diff changeset
  1638
#else
f997c3873602 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 531
diff changeset
  1639
    hasIt = false;
f997c3873602 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 531
diff changeset
  1640
#endif
f997c3873602 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 531
diff changeset
  1641
%}.
f997c3873602 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 531
diff changeset
  1642
    hasIt ifTrue:[list add:#bridge].
f997c3873602 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 531
diff changeset
  1643
571
191b37534643 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 563
diff changeset
  1644
%{
191b37534643 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 563
diff changeset
  1645
#ifdef AF_BSC
191b37534643 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 563
diff changeset
  1646
    hasIt = true;
191b37534643 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 563
diff changeset
  1647
#else
191b37534643 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 563
diff changeset
  1648
    hasIt = false;
191b37534643 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 563
diff changeset
  1649
#endif
191b37534643 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 563
diff changeset
  1650
%}.
191b37534643 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 563
diff changeset
  1651
    hasIt ifTrue:[list add:#bsc].
191b37534643 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 563
diff changeset
  1652
191b37534643 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 563
diff changeset
  1653
532
f997c3873602 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 531
diff changeset
  1654
    ^ list
f997c3873602 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 531
diff changeset
  1655
f997c3873602 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 531
diff changeset
  1656
    "
f997c3873602 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 531
diff changeset
  1657
     Socket supportedProtocolFamilies
f997c3873602 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 531
diff changeset
  1658
    "
559
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
61012867ebed cleanup if #connect is interrupted
Claus Gittinger <cg@exept.de>
parents: 551
diff changeset
  1661
typeOfProtocol:aProtocol
61012867ebed cleanup if #connect is interrupted
Claus Gittinger <cg@exept.de>
parents: 551
diff changeset
  1662
    "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
  1663
     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
  1664
61012867ebed cleanup if #connect is interrupted
Claus Gittinger <cg@exept.de>
parents: 551
diff changeset
  1665
    (aProtocol = 'tcp') ifTrue:[^ #stream].
61012867ebed cleanup if #connect is interrupted
Claus Gittinger <cg@exept.de>
parents: 551
diff changeset
  1666
    (aProtocol = 'udp') ifTrue:[^ #datagram].
61012867ebed cleanup if #connect is interrupted
Claus Gittinger <cg@exept.de>
parents: 551
diff changeset
  1667
    (aProtocol = 'ip')  ifTrue:[^ #raw].
61012867ebed cleanup if #connect is interrupted
Claus Gittinger <cg@exept.de>
parents: 551
diff changeset
  1668
    "
61012867ebed cleanup if #connect is interrupted
Claus Gittinger <cg@exept.de>
parents: 551
diff changeset
  1669
     unix domain
61012867ebed cleanup if #connect is interrupted
Claus Gittinger <cg@exept.de>
parents: 551
diff changeset
  1670
    "
61012867ebed cleanup if #connect is interrupted
Claus Gittinger <cg@exept.de>
parents: 551
diff changeset
  1671
    (aProtocol = 'ud')  ifTrue:[^ #stream].
61012867ebed cleanup if #connect is interrupted
Claus Gittinger <cg@exept.de>
parents: 551
diff changeset
  1672
    "
61012867ebed cleanup if #connect is interrupted
Claus Gittinger <cg@exept.de>
parents: 551
diff changeset
  1673
     add x25 stuff (if any) here ...
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
    "
61012867ebed cleanup if #connect is interrupted
Claus Gittinger <cg@exept.de>
parents: 551
diff changeset
  1676
     add appletalk stuff (if any) here ...
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
    "
61012867ebed cleanup if #connect is interrupted
Claus Gittinger <cg@exept.de>
parents: 551
diff changeset
  1679
     add other stuff (if any) here ...
61012867ebed cleanup if #connect is interrupted
Claus Gittinger <cg@exept.de>
parents: 551
diff changeset
  1680
    "
61012867ebed cleanup if #connect is interrupted
Claus Gittinger <cg@exept.de>
parents: 551
diff changeset
  1681
    ^ nil
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
    "
61012867ebed cleanup if #connect is interrupted
Claus Gittinger <cg@exept.de>
parents: 551
diff changeset
  1684
     Socket typeOfProtocol:'tcp'
61012867ebed cleanup if #connect is interrupted
Claus Gittinger <cg@exept.de>
parents: 551
diff changeset
  1685
     Socket typeOfProtocol:'ucp'
61012867ebed cleanup if #connect is interrupted
Claus Gittinger <cg@exept.de>
parents: 551
diff changeset
  1686
     Socket typeOfProtocol:(Socket protocolOfService:'nntp')
61012867ebed cleanup if #connect is interrupted
Claus Gittinger <cg@exept.de>
parents: 551
diff changeset
  1687
     Socket typeOfProtocol:(Socket protocolOfService:'echo')
61012867ebed cleanup if #connect is interrupted
Claus Gittinger <cg@exept.de>
parents: 551
diff changeset
  1688
    "
28
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  1689
! !
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  1690
781
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  1691
!Socket methodsFor:'ST-80 compatibility'!
28
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  1692
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1693
errorReporter
781
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  1694
    "ST-80 mimicry."
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  1695
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1696
    ^ self
28
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  1697
!
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  1698
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1699
notReadySignal
781
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  1700
    "ST-80 mimicry.
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  1701
     for now - this is not yet raised"
71
claus
parents: 63
diff changeset
  1702
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1703
    ^ Signal new
486
ed4e215e83ef ST-80 mimicry
Claus Gittinger <cg@exept.de>
parents: 470
diff changeset
  1704
!
ed4e215e83ef ST-80 mimicry
Claus Gittinger <cg@exept.de>
parents: 470
diff changeset
  1705
576
13acab81fad0 more ST80 compatibility
ca
parents: 572
diff changeset
  1706
readAppendStream
781
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  1707
    "ST-80 mimicry.
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  1708
     In ST-80, socket is not a stream, but referes to one.
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  1709
     ST-80 code therefore uses 'Socket readWriteStream' to access
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  1710
     the actual stream. 
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  1711
     In ST/X, sockets inherit from stream, so
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  1712
     this method returns the receiver, for transparency"
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  1713
576
13acab81fad0 more ST80 compatibility
ca
parents: 572
diff changeset
  1714
    ^ self
13acab81fad0 more ST80 compatibility
ca
parents: 572
diff changeset
  1715
!
13acab81fad0 more ST80 compatibility
ca
parents: 572
diff changeset
  1716
486
ed4e215e83ef ST-80 mimicry
Claus Gittinger <cg@exept.de>
parents: 470
diff changeset
  1717
readStream
ed4e215e83ef ST-80 mimicry
Claus Gittinger <cg@exept.de>
parents: 470
diff changeset
  1718
    "ST-80 mimicry.
ed4e215e83ef ST-80 mimicry
Claus Gittinger <cg@exept.de>
parents: 470
diff changeset
  1719
     In ST-80, socket is not a stream, but referes to one.
ed4e215e83ef ST-80 mimicry
Claus Gittinger <cg@exept.de>
parents: 470
diff changeset
  1720
     ST-80 code therefore uses 'Socket readStream' to access
781
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  1721
     the actual stream. 
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  1722
     In ST/X, sockets inherit from stream, so
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  1723
     this method returns the receiver, for transparency"
486
ed4e215e83ef ST-80 mimicry
Claus Gittinger <cg@exept.de>
parents: 470
diff changeset
  1724
ed4e215e83ef ST-80 mimicry
Claus Gittinger <cg@exept.de>
parents: 470
diff changeset
  1725
    ^ self
ed4e215e83ef ST-80 mimicry
Claus Gittinger <cg@exept.de>
parents: 470
diff changeset
  1726
ed4e215e83ef ST-80 mimicry
Claus Gittinger <cg@exept.de>
parents: 470
diff changeset
  1727
    "Created: 24.1.1997 / 23:52:57 / cg"
ed4e215e83ef ST-80 mimicry
Claus Gittinger <cg@exept.de>
parents: 470
diff changeset
  1728
!
ed4e215e83ef ST-80 mimicry
Claus Gittinger <cg@exept.de>
parents: 470
diff changeset
  1729
576
13acab81fad0 more ST80 compatibility
ca
parents: 572
diff changeset
  1730
shutdown:how
13acab81fad0 more ST80 compatibility
ca
parents: 572
diff changeset
  1731
    "ST-80 compatibility"
13acab81fad0 more ST80 compatibility
ca
parents: 572
diff changeset
  1732
13acab81fad0 more ST80 compatibility
ca
parents: 572
diff changeset
  1733
    self shutDown
13acab81fad0 more ST80 compatibility
ca
parents: 572
diff changeset
  1734
!
13acab81fad0 more ST80 compatibility
ca
parents: 572
diff changeset
  1735
486
ed4e215e83ef ST-80 mimicry
Claus Gittinger <cg@exept.de>
parents: 470
diff changeset
  1736
writeStream
ed4e215e83ef ST-80 mimicry
Claus Gittinger <cg@exept.de>
parents: 470
diff changeset
  1737
    "ST-80 mimicry.
ed4e215e83ef ST-80 mimicry
Claus Gittinger <cg@exept.de>
parents: 470
diff changeset
  1738
     In ST-80, socket is not a stream, but referes to one.
ed4e215e83ef ST-80 mimicry
Claus Gittinger <cg@exept.de>
parents: 470
diff changeset
  1739
     ST-80 code therefore uses 'Socket writeStream' to access
781
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  1740
     the actual stream. 
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  1741
     In ST/X, sockets inherit from stream, so
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  1742
     this method returns the receiver, for transparency"
486
ed4e215e83ef ST-80 mimicry
Claus Gittinger <cg@exept.de>
parents: 470
diff changeset
  1743
ed4e215e83ef ST-80 mimicry
Claus Gittinger <cg@exept.de>
parents: 470
diff changeset
  1744
    ^ self
ed4e215e83ef ST-80 mimicry
Claus Gittinger <cg@exept.de>
parents: 470
diff changeset
  1745
ed4e215e83ef ST-80 mimicry
Claus Gittinger <cg@exept.de>
parents: 470
diff changeset
  1746
    "Created: 24.1.1997 / 10:34:35 / cg"
ed4e215e83ef ST-80 mimicry
Claus Gittinger <cg@exept.de>
parents: 470
diff changeset
  1747
    "Modified: 24.1.1997 / 23:52:52 / cg"
71
claus
parents: 63
diff changeset
  1748
! !
claus
parents: 63
diff changeset
  1749
771
74abb04ef57c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 752
diff changeset
  1750
!Socket methodsFor:'Squeak compatibility'!
74abb04ef57c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 752
diff changeset
  1751
74abb04ef57c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 752
diff changeset
  1752
peerName
74abb04ef57c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 752
diff changeset
  1753
    "return my peer (i.e. ipAddr + port);
74abb04ef57c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 752
diff changeset
  1754
     May return nil if not yet setup completely."
74abb04ef57c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 752
diff changeset
  1755
74abb04ef57c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 752
diff changeset
  1756
    ^ self getPeer
74abb04ef57c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 752
diff changeset
  1757
! !
74abb04ef57c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 752
diff changeset
  1758
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1759
!Socket methodsFor:'datagram transmission'!
28
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  1760
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1761
receiveFrom:anAddressBuffer buffer:aDataBuffer
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1762
    "receive datagramm data - put address of originating host into
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1763
     anAddressBuffer, data into aBuffer. 
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1764
     Both must be ByteArray-like. The addressBuffer must
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1765
     provide space for a valid address for my domain (i.e. for inet, a 4-byte byteArray).
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1766
     Return the number of bytes received, or a negative number on error.
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1767
     On error, the unix error code is left in the lastErrorNumber
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1768
     instance variable."
28
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  1769
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1770
    ^ 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
  1771
!
7d016cc30052 fixed & moved pingWalk from SNMPSession to here;
Claus Gittinger <cg@exept.de>
parents: 98
diff changeset
  1772
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1773
receiveFrom:anAddressBuffer buffer:aDataBuffer start:startIndex for:nBytes
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1774
    "receive datagramm data - put address of originating host into
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1775
     anAddressBuffer, data into aBuffer. For ST-80 compatibility,
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1776
     the addressBuffer may be a non-ByteArray; then, it must understand
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1777
     the addressBytes-message (i.e. be a SocketAddress instance).
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1778
     Return the number of bytes received, or a negative number on error.
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1779
     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
  1780
     instance variable.
b8042ff0f82c udp receive: translate received address according to the domain
Claus Gittinger <cg@exept.de>
parents: 511
diff changeset
  1781
     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
  1782
     receiving, using #readWait or #readWaitWithTimeout:."
b8042ff0f82c udp receive: translate received address according to the domain
Claus Gittinger <cg@exept.de>
parents: 511
diff changeset
  1783
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1784
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1785
    |addrBytes addrLen nReceived|
28
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  1786
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1787
    addrBytes := ByteArray new:100.
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1788
%{
418
317e55c6c281 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 403
diff changeset
  1789
#ifndef NO_SOCKET
513
b8042ff0f82c udp receive: translate received address according to the domain
Claus Gittinger <cg@exept.de>
parents: 511
diff changeset
  1790
    OBJ oClass, myDomain;
217
fcfbc9f71048 underscore cleanup
Claus Gittinger <cg@exept.de>
parents: 209
diff changeset
  1791
    OBJ fp = __INST(filePointer);
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1792
    int nInstVars, nInstBytes, objSize;
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1793
    int sock;
513
b8042ff0f82c udp receive: translate received address according to the domain
Claus Gittinger <cg@exept.de>
parents: 511
diff changeset
  1794
    union {
526
1748ab3892a3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 525
diff changeset
  1795
# ifdef AF_INET
789
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  1796
	struct sockaddr_in in;
530
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  1797
# endif
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  1798
# ifdef AF_INET6
789
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  1799
	struct sockaddr_in6 in6;
526
1748ab3892a3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 525
diff changeset
  1800
# endif
1748ab3892a3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 525
diff changeset
  1801
# ifdef AF_UNIX
789
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  1802
	struct sockaddr_un un;
526
1748ab3892a3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 525
diff changeset
  1803
# endif
1748ab3892a3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 525
diff changeset
  1804
# ifdef AF_APPLETALK
789
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  1805
	struct sockaddr_at at;
526
1748ab3892a3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 525
diff changeset
  1806
# endif
513
b8042ff0f82c udp receive: translate received address according to the domain
Claus Gittinger <cg@exept.de>
parents: 511
diff changeset
  1807
    } sa;
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1808
    int alen;
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1809
    int n;
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1810
    char *cp;
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1811
    int flags = 0;
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1812
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1813
    if (fp != nil) {
789
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  1814
	sock = fileno(__FILEVal(fp));
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  1815
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  1816
	oClass = __Class(aDataBuffer);
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  1817
	switch (_intVal(_ClassInstPtr(oClass)->c_flags) & ARRAYMASK) {
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  1818
	    case BYTEARRAY:
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  1819
	    case WORDARRAY:
790
6f58d65fac5e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 789
diff changeset
  1820
	    case SWORDARRAY:
789
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  1821
	    case LONGARRAY:
790
6f58d65fac5e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 789
diff changeset
  1822
	    case SLONGARRAY:
789
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  1823
	    case FLOATARRAY:
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  1824
	    case DOUBLEARRAY:
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  1825
		break;
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  1826
	    default:
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  1827
		goto bad;
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  1828
	}
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  1829
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  1830
	nInstVars = _intVal(_ClassInstPtr(oClass)->c_ninstvars);
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  1831
	nInstBytes = OHDR_SIZE + nInstVars * sizeof(OBJ);
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  1832
	objSize = _Size(aDataBuffer) - nInstBytes;
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  1833
	cp = (char *)__InstPtr(aDataBuffer) + nInstBytes;
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  1834
	if (__isSmallInteger(startIndex)) {
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  1835
	    cp += __intVal(startIndex);
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  1836
	    objSize -= __intVal(startIndex);
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  1837
	}
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  1838
	if (__isSmallInteger(nBytes)) {
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  1839
	    if (__intVal(nBytes) < objSize) {
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  1840
		objSize = __intVal(nBytes);
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  1841
	    }
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  1842
	}
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  1843
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  1844
	__BEGIN_INTERRUPTABLE__
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  1845
	do {
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  1846
	    if (addrBytes == nil) {
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  1847
		n = recvfrom(sock, cp, objSize, flags, (struct sockaddr *) 0, 0);
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  1848
	    } else {
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  1849
		n = recvfrom(sock, cp, objSize, flags, (struct sockaddr *) &sa, &alen);
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  1850
	    }
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  1851
	} while ((n < 0) && (errno == EINTR));
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  1852
	__END_INTERRUPTABLE__
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  1853
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  1854
	if (n >= 0) {
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  1855
	    if (addrBytes != nil) {
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  1856
		oClass = __Class(addrBytes);
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  1857
		if ((_intVal(_ClassInstPtr(oClass)->c_flags) & ARRAYMASK) != BYTEARRAY) 
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  1858
		    goto bad;
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  1859
		nInstVars = _intVal(_ClassInstPtr(oClass)->c_ninstvars);
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  1860
		nInstBytes = OHDR_SIZE + nInstVars * sizeof(OBJ);
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  1861
		objSize = _Size(addrBytes) - nInstBytes;
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  1862
		cp = (char *)__InstPtr(addrBytes) + nInstBytes;
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  1863
		if (objSize < alen) 
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  1864
		    goto bad;
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  1865
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  1866
		myDomain = __INST(domain);
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  1867
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  1868
		/*
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  1869
		 * extract the datagrams address
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  1870
		 */
653
219b89f62113 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 650
diff changeset
  1871
# ifdef AF_INET
789
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  1872
		if (myDomain == @symbol(inet)) {
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  1873
		    cp[0] = (sa.in.sin_addr.s_addr >> 24) & 0xFF;
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  1874
		    cp[2] = (sa.in.sin_addr.s_addr >> 16) & 0xFF;
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  1875
		    cp[3] = (sa.in.sin_addr.s_addr >> 8) & 0xFF;
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  1876
		    cp[4] = (sa.in.sin_addr.s_addr >> 0) & 0xFF;
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  1877
		    alen = 4;
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  1878
		}
653
219b89f62113 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 650
diff changeset
  1879
# endif /* AF_INET */
219b89f62113 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 650
diff changeset
  1880
789
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  1881
		/*
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  1882
		 * XXXX add addressing stuff for other domains here ...
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  1883
		 */
653
219b89f62113 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 650
diff changeset
  1884
# ifdef AF_INET6
219b89f62113 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 650
diff changeset
  1885
# endif /* AF_INET6 */
219b89f62113 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 650
diff changeset
  1886
513
b8042ff0f82c udp receive: translate received address according to the domain
Claus Gittinger <cg@exept.de>
parents: 511
diff changeset
  1887
# ifdef AF_X25
789
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  1888
		if (myDomain == @symbol(x25)) {
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  1889
		}
513
b8042ff0f82c udp receive: translate received address according to the domain
Claus Gittinger <cg@exept.de>
parents: 511
diff changeset
  1890
# endif
b8042ff0f82c udp receive: translate received address according to the domain
Claus Gittinger <cg@exept.de>
parents: 511
diff changeset
  1891
# ifdef AF_NS
789
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  1892
		if (myDomain == @symbol(ns)) {
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  1893
		}
513
b8042ff0f82c udp receive: translate received address according to the domain
Claus Gittinger <cg@exept.de>
parents: 511
diff changeset
  1894
# endif
b8042ff0f82c udp receive: translate received address according to the domain
Claus Gittinger <cg@exept.de>
parents: 511
diff changeset
  1895
# ifdef AF_APPLETALK
789
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  1896
		if (myDomain == @symbol(appletalk)) {
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  1897
		}
513
b8042ff0f82c udp receive: translate received address according to the domain
Claus Gittinger <cg@exept.de>
parents: 511
diff changeset
  1898
# endif
b8042ff0f82c udp receive: translate received address according to the domain
Claus Gittinger <cg@exept.de>
parents: 511
diff changeset
  1899
# ifdef AF_SNA
789
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  1900
		if (myDomain == @symbol(sna)) {
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  1901
		}
513
b8042ff0f82c udp receive: translate received address according to the domain
Claus Gittinger <cg@exept.de>
parents: 511
diff changeset
  1902
# endif
b8042ff0f82c udp receive: translate received address according to the domain
Claus Gittinger <cg@exept.de>
parents: 511
diff changeset
  1903
# ifdef AF_NS
789
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  1904
		if (myDomain == @symbol(xns)) {
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  1905
		}
513
b8042ff0f82c udp receive: translate received address according to the domain
Claus Gittinger <cg@exept.de>
parents: 511
diff changeset
  1906
# endif
b8042ff0f82c udp receive: translate received address according to the domain
Claus Gittinger <cg@exept.de>
parents: 511
diff changeset
  1907
# ifdef AF_RAW
789
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  1908
		if (myDomain == @symbol(raw)) {
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  1909
		}
524
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  1910
# endif
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  1911
# ifdef AF_ISO
789
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  1912
		if (myDomain == @symbol(iso)) {
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  1913
		}
524
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  1914
# endif
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  1915
# ifdef AF_DECnet
789
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  1916
		if (myDomain == @symbol(decnet)) {
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  1917
		}
513
b8042ff0f82c udp receive: translate received address according to the domain
Claus Gittinger <cg@exept.de>
parents: 511
diff changeset
  1918
# endif
524
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  1919
# ifdef AF_NETBIOS
789
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  1920
		if (myDomain == @symbol(netbios)) {
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  1921
		}
530
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  1922
# endif
653
219b89f62113 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 650
diff changeset
  1923
# ifdef AF_IPX
789
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  1924
		if (myDomain == @symbol(ipx)) {
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  1925
		}
530
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  1926
# endif
653
219b89f62113 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 650
diff changeset
  1927
# ifdef AF_BRIDGE
789
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  1928
		if (myDomain == @symbol(bridge)) {
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  1929
		}
524
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  1930
# endif
653
219b89f62113 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 650
diff changeset
  1931
# ifdef AF_BSC
789
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  1932
		if (myDomain == @symbol(bsc)) {
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  1933
		}
571
191b37534643 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 563
diff changeset
  1934
# endif
524
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  1935
# if defined(AF_CCITT) && (AF_CCITT != AF_X25)
789
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  1936
		if (myDomain == @symbol(ccitt)) {
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  1937
		}
524
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  1938
# endif
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  1939
789
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  1940
		addrLen = __MKSMALLINT(alen);
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  1941
	    }
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  1942
	}
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  1943
	if (n < 0) {
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  1944
	    __INST(lastErrorNumber) = __MKSMALLINT(errno);
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  1945
	}
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  1946
	nReceived = __MKSMALLINT(n);
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1947
    }
418
317e55c6c281 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 403
diff changeset
  1948
#endif
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1949
bad: ;
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1950
%}.
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1951
    nReceived notNil ifTrue:[
789
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  1952
	nReceived < 0 ifTrue:[
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  1953
	    'Socket [warning]: ' infoPrint.
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  1954
	    (OperatingSystem errorTextForNumber:lastErrorNumber) infoPrintCR.
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  1955
	].
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  1956
	addrLen notNil ifTrue:[
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  1957
	    anAddressBuffer class isBytes ifTrue:[
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  1958
		anAddressBuffer replaceFrom:1 to:addrLen with:addrBytes
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  1959
	    ] ifFalse:[
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  1960
		"/ can be SocketAddress for ST-80 compatibility
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  1961
		anAddressBuffer hostAddress:(addrBytes copyTo:addrLen)
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  1962
	    ].
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  1963
	].
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  1964
	^ nReceived
28
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  1965
    ].
116
7789fb1c9fa2 more UD socket fixes (at least client side seems to work now)
Claus Gittinger <cg@exept.de>
parents: 115
diff changeset
  1966
    "
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1967
     arrive here if you try to receive into an invalid buffer
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1968
     (i.e. not ByteArray-like), 
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1969
     or if the addressBuffer is nonNil AND not a ByteArray/String 
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1970
     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
  1971
    "
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1972
    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
  1973
!
7789fb1c9fa2 more UD socket fixes (at least client side seems to work now)
Claus Gittinger <cg@exept.de>
parents: 115
diff changeset
  1974
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1975
sendTo:anAddressBuffer buffer:buffer
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1976
    "send datagramm data - fetch address of destination host from
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1977
     anAddressBuffer, data from aDataBuffer. 
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1978
     Both must be ByteArray-like. The bytes in the addressBuffer must
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1979
     be a valid address for my domain (i.e. for inet, a 4-byte byteArray).
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1980
     Return the number of bytes transmitted, or a negative number on error.
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1981
     On error, the unix error code is left in the lastErrorNumber
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1982
     instance variable.
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1983
     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
  1984
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1985
    ^ 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
  1986
!
7789fb1c9fa2 more UD socket fixes (at least client side seems to work now)
Claus Gittinger <cg@exept.de>
parents: 115
diff changeset
  1987
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1988
sendTo:anAddressBuffer buffer:aDataBuffer start:startIndex for:count flags:flags
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1989
    "send datagramm data - fetch address of destination host from
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1990
     anAddressBuffer, data from aDataBuffer starting at startIndex,
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1991
     sending count bytes. 
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1992
     Both must be ByteArray-like. The bytes in the addressBuffer must
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1993
     be a valid address for my domain (i.e. for inet, a 4-byte byteArray).
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1994
     Return the number of bytes transmitted, or a negative number on error.
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1995
     On error, the unix error code is left in the lastErrorNumber
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1996
     instance variable."
0
1cf8d1747859 Initial revision
claus
parents:
diff changeset
  1997
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1998
    |addrBytes addrLen nReceived portNo|
93
Claus Gittinger <cg@exept.de>
parents: 92
diff changeset
  1999
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  2000
    "/ addressBuffer can be a 6-byte byteArray (last 2 bytes are portNo, msb-first)
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  2001
    "/ or an instance of IPSocketAddress
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  2002
    "/
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  2003
    anAddressBuffer class isBytes ifTrue:[
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  2004
	addrBytes := anAddressBuffer copyFrom:1 to:4.
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  2005
	portNo := ((anAddressBuffer at:5) bitShift:8)
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  2006
		  + (anAddressBuffer at:6).
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  2007
    ] ifFalse:[
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  2008
	addrBytes := anAddressBuffer hostAddress.
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  2009
	portNo := anAddressBuffer port.
28
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  2010
    ].
0
1cf8d1747859 Initial revision
claus
parents:
diff changeset
  2011
%{
418
317e55c6c281 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 403
diff changeset
  2012
#ifndef NO_SOCKET
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  2013
    OBJ oClass;
217
fcfbc9f71048 underscore cleanup
Claus Gittinger <cg@exept.de>
parents: 209
diff changeset
  2014
    OBJ fp = __INST(filePointer);
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  2015
    int nInstVars, nInstBytes, objSize;
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  2016
    int sock;
526
1748ab3892a3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 525
diff changeset
  2017
    union {
1748ab3892a3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 525
diff changeset
  2018
# ifdef AF_INET
530
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  2019
	struct sockaddr_in in;
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  2020
# endif
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  2021
# ifdef AF_INET6
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  2022
	struct sockaddr_in6 in6;
526
1748ab3892a3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 525
diff changeset
  2023
# endif
1748ab3892a3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 525
diff changeset
  2024
# ifdef AF_UNIX
1748ab3892a3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 525
diff changeset
  2025
	struct sockaddr_un un;
1748ab3892a3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 525
diff changeset
  2026
# endif
1748ab3892a3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 525
diff changeset
  2027
# ifdef AF_APPLETALK
1748ab3892a3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 525
diff changeset
  2028
	struct sockaddr_at at;
1748ab3892a3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 525
diff changeset
  2029
# endif
1748ab3892a3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 525
diff changeset
  2030
    } sa;
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  2031
    struct sockaddr *saPtr = (struct sockaddr *)&sa;
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  2032
    int alen = sizeof(sa);
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  2033
    int n;
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  2034
    char *cp;
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  2035
    int _flags = 0;
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  2036
    int offs, nBytes;
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  2037
    unsigned long norder;
21
33eb5ffad09d *** empty log message ***
claus
parents: 8
diff changeset
  2038
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  2039
    _flags = __longIntVal(flags);
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  2040
 
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  2041
    if ((fp != nil) 
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  2042
     && __isSmallInteger(startIndex)
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  2043
     && __isSmallInteger(count)) {
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  2044
	sock = fileno(__FILEVal(fp));
0
1cf8d1747859 Initial revision
claus
parents:
diff changeset
  2045
525
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  2046
	if (addrBytes == nil) {
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  2047
	    alen = 0;
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  2048
	    saPtr = (struct sockaddr *)0;
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  2049
	} else {
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  2050
	    if (! __isByteArray(addrBytes)) goto bad;
525
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  2051
551
b2d6e4d86e77 avoid warnings (signed char vs. unsigned char)
Claus Gittinger <cg@exept.de>
parents: 537
diff changeset
  2052
	    cp = (char *)__ByteArrayInstPtr(addrBytes)->ba_element;
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  2053
	    n = __byteArraySize(addrBytes);
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  2054
	    if (alen < n) n = alen;
790
6f58d65fac5e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 789
diff changeset
  2055
# ifdef DGRAM_DEBUG
526
1748ab3892a3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 525
diff changeset
  2056
	    printf("address is %d bytes ... %d.%d.%d.%d", n, cp[0], cp[1], cp[2], cp[3]);
790
6f58d65fac5e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 789
diff changeset
  2057
# endif
526
1748ab3892a3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 525
diff changeset
  2058
	    bcopy(cp, &sa.in.sin_addr.s_addr, n);
790
6f58d65fac5e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 789
diff changeset
  2059
# ifdef AF_INET
526
1748ab3892a3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 525
diff changeset
  2060
	    if (__INST(domain) == @symbol(inet)) {
533
ced9950b551f added query about which protocols are supported
Claus Gittinger <cg@exept.de>
parents: 532
diff changeset
  2061
		sa.in.sin_family = AF_INET;
ced9950b551f added query about which protocols are supported
Claus Gittinger <cg@exept.de>
parents: 532
diff changeset
  2062
		sa.in.sin_port = htons((u_short) __intVal(portNo)); 
526
1748ab3892a3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 525
diff changeset
  2063
	    }
790
6f58d65fac5e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 789
diff changeset
  2064
# endif
6f58d65fac5e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 789
diff changeset
  2065
# ifdef AF_INET6
533
ced9950b551f added query about which protocols are supported
Claus Gittinger <cg@exept.de>
parents: 532
diff changeset
  2066
	    if (__INST(domain) == @symbol(inet6)) {
ced9950b551f added query about which protocols are supported
Claus Gittinger <cg@exept.de>
parents: 532
diff changeset
  2067
		sa.in6.sin6_family = AF_INET;
ced9950b551f added query about which protocols are supported
Claus Gittinger <cg@exept.de>
parents: 532
diff changeset
  2068
		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
  2069
	    }
790
6f58d65fac5e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 789
diff changeset
  2070
# endif
6f58d65fac5e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 789
diff changeset
  2071
# ifdef AF_APPLETALK
526
1748ab3892a3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 525
diff changeset
  2072
	    if (__INST(domain) == @symbol(appletalk)) {
533
ced9950b551f added query about which protocols are supported
Claus Gittinger <cg@exept.de>
parents: 532
diff changeset
  2073
		sa.at.sat_family = AF_INET;
ced9950b551f added query about which protocols are supported
Claus Gittinger <cg@exept.de>
parents: 532
diff changeset
  2074
		sa.at.sat_port = __intVal(portNo);
ced9950b551f added query about which protocols are supported
Claus Gittinger <cg@exept.de>
parents: 532
diff changeset
  2075
	    }
790
6f58d65fac5e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 789
diff changeset
  2076
# endif
93
Claus Gittinger <cg@exept.de>
parents: 92
diff changeset
  2077
	}
6
claus
parents: 4
diff changeset
  2078
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  2079
	oClass = __Class(aDataBuffer);
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  2080
	switch (_intVal(_ClassInstPtr(oClass)->c_flags) & ARRAYMASK) {
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  2081
	    case BYTEARRAY:
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  2082
		offs = __intVal(startIndex) - 1;
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  2083
		break;
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  2084
	    case WORDARRAY:
790
6f58d65fac5e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 789
diff changeset
  2085
	    case SWORDARRAY:
6f58d65fac5e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 789
diff changeset
  2086
		offs = (__intVal(startIndex) - 1) * 2;
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  2087
		break;
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  2088
	    case LONGARRAY:
790
6f58d65fac5e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 789
diff changeset
  2089
	    case SLONGARRAY:
6f58d65fac5e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 789
diff changeset
  2090
		offs = (__intVal(startIndex) - 1) * 4;
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  2091
		break;
790
6f58d65fac5e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 789
diff changeset
  2092
	    case LONGLONGARRAY:
6f58d65fac5e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 789
diff changeset
  2093
	    case SLONGLONGARRAY:
6f58d65fac5e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 789
diff changeset
  2094
		offs = (__intVal(startIndex) - 1) * 8;
6f58d65fac5e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 789
diff changeset
  2095
# ifdef __NEED_LONGLONG_ALIGN
6f58d65fac5e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 789
diff changeset
  2096
		offs += 4;
6f58d65fac5e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 789
diff changeset
  2097
# endif
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  2098
	    case FLOATARRAY:
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  2099
		offs = (__intVal(startIndex) - 1) * sizeof(float);
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  2100
		break;
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  2101
	    case DOUBLEARRAY:
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  2102
		offs = (__intVal(startIndex) - 1) * sizeof(double);
790
6f58d65fac5e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 789
diff changeset
  2103
# ifdef __NEED_DOUBLE_ALIGN
6f58d65fac5e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 789
diff changeset
  2104
		offs += 4;
6f58d65fac5e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 789
diff changeset
  2105
# endif
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  2106
		break;
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  2107
	    default:
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  2108
		goto bad;
42
506596f9a1a8 *** empty log message ***
claus
parents: 38
diff changeset
  2109
	}
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  2110
	nBytes = __intVal(count);
71
claus
parents: 63
diff changeset
  2111
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  2112
	nInstVars = _intVal(_ClassInstPtr(oClass)->c_ninstvars);
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  2113
	nInstBytes = OHDR_SIZE + nInstVars * sizeof(OBJ);
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  2114
	objSize = __qSize(aDataBuffer) - nInstBytes;
217
fcfbc9f71048 underscore cleanup
Claus Gittinger <cg@exept.de>
parents: 209
diff changeset
  2115
	cp = (char *)__InstPtr(aDataBuffer) + nInstBytes;
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  2116
	cp += offs;
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  2117
	if ((offs + nBytes) > objSize) {
790
6f58d65fac5e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 789
diff changeset
  2118
# ifdef DGRAM_DEBUG
526
1748ab3892a3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 525
diff changeset
  2119
	    printf("cut off ...\n");
790
6f58d65fac5e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 789
diff changeset
  2120
# endif
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  2121
	    nBytes = objSize - offs;
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  2122
	}
0
1cf8d1747859 Initial revision
claus
parents:
diff changeset
  2123
526
1748ab3892a3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 525
diff changeset
  2124
	norder = htonl(sa.in.sin_addr.s_addr);
790
6f58d65fac5e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 789
diff changeset
  2125
# ifdef DGRAM_DEBUG
526
1748ab3892a3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 525
diff changeset
  2126
	printf("sending %d bytes ... to ", nBytes);
1748ab3892a3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 525
diff changeset
  2127
	printf("%d.%d.%d.%d\n",
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  2128
		    (norder >> 24) & 0xFF,
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  2129
		    (norder >> 16) & 0xFF,
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  2130
		    (norder >> 8) & 0xFF,
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  2131
		    norder & 0xFF);
790
6f58d65fac5e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 789
diff changeset
  2132
# endif
0
1cf8d1747859 Initial revision
claus
parents:
diff changeset
  2133
81
claus
parents: 79
diff changeset
  2134
	__BEGIN_INTERRUPTABLE__
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  2135
	do {
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  2136
	    n = sendto(sock, cp, nBytes, _flags, saPtr, alen);
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  2137
	} while ((n < 0) && (errno == EINTR));
81
claus
parents: 79
diff changeset
  2138
	__END_INTERRUPTABLE__
0
1cf8d1747859 Initial revision
claus
parents:
diff changeset
  2139
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  2140
	if (n < 0) {
217
fcfbc9f71048 underscore cleanup
Claus Gittinger <cg@exept.de>
parents: 209
diff changeset
  2141
	    __INST(lastErrorNumber) = __MKSMALLINT(errno);
42
506596f9a1a8 *** empty log message ***
claus
parents: 38
diff changeset
  2142
	}
217
fcfbc9f71048 underscore cleanup
Claus Gittinger <cg@exept.de>
parents: 209
diff changeset
  2143
	RETURN (__MKSMALLINT(n));
0
1cf8d1747859 Initial revision
claus
parents:
diff changeset
  2144
    }
418
317e55c6c281 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 403
diff changeset
  2145
#endif
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  2146
bad: ;
42
506596f9a1a8 *** empty log message ***
claus
parents: 38
diff changeset
  2147
%}.
506596f9a1a8 *** empty log message ***
claus
parents: 38
diff changeset
  2148
    "
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  2149
     arrive here if you try to send from an invalid buffer
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  2150
     (i.e. not ByteArray-like), 
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  2151
     or if the addressBuffer is nonNil AND not a ByteArray/String 
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  2152
     or if the addressBuffer is nonNil AND too small.
42
506596f9a1a8 *** empty log message ***
claus
parents: 38
diff changeset
  2153
    "
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  2154
    self primitiveFailed
0
1cf8d1747859 Initial revision
claus
parents:
diff changeset
  2155
! !
1cf8d1747859 Initial revision
claus
parents:
diff changeset
  2156
1cf8d1747859 Initial revision
claus
parents:
diff changeset
  2157
!Socket methodsFor:'low level'!
1cf8d1747859 Initial revision
claus
parents:
diff changeset
  2158
507
91fb3dfd91a5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 506
diff changeset
  2159
bindAnonymously
91fb3dfd91a5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 506
diff changeset
  2160
    ^ self
91fb3dfd91a5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 506
diff changeset
  2161
	bindTo:0
91fb3dfd91a5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 506
diff changeset
  2162
	address:nil
509
eb5a2d5bab0b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 508
diff changeset
  2163
	reuseAddress:false
eb5a2d5bab0b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 508
diff changeset
  2164
!
eb5a2d5bab0b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 508
diff changeset
  2165
eb5a2d5bab0b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 508
diff changeset
  2166
bindAnonymouslyToAddress:addressString
eb5a2d5bab0b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 508
diff changeset
  2167
    ^ self
eb5a2d5bab0b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 508
diff changeset
  2168
	bindTo:0
eb5a2d5bab0b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 508
diff changeset
  2169
	address:addressString
eb5a2d5bab0b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 508
diff changeset
  2170
	reuseAddress:false
507
91fb3dfd91a5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 506
diff changeset
  2171
!
91fb3dfd91a5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 506
diff changeset
  2172
71
claus
parents: 63
diff changeset
  2173
bindTo:aSocketAddress 
425
eb8198e9f1b0 comment
Claus Gittinger <cg@exept.de>
parents: 421
diff changeset
  2174
    "ST80 compatible bind, expecting a socketAddress argument.
eb8198e9f1b0 comment
Claus Gittinger <cg@exept.de>
parents: 421
diff changeset
  2175
     The socketAddress object (an instance of SocketAddress)
eb8198e9f1b0 comment
Claus Gittinger <cg@exept.de>
parents: 421
diff changeset
  2176
     is supposed to respond to #portOrName and #address requests."
71
claus
parents: 63
diff changeset
  2177
claus
parents: 63
diff changeset
  2178
    ^ self bindTo:(aSocketAddress portOrName)
claus
parents: 63
diff changeset
  2179
	   address:(aSocketAddress address)
425
eb8198e9f1b0 comment
Claus Gittinger <cg@exept.de>
parents: 421
diff changeset
  2180
	   reuseAddress:true
71
claus
parents: 63
diff changeset
  2181
!
claus
parents: 63
diff changeset
  2182
425
eb8198e9f1b0 comment
Claus Gittinger <cg@exept.de>
parents: 421
diff changeset
  2183
bindTo:portNrOrNameString address:addressString
28
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  2184
    "low level bind - returns true if ok, false otherwise.
71
claus
parents: 63
diff changeset
  2185
     Currently only non-address binding is supported; 
425
eb8198e9f1b0 comment
Claus Gittinger <cg@exept.de>
parents: 421
diff changeset
  2186
     i.e. the address must always be nil.
71
claus
parents: 63
diff changeset
  2187
claus
parents: 63
diff changeset
  2188
     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
  2189
	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
  2190
	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
  2191
	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
  2192
     "
7789fb1c9fa2 more UD socket fixes (at least client side seems to work now)
Claus Gittinger <cg@exept.de>
parents: 115
diff changeset
  2193
425
eb8198e9f1b0 comment
Claus Gittinger <cg@exept.de>
parents: 421
diff changeset
  2194
    ^ self 
eb8198e9f1b0 comment
Claus Gittinger <cg@exept.de>
parents: 421
diff changeset
  2195
	bindTo:portNrOrNameString 
eb8198e9f1b0 comment
Claus Gittinger <cg@exept.de>
parents: 421
diff changeset
  2196
	address:addressString 
eb8198e9f1b0 comment
Claus Gittinger <cg@exept.de>
parents: 421
diff changeset
  2197
	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
  2198
!
7789fb1c9fa2 more UD socket fixes (at least client side seems to work now)
Claus Gittinger <cg@exept.de>
parents: 115
diff changeset
  2199
7789fb1c9fa2 more UD socket fixes (at least client side seems to work now)
Claus Gittinger <cg@exept.de>
parents: 115
diff changeset
  2200
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
  2201
    "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
  2202
     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
  2203
     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
  2204
7789fb1c9fa2 more UD socket fixes (at least client side seems to work now)
Claus Gittinger <cg@exept.de>
parents: 115
diff changeset
  2205
     The interpretation of portNrOrName depends on the domain:
789
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2206
	inet domain uses (4byte) byteArray like internet numbers,
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2207
	unix domain uses pathname strings,
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2208
	others use whatever will come up in the future
425
eb8198e9f1b0 comment
Claus Gittinger <cg@exept.de>
parents: 421
diff changeset
  2209
eb8198e9f1b0 comment
Claus Gittinger <cg@exept.de>
parents: 421
diff changeset
  2210
     The reuse boolean argument controls if the SO_REUSEADDR socket option
eb8198e9f1b0 comment
Claus Gittinger <cg@exept.de>
parents: 421
diff changeset
  2211
     is to be set (to avoid the 'bind: address in use' error).
eb8198e9f1b0 comment
Claus Gittinger <cg@exept.de>
parents: 421
diff changeset
  2212
    "
28
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  2213
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  2214
    filePointer isNil ifTrue:[
789
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2215
	^ self errorNotOpen
28
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  2216
    ].
0
1cf8d1747859 Initial revision
claus
parents:
diff changeset
  2217
%{
418
317e55c6c281 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 403
diff changeset
  2218
#ifndef NO_SOCKET
217
fcfbc9f71048 underscore cleanup
Claus Gittinger <cg@exept.de>
parents: 209
diff changeset
  2219
    OBJ t = __INST(filePointer);
71
claus
parents: 63
diff changeset
  2220
    OBJ myDomain;
28
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  2221
    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
  2222
    union {
525
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  2223
# ifdef AF_INET
789
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2224
	struct sockaddr_in in;
525
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  2225
# endif
530
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  2226
# ifdef AF_INET6
789
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2227
	struct sockaddr_in6 in6;
530
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  2228
# endif
524
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  2229
# ifdef AF_UNIX
789
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2230
	struct sockaddr_un un;
525
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  2231
# endif
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  2232
# ifdef AF_APPLETALK
789
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2233
	struct sockaddr_at at;
525
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  2234
# endif
116
7789fb1c9fa2 more UD socket fixes (at least client side seems to work now)
Claus Gittinger <cg@exept.de>
parents: 115
diff changeset
  2235
    } sa;
7789fb1c9fa2 more UD socket fixes (at least client side seems to work now)
Claus Gittinger <cg@exept.de>
parents: 115
diff changeset
  2236
    int sockaddr_size;
6
claus
parents: 4
diff changeset
  2237
    int ret;
25
996051271ce9 *** empty log message ***
claus
parents: 21
diff changeset
  2238
    int on = 1;
28
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  2239
    int ok;
0
1cf8d1747859 Initial revision
claus
parents:
diff changeset
  2240
217
fcfbc9f71048 underscore cleanup
Claus Gittinger <cg@exept.de>
parents: 209
diff changeset
  2241
    if (!__isString(__INST(domain)) && !__isSymbol(__INST(domain))) {
789
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2242
	DBGPRINTF(("SOCKET: invalid domain arg\n"));
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2243
	RETURN (false);
28
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  2244
    }
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  2245
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  2246
    ok = 0;
217
fcfbc9f71048 underscore cleanup
Claus Gittinger <cg@exept.de>
parents: 209
diff changeset
  2247
    myDomain = __INST(domain);
525
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  2248
506
11ef93d12870 support anonymous (OS_specified) ports. (for FTP-protocol)
Claus Gittinger <cg@exept.de>
parents: 486
diff changeset
  2249
# ifdef AF_INET
71
claus
parents: 63
diff changeset
  2250
    if (myDomain == @symbol(inet)) {
789
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2251
	/*
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2252
	 * INET addresses - port must be a smallinteger or nil
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2253
	 */
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2254
	sa.in.sin_family = AF_INET;
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2255
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2256
	if (portNrOrName == nil) {
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2257
	    sa.in.sin_port = 0;
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2258
	} else {
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2259
	    if (! __isSmallInteger(portNrOrName)) {
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2260
		DBGPRINTF(("SOCKET: invalid port arg\n"));
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2261
		RETURN (false);
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2262
	    }
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2263
	    sa.in.sin_port = htons((u_short) _intVal(portNrOrName));
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2264
	}
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2265
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2266
	/*
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2267
	 * INET addresses - addr must be nil, integer or byteArray
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2268
	 */
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2269
	if (address == nil) {
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2270
	    sa.in.sin_addr.s_addr = htonl(INADDR_ANY);
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2271
	} else {
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2272
	    if (__isInteger(address)) {
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2273
		sa.in.sin_addr.s_addr = htonl(__longIntVal(address));
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2274
	    } else {
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2275
		if (__isByteArray(address)) {
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2276
		    unsigned char *cp;
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2277
		    int n;
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2278
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2279
		    cp = __ByteArrayInstPtr(address)->ba_element;
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2280
		    n = __byteArraySize(address);
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2281
		    if (n > 4) n = 4;
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2282
		    bcopy(cp, &sa.in.sin_addr.s_addr, n);
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2283
		} else {
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2284
		    unsigned addr;
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2285
		    struct hostent *hp ;
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2286
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2287
		    if (! __isString(address)) {
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2288
			DBGPRINTF(("SOCKET: invalid address arg in bind\n"));
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2289
			RETURN (false);
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2290
		    }
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2291
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2292
		    if ((addr = inet_addr(__stringVal(address))) != -1) {
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2293
			/* 
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2294
			 * is Internet addr in octet notation 
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2295
			 */
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2296
			bcopy(&addr, (char *) &sa.in.sin_addr, sizeof(addr)) ; /* set address */
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2297
		    } else {
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2298
			/* 
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2299
			 * do we know the host's address? 
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2300
			 */
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2301
			GETHOSTBYNAME(hp, __stringVal(address))
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2302
			if (hp == NULL) {
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2303
			    DBGPRINTF(("SOCKET: unknown host:%s\n", __stringVal(address)));
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2304
			    RETURN (false);
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2305
			}
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2306
			bcopy(hp->h_addr, (char *) &sa.in.sin_addr, hp->h_length) ;
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2307
			sa.in.sin_family = hp->h_addrtype;
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2308
		    }
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2309
		}
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2310
	    }
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2311
	}
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2312
	DBGPRINTF(("SOCKET: bind addr: %x port: %x\n", sa.in.sin_addr.s_addr, sa.in.sin_port));
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2313
	sockaddr_size = sizeof(struct sockaddr_in);
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2314
	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
  2315
    }
530
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  2316
# endif /* AF_INET */
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  2317
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  2318
# ifdef AF_INET6
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  2319
    if (myDomain == @symbol(inet6)) {
789
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2320
	/*
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2321
	 * INET6 addresses - port must be a smallinteger or nil
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2322
	 */
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2323
	sa.in6.sin6_family = AF_INET6;
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2324
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2325
	if (portNrOrName == nil) {
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2326
	    sa.in6.sin6_port = 0;
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2327
	} else {
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2328
	    if (! __isSmallInteger(portNrOrName)) {
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2329
		DBGPRINTF(("SOCKET: invalid port arg\n"));
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2330
		RETURN (false);
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2331
	    }
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2332
	    sa.in6.sin6_port = htons((u_short) _intVal(portNrOrName));
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2333
	}
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2334
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2335
	/*
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2336
	 * INET6 addresses - addr must be nil or byteArray or string
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2337
	 */
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2338
	if (address == nil) {
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2339
	    sa.in6.sin6_addr.s6_addr[0] = 0;
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2340
	    sa.in6.sin6_addr.s6_addr[1] = 0;
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2341
	    sa.in6.sin6_addr.s6_addr[2] = 0;
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2342
	    sa.in6.sin6_addr.s6_addr[3] = 0;
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2343
	    sa.in6.sin6_addr.s6_addr[4] = 0;
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2344
	    sa.in6.sin6_addr.s6_addr[5] = 0;
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2345
	} else {
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2346
	    if (__isByteArray(address)) {
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2347
		unsigned char *cp;
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2348
		int n;
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2349
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2350
		cp = __ByteArrayInstPtr(address)->ba_element;
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2351
		n = __byteArraySize(address);
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2352
		if (n > 6) n = 6;
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2353
		bcopy(cp, &sa.in6.sin6_addr.s6_addr, n);
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2354
	    } else {
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2355
		unsigned addr;
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2356
		struct hostent *hp ;
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2357
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2358
		if (! __isString(address)) {
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2359
		    DBGPRINTF(("SOCKET: invalid address arg in bind\n"));
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2360
		    RETURN (false);
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2361
		}
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2362
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2363
		/* 
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2364
		 * do we know the host's address? 
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2365
		 */
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2366
		GETHOSTBYNAME(hp, __stringVal(address))
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2367
		if (hp == NULL) {
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2368
		    DBGPRINTF(("SOCKET: unknown host:%s\n", __stringVal(address)));
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2369
		    RETURN (false);
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2370
		}
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2371
		bcopy(hp->h_addr, (char *) &sa.in6.sin6_addr, hp->h_length) ;
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2372
		sa.in.sin_family = hp->h_addrtype;
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2373
	    }
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2374
	}
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2375
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2376
	DBGPRINTF(("SOCKET: bind addr: %x.%x.%x.%x.%x.%x port: %x\n", 
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2377
			sa.in6.sin6_addr.s6_addr[0], 
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2378
			sa.in6.sin6_addr.s6_addr[1], 
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2379
			sa.in6.sin6_addr.s6_addr[2], 
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2380
			sa.in6.sin6_addr.s6_addr[3], 
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2381
			sa.in6.sin6_addr.s6_addr[4], 
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2382
			sa.in6.sin6_addr.s6_addr[5], 
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2383
			sa.in6.sin6_port));
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2384
	sockaddr_size = sizeof(struct sockaddr_in6);
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2385
	ok = 1;
530
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
# endif /* AF_INET6 */
525
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  2388
506
11ef93d12870 support anonymous (OS_specified) ports. (for FTP-protocol)
Claus Gittinger <cg@exept.de>
parents: 486
diff changeset
  2389
# ifdef AF_UNIX
525
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  2390
    /*
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  2391
     * UNIX domain - port is ignored; address must be a string (path)
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  2392
     */
116
7789fb1c9fa2 more UD socket fixes (at least client side seems to work now)
Claus Gittinger <cg@exept.de>
parents: 115
diff changeset
  2393
    if (myDomain == @symbol(unix)) {
789
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2394
	char *pathName;
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2395
	int l;
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2396
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2397
	if (! __isString(portNrOrName)) {
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2398
	    DBGPRINTF(("SOCKET: invalid port (pathname) arg\n"));
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2399
	    RETURN (false);
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2400
	}
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2401
	pathName = (char *)__stringVal(portNrOrName);
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2402
	l = strlen(pathName);
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2403
	if ((l + sizeof ( sa.un.sun_family )) > sizeof(struct sockaddr_un)) {
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2404
	    DBGPRINTF(("SOCKET: pathname too long\n"));
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2405
	    RETURN (false);
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2406
	}
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2407
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2408
	strcpy(sa.un.sun_path, pathName);
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2409
	sa.un.sun_family = AF_UNIX;
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2410
	sockaddr_size = l + sizeof ( sa.un.sun_family );
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2411
	ok = 1;
28
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  2412
    }
530
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  2413
# endif /* AF_UNIX */
525
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  2414
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  2415
# ifdef AF_APPLETALK
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  2416
    /*
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  2417
     * this has never been tested ....
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  2418
     */
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  2419
    if (myDomain == @symbol(appletalk)) {
789
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2420
	/*
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2421
	 * APPLETALK addresses - port must be a smallinteger or nil
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2422
	 */
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2423
	sa.at.sat_family = AF_APPLETALK;
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2424
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2425
	if (portNrOrName == nil) {
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2426
	    sa.at.sat_port = 0;
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2427
	} else {
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2428
	    if (! __isSmallInteger(portNrOrName)) {
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2429
		DBGPRINTF(("SOCKET: invalid port arg\n"));
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2430
		RETURN (false);
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2431
	    }
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2432
	    sa.at.sat_port = __intVal(portNrOrName);
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2433
	}
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2434
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2435
	/*
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2436
	 * APPLETALK addresses - addr must be nil, integer or byteArray
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2437
	 * if integer, the low 8 bits are the node, the next higher 16
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2438
	 * bit are the net.
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2439
	 */
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2440
	if (address == nil) {
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2441
	    sa.at.sat_addr.s_net = ATADDR_ANYNET;
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2442
	    sa.at.sat_addr.s_node = ATADDR_ANYNODE;
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2443
	} else {
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2444
	    if (__isInteger(address)) {
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2445
		unsigned a = __longIntVal(address);
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2446
		sa.at.sat_addr.s_net = htons((a >> 8) & 0xFFFF);
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2447
		sa.at.sat_addr.s_node = htons(a & 0xFF);
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2448
	    } else {
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2449
		if (__isByteArray(address)) {
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2450
		    unsigned char *cp;
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2451
		    int n;
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2452
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2453
		    cp = __ByteArrayInstPtr(address)->ba_element;
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2454
		    n = __byteArraySize(address);
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2455
		    if (n > 3) n = 3;
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2456
		    bcopy(cp, &sa.at.sat_addr, n);
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2457
		} else {
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2458
		    unsigned addr;
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2459
		    struct hostent *hp ;
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2460
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2461
		    if (! __isString(address)) {
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2462
			DBGPRINTF(("SOCKET: invalid address arg in bind\n"));
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2463
			RETURN (false);
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2464
		    }
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2465
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2466
		    /* 
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2467
		     * do we know the host's address? 
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2468
		     */
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2469
		    GETHOSTBYNAME(hp, __stringVal(address))
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2470
		    if (hp == NULL) {
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2471
			DBGPRINTF(("SOCKET: unknown host: %s\n", __stringVal(address)));
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2472
			RETURN (false);
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2473
		    }
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2474
		    if (hp->h_addrtype != AF_APPLETALK) {
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2475
			DBGPRINTF(("SOCKET: host:%s is not an appletalk host\n", __stringVal(address)));
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2476
			RETURN (false);
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2477
		    }
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2478
		    bcopy(hp->h_addr, (char *) &sa.at.sat_addr, hp->h_length) ;
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2479
		    sa.at.sat_family = hp->h_addrtype;
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2480
		}
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2481
	    }
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2482
	}
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2483
	DBGPRINTF(("SOCKET: bind addr: %x port: %x\n", sa.in.sin_addr.s_addr, sa.in.sin_port));
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2484
	sockaddr_size = sizeof(struct sockaddr_at);
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2485
	ok = 1;
525
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  2486
    }
530
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  2487
# endif /* AF_APPLETALK */
525
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  2488
28
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  2489
    /*
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  2490
     * XXXX add addressing stuff for other domains here ...
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  2491
     */
506
11ef93d12870 support anonymous (OS_specified) ports. (for FTP-protocol)
Claus Gittinger <cg@exept.de>
parents: 486
diff changeset
  2492
# ifdef AF_X25
71
claus
parents: 63
diff changeset
  2493
    if (myDomain == @symbol(x25)) {
28
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  2494
    }
506
11ef93d12870 support anonymous (OS_specified) ports. (for FTP-protocol)
Claus Gittinger <cg@exept.de>
parents: 486
diff changeset
  2495
# endif
11ef93d12870 support anonymous (OS_specified) ports. (for FTP-protocol)
Claus Gittinger <cg@exept.de>
parents: 486
diff changeset
  2496
# ifdef AF_NS
71
claus
parents: 63
diff changeset
  2497
    if (myDomain == @symbol(ns)) {
28
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  2498
    }
506
11ef93d12870 support anonymous (OS_specified) ports. (for FTP-protocol)
Claus Gittinger <cg@exept.de>
parents: 486
diff changeset
  2499
# endif
524
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  2500
# ifdef AF_DECnet
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  2501
    if (myDomain == @symbol(decnet)) {
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  2502
    }
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  2503
# endif
506
11ef93d12870 support anonymous (OS_specified) ports. (for FTP-protocol)
Claus Gittinger <cg@exept.de>
parents: 486
diff changeset
  2504
# ifdef AF_SNA
93
Claus Gittinger <cg@exept.de>
parents: 92
diff changeset
  2505
    if (myDomain == @symbol(sna)) {
Claus Gittinger <cg@exept.de>
parents: 92
diff changeset
  2506
    }
506
11ef93d12870 support anonymous (OS_specified) ports. (for FTP-protocol)
Claus Gittinger <cg@exept.de>
parents: 486
diff changeset
  2507
# endif
11ef93d12870 support anonymous (OS_specified) ports. (for FTP-protocol)
Claus Gittinger <cg@exept.de>
parents: 486
diff changeset
  2508
# ifdef AF_NS
93
Claus Gittinger <cg@exept.de>
parents: 92
diff changeset
  2509
    if (myDomain == @symbol(xns)) {
Claus Gittinger <cg@exept.de>
parents: 92
diff changeset
  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_RAW
93
Claus Gittinger <cg@exept.de>
parents: 92
diff changeset
  2513
    if (myDomain == @symbol(raw)) {
Claus Gittinger <cg@exept.de>
parents: 92
diff changeset
  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_ISO
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  2517
    if (myDomain == @symbol(iso)) {
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
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  2520
# ifdef AF_NETBIOS
530
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  2521
    if (myDomain == @symbol(netbios)) {
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  2522
    }
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  2523
# endif
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  2524
# ifdef AF_IPX
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  2525
    if (myDomain == @symbol(ipx)) {
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  2526
    }
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  2527
# endif
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  2528
# ifdef AF_BRIDGE
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  2529
    if (myDomain == @symbol(bridge)) {
524
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  2530
    }
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  2531
# endif
571
191b37534643 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 563
diff changeset
  2532
# ifdef AF_BSC
191b37534643 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 563
diff changeset
  2533
    if (myDomain == @symbol(bsc)) {
191b37534643 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 563
diff changeset
  2534
    }
191b37534643 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 563
diff changeset
  2535
# endif
524
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  2536
# if defined(AF_CCITT) && (AF_CCITT != AF_X25)
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  2537
    if (myDomain == @symbol(ccitt)) {
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  2538
    }
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  2539
# endif
0
1cf8d1747859 Initial revision
claus
parents:
diff changeset
  2540
28
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  2541
    if (! ok) {
789
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2542
	DBGPRINTF(("SOCKET: unsupported domain\n"));
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2543
	RETURN (false);
28
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  2544
    }
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  2545
110
7af19ae8693b use new FILE* wrapper macros (based on externalAddress)
Claus Gittinger <cg@exept.de>
parents: 106
diff changeset
  2546
    sock = fileno(__FILEVal(t));
28
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  2547
506
11ef93d12870 support anonymous (OS_specified) ports. (for FTP-protocol)
Claus Gittinger <cg@exept.de>
parents: 486
diff changeset
  2548
# 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
  2549
    if (reuse == true) {
789
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2550
	if (setsockopt(sock, SOL_SOCKET, SO_REUSEADDR, (char *) &on, sizeof (on)) < 0) {
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2551
	    DBGPRINTF(("SOCKET: setsockopt - SO_REUSEADDR failed\n"));
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2552
	}
28
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  2553
    }
506
11ef93d12870 support anonymous (OS_specified) ports. (for FTP-protocol)
Claus Gittinger <cg@exept.de>
parents: 486
diff changeset
  2554
# endif /* SO_REUSEADDR */
28
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  2555
117
03cefad7e40b UD socket example & interruptable bind
Claus Gittinger <cg@exept.de>
parents: 116
diff changeset
  2556
    __BEGIN_INTERRUPTABLE__
28
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  2557
    do {
789
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2558
	ret = bind(sock, (struct sockaddr *)&sa, sockaddr_size);
28
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  2559
    } while ((ret < 0) && (errno == EINTR));
117
03cefad7e40b UD socket example & interruptable bind
Claus Gittinger <cg@exept.de>
parents: 116
diff changeset
  2560
    __END_INTERRUPTABLE__
28
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  2561
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  2562
    if (ret < 0) {
789
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2563
	DBGPRINTF(("SOCKET: bind failed errno=%d\n", errno));
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2564
	__INST(lastErrorNumber) = __MKSMALLINT(errno);
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2565
	RETURN (false);
0
1cf8d1747859 Initial revision
claus
parents:
diff changeset
  2566
    }
506
11ef93d12870 support anonymous (OS_specified) ports. (for FTP-protocol)
Claus Gittinger <cg@exept.de>
parents: 486
diff changeset
  2567
11ef93d12870 support anonymous (OS_specified) ports. (for FTP-protocol)
Claus Gittinger <cg@exept.de>
parents: 486
diff changeset
  2568
    __INST(port) = portNrOrName; __STORE(self, portNrOrName);
11ef93d12870 support anonymous (OS_specified) ports. (for FTP-protocol)
Claus Gittinger <cg@exept.de>
parents: 486
diff changeset
  2569
11ef93d12870 support anonymous (OS_specified) ports. (for FTP-protocol)
Claus Gittinger <cg@exept.de>
parents: 486
diff changeset
  2570
# ifdef AF_INET
11ef93d12870 support anonymous (OS_specified) ports. (for FTP-protocol)
Claus Gittinger <cg@exept.de>
parents: 486
diff changeset
  2571
    if (myDomain == @symbol(inet)) {
789
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2572
	if (! __isSmallInteger(portNrOrName)
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2573
	 || (portNrOrName == __MKSMALLINT(0))) {
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2574
	    int p;
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2575
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2576
	    /*
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2577
	     * INET anonymous port - get the actual portNr
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2578
	     */
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2579
	    if (getsockname(sock, (struct sockaddr *)&sa, &sockaddr_size) < 0) {
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2580
		DBGPRINTF(("SOCKET: cannot get peername\n"));
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2581
	    } else {
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2582
		DBGPRINTF(("SOCKET: anon port=%x\n", sa.in.sin_port));
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2583
		p = ntohs(sa.in.sin_port);
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2584
		__INST(port) = __MKSMALLINT(p);
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2585
	    }
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2586
	}
506
11ef93d12870 support anonymous (OS_specified) ports. (for FTP-protocol)
Claus Gittinger <cg@exept.de>
parents: 486
diff changeset
  2587
    }
11ef93d12870 support anonymous (OS_specified) ports. (for FTP-protocol)
Claus Gittinger <cg@exept.de>
parents: 486
diff changeset
  2588
# endif
530
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  2589
# ifdef AF_INET6
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  2590
    if (myDomain == @symbol(inet6)) {
789
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2591
	if (! __isSmallInteger(portNrOrName)
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2592
	 || (portNrOrName == __MKSMALLINT(0))) {
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2593
	    int p;
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2594
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2595
	    /*
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2596
	     * INET6 anonymous port - get the actual portNr
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2597
	     */
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2598
	    if (getsockname(sock, (struct sockaddr *)&sa, &sockaddr_size) < 0) {
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2599
		DBGPRINTF(("SOCKET: cannot get peername\n"));
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2600
	    } else {
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2601
		DBGPRINTF(("SOCKET: anon port=%x\n", sa.in.sin_port));
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2602
		p = ntohs(sa.in6.sin6_port);
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2603
		__INST(port) = __MKSMALLINT(p);
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2604
	    }
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2605
	}
530
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  2606
    }
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  2607
# endif
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  2608
# ifdef AF_APPLETALK
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  2609
    if (myDomain == @symbol(appletalk)) {
789
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2610
	if (! __isSmallInteger(portNrOrName)
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2611
	 || (portNrOrName == __MKSMALLINT(0))) {
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2612
	    int p;
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2613
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2614
	    /*
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2615
	     * APPLETALK anonymous port - get the actual portNr
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2616
	     */
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2617
	    if (getsockname(sock, (struct sockaddr *)&sa, &sockaddr_size) < 0) {
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2618
		DBGPRINTF(("SOCKET: cannot get peername\n"));
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2619
	    } else {
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2620
		DBGPRINTF(("SOCKET: anon port=%x\n", sa.in.sin_port));
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2621
		p = sa.at.sat_port;
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2622
		__INST(port) = __MKSMALLINT(p);
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2623
	    }
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2624
	}
530
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  2625
    }
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  2626
# endif
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  2627
506
11ef93d12870 support anonymous (OS_specified) ports. (for FTP-protocol)
Claus Gittinger <cg@exept.de>
parents: 486
diff changeset
  2628
#else /* NO_SOCKET */
418
317e55c6c281 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 403
diff changeset
  2629
    RETURN (false);
506
11ef93d12870 support anonymous (OS_specified) ports. (for FTP-protocol)
Claus Gittinger <cg@exept.de>
parents: 486
diff changeset
  2630
#endif /* NO_SOCKET */
42
506596f9a1a8 *** empty log message ***
claus
parents: 38
diff changeset
  2631
%}.
28
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  2632
    ^ true
0
1cf8d1747859 Initial revision
claus
parents:
diff changeset
  2633
28
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  2634
    "
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  2635
     (Socket domain:#inet type:#stream)
789
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2636
	 bindTo:9999
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2637
	 address:nil
28
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  2638
    "
0
1cf8d1747859 Initial revision
claus
parents:
diff changeset
  2639
!
1cf8d1747859 Initial revision
claus
parents:
diff changeset
  2640
781
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  2641
closeFile
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  2642
    "low level close"
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  2643
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  2644
%{  /* NOCONTEXT */
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  2645
#ifndef NO_SOCKET
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  2646
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  2647
    OBJ t;
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  2648
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  2649
    t = __INST(filePointer);
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  2650
    if (t != nil) {
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  2651
	FILE *fp;
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  2652
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  2653
	fp = __FILEVal(t);
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  2654
	fflush(fp);
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  2655
	shutdown(fileno(fp), 2);
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  2656
	fclose(fp);
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  2657
	__INST(filePointer) = nil;
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  2658
    }
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  2659
#endif
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  2660
%}
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  2661
!
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  2662
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  2663
listenFor:aNumber
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  2664
    "same as listenWithBacklog: - for ST-80 compatibility"
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  2665
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  2666
    ^ self listenWithBacklog:aNumber
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  2667
!
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  2668
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  2669
listenWithBacklog:aNumber
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  2670
    "start listening; return true if ok, false on error"
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  2671
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  2672
    filePointer isNil ifTrue:[
789
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2673
	^ self errorNotOpen
781
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  2674
    ].
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  2675
%{
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  2676
#ifndef NO_SOCKET
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  2677
    OBJ fp = __INST(filePointer);
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  2678
    int sock;
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  2679
    int ret;
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  2680
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  2681
    if (! __isSmallInteger(aNumber)) {
789
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2682
	DBGPRINTF(("SOCKET: invalid arg\n"));
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2683
	RETURN (false);
781
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  2684
    }
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  2685
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  2686
    sock = fileno(__FILEVal(fp));
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  2687
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  2688
    __BEGIN_INTERRUPTABLE__
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  2689
    do {
789
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2690
	ret = listen(sock, _intVal(aNumber));
781
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  2691
    } while ((ret < 0) && (errno == EINTR));
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  2692
    __END_INTERRUPTABLE__
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  2693
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  2694
    if (ret < 0) {
789
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2695
	DBGPRINTF(("SOCKET: listen call failed errno=%d\n", errno));
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2696
	__INST(lastErrorNumber) = __MKSMALLINT(errno);
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2697
	RETURN (false);
781
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  2698
    }
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  2699
#else
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  2700
    RETURN (false);
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  2701
#endif
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  2702
%}.
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  2703
    ^ true
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  2704
!
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  2705
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  2706
shutDown 
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  2707
    "shutDown without flushing "
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  2708
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  2709
    filePointer isNil ifTrue:[^ self].
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  2710
    Lobby unregister:self.
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  2711
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  2712
%{
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  2713
#ifndef NO_SOCKET
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  2714
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  2715
    OBJ fp;
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  2716
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  2717
    fp = __INST(filePointer);
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  2718
    if (fp != nil) {
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  2719
	FILE *f;
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  2720
	int fd;
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  2721
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  2722
	__INST(filePointer) = nil;
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  2723
	f = __FILEVal(fp);
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  2724
	fd = fileno(f);
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  2725
	__BEGIN_INTERRUPTABLE__
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  2726
	shutdown(fd, 2);
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  2727
	close(fd);
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  2728
	__END_INTERRUPTABLE__
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  2729
    }
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  2730
#endif
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  2731
%}
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  2732
! !
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  2733
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  2734
!Socket methodsFor:'low level-accepting'!
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  2735
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  2736
accept
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  2737
    "create a new TCP socket from accepting on the receiver.
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  2738
     This method will suspend the current process if no connection is waiting.
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  2739
     For ST-80 compatibility"
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  2740
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  2741
    |newSock|
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  2742
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  2743
    newSock := self class new.
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  2744
    (newSock acceptOn:self) ifFalse:[^ nil].
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  2745
    ^ newSock
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  2746
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  2747
    "
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  2748
     |sock newSock|
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  2749
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  2750
     sock := Socket provide:8004.
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  2751
     sock listenFor:5.
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  2752
     newSock := sock accept.
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  2753
    "
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  2754
!
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  2755
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  2756
acceptOn:aSocket
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  2757
    "accept a connection on a server port (created with:'Socket>>onIPPort:')
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  2758
     usage is: (Socket basicNew acceptOn:(Socket onIPPort:9999)).
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  2759
     This method will suspend the current process if no connection is waiting.
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  2760
     Return the true if ok; false if not."
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  2761
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  2762
    aSocket readWriteWait.
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  2763
    ^ self blockingAcceptOn:aSocket
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  2764
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  2765
    "Modified: / 11.3.1996 / 14:21:31 / stefan"
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  2766
    "Modified: / 1.8.1998 / 23:39:10 / cg"
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  2767
!
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  2768
208
c3eca2cc16dc accept: do not wait for input on non-connected socket.
Stefan Vogel <sv@exept.de>
parents: 207
diff changeset
  2769
blockingAcceptOn:aSocket
c3eca2cc16dc accept: do not wait for input on non-connected socket.
Stefan Vogel <sv@exept.de>
parents: 207
diff changeset
  2770
    "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
  2771
     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
  2772
     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
  2773
c3eca2cc16dc accept: do not wait for input on non-connected socket.
Stefan Vogel <sv@exept.de>
parents: 207
diff changeset
  2774
     NOTICE: this method will block, if no connection is already pending.
789
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2775
	     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
  2776
c3eca2cc16dc accept: do not wait for input on non-connected socket.
Stefan Vogel <sv@exept.de>
parents: 207
diff changeset
  2777
    |serverSocketFd|
c3eca2cc16dc accept: do not wait for input on non-connected socket.
Stefan Vogel <sv@exept.de>
parents: 207
diff changeset
  2778
c3eca2cc16dc accept: do not wait for input on non-connected socket.
Stefan Vogel <sv@exept.de>
parents: 207
diff changeset
  2779
    filePointer notNil ifTrue:[
789
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2780
	^ self errorAlreadyOpen
208
c3eca2cc16dc accept: do not wait for input on non-connected socket.
Stefan Vogel <sv@exept.de>
parents: 207
diff changeset
  2781
    ].
c3eca2cc16dc accept: do not wait for input on non-connected socket.
Stefan Vogel <sv@exept.de>
parents: 207
diff changeset
  2782
c3eca2cc16dc accept: do not wait for input on non-connected socket.
Stefan Vogel <sv@exept.de>
parents: 207
diff changeset
  2783
    domain := aSocket domain.
c3eca2cc16dc accept: do not wait for input on non-connected socket.
Stefan Vogel <sv@exept.de>
parents: 207
diff changeset
  2784
    socketType := aSocket type.
c3eca2cc16dc accept: do not wait for input on non-connected socket.
Stefan Vogel <sv@exept.de>
parents: 207
diff changeset
  2785
    serverSocketFd := aSocket fileDescriptor.
c3eca2cc16dc accept: do not wait for input on non-connected socket.
Stefan Vogel <sv@exept.de>
parents: 207
diff changeset
  2786
    serverSocketFd isNil ifTrue:[
789
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2787
	^ 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
  2788
    ].
c3eca2cc16dc accept: do not wait for input on non-connected socket.
Stefan Vogel <sv@exept.de>
parents: 207
diff changeset
  2789
    (serverSocketFd isMemberOf:SmallInteger) ifFalse:[
789
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2790
	^ 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
  2791
    ].
c3eca2cc16dc accept: do not wait for input on non-connected socket.
Stefan Vogel <sv@exept.de>
parents: 207
diff changeset
  2792
%{
418
317e55c6c281 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 403
diff changeset
  2793
#ifndef NO_SOCKET
208
c3eca2cc16dc accept: do not wait for input on non-connected socket.
Stefan Vogel <sv@exept.de>
parents: 207
diff changeset
  2794
    FILE *fp;
c3eca2cc16dc accept: do not wait for input on non-connected socket.
Stefan Vogel <sv@exept.de>
parents: 207
diff changeset
  2795
    int flags;
c3eca2cc16dc accept: do not wait for input on non-connected socket.
Stefan Vogel <sv@exept.de>
parents: 207
diff changeset
  2796
    int sock, newSock;
c3eca2cc16dc accept: do not wait for input on non-connected socket.
Stefan Vogel <sv@exept.de>
parents: 207
diff changeset
  2797
    union {
525
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  2798
#ifdef AF_INET
789
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2799
	struct sockaddr_in in;
525
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  2800
#endif
530
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  2801
# ifdef AF_INET6
789
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2802
	struct sockaddr_in6 in6;
530
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  2803
# endif
524
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  2804
# ifdef AF_UNIX
789
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2805
	struct sockaddr_un un;
525
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  2806
# endif
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  2807
# ifdef AF_APPLETALK
789
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2808
	struct sockaddr_at at;
524
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  2809
# endif
208
c3eca2cc16dc accept: do not wait for input on non-connected socket.
Stefan Vogel <sv@exept.de>
parents: 207
diff changeset
  2810
    } sa;
464
600b101a7035 alen in accept
Claus Gittinger <cg@exept.de>
parents: 463
diff changeset
  2811
    int alen, alen0;
208
c3eca2cc16dc accept: do not wait for input on non-connected socket.
Stefan Vogel <sv@exept.de>
parents: 207
diff changeset
  2812
    struct hostent *he ;
c3eca2cc16dc accept: do not wait for input on non-connected socket.
Stefan Vogel <sv@exept.de>
parents: 207
diff changeset
  2813
    char dotted[20] ;
c3eca2cc16dc accept: do not wait for input on non-connected socket.
Stefan Vogel <sv@exept.de>
parents: 207
diff changeset
  2814
c3eca2cc16dc accept: do not wait for input on non-connected socket.
Stefan Vogel <sv@exept.de>
parents: 207
diff changeset
  2815
    sock = _intVal(serverSocketFd);
c3eca2cc16dc accept: do not wait for input on non-connected socket.
Stefan Vogel <sv@exept.de>
parents: 207
diff changeset
  2816
c3eca2cc16dc accept: do not wait for input on non-connected socket.
Stefan Vogel <sv@exept.de>
parents: 207
diff changeset
  2817
#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
  2818
    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
  2819
    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
  2820
#endif
464
600b101a7035 alen in accept
Claus Gittinger <cg@exept.de>
parents: 463
diff changeset
  2821
600b101a7035 alen in accept
Claus Gittinger <cg@exept.de>
parents: 463
diff changeset
  2822
#ifdef AF_INET
600b101a7035 alen in accept
Claus Gittinger <cg@exept.de>
parents: 463
diff changeset
  2823
    if (__INST(domain) == @symbol(inet)) {
789
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2824
	alen0 = sizeof(sa.in);
464
600b101a7035 alen in accept
Claus Gittinger <cg@exept.de>
parents: 463
diff changeset
  2825
    }
600b101a7035 alen in accept
Claus Gittinger <cg@exept.de>
parents: 463
diff changeset
  2826
#endif
530
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  2827
#ifdef AF_INET6
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  2828
    if (__INST(domain) == @symbol(inet6)) {
789
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2829
	alen0 = sizeof(sa.in6);
530
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  2830
    }
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  2831
#endif
464
600b101a7035 alen in accept
Claus Gittinger <cg@exept.de>
parents: 463
diff changeset
  2832
#ifdef AF_UNIX
600b101a7035 alen in accept
Claus Gittinger <cg@exept.de>
parents: 463
diff changeset
  2833
    if (__INST(domain) == @symbol(unix)) {
789
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2834
	alen0 = sizeof(sa.un);
464
600b101a7035 alen in accept
Claus Gittinger <cg@exept.de>
parents: 463
diff changeset
  2835
    }
600b101a7035 alen in accept
Claus Gittinger <cg@exept.de>
parents: 463
diff changeset
  2836
#endif
530
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  2837
# ifdef AF_APPLETALK
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  2838
    if (__INST(domain) == @symbol(appletalk)) {
789
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2839
	alen0 = sizeof(sa.at);
530
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  2840
    }
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  2841
# endif
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  2842
524
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  2843
    /*
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  2844
     * XXXX add addressing stuff for other domains here ...
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  2845
     */
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  2846
# ifdef AF_X25
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  2847
    if (__INST(domain) == @symbol(x25)) {
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  2848
    }
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  2849
# endif
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  2850
# ifdef AF_NS
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  2851
    if (__INST(domain) == @symbol(ns)) {
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  2852
    }
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  2853
# endif
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  2854
# ifdef AF_DECnet
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  2855
    if (__INST(domain) == @symbol(decnet)) {
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  2856
    }
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  2857
# endif
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  2858
# ifdef AF_SNA
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  2859
    if (__INST(domain) == @symbol(sna)) {
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  2860
    }
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  2861
# endif
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  2862
# ifdef AF_NS
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  2863
    if (__INST(domain) == @symbol(xns)) {
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  2864
    }
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  2865
# endif
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  2866
# ifdef AF_RAW
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  2867
    if (__INST(domain) == @symbol(raw)) {
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  2868
    }
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  2869
# endif
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  2870
# ifdef AF_ISO
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  2871
    if (__INST(domain) == @symbol(iso)) {
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  2872
    }
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  2873
# endif
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  2874
# ifdef AF_NETBIOS
530
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  2875
    if (__INST(domain) == @symbol(netbios)) {
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  2876
    }
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  2877
# endif
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  2878
# ifdef AF_IPX
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  2879
    if (__INST(domain) == @symbol(ipx)) {
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  2880
    }
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  2881
# endif
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  2882
# ifdef AF_BRIDGE
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  2883
    if (__INST(domain) == @symbol(bridge)) {
524
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  2884
    }
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  2885
# endif
571
191b37534643 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 563
diff changeset
  2886
# ifdef AF_BSC
191b37534643 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 563
diff changeset
  2887
    if (__INST(domain) == @symbol(bsc)) {
191b37534643 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 563
diff changeset
  2888
    }
191b37534643 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 563
diff changeset
  2889
# endif
524
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  2890
# if defined(AF_CCITT) && (AF_CCITT != AF_X25)
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  2891
    if (__INST(domain) == @symbol(ccitt)) {
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  2892
    }
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  2893
# endif
464
600b101a7035 alen in accept
Claus Gittinger <cg@exept.de>
parents: 463
diff changeset
  2894
208
c3eca2cc16dc accept: do not wait for input on non-connected socket.
Stefan Vogel <sv@exept.de>
parents: 207
diff changeset
  2895
    __BEGIN_INTERRUPTABLE__
c3eca2cc16dc accept: do not wait for input on non-connected socket.
Stefan Vogel <sv@exept.de>
parents: 207
diff changeset
  2896
    do {
789
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2897
	alen = alen0;
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2898
	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
  2899
    } 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
  2900
    __END_INTERRUPTABLE__
c3eca2cc16dc accept: do not wait for input on non-connected socket.
Stefan Vogel <sv@exept.de>
parents: 207
diff changeset
  2901
c3eca2cc16dc accept: do not wait for input on non-connected socket.
Stefan Vogel <sv@exept.de>
parents: 207
diff changeset
  2902
#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
  2903
    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
  2904
#endif
c3eca2cc16dc accept: do not wait for input on non-connected socket.
Stefan Vogel <sv@exept.de>
parents: 207
diff changeset
  2905
c3eca2cc16dc accept: do not wait for input on non-connected socket.
Stefan Vogel <sv@exept.de>
parents: 207
diff changeset
  2906
    if (newSock < 0) {
789
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2907
	DBGPRINTF(("SOCKET: accept call failed errno=%d\n", errno));
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2908
	__INST(lastErrorNumber) = __MKSMALLINT(errno);
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2909
	RETURN (false);
208
c3eca2cc16dc accept: do not wait for input on non-connected socket.
Stefan Vogel <sv@exept.de>
parents: 207
diff changeset
  2910
    }
c3eca2cc16dc accept: do not wait for input on non-connected socket.
Stefan Vogel <sv@exept.de>
parents: 207
diff changeset
  2911
c3eca2cc16dc accept: do not wait for input on non-connected socket.
Stefan Vogel <sv@exept.de>
parents: 207
diff changeset
  2912
    /*
c3eca2cc16dc accept: do not wait for input on non-connected socket.
Stefan Vogel <sv@exept.de>
parents: 207
diff changeset
  2913
     * extract the partners address
c3eca2cc16dc accept: do not wait for input on non-connected socket.
Stefan Vogel <sv@exept.de>
parents: 207
diff changeset
  2914
     */
c3eca2cc16dc accept: do not wait for input on non-connected socket.
Stefan Vogel <sv@exept.de>
parents: 207
diff changeset
  2915
#ifdef AF_INET
217
fcfbc9f71048 underscore cleanup
Claus Gittinger <cg@exept.de>
parents: 209
diff changeset
  2916
    if (__INST(domain) == @symbol(inet)) {
789
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2917
	GETHOSTBYADDR(he, (char *) &sa.in.sin_addr.s_addr, alen, AF_INET);
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2918
	if (! he) {
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2919
	    unsigned long norder;
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2920
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2921
	    norder = htonl(sa.in.sin_addr.s_addr) ;
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2922
	    sprintf(dotted, "%d.%d.%d.%d",
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2923
		    (norder >> 24) & 0xFF,
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2924
		    (norder >> 16) & 0xFF,
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2925
		    (norder >> 8) & 0xFF,
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2926
		    norder & 0xFF);
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2927
	}
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2928
	DBGPRINTF(("SOCKET: accepted connection from host %s\n", (he ? he->h_name : dotted))) ;
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2929
	__INST(peerName) = __MKSTRING((he ? he->h_name : dotted));
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2930
	__STORESELF(peerName);
208
c3eca2cc16dc accept: do not wait for input on non-connected socket.
Stefan Vogel <sv@exept.de>
parents: 207
diff changeset
  2931
    }
c3eca2cc16dc accept: do not wait for input on non-connected socket.
Stefan Vogel <sv@exept.de>
parents: 207
diff changeset
  2932
#endif
530
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  2933
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  2934
#ifdef AF_INET6
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  2935
    if (__INST(domain) == @symbol(inet6)) {
789
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2936
	GETHOSTBYADDR(he, (char *) &sa.in6.sin6_addr.s6_addr, alen, AF_INET6);
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2937
	if (! he) {
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2938
	    unsigned long norder;
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2939
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2940
	    /*
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2941
	     * XXX: what is inet6's naming convention ?
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2942
	     */
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2943
	    norder = htonl(sa.in.sin_addr.s_addr) ;
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2944
	    sprintf(dotted, "%d.%d.%d.%d",
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2945
		    sa.in6.sin6_addr.s6_addr[0],
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2946
		    sa.in6.sin6_addr.s6_addr[1],
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2947
		    sa.in6.sin6_addr.s6_addr[2],
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2948
		    sa.in6.sin6_addr.s6_addr[3],
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2949
		    sa.in6.sin6_addr.s6_addr[4],
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2950
		    sa.in6.sin6_addr.s6_addr[5]);
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2951
	}
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2952
	DBGPRINTF(("SOCKET: accepted connection from host %s\n", (he ? he->h_name : dotted))) ;
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2953
	__INST(peerName) = __MKSTRING((he ? he->h_name : dotted));
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2954
	__STORESELF(peerName);
530
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  2955
    }
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  2956
#endif
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  2957
208
c3eca2cc16dc accept: do not wait for input on non-connected socket.
Stefan Vogel <sv@exept.de>
parents: 207
diff changeset
  2958
#ifdef AF_UNIX
217
fcfbc9f71048 underscore cleanup
Claus Gittinger <cg@exept.de>
parents: 209
diff changeset
  2959
    if (__INST(domain) == @symbol(unix)) {
789
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2960
	DBGPRINTF(("SOCKET: accepted connection on unix socket\n")) ;
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2961
	/* 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
  2962
    }
c3eca2cc16dc accept: do not wait for input on non-connected socket.
Stefan Vogel <sv@exept.de>
parents: 207
diff changeset
  2963
#endif
530
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  2964
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  2965
#ifdef AF_APPLETALK
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  2966
    if (__INST(domain) == @symbol(appletalk)) {
789
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2967
	GETHOSTBYADDR(he, (char *) &sa.at.sat_addr, alen, AF_APPLETALK);
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2968
	if (! he) {
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2969
	    unsigned net;
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2970
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2971
	    /*
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2972
	     * XXX: what is apples naming convention ?
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2973
	     */
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2974
	    net = htons(sa.at.sat_addr.s_net) ;
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2975
	    sprintf(dotted, "%d.%d",
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2976
		    net,
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2977
		    sa.at.sat_addr.s_node);
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2978
	}
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2979
	DBGPRINTF(("SOCKET: accepted connection from host %s\n", (he ? he->h_name : dotted))) ;
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2980
	__INST(peerName) = __MKSTRING((he ? he->h_name : dotted));
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2981
	__STORESELF(peerName);
530
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  2982
    }
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  2983
# endif
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  2984
524
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  2985
    /*
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  2986
     * XXXX add addressing stuff for other domains here ...
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  2987
     */
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  2988
# ifdef AF_X25
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  2989
    if (__INST(domain) == @symbol(x25)) {
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  2990
    }
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  2991
# endif
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  2992
# ifdef AF_NS
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  2993
    if (__INST(domain) == @symbol(ns)) {
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  2994
    }
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  2995
# endif
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  2996
# ifdef AF_DECnet
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  2997
    if (__INST(domain) == @symbol(decnet)) {
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  2998
    }
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  2999
# endif
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  3000
# ifdef AF_SNA
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  3001
    if (__INST(domain) == @symbol(sna)) {
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  3002
    }
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  3003
# endif
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  3004
# ifdef AF_NS
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  3005
    if (__INST(domain) == @symbol(xns)) {
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  3006
    }
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  3007
# endif
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  3008
# ifdef AF_RAW
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  3009
    if (__INST(domain) == @symbol(raw)) {
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  3010
    }
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  3011
# endif
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  3012
# ifdef AF_ISO
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  3013
    if (__INST(domain) == @symbol(iso)) {
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  3014
    }
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  3015
# endif
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  3016
# ifdef AF_NETBIOS
530
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  3017
    if (__INST(domain) == @symbol(netbios)) {
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  3018
    }
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  3019
# endif
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  3020
# ifdef AF_IPX
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  3021
    if (__INST(domain) == @symbol(ipx)) {
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  3022
    }
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  3023
# endif
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  3024
# ifdef AF_BRIDGE
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  3025
    if (__INST(domain) == @symbol(bridge)) {
524
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  3026
    }
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  3027
# endif
571
191b37534643 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 563
diff changeset
  3028
# ifdef AF_BSC
191b37534643 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 563
diff changeset
  3029
    if (__INST(domain) == @symbol(bsc)) {
191b37534643 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 563
diff changeset
  3030
    }
191b37534643 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 563
diff changeset
  3031
# endif
524
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  3032
# if defined(AF_CCITT) && (AF_CCITT != AF_X25)
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  3033
    if (__INST(domain) == @symbol(ccitt)) {
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  3034
    }
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  3035
# endif
208
c3eca2cc16dc accept: do not wait for input on non-connected socket.
Stefan Vogel <sv@exept.de>
parents: 207
diff changeset
  3036
c3eca2cc16dc accept: do not wait for input on non-connected socket.
Stefan Vogel <sv@exept.de>
parents: 207
diff changeset
  3037
    /* 
c3eca2cc16dc accept: do not wait for input on non-connected socket.
Stefan Vogel <sv@exept.de>
parents: 207
diff changeset
  3038
     * make it a FILE * 
c3eca2cc16dc accept: do not wait for input on non-connected socket.
Stefan Vogel <sv@exept.de>
parents: 207
diff changeset
  3039
     */
c3eca2cc16dc accept: do not wait for input on non-connected socket.
Stefan Vogel <sv@exept.de>
parents: 207
diff changeset
  3040
    fp = fdopen(newSock, "r+");
c3eca2cc16dc accept: do not wait for input on non-connected socket.
Stefan Vogel <sv@exept.de>
parents: 207
diff changeset
  3041
    if (! fp) {
789
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3042
	DBGPRINTF(("SOCKET: fdopen call failed\n"));
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3043
	__INST(lastErrorNumber) = __MKSMALLINT(errno);
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3044
	close(newSock);
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3045
	RETURN (false);
208
c3eca2cc16dc accept: do not wait for input on non-connected socket.
Stefan Vogel <sv@exept.de>
parents: 207
diff changeset
  3046
    } else {
444
9ba31a1fba38 always unbuffered on linux
Claus Gittinger <cg@exept.de>
parents: 430
diff changeset
  3047
#ifdef BUGGY_STDIO_LIB
789
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3048
	setbuf(fp, NULL);
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3049
	__INST(buffered) = false;
208
c3eca2cc16dc accept: do not wait for input on non-connected socket.
Stefan Vogel <sv@exept.de>
parents: 207
diff changeset
  3050
#endif
789
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3051
	__INST(filePointer) = __MKOBJ(fp);
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3052
	__STORESELF(filePointer);
208
c3eca2cc16dc accept: do not wait for input on non-connected socket.
Stefan Vogel <sv@exept.de>
parents: 207
diff changeset
  3053
    }
418
317e55c6c281 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 403
diff changeset
  3054
#endif
208
c3eca2cc16dc accept: do not wait for input on non-connected socket.
Stefan Vogel <sv@exept.de>
parents: 207
diff changeset
  3055
%}.
c3eca2cc16dc accept: do not wait for input on non-connected socket.
Stefan Vogel <sv@exept.de>
parents: 207
diff changeset
  3056
    mode := #readwrite.
c3eca2cc16dc accept: do not wait for input on non-connected socket.
Stefan Vogel <sv@exept.de>
parents: 207
diff changeset
  3057
    Lobby register:self.
c3eca2cc16dc accept: do not wait for input on non-connected socket.
Stefan Vogel <sv@exept.de>
parents: 207
diff changeset
  3058
    binary := false.
c3eca2cc16dc accept: do not wait for input on non-connected socket.
Stefan Vogel <sv@exept.de>
parents: 207
diff changeset
  3059
    port := aSocket port.
c3eca2cc16dc accept: do not wait for input on non-connected socket.
Stefan Vogel <sv@exept.de>
parents: 207
diff changeset
  3060
    ^ true
c3eca2cc16dc accept: do not wait for input on non-connected socket.
Stefan Vogel <sv@exept.de>
parents: 207
diff changeset
  3061
!
c3eca2cc16dc accept: do not wait for input on non-connected socket.
Stefan Vogel <sv@exept.de>
parents: 207
diff changeset
  3062
781
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  3063
waitForNewConnectionOrDataOnAny:otherConnections timeout:timeoutSeconds
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  3064
    "suspend the current process, until either a new connection comes
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  3065
     in at the receiver, or data arrives on any of the otherConnections.
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  3066
     For a new connection, an accept is performed and the new socket is returned.
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  3067
     For an old connection, that socket is returned.
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  3068
     In any case, the caller gets a socket to operate on as return value,
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  3069
     or nil, if a timeout occured.
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  3070
     This method implements the inner wait-primitive of a multi-connection 
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  3071
     server application."
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  3072
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  3073
    "/ first, a quick check if data is already available
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  3074
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  3075
    |connection wasBlocked sema|
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  3076
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  3077
    self canReadWithoutBlocking ifTrue:[
789
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3078
	^ self accept.
781
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  3079
    ].
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  3080
    otherConnections do:[:aConnection |
789
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3081
	aConnection canReadWithoutBlocking ifTrue:[
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3082
	    ^ aConnection
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3083
	]
781
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  3084
    ].
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  3085
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  3086
    [
789
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3087
	"/ check again - prevent incoming interrupts from disturbing our setup
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3088
	wasBlocked := OperatingSystem blockInterrupts.
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3089
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3090
	self canReadWithoutBlocking ifTrue:[
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3091
	    wasBlocked ifFalse:[OperatingSystem unblockInterrupts].
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3092
	    ^ self accept.
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3093
	].
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3094
	otherConnections do:[:aConnection |
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3095
	    aConnection canReadWithoutBlocking ifTrue:[
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3096
		wasBlocked ifFalse:[OperatingSystem unblockInterrupts].
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3097
		^ aConnection
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3098
	    ]
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3099
	].
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3100
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3101
	"/ nope - must wait.
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3102
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3103
	sema := Semaphore new name:'multiReadWait'.
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3104
	otherConnections do:[:aConnection |
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3105
	    Processor signal:sema onInput:(aConnection fileDescriptor).
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3106
	].
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3107
	Processor signal:sema onInput:(self fileDescriptor).
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3108
	timeoutSeconds notNil ifTrue:[
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3109
	    Processor signal:sema afterSeconds:timeoutSeconds 
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3110
	].
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3111
	Processor activeProcess state:#ioWait.
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3112
	sema wait.
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3113
	Processor disableSemaphore:sema.
781
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  3114
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  3115
    ] valueOnUnwindDo:[
789
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3116
	Processor disableSemaphore:sema.
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3117
	wasBlocked ifFalse:[OperatingSystem unblockInterrupts].
781
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  3118
    ].
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  3119
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  3120
    "/ see who it was ...
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  3121
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  3122
    self canReadWithoutBlocking ifTrue:[
789
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3123
	^ self accept.
781
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  3124
    ].
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  3125
    otherConnections do:[:aConnection |
789
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3126
	aConnection canReadWithoutBlocking ifTrue:[
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3127
	    ^ aConnection
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3128
	]
781
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  3129
    ].
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  3130
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  3131
    "/ none - a timeout
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  3132
    ^ nil
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  3133
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  3134
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  3135
! !
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  3136
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  3137
!Socket methodsFor:'low level-connecting'!
99
7d016cc30052 fixed & moved pingWalk from SNMPSession to here;
Claus Gittinger <cg@exept.de>
parents: 98
diff changeset
  3138
116
7789fb1c9fa2 more UD socket fixes (at least client side seems to work now)
Claus Gittinger <cg@exept.de>
parents: 115
diff changeset
  3139
connectTo:hostOrPathName port:portNrOrName
71
claus
parents: 63
diff changeset
  3140
    "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
  3141
     For unix-domain sockets, the port argument is ignored and pathName is taken.
115
a9d85df931c4 added Unix domain support
Claus Gittinger <cg@exept.de>
parents: 112
diff changeset
  3142
     Other sockets are not yet implemented.
71
claus
parents: 63
diff changeset
  3143
     Return true if ok, false otherwise.
99
7d016cc30052 fixed & moved pingWalk from SNMPSession to here;
Claus Gittinger <cg@exept.de>
parents: 98
diff changeset
  3144
     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
  3145
     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
  3146
     is established. 
7789fb1c9fa2 more UD socket fixes (at least client side seems to work now)
Claus Gittinger <cg@exept.de>
parents: 115
diff changeset
  3147
     See also: #connectTo:port:withTimeout: for a somewhat nicer interface."
28
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  3148
649
1bc56594db85 fixed connect for sun/irix
Claus Gittinger <cg@exept.de>
parents: 648
diff changeset
  3149
    ^ self connectTo:hostOrPathName port:portNrOrName blocking:false
1bc56594db85 fixed connect for sun/irix
Claus Gittinger <cg@exept.de>
parents: 648
diff changeset
  3150
!
1bc56594db85 fixed connect for sun/irix
Claus Gittinger <cg@exept.de>
parents: 648
diff changeset
  3151
1bc56594db85 fixed connect for sun/irix
Claus Gittinger <cg@exept.de>
parents: 648
diff changeset
  3152
connectTo:hostOrPathName port:portNrOrName blocking:blocking
1bc56594db85 fixed connect for sun/irix
Claus Gittinger <cg@exept.de>
parents: 648
diff changeset
  3153
    "low level connect; connect to port, portNrOrName on host, hostName.
1bc56594db85 fixed connect for sun/irix
Claus Gittinger <cg@exept.de>
parents: 648
diff changeset
  3154
     For unix-domain sockets, the port argument is ignored and pathName is taken.
1bc56594db85 fixed connect for sun/irix
Claus Gittinger <cg@exept.de>
parents: 648
diff changeset
  3155
     Other sockets are not yet implemented.
1bc56594db85 fixed connect for sun/irix
Claus Gittinger <cg@exept.de>
parents: 648
diff changeset
  3156
     Return true if ok, false otherwise.
1bc56594db85 fixed connect for sun/irix
Claus Gittinger <cg@exept.de>
parents: 648
diff changeset
  3157
     Hostname must be a string, portNrOrName an integer port number (in inet domain).
1bc56594db85 fixed connect for sun/irix
Claus Gittinger <cg@exept.de>
parents: 648
diff changeset
  3158
     The current process will block (but not the whole Smalltalk) until the connection
1bc56594db85 fixed connect for sun/irix
Claus Gittinger <cg@exept.de>
parents: 648
diff changeset
  3159
     is established. 
1bc56594db85 fixed connect for sun/irix
Claus Gittinger <cg@exept.de>
parents: 648
diff changeset
  3160
     See also: #connectTo:port:withTimeout: for a somewhat nicer interface."
1bc56594db85 fixed connect for sun/irix
Claus Gittinger <cg@exept.de>
parents: 648
diff changeset
  3161
430
12d736316f69 Fix #connectTo:port: Do not call connect() when we get EINPROGRESS
Stefan Vogel <sv@exept.de>
parents: 429
diff changeset
  3162
    |isAsync|
12d736316f69 Fix #connectTo:port: Do not call connect() when we get EINPROGRESS
Stefan Vogel <sv@exept.de>
parents: 429
diff changeset
  3163
28
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  3164
    filePointer isNil ifTrue:[
789
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3165
	^ self errorNotOpen
28
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  3166
    ].
0
1cf8d1747859 Initial revision
claus
parents:
diff changeset
  3167
%{
649
1bc56594db85 fixed connect for sun/irix
Claus Gittinger <cg@exept.de>
parents: 648
diff changeset
  3168
418
317e55c6c281 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 403
diff changeset
  3169
#ifndef NO_SOCKET
217
fcfbc9f71048 underscore cleanup
Claus Gittinger <cg@exept.de>
parents: 209
diff changeset
  3170
    OBJ t = __INST(filePointer);
71
claus
parents: 63
diff changeset
  3171
    OBJ myDomain;
115
a9d85df931c4 added Unix domain support
Claus Gittinger <cg@exept.de>
parents: 112
diff changeset
  3172
    union {
525
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  3173
# ifdef AF_INET
789
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3174
	struct sockaddr_in in ;
525
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  3175
# endif
530
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  3176
# ifdef AF_INET6
789
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3177
	struct sockaddr_in6 in6;
530
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  3178
# endif
524
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  3179
# ifdef AF_UNIX
789
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3180
	struct sockaddr_un un;
524
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  3181
# endif
525
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  3182
# ifdef AF_APPLETALK
789
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3183
	struct sockaddr_at at;
525
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  3184
# endif
115
a9d85df931c4 added Unix domain support
Claus Gittinger <cg@exept.de>
parents: 112
diff changeset
  3185
    } sa;
28
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  3186
    struct hostent *hp ;
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  3187
    int a, sock ;
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  3188
    long addr;
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  3189
    FILE *fp;
649
1bc56594db85 fixed connect for sun/irix
Claus Gittinger <cg@exept.de>
parents: 648
diff changeset
  3190
    int ret, oldFlags;
28
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  3191
    int on = 1;
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  3192
    int ok;
115
a9d85df931c4 added Unix domain support
Claus Gittinger <cg@exept.de>
parents: 112
diff changeset
  3193
    int sockaddr_size;
28
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  3194
217
fcfbc9f71048 underscore cleanup
Claus Gittinger <cg@exept.de>
parents: 209
diff changeset
  3195
    if (!__isString(__INST(domain)) && !__isSymbol(__INST(domain))) {
789
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3196
	DBGPRINTF(("SOCKET: invalid domain arg\n"));
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3197
	RETURN (false);
28
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  3198
    }
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  3199
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  3200
    ok = 0;
217
fcfbc9f71048 underscore cleanup
Claus Gittinger <cg@exept.de>
parents: 209
diff changeset
  3201
    myDomain = __INST(domain);
115
a9d85df931c4 added Unix domain support
Claus Gittinger <cg@exept.de>
parents: 112
diff changeset
  3202
    bzero((char *) &sa, sizeof(sa)) ;
508
55d1e49c7157 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 507
diff changeset
  3203
28
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  3204
#ifdef AF_INET
71
claus
parents: 63
diff changeset
  3205
    if (myDomain == @symbol(inet)) {
789
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3206
	/*
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3207
	 * INET addressing: port must be a smallInteger;
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3208
	 * hostOrPathName the name of the host (dot notation allowed)
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3209
	 * or a byteArray containing the 4 address bytes.
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3210
	 */
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3211
	if (! __isSmallInteger(portNrOrName)) {
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3212
	    DBGPRINTF(("SOCKET: invalid port arg\n"));
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3213
	    RETURN (false);
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3214
	}
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3215
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3216
	sa.in.sin_family = AF_INET;
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3217
	sa.in.sin_port = htons((u_short) _intVal(portNrOrName)) ;
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3218
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3219
	if (__isByteArray(hostOrPathName)) {
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3220
	    unsigned char *cp;
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3221
	    int n;
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3222
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3223
	    cp = __ByteArrayInstPtr(hostOrPathName)->ba_element;
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3224
	    n = __byteArraySize(hostOrPathName);
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3225
	    if (n > 4) n = 4;
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3226
	    bcopy(cp, &sa.in.sin_addr.s_addr, n);
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3227
	} else {
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3228
	    if (! __isString(hostOrPathName)) {
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3229
		DBGPRINTF(("SOCKET: invalid hostname arg\n"));
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3230
		RETURN (false);
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3231
	    }
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3232
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3233
	    if ((addr = inet_addr(__stringVal(hostOrPathName))) != -1) {
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3234
		/* 
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3235
		 * is Internet addr in octet notation 
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3236
		 */
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3237
		bcopy(&addr, (char *) &sa.in.sin_addr, sizeof(addr)) ; /* set address */
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3238
	    } else {
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3239
		/* 
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3240
		 * do we know the host's address? 
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3241
		 */
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3242
		GETHOSTBYNAME(hp, __stringVal(hostOrPathName))
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3243
		if (hp == NULL) {
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3244
		    DBGPRINTF(("SOCKET: unknown host:%s\n", __stringVal(hostOrPathName)));
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3245
		    RETURN (false);
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3246
		}
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3247
		bcopy(hp->h_addr, (char *) &sa.in.sin_addr, hp->h_length) ;
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3248
		sa.in.sin_family = hp->h_addrtype;
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3249
	    }
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3250
	}
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3251
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3252
	DBGPRINTF(("SOCKET: connect addr: %x port: %d\n", sa.in.sin_addr, sa.in.sin_port));
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3253
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3254
	sockaddr_size = sizeof(struct sockaddr_in);
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3255
	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
  3256
    }
525
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  3257
#endif /* AF_INET */
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  3258
530
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  3259
#ifdef AF_INET6
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  3260
    if (myDomain == @symbol(inet6)) {
789
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3261
	/*
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3262
	 * INET6 addressing: port must be a smallInteger;
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3263
	 * hostOrPathName the name of the host
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3264
	 * or a byteArray containing the 6 address bytes.
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3265
	 */
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3266
	if (! __isSmallInteger(portNrOrName)) {
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3267
	    DBGPRINTF(("SOCKET: invalid port arg\n"));
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3268
	    RETURN (false);
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3269
	}
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3270
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3271
	sa.in6.sin6_family = AF_INET6;
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3272
	sa.in6.sin6_port = htons((u_short) _intVal(portNrOrName)) ;
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3273
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3274
	if (__isByteArray(hostOrPathName)) {
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3275
	    unsigned char *cp;
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3276
	    int n;
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3277
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3278
	    cp = __ByteArrayInstPtr(hostOrPathName)->ba_element;
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3279
	    n = __byteArraySize(hostOrPathName);
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3280
	    if (n > 6) n = 6;
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3281
	    bcopy(cp, &sa.in6.sin6_addr.s6_addr, n);
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3282
	} else {
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3283
	    if (! __isString(hostOrPathName)) {
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3284
		DBGPRINTF(("SOCKET: invalid hostname arg\n"));
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3285
		RETURN (false);
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3286
	    }
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3287
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3288
	    /* 
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3289
	     * do we know the host's address? 
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3290
	     */
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3291
	    GETHOSTBYNAME(hp, __stringVal(hostOrPathName))
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3292
	    if (hp == NULL) {
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3293
		DBGPRINTF(("SOCKET: unknown host:%s\n", __stringVal(hostOrPathName)));
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3294
		RETURN (false);
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3295
	    }
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3296
	    bcopy(hp->h_addr, (char *) &sa.in.sin_addr, hp->h_length) ;
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3297
	    sa.in.sin_family = hp->h_addrtype;
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3298
	}
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3299
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3300
	DBGPRINTF(("SOCKET: connect addr: %x.%x.%x.%x.%x.%x port: %d\n", 
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3301
		sa.in6.sin6_addr.s6_addr[0],
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3302
		sa.in6.sin6_addr.s6_addr[1],
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3303
		sa.in6.sin6_addr.s6_addr[2],
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3304
		sa.in6.sin6_addr.s6_addr[3],
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3305
		sa.in6.sin6_addr.s6_addr[4],
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3306
		sa.in6.sin6_addr.s6_addr[5],
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3307
		sa.in6.sin6_port));
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3308
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3309
	sockaddr_size = sizeof(struct sockaddr_in6);
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3310
	ok = 1;
530
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  3311
    }
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  3312
#endif /* AF_INET6 */
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  3313
116
7789fb1c9fa2 more UD socket fixes (at least client side seems to work now)
Claus Gittinger <cg@exept.de>
parents: 115
diff changeset
  3314
#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
  3315
    if (myDomain == @symbol(unix)) {
789
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3316
	char *pathName;
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3317
	int l;
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3318
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3319
	/*
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3320
	 * UNIX domain: port is ignored;
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3321
	 * hostOrPathName is a pathName
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3322
	 */
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3323
	if (! __isString(hostOrPathName)) {
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3324
	    DBGPRINTF(("SOCKET: invalid port (pathname) arg\n"));
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3325
	    RETURN (false);
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3326
	}
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3327
	pathName = (char *) __stringVal(hostOrPathName);
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3328
	l = strlen(pathName);
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3329
	if ((l + sizeof ( sa.un.sun_family )) > sizeof(struct sockaddr_un)) {
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3330
	    DBGPRINTF(("SOCKET: pathname too long\n"));
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3331
	    RETURN (false);
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3332
	}
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3333
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3334
	strcpy(sa.un.sun_path, pathName);
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3335
	sa.un.sun_family = AF_UNIX;
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3336
	sockaddr_size = l + sizeof ( sa.un.sun_family );
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3337
	ok = 1;
28
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  3338
    }
525
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  3339
#endif /* AF_UNIX */
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  3340
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  3341
#ifdef AF_APPLETALK
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  3342
    if (myDomain == @symbol(appletalk)) {
789
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3343
	/*
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3344
	 * APPLETALK addressing: port must be a smallInteger;
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3345
	 * hostOrPathName the name of the host
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3346
	 * or a byteArray containing the 3 address bytes.
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3347
	 */
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3348
	if (! __isSmallInteger(portNrOrName)) {
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3349
	    DBGPRINTF(("SOCKET: invalid port arg\n"));
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3350
	    RETURN (false);
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3351
	}
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3352
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3353
	sa.at.sat_family = AF_APPLETALK;
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3354
	sa.at.sat_port = __intVal(portNrOrName);
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3355
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3356
	if (__isByteArray(hostOrPathName)) {
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3357
	    unsigned char *cp;
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3358
	    int n;
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3359
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3360
	    cp = __ByteArrayInstPtr(hostOrPathName)->ba_element;
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3361
	    n = __byteArraySize(hostOrPathName);
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3362
	    if (n > 3) n = 3;
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3363
	    bcopy(cp, &sa.at.sat_addr, n);
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3364
	} else {
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3365
	    if (! __isString(hostOrPathName)) {
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3366
		DBGPRINTF(("SOCKET: invalid hostname arg\n"));
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3367
		RETURN (false);
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3368
	    }
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3369
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3370
	    /* 
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3371
	     * do we know the host's address? 
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3372
	     */
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3373
	    GETHOSTBYNAME(hp, __stringVal(hostOrPathName))
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3374
	    if (hp == NULL) {
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3375
		DBGPRINTF(("SOCKET: unknown host:%s\n", __stringVal(hostOrPathName)));
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3376
		RETURN (false);
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3377
	    }
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3378
	    if (hp->h_addrtype != AF_APPLETALK) {
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3379
		DBGPRINTF(("SOCKET: host:%s is not an appletalk host\n", __stringVal(hostOrPathName)));
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3380
		RETURN (false);
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3381
	    }
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3382
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3383
	    bcopy(hp->h_addr, (char *) &sa.at.sat_addr, hp->h_length) ;
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3384
	    sa.at.sat_family = hp->h_addrtype;
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3385
	}
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3386
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3387
	DBGPRINTF(("SOCKET: connect addr: %x port: %d\n", sa.in.sin_addr, sa.in.sin_port));
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3388
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3389
	sockaddr_size = sizeof(struct sockaddr_at);
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3390
	ok = 1;
525
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  3391
    }
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  3392
#endif /* APPLETALK */
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  3393
28
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  3394
    /*
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  3395
     * XXXX add addressing stuff for other domains here ...
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  3396
     */
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  3397
#ifdef AF_X25
71
claus
parents: 63
diff changeset
  3398
    if (myDomain == @symbol(x25)) {
28
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  3399
    }
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  3400
#endif
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  3401
#ifdef AF_NS
71
claus
parents: 63
diff changeset
  3402
    if (myDomain == @symbol(ns)) {
28
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  3403
    }
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  3404
#endif
524
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  3405
# ifdef AF_DECnet
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  3406
    if (myDomain == @symbol(decnet)) {
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  3407
    }
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  3408
# endif
93
Claus Gittinger <cg@exept.de>
parents: 92
diff changeset
  3409
#ifdef AF_NS 
Claus Gittinger <cg@exept.de>
parents: 92
diff changeset
  3410
    if (myDomain == @symbol(xns)) {
Claus Gittinger <cg@exept.de>
parents: 92
diff changeset
  3411
    }
Claus Gittinger <cg@exept.de>
parents: 92
diff changeset
  3412
#endif
Claus Gittinger <cg@exept.de>
parents: 92
diff changeset
  3413
#ifdef AF_SNA
Claus Gittinger <cg@exept.de>
parents: 92
diff changeset
  3414
    if (myDomain == @symbol(sna)) {
Claus Gittinger <cg@exept.de>
parents: 92
diff changeset
  3415
    }
Claus Gittinger <cg@exept.de>
parents: 92
diff changeset
  3416
#endif
Claus Gittinger <cg@exept.de>
parents: 92
diff changeset
  3417
#ifdef AF_RAW 
Claus Gittinger <cg@exept.de>
parents: 92
diff changeset
  3418
    if (myDomain == @symbol(raw)) {
Claus Gittinger <cg@exept.de>
parents: 92
diff changeset
  3419
    }
Claus Gittinger <cg@exept.de>
parents: 92
diff changeset
  3420
#endif
524
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  3421
# ifdef AF_ISO
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  3422
    if (myDomain == @symbol(iso)) {
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  3423
    }
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  3424
# endif
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  3425
# ifdef AF_NETBIOS
530
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  3426
    if (myDomain == @symbol(netbios)) {
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  3427
    }
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  3428
# endif
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  3429
# ifdef AF_IPX
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  3430
    if (myDomain == @symbol(ipx)) {
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  3431
    }
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  3432
# endif
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  3433
# ifdef AF_BRIDGE
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  3434
    if (myDomain == @symbol(bridge)) {
524
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  3435
    }
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  3436
# endif
571
191b37534643 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 563
diff changeset
  3437
# ifdef AF_BSC
191b37534643 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 563
diff changeset
  3438
    if (myDomain == @symbol(bsc)) {
191b37534643 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 563
diff changeset
  3439
    }
191b37534643 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 563
diff changeset
  3440
# endif
524
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  3441
# if defined(AF_CCITT) && (AF_CCITT != AF_X25)
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  3442
    if (myDomain == @symbol(ccitt)) {
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  3443
    }
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  3444
# endif
28
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  3445
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  3446
    if (! ok) {
789
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3447
	DBGPRINTF(("SOCKET: unsupported domain\n"));
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3448
	RETURN (false);
28
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  3449
    }
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  3450
110
7af19ae8693b use new FILE* wrapper macros (based on externalAddress)
Claus Gittinger <cg@exept.de>
parents: 106
diff changeset
  3451
    sock = fileno(__FILEVal(t));
28
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  3452
649
1bc56594db85 fixed connect for sun/irix
Claus Gittinger <cg@exept.de>
parents: 648
diff changeset
  3453
#if defined(O_NONBLOCK)
1bc56594db85 fixed connect for sun/irix
Claus Gittinger <cg@exept.de>
parents: 648
diff changeset
  3454
    if (blocking != true) {
789
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3455
	/*
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3456
	 * set to non-blocking and wait later
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3457
	 */
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3458
	oldFlags = fcntl(sock, F_GETFL, 0);
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3459
	/* on SUNOS4.x, would use fcntl(osfd, F_SETFL, flags | FNDELAY); */
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3460
	fcntl(sock, F_SETFL, oldFlags | O_NONBLOCK);
649
1bc56594db85 fixed connect for sun/irix
Claus Gittinger <cg@exept.de>
parents: 648
diff changeset
  3461
    }
1bc56594db85 fixed connect for sun/irix
Claus Gittinger <cg@exept.de>
parents: 648
diff changeset
  3462
#endif
1bc56594db85 fixed connect for sun/irix
Claus Gittinger <cg@exept.de>
parents: 648
diff changeset
  3463
28
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  3464
    /* 
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  3465
     * connect 
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  3466
     */
81
claus
parents: 79
diff changeset
  3467
    __BEGIN_INTERRUPTABLE__
28
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  3468
    do {
789
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3469
	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
  3470
    } while ((ret < 0) 
789
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3471
	     && ((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
  3472
#ifdef EAGAIN
789
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3473
		 || (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
  3474
#endif
789
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3475
		));
81
claus
parents: 79
diff changeset
  3476
    __END_INTERRUPTABLE__
28
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  3477
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  3478
    if (ret < 0) { 
649
1bc56594db85 fixed connect for sun/irix
Claus Gittinger <cg@exept.de>
parents: 648
diff changeset
  3479
#if defined(EINPROGRESS) || defined(EALREADY)
789
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3480
	if (0
649
1bc56594db85 fixed connect for sun/irix
Claus Gittinger <cg@exept.de>
parents: 648
diff changeset
  3481
# ifdef EINPROGRESS
789
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3482
	    || (errno == EINPROGRESS) 
649
1bc56594db85 fixed connect for sun/irix
Claus Gittinger <cg@exept.de>
parents: 648
diff changeset
  3483
# endif
1bc56594db85 fixed connect for sun/irix
Claus Gittinger <cg@exept.de>
parents: 648
diff changeset
  3484
# ifdef EALREADY
789
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3485
	    || (errno == EALREADY)
649
1bc56594db85 fixed connect for sun/irix
Claus Gittinger <cg@exept.de>
parents: 648
diff changeset
  3486
# endif
789
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3487
	) {
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3488
	    /*
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3489
	     * We were interrupted. Do not call connect again
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3490
	     * (we will get an EALREADY.
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3491
	     * Do a select on write instead.
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3492
	     */
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3493
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3494
	    isAsync = true;
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3495
	} else
649
1bc56594db85 fixed connect for sun/irix
Claus Gittinger <cg@exept.de>
parents: 648
diff changeset
  3496
#endif /* EINPROGRESS or EALREADY */
789
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3497
	{
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3498
	    DBGPRINTF(("SOCKET: connect failed errno=%d\n", errno));
117
03cefad7e40b UD socket example & interruptable bind
Claus Gittinger <cg@exept.de>
parents: 116
diff changeset
  3499
#ifdef DUMP_ADDRESS
789
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3500
	    {
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3501
		char *cp = (char *)(&sa);
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3502
		int i;
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3503
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3504
		printf("address data:\n");
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3505
		for (i=0; i<sockaddr_size; i++) {
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3506
		    printf(" %02x\n", *cp++);
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3507
		}
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3508
	    }
117
03cefad7e40b UD socket example & interruptable bind
Claus Gittinger <cg@exept.de>
parents: 116
diff changeset
  3509
#endif
789
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3510
	    __INST(lastErrorNumber) = __MKSMALLINT(errno);
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3511
	    RETURN (false);
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3512
	}
28
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  3513
    }
649
1bc56594db85 fixed connect for sun/irix
Claus Gittinger <cg@exept.de>
parents: 648
diff changeset
  3514
1bc56594db85 fixed connect for sun/irix
Claus Gittinger <cg@exept.de>
parents: 648
diff changeset
  3515
#if defined(O_NONBLOCK)
1bc56594db85 fixed connect for sun/irix
Claus Gittinger <cg@exept.de>
parents: 648
diff changeset
  3516
    if (blocking != true) {
789
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3517
	fcntl(sock, F_SETFL, oldFlags);
649
1bc56594db85 fixed connect for sun/irix
Claus Gittinger <cg@exept.de>
parents: 648
diff changeset
  3518
    }
1bc56594db85 fixed connect for sun/irix
Claus Gittinger <cg@exept.de>
parents: 648
diff changeset
  3519
#endif
1bc56594db85 fixed connect for sun/irix
Claus Gittinger <cg@exept.de>
parents: 648
diff changeset
  3520
430
12d736316f69 Fix #connectTo:port: Do not call connect() when we get EINPROGRESS
Stefan Vogel <sv@exept.de>
parents: 429
diff changeset
  3521
#else /* NO_SOCKET */
418
317e55c6c281 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 403
diff changeset
  3522
    RETURN (false);
430
12d736316f69 Fix #connectTo:port: Do not call connect() when we get EINPROGRESS
Stefan Vogel <sv@exept.de>
parents: 429
diff changeset
  3523
#endif /* NO_SOCKET */
42
506596f9a1a8 *** empty log message ***
claus
parents: 38
diff changeset
  3524
%}.
430
12d736316f69 Fix #connectTo:port: Do not call connect() when we get EINPROGRESS
Stefan Vogel <sv@exept.de>
parents: 429
diff changeset
  3525
    isAsync == true ifTrue:[
789
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3526
	self readWriteWait.
430
12d736316f69 Fix #connectTo:port: Do not call connect() when we get EINPROGRESS
Stefan Vogel <sv@exept.de>
parents: 429
diff changeset
  3527
    ].
71
claus
parents: 63
diff changeset
  3528
    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
  3529
    peerName := hostOrPathName.
28
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  3530
    ^ true
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  3531
!
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  3532
649
1bc56594db85 fixed connect for sun/irix
Claus Gittinger <cg@exept.de>
parents: 648
diff changeset
  3533
connectTo:hostOrPathName port:portNrOrName blocking:blocking withTimeout:millis
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3534
    "connect to port, portNrOrName on host, hostName.
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3535
     Or path (UNIX socket), where portNrOrName is ignored.
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3536
     Return true if ok, false otherwise.
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3537
     Hostname must be a string, portNrOrName an integer port number (in inet domain).
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3538
     If a non-nil timeout is given, stop trying after that time and return false as well."
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3539
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3540
    |stopSignal stopMe connection|
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3541
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3542
    millis isNil ifTrue:[
789
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3543
	^ self connectTo:hostOrPathName port:portNrOrName
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3544
    ].
559
61012867ebed cleanup if #connect is interrupted
Claus Gittinger <cg@exept.de>
parents: 551
diff changeset
  3545
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3546
    stopSignal := Signal new.
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3547
    stopMe := [stopSignal raise].
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3548
    stopSignal handle:[:ex |
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3549
"/        'timeout on connect' infoPrintNL.
789
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3550
	^ false
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3551
    ] do:[
789
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3552
	Processor addTimedBlock:stopMe afterMilliseconds:millis.
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3553
	[
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3554
	    connection := self connectTo:hostOrPathName port:portNrOrName blocking:blocking.
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3555
	] valueNowOrOnUnwindDo:[
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3556
	    Processor removeTimedBlock:stopMe.
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3557
	]
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3558
    ].
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3559
    ^ connection
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3560
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3561
    "Created: 31.10.1995 / 18:52:49 / cg"
559
61012867ebed cleanup if #connect is interrupted
Claus Gittinger <cg@exept.de>
parents: 551
diff changeset
  3562
    "Modified: 16.8.1997 / 02:11:21 / cg"
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3563
!
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3564
649
1bc56594db85 fixed connect for sun/irix
Claus Gittinger <cg@exept.de>
parents: 648
diff changeset
  3565
connectTo:hostOrPathName port:portNrOrName withTimeout:millis
1bc56594db85 fixed connect for sun/irix
Claus Gittinger <cg@exept.de>
parents: 648
diff changeset
  3566
    "connect to port, portNrOrName on host, hostName.
1bc56594db85 fixed connect for sun/irix
Claus Gittinger <cg@exept.de>
parents: 648
diff changeset
  3567
     Or path (UNIX socket), where portNrOrName is ignored.
1bc56594db85 fixed connect for sun/irix
Claus Gittinger <cg@exept.de>
parents: 648
diff changeset
  3568
     Return true if ok, false otherwise.
1bc56594db85 fixed connect for sun/irix
Claus Gittinger <cg@exept.de>
parents: 648
diff changeset
  3569
     Hostname must be a string, portNrOrName an integer port number (in inet domain).
1bc56594db85 fixed connect for sun/irix
Claus Gittinger <cg@exept.de>
parents: 648
diff changeset
  3570
     If a non-nil timeout is given, stop trying after that time and return false as well."
1bc56594db85 fixed connect for sun/irix
Claus Gittinger <cg@exept.de>
parents: 648
diff changeset
  3571
1bc56594db85 fixed connect for sun/irix
Claus Gittinger <cg@exept.de>
parents: 648
diff changeset
  3572
    ^ self connectTo:hostOrPathName port:portNrOrName blocking:false withTimeout:millis
25
996051271ce9 *** empty log message ***
claus
parents: 21
diff changeset
  3573
! !
996051271ce9 *** empty log message ***
claus
parents: 21
diff changeset
  3574
996051271ce9 *** empty log message ***
claus
parents: 21
diff changeset
  3575
!Socket methodsFor:'queries'!
996051271ce9 *** empty log message ***
claus
parents: 21
diff changeset
  3576
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3577
domain
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3578
    "return the sockets addressing domain (i.e. #inet, #unix, #x25, #appletalk)"
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3579
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3580
    ^ domain
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3581
!
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3582
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3583
getName
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3584
    "return the name; here, we return the ports name"
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3585
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3586
    ^ port printString
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3587
!
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3588
102
5dc264007513 added getPeer for ST-80 compatibility
Claus Gittinger <cg@exept.de>
parents: 99
diff changeset
  3589
getPeer
5dc264007513 added getPeer for ST-80 compatibility
Claus Gittinger <cg@exept.de>
parents: 99
diff changeset
  3590
    "ST-80 compatibility: return an IPSocketAddress instance representing
5dc264007513 added getPeer for ST-80 compatibility
Claus Gittinger <cg@exept.de>
parents: 99
diff changeset
  3591
     my hostname/port combination.
155
fcf846c707b7 interest is written with one 'r' (shame on me)
Claus Gittinger <cg@exept.de>
parents: 126
diff changeset
  3592
     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
  3593
116
7789fb1c9fa2 more UD socket fixes (at least client side seems to work now)
Claus Gittinger <cg@exept.de>
parents: 115
diff changeset
  3594
    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
  3595
	^ 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
  3596
    ].
102
5dc264007513 added getPeer for ST-80 compatibility
Claus Gittinger <cg@exept.de>
parents: 99
diff changeset
  3597
    ^ IPSocketAddress hostAddress:(self class ipAddressOfHost:peerName) port:port
5dc264007513 added getPeer for ST-80 compatibility
Claus Gittinger <cg@exept.de>
parents: 99
diff changeset
  3598
5dc264007513 added getPeer for ST-80 compatibility
Claus Gittinger <cg@exept.de>
parents: 99
diff changeset
  3599
    "Created: 2.11.1995 / 11:22:39 / cg"
5dc264007513 added getPeer for ST-80 compatibility
Claus Gittinger <cg@exept.de>
parents: 99
diff changeset
  3600
!
5dc264007513 added getPeer for ST-80 compatibility
Claus Gittinger <cg@exept.de>
parents: 99
diff changeset
  3601
25
996051271ce9 *** empty log message ***
claus
parents: 21
diff changeset
  3602
getPeerName
996051271ce9 *** empty log message ***
claus
parents: 21
diff changeset
  3603
    "return the peer name; thats the hostname (or dotted name) of the
996051271ce9 *** empty log message ***
claus
parents: 21
diff changeset
  3604
     partners host after an accept."
996051271ce9 *** empty log message ***
claus
parents: 21
diff changeset
  3605
996051271ce9 *** empty log message ***
claus
parents: 21
diff changeset
  3606
    ^ peerName
28
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  3607
!
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  3608
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3609
isActive
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3610
    "return true, if the receiver has a connection"
81
claus
parents: 79
diff changeset
  3611
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3612
    ^ filePointer notNil
81
claus
parents: 79
diff changeset
  3613
!
claus
parents: 79
diff changeset
  3614
71
claus
parents: 63
diff changeset
  3615
port
claus
parents: 63
diff changeset
  3616
    "return the port number (or name for unix-sockets) to which the socket is bound"
28
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  3617
506
11ef93d12870 support anonymous (OS_specified) ports. (for FTP-protocol)
Claus Gittinger <cg@exept.de>
parents: 486
diff changeset
  3618
    |p|
11ef93d12870 support anonymous (OS_specified) ports. (for FTP-protocol)
Claus Gittinger <cg@exept.de>
parents: 486
diff changeset
  3619
11ef93d12870 support anonymous (OS_specified) ports. (for FTP-protocol)
Claus Gittinger <cg@exept.de>
parents: 486
diff changeset
  3620
    port == 0 ifTrue:[
524
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  3621
	p := self getPort.
506
11ef93d12870 support anonymous (OS_specified) ports. (for FTP-protocol)
Claus Gittinger <cg@exept.de>
parents: 486
diff changeset
  3622
	p notNil ifTrue:[
11ef93d12870 support anonymous (OS_specified) ports. (for FTP-protocol)
Claus Gittinger <cg@exept.de>
parents: 486
diff changeset
  3623
	    port := p
11ef93d12870 support anonymous (OS_specified) ports. (for FTP-protocol)
Claus Gittinger <cg@exept.de>
parents: 486
diff changeset
  3624
	]
11ef93d12870 support anonymous (OS_specified) ports. (for FTP-protocol)
Claus Gittinger <cg@exept.de>
parents: 486
diff changeset
  3625
    ].
71
claus
parents: 63
diff changeset
  3626
    ^ port
28
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  3627
!
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  3628
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  3629
type
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  3630
    "return the sockets connection type (i.e. #datagram, #stream etc)"
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  3631
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  3632
    ^ socketType
81
claus
parents: 79
diff changeset
  3633
! !
claus
parents: 79
diff changeset
  3634
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3635
!Socket methodsFor:'socket setup'!
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3636
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3637
domain:domainArg type:typeArg
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3638
    "set up socket with domain and type.
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3639
     This is a low level entry; no binding, listening or connect
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3640
     is done. Both arguments must be symbols from one of
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3641
     #inet,#unix, #appletalk, #x25 .. and #stream, #datagram, #raw resp."
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3642
649
1bc56594db85 fixed connect for sun/irix
Claus Gittinger <cg@exept.de>
parents: 648
diff changeset
  3643
    ^ self domain:domainArg type:typeArg protocol:0 reuseAddress:true
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3644
!
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3645
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3646
domain:domainArg type:typeArg protocol:protocolNumber
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3647
    "set up socket with domain, type and protocol number.
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3648
     This is a low level entry; no binding, listening or connect
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3649
     is done. Both arguments must be symbols from one of
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3650
     #inet,#unix, #appletalk, #x25 .. and #stream, #datagram, #raw resp."
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3651
649
1bc56594db85 fixed connect for sun/irix
Claus Gittinger <cg@exept.de>
parents: 648
diff changeset
  3652
    ^ self domain:domainArg type:typeArg protocol:protocolNumber reuseAddress:true
1bc56594db85 fixed connect for sun/irix
Claus Gittinger <cg@exept.de>
parents: 648
diff changeset
  3653
1bc56594db85 fixed connect for sun/irix
Claus Gittinger <cg@exept.de>
parents: 648
diff changeset
  3654
    "
1bc56594db85 fixed connect for sun/irix
Claus Gittinger <cg@exept.de>
parents: 648
diff changeset
  3655
     Socket new domain:#inet type:#stream
1bc56594db85 fixed connect for sun/irix
Claus Gittinger <cg@exept.de>
parents: 648
diff changeset
  3656
     Socket new domain:#unix type:#stream
1bc56594db85 fixed connect for sun/irix
Claus Gittinger <cg@exept.de>
parents: 648
diff changeset
  3657
    "
1bc56594db85 fixed connect for sun/irix
Claus Gittinger <cg@exept.de>
parents: 648
diff changeset
  3658
!
1bc56594db85 fixed connect for sun/irix
Claus Gittinger <cg@exept.de>
parents: 648
diff changeset
  3659
1bc56594db85 fixed connect for sun/irix
Claus Gittinger <cg@exept.de>
parents: 648
diff changeset
  3660
domain:domainArg type:typeArg protocol:protocolNumber reuseAddress:reuse
1bc56594db85 fixed connect for sun/irix
Claus Gittinger <cg@exept.de>
parents: 648
diff changeset
  3661
    "set up socket with domain, type and protocol number.
1bc56594db85 fixed connect for sun/irix
Claus Gittinger <cg@exept.de>
parents: 648
diff changeset
  3662
     This is a low level entry; no binding, listening or connect
1bc56594db85 fixed connect for sun/irix
Claus Gittinger <cg@exept.de>
parents: 648
diff changeset
  3663
     is done. Both arguments must be symbols from one of
1bc56594db85 fixed connect for sun/irix
Claus Gittinger <cg@exept.de>
parents: 648
diff changeset
  3664
     #inet,#unix, #appletalk, #x25 .. and #stream, #datagram, #raw resp.
1bc56594db85 fixed connect for sun/irix
Claus Gittinger <cg@exept.de>
parents: 648
diff changeset
  3665
1bc56594db85 fixed connect for sun/irix
Claus Gittinger <cg@exept.de>
parents: 648
diff changeset
  3666
     The reuse boolean argument controls if the SO_REUSEADDR socket option
1bc56594db85 fixed connect for sun/irix
Claus Gittinger <cg@exept.de>
parents: 648
diff changeset
  3667
     is to be set (to avoid the 'bind: address in use' error)."
1bc56594db85 fixed connect for sun/irix
Claus Gittinger <cg@exept.de>
parents: 648
diff changeset
  3668
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3669
    |errorNr|
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3670
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3671
    filePointer notNil ifTrue:[
789
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3672
	^ self errorAlreadyOpen
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3673
    ].
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3674
%{
649
1bc56594db85 fixed connect for sun/irix
Claus Gittinger <cg@exept.de>
parents: 648
diff changeset
  3675
418
317e55c6c281 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 403
diff changeset
  3676
#ifndef NO_SOCKET
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3677
    FILE *fp;
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3678
    int dom, typ, pf, proto = 0, sock;
649
1bc56594db85 fixed connect for sun/irix
Claus Gittinger <cg@exept.de>
parents: 648
diff changeset
  3679
    int on = 1;
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3680
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3681
    if (! __isSymbol(domainArg)) { 
789
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3682
	DBGPRINTF(("SOCKET: bad domain\n"));
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3683
	RETURN ( nil );
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3684
    }
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3685
    if (! __isSymbol(typeArg)) { 
789
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3686
	DBGPRINTF(("SOCKET: bad type\n"));
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3687
	RETURN ( nil );
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3688
    }
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3689
    if (protocolNumber != nil) {
789
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3690
	if (!__isSmallInteger(protocolNumber)) {
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3691
	    DBGPRINTF(("SOCKET: bad protocol\n"));
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3692
	    RETURN ( nil );
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3693
	}
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3694
	proto = __intVal(protocolNumber);
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3695
    }
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3696
        
81
claus
parents: 79
diff changeset
  3697
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3698
    /*
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3699
     * get address and protocol-family
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3700
     */
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3701
#ifdef AF_UNIX
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3702
    if (domainArg == @symbol(unix)) {
789
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3703
	dom = AF_UNIX;
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3704
    } else
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3705
#endif
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3706
#ifdef AF_INET
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3707
    if (domainArg == @symbol(inet)) {
789
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3708
	dom = AF_INET;
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3709
    } else
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3710
#endif
530
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  3711
#ifdef AF_INET6
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  3712
    if (domainArg == @symbol(inet6)) {
789
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3713
	dom = AF_INET6;
530
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  3714
    } else
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  3715
#endif
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3716
#ifdef AF_DECnet
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3717
    if (domainArg == @symbol(DECnet)) {
789
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3718
	dom = AF_DECnet;
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3719
    } else
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3720
#endif
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3721
#ifdef AF_APPLETALK
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3722
    if (domainArg == @symbol(appletalk)) {
789
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3723
	dom = AF_APPLETALK;
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3724
    } else
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3725
#endif
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3726
#ifdef AF_X25
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3727
    if (domainArg == @symbol(x25)) {
789
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3728
	dom = AF_X25;
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3729
    } else
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3730
#endif
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3731
#ifdef AF_NS
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3732
    if (domainArg == @symbol(xns)) {
789
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3733
	dom = AF_NS;
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3734
    } else
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3735
#endif
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3736
#ifdef AF_SNA
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3737
    if (domainArg == @symbol(sna)) {
789
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3738
	dom = AF_SNA;
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3739
    } else
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3740
#endif
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3741
#ifdef AF_RAW
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3742
    if (domainArg == @symbol(raw)) {
789
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3743
	dom = AF_RAW;
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3744
    } else
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3745
#endif
524
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  3746
# ifdef AF_ISO
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  3747
    if (domainArg == @symbol(iso)) {
789
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3748
	dom = AF_ISO;
524
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  3749
    }
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  3750
# endif
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  3751
# ifdef AF_NETBIOS
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  3752
    if (domainArg == @symbol(netbios)) {
789
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3753
	dom = AF_NETBIOS;
524
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  3754
    }
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  3755
# endif
530
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  3756
# ifdef AF_IPX
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  3757
    if (domainArg == @symbol(ipx)) {
789
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3758
	dom = AF_IPX;
530
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  3759
    }
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  3760
# endif
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  3761
# ifdef AF_BRIDGE
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  3762
    if (domainArg == @symbol(bridge)) {
789
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3763
	dom = AF_BRIDGE;
530
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  3764
    }
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  3765
# endif
571
191b37534643 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 563
diff changeset
  3766
# ifdef AF_BSC
191b37534643 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 563
diff changeset
  3767
    if (domainArg == @symbol(bsc)) {
789
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3768
	dom = AF_BSC;
571
191b37534643 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 563
diff changeset
  3769
    }
191b37534643 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 563
diff changeset
  3770
# endif
524
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  3771
# if defined(AF_CCITT) && (AF_CCITT != AF_X25)
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  3772
    if (domainArg == @symbol(ccitt)) {
789
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3773
	dom = AF_CCITT;
524
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  3774
    }
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  3775
# endif
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3776
    {
789
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3777
	DBGPRINTF(("SOCKET: unknown domain <%s>\n", __stringVal(domainArg)));
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3778
	RETURN ( nil );
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3779
    }
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3780
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3781
#ifdef SOCK_STREAM
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3782
    if (typeArg == @symbol(stream)) {
789
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3783
	typ = SOCK_STREAM;
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3784
    } else
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3785
#endif
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3786
#ifdef SOCK_DGRAM
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3787
    if (typeArg == @symbol(datagram)) {
789
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3788
	typ = SOCK_DGRAM;
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3789
    } else 
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3790
#endif
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3791
#ifdef SOCK_RAW
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3792
    if (typeArg == @symbol(raw))
789
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3793
	typ = SOCK_RAW;
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3794
    else
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3795
#endif
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3796
#ifdef SOCK_SEQPACKET
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3797
    if (typeArg == @symbol(seqPacket))
789
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3798
	typ = SOCK_SEQPACKET;
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3799
    else
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3800
#endif
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3801
    {
789
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3802
	DBGPRINTF(("SOCKET: bad type <%s>\n", __stringVal(typeArg)));
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3803
	RETURN ( nil );
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3804
    }
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3805
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3806
    __BEGIN_INTERRUPTABLE__
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3807
    do {
789
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3808
	DBGPRINTF(("SOCKET: opening socket domain=%d type=%d proto=%d\n", dom, typ, proto));
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3809
	sock = socket(dom, typ, proto);
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3810
#if defined(EPROTONOSUPPORT) /* for SGI */
789
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3811
	if ((proto != 0) && (sock < 0) && (errno == EPROTONOSUPPORT)) {
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3812
	    DBGPRINTF(("SOCKET: retry with UNSPEC protocol\n"));
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3813
	    proto = 0;
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3814
	    sock = socket(dom, typ, 0);
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3815
	}
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3816
#endif
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3817
    } while ((sock < 0) && (errno == EINTR));
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3818
    __END_INTERRUPTABLE__
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3819
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3820
    if (sock < 0) {
789
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3821
	DBGPRINTF(("SOCKET: socket(dom=%d typ=%d proto=%d) call failed errno=%d\n", dom, typ, proto, errno));
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3822
	__INST(lastErrorNumber) = __MKSMALLINT(errno);
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3823
    } else {
649
1bc56594db85 fixed connect for sun/irix
Claus Gittinger <cg@exept.de>
parents: 648
diff changeset
  3824
# ifdef SO_REUSEADDR
789
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3825
	if (reuse == true) {
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3826
	    DBGPRINTF(("SOCKET: setsockopt - SO_REUSEADDR\n"));
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3827
	    if (setsockopt(sock, SOL_SOCKET, SO_REUSEADDR, (char *) &on, sizeof (on)) < 0) {
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3828
		DBGPRINTF(("SOCKET: setsockopt - SO_REUSEADDR failed\n"));
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3829
	    }
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3830
	}
649
1bc56594db85 fixed connect for sun/irix
Claus Gittinger <cg@exept.de>
parents: 648
diff changeset
  3831
# endif /* SO_REUSEADDR */
711
487b2bff9d31 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 693
diff changeset
  3832
789
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3833
	/* 
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3834
	 * make it a FILE * 
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3835
	 */
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3836
	fp = fdopen(sock, "r+");
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3837
	if (! fp) {
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3838
	    DBGPRINTF(("SOCKET: fdopen call failed\n"));
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3839
	    __INST(lastErrorNumber) = __MKSMALLINT(errno);
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3840
	    __BEGIN_INTERRUPTABLE__
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3841
	    close(sock);
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3842
	    __END_INTERRUPTABLE__
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3843
	} else {
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3844
	    __INST(filePointer) = __MKOBJ(fp);
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3845
	    __STORESELF(filePointer);
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3846
	}
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3847
    }
418
317e55c6c281 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 403
diff changeset
  3848
#endif
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3849
%}.
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3850
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3851
    "all ok?"
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3852
    filePointer notNil ifTrue:[
789
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3853
	domain := domainArg.
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3854
	socketType := typeArg.
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3855
	Lobby register:self.
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3856
    ] ifFalse:[
789
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3857
	^ nil
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3858
    ].
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3859
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3860
    "
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3861
     Socket new domain:#inet type:#stream
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3862
     Socket new domain:#unix type:#stream
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3863
    "
81
claus
parents: 79
diff changeset
  3864
!
claus
parents: 79
diff changeset
  3865
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3866
for:hostName port:portNr
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3867
    "setup for a TCP socket (i.e. inet domain, stream type) 
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3868
     If hostname is nil, a server port is opened,
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3869
     otherwise a client port to the server on host.
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3870
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3871
     HISTORIC LEFTOVER:
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3872
     This method will vanish, as soon as the low level
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3873
     connect/bind works,"
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3874
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3875
    self obsoleteMethodWarning.
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3876
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3877
    filePointer notNil ifTrue:[
789
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3878
	^ self errorAlreadyOpen
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3879
    ].
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3880
    (portNr isMemberOf:SmallInteger) ifFalse:[
789
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3881
	self error:'invalid portNr'
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3882
    ].
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3883
%{
418
317e55c6c281 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 403
diff changeset
  3884
#ifndef NO_SOCKET
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3885
    struct sockaddr_in sa ;
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3886
    struct hostent *hp ;
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3887
    int a, sock ;
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3888
    long addr;
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3889
    FILE *fp;
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3890
    int ret;
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3891
    int on = 1;
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3892
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3893
    bzero((char *) &sa, sizeof(sa)) ;
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3894
    sa.sin_family = AF_INET;
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3895
    sa.sin_addr.s_addr = htonl(INADDR_ANY);
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3896
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3897
    if ((hostName != nil) && __isString(hostName)){
789
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3898
	bzero(&sa, sizeof(sa)) ;
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3899
	if ((addr = inet_addr((char *) __stringVal(hostName))) != -1) {
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3900
	    /* 
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3901
	     * is Internet addr in octet notation 
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3902
	     */
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3903
	    bcopy(&addr, (char *) &sa.sin_addr, sizeof(addr)) ; /* set address */
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3904
	} else {
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3905
	    /* 
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3906
	     * do we know the host's address? 
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3907
	     */
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3908
	    GETHOSTBYNAME(hp, __stringVal(hostName))
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3909
	    if (hp == NULL) {
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3910
		DBGPRINTF(("SOCKET: unknown host: %s\n", __stringVal(hostName)));
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3911
		RETURN ( nil );
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3912
	    }
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3913
	    bcopy(hp->h_addr, (char *) &sa.sin_addr, hp->h_length) ;
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3914
	    sa.sin_family = hp->h_addrtype;
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3915
	}
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3916
    }
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3917
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3918
    /*
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3919
     * create the socket
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3920
     */
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3921
    __BEGIN_INTERRUPTABLE__
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3922
    do {
789
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3923
	sock = socket(sa.sin_family, SOCK_STREAM, 0);
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3924
    } while ((sock < 0) && (errno == EINTR));
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3925
    __END_INTERRUPTABLE__
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3926
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3927
    if (sock < 0) {
789
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3928
	DBGPRINTF(("SOCKET: socket(dom=%d typ=%d proto=0) call failed errno=%d\n", sa.sin_family, SOCK_STREAM, errno));
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3929
	__INST(lastErrorNumber) = __MKSMALLINT(errno);
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3930
    } else {
789
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3931
	/* 
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3932
	 * connect/bind 
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3933
	 */
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3934
	sa.sin_port = htons((u_short) _intVal(portNr)) ;
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3935
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3936
	__BEGIN_INTERRUPTABLE__
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3937
	if (hostName != nil) {
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3938
	    do {
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3939
		ret = connect(sock, (struct sockaddr *)&sa, sizeof(sa));
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3940
	    } while ((ret < 0) && (errno == EINTR));
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3941
	} else {
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3942
#ifdef SO_REUSEADDR
789
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3943
	    /*
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3944
	     * should I also do this for DGRAM sockets ?
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3945
	     */
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3946
	    if (setsockopt(sock, SOL_SOCKET, SO_REUSEADDR, (char *) &on, sizeof (on)) < 0) {
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3947
		DBGPRINTF(("SOCKET: setsockopt - SO_REUSEADDR failed\n"));
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3948
	    }
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3949
#endif /* SO_REUSEADDR */
789
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3950
	    sa.sin_addr.s_addr = htonl(INADDR_ANY);
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3951
	    do {
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3952
		ret = bind(sock, (struct sockaddr *)&sa, sizeof(sa));
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3953
	    } while ((ret < 0) && (errno == EINTR));
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3954
	}
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3955
	__END_INTERRUPTABLE__
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3956
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3957
	if (ret < 0) { 
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3958
	    DBGPRINTF(("SOCKET: bind/connect call failed errno=%d\n", errno));
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3959
	    __INST(lastErrorNumber) = __MKSMALLINT(errno);
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3960
	    __BEGIN_INTERRUPTABLE__
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3961
	    close(sock) ;
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3962
	    __END_INTERRUPTABLE__
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3963
	} else {
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3964
	    /* 
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3965
	     * make it a FILE * 
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3966
	     */
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3967
	    fp = fdopen(sock, "r+");
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3968
	    if (! fp) {
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3969
		DBGPRINTF(("SOCKET: fdopen failed\n"));
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3970
		__INST(lastErrorNumber) = __MKSMALLINT(errno);
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3971
		__BEGIN_INTERRUPTABLE__
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3972
		close(sock);
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3973
		__END_INTERRUPTABLE__
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3974
	    } else {
444
9ba31a1fba38 always unbuffered on linux
Claus Gittinger <cg@exept.de>
parents: 430
diff changeset
  3975
#ifdef BUGGY_STDIO_LIB
789
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3976
		setbuf(fp, NULL);
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3977
		__INST(buffered) = false;
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3978
#endif
789
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3979
		__INST(filePointer) = __MKOBJ(fp);
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3980
		__STORESELF(filePointer);
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3981
	    }
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3982
	}
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3983
    }
418
317e55c6c281 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 403
diff changeset
  3984
#endif
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3985
%}.
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3986
    filePointer isNil ifTrue:[
789
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3987
	^ nil
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3988
    ].
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3989
    mode := #readwrite.
169
ba5dac089c64 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 168
diff changeset
  3990
    Lobby register:self.
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3991
    binary := false.
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3992
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3993
    domain := #inet.
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3994
    socketType := #stream.
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3995
    protocol := portNr.
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3996
    peerName := hostName.
81
claus
parents: 79
diff changeset
  3997
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3998
    "
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3999
     Socket new for:'clam' port:(Socket portOfService:'echo')
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4000
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4001
     Socket new for:nil port:9999
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4002
     Socket new for:(OperatingSystem getHostName) port:9999
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4003
    "
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4004
!
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4005
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4006
for:hostName udpPort:portNr
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4007
    "setup for a UDP socket (i.e. inet domain, datagram type) 
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4008
     if hostname is nil, a server port is opened;
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4009
     otherwise a client port to the server on host.
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4010
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4011
     HISTORIC LEFTOVER:
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4012
     This method will vanish, as soon as the low level
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4013
     connect/bind works,"
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4014
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4015
    self obsoleteMethodWarning.
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4016
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4017
    filePointer notNil ifTrue:[
789
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  4018
	^ self errorAlreadyOpen
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4019
    ].
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4020
    (portNr isMemberOf:SmallInteger) ifFalse:[
789
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  4021
	self error:'invalid portNr'
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4022
    ].
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4023
%{
418
317e55c6c281 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 403
diff changeset
  4024
#ifndef NO_SOCKET
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4025
    struct sockaddr_in sa ;
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4026
    struct hostent *hp ;
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4027
    int a, sock ;
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4028
    long addr;
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4029
    FILE *fp;
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4030
    int ret;
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4031
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4032
    if (hostName != nil) {
789
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  4033
	bzero(&sa, sizeof(sa)) ;
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  4034
	if ((addr = inet_addr((char *) __stringVal(hostName))) != -1) {
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  4035
	    /* 
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  4036
	     * is Internet addr in octet notation 
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  4037
	     */
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  4038
	    bcopy(&addr, (char *) &sa.sin_addr, sizeof(addr)) ; /* set address */
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  4039
	    sa.sin_family = AF_INET ;
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  4040
	} else {
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  4041
	    /* 
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  4042
	     * is hostname - 
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  4043
	     * do we know the host's address? 
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  4044
	     */
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  4045
	    GETHOSTBYNAME(hp, __stringVal(hostName))
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  4046
	    if (hp == NULL) {
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  4047
		DBGPRINTF(("SOCKET: unknown host: %s\n", __stringVal(hostName)));
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  4048
		RETURN ( nil );
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  4049
	    }
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  4050
	    bcopy(hp->h_addr, (char *) &sa.sin_addr, hp->h_length) ;
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  4051
	    sa.sin_family = hp->h_addrtype ;
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  4052
	}
526
1748ab3892a3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 525
diff changeset
  4053
    } else {
789
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  4054
	sa.sin_family = AF_INET;
526
1748ab3892a3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 525
diff changeset
  4055
    }
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4056
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4057
    /*
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4058
     * create the socket
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4059
     */
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4060
    __BEGIN_INTERRUPTABLE__
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4061
    do {
789
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  4062
	sock = socket(sa.sin_family, SOCK_DGRAM, 0);
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4063
    } while ((sock < 0) && (errno == EINTR));
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4064
    __END_INTERRUPTABLE__
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4065
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4066
    if (sock < 0) {
789
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  4067
	DBGPRINTF(("SOCKET: socket(dom=%d typ=%d proto=0) call failed errno=%d\n", sa.sin_family, SOCK_DGRAM, errno));
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  4068
	__INST(lastErrorNumber) = __MKSMALLINT(errno);
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4069
    } else {
789
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  4070
	/* 
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  4071
	 * ok,
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  4072
	 * connect/bind 
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  4073
	 */
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  4074
	__BEGIN_INTERRUPTABLE__
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  4075
	if (hostName == nil) {
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  4076
	    sa.sin_addr.s_addr = htonl(INADDR_ANY);
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  4077
	    do {
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  4078
		ret = bind(sock, (struct sockaddr *)&sa, sizeof(sa));
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  4079
	    } while ((ret < 0) && (errno == EINTR));
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  4080
	} else {
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  4081
	    sa.sin_port = htons((u_short) _intVal(portNr)) ;
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  4082
	    do {
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  4083
		ret = connect(sock, (struct sockaddr *)&sa, sizeof(sa));
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  4084
	    } while ((ret < 0) && (errno == EINTR));
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  4085
	}
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  4086
	__END_INTERRUPTABLE__
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  4087
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  4088
	if (ret < 0) {
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  4089
	    DBGPRINTF(("SOCKET: bind/connect call failed\n"));
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  4090
	    __INST(lastErrorNumber) = __MKSMALLINT(errno);
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  4091
	    __BEGIN_INTERRUPTABLE__
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  4092
	    close(sock) ;
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  4093
	    __END_INTERRUPTABLE__
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  4094
	} else {
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  4095
	    /* 
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  4096
	     * make it a FILE * 
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  4097
	     */
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  4098
	    fp = fdopen(sock, "r+");
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  4099
	    if (! fp) {
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  4100
		DBGPRINTF(("SOCKET: fdopen call failed\n"));
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  4101
		__INST(lastErrorNumber) = __MKSMALLINT(errno);
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  4102
		__BEGIN_INTERRUPTABLE__
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  4103
		close(sock);
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  4104
		__END_INTERRUPTABLE__
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  4105
	    } else {
444
9ba31a1fba38 always unbuffered on linux
Claus Gittinger <cg@exept.de>
parents: 430
diff changeset
  4106
#ifdef BUGGY_STDIO_LIB
789
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  4107
		setbuf(fp, NULL);
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  4108
		__INST(buffered) = false;
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4109
#endif
789
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  4110
		__INST(filePointer) = __MKOBJ(fp);
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  4111
		__STORESELF(filePointer);
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  4112
	    }
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  4113
	}
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4114
    }
418
317e55c6c281 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 403
diff changeset
  4115
#endif
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4116
%}.
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4117
    filePointer isNil ifTrue:[
789
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  4118
	^ nil
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4119
    ].
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4120
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4121
    mode := #readwrite.
169
ba5dac089c64 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 168
diff changeset
  4122
    Lobby register:self.
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4123
    binary := false.
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4124
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4125
    domain := #inet.
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4126
    socketType := #datagram.
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4127
    protocol := portNr.
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4128
    peerName := hostName.
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4129
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4130
    "
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4131
     Socket new for:'clam' udpPort:(Socket portOfService:'echo')
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4132
    "
28
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  4133
! !
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  4134
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  4135
!Socket methodsFor:'specials'!
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  4136
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  4137
receiveTimeout:seconds
71
claus
parents: 63
diff changeset
  4138
    "set the receive timeout - for special applications only.
claus
parents: 63
diff changeset
  4139
     Not all operatingSystems offer this functionality
claus
parents: 63
diff changeset
  4140
     (returns false, if unsupported)"
28
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  4141
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  4142
    |millis|
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  4143
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  4144
    filePointer isNil ifTrue:[
789
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  4145
	^ self errorNotOpen
28
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  4146
    ].
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  4147
    millis := (seconds * 1000) rounded.
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  4148
%{
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  4149
#if defined(SO_RCVTIMEO) && defined(SOL_SOCKET) && defined(HZ)
58
bd6753bf0401 *** empty log message ***
claus
parents: 51
diff changeset
  4150
    if (__isSmallInteger(millis)) {
789
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  4151
	OBJ fp = __INST(filePointer);
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  4152
	int sock;
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  4153
	int opt;
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  4154
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  4155
	sock = fileno(__FILEVal(fp));
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  4156
	opt = _intVal(millis) / (1000 / HZ);
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  4157
	setsockopt(sock, SOL_SOCKET, SO_RCVTIMEO, (char *)&opt, sizeof(int));
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  4158
	RETURN(true);
28
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  4159
    }
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  4160
#endif
71
claus
parents: 63
diff changeset
  4161
%}.
28
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  4162
    ^ false
81
claus
parents: 79
diff changeset
  4163
!
claus
parents: 79
diff changeset
  4164
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4165
sendTimeout:seconds
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4166
    "set the send timeout - for special applications only.
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4167
     Not all operatingSystems offer this functionality
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4168
     (returns false, if unsupported)"
81
claus
parents: 79
diff changeset
  4169
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4170
    |millis|
25
996051271ce9 *** empty log message ***
claus
parents: 21
diff changeset
  4171
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4172
    filePointer isNil ifTrue:[
789
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  4173
	^ self errorNotOpen
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4174
    ].
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4175
    millis := (seconds * 1000) rounded.
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4176
%{
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4177
#if defined(SO_SNDTIMEO) && defined(SOL_SOCKET) && defined(HZ)
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4178
    if (__isSmallInteger(millis)) {
789
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  4179
	OBJ fp = __INST(filePointer);
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  4180
	int sock;
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  4181
	int opt;
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  4182
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  4183
	sock = fileno(__FILEVal(fp));
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  4184
	opt = _intVal(millis) / (1000 / HZ);
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  4185
	setsockopt(sock, SOL_SOCKET, SO_SNDTIMEO, (char *)&opt, sizeof(int));
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  4186
	RETURN(true);
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4187
    }
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4188
#endif
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4189
%}.
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4190
    ^ false
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4191
! !
82
claus
parents: 81
diff changeset
  4192
464
600b101a7035 alen in accept
Claus Gittinger <cg@exept.de>
parents: 463
diff changeset
  4193
!Socket class methodsFor:'documentation'!
206
77166a6b3ee6 For ST80 style socket creation: register socket in Lobby.
Stefan Vogel <sv@exept.de>
parents: 203
diff changeset
  4194
77166a6b3ee6 For ST80 style socket creation: register socket in Lobby.
Stefan Vogel <sv@exept.de>
parents: 203
diff changeset
  4195
version
790
6f58d65fac5e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 789
diff changeset
  4196
    ^ '$Header: /cvs/stx/stx/libbasic2/Socket.st,v 1.124 1999-08-11 14:42:43 cg Exp $'
206
77166a6b3ee6 For ST80 style socket creation: register socket in Lobby.
Stefan Vogel <sv@exept.de>
parents: 203
diff changeset
  4197
! !