Socket.st
author penk
Mon, 31 Mar 2003 11:34:18 +0200
changeset 1170 270d76fc288f
parent 1146 71a9df78ba9e
child 1185 7b269562f7b4
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
888
a868b0e54a2b ipAddress stuff
Claus Gittinger <cg@exept.de>
parents: 887
diff changeset
    13
"{ Package: 'stx:libbasic2' }"
a868b0e54a2b ipAddress stuff
Claus Gittinger <cg@exept.de>
parents: 887
diff changeset
    14
63
7dd3d5b7877e *** empty log message ***
claus
parents: 58
diff changeset
    15
NonPositionableExternalStream subclass:#Socket
206
77166a6b3ee6 For ST80 style socket creation: register socket in Lobby.
Stefan Vogel <sv@exept.de>
parents: 203
diff changeset
    16
	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
    17
	classVariableNames:''
77166a6b3ee6 For ST80 style socket creation: register socket in Lobby.
Stefan Vogel <sv@exept.de>
parents: 203
diff changeset
    18
	poolDictionaries:''
77166a6b3ee6 For ST80 style socket creation: register socket in Lobby.
Stefan Vogel <sv@exept.de>
parents: 203
diff changeset
    19
	category:'Streams-External'
0
1cf8d1747859 Initial revision
claus
parents:
diff changeset
    20
!
1cf8d1747859 Initial revision
claus
parents:
diff changeset
    21
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
    22
!Socket primitiveDefinitions!
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
    23
%{
444
9ba31a1fba38 always unbuffered on linux
Claus Gittinger <cg@exept.de>
parents: 430
diff changeset
    24
1009
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
    25
/* #define DGRAM_DEBUG /* */
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
    26
444
9ba31a1fba38 always unbuffered on linux
Claus Gittinger <cg@exept.de>
parents: 430
diff changeset
    27
#ifdef LINUX
9ba31a1fba38 always unbuffered on linux
Claus Gittinger <cg@exept.de>
parents: 430
diff changeset
    28
# define BUGGY_STDIO_LIB
822
a08e230988fe *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 821
diff changeset
    29
# include <linux/version.h>
a08e230988fe *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 821
diff changeset
    30
a08e230988fe *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 821
diff changeset
    31
# ifndef KERNEL_VERSION
a08e230988fe *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 821
diff changeset
    32
#  define KERNEL_VERSION(a,b,c) (((a) << 16) + ((b) << 8) + (c))
a08e230988fe *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 821
diff changeset
    33
# endif
a08e230988fe *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 821
diff changeset
    34
#endif /* LINUX */
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
    35
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
    36
#include <stdio.h>
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
    37
#include <errno.h>
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
    38
533
ced9950b551f added query about which protocols are supported
Claus Gittinger <cg@exept.de>
parents: 532
diff changeset
    39
#define UNIX_LIKE
ced9950b551f added query about which protocols are supported
Claus Gittinger <cg@exept.de>
parents: 532
diff changeset
    40
ced9950b551f added query about which protocols are supported
Claus Gittinger <cg@exept.de>
parents: 532
diff changeset
    41
#if defined(transputer)
ced9950b551f added query about which protocols are supported
Claus Gittinger <cg@exept.de>
parents: 532
diff changeset
    42
# undef UNIX_LIKE
418
317e55c6c281 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 403
diff changeset
    43
# define NO_SOCKET
317e55c6c281 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 403
diff changeset
    44
#endif
317e55c6c281 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 403
diff changeset
    45
525
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
    46
/*
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
    47
 * which protocols can we support ?
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
    48
 */
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
    49
#ifndef NO_SOCKET
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
    50
# define WANT__AF_INET
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
    51
#endif
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
    52
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
    53
#ifdef UNIX_LIKE
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
    54
# define WANT__AF_UNIX
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
    55
#endif
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
    56
563
23a6b265bdd0 VMS stuff
Claus Gittinger <cg@exept.de>
parents: 559
diff changeset
    57
#ifdef __VMS__
23a6b265bdd0 VMS stuff
Claus Gittinger <cg@exept.de>
parents: 559
diff changeset
    58
# undef WANT__AF_UNIX
571
191b37534643 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 563
diff changeset
    59
# define WANT_AF_DECnet
563
23a6b265bdd0 VMS stuff
Claus Gittinger <cg@exept.de>
parents: 559
diff changeset
    60
#endif
23a6b265bdd0 VMS stuff
Claus Gittinger <cg@exept.de>
parents: 559
diff changeset
    61
527
f48fd11817e2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 526
diff changeset
    62
#ifdef LINUX
822
a08e230988fe *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 821
diff changeset
    63
# ifndef LINUX_VERSION_CODE
a08e230988fe *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 821
diff changeset
    64
   /* PRE 2.0 Linux kernel. */
a08e230988fe *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 821
diff changeset
    65
# else
a08e230988fe *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 821
diff changeset
    66
#  if LINUX_VERSION_CODE < KERNEL_VERSION(2,0,0)
a08e230988fe *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 821
diff changeset
    67
   /* PRE 2.0 Linux kernel. */
a08e230988fe *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 821
diff changeset
    68
#  else
a08e230988fe *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 821
diff changeset
    69
#   if LINUX_VERSION_CODE >= KERNEL_VERSION(2,1,0)
a08e230988fe *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 821
diff changeset
    70
#    define WANT__AF_APPLETALK
a08e230988fe *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 821
diff changeset
    71
#    define xxWANT__AF_X25
a08e230988fe *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 821
diff changeset
    72
#    define xxWANT__AF_AX25
a08e230988fe *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 821
diff changeset
    73
#    define xxWANT__AF_IPX
a08e230988fe *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 821
diff changeset
    74
#    define WANT__AF_INET6 */
869
a6e5cbe9f558 preps for AF_IRDA
Claus Gittinger <cg@exept.de>
parents: 867
diff changeset
    75
#    if LINUX_VERSION_CODE >= KERNEL_VERSION(2,2,0)
875
5e284df91764 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 874
diff changeset
    76
#     define xxWANT__AF_IRDA */
869
a6e5cbe9f558 preps for AF_IRDA
Claus Gittinger <cg@exept.de>
parents: 867
diff changeset
    77
#    endif /* >= 2.2.0 */
822
a08e230988fe *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 821
diff changeset
    78
#   endif /* >= 2.1.0 */
a08e230988fe *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 821
diff changeset
    79
#  endif /* pre 2.0.0 */
a08e230988fe *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 821
diff changeset
    80
# endif /* pre 2.0.0 */
a08e230988fe *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 821
diff changeset
    81
#endif /* LINIX */
525
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
    82
819
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
    83
#ifdef solaris2_0
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
    84
# define xxxWANT__AF_DECNET
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
    85
#endif
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
    86
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
    87
#ifdef LINUX
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
    88
/* kludge to avoid some redefines ... */
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
    89
# define _ARPA_NAMESER_H
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
    90
# define _NETINET_TCP_H
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
    91
#endif
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
    92
739
eb3878300c3b removed WIN32 ifdef's - win32 uses Socket_win32.st anyway.
Claus Gittinger <cg@exept.de>
parents: 726
diff changeset
    93
#if !defined(NO_SOCKET)
eb3878300c3b removed WIN32 ifdef's - win32 uses Socket_win32.st anyway.
Claus Gittinger <cg@exept.de>
parents: 726
diff changeset
    94
# include <fcntl.h>
eb3878300c3b removed WIN32 ifdef's - win32 uses Socket_win32.st anyway.
Claus Gittinger <cg@exept.de>
parents: 726
diff changeset
    95
# include <sys/types.h>
eb3878300c3b removed WIN32 ifdef's - win32 uses Socket_win32.st anyway.
Claus Gittinger <cg@exept.de>
parents: 726
diff changeset
    96
# 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
    97
eb3878300c3b removed WIN32 ifdef's - win32 uses Socket_win32.st anyway.
Claus Gittinger <cg@exept.de>
parents: 726
diff changeset
    98
# 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
    99
   /* 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
   100
#  ifndef AF_UNIX
eb3878300c3b removed WIN32 ifdef's - win32 uses Socket_win32.st anyway.
Claus Gittinger <cg@exept.de>
parents: 726
diff changeset
   101
#   define AF_UNIX 1
eb3878300c3b removed WIN32 ifdef's - win32 uses Socket_win32.st anyway.
Claus Gittinger <cg@exept.de>
parents: 726
diff changeset
   102
#  endif
eb3878300c3b removed WIN32 ifdef's - win32 uses Socket_win32.st anyway.
Claus Gittinger <cg@exept.de>
parents: 726
diff changeset
   103
#  ifndef AF_INET
eb3878300c3b removed WIN32 ifdef's - win32 uses Socket_win32.st anyway.
Claus Gittinger <cg@exept.de>
parents: 726
diff changeset
   104
#   define AF_INET 2
eb3878300c3b removed WIN32 ifdef's - win32 uses Socket_win32.st anyway.
Claus Gittinger <cg@exept.de>
parents: 726
diff changeset
   105
#  endif
789
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
   106
739
eb3878300c3b removed WIN32 ifdef's - win32 uses Socket_win32.st anyway.
Claus Gittinger <cg@exept.de>
parents: 726
diff changeset
   107
#  ifndef SOCK_STREAM
eb3878300c3b removed WIN32 ifdef's - win32 uses Socket_win32.st anyway.
Claus Gittinger <cg@exept.de>
parents: 726
diff changeset
   108
#   define SOCK_STREAM 1
eb3878300c3b removed WIN32 ifdef's - win32 uses Socket_win32.st anyway.
Claus Gittinger <cg@exept.de>
parents: 726
diff changeset
   109
#  endif
eb3878300c3b removed WIN32 ifdef's - win32 uses Socket_win32.st anyway.
Claus Gittinger <cg@exept.de>
parents: 726
diff changeset
   110
#  ifndef SOCK_DGRAM
eb3878300c3b removed WIN32 ifdef's - win32 uses Socket_win32.st anyway.
Claus Gittinger <cg@exept.de>
parents: 726
diff changeset
   111
#   define SOCK_DGRAM  2
eb3878300c3b removed WIN32 ifdef's - win32 uses Socket_win32.st anyway.
Claus Gittinger <cg@exept.de>
parents: 726
diff changeset
   112
#  endif
eb3878300c3b removed WIN32 ifdef's - win32 uses Socket_win32.st anyway.
Claus Gittinger <cg@exept.de>
parents: 726
diff changeset
   113
#  ifndef SOCK_RAW
eb3878300c3b removed WIN32 ifdef's - win32 uses Socket_win32.st anyway.
Claus Gittinger <cg@exept.de>
parents: 726
diff changeset
   114
#   define SOCK_RAW    3
eb3878300c3b removed WIN32 ifdef's - win32 uses Socket_win32.st anyway.
Claus Gittinger <cg@exept.de>
parents: 726
diff changeset
   115
#  endif
656
fcd2139d83a5 borland-C support
Claus Gittinger <cg@exept.de>
parents: 653
diff changeset
   116
# else
739
eb3878300c3b removed WIN32 ifdef's - win32 uses Socket_win32.st anyway.
Claus Gittinger <cg@exept.de>
parents: 726
diff changeset
   117
#  include <sys/socket.h>
506
11ef93d12870 support anonymous (OS_specified) ports. (for FTP-protocol)
Claus Gittinger <cg@exept.de>
parents: 486
diff changeset
   118
# endif
739
eb3878300c3b removed WIN32 ifdef's - win32 uses Socket_win32.st anyway.
Claus Gittinger <cg@exept.de>
parents: 726
diff changeset
   119
eb3878300c3b removed WIN32 ifdef's - win32 uses Socket_win32.st anyway.
Claus Gittinger <cg@exept.de>
parents: 726
diff changeset
   120
# ifdef NEXT3
eb3878300c3b removed WIN32 ifdef's - win32 uses Socket_win32.st anyway.
Claus Gittinger <cg@exept.de>
parents: 726
diff changeset
   121
#  include <netinet/in_systm.h>
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   122
# endif
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   123
#endif
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   124
525
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
   125
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   126
/*
528
928f68d9c080 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 527
diff changeset
   127
 * see what we want ...
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   128
 */
525
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
   129
#ifdef WANT__AF_UNIX
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
   130
# ifdef AF_UNIX
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
   131
#  ifndef PF_UNIX
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
   132
#   define PF_UNIX AF_UNIX
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
   133
#  endif
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   134
# endif
525
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
   135
#else
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
   136
# undef AF_UNIX
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
   137
#endif
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
   138
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
   139
#ifdef WANT__AF_INET
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
   140
# ifdef AF_INET
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
   141
#  ifndef PF_INET
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
   142
#   define PF_INET AF_INET
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
   143
#  endif
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
   144
# endif
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
   145
#else
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
   146
# undef AF_INET
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   147
#endif
525
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
   148
530
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
   149
#ifdef WANT__AF_INET6
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
   150
# ifdef AF_INET6
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
   151
#  ifndef PF_INET6
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
   152
#   define PF_INET6 AF_INET6
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
   153
#  endif
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
   154
# endif
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
   155
#else
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
   156
# undef AF_INET6
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
   157
#endif
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
   158
525
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
   159
#ifdef WANT__AF_DECnet
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
   160
# ifdef AF_DECnet
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
   161
#  ifndef PF_DECnet
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
   162
#   define PF_DECnet AF_DECnet
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
   163
#  endif
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
   164
# endif
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
   165
#else
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
   166
# undef AF_DECnet
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
   167
#endif
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
   168
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
   169
#ifdef WANT__AF_APPLETALK
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
   170
# ifdef AF_APPLETALK
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
   171
#  ifndef PF_APPLETALK
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
   172
#   define PF_APPLETALK AF_APPLETALK
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
   173
#  endif
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   174
# endif
525
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
   175
#else
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
   176
# undef AF_APPLETALK
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   177
#endif
525
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
   178
533
ced9950b551f added query about which protocols are supported
Claus Gittinger <cg@exept.de>
parents: 532
diff changeset
   179
#ifdef WANT__AF_X25     /* X.25 */
525
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
   180
# ifdef AF_X25
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
   181
#  ifndef PF_X25
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
   182
#   define PF_X25 AF_X25
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
   183
#  endif
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
#else
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
   186
# undef AF_X25
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
   187
#endif
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
   188
533
ced9950b551f added query about which protocols are supported
Claus Gittinger <cg@exept.de>
parents: 532
diff changeset
   189
#ifdef WANT__AF_NS      /* Xerox XNS */
525
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
   190
# ifdef AF_NS
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
   191
#  ifndef PF_NS
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
   192
#   define PF_NS AF_NS
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
   193
#  endif
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   194
# endif
525
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
   195
#else
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
   196
# undef AF_NS
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   197
#endif
525
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
   198
533
ced9950b551f added query about which protocols are supported
Claus Gittinger <cg@exept.de>
parents: 532
diff changeset
   199
#ifdef WANT__AF_SNA     /* IBM SNA */
525
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
   200
# ifdef AF_SNA
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
   201
#  ifndef PF_SNA
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
   202
#   define PF_SNA AF_SNA
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
   203
#  endif
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   204
# endif
525
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
   205
#else
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
   206
# undef AF_SNA
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
   207
#endif
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
   208
533
ced9950b551f added query about which protocols are supported
Claus Gittinger <cg@exept.de>
parents: 532
diff changeset
   209
#ifdef WANT__AF_RAW     /* RAW packets */
525
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
   210
# ifdef AF_RAW
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
   211
#  ifndef PF_RAW
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
   212
#   define PF_RAW AF_RAW
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
   213
#  endif
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
#else
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
   216
# undef AF_RAW
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   217
#endif
525
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
   218
533
ced9950b551f added query about which protocols are supported
Claus Gittinger <cg@exept.de>
parents: 532
diff changeset
   219
#ifdef WANT__AF_ISO     /* ? */
525
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
   220
# ifdef AF_ISO
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
   221
#  ifndef PF_ISO
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
   222
#   define PF_ISO AF_ISO
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
   223
#  endif
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
   224
# endif
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
   225
#else
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
   226
# undef AF_ISO
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
   227
#endif
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
   228
823
85c20f9e71de *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 822
diff changeset
   229
#ifdef WANT__AF_NETBIOS /* NETBIOS */
525
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
   230
# ifdef AF_NETBIOS
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
   231
#  ifndef PF_NETBIOS
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
   232
#   define PF_NETBIOS AF_NETBIOS
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
   233
#  endif
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   234
# endif
525
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
   235
#else
533
ced9950b551f added query about which protocols are supported
Claus Gittinger <cg@exept.de>
parents: 532
diff changeset
   236
# undef AF_NETBIOS
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   237
#endif
525
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
   238
530
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
   239
#ifdef WANT__AF_CCITT /* ? */
525
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
   240
# if defined(AF_CCITT) && (AF_CCITT != AF_X25)
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
   241
#  ifndef PF_CCITT
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
   242
#   define PF_CCITT AF_CCITT
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
   243
#  endif
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
   244
# endif
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
   245
#else
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
   246
# undef AF_CCITT
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
   247
#endif
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
   248
530
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
   249
#ifdef WANT__AF_IPX /* Novell IPX */
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
   250
# ifdef AF_IPX
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
   251
#  ifndef PF_IPX
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
   252
#   define PF_IPX AF_IPX
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
   253
#  endif
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
   254
# endif
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
   255
#else
533
ced9950b551f added query about which protocols are supported
Claus Gittinger <cg@exept.de>
parents: 532
diff changeset
   256
# undef AF_IPX
530
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
   257
#endif
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
   258
812
c8101ea70e6c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 811
diff changeset
   259
#ifdef WANT__AF_AX25 /* Amateur Radio AX.25 */
530
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
   260
# ifdef AF_AX25
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
   261
#  ifndef PF_AX25
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
   262
#   define PF_AX25 AF_AX25
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
   263
#  endif
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
   264
# endif
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
   265
#else
533
ced9950b551f added query about which protocols are supported
Claus Gittinger <cg@exept.de>
parents: 532
diff changeset
   266
# undef AF_AX25
530
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
   267
#endif
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
   268
812
c8101ea70e6c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 811
diff changeset
   269
#ifdef WANT__AF_NETROM /* Amateur Radio NET/ROM */
530
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
   270
# ifdef AF_NETROM
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
   271
#  ifndef PF_NETROM
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
   272
#   define PF_NETROM AF_NETROM
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
   273
#  endif
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
   274
# endif
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
   275
#else
533
ced9950b551f added query about which protocols are supported
Claus Gittinger <cg@exept.de>
parents: 532
diff changeset
   276
# undef AF_NETROM
530
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
   277
#endif
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
   278
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
   279
#ifdef WANT__AF_BRIDGE /* multiprotocol bridge */
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
   280
# ifdef AF_BRIDGE
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
   281
#  ifndef PF_BRIDGE
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
   282
#   define PF_BRIDGE AF_BRIDGE
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
   283
#  endif
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
   284
# endif
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
   285
#else
533
ced9950b551f added query about which protocols are supported
Claus Gittinger <cg@exept.de>
parents: 532
diff changeset
   286
# undef AF_BRIDGE
530
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
   287
#endif
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
   288
571
191b37534643 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 563
diff changeset
   289
#ifdef WANT__AF_BSC /* BISYNC 2780/3780 */
191b37534643 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 563
diff changeset
   290
# ifdef AF_BSC
191b37534643 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 563
diff changeset
   291
#  ifndef PF_BSC
191b37534643 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 563
diff changeset
   292
#   define PF_BSC AF_BSC
191b37534643 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 563
diff changeset
   293
#  endif
191b37534643 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 563
diff changeset
   294
# endif
191b37534643 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 563
diff changeset
   295
#else
191b37534643 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 563
diff changeset
   296
# undef AF_BSC
191b37534643 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 563
diff changeset
   297
#endif
191b37534643 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 563
diff changeset
   298
812
c8101ea70e6c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 811
diff changeset
   299
#ifdef WANT__AF_ROSE /* Amateur Radio X.25 PLP */
814
d0e45218532d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 812
diff changeset
   300
# ifdef AF_ROSE
d0e45218532d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 812
diff changeset
   301
#  ifndef PF_ROSE
d0e45218532d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 812
diff changeset
   302
#   define PF_ROSE AF_ROSE
812
c8101ea70e6c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 811
diff changeset
   303
#  endif
c8101ea70e6c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 811
diff changeset
   304
# endif
c8101ea70e6c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 811
diff changeset
   305
#else
814
d0e45218532d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 812
diff changeset
   306
# undef AF_ROSE
812
c8101ea70e6c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 811
diff changeset
   307
#endif
c8101ea70e6c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 811
diff changeset
   308
823
85c20f9e71de *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 822
diff changeset
   309
#ifdef WANT__AF_ATM /* ATM Services */
85c20f9e71de *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 822
diff changeset
   310
# ifdef AF_ATM
85c20f9e71de *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 822
diff changeset
   311
#  ifndef PF_ATM
85c20f9e71de *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 822
diff changeset
   312
#   define PF_ATM AF_ATM
85c20f9e71de *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 822
diff changeset
   313
#  endif
85c20f9e71de *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 822
diff changeset
   314
# endif
85c20f9e71de *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 822
diff changeset
   315
#else
85c20f9e71de *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 822
diff changeset
   316
# undef AF_ATM
85c20f9e71de *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 822
diff changeset
   317
#endif
85c20f9e71de *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 822
diff changeset
   318
85c20f9e71de *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 822
diff changeset
   319
#ifdef WANT__AF_BAN /* BAN / VINES IP Services */
85c20f9e71de *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 822
diff changeset
   320
# ifdef AF_BAN
85c20f9e71de *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 822
diff changeset
   321
#  ifndef PF_BAN
85c20f9e71de *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 822
diff changeset
   322
#   define PF_BAN AF_BAN
85c20f9e71de *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 822
diff changeset
   323
#  endif
85c20f9e71de *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 822
diff changeset
   324
# endif
85c20f9e71de *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 822
diff changeset
   325
#else
85c20f9e71de *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 822
diff changeset
   326
# undef AF_BAN
85c20f9e71de *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 822
diff changeset
   327
#endif
85c20f9e71de *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 822
diff changeset
   328
85c20f9e71de *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 822
diff changeset
   329
#ifdef WANT__AF_VOICEVIEW /* VoiceView Services W95 only */
85c20f9e71de *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 822
diff changeset
   330
# ifdef AF_VOICEVIEW
85c20f9e71de *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 822
diff changeset
   331
#  ifndef PF_VOICEVIEW
85c20f9e71de *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 822
diff changeset
   332
#   define PF_VOICEVIEW AF_VOICEVIEW
85c20f9e71de *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 822
diff changeset
   333
#  endif
85c20f9e71de *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 822
diff changeset
   334
# endif
85c20f9e71de *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 822
diff changeset
   335
#else
85c20f9e71de *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 822
diff changeset
   336
# undef AF_VOICEVIEW
85c20f9e71de *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 822
diff changeset
   337
#endif
85c20f9e71de *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 822
diff changeset
   338
869
a6e5cbe9f558 preps for AF_IRDA
Claus Gittinger <cg@exept.de>
parents: 867
diff changeset
   339
#ifdef WANT__AF_IRDA /* infrared */
a6e5cbe9f558 preps for AF_IRDA
Claus Gittinger <cg@exept.de>
parents: 867
diff changeset
   340
# ifdef AF_IRDA
a6e5cbe9f558 preps for AF_IRDA
Claus Gittinger <cg@exept.de>
parents: 867
diff changeset
   341
#  ifndef PF_IRDA
a6e5cbe9f558 preps for AF_IRDA
Claus Gittinger <cg@exept.de>
parents: 867
diff changeset
   342
#   define PF_IRDA AF_IRDA
a6e5cbe9f558 preps for AF_IRDA
Claus Gittinger <cg@exept.de>
parents: 867
diff changeset
   343
#  endif
a6e5cbe9f558 preps for AF_IRDA
Claus Gittinger <cg@exept.de>
parents: 867
diff changeset
   344
# endif
a6e5cbe9f558 preps for AF_IRDA
Claus Gittinger <cg@exept.de>
parents: 867
diff changeset
   345
#else
a6e5cbe9f558 preps for AF_IRDA
Claus Gittinger <cg@exept.de>
parents: 867
diff changeset
   346
# undef AF_IRDA
a6e5cbe9f558 preps for AF_IRDA
Claus Gittinger <cg@exept.de>
parents: 867
diff changeset
   347
#endif
a6e5cbe9f558 preps for AF_IRDA
Claus Gittinger <cg@exept.de>
parents: 867
diff changeset
   348
571
191b37534643 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 563
diff changeset
   349
528
928f68d9c080 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 527
diff changeset
   350
/*
928f68d9c080 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 527
diff changeset
   351
 * now, include what we have to ...
819
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
   352
 * undef support, if no include file is present
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
   353
 * (or I dont know yet, where to find it)
528
928f68d9c080 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 527
diff changeset
   354
 */
739
eb3878300c3b removed WIN32 ifdef's - win32 uses Socket_win32.st anyway.
Claus Gittinger <cg@exept.de>
parents: 726
diff changeset
   355
823
85c20f9e71de *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 822
diff changeset
   356
#ifdef AF_UNIX
85c20f9e71de *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 822
diff changeset
   357
# ifdef UNIX
85c20f9e71de *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 822
diff changeset
   358
#  include <sys/un.h>
85c20f9e71de *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 822
diff changeset
   359
# else
85c20f9e71de *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 822
diff changeset
   360
#  undef AF_UNIX
85c20f9e71de *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 822
diff changeset
   361
# endif
85c20f9e71de *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 822
diff changeset
   362
#endif
85c20f9e71de *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 822
diff changeset
   363
739
eb3878300c3b removed WIN32 ifdef's - win32 uses Socket_win32.st anyway.
Claus Gittinger <cg@exept.de>
parents: 726
diff changeset
   364
#ifdef AF_INET
eb3878300c3b removed WIN32 ifdef's - win32 uses Socket_win32.st anyway.
Claus Gittinger <cg@exept.de>
parents: 726
diff changeset
   365
# include <netdb.h>
969
ea88dde53584 includes for suse7.2
penk
parents: 968
diff changeset
   366
# if defined(PRE_SUSE_7_2)
ea88dde53584 includes for suse7.2
penk
parents: 968
diff changeset
   367
#  if defined(LINUX) && defined(AF_INET6)
ea88dde53584 includes for suse7.2
penk
parents: 968
diff changeset
   368
#   include <linux/in.h>
ea88dde53584 includes for suse7.2
penk
parents: 968
diff changeset
   369
#  else
ea88dde53584 includes for suse7.2
penk
parents: 968
diff changeset
   370
#   include <netinet/in.h>
ea88dde53584 includes for suse7.2
penk
parents: 968
diff changeset
   371
#  endif
739
eb3878300c3b removed WIN32 ifdef's - win32 uses Socket_win32.st anyway.
Claus Gittinger <cg@exept.de>
parents: 726
diff changeset
   372
# else
eb3878300c3b removed WIN32 ifdef's - win32 uses Socket_win32.st anyway.
Claus Gittinger <cg@exept.de>
parents: 726
diff changeset
   373
#  include <netinet/in.h>
eb3878300c3b removed WIN32 ifdef's - win32 uses Socket_win32.st anyway.
Claus Gittinger <cg@exept.de>
parents: 726
diff changeset
   374
# endif
969
ea88dde53584 includes for suse7.2
penk
parents: 968
diff changeset
   375
# if !defined(LINUX)
ea88dde53584 includes for suse7.2
penk
parents: 968
diff changeset
   376
#  if ! (defined(SYSV3) && defined(mc88k))
ea88dde53584 includes for suse7.2
penk
parents: 968
diff changeset
   377
#   include <netinet/tcp.h>
ea88dde53584 includes for suse7.2
penk
parents: 968
diff changeset
   378
#  endif
739
eb3878300c3b removed WIN32 ifdef's - win32 uses Socket_win32.st anyway.
Claus Gittinger <cg@exept.de>
parents: 726
diff changeset
   379
# endif
eb3878300c3b removed WIN32 ifdef's - win32 uses Socket_win32.st anyway.
Claus Gittinger <cg@exept.de>
parents: 726
diff changeset
   380
#endif
eb3878300c3b removed WIN32 ifdef's - win32 uses Socket_win32.st anyway.
Claus Gittinger <cg@exept.de>
parents: 726
diff changeset
   381
eb3878300c3b removed WIN32 ifdef's - win32 uses Socket_win32.st anyway.
Claus Gittinger <cg@exept.de>
parents: 726
diff changeset
   382
#ifdef AF_INET6
819
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
   383
# if defined(LINUX) && defined(__GLIBC__)
969
ea88dde53584 includes for suse7.2
penk
parents: 968
diff changeset
   384
#  if defined(PRE_SUSE_7_2)
ea88dde53584 includes for suse7.2
penk
parents: 968
diff changeset
   385
#   include <linux/in6.h>
ea88dde53584 includes for suse7.2
penk
parents: 968
diff changeset
   386
#  endif
819
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
   387
# else
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
   388
#  undef AF_INET6
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   389
# endif
739
eb3878300c3b removed WIN32 ifdef's - win32 uses Socket_win32.st anyway.
Claus Gittinger <cg@exept.de>
parents: 726
diff changeset
   390
#endif
eb3878300c3b removed WIN32 ifdef's - win32 uses Socket_win32.st anyway.
Claus Gittinger <cg@exept.de>
parents: 726
diff changeset
   391
eb3878300c3b removed WIN32 ifdef's - win32 uses Socket_win32.st anyway.
Claus Gittinger <cg@exept.de>
parents: 726
diff changeset
   392
#ifdef AF_APPLETALK
eb3878300c3b removed WIN32 ifdef's - win32 uses Socket_win32.st anyway.
Claus Gittinger <cg@exept.de>
parents: 726
diff changeset
   393
# ifdef LINUX
eb3878300c3b removed WIN32 ifdef's - win32 uses Socket_win32.st anyway.
Claus Gittinger <cg@exept.de>
parents: 726
diff changeset
   394
#  include <asm/types.h>
eb3878300c3b removed WIN32 ifdef's - win32 uses Socket_win32.st anyway.
Claus Gittinger <cg@exept.de>
parents: 726
diff changeset
   395
#  include <linux/atalk.h>
819
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
   396
# else
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
   397
#  undef AF_APPLETALK
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
   398
# endif
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
   399
#endif
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
   400
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
   401
#ifdef AF_DECNET
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
   402
# ifdef solaris2_0
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
   403
#  include <X11/dni8.h>
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
   404
# else
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
   405
#  undef AF_DECNET
465
3673e44dbd2f remove windows ^M characters
Claus Gittinger <cg@exept.de>
parents: 464
diff changeset
   406
# endif
739
eb3878300c3b removed WIN32 ifdef's - win32 uses Socket_win32.st anyway.
Claus Gittinger <cg@exept.de>
parents: 726
diff changeset
   407
#endif
eb3878300c3b removed WIN32 ifdef's - win32 uses Socket_win32.st anyway.
Claus Gittinger <cg@exept.de>
parents: 726
diff changeset
   408
812
c8101ea70e6c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 811
diff changeset
   409
#ifdef AF_X25
c8101ea70e6c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 811
diff changeset
   410
# ifdef LINUX
c8101ea70e6c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 811
diff changeset
   411
#  include <linux/x25.h>
819
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
   412
# else
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
   413
#  undef AF_X25
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
   414
# endif
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
   415
#endif
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
   416
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
   417
#ifdef AF_AX25
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
   418
# ifdef LINUX
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
   419
#  include <linux/ax25.h>
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
   420
# else
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
   421
#  undef AF_AX25
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
   422
# endif
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
   423
#endif
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
   424
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
   425
#ifdef AF_IPX
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
   426
# ifdef LINUX
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
   427
#  include <linux/ipx.h>
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
   428
# else
823
85c20f9e71de *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 822
diff changeset
   429
#  ifdef WIN32
85c20f9e71de *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 822
diff changeset
   430
#   include <wsipx.h>
85c20f9e71de *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 822
diff changeset
   431
#  else
85c20f9e71de *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 822
diff changeset
   432
#   undef AF_IPX
85c20f9e71de *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 822
diff changeset
   433
#  endif
85c20f9e71de *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 822
diff changeset
   434
# endif
85c20f9e71de *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 822
diff changeset
   435
#endif
85c20f9e71de *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 822
diff changeset
   436
85c20f9e71de *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 822
diff changeset
   437
#ifdef AF_NETBIOS
85c20f9e71de *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 822
diff changeset
   438
# ifdef WIN32
85c20f9e71de *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 822
diff changeset
   439
#  include <wsnetbs.h>
85c20f9e71de *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 822
diff changeset
   440
# else
85c20f9e71de *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 822
diff changeset
   441
#  undef AF_NETBIOS
85c20f9e71de *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 822
diff changeset
   442
# endif
85c20f9e71de *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 822
diff changeset
   443
#endif
85c20f9e71de *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 822
diff changeset
   444
85c20f9e71de *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 822
diff changeset
   445
#ifdef AF_ATM
85c20f9e71de *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 822
diff changeset
   446
# ifdef WIN32
85c20f9e71de *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 822
diff changeset
   447
#  include <ws2atm.h>
85c20f9e71de *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 822
diff changeset
   448
# else
85c20f9e71de *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 822
diff changeset
   449
#  undef AF_ATM
812
c8101ea70e6c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 811
diff changeset
   450
# endif
c8101ea70e6c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 811
diff changeset
   451
#endif
c8101ea70e6c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 811
diff changeset
   452
823
85c20f9e71de *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 822
diff changeset
   453
#ifdef AF_BAN
85c20f9e71de *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 822
diff changeset
   454
# ifdef WIN32
85c20f9e71de *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 822
diff changeset
   455
#  include <wsvns.h>
85c20f9e71de *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 822
diff changeset
   456
# else
85c20f9e71de *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 822
diff changeset
   457
#  undef AF_BAN
85c20f9e71de *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 822
diff changeset
   458
# endif
85c20f9e71de *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 822
diff changeset
   459
#endif
85c20f9e71de *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 822
diff changeset
   460
85c20f9e71de *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 822
diff changeset
   461
#ifdef AF_VOICEVIEW
85c20f9e71de *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 822
diff changeset
   462
# ifdef WIN32
85c20f9e71de *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 822
diff changeset
   463
#  include <wsvv.h>
85c20f9e71de *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 822
diff changeset
   464
# else
85c20f9e71de *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 822
diff changeset
   465
#  undef AF_VOICEVIEW
85c20f9e71de *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 822
diff changeset
   466
# endif
85c20f9e71de *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 822
diff changeset
   467
#endif
85c20f9e71de *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 822
diff changeset
   468
869
a6e5cbe9f558 preps for AF_IRDA
Claus Gittinger <cg@exept.de>
parents: 867
diff changeset
   469
#ifdef AF_IRDA
a6e5cbe9f558 preps for AF_IRDA
Claus Gittinger <cg@exept.de>
parents: 867
diff changeset
   470
# ifdef LINUX
a6e5cbe9f558 preps for AF_IRDA
Claus Gittinger <cg@exept.de>
parents: 867
diff changeset
   471
#  include <linux/irda.h>
a6e5cbe9f558 preps for AF_IRDA
Claus Gittinger <cg@exept.de>
parents: 867
diff changeset
   472
# else
a6e5cbe9f558 preps for AF_IRDA
Claus Gittinger <cg@exept.de>
parents: 867
diff changeset
   473
#  undef AF_IRDA
a6e5cbe9f558 preps for AF_IRDA
Claus Gittinger <cg@exept.de>
parents: 867
diff changeset
   474
# endif
a6e5cbe9f558 preps for AF_IRDA
Claus Gittinger <cg@exept.de>
parents: 867
diff changeset
   475
#endif
a6e5cbe9f558 preps for AF_IRDA
Claus Gittinger <cg@exept.de>
parents: 867
diff changeset
   476
823
85c20f9e71de *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 822
diff changeset
   477
#undef AF_SNA     /* not yet implemented */
85c20f9e71de *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 822
diff changeset
   478
#undef AF_RAW     /* not yet implemented */
85c20f9e71de *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 822
diff changeset
   479
#undef AF_NETROM  /* not yet implemented */
85c20f9e71de *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 822
diff changeset
   480
#undef AF_BRIDGE  /* not yet implemented */
85c20f9e71de *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 822
diff changeset
   481
#undef AF_BSC     /* not yet implemented */
85c20f9e71de *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 822
diff changeset
   482
819
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
   483
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
   484
/*
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
   485
 * see what is leftOver
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
   486
 */
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
   487
union sockaddr_u {
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
   488
#ifdef AF_UNIX
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
   489
	struct sockaddr_un un;
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
   490
#endif
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
   491
#ifdef AF_INET
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
   492
	struct sockaddr_in in;
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
   493
#endif
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
   494
#ifdef AF_INET6
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
   495
	struct sockaddr_in6 in6;
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
   496
#endif
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
   497
#ifdef AF_APPLETALK
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
   498
	struct sockaddr_at at;
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
   499
#endif
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
   500
#ifdef AF_DECNET
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
   501
	struct sockaddr_dn dn;
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
   502
#endif
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
   503
#ifdef AF_X25
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
   504
	struct sockaddr_x25 x25;
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
   505
#endif
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
   506
#ifdef AF_AX25
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
   507
	struct sockaddr_ax25 ax25;
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
   508
#endif
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
   509
#ifdef AF_IPX
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
   510
	struct sockaddr_ipx ipx;
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
   511
#endif
823
85c20f9e71de *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 822
diff changeset
   512
#ifdef AF_NETBIOS
85c20f9e71de *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 822
diff changeset
   513
	struct sockaddr_nb nb;
85c20f9e71de *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 822
diff changeset
   514
#endif
85c20f9e71de *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 822
diff changeset
   515
#ifdef AF_ATM
85c20f9e71de *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 822
diff changeset
   516
	struct sockaddr_atm atm;
85c20f9e71de *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 822
diff changeset
   517
#endif
85c20f9e71de *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 822
diff changeset
   518
#ifdef AF_BAN
85c20f9e71de *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 822
diff changeset
   519
	struct sockaddr_vns vns;
85c20f9e71de *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 822
diff changeset
   520
#endif
85c20f9e71de *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 822
diff changeset
   521
#ifdef AF_VOICEVIEW
85c20f9e71de *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 822
diff changeset
   522
	struct sockaddr_vv vv;
85c20f9e71de *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 822
diff changeset
   523
#endif
869
a6e5cbe9f558 preps for AF_IRDA
Claus Gittinger <cg@exept.de>
parents: 867
diff changeset
   524
#ifdef AF_IRDA
a6e5cbe9f558 preps for AF_IRDA
Claus Gittinger <cg@exept.de>
parents: 867
diff changeset
   525
	struct sockaddr_irda irda;
a6e5cbe9f558 preps for AF_IRDA
Claus Gittinger <cg@exept.de>
parents: 867
diff changeset
   526
#endif
819
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
   527
};
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
   528
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
   529
739
eb3878300c3b removed WIN32 ifdef's - win32 uses Socket_win32.st anyway.
Claus Gittinger <cg@exept.de>
parents: 726
diff changeset
   530
#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
   531
# define USE_H_ERRNO
eb3878300c3b removed WIN32 ifdef's - win32 uses Socket_win32.st anyway.
Claus Gittinger <cg@exept.de>
parents: 726
diff changeset
   532
#endif
eb3878300c3b removed WIN32 ifdef's - win32 uses Socket_win32.st anyway.
Claus Gittinger <cg@exept.de>
parents: 726
diff changeset
   533
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   534
819
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
   535
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   536
/*
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   537
 * on some systems errno is a macro ... check for it here
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   538
 */
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   539
#ifndef errno
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   540
 extern errno;
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   541
#endif
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   542
648
58e11a70ddaf gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents: 617
diff changeset
   543
#ifdef USE_H_ERRNO
58e11a70ddaf gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents: 617
diff changeset
   544
# ifndef h_errno
58e11a70ddaf gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents: 617
diff changeset
   545
 extern h_errno;
58e11a70ddaf gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents: 617
diff changeset
   546
# endif
58e11a70ddaf gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents: 617
diff changeset
   547
#endif
58e11a70ddaf gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents: 617
diff changeset
   548
720
967fad20a8f1 newest stdio uses __new
Claus Gittinger <cg@exept.de>
parents: 711
diff changeset
   549
#ifdef xxLINUX
967fad20a8f1 newest stdio uses __new
Claus Gittinger <cg@exept.de>
parents: 711
diff changeset
   550
/* use inline string macros ... */
967fad20a8f1 newest stdio uses __new
Claus Gittinger <cg@exept.de>
parents: 711
diff changeset
   551
# define __STRINGDEFS__
967fad20a8f1 newest stdio uses __new
Claus Gittinger <cg@exept.de>
parents: 711
diff changeset
   552
# include <linuxIntern.h>
967fad20a8f1 newest stdio uses __new
Claus Gittinger <cg@exept.de>
parents: 711
diff changeset
   553
#endif
967fad20a8f1 newest stdio uses __new
Claus Gittinger <cg@exept.de>
parents: 711
diff changeset
   554
648
58e11a70ddaf gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents: 617
diff changeset
   555
/*
58e11a70ddaf gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents: 617
diff changeset
   556
 * 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
   557
 * 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
   558
 * 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
   559
 * (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
   560
 * 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
   561
 */
692
85d64f84be0c oops - do not make gethostbyaddr / byname interruptable;
Claus Gittinger <cg@exept.de>
parents: 672
diff changeset
   562
#ifdef LINUX
85d64f84be0c oops - do not make gethostbyaddr / byname interruptable;
Claus Gittinger <cg@exept.de>
parents: 672
diff changeset
   563
85d64f84be0c oops - do not make gethostbyaddr / byname interruptable;
Claus Gittinger <cg@exept.de>
parents: 672
diff changeset
   564
# define GETHOSTBYNAME(hp, name) \
85d64f84be0c oops - do not make gethostbyaddr / byname interruptable;
Claus Gittinger <cg@exept.de>
parents: 672
diff changeset
   565
	hp = gethostbyname((char *) name);
85d64f84be0c oops - do not make gethostbyaddr / byname interruptable;
Claus Gittinger <cg@exept.de>
parents: 672
diff changeset
   566
85d64f84be0c oops - do not make gethostbyaddr / byname interruptable;
Claus Gittinger <cg@exept.de>
parents: 672
diff changeset
   567
# define GETHOSTBYADDR(hp, addr, alen, af) \
85d64f84be0c oops - do not make gethostbyaddr / byname interruptable;
Claus Gittinger <cg@exept.de>
parents: 672
diff changeset
   568
	hp = gethostbyaddr(addr, alen, af);
85d64f84be0c oops - do not make gethostbyaddr / byname interruptable;
Claus Gittinger <cg@exept.de>
parents: 672
diff changeset
   569
85d64f84be0c oops - do not make gethostbyaddr / byname interruptable;
Claus Gittinger <cg@exept.de>
parents: 672
diff changeset
   570
#else
85d64f84be0c oops - do not make gethostbyaddr / byname interruptable;
Claus Gittinger <cg@exept.de>
parents: 672
diff changeset
   571
693
c7a1bf49dcf5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 692
diff changeset
   572
# ifdef IRIX5_3
c7a1bf49dcf5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 692
diff changeset
   573
#  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
   574
	do { \
58e11a70ddaf gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents: 617
diff changeset
   575
	    __BEGIN_INTERRUPTABLE__  \
58e11a70ddaf gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents: 617
diff changeset
   576
	    hp = gethostbyname((char *) name); \
58e11a70ddaf gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents: 617
diff changeset
   577
	    __END_INTERRUPTABLE__ \
58e11a70ddaf gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents: 617
diff changeset
   578
	} while ((hp == NULL) && \
58e11a70ddaf gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents: 617
diff changeset
   579
		 ((h_errno == TRY_AGAIN) || (errno == ECONNREFUSED)));
650
8c5616f17ed6 made gethostbyaddr interruptable
Claus Gittinger <cg@exept.de>
parents: 649
diff changeset
   580
693
c7a1bf49dcf5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 692
diff changeset
   581
#  define GETHOSTBYADDR(hp, addr, alen, af) \
789
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
   582
	do { \
650
8c5616f17ed6 made gethostbyaddr interruptable
Claus Gittinger <cg@exept.de>
parents: 649
diff changeset
   583
	    __BEGIN_INTERRUPTABLE__ \
8c5616f17ed6 made gethostbyaddr interruptable
Claus Gittinger <cg@exept.de>
parents: 649
diff changeset
   584
	    hp = gethostbyaddr(addr, alen, af); \
8c5616f17ed6 made gethostbyaddr interruptable
Claus Gittinger <cg@exept.de>
parents: 649
diff changeset
   585
	    __END_INTERRUPTABLE__ \
8c5616f17ed6 made gethostbyaddr interruptable
Claus Gittinger <cg@exept.de>
parents: 649
diff changeset
   586
	} while ((hp == NULL) && \
8c5616f17ed6 made gethostbyaddr interruptable
Claus Gittinger <cg@exept.de>
parents: 649
diff changeset
   587
		((h_errno == TRY_AGAIN) || (errno == ECONNREFUSED)));
693
c7a1bf49dcf5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 692
diff changeset
   588
# else
c7a1bf49dcf5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 692
diff changeset
   589
#  ifdef USE_H_ERRNO
c7a1bf49dcf5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 692
diff changeset
   590
#   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
   591
	do { \
58e11a70ddaf gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents: 617
diff changeset
   592
	    __BEGIN_INTERRUPTABLE__  \
58e11a70ddaf gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents: 617
diff changeset
   593
	    hp = gethostbyname((char *) name); \
58e11a70ddaf gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents: 617
diff changeset
   594
	    __END_INTERRUPTABLE__ \
58e11a70ddaf gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents: 617
diff changeset
   595
	} while ((hp == NULL) && (h_errno == TRY_AGAIN));
650
8c5616f17ed6 made gethostbyaddr interruptable
Claus Gittinger <cg@exept.de>
parents: 649
diff changeset
   596
693
c7a1bf49dcf5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 692
diff changeset
   597
#   define GETHOSTBYADDR(hp, addr, alen, af) \
650
8c5616f17ed6 made gethostbyaddr interruptable
Claus Gittinger <cg@exept.de>
parents: 649
diff changeset
   598
	do { \
8c5616f17ed6 made gethostbyaddr interruptable
Claus Gittinger <cg@exept.de>
parents: 649
diff changeset
   599
	    __BEGIN_INTERRUPTABLE__  \
8c5616f17ed6 made gethostbyaddr interruptable
Claus Gittinger <cg@exept.de>
parents: 649
diff changeset
   600
	    hp = gethostbyaddr(addr, alen, af); \
8c5616f17ed6 made gethostbyaddr interruptable
Claus Gittinger <cg@exept.de>
parents: 649
diff changeset
   601
	    __END_INTERRUPTABLE__ \
8c5616f17ed6 made gethostbyaddr interruptable
Claus Gittinger <cg@exept.de>
parents: 649
diff changeset
   602
	} while ((hp == NULL) && (h_errno == TRY_AGAIN));
693
c7a1bf49dcf5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 692
diff changeset
   603
#  else
c7a1bf49dcf5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 692
diff changeset
   604
#   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
   605
	__BEGIN_INTERRUPTABLE__  \
58e11a70ddaf gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents: 617
diff changeset
   606
	hp = gethostbyname((char *) name); \
58e11a70ddaf gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents: 617
diff changeset
   607
	__END_INTERRUPTABLE__ 
650
8c5616f17ed6 made gethostbyaddr interruptable
Claus Gittinger <cg@exept.de>
parents: 649
diff changeset
   608
693
c7a1bf49dcf5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 692
diff changeset
   609
#   define GETHOSTBYADDR(hp, addr, alen, af) \
650
8c5616f17ed6 made gethostbyaddr interruptable
Claus Gittinger <cg@exept.de>
parents: 649
diff changeset
   610
	__BEGIN_INTERRUPTABLE__ \
8c5616f17ed6 made gethostbyaddr interruptable
Claus Gittinger <cg@exept.de>
parents: 649
diff changeset
   611
	hp = gethostbyaddr(addr, alen, af); \
8c5616f17ed6 made gethostbyaddr interruptable
Claus Gittinger <cg@exept.de>
parents: 649
diff changeset
   612
	__END_INTERRUPTABLE__
693
c7a1bf49dcf5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 692
diff changeset
   613
#  endif
648
58e11a70ddaf gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents: 617
diff changeset
   614
# endif
58e11a70ddaf gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents: 617
diff changeset
   615
#endif
58e11a70ddaf gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents: 617
diff changeset
   616
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   617
#ifdef DEBUG
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   618
# define DBGPRINTF(x)    { if (__debugging__) printf x; }
821
40b0b69bf4b5 more debugs; fixed at-addresses
Claus Gittinger <cg@exept.de>
parents: 820
diff changeset
   619
# define DBGFPRINTF(x)   { if (__debugging__) fprintf x; }
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   620
#else
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   621
# define DBGPRINTF(x)    /* as nothing */
821
40b0b69bf4b5 more debugs; fixed at-addresses
Claus Gittinger <cg@exept.de>
parents: 820
diff changeset
   622
# define DBGFPRINTF(x)   /* as nothing */
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   623
#endif
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   624
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   625
%}
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   626
! !
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   627
511
c071e228cb24 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 510
diff changeset
   628
!Socket primitiveVariables!
c071e228cb24 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 510
diff changeset
   629
%{
c071e228cb24 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 510
diff changeset
   630
static int __debugging__ = 0;
c071e228cb24 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 510
diff changeset
   631
%}
c071e228cb24 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 510
diff changeset
   632
! !
c071e228cb24 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 510
diff changeset
   633
464
600b101a7035 alen in accept
Claus Gittinger <cg@exept.de>
parents: 463
diff changeset
   634
!Socket class methodsFor:'documentation'!
25
996051271ce9 *** empty log message ***
claus
parents: 21
diff changeset
   635
31
e223f3cf2995 *** empty log message ***
claus
parents: 28
diff changeset
   636
copyright
e223f3cf2995 *** empty log message ***
claus
parents: 28
diff changeset
   637
"
e223f3cf2995 *** empty log message ***
claus
parents: 28
diff changeset
   638
 COPYRIGHT (c) 1992 by Claus Gittinger
42
506596f9a1a8 *** empty log message ***
claus
parents: 38
diff changeset
   639
	      All Rights Reserved
31
e223f3cf2995 *** empty log message ***
claus
parents: 28
diff changeset
   640
e223f3cf2995 *** empty log message ***
claus
parents: 28
diff changeset
   641
 This software is furnished under a license and may be used
e223f3cf2995 *** empty log message ***
claus
parents: 28
diff changeset
   642
 only in accordance with the terms of that license and with the
e223f3cf2995 *** empty log message ***
claus
parents: 28
diff changeset
   643
 inclusion of the above copyright notice.   This software may not
e223f3cf2995 *** empty log message ***
claus
parents: 28
diff changeset
   644
 be provided or otherwise made available to, or used by, any
e223f3cf2995 *** empty log message ***
claus
parents: 28
diff changeset
   645
 other person.  No title to or ownership of the software is
e223f3cf2995 *** empty log message ***
claus
parents: 28
diff changeset
   646
 hereby transferred.
e223f3cf2995 *** empty log message ***
claus
parents: 28
diff changeset
   647
"
e223f3cf2995 *** empty log message ***
claus
parents: 28
diff changeset
   648
!
e223f3cf2995 *** empty log message ***
claus
parents: 28
diff changeset
   649
25
996051271ce9 *** empty log message ***
claus
parents: 21
diff changeset
   650
documentation
996051271ce9 *** empty log message ***
claus
parents: 21
diff changeset
   651
"
524
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
   652
    This class provides access to sockets for interprocess communication.
25
996051271ce9 *** empty log message ***
claus
parents: 21
diff changeset
   653
    The message protocol is preliminary, until someone tells me how
31
e223f3cf2995 *** empty log message ***
claus
parents: 28
diff changeset
   654
    other smalltalk's socket interfaces look like.
25
996051271ce9 *** empty log message ***
claus
parents: 21
diff changeset
   655
525
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
   656
    Currently, only IP and UNIX domain sockets are supported.
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
   657
    Code for appletalk is included, but was never tested ...
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
   658
    More may be added in the future.
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
   659
    (the code is prepared for things like SNA or decNet;
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
   660
     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
   661
     Implementing those is pretty straight forward, once the address
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
   662
     data structures are known.)
524
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
   663
28
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
   664
    Due to historic reasons (I started this class, before I got hold of some
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
   665
    code using ST-80 Sockets i.e. RemoteInvocation), there is some old interface
71
claus
parents: 63
diff changeset
   666
    still provided. 
524
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
   667
    This will vanish; use the #family:type: or #newTCPxxx and #newUDPxxx interfaces,
71
claus
parents: 63
diff changeset
   668
    together with the bind/listen and accept calls,
claus
parents: 63
diff changeset
   669
    which are meant to be compatible to ST-80's UnixSocketAccessor interface.
claus
parents: 63
diff changeset
   670
869
a6e5cbe9f558 preps for AF_IRDA
Claus Gittinger <cg@exept.de>
parents: 867
diff changeset
   671
    ST/X does not yet use IPSocketAddress, UDSocketAddress etc; all addressing
71
claus
parents: 63
diff changeset
   672
    is done by passing appropriate string- or byteArray objects containing
claus
parents: 63
diff changeset
   673
    the addresses. This may change, too.
claus
parents: 63
diff changeset
   674
claus
parents: 63
diff changeset
   675
    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
   676
	  (mhmh - how can I test those ?)
532
f997c3873602 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 531
diff changeset
   677
	  change to raise more signals on errors.
529
fc7ec265717b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   678
	  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
   679
		 net please test this (and send bug fixes ...)
259
6d36f3ac42a2 documentation
Claus Gittinger <cg@exept.de>
parents: 220
diff changeset
   680
6d36f3ac42a2 documentation
Claus Gittinger <cg@exept.de>
parents: 220
diff changeset
   681
    [author:]
425
eb8198e9f1b0 comment
Claus Gittinger <cg@exept.de>
parents: 421
diff changeset
   682
	Claus Gittinger
48
18b9353c9d07 *** empty log message ***
claus
parents: 44
diff changeset
   683
"
18b9353c9d07 *** empty log message ***
claus
parents: 44
diff changeset
   684
!
28
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
   685
48
18b9353c9d07 *** empty log message ***
claus
parents: 44
diff changeset
   686
examples
18b9353c9d07 *** empty log message ***
claus
parents: 44
diff changeset
   687
"
28
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
   688
    example (get help info from an nntp server):
1009
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
   689
									[exBegin]
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
   690
	|sock host|
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
   691
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
   692
	host := OperatingSystem getEnvironment:'NNTPSERVER'.
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
   693
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
   694
	sock := Socket newTCPclientToHost:host port:'nntp'.
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
   695
	Transcript showCR:sock nextLine.
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
   696
	sock buffered:false.
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
   697
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
   698
	sock nextPutAll:'HELP'; cr.
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
   699
	[:exit |
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
   700
	    |line|
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
   701
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
   702
	    line := sock nextLine.
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
   703
	    line = '.' ifTrue:[exit value:nil].
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
   704
	    Transcript showCR:line.
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
   705
	] loopWithExit.
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
   706
	sock close
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
   707
									[exEnd]
209
2152fceba563 finger example
Claus Gittinger <cg@exept.de>
parents: 208
diff changeset
   708
28
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
   709
209
2152fceba563 finger example
Claus Gittinger <cg@exept.de>
parents: 208
diff changeset
   710
    example (connect to finger daemon, get users entry):
1009
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
   711
									[exBegin]
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
   712
	|sock host entry|
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
   713
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
   714
	host := OperatingSystem getHostName.
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
   715
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
   716
	sock := Socket newTCPclientToHost:host port:'finger'.
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
   717
	sock isNil ifTrue:[
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
   718
	    self warn:'no finger daemon is running'.
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
   719
	    ^ self
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
   720
	].
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
   721
	sock useCRLF:true.
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
   722
	sock buffered:false.
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
   723
	sock isNil ifTrue:[
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
   724
	    Transcript showCR:'cannot connect to local finger daemon'
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
   725
	] ifFalse:[
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
   726
	    sock nextPutAll:(OperatingSystem getLoginName).
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
   727
	    sock cr.
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
   728
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
   729
	    entry := sock nextLine.
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
   730
	    Transcript showCR:entry.
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
   731
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
   732
	    sock close
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
   733
	]
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
   734
									[exEnd]
99
7d016cc30052 fixed & moved pingWalk from SNMPSession to here;
Claus Gittinger <cg@exept.de>
parents: 98
diff changeset
   735
28
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
   736
    example (connect to an ftp server):
1009
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
   737
									[exBegin]
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
   738
	|sock host|
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
   739
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
   740
	host := OperatingSystem getHostName.
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
   741
	sock := Socket newTCPclientToHost:host port:'ftp'.
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
   742
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
   743
	sock buffered:false.
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
   744
	Transcript showCR:sock nextLine.
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
   745
	sock nextPutAll:('USER ' , 'anonymous'); cr.
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
   746
	Transcript showCR:sock nextLine.
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
   747
	sock nextPutAll:('PASS ' , 'fooBar'); cr.
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
   748
	Transcript showCR:sock nextLine.
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
   749
	sock nextPutAll:'LIST'; cr.
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
   750
	Transcript showCR:sock nextLine.
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
   751
	sock close.
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
   752
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
   753
	'dont know enough of the ftp protocol to continue here ...'
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
   754
									[exEnd]
28
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
   755
99
7d016cc30052 fixed & moved pingWalk from SNMPSession to here;
Claus Gittinger <cg@exept.de>
parents: 98
diff changeset
   756
93
Claus Gittinger <cg@exept.de>
parents: 92
diff changeset
   757
    example (connect to an snmp server [UDP]):
1009
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
   758
									[exBegin]
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
   759
	|sock port|
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
   760
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
   761
	sock := Socket newUDP.
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
   762
	port := Socket portOfService:'snmp'.
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
   763
	sock connectTo:(OperatingSystem getHostName) port:port.
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
   764
	sock buffered:false.
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
   765
	Transcript showCR:'got it'.
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
   766
	sock close.
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
   767
									[exEnd]
42
506596f9a1a8 *** empty log message ***
claus
parents: 38
diff changeset
   768
99
7d016cc30052 fixed & moved pingWalk from SNMPSession to here;
Claus Gittinger <cg@exept.de>
parents: 98
diff changeset
   769
42
506596f9a1a8 *** empty log message ***
claus
parents: 38
diff changeset
   770
    example (await connection from a client and read some data):
1009
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
   771
									[exBegin]
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
   772
	|connectSock sock|
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
   773
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
   774
	connectSock := Socket newTCPserverAtPort:9998.  
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
   775
	connectSock isNil ifTrue:[
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
   776
	    Transcript showCR:'socket setup failed.'.
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
   777
	] ifFalse:[
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
   778
	    Transcript showCR:'listen ..'.
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
   779
	    (connectSock listenFor:5) ifFalse:[
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
   780
		Transcript showCR:'listen failed.'.
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
   781
	    ] ifTrue:[
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
   782
		Transcript showCR:'wait'.
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
   783
		connectSock readWait.  
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
   784
		Transcript showCR:'accept'.
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
   785
		sock := connectSock accept.
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
   786
		sock isNil ifTrue:[
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
   787
		    Transcript showCR:'accept failed.'.
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
   788
		] ifFalse:[
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
   789
		    sock buffered:false.
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
   790
		    Transcript showCR:'server: got it'.
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
   791
		    'can now do transfer via sock'.
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
   792
		    Transcript showCR:'read'.
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
   793
		    Transcript showCR:('got: ' , sock nextLine).
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
   794
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
   795
		    Transcript showCR:'close'.
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
   796
		    sock close
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
   797
		].
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
   798
		connectSock close.
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
   799
	    ]
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
   800
	]
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
   801
									[exEnd]
42
506596f9a1a8 *** empty log message ***
claus
parents: 38
diff changeset
   802
99
7d016cc30052 fixed & moved pingWalk from SNMPSession to here;
Claus Gittinger <cg@exept.de>
parents: 98
diff changeset
   803
42
506596f9a1a8 *** empty log message ***
claus
parents: 38
diff changeset
   804
    example (connect to above server and send some data):
1009
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
   805
									[exBegin]
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
   806
	|sock|
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
   807
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
   808
	sock := Socket newTCPclientToHost:(OperatingSystem getHostName) port:9998.
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
   809
	sock isNil ifTrue:[
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
   810
	    Transcript showCR:'nope'
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
   811
	] ifFalse:[
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
   812
	    sock buffered:false.
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
   813
	    Transcript showCR:'client: got it'.
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
   814
	    'can now do transfer via sock'.
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
   815
	    Transcript showCR:'sending <hello>'.
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
   816
	    sock nextPutLine:'hello'.
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
   817
	    sock close
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
   818
	]
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
   819
									[exEnd]
117
03cefad7e40b UD socket example & interruptable bind
Claus Gittinger <cg@exept.de>
parents: 116
diff changeset
   820
03cefad7e40b UD socket example & interruptable bind
Claus Gittinger <cg@exept.de>
parents: 116
diff changeset
   821
    example: UNIX domain socket (await connection from a client and read some data):
1009
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
   822
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
   823
	|connectSock sock|
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
   824
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
   825
	'/tmp/ud_socket' asFilename remove.
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
   826
	connectSock := Socket newUNIXserverAt:'/tmp/ud_socket'.  
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
   827
	connectSock isNil ifTrue:[
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
   828
	    Transcript showCR:'socket setup failed.'.
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
   829
	] ifFalse:[
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
   830
	    Transcript showCR:'listen ..'.
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
   831
	    (connectSock listenFor:5) ifFalse:[
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
   832
		Transcript showCR:'listen failed.'.
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
   833
	    ] ifTrue:[
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
   834
		Transcript showCR:'wait'.
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
   835
		connectSock buffered:false.
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
   836
		connectSock readWait.  
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
   837
		Transcript showCR:'accept'.
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
   838
		sock := connectSock accept.
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
   839
		sock isNil ifTrue:[
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
   840
		    Transcript showCR:'accept failed.'.
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
   841
		] ifFalse:[
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
   842
		    sock buffered:false.
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
   843
		    Transcript showCR:'server: got it'.
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
   844
		    'can now do transfer via sock'.
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
   845
		    Transcript showCR:'read'.
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
   846
		    Transcript showCR:('got: ' , sock nextLine).
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
   847
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
   848
		    Transcript showCR:'close'.
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
   849
		    sock close
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
   850
		].
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
   851
		connectSock close.
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
   852
	    ]
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
   853
	]
117
03cefad7e40b UD socket example & interruptable bind
Claus Gittinger <cg@exept.de>
parents: 116
diff changeset
   854
03cefad7e40b UD socket example & interruptable bind
Claus Gittinger <cg@exept.de>
parents: 116
diff changeset
   855
118
142d5c273454 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 117
diff changeset
   856
    example (connect to above server and send some data;
1009
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
   857
	     Notice, this fails, if above server code is executed in the same ST/X image
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
   858
		     (at least on LINUX), since the OS does not correctly handle
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
   859
		     a connect from within an interrupted accept system call
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
   860
		     On SGI's SVR4, this works ok
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
   861
									[exBegin]
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
   862
	|sock|
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
   863
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
   864
	sock := Socket newUNIXclientTo:'/tmp/ud_socket'.
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
   865
	sock isNil ifTrue:[
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
   866
	    Transcript showCR:'nope'
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
   867
	] ifFalse:[
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
   868
	    sock buffered:false.
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
   869
	    Transcript showCR:'client: got it'.
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
   870
	    'can now do transfer via sock'.
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
   871
	    Transcript showCR:'sending <hello>'.
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
   872
	    sock nextPutLine:'hello'.
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
   873
	    sock close
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
   874
	]
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
   875
									[exEnd]
1007
5267b5738779 UDP examples
Claus Gittinger <cg@exept.de>
parents: 1004
diff changeset
   876
5267b5738779 UDP examples
Claus Gittinger <cg@exept.de>
parents: 1004
diff changeset
   877
5267b5738779 UDP examples
Claus Gittinger <cg@exept.de>
parents: 1004
diff changeset
   878
    example (UDP await packet from a client and read some data):
1009
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
   879
									[exBegin]
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
   880
	|udpSock sock addr n dataBuffer|
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
   881
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
   882
	udpSock := Socket newUDPserverAtPort:9999.  
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
   883
	udpSock isNil ifTrue:[
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
   884
	    Transcript showCR:'socket setup failed.'.
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
   885
	] ifFalse:[
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
   886
	    Transcript showCR:'wait'.
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
   887
	    udpSock readWait.  
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
   888
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
   889
	    addr := IPSocketAddress new.
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
   890
	    dataBuffer := ByteArray new:1000.    
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
   891
	    n := udpSock receiveFrom:addr buffer:dataBuffer start:1 for:dataBuffer size.
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
   892
	    n > 0 ifTrue:[
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
   893
		Transcript showCR:('got: ' , n printString , 'bytes  from ' , addr printString).
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
   894
		Transcript showCR:('data: ' , (dataBuffer copyTo:n) printString).
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
   895
	    ] ifFalse:[
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
   896
		Transcript showCR:'read failed'.
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
   897
	    ].
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
   898
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
   899
	    Transcript showCR:'close'.
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
   900
	    udpSock close
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
   901
	]
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
   902
									[exEnd]
1007
5267b5738779 UDP examples
Claus Gittinger <cg@exept.de>
parents: 1004
diff changeset
   903
    example (connect to above UDP server and send some data;
1009
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
   904
									[exBegin]
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
   905
	|sock|
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
   906
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
   907
	sock := Socket newUDP.
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
   908
	sock isNil ifTrue:[
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
   909
	    Transcript showCR:'nope'
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
   910
	] ifFalse:[
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
   911
	    sock sendTo:(IPSocketAddress new hostName:'localhost' port:9999) buffer:'hello world'.
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
   912
	    sock close
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
   913
	]
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
   914
									[exEnd]
99
7d016cc30052 fixed & moved pingWalk from SNMPSession to here;
Claus Gittinger <cg@exept.de>
parents: 98
diff changeset
   915
7d016cc30052 fixed & moved pingWalk from SNMPSession to here;
Claus Gittinger <cg@exept.de>
parents: 98
diff changeset
   916
    example: pingWalk (try to ping hosts on the local network)
1009
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
   917
									[exBegin]
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
   918
	|myName myAddress list top hosts walkProcess port|
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
   919
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
   920
	myName := OperatingSystem getHostName.
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
   921
	myAddress := Socket ipAddressOfHost:myName.
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
   922
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
   923
	port := Socket portOfService:'echo'.
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
   924
	port isNil ifTrue:[
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
   925
	    self error:'dont know echo port'.
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
   926
	    ^ self
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
   927
	].
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
   928
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
   929
	top := StandardSystemView new.
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
   930
	top label:'PING net walk'.
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
   931
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
   932
	list := ScrollableView for:ListView in:top.
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
   933
	list origin:0.0@0.0 corner:1.0@1.0.
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
   934
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
   935
	top openAndWait.
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
   936
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
   937
	walkProcess := [
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
   938
	    |l low hi direction tryHostID dottedName hostName conn addr|
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
   939
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
   940
	    l := SortedCollection new.
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
   941
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
   942
	    ' only works with type C-net
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
   943
	      the code below could simply do 1 to:254 do:[:hostID }
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
   944
	      but, to probe likely hosts earlier, the probing is done
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
   945
	      ping-pong like around my ip-address (assuming, that other machines
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
   946
	      have numbers around my own)'.
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
   947
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
   948
	    low := hi := (myAddress at:4).
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
   949
	    direction := 1.
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
   950
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
   951
	    [low > 0 or:[hi < 255]] whileTrue:[
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
   952
		direction > 0 ifTrue:[
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
   953
		    hi := hi + 1.
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
   954
		    tryHostID := hi.
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
   955
		    direction := -1.
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
   956
		] ifFalse:[
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
   957
		    low := low - 1.
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
   958
		    tryHostID := low.
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
   959
		    direction := 1.
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
   960
		].
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
   961
		(tryHostID between:1 and:254) ifTrue:[
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
   962
		    dottedName := (myAddress at:1) printString
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
   963
				  , '.' , (myAddress at:2) printString
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
   964
				  , '.' , (myAddress at:3) printString
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
   965
				  , '.' , tryHostID printString.
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
   966
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
   967
		    top label:'PING net walk - trying ' , dottedName.
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
   968
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
   969
		    top windowGroup withCursor:Cursor wait do:[
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
   970
			conn := Socket newTCPclientToHost:dottedName port:port withTimeout:1000.
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
   971
			conn notNil ifTrue:[
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
   972
			    addr := Socket ipAddressOfHost:dottedName.
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
   973
			    hostName := Socket hostWithIpAddress:addr.
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
   974
			    hostName isNil ifTrue:[
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
   975
				hostName :='?'
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
   976
			    ].
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
   977
			    l add:(dottedName paddedTo:15 with:Character space) 
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
   978
				   , ' ' 
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
   979
				   , (hostName paddedTo:15 with:Character space)
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
   980
				   , ' up & reachable'.
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
   981
			    list list:l.
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
   982
			    conn close.
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
   983
			]
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
   984
		    ].
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
   985
		].
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
   986
	    ].
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
   987
	    top label:'PING reachable hosts'.
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
   988
	] forkAt:(Processor userBackgroundPriority).
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
   989
	walkProcess name:'ping net walker'.
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
   990
									[exEnd]
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
   991
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
   992
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
   993
	This example creates a simple UDP server that accepts 
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
   994
	single packets from anybody and broadcasts them to all 
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
   995
	clients that have connected so far. 
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
   996
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
   997
									[exBegin]
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
   998
	| socket address buffer msgSize clients |
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
   999
	clients := Set new.
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  1000
	address := IPSocketAddress new.
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  1001
	buffer := String new: 1024.
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  1002
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  1003
	socket := self newUDPserverAtPort: 6666.
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  1004
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  1005
	Transcript showCR: 'server starting'.
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  1006
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  1007
	[
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  1008
	    [true] whileTrue: [
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  1009
		(socket readWaitWithTimeoutMs: 200) ifFalse: [
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  1010
		    msgSize := socket 
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  1011
			    receiveFrom: address 
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  1012
			    buffer: buffer 
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  1013
			    start: 1 
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  1014
			    for: buffer size.
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  1015
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  1016
		    clients add: address copy.
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  1017
		    clients do: [ :clientAddress | 
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  1018
			    socket 
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  1019
				    sendTo: clientAddress 
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  1020
				    buffer: buffer 
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  1021
				    start: 1 
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  1022
				    for: msgSize]]
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  1023
	    ]
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  1024
	] valueNowOrOnUnwindDo:[
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  1025
	    Transcript showCR: 'server shutting down'.
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  1026
	    socket close
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  1027
	]
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  1028
									[exEnd]
817
eda0065cbd47 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 814
diff changeset
  1029
eda0065cbd47 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 814
diff changeset
  1030
   send a datagram to above server:
1009
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  1031
									[exBegin]
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  1032
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  1033
	| socket address buffer host msg |
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  1034
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  1035
	host := Dialog
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  1036
		request: 'What is the name of the server''s host?'
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  1037
		initialAnswer: 'localhost'.
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  1038
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  1039
	socket := self newUDP.
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  1040
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  1041
	address := IPSocketAddress hostName: host port: 6666.
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  1042
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  1043
	buffer := ByteArray new: 1000.
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  1044
	[
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  1045
	    [(msg := Dialog request: 'Say something') isEmpty] whileFalse:[
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  1046
		| replySize stream |
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  1047
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  1048
		socket writeWait.
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  1049
		stream := buffer writeStream.
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  1050
		stream nextPutAll: msg.
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  1051
		socket sendTo:address buffer:buffer start:1 for:stream position.
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  1052
		socket readWait.
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  1053
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  1054
		replySize := socket receiveFrom:address buffer:buffer.
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  1055
		replySize > 0 ifTrue: [
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  1056
		    Transcript cr; nextPutAll: 'Server acknowledged: '.
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  1057
		    Transcript show: ((buffer copyFrom: 1 to: replySize) asString) 
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  1058
		]
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  1059
	    ]
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  1060
	] valueNowOrOnUnwindDo: [socket close].
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  1061
	Transcript cr
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  1062
									[exEnd]
25
996051271ce9 *** empty log message ***
claus
parents: 21
diff changeset
  1063
"
996051271ce9 *** empty log message ***
claus
parents: 21
diff changeset
  1064
! !
996051271ce9 *** empty log message ***
claus
parents: 21
diff changeset
  1065
1119
ec18fa40d90b category change
Claus Gittinger <cg@exept.de>
parents: 1112
diff changeset
  1066
!Socket class methodsFor:'Compatibility - ST80'!
91
Claus Gittinger <cg@exept.de>
parents: 85
diff changeset
  1067
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1068
family:domainSymbol type:typeSymbol
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1069
    "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
  1070
     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
  1071
     Type must be #stream, #datagram or #raw
91
Claus Gittinger <cg@exept.de>
parents: 85
diff changeset
  1072
811
72d9ac1a7f95 comments
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  1073
     XXX: currently only the #inet and #unix domains is supported"
91
Claus Gittinger <cg@exept.de>
parents: 85
diff changeset
  1074
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1075
    ^ self domain:domainSymbol type:typeSymbol
51
24f978f1d849 *** empty log message ***
claus
parents: 48
diff changeset
  1076
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1077
    "
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1078
     Socket family:#inet type:#stream
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1079
     Socket family:#inet type:#datagram
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1080
     Socket family:#unix type:#stream
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1081
    "
867
56ca0cc52fa7 category renamining
Claus Gittinger <cg@exept.de>
parents: 859
diff changeset
  1082
!
115
a9d85df931c4 added Unix domain support
Claus Gittinger <cg@exept.de>
parents: 112
diff changeset
  1083
617
6ccbaa111a74 added #getHostname (ST80 compatibility)
Claus Gittinger <cg@exept.de>
parents: 604
diff changeset
  1084
getHostname
6ccbaa111a74 added #getHostname (ST80 compatibility)
Claus Gittinger <cg@exept.de>
parents: 604
diff changeset
  1085
    "return the computers hostname string"
6ccbaa111a74 added #getHostname (ST80 compatibility)
Claus Gittinger <cg@exept.de>
parents: 604
diff changeset
  1086
6ccbaa111a74 added #getHostname (ST80 compatibility)
Claus Gittinger <cg@exept.de>
parents: 604
diff changeset
  1087
    ^ OperatingSystem getHostName
6ccbaa111a74 added #getHostname (ST80 compatibility)
Claus Gittinger <cg@exept.de>
parents: 604
diff changeset
  1088
6ccbaa111a74 added #getHostname (ST80 compatibility)
Claus Gittinger <cg@exept.de>
parents: 604
diff changeset
  1089
    "Created: / 27.2.1998 / 02:32:17 / cg"
6ccbaa111a74 added #getHostname (ST80 compatibility)
Claus Gittinger <cg@exept.de>
parents: 604
diff changeset
  1090
!
6ccbaa111a74 added #getHostname (ST80 compatibility)
Claus Gittinger <cg@exept.de>
parents: 604
diff changeset
  1091
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1092
sockStream
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1093
    "return the type code for stream sockets"
51
24f978f1d849 *** empty log message ***
claus
parents: 48
diff changeset
  1094
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1095
    ^ #stream
44
b4db396f9255 EINTR stuff
claus
parents: 42
diff changeset
  1096
! !
b4db396f9255 EINTR stuff
claus
parents: 42
diff changeset
  1097
464
600b101a7035 alen in accept
Claus Gittinger <cg@exept.de>
parents: 463
diff changeset
  1098
!Socket class methodsFor:'Signal constants'!
21
33eb5ffad09d *** empty log message ***
claus
parents: 8
diff changeset
  1099
33eb5ffad09d *** empty log message ***
claus
parents: 8
diff changeset
  1100
brokenConnectionSignal
33eb5ffad09d *** empty log message ***
claus
parents: 8
diff changeset
  1101
    "return the signal used to tell broken connections.
33eb5ffad09d *** empty log message ***
claus
parents: 8
diff changeset
  1102
     Since in unix, this is the same as the broken pipe signal,
33eb5ffad09d *** empty log message ***
claus
parents: 8
diff changeset
  1103
     return that one.
33eb5ffad09d *** empty log message ***
claus
parents: 8
diff changeset
  1104
     (for other Operatingsystems, this may change ..)"
33eb5ffad09d *** empty log message ***
claus
parents: 8
diff changeset
  1105
33eb5ffad09d *** empty log message ***
claus
parents: 8
diff changeset
  1106
    ^ PipeStream brokenPipeSignal
887
2b2dc6b59b5a more VW compatibility
Claus Gittinger <cg@exept.de>
parents: 876
diff changeset
  1107
!
2b2dc6b59b5a more VW compatibility
Claus Gittinger <cg@exept.de>
parents: 876
diff changeset
  1108
2b2dc6b59b5a more VW compatibility
Claus Gittinger <cg@exept.de>
parents: 876
diff changeset
  1109
invalidArgumentsSignal
2b2dc6b59b5a more VW compatibility
Claus Gittinger <cg@exept.de>
parents: 876
diff changeset
  1110
    "dummy for compatibility"
2b2dc6b59b5a more VW compatibility
Claus Gittinger <cg@exept.de>
parents: 876
diff changeset
  1111
2b2dc6b59b5a more VW compatibility
Claus Gittinger <cg@exept.de>
parents: 876
diff changeset
  1112
    ^ self errorSignal
21
33eb5ffad09d *** empty log message ***
claus
parents: 8
diff changeset
  1113
! !
33eb5ffad09d *** empty log message ***
claus
parents: 8
diff changeset
  1114
464
600b101a7035 alen in accept
Claus Gittinger <cg@exept.de>
parents: 463
diff changeset
  1115
!Socket class methodsFor:'debugging'!
71
claus
parents: 63
diff changeset
  1116
claus
parents: 63
diff changeset
  1117
debug:aBoolean
claus
parents: 63
diff changeset
  1118
    "turn on/off internal debugprints.
claus
parents: 63
diff changeset
  1119
     This method is for ST/X debugging only and
claus
parents: 63
diff changeset
  1120
     may  be removed in later versions"
claus
parents: 63
diff changeset
  1121
claus
parents: 63
diff changeset
  1122
%{  /* NOCONTEXT */
claus
parents: 63
diff changeset
  1123
claus
parents: 63
diff changeset
  1124
    __debugging__ = (aBoolean == true);
claus
parents: 63
diff changeset
  1125
%}
93
Claus Gittinger <cg@exept.de>
parents: 92
diff changeset
  1126
    "
Claus Gittinger <cg@exept.de>
parents: 92
diff changeset
  1127
     Socket debug:true
Claus Gittinger <cg@exept.de>
parents: 92
diff changeset
  1128
     Socket debug:false
Claus Gittinger <cg@exept.de>
parents: 92
diff changeset
  1129
    "
71
claus
parents: 63
diff changeset
  1130
! !
claus
parents: 63
diff changeset
  1131
464
600b101a7035 alen in accept
Claus Gittinger <cg@exept.de>
parents: 463
diff changeset
  1132
!Socket class methodsFor:'easy tcp/ip instance creation'!
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1133
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1134
connectTo:service on:host
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1135
    "standard & easy client setup: 
1170
270d76fc288f *** empty log message ***
penk
parents: 1146
diff changeset
  1136
	create new client tcp socket, bind and connect; 
270d76fc288f *** empty log message ***
penk
parents: 1146
diff changeset
  1137
	return the socket.
811
72d9ac1a7f95 comments
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  1138
     The thread block (interruptable), until the connection is 
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1139
     established."
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1140
968
c73180e4ab6a obsoleteMethodWarning
Claus Gittinger <cg@exept.de>
parents: 964
diff changeset
  1141
    self obsoleteMethodWarning:'use newTCP: / connect'.
c73180e4ab6a obsoleteMethodWarning
Claus Gittinger <cg@exept.de>
parents: 964
diff changeset
  1142
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1143
    ^ (self new) for:host port:(self portOfService:service).
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1144
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1145
    "
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1146
     Socket connectTo:9995 on:'clam'
1112
b30ccede6078 oops - removed swazoo stuff
Claus Gittinger <cg@exept.de>
parents: 1110
diff changeset
  1147
     Socket connectTo:4711 on:'exept'
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1148
     Socket connectTo:'finger' on:'clam'
1112
b30ccede6078 oops - removed swazoo stuff
Claus Gittinger <cg@exept.de>
parents: 1110
diff changeset
  1149
     Socket connectTo:'ftp' on:'exept'
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1150
     Socket connectTo:'nntp' on:(OperatingSystem getEnvironment:'NNTPSERVER')
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1151
    "
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1152
!
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1153
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1154
provide:service
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1155
    "standard & easy server setup: 
811
72d9ac1a7f95 comments
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  1156
     create a new TCP server socket providing a service."
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1157
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1158
    |newSock|
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1159
968
c73180e4ab6a obsoleteMethodWarning
Claus Gittinger <cg@exept.de>
parents: 964
diff changeset
  1160
    self obsoleteMethodWarning:'use newTCP: / listen'.
c73180e4ab6a obsoleteMethodWarning
Claus Gittinger <cg@exept.de>
parents: 964
diff changeset
  1161
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1162
    newSock := (self new) for:nil port:(self portOfService:service).
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1163
    newSock notNil ifTrue:[
1009
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  1164
	newSock listenFor:5.
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1165
    ].
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1166
    ^ newSock
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1167
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1168
    "
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1169
     Socket provide:9995
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1170
     (Socket provide:9996) accept
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1171
     Socket provide:'nntp'
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1172
    "
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1173
! !
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1174
464
600b101a7035 alen in accept
Claus Gittinger <cg@exept.de>
parents: 463
diff changeset
  1175
!Socket class methodsFor:'general instance creation'!
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1176
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1177
domain:domainSymbol type:type
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1178
    "create a socket for domain and type -
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1179
     neither any connect nor binding is done.
819
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
  1180
     Domain must be one of the symbols: 
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
  1181
	#inet, #unix, #appletalk, #decnet, #xns, ...;
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
  1182
     Type must be:
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
  1183
	#stream, #datagram or #raw
126
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
     XXX: currently only the #inet domain is supported"
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1186
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1187
    ^ self new domain:domainSymbol type:type
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1188
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1189
    "
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1190
     Socket domain:#inet type:#stream
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1191
     Socket domain:#inet type:#datagram
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1192
     Socket domain:#unix type:#stream
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1193
     Socket domain:#appletalk type:#stream
819
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
  1194
     Socket domain:#decnet type:#stream
869
a6e5cbe9f558 preps for AF_IRDA
Claus Gittinger <cg@exept.de>
parents: 867
diff changeset
  1195
     Socket domain:#irda type:#stream
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1196
    "
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1197
!
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1198
576
13acab81fad0 more ST80 compatibility
ca
parents: 572
diff changeset
  1199
new
13acab81fad0 more ST80 compatibility
ca
parents: 572
diff changeset
  1200
    "create a TCP socket"
13acab81fad0 more ST80 compatibility
ca
parents: 572
diff changeset
  1201
13acab81fad0 more ST80 compatibility
ca
parents: 572
diff changeset
  1202
    ^ super new buffered:false 
13acab81fad0 more ST80 compatibility
ca
parents: 572
diff changeset
  1203
!
13acab81fad0 more ST80 compatibility
ca
parents: 572
diff changeset
  1204
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1205
newTCP
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1206
    "create a TCP socket - no binding or other setup is done,
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1207
     neither connect nor connect-wait is done."
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1208
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1209
    ^ self new domain:#inet type:#stream 
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1210
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1211
    "Socket newUDP"
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1212
!
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1213
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1214
newTCP:aServiceOrNil
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1215
    "create a TCP socket for a service -
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1216
     neither connect nor connect-wait is done."
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1217
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1218
    |newSock|
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
    newSock := self newTCP.
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1221
    (newSock notNil and:[aServiceOrNil notNil]) ifTrue:[
819
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
  1222
	(newSock bindTo:(self portOfService:aServiceOrNil) address:nil) ifFalse:[
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
  1223
	    ^ nil
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
  1224
	]
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1225
    ].
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1226
    ^ newSock
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1227
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1228
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1229
    "Socket newTCP:'nntp'"
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1230
    "Socket newTCP:9995"
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1231
!
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1232
576
13acab81fad0 more ST80 compatibility
ca
parents: 572
diff changeset
  1233
newTCPclientToAddress:aHostAddress port:aService
13acab81fad0 more ST80 compatibility
ca
parents: 572
diff changeset
  1234
    "create a new TCP client socket connecting to a service.
13acab81fad0 more ST80 compatibility
ca
parents: 572
diff changeset
  1235
     Return a socket instance if ok, nil on failure.
13acab81fad0 more ST80 compatibility
ca
parents: 572
diff changeset
  1236
     Block until a connection is established (but only the current thread;
13acab81fad0 more ST80 compatibility
ca
parents: 572
diff changeset
  1237
     not the whole smalltalk). 
13acab81fad0 more ST80 compatibility
ca
parents: 572
diff changeset
  1238
     See also: #newTCPclientToAddress:port:withTimeout:"
13acab81fad0 more ST80 compatibility
ca
parents: 572
diff changeset
  1239
13acab81fad0 more ST80 compatibility
ca
parents: 572
diff changeset
  1240
    ^ self newTCPclientToAddress:aHostAddress port:aService withTimeout:nil
13acab81fad0 more ST80 compatibility
ca
parents: 572
diff changeset
  1241
!
13acab81fad0 more ST80 compatibility
ca
parents: 572
diff changeset
  1242
13acab81fad0 more ST80 compatibility
ca
parents: 572
diff changeset
  1243
newTCPclientToAddress:aHostAddress port:aService withTimeout:millis
13acab81fad0 more ST80 compatibility
ca
parents: 572
diff changeset
  1244
    "create a new TCP client socket connecting to a service.
13acab81fad0 more ST80 compatibility
ca
parents: 572
diff changeset
  1245
     Return a socket instance if ok, nil on failure.
13acab81fad0 more ST80 compatibility
ca
parents: 572
diff changeset
  1246
     If the millis arg is nonNil, stop trying to connect after that many milliseconds
811
72d9ac1a7f95 comments
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  1247
     and return nil."
576
13acab81fad0 more ST80 compatibility
ca
parents: 572
diff changeset
  1248
13acab81fad0 more ST80 compatibility
ca
parents: 572
diff changeset
  1249
    ^ self newTCPclientToHost:aHostAddress port:aService withTimeout:millis
13acab81fad0 more ST80 compatibility
ca
parents: 572
diff changeset
  1250
!
13acab81fad0 more ST80 compatibility
ca
parents: 572
diff changeset
  1251
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1252
newTCPclientToHost:hostname port:aService
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1253
    "create a new TCP client socket connecting to a service.
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1254
     Return a socket instance if ok, nil on failure.
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1255
     Block until a connection is established (but only the current thread;
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1256
     not the whole smalltalk). 
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1257
     See also: #newTCPclientToHost:port:withTimeout:"
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1258
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1259
    ^ self newTCPclientToHost:hostname port:aService withTimeout:nil
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1260
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1261
    "
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1262
      Socket newTCPclientToHost:'localhost' port:'nntp'
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1263
    "
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1264
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1265
    "Created: 31.10.1995 / 18:54:11 / cg"
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1266
!
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1267
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1268
newTCPclientToHost:hostname port:aService withTimeout:millis
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1269
    "create a new TCP client socket connecting to a service.
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1270
     Return a socket instance if ok, nil on failure.
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1271
     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
  1272
     and return nil.."
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1273
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1274
    |newSock|
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1275
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1276
    newSock := self newTCP.
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1277
    newSock notNil ifTrue:[
648
58e11a70ddaf gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents: 617
diff changeset
  1278
	(newSock connectTo:hostname 
58e11a70ddaf gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents: 617
diff changeset
  1279
		 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
  1280
		 withTimeout:millis
58e11a70ddaf gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents: 617
diff changeset
  1281
	) ifFalse:[
58e11a70ddaf gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents: 617
diff changeset
  1282
	    newSock close.
58e11a70ddaf gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents: 617
diff changeset
  1283
	    ^ nil
58e11a70ddaf gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents: 617
diff changeset
  1284
	]
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1285
    ].
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1286
    ^ newSock
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1287
"
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1288
same as:
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1289
    ^ (self new) for:hostname port:(self portOfService:aPort).
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1290
"
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1291
    "
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1292
      Socket newTCPclientToHost:'slsv6bt' port:'nntp'
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1293
      Socket newTCPclientToHost:'localhost' port:'nntp' withTimeout:1000
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1294
    "
604
b302a21afece Remove redundant code.
Stefan Vogel <sv@exept.de>
parents: 589
diff changeset
  1295
b302a21afece Remove redundant code.
Stefan Vogel <sv@exept.de>
parents: 589
diff changeset
  1296
    "Modified: / 16.1.1998 / 09:47:06 / stefan"
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1297
!
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1298
506
11ef93d12870 support anonymous (OS_specified) ports. (for FTP-protocol)
Claus Gittinger <cg@exept.de>
parents: 486
diff changeset
  1299
newTCPserverAtAnonymousPort
11ef93d12870 support anonymous (OS_specified) ports. (for FTP-protocol)
Claus Gittinger <cg@exept.de>
parents: 486
diff changeset
  1300
    "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
  1301
     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
  1302
811
72d9ac1a7f95 comments
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  1303
    ^ self newTCPserverAtPort:0
506
11ef93d12870 support anonymous (OS_specified) ports. (for FTP-protocol)
Claus Gittinger <cg@exept.de>
parents: 486
diff changeset
  1304
11ef93d12870 support anonymous (OS_specified) ports. (for FTP-protocol)
Claus Gittinger <cg@exept.de>
parents: 486
diff changeset
  1305
!
11ef93d12870 support anonymous (OS_specified) ports. (for FTP-protocol)
Claus Gittinger <cg@exept.de>
parents: 486
diff changeset
  1306
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1307
newTCPserverAtPort:aService
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1308
    "create a new TCP server socket providing service."
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1309
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1310
    |newSock|
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1311
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1312
    newSock := self newTCP.
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1313
    newSock notNil ifTrue:[
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1314
	(newSock bindTo:(self portOfService:aService) address:nil) ifFalse:[
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1315
	    ^ nil
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1316
	]
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1317
    ].
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1318
    ^ newSock
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1319
"
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1320
same as:
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1321
    ^ (self new) for:nil port:aPort
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1322
"
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1323
!
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1324
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1325
newUDP
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1326
    "create a UDP socket - no binding or other setup is done,
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1327
     neither connect nor connect-wait is done."
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1328
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1329
    ^ self new domain:#inet type:#datagram
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1330
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1331
    "Socket newUDP"
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1332
!
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1333
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1334
newUDP:aServiceOrNil
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1335
    "create a UDP socket for a service -
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1336
     neither connect nor connect-wait is done."
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1337
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1338
    |newSock|
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1339
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1340
    newSock := self newUDP.
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1341
    (newSock notNil and:[aServiceOrNil notNil]) ifTrue:[
819
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
  1342
	(newSock bindTo:(self portOfService:aServiceOrNil) address:nil) ifFalse:[
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
  1343
	    ^ nil
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
  1344
	]
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1345
    ].
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1346
    ^ newSock
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1347
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1348
    "Socket newUDP:nil"
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1349
!
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1350
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1351
newUDPserverAtPort:aService
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1352
    "create a new UDP server socket providing service."
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1353
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1354
    |newSock|
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1355
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1356
    newSock := self newUDP.
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1357
    newSock notNil ifTrue:[
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1358
	(newSock bindTo:(self portOfService:aService) address:nil) ifFalse:[
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1359
	    ^ nil
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1360
	]
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1361
    ].
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1362
    ^ newSock
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1363
"
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1364
same as:
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1365
    ^ (self new) for:nil udpPort:aPort
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1366
"
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1367
!
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1368
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1369
newUNIX
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1370
    "create a UNIX domain socket - no binding or other setup is done,
811
72d9ac1a7f95 comments
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  1371
     neither connect nor connect-wait is done.
72d9ac1a7f95 comments
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  1372
     If the system does not support unix domain sockets (i.e. VMS or MSDOS),
72d9ac1a7f95 comments
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  1373
     return nil."
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1374
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1375
    ^ self new domain:#unix type:#stream 
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1376
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1377
    "
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1378
     Socket newUNIX
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1379
    "
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1380
!
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1381
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1382
newUNIXclientTo:pathName 
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1383
    "create a new UNIX client socket connecting to a pathname.
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1384
     Return a socket instance if ok, nil on failure.
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1385
     Block until a connection is established (but only the current thread;
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1386
     not the whole smalltalk). 
811
72d9ac1a7f95 comments
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  1387
     If the system does not support unix domain sockets (i.e. VMS or MSDOS),
72d9ac1a7f95 comments
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  1388
     return nil.
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1389
     See also: #newUNIXclientTo:withTimeout:"
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1390
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1391
    ^ self newUNIXclientTo:pathName withTimeout:nil
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1392
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1393
!
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1394
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1395
newUNIXclientTo:pathName withTimeout:millis
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1396
    "create a new UNIX client socket connecting to a pathname.
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1397
     Return a socket instance if ok, nil on failure.
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1398
     If the millis arg is nonNil, stop trying to connect after that many milliseconds
811
72d9ac1a7f95 comments
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  1399
     and return nil.
72d9ac1a7f95 comments
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  1400
     If the system does not support unix domain sockets (i.e. VMS or MSDOS),
72d9ac1a7f95 comments
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  1401
     return nil."
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1402
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1403
    |newSock|
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1404
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1405
    newSock := self newUNIX.
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1406
    newSock notNil ifTrue:[
812
c8101ea70e6c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 811
diff changeset
  1407
	(newSock connectTo:pathName port:nil withTimeout:millis) ifFalse:[
c8101ea70e6c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 811
diff changeset
  1408
	    newSock close.
c8101ea70e6c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 811
diff changeset
  1409
	    ^ nil
c8101ea70e6c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 811
diff changeset
  1410
	]
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1411
    ].
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1412
    ^ newSock
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1413
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1414
    "
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1415
     |s|
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1416
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1417
     s := Socket newUNIXclientTo:'/tmp/foo'
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1418
    "
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1419
!
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1420
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1421
newUNIXserverAt:pathName
811
72d9ac1a7f95 comments
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  1422
    "create a new UNIX server socket providing service at a pathname.
72d9ac1a7f95 comments
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  1423
     If the system does not support unix domain sockets (i.e. VMS or MSDOS),
72d9ac1a7f95 comments
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  1424
     return nil."
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1425
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1426
    |newSock|
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1427
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1428
    newSock := self newUNIX.
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1429
    newSock notNil ifTrue:[
812
c8101ea70e6c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 811
diff changeset
  1430
	(newSock bindTo:pathName address:nil) ifFalse:[
c8101ea70e6c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 811
diff changeset
  1431
	    ^ nil
c8101ea70e6c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 811
diff changeset
  1432
	]
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1433
    ].
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1434
    ^ newSock
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1435
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1436
    "
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1437
     |s s2|
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1438
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1439
     s := Socket newUNIXserverAt:'/tmp/foo'.
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1440
     s listenFor:5.
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1441
     s2 := s accept.
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1442
    "
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1443
! !
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1444
525
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  1445
!Socket class methodsFor:'host queries'!
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  1446
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  1447
appletalkAddressOfHost:aHostName
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  1448
    "return the APPLETALK address for a hostname as a byteArray,
819
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
  1449
     where the network bytes come first (no matter what the local byteorder is)
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
  1450
     followed by the node byte.
525
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  1451
     If the host is unknown, return nil.
812
c8101ea70e6c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 811
diff changeset
  1452
     This is the reverse operation to #hostWithAppletalkAddress:.
c8101ea70e6c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 811
diff changeset
  1453
     WARNING: untested code - I have no appletalk to test this."
525
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  1454
1120
b43bcd84bca8 gethostbyname beeds more than 64kb stack
martin
parents: 1119
diff changeset
  1455
%{  /* STACK: 100000 */
526
1748ab3892a3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 525
diff changeset
  1456
#if !defined(NO_SOCKET) && defined(AF_APPLETALK)
819
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
  1457
    struct sockaddr_at sa;
525
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  1458
    struct hostent *hp ;
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  1459
    long addr;
653
219b89f62113 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 650
diff changeset
  1460
    OBJ rslt;
525
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  1461
529
fc7ec265717b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
  1462
    sa.sat_family = -1;
525
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  1463
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  1464
    if (__isString(aHostName)) {
789
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  1465
	bzero(&sa, sizeof(sa)) ;
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  1466
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  1467
	/* do we know the host's address? */
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  1468
	GETHOSTBYNAME(hp, __stringVal(aHostName))
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  1469
	if (hp == NULL) {
819
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
  1470
	    DBGPRINTF(("SOCKET: unknown appletalk host: %s\n", __stringVal(aHostName)));
789
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  1471
	    RETURN ( nil );
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  1472
	}
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  1473
	bcopy(hp->h_addr, (char *) &sa.sat_addr, hp->h_length) ;
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  1474
	sa.sat_family = hp->h_addrtype;
525
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  1475
    }
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  1476
752
c4176e236d83 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 741
diff changeset
  1477
    /* if the addressing family is not AF_APPLETALK, Return nil */
812
c8101ea70e6c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 811
diff changeset
  1478
    if (sa.sat_family != AF_APPLETALK) {
789
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  1479
	DBGPRINTF(("SOCKET: not an appletalk host\n"));
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  1480
	RETURN ( nil );
525
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  1481
    }
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  1482
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  1483
    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
  1484
    rslt = __BYTEARRAY_NEW_INT(3);
219b89f62113 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 650
diff changeset
  1485
    if (rslt != nil) {
789
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  1486
	__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
  1487
	__ByteArrayInstPtr(rslt)->ba_element[1] = (sa.sat_addr.s_net) & 0xFF;
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  1488
	__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
  1489
       RETURN (rslt);
219b89f62113 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 650
diff changeset
  1490
    }
525
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  1491
#endif
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  1492
%}.
653
219b89f62113 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 650
diff changeset
  1493
    ^ nil
525
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  1494
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  1495
!
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  1496
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  1497
hostWithAppletalkAddress:anAddress
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  1498
    "return the hostname for an APPLETALK address.
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  1499
     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
  1500
     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
  1501
     The last byte is the node number.
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  1502
     Nil is returned for an unknown host or if its not an appletalk host.
812
c8101ea70e6c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 811
diff changeset
  1503
     This is is the reverse operation to #appletalkAddressOfHost:.
c8101ea70e6c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 811
diff changeset
  1504
     WARNING: untested code - I have no appletalk to test this."
525
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  1505
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  1506
    |b1 b2 b3 b4|
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  1507
812
c8101ea70e6c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 811
diff changeset
  1508
    b1 := anAddress at:1. "/ net-hi
c8101ea70e6c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 811
diff changeset
  1509
    b2 := anAddress at:2. "/ net-low
c8101ea70e6c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 811
diff changeset
  1510
    b3 := anAddress at:3. "/ node
1120
b43bcd84bca8 gethostbyname beeds more than 64kb stack
martin
parents: 1119
diff changeset
  1511
b43bcd84bca8 gethostbyname beeds more than 64kb stack
martin
parents: 1119
diff changeset
  1512
%{  /* STACK: 100000 */
525
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  1513
#if !defined(NO_SOCKET) && defined(AF_APPLETALK)
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  1514
    struct sockaddr_at sa ;
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  1515
    struct hostent *hp ;
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  1516
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  1517
    sa.sat_family = -1;
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  1518
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  1519
    if (__bothSmallInteger(b1, b2) && __bothSmallInteger(b3, b4)) {
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  1520
	bzero(&sa, sizeof(sa)) ;
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  1521
1009
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  1522
	sa.sat_addr.s_net = __intVal(b1) & 0xFF;
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  1523
	sa.sat_addr.s_net = (sa.sat_addr.s_net << 8) | (__intVal(b2) & 0xFF);
529
fc7ec265717b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
  1524
	sa.sat_addr.s_net = htons(sa.sat_addr.s_net);    
1009
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  1525
	sa.sat_addr.s_node = __intVal(b3) & 0xFF;
529
fc7ec265717b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
  1526
	sa.sat_family = AF_APPLETALK;
fc7ec265717b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
  1527
525
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  1528
	/* do we know the host's address? */
650
8c5616f17ed6 made gethostbyaddr interruptable
Claus Gittinger <cg@exept.de>
parents: 649
diff changeset
  1529
	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
  1530
	if (hp != NULL) {
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  1531
	    sa.sat_family = hp->h_addrtype;
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  1532
	} else {
819
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
  1533
	    DBGPRINTF(("SOCKET: unknown appletalk address: %d.%d.%d.%d\n", 
1009
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  1534
		       __intVal(b1), __intVal(b2), __intVal(b3)));
525
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  1535
	}
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  1536
    }
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  1537
752
c4176e236d83 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 741
diff changeset
  1538
    /* if the addressing family is not AF_APPLETALK, Return nil */
525
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  1539
    if (sa.sat_family != AF_APPLETALK) {
819
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
  1540
	DBGPRINTF(("SOCKET: not an appletalk host\n"));
525
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  1541
	RETURN ( nil );
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  1542
    }
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  1543
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  1544
    if (hp != NULL) {
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  1545
	RETURN (__MKSTRING(hp->h_name));
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  1546
    }
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  1547
#endif
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  1548
    RETURN (nil);
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  1549
%}.
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  1550
    "
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  1551
     Socket appletalkAddressOfHost:'clam'
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  1552
     Socket hostWithAppletalkAddress:#[1 2 3]  
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  1553
     "
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1554
!
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1555
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1556
hostWithIpAddress:anAddress
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1557
    "return the hostname for an IP (internet-) address.
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1558
     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
  1559
     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
  1560
     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
  1561
     This is the reverse operation to #ipAddressOfHost:."
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1562
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1563
    |b1 b2 b3 b4|
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1564
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1565
    b1 := anAddress at:1.
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1566
    b2 := anAddress at:2.
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1567
    b3 := anAddress at:3.
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1568
    b4 := anAddress at:4.
1120
b43bcd84bca8 gethostbyname beeds more than 64kb stack
martin
parents: 1119
diff changeset
  1569
b43bcd84bca8 gethostbyname beeds more than 64kb stack
martin
parents: 1119
diff changeset
  1570
%{  /* STACK: 100000 */
525
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  1571
#if !defined(NO_SOCKET) && defined(AF_INET)
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1572
    struct sockaddr_in sa ;
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1573
    struct hostent *hp ;
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1574
525
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  1575
    sa.sin_family = -1;
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1576
    if (__bothSmallInteger(b1, b2) && __bothSmallInteger(b3, b4)) {
822
a08e230988fe *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 821
diff changeset
  1577
	bzero(&sa, sizeof(sa)) ;
1009
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  1578
	sa.sin_addr.s_addr = __intVal(b1) & 0xFF;
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  1579
	sa.sin_addr.s_addr = (sa.sin_addr.s_addr << 8) | (__intVal(b2) & 0xFF);
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  1580
	sa.sin_addr.s_addr = (sa.sin_addr.s_addr << 8) | (__intVal(b3) & 0xFF);
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  1581
	sa.sin_addr.s_addr = (sa.sin_addr.s_addr << 8) | (__intVal(b4) & 0xFF);
822
a08e230988fe *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 821
diff changeset
  1582
	sa.sin_addr.s_addr = htonl(sa.sin_addr.s_addr);    
a08e230988fe *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 821
diff changeset
  1583
	sa.sin_family = AF_INET;
a08e230988fe *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 821
diff changeset
  1584
	/* do we know the host's address? */
a08e230988fe *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 821
diff changeset
  1585
	GETHOSTBYADDR(hp, (char *) &sa.sin_addr, sizeof(sa.sin_addr), AF_INET);
820
b6860c3660c8 Fix address sizes when calling gethostbyaddr
Stefan Vogel <sv@exept.de>
parents: 819
diff changeset
  1586
        
822
a08e230988fe *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 821
diff changeset
  1587
	if (hp == NULL) {
a08e230988fe *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 821
diff changeset
  1588
	    DBGPRINTF(("SOCKET: unknown ip address: %d.%d.%d.%d\n", 
1009
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  1589
		       __intVal(b1), __intVal(b2), __intVal(b3), __intVal(b4)));
822
a08e230988fe *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 821
diff changeset
  1590
	} else {
a08e230988fe *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 821
diff changeset
  1591
	    sa.sin_family = hp->h_addrtype;
a08e230988fe *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 821
diff changeset
  1592
	}
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1593
    }
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1594
752
c4176e236d83 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 741
diff changeset
  1595
    /* if the addressing family is not AF_INET, Return nil */
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1596
    if (sa.sin_family != AF_INET) {
822
a08e230988fe *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 821
diff changeset
  1597
	RETURN ( nil );
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1598
    }
525
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  1599
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  1600
    if (hp != NULL) {
822
a08e230988fe *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 821
diff changeset
  1601
	RETURN (__MKSTRING(hp->h_name));
525
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  1602
    }
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  1603
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  1604
    /*
752
c4176e236d83 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 741
diff changeset
  1605
     * Return it in dot-notation
525
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  1606
     */
448
2203a4bb620d removed all COMMA_CON / CON_COMMA uses
Claus Gittinger <cg@exept.de>
parents: 444
diff changeset
  1607
    RETURN (__MKSTRING(inet_ntoa(sa.sin_addr)));
418
317e55c6c281 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 403
diff changeset
  1608
#else
317e55c6c281 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 403
diff changeset
  1609
    RETURN (nil);
317e55c6c281 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 403
diff changeset
  1610
#endif
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1611
%}
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1612
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1613
    "
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1614
     Socket ipAddressOfHost:'clam'
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1615
     Socket hostWithIpAddress:(Socket ipAddressOfHost:'clam') 
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1616
     Socket ipAddressOfHost:'porty'
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1617
     Socket hostWithIpAddress:(Socket ipAddressOfHost:'porty') 
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1618
     Socket hostWithIpAddress:#[1 2 3 4]  
796
c9f6b3b667fb Fix ipAddressOfHost
Stefan Vogel <sv@exept.de>
parents: 790
diff changeset
  1619
     Socket hostWithIpAddress:#[127 0 0 1]  
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1620
     Socket hostWithIpAddress:(Socket ipAddressOfHost:'1.2.3.4')  
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1621
     "
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1622
!
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1623
820
b6860c3660c8 Fix address sizes when calling gethostbyaddr
Stefan Vogel <sv@exept.de>
parents: 819
diff changeset
  1624
hostWithIpV6Address:anAddress
b6860c3660c8 Fix address sizes when calling gethostbyaddr
Stefan Vogel <sv@exept.de>
parents: 819
diff changeset
  1625
    "return the hostname for an IPv6 (internet-) address.
b6860c3660c8 Fix address sizes when calling gethostbyaddr
Stefan Vogel <sv@exept.de>
parents: 819
diff changeset
  1626
     The address is supposed to be a byteArray consisting ??? bytes,
b6860c3660c8 Fix address sizes when calling gethostbyaddr
Stefan Vogel <sv@exept.de>
parents: 819
diff changeset
  1627
     the network bytes come first (no matter what the local byteorder is).
b6860c3660c8 Fix address sizes when calling gethostbyaddr
Stefan Vogel <sv@exept.de>
parents: 819
diff changeset
  1628
     Nil is returned for an unknown host or if its not an internet host.
b6860c3660c8 Fix address sizes when calling gethostbyaddr
Stefan Vogel <sv@exept.de>
parents: 819
diff changeset
  1629
     This is the reverse operation to #ipV6AddressOfHost:."
b6860c3660c8 Fix address sizes when calling gethostbyaddr
Stefan Vogel <sv@exept.de>
parents: 819
diff changeset
  1630
1120
b43bcd84bca8 gethostbyname beeds more than 64kb stack
martin
parents: 1119
diff changeset
  1631
%{  /* STACK: 100000 */
820
b6860c3660c8 Fix address sizes when calling gethostbyaddr
Stefan Vogel <sv@exept.de>
parents: 819
diff changeset
  1632
#if !defined(NO_SOCKET) && defined(AF_INET6)
b6860c3660c8 Fix address sizes when calling gethostbyaddr
Stefan Vogel <sv@exept.de>
parents: 819
diff changeset
  1633
    struct sockaddr_in6 sa ;
b6860c3660c8 Fix address sizes when calling gethostbyaddr
Stefan Vogel <sv@exept.de>
parents: 819
diff changeset
  1634
    struct hostent *hp ;
b6860c3660c8 Fix address sizes when calling gethostbyaddr
Stefan Vogel <sv@exept.de>
parents: 819
diff changeset
  1635
b6860c3660c8 Fix address sizes when calling gethostbyaddr
Stefan Vogel <sv@exept.de>
parents: 819
diff changeset
  1636
    sa.sin6_family = -1;
b6860c3660c8 Fix address sizes when calling gethostbyaddr
Stefan Vogel <sv@exept.de>
parents: 819
diff changeset
  1637
    if (__isByteArray(anAddress)) {
b6860c3660c8 Fix address sizes when calling gethostbyaddr
Stefan Vogel <sv@exept.de>
parents: 819
diff changeset
  1638
	bzero(&sa, sizeof(sa)) ;
b6860c3660c8 Fix address sizes when calling gethostbyaddr
Stefan Vogel <sv@exept.de>
parents: 819
diff changeset
  1639
	if (__byteArraySize(anAddress) <= sizeof(sa.sin6_addr.s6_addr))
b6860c3660c8 Fix address sizes when calling gethostbyaddr
Stefan Vogel <sv@exept.de>
parents: 819
diff changeset
  1640
	    goto bad;
b6860c3660c8 Fix address sizes when calling gethostbyaddr
Stefan Vogel <sv@exept.de>
parents: 819
diff changeset
  1641
	bcopy(sa.sin6_addr.s6_addr, __ByteArrayInstPtr(anAddress)->ba_element, sizeof(sa.sin6_addr.s6_addr));
b6860c3660c8 Fix address sizes when calling gethostbyaddr
Stefan Vogel <sv@exept.de>
parents: 819
diff changeset
  1642
b6860c3660c8 Fix address sizes when calling gethostbyaddr
Stefan Vogel <sv@exept.de>
parents: 819
diff changeset
  1643
	sa.sin6_family = AF_INET6;
b6860c3660c8 Fix address sizes when calling gethostbyaddr
Stefan Vogel <sv@exept.de>
parents: 819
diff changeset
  1644
	/* do we know the host's address? */
b6860c3660c8 Fix address sizes when calling gethostbyaddr
Stefan Vogel <sv@exept.de>
parents: 819
diff changeset
  1645
	GETHOSTBYADDR(hp, (char *) &sa.sin6_addr, sizeof(sa.sin6_addr), AF_INET6);
b6860c3660c8 Fix address sizes when calling gethostbyaddr
Stefan Vogel <sv@exept.de>
parents: 819
diff changeset
  1646
	if (hp == NULL) {
b6860c3660c8 Fix address sizes when calling gethostbyaddr
Stefan Vogel <sv@exept.de>
parents: 819
diff changeset
  1647
	    DBGPRINTF(("SOCKET: unknown ipv6 address: %d.%d.%d.%d...\n", 
b6860c3660c8 Fix address sizes when calling gethostbyaddr
Stefan Vogel <sv@exept.de>
parents: 819
diff changeset
  1648
		       sa.sin6_addr.s6_addr[0], 
b6860c3660c8 Fix address sizes when calling gethostbyaddr
Stefan Vogel <sv@exept.de>
parents: 819
diff changeset
  1649
		       sa.sin6_addr.s6_addr[1], 
b6860c3660c8 Fix address sizes when calling gethostbyaddr
Stefan Vogel <sv@exept.de>
parents: 819
diff changeset
  1650
		       sa.sin6_addr.s6_addr[2],
b6860c3660c8 Fix address sizes when calling gethostbyaddr
Stefan Vogel <sv@exept.de>
parents: 819
diff changeset
  1651
		       sa.sin6_addr.s6_addr[3] ));
b6860c3660c8 Fix address sizes when calling gethostbyaddr
Stefan Vogel <sv@exept.de>
parents: 819
diff changeset
  1652
	} else {
b6860c3660c8 Fix address sizes when calling gethostbyaddr
Stefan Vogel <sv@exept.de>
parents: 819
diff changeset
  1653
	    sa.sin6_family = hp->h_addrtype;
b6860c3660c8 Fix address sizes when calling gethostbyaddr
Stefan Vogel <sv@exept.de>
parents: 819
diff changeset
  1654
	}
b6860c3660c8 Fix address sizes when calling gethostbyaddr
Stefan Vogel <sv@exept.de>
parents: 819
diff changeset
  1655
    }
b6860c3660c8 Fix address sizes when calling gethostbyaddr
Stefan Vogel <sv@exept.de>
parents: 819
diff changeset
  1656
    bad: ;
b6860c3660c8 Fix address sizes when calling gethostbyaddr
Stefan Vogel <sv@exept.de>
parents: 819
diff changeset
  1657
    /* if the addressing family is not AF_INET6, Return nil */
b6860c3660c8 Fix address sizes when calling gethostbyaddr
Stefan Vogel <sv@exept.de>
parents: 819
diff changeset
  1658
    if (sa.sin6_family != AF_INET6) {
b6860c3660c8 Fix address sizes when calling gethostbyaddr
Stefan Vogel <sv@exept.de>
parents: 819
diff changeset
  1659
	DBGPRINTF(("SOCKET: not an ipv6 host\n")); 
b6860c3660c8 Fix address sizes when calling gethostbyaddr
Stefan Vogel <sv@exept.de>
parents: 819
diff changeset
  1660
	RETURN ( nil );
b6860c3660c8 Fix address sizes when calling gethostbyaddr
Stefan Vogel <sv@exept.de>
parents: 819
diff changeset
  1661
    }
b6860c3660c8 Fix address sizes when calling gethostbyaddr
Stefan Vogel <sv@exept.de>
parents: 819
diff changeset
  1662
b6860c3660c8 Fix address sizes when calling gethostbyaddr
Stefan Vogel <sv@exept.de>
parents: 819
diff changeset
  1663
    if (hp != NULL) {
b6860c3660c8 Fix address sizes when calling gethostbyaddr
Stefan Vogel <sv@exept.de>
parents: 819
diff changeset
  1664
	RETURN (__MKSTRING(hp->h_name));
b6860c3660c8 Fix address sizes when calling gethostbyaddr
Stefan Vogel <sv@exept.de>
parents: 819
diff changeset
  1665
    }
b6860c3660c8 Fix address sizes when calling gethostbyaddr
Stefan Vogel <sv@exept.de>
parents: 819
diff changeset
  1666
b6860c3660c8 Fix address sizes when calling gethostbyaddr
Stefan Vogel <sv@exept.de>
parents: 819
diff changeset
  1667
    /*
b6860c3660c8 Fix address sizes when calling gethostbyaddr
Stefan Vogel <sv@exept.de>
parents: 819
diff changeset
  1668
     * Return it in dot-notation
b6860c3660c8 Fix address sizes when calling gethostbyaddr
Stefan Vogel <sv@exept.de>
parents: 819
diff changeset
  1669
     */
b6860c3660c8 Fix address sizes when calling gethostbyaddr
Stefan Vogel <sv@exept.de>
parents: 819
diff changeset
  1670
    RETURN (__MKSTRING(inet_ntoa(sa.sin6_addr)));
b6860c3660c8 Fix address sizes when calling gethostbyaddr
Stefan Vogel <sv@exept.de>
parents: 819
diff changeset
  1671
#else
b6860c3660c8 Fix address sizes when calling gethostbyaddr
Stefan Vogel <sv@exept.de>
parents: 819
diff changeset
  1672
    RETURN (nil);
b6860c3660c8 Fix address sizes when calling gethostbyaddr
Stefan Vogel <sv@exept.de>
parents: 819
diff changeset
  1673
#endif
b6860c3660c8 Fix address sizes when calling gethostbyaddr
Stefan Vogel <sv@exept.de>
parents: 819
diff changeset
  1674
%}
b6860c3660c8 Fix address sizes when calling gethostbyaddr
Stefan Vogel <sv@exept.de>
parents: 819
diff changeset
  1675
b6860c3660c8 Fix address sizes when calling gethostbyaddr
Stefan Vogel <sv@exept.de>
parents: 819
diff changeset
  1676
    "
b6860c3660c8 Fix address sizes when calling gethostbyaddr
Stefan Vogel <sv@exept.de>
parents: 819
diff changeset
  1677
     Socket ipV6AddressOfHost:'clam'
b6860c3660c8 Fix address sizes when calling gethostbyaddr
Stefan Vogel <sv@exept.de>
parents: 819
diff changeset
  1678
     Socket hostWithIpV6Address:(Socket ipAddressOfHost:'clam') 
b6860c3660c8 Fix address sizes when calling gethostbyaddr
Stefan Vogel <sv@exept.de>
parents: 819
diff changeset
  1679
     Socket ipV6AddressOfHost:'porty'
b6860c3660c8 Fix address sizes when calling gethostbyaddr
Stefan Vogel <sv@exept.de>
parents: 819
diff changeset
  1680
     Socket hostWithIpV6Address:(Socket ipAddressOfHost:'porty') 
b6860c3660c8 Fix address sizes when calling gethostbyaddr
Stefan Vogel <sv@exept.de>
parents: 819
diff changeset
  1681
     Socket hostWithIpV6Address:#[1 2 3 4 5 6 7 8 9 10 11 12 13 14]  
b6860c3660c8 Fix address sizes when calling gethostbyaddr
Stefan Vogel <sv@exept.de>
parents: 819
diff changeset
  1682
     "
b6860c3660c8 Fix address sizes when calling gethostbyaddr
Stefan Vogel <sv@exept.de>
parents: 819
diff changeset
  1683
!
b6860c3660c8 Fix address sizes when calling gethostbyaddr
Stefan Vogel <sv@exept.de>
parents: 819
diff changeset
  1684
6
claus
parents: 4
diff changeset
  1685
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
  1686
    "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
  1687
     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
  1688
     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
  1689
     This is the reverse operation to #hostWithIpAddress:."
6
claus
parents: 4
diff changeset
  1690
1120
b43bcd84bca8 gethostbyname beeds more than 64kb stack
martin
parents: 1119
diff changeset
  1691
%{  /* STACK: 100000 */
525
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  1692
#if !defined(NO_SOCKET) && defined(AF_INET)
6
claus
parents: 4
diff changeset
  1693
    struct sockaddr_in sa ;
claus
parents: 4
diff changeset
  1694
    struct hostent *hp ;
claus
parents: 4
diff changeset
  1695
    long addr;
653
219b89f62113 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 650
diff changeset
  1696
    OBJ rslt;
6
claus
parents: 4
diff changeset
  1697
525
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  1698
    sa.sin_family = -1;
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  1699
21
33eb5ffad09d *** empty log message ***
claus
parents: 8
diff changeset
  1700
    if (__isString(aHostName)) {
812
c8101ea70e6c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 811
diff changeset
  1701
	bzero(&sa, sizeof(sa)) ;
c8101ea70e6c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 811
diff changeset
  1702
	if ((addr = inet_addr((char *) __stringVal(aHostName))) != -1) {
c8101ea70e6c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 811
diff changeset
  1703
	    /* is Internet addr in octet notation */
c8101ea70e6c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 811
diff changeset
  1704
	    bcopy(&addr, (char *) &sa.sin_addr, sizeof(addr)); 
c8101ea70e6c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 811
diff changeset
  1705
	    sa.sin_family = AF_INET;
c8101ea70e6c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 811
diff changeset
  1706
	} else {
c8101ea70e6c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 811
diff changeset
  1707
	    /* do we know the host's address? */
c8101ea70e6c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 811
diff changeset
  1708
	    GETHOSTBYNAME(hp, __stringVal(aHostName))
c8101ea70e6c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 811
diff changeset
  1709
	    if (hp == NULL) {
819
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
  1710
		DBGPRINTF(("SOCKET: unknown ip host: %s\n", __stringVal(aHostName)));
812
c8101ea70e6c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 811
diff changeset
  1711
		RETURN ( nil );
c8101ea70e6c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 811
diff changeset
  1712
	    }
c8101ea70e6c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 811
diff changeset
  1713
	    bcopy(hp->h_addr, (char *) &sa.sin_addr, hp->h_length) ;
c8101ea70e6c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 811
diff changeset
  1714
	    sa.sin_family = hp->h_addrtype;
c8101ea70e6c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 811
diff changeset
  1715
	}
6
claus
parents: 4
diff changeset
  1716
    }
525
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  1717
752
c4176e236d83 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 741
diff changeset
  1718
    /* if the addressing family is not AF_INET, Return nil */
6
claus
parents: 4
diff changeset
  1719
    if (sa.sin_family != AF_INET) {
819
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
  1720
	DBGPRINTF(("SOCKET: not an ip host\n"));
812
c8101ea70e6c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 811
diff changeset
  1721
	RETURN ( nil );
6
claus
parents: 4
diff changeset
  1722
    }
98
5e787ba2cb31 use common byteOrder when representing IP numbers as byteArrays (always network-first)
Claus Gittinger <cg@exept.de>
parents: 96
diff changeset
  1723
5e787ba2cb31 use common byteOrder when representing IP numbers as byteArrays (always network-first)
Claus Gittinger <cg@exept.de>
parents: 96
diff changeset
  1724
    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
  1725
    rslt = __BYTEARRAY_NEW_INT(4);
219b89f62113 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 650
diff changeset
  1726
    if (rslt != nil) {
812
c8101ea70e6c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 811
diff changeset
  1727
	__ByteArrayInstPtr(rslt)->ba_element[0] = (sa.sin_addr.s_addr >> 24) & 0xFF;
c8101ea70e6c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 811
diff changeset
  1728
	__ByteArrayInstPtr(rslt)->ba_element[1] = (sa.sin_addr.s_addr >> 16) & 0xFF;
c8101ea70e6c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 811
diff changeset
  1729
	__ByteArrayInstPtr(rslt)->ba_element[2] = (sa.sin_addr.s_addr >> 8) & 0xFF;
c8101ea70e6c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 811
diff changeset
  1730
	__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
  1731
       RETURN (rslt);
219b89f62113 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 650
diff changeset
  1732
    }
418
317e55c6c281 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 403
diff changeset
  1733
#endif
525
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  1734
%}.
653
219b89f62113 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 650
diff changeset
  1735
    ^ nil
21
33eb5ffad09d *** empty log message ***
claus
parents: 8
diff changeset
  1736
71
claus
parents: 63
diff changeset
  1737
    "
796
c9f6b3b667fb Fix ipAddressOfHost
Stefan Vogel <sv@exept.de>
parents: 790
diff changeset
  1738
     Socket ipAddressOfHost:'localhost' 
c9f6b3b667fb Fix ipAddressOfHost
Stefan Vogel <sv@exept.de>
parents: 790
diff changeset
  1739
     Socket ipAddressOfHost:'exept'    
98
5e787ba2cb31 use common byteOrder when representing IP numbers as byteArrays (always network-first)
Claus Gittinger <cg@exept.de>
parents: 96
diff changeset
  1740
     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
  1741
     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
  1742
     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
  1743
     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
  1744
     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
  1745
     Socket ipAddressOfHost:(Socket hostWithIpAddress:'127.0.0.1') 
71
claus
parents: 63
diff changeset
  1746
    "
819
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
  1747
!
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
  1748
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
  1749
ipV6AddressOfHost:aHostName
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
  1750
    "return the IPv6 (internet-) number for a hostname as a byteArray,
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
  1751
     where the network bytes come first (no matter what the cpus byteOrder is).
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
  1752
     If the host is unknown, return nil.
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
  1753
     This is the reverse operation to #hostWithIpV6Address:."
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
  1754
1120
b43bcd84bca8 gethostbyname beeds more than 64kb stack
martin
parents: 1119
diff changeset
  1755
%{  /* STACK: 100000 */
819
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
  1756
#if !defined(NO_SOCKET) && defined(AF_INET6)
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
  1757
    struct sockaddr_in6 sa;
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
  1758
    struct hostent *hp ;
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
  1759
    long addr;
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
  1760
    OBJ rslt;
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
  1761
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
  1762
    sa.sin6_family = -1;
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
  1763
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
  1764
    if (__isString(aHostName)) {
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
  1765
	bzero(&sa, sizeof(sa)) ;
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
  1766
#if 0
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
  1767
	if ((addr = inet_addr((char *) __stringVal(aHostName))) != -1) {
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
  1768
	    /* is Internet addr in octet notation */
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
  1769
	    bcopy(&addr, (char *) &sa.sin_addr, sizeof(addr)); 
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
  1770
	    sa.sin_family = AF_INET;
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
  1771
	} else 
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
  1772
#endif
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
  1773
	{
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
  1774
	    /* do we know the host's address? */
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
  1775
	    GETHOSTBYNAME(hp, __stringVal(aHostName))
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
  1776
	    if (hp == NULL) {
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
  1777
		DBGPRINTF(("SOCKET: unknown host: %s\n", __stringVal(aHostName)));
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
  1778
		RETURN ( nil );
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
  1779
	    }
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
  1780
	    bcopy(hp->h_addr, (char *) &sa.sin6_addr, hp->h_length) ;
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
  1781
	    sa.sin6_family = hp->h_addrtype;
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
  1782
	}
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
  1783
    }
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
  1784
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
  1785
    /* if the addressing family is not AF_INET, Return nil */
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
  1786
    if (sa.sin6_family != AF_INET) {
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
  1787
	DBGPRINTF(("SOCKET: not an ipv6 host\n"));
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
  1788
	RETURN ( nil );
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
  1789
    }
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
  1790
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
  1791
    rslt = __BYTEARRAY_NEW_INT(hp->h_length);
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
  1792
    if (rslt != nil) {
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
  1793
	bcopy(sa.sin6_addr.s6_addr, __ByteArrayInstPtr(rslt)->ba_element, hp->h_length);
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
  1794
       RETURN (rslt);
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
  1795
    }
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
  1796
#endif
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
  1797
%}.
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
  1798
    ^ nil
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
  1799
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
  1800
    "
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
  1801
     Socket ipV6AddressOfHost:'localhost' 
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
  1802
     Socket ipV6AddressOfHost:'exept'    
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
  1803
     Socket ipV6AddressOfHost:'1.2.3.4.5.6.7.8.9.10.11.12.13.14.15.16'    
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
  1804
     Socket ipV6AddressOfHost:'193.15.16.17'    
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
  1805
     Socket ipV6AddressOfHost:'josef'     
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
  1806
     Socket ipV6AddressOfHost:'styx.com'  
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
  1807
     Socket hostWithIpV6Address:(Socket ipV6AddressOfHost:'localhost') 
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
  1808
     Socket ipV6AddressOfHost:(Socket hostV6WithIpAddress:'127.0.0.1') 
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
  1809
    "
531
ca4c73813531 category changes
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1810
! !
ca4c73813531 category changes
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1811
ca4c73813531 category changes
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1812
!Socket class methodsFor:'queries'!
ca4c73813531 category changes
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1813
ca4c73813531 category changes
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1814
domainOfProtocol:aProtocol
ca4c73813531 category changes
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1815
    "given a protocols name (i.e. tcp, udp etc) return the domain.
ca4c73813531 category changes
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1816
     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
  1817
ca4c73813531 category changes
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1818
    "
ca4c73813531 category changes
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1819
     tcp/ip stuff
ca4c73813531 category changes
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1820
    "
ca4c73813531 category changes
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1821
    (aProtocol = 'tcp') ifTrue:[^ #inet].
ca4c73813531 category changes
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1822
    (aProtocol = 'udp') ifTrue:[^ #inet].
ca4c73813531 category changes
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1823
    (aProtocol = 'ip')  ifTrue:[^ #inet].
ca4c73813531 category changes
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1824
    "
ca4c73813531 category changes
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1825
     unix domain
ca4c73813531 category changes
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1826
    "
ca4c73813531 category changes
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1827
    (aProtocol = 'ud')  ifTrue:[^ #unix].
ca4c73813531 category changes
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1828
ca4c73813531 category changes
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1829
    "
ca4c73813531 category changes
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1830
     add x25 stuff (if any) here ...
ca4c73813531 category changes
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1831
    "
ca4c73813531 category changes
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1832
    "
ca4c73813531 category changes
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1833
     add appletalk stuff (if any) here ...
ca4c73813531 category changes
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1834
    "
ca4c73813531 category changes
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1835
    "
ca4c73813531 category changes
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1836
     add other stuff (if any) here ...
ca4c73813531 category changes
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1837
    "
ca4c73813531 category changes
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1838
    ^ nil
ca4c73813531 category changes
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1839
ca4c73813531 category changes
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1840
    "
ca4c73813531 category changes
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1841
     Socket domainOfProtocol:'tcp'
ca4c73813531 category changes
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1842
     Socket domainOfProtocol:'ucp'
ca4c73813531 category changes
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1843
     Socket domainOfProtocol:(Socket protocolOfService:'nntp')
ca4c73813531 category changes
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1844
     Socket domainOfProtocol:(Socket protocolOfService:'echo')
ca4c73813531 category changes
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1845
    "
6
claus
parents: 4
diff changeset
  1846
!
claus
parents: 4
diff changeset
  1847
206
77166a6b3ee6 For ST80 style socket creation: register socket in Lobby.
Stefan Vogel <sv@exept.de>
parents: 203
diff changeset
  1848
networkLongOrderIsMSB
964
a11c607f1a3e checkin from browser
ca
parents: 962
diff changeset
  1849
    "return true, if the network-byte-order of longs is MSB (which it is).
206
77166a6b3ee6 For ST80 style socket creation: register socket in Lobby.
Stefan Vogel <sv@exept.de>
parents: 203
diff changeset
  1850
     To be used as in:
1009
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  1851
	'aStream nextPutLong:someValue MSB:(Socket networkLongOrderIsMSB)'."
964
a11c607f1a3e checkin from browser
ca
parents: 962
diff changeset
  1852
a11c607f1a3e checkin from browser
ca
parents: 962
diff changeset
  1853
    ^ true
206
77166a6b3ee6 For ST80 style socket creation: register socket in Lobby.
Stefan Vogel <sv@exept.de>
parents: 203
diff changeset
  1854
77166a6b3ee6 For ST80 style socket creation: register socket in Lobby.
Stefan Vogel <sv@exept.de>
parents: 203
diff changeset
  1855
    "
77166a6b3ee6 For ST80 style socket creation: register socket in Lobby.
Stefan Vogel <sv@exept.de>
parents: 203
diff changeset
  1856
     Socket networkLongOrderIsMSB
77166a6b3ee6 For ST80 style socket creation: register socket in Lobby.
Stefan Vogel <sv@exept.de>
parents: 203
diff changeset
  1857
    "
77166a6b3ee6 For ST80 style socket creation: register socket in Lobby.
Stefan Vogel <sv@exept.de>
parents: 203
diff changeset
  1858
!
77166a6b3ee6 For ST80 style socket creation: register socket in Lobby.
Stefan Vogel <sv@exept.de>
parents: 203
diff changeset
  1859
77166a6b3ee6 For ST80 style socket creation: register socket in Lobby.
Stefan Vogel <sv@exept.de>
parents: 203
diff changeset
  1860
networkShortOrderIsMSB
77166a6b3ee6 For ST80 style socket creation: register socket in Lobby.
Stefan Vogel <sv@exept.de>
parents: 203
diff changeset
  1861
    "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
  1862
     To be used as in:
77166a6b3ee6 For ST80 style socket creation: register socket in Lobby.
Stefan Vogel <sv@exept.de>
parents: 203
diff changeset
  1863
	'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
  1864
77166a6b3ee6 For ST80 style socket creation: register socket in Lobby.
Stefan Vogel <sv@exept.de>
parents: 203
diff changeset
  1865
%{  /* NOCONTEXT */
418
317e55c6c281 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 403
diff changeset
  1866
#ifndef NO_SOCKET
206
77166a6b3ee6 For ST80 style socket creation: register socket in Lobby.
Stefan Vogel <sv@exept.de>
parents: 203
diff changeset
  1867
    /*
77166a6b3ee6 For ST80 style socket creation: register socket in Lobby.
Stefan Vogel <sv@exept.de>
parents: 203
diff changeset
  1868
     * 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
  1869
     */
77166a6b3ee6 For ST80 style socket creation: register socket in Lobby.
Stefan Vogel <sv@exept.de>
parents: 203
diff changeset
  1870
    if (htons(0x3210) == 0x3210) {
77166a6b3ee6 For ST80 style socket creation: register socket in Lobby.
Stefan Vogel <sv@exept.de>
parents: 203
diff changeset
  1871
	RETURN (true);
77166a6b3ee6 For ST80 style socket creation: register socket in Lobby.
Stefan Vogel <sv@exept.de>
parents: 203
diff changeset
  1872
    }
418
317e55c6c281 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 403
diff changeset
  1873
#endif
206
77166a6b3ee6 For ST80 style socket creation: register socket in Lobby.
Stefan Vogel <sv@exept.de>
parents: 203
diff changeset
  1874
%}.
77166a6b3ee6 For ST80 style socket creation: register socket in Lobby.
Stefan Vogel <sv@exept.de>
parents: 203
diff changeset
  1875
    ^ false
77166a6b3ee6 For ST80 style socket creation: register socket in Lobby.
Stefan Vogel <sv@exept.de>
parents: 203
diff changeset
  1876
77166a6b3ee6 For ST80 style socket creation: register socket in Lobby.
Stefan Vogel <sv@exept.de>
parents: 203
diff changeset
  1877
    "
77166a6b3ee6 For ST80 style socket creation: register socket in Lobby.
Stefan Vogel <sv@exept.de>
parents: 203
diff changeset
  1878
     Socket networkShortOrderIsMSB
77166a6b3ee6 For ST80 style socket creation: register socket in Lobby.
Stefan Vogel <sv@exept.de>
parents: 203
diff changeset
  1879
    "
77166a6b3ee6 For ST80 style socket creation: register socket in Lobby.
Stefan Vogel <sv@exept.de>
parents: 203
diff changeset
  1880
!
77166a6b3ee6 For ST80 style socket creation: register socket in Lobby.
Stefan Vogel <sv@exept.de>
parents: 203
diff changeset
  1881
0
1cf8d1747859 Initial revision
claus
parents:
diff changeset
  1882
portOfService:aNameOrNumber
819
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
  1883
    "returns the port-number for a given IP-service
0
1cf8d1747859 Initial revision
claus
parents:
diff changeset
  1884
     or nil if no such service exists;
1cf8d1747859 Initial revision
claus
parents:
diff changeset
  1885
     - used to convert service names to portNumbers"
1cf8d1747859 Initial revision
claus
parents:
diff changeset
  1886
91
Claus Gittinger <cg@exept.de>
parents: 85
diff changeset
  1887
    ^ self portOfService:aNameOrNumber protocol:nil
Claus Gittinger <cg@exept.de>
parents: 85
diff changeset
  1888
28
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  1889
    "
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  1890
     Socket portOfService:'finger'
74
claus
parents: 71
diff changeset
  1891
     Socket portOfService:'nntp'  
claus
parents: 71
diff changeset
  1892
     Socket portOfService:'echo' 
claus
parents: 71
diff changeset
  1893
     Socket portOfService:'snmp' 
28
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  1894
    "
0
1cf8d1747859 Initial revision
claus
parents:
diff changeset
  1895
!
1cf8d1747859 Initial revision
claus
parents:
diff changeset
  1896
91
Claus Gittinger <cg@exept.de>
parents: 85
diff changeset
  1897
portOfService:aNameOrNumber protocol:aProtocol
819
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
  1898
    "returns the port-number for a given IP-service
91
Claus Gittinger <cg@exept.de>
parents: 85
diff changeset
  1899
     or nil if no such service exists;
Claus Gittinger <cg@exept.de>
parents: 85
diff changeset
  1900
     - used to convert service names to portNumbers"
Claus Gittinger <cg@exept.de>
parents: 85
diff changeset
  1901
604
b302a21afece Remove redundant code.
Stefan Vogel <sv@exept.de>
parents: 589
diff changeset
  1902
%{ /* NOCONTEXT */
418
317e55c6c281 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 403
diff changeset
  1903
#ifndef NO_SOCKET
91
Claus Gittinger <cg@exept.de>
parents: 85
diff changeset
  1904
    struct servent *servent = NULL;
Claus Gittinger <cg@exept.de>
parents: 85
diff changeset
  1905
    char *protocol;
Claus Gittinger <cg@exept.de>
parents: 85
diff changeset
  1906
    int tryBoth = 0;
524
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  1907
    short portNo;
91
Claus Gittinger <cg@exept.de>
parents: 85
diff changeset
  1908
604
b302a21afece Remove redundant code.
Stefan Vogel <sv@exept.de>
parents: 589
diff changeset
  1909
    if (__isSmallInteger(aNameOrNumber)) {
648
58e11a70ddaf gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents: 617
diff changeset
  1910
	RETURN ( aNameOrNumber );
92
Claus Gittinger <cg@exept.de>
parents: 91
diff changeset
  1911
    }
Claus Gittinger <cg@exept.de>
parents: 91
diff changeset
  1912
604
b302a21afece Remove redundant code.
Stefan Vogel <sv@exept.de>
parents: 589
diff changeset
  1913
    if (__isString(aProtocol)) {
648
58e11a70ddaf gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents: 617
diff changeset
  1914
	protocol = (char *)__stringVal(aProtocol);
604
b302a21afece Remove redundant code.
Stefan Vogel <sv@exept.de>
parents: 589
diff changeset
  1915
    } else {
648
58e11a70ddaf gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents: 617
diff changeset
  1916
	protocol = "tcp";
58e11a70ddaf gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents: 617
diff changeset
  1917
	tryBoth = 1;
91
Claus Gittinger <cg@exept.de>
parents: 85
diff changeset
  1918
    }
524
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  1919
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  1920
    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
  1921
	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
  1922
	if (servent != NULL) {
58e11a70ddaf gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents: 617
diff changeset
  1923
	    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
  1924
	}
58e11a70ddaf gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents: 617
diff changeset
  1925
	if (tryBoth) {
58e11a70ddaf gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents: 617
diff changeset
  1926
	    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
  1927
	    if (servent != NULL) {
58e11a70ddaf gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents: 617
diff changeset
  1928
		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
  1929
	    }
58e11a70ddaf gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents: 617
diff changeset
  1930
	}
58e11a70ddaf gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents: 617
diff changeset
  1931
	RETURN ( nil );
91
Claus Gittinger <cg@exept.de>
parents: 85
diff changeset
  1932
    }
418
317e55c6c281 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 403
diff changeset
  1933
#endif
91
Claus Gittinger <cg@exept.de>
parents: 85
diff changeset
  1934
    RETURN ( nil );
Claus Gittinger <cg@exept.de>
parents: 85
diff changeset
  1935
%}
Claus Gittinger <cg@exept.de>
parents: 85
diff changeset
  1936
    "
Claus Gittinger <cg@exept.de>
parents: 85
diff changeset
  1937
     Socket portOfService:'echo' protocol:'udp'
Claus Gittinger <cg@exept.de>
parents: 85
diff changeset
  1938
     Socket portOfService:'echo' protocol:'tcp'
Claus Gittinger <cg@exept.de>
parents: 85
diff changeset
  1939
    "
Claus Gittinger <cg@exept.de>
parents: 85
diff changeset
  1940
!
Claus Gittinger <cg@exept.de>
parents: 85
diff changeset
  1941
0
1cf8d1747859 Initial revision
claus
parents:
diff changeset
  1942
protocolOfService:aNameOrNumber
819
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
  1943
    "returns the protocol (as string) for a given IP-service
28
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  1944
     or nil if no such service exists."
0
1cf8d1747859 Initial revision
claus
parents:
diff changeset
  1945
%{
418
317e55c6c281 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 403
diff changeset
  1946
#ifndef NO_SOCKET
0
1cf8d1747859 Initial revision
claus
parents:
diff changeset
  1947
    struct servent *servent = NULL;
524
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  1948
    short portNo;
0
1cf8d1747859 Initial revision
claus
parents:
diff changeset
  1949
58
bd6753bf0401 *** empty log message ***
claus
parents: 51
diff changeset
  1950
    if (__isSmallInteger(aNameOrNumber)) {
524
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  1951
	portNo = __intVal(aNameOrNumber);
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  1952
	servent = getservbyport(htons(portNo), "tcp") ;
42
506596f9a1a8 *** empty log message ***
claus
parents: 38
diff changeset
  1953
	if (servent == NULL) {
524
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  1954
	    servent = getservbyport(htons(portNo), "udp") ;
42
506596f9a1a8 *** empty log message ***
claus
parents: 38
diff changeset
  1955
	    if (servent == NULL) {
506596f9a1a8 *** empty log message ***
claus
parents: 38
diff changeset
  1956
		RETURN ( nil );
506596f9a1a8 *** empty log message ***
claus
parents: 38
diff changeset
  1957
	    }
506596f9a1a8 *** empty log message ***
claus
parents: 38
diff changeset
  1958
	}
0
1cf8d1747859 Initial revision
claus
parents:
diff changeset
  1959
    } else {
42
506596f9a1a8 *** empty log message ***
claus
parents: 38
diff changeset
  1960
	if (__isString(aNameOrNumber)) {
524
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  1961
	    servent = getservbyname((char *) __stringVal(aNameOrNumber), "tcp");
42
506596f9a1a8 *** empty log message ***
claus
parents: 38
diff changeset
  1962
	    if (servent == NULL) {
524
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  1963
		servent = getservbyname((char *) __stringVal(aNameOrNumber), "udp");
42
506596f9a1a8 *** empty log message ***
claus
parents: 38
diff changeset
  1964
		if (servent == NULL) {
506596f9a1a8 *** empty log message ***
claus
parents: 38
diff changeset
  1965
		    RETURN ( nil );
506596f9a1a8 *** empty log message ***
claus
parents: 38
diff changeset
  1966
		}
506596f9a1a8 *** empty log message ***
claus
parents: 38
diff changeset
  1967
	    }
506596f9a1a8 *** empty log message ***
claus
parents: 38
diff changeset
  1968
	}
0
1cf8d1747859 Initial revision
claus
parents:
diff changeset
  1969
    }
1cf8d1747859 Initial revision
claus
parents:
diff changeset
  1970
    if (servent) {
448
2203a4bb620d removed all COMMA_CON / CON_COMMA uses
Claus Gittinger <cg@exept.de>
parents: 444
diff changeset
  1971
	RETURN ( __MKSTRING(servent->s_proto) );
0
1cf8d1747859 Initial revision
claus
parents:
diff changeset
  1972
    }
418
317e55c6c281 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 403
diff changeset
  1973
#endif
0
1cf8d1747859 Initial revision
claus
parents:
diff changeset
  1974
    RETURN ( nil );
1cf8d1747859 Initial revision
claus
parents:
diff changeset
  1975
%}
28
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  1976
    "
74
claus
parents: 71
diff changeset
  1977
     Socket protocolOfService:'finger' 
claus
parents: 71
diff changeset
  1978
     Socket protocolOfService:'nntp'  
28
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  1979
     Socket protocolOfService:'xxx'
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  1980
     Socket protocolOfService:79
74
claus
parents: 71
diff changeset
  1981
     Socket protocolOfService:'snmp' 
28
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  1982
    "
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  1983
!
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  1984
532
f997c3873602 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 531
diff changeset
  1985
supportedProtocolFamilies
f997c3873602 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 531
diff changeset
  1986
    "return a collection of supported protocol families.
f997c3873602 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 531
diff changeset
  1987
     This list specifies what the Socket class supports -
f997c3873602 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 531
diff changeset
  1988
     socket creation may still fail, if your system was built
f997c3873602 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 531
diff changeset
  1989
     without it."
f997c3873602 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 531
diff changeset
  1990
f997c3873602 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 531
diff changeset
  1991
    |list hasIt|
f997c3873602 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 531
diff changeset
  1992
f997c3873602 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 531
diff changeset
  1993
    list := OrderedCollection new.
f997c3873602 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 531
diff changeset
  1994
f997c3873602 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 531
diff changeset
  1995
%{
f997c3873602 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 531
diff changeset
  1996
#ifdef AF_INET
812
c8101ea70e6c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 811
diff changeset
  1997
%}.
c8101ea70e6c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 811
diff changeset
  1998
    list add:#inet.
c8101ea70e6c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 811
diff changeset
  1999
%{
532
f997c3873602 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 531
diff changeset
  2000
#endif
f997c3873602 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 531
diff changeset
  2001
%}.
f997c3873602 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 531
diff changeset
  2002
f997c3873602 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 531
diff changeset
  2003
%{
f997c3873602 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 531
diff changeset
  2004
#ifdef AF_UNIX
812
c8101ea70e6c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 811
diff changeset
  2005
%}.
c8101ea70e6c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 811
diff changeset
  2006
    list add:#unix.
c8101ea70e6c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 811
diff changeset
  2007
%{
532
f997c3873602 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 531
diff changeset
  2008
#endif
f997c3873602 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 531
diff changeset
  2009
%}.
f997c3873602 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 531
diff changeset
  2010
f997c3873602 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 531
diff changeset
  2011
%{
f997c3873602 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 531
diff changeset
  2012
#ifdef AF_INET6
812
c8101ea70e6c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 811
diff changeset
  2013
%}.
c8101ea70e6c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 811
diff changeset
  2014
    list add:#inet6.   "/ internet v6
c8101ea70e6c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 811
diff changeset
  2015
%{
532
f997c3873602 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 531
diff changeset
  2016
#endif
f997c3873602 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 531
diff changeset
  2017
%}.
f997c3873602 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 531
diff changeset
  2018
f997c3873602 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 531
diff changeset
  2019
%{
f997c3873602 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 531
diff changeset
  2020
#ifdef AF_APPLETALK
812
c8101ea70e6c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 811
diff changeset
  2021
%}.
c8101ea70e6c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 811
diff changeset
  2022
    list add:#appletalk.  "/ appletalk
c8101ea70e6c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 811
diff changeset
  2023
%{
532
f997c3873602 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 531
diff changeset
  2024
#endif
f997c3873602 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 531
diff changeset
  2025
%}.
f997c3873602 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 531
diff changeset
  2026
f997c3873602 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 531
diff changeset
  2027
%{
f997c3873602 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 531
diff changeset
  2028
#ifdef AF_DECnet
812
c8101ea70e6c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 811
diff changeset
  2029
%}.
c8101ea70e6c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 811
diff changeset
  2030
    list add:#decnet.  "/ dec net
c8101ea70e6c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 811
diff changeset
  2031
%{
532
f997c3873602 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 531
diff changeset
  2032
#endif
f997c3873602 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 531
diff changeset
  2033
%}.
f997c3873602 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 531
diff changeset
  2034
f997c3873602 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 531
diff changeset
  2035
%{
f997c3873602 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 531
diff changeset
  2036
#ifdef AF_NS
812
c8101ea70e6c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 811
diff changeset
  2037
%}.
c8101ea70e6c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 811
diff changeset
  2038
    list add:#xns.     "/ Xerox XNS
c8101ea70e6c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 811
diff changeset
  2039
%{
532
f997c3873602 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 531
diff changeset
  2040
#endif
f997c3873602 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 531
diff changeset
  2041
%}.
f997c3873602 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 531
diff changeset
  2042
f997c3873602 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 531
diff changeset
  2043
%{
812
c8101ea70e6c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 811
diff changeset
  2044
#ifdef AF_X25
c8101ea70e6c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 811
diff changeset
  2045
%}.
c8101ea70e6c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 811
diff changeset
  2046
    list add:#x25.     "/ X.25
c8101ea70e6c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 811
diff changeset
  2047
%{
532
f997c3873602 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 531
diff changeset
  2048
#endif
f997c3873602 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 531
diff changeset
  2049
%}.
f997c3873602 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 531
diff changeset
  2050
f997c3873602 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 531
diff changeset
  2051
%{
f997c3873602 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 531
diff changeset
  2052
#ifdef AF_SNA
812
c8101ea70e6c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 811
diff changeset
  2053
%}.
c8101ea70e6c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 811
diff changeset
  2054
    list add:#sna.     "/ IBM SNA
c8101ea70e6c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 811
diff changeset
  2055
%{
532
f997c3873602 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 531
diff changeset
  2056
#endif
f997c3873602 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 531
diff changeset
  2057
%}.
f997c3873602 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 531
diff changeset
  2058
f997c3873602 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 531
diff changeset
  2059
%{
f997c3873602 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 531
diff changeset
  2060
#ifdef AF_RAW
812
c8101ea70e6c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 811
diff changeset
  2061
%}.
c8101ea70e6c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 811
diff changeset
  2062
    list add:#raw.     "/ ?? RAW packets
c8101ea70e6c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 811
diff changeset
  2063
%{
532
f997c3873602 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 531
diff changeset
  2064
#endif
f997c3873602 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 531
diff changeset
  2065
%}.
f997c3873602 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 531
diff changeset
  2066
f997c3873602 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 531
diff changeset
  2067
%{
f997c3873602 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 531
diff changeset
  2068
#ifdef AF_ISO
812
c8101ea70e6c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 811
diff changeset
  2069
%}.
c8101ea70e6c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 811
diff changeset
  2070
    list add:#iso.     "/ ??
c8101ea70e6c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 811
diff changeset
  2071
%{
532
f997c3873602 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 531
diff changeset
  2072
#endif
f997c3873602 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 531
diff changeset
  2073
%}.
f997c3873602 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 531
diff changeset
  2074
f997c3873602 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 531
diff changeset
  2075
%{
f997c3873602 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 531
diff changeset
  2076
#ifdef AF_NETBIOS
812
c8101ea70e6c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 811
diff changeset
  2077
%}.
c8101ea70e6c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 811
diff changeset
  2078
    list add:#netbios. "/ ??
c8101ea70e6c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 811
diff changeset
  2079
%{
532
f997c3873602 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 531
diff changeset
  2080
#endif
f997c3873602 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 531
diff changeset
  2081
%}.
f997c3873602 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 531
diff changeset
  2082
f997c3873602 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 531
diff changeset
  2083
%{
f997c3873602 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 531
diff changeset
  2084
#ifdef AF_IPX
812
c8101ea70e6c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 811
diff changeset
  2085
%}.
c8101ea70e6c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 811
diff changeset
  2086
    list add:#ipx.     "/ Novell IPX
c8101ea70e6c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 811
diff changeset
  2087
%{
532
f997c3873602 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 531
diff changeset
  2088
#endif
f997c3873602 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 531
diff changeset
  2089
%}.
f997c3873602 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 531
diff changeset
  2090
f997c3873602 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 531
diff changeset
  2091
%{
f997c3873602 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 531
diff changeset
  2092
#ifdef AF_AX25
812
c8101ea70e6c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 811
diff changeset
  2093
%}.
c8101ea70e6c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 811
diff changeset
  2094
    list add:#ax25.    "/ Amateur Radio AX.25
c8101ea70e6c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 811
diff changeset
  2095
%{
532
f997c3873602 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 531
diff changeset
  2096
#endif
f997c3873602 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 531
diff changeset
  2097
%}.
f997c3873602 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 531
diff changeset
  2098
f997c3873602 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 531
diff changeset
  2099
%{
f997c3873602 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 531
diff changeset
  2100
#ifdef AF_NETROM
812
c8101ea70e6c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 811
diff changeset
  2101
%}.
c8101ea70e6c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 811
diff changeset
  2102
    list add:#netrom.  "/ Amateur Radio NET/ROM
c8101ea70e6c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 811
diff changeset
  2103
%{
532
f997c3873602 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 531
diff changeset
  2104
#endif
f997c3873602 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 531
diff changeset
  2105
%}.
f997c3873602 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 531
diff changeset
  2106
f997c3873602 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 531
diff changeset
  2107
%{
f997c3873602 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 531
diff changeset
  2108
#ifdef AF_BRIDGE
812
c8101ea70e6c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 811
diff changeset
  2109
%}.
c8101ea70e6c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 811
diff changeset
  2110
    list add:#bridge.  "/ multiprotocol bridge
c8101ea70e6c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 811
diff changeset
  2111
%{
532
f997c3873602 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 531
diff changeset
  2112
#endif
f997c3873602 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 531
diff changeset
  2113
%}.
f997c3873602 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 531
diff changeset
  2114
571
191b37534643 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 563
diff changeset
  2115
%{
191b37534643 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 563
diff changeset
  2116
#ifdef AF_BSC
812
c8101ea70e6c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 811
diff changeset
  2117
%}.
c8101ea70e6c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 811
diff changeset
  2118
    list add:#bsc.     "/ BISYNC 2780/3780
c8101ea70e6c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 811
diff changeset
  2119
%{
571
191b37534643 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 563
diff changeset
  2120
#endif
191b37534643 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 563
diff changeset
  2121
%}.
812
c8101ea70e6c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 811
diff changeset
  2122
c8101ea70e6c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 811
diff changeset
  2123
%{
c8101ea70e6c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 811
diff changeset
  2124
#ifdef AF_ROSE
c8101ea70e6c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 811
diff changeset
  2125
%}.
c8101ea70e6c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 811
diff changeset
  2126
    list add:#rose.    "/ Amateur Radio X.25 PLP
c8101ea70e6c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 811
diff changeset
  2127
%{
c8101ea70e6c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 811
diff changeset
  2128
#endif
c8101ea70e6c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 811
diff changeset
  2129
%}.
571
191b37534643 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 563
diff changeset
  2130
869
a6e5cbe9f558 preps for AF_IRDA
Claus Gittinger <cg@exept.de>
parents: 867
diff changeset
  2131
%{
a6e5cbe9f558 preps for AF_IRDA
Claus Gittinger <cg@exept.de>
parents: 867
diff changeset
  2132
#ifdef AF_IRDA
a6e5cbe9f558 preps for AF_IRDA
Claus Gittinger <cg@exept.de>
parents: 867
diff changeset
  2133
%}.
a6e5cbe9f558 preps for AF_IRDA
Claus Gittinger <cg@exept.de>
parents: 867
diff changeset
  2134
    list add:#irda.  "/ infrared
a6e5cbe9f558 preps for AF_IRDA
Claus Gittinger <cg@exept.de>
parents: 867
diff changeset
  2135
%{
a6e5cbe9f558 preps for AF_IRDA
Claus Gittinger <cg@exept.de>
parents: 867
diff changeset
  2136
#endif
a6e5cbe9f558 preps for AF_IRDA
Claus Gittinger <cg@exept.de>
parents: 867
diff changeset
  2137
%}.
a6e5cbe9f558 preps for AF_IRDA
Claus Gittinger <cg@exept.de>
parents: 867
diff changeset
  2138
571
191b37534643 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 563
diff changeset
  2139
532
f997c3873602 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 531
diff changeset
  2140
    ^ list
f997c3873602 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 531
diff changeset
  2141
f997c3873602 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 531
diff changeset
  2142
    "
f997c3873602 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 531
diff changeset
  2143
     Socket supportedProtocolFamilies
f997c3873602 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 531
diff changeset
  2144
    "
559
61012867ebed cleanup if #connect is interrupted
Claus Gittinger <cg@exept.de>
parents: 551
diff changeset
  2145
!
61012867ebed cleanup if #connect is interrupted
Claus Gittinger <cg@exept.de>
parents: 551
diff changeset
  2146
61012867ebed cleanup if #connect is interrupted
Claus Gittinger <cg@exept.de>
parents: 551
diff changeset
  2147
typeOfProtocol:aProtocol
61012867ebed cleanup if #connect is interrupted
Claus Gittinger <cg@exept.de>
parents: 551
diff changeset
  2148
    "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
  2149
     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
  2150
61012867ebed cleanup if #connect is interrupted
Claus Gittinger <cg@exept.de>
parents: 551
diff changeset
  2151
    (aProtocol = 'tcp') ifTrue:[^ #stream].
61012867ebed cleanup if #connect is interrupted
Claus Gittinger <cg@exept.de>
parents: 551
diff changeset
  2152
    (aProtocol = 'udp') ifTrue:[^ #datagram].
61012867ebed cleanup if #connect is interrupted
Claus Gittinger <cg@exept.de>
parents: 551
diff changeset
  2153
    (aProtocol = 'ip')  ifTrue:[^ #raw].
61012867ebed cleanup if #connect is interrupted
Claus Gittinger <cg@exept.de>
parents: 551
diff changeset
  2154
    "
61012867ebed cleanup if #connect is interrupted
Claus Gittinger <cg@exept.de>
parents: 551
diff changeset
  2155
     unix domain
61012867ebed cleanup if #connect is interrupted
Claus Gittinger <cg@exept.de>
parents: 551
diff changeset
  2156
    "
61012867ebed cleanup if #connect is interrupted
Claus Gittinger <cg@exept.de>
parents: 551
diff changeset
  2157
    (aProtocol = 'ud')  ifTrue:[^ #stream].
61012867ebed cleanup if #connect is interrupted
Claus Gittinger <cg@exept.de>
parents: 551
diff changeset
  2158
    "
61012867ebed cleanup if #connect is interrupted
Claus Gittinger <cg@exept.de>
parents: 551
diff changeset
  2159
     add x25 stuff (if any) here ...
61012867ebed cleanup if #connect is interrupted
Claus Gittinger <cg@exept.de>
parents: 551
diff changeset
  2160
    "
61012867ebed cleanup if #connect is interrupted
Claus Gittinger <cg@exept.de>
parents: 551
diff changeset
  2161
    "
61012867ebed cleanup if #connect is interrupted
Claus Gittinger <cg@exept.de>
parents: 551
diff changeset
  2162
     add appletalk stuff (if any) here ...
61012867ebed cleanup if #connect is interrupted
Claus Gittinger <cg@exept.de>
parents: 551
diff changeset
  2163
    "
61012867ebed cleanup if #connect is interrupted
Claus Gittinger <cg@exept.de>
parents: 551
diff changeset
  2164
    "
61012867ebed cleanup if #connect is interrupted
Claus Gittinger <cg@exept.de>
parents: 551
diff changeset
  2165
     add other stuff (if any) here ...
61012867ebed cleanup if #connect is interrupted
Claus Gittinger <cg@exept.de>
parents: 551
diff changeset
  2166
    "
61012867ebed cleanup if #connect is interrupted
Claus Gittinger <cg@exept.de>
parents: 551
diff changeset
  2167
    ^ nil
61012867ebed cleanup if #connect is interrupted
Claus Gittinger <cg@exept.de>
parents: 551
diff changeset
  2168
61012867ebed cleanup if #connect is interrupted
Claus Gittinger <cg@exept.de>
parents: 551
diff changeset
  2169
    "
61012867ebed cleanup if #connect is interrupted
Claus Gittinger <cg@exept.de>
parents: 551
diff changeset
  2170
     Socket typeOfProtocol:'tcp'
61012867ebed cleanup if #connect is interrupted
Claus Gittinger <cg@exept.de>
parents: 551
diff changeset
  2171
     Socket typeOfProtocol:'ucp'
61012867ebed cleanup if #connect is interrupted
Claus Gittinger <cg@exept.de>
parents: 551
diff changeset
  2172
     Socket typeOfProtocol:(Socket protocolOfService:'nntp')
61012867ebed cleanup if #connect is interrupted
Claus Gittinger <cg@exept.de>
parents: 551
diff changeset
  2173
     Socket typeOfProtocol:(Socket protocolOfService:'echo')
61012867ebed cleanup if #connect is interrupted
Claus Gittinger <cg@exept.de>
parents: 551
diff changeset
  2174
    "
28
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  2175
! !
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  2176
1110
0876a3d30fd2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1035
diff changeset
  2177
!Socket methodsFor:'Compatibility - Dolphin'!
0876a3d30fd2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1035
diff changeset
  2178
0876a3d30fd2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1035
diff changeset
  2179
setReceiveTimeout: milliseconds
0876a3d30fd2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1035
diff changeset
  2180
    self receiveTimeout:(milliseconds / 1000)
0876a3d30fd2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1035
diff changeset
  2181
!
0876a3d30fd2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1035
diff changeset
  2182
0876a3d30fd2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1035
diff changeset
  2183
setSendTimeout: milliseconds
0876a3d30fd2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1035
diff changeset
  2184
    self sendTimeout:(milliseconds / 1000)
0876a3d30fd2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1035
diff changeset
  2185
! !
0876a3d30fd2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1035
diff changeset
  2186
867
56ca0cc52fa7 category renamining
Claus Gittinger <cg@exept.de>
parents: 859
diff changeset
  2187
!Socket methodsFor:'Compatibility - ST80'!
28
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  2188
887
2b2dc6b59b5a more VW compatibility
Claus Gittinger <cg@exept.de>
parents: 876
diff changeset
  2189
acceptNonBlock
2b2dc6b59b5a more VW compatibility
Claus Gittinger <cg@exept.de>
parents: 876
diff changeset
  2190
    ^ self accept
2b2dc6b59b5a more VW compatibility
Claus Gittinger <cg@exept.de>
parents: 876
diff changeset
  2191
!
2b2dc6b59b5a more VW compatibility
Claus Gittinger <cg@exept.de>
parents: 876
diff changeset
  2192
870
452fc695de34 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 869
diff changeset
  2193
connectTo:aSocketAddress
452fc695de34 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 869
diff changeset
  2194
    ^ self connectTo:aSocketAddress hostAddress port:aSocketAddress port
452fc695de34 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 869
diff changeset
  2195
!
452fc695de34 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 869
diff changeset
  2196
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  2197
errorReporter
781
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  2198
    "ST-80 mimicry."
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  2199
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  2200
    ^ self
28
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  2201
!
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  2202
887
2b2dc6b59b5a more VW compatibility
Claus Gittinger <cg@exept.de>
parents: 876
diff changeset
  2203
ioConnection 
2b2dc6b59b5a more VW compatibility
Claus Gittinger <cg@exept.de>
parents: 876
diff changeset
  2204
    ^ self
2b2dc6b59b5a more VW compatibility
Claus Gittinger <cg@exept.de>
parents: 876
diff changeset
  2205
!
2b2dc6b59b5a more VW compatibility
Claus Gittinger <cg@exept.de>
parents: 876
diff changeset
  2206
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  2207
notReadySignal
781
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  2208
    "ST-80 mimicry.
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  2209
     for now - this is not yet raised"
71
claus
parents: 63
diff changeset
  2210
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  2211
    ^ Signal new
486
ed4e215e83ef ST-80 mimicry
Claus Gittinger <cg@exept.de>
parents: 470
diff changeset
  2212
!
ed4e215e83ef ST-80 mimicry
Claus Gittinger <cg@exept.de>
parents: 470
diff changeset
  2213
576
13acab81fad0 more ST80 compatibility
ca
parents: 572
diff changeset
  2214
readAppendStream
781
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  2215
    "ST-80 mimicry.
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  2216
     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
  2217
     ST-80 code therefore uses 'Socket readWriteStream' to access
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  2218
     the actual stream. 
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  2219
     In ST/X, sockets inherit from stream, so
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  2220
     this method returns the receiver, for transparency"
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  2221
576
13acab81fad0 more ST80 compatibility
ca
parents: 572
diff changeset
  2222
    ^ self
13acab81fad0 more ST80 compatibility
ca
parents: 572
diff changeset
  2223
!
13acab81fad0 more ST80 compatibility
ca
parents: 572
diff changeset
  2224
486
ed4e215e83ef ST-80 mimicry
Claus Gittinger <cg@exept.de>
parents: 470
diff changeset
  2225
readStream
ed4e215e83ef ST-80 mimicry
Claus Gittinger <cg@exept.de>
parents: 470
diff changeset
  2226
    "ST-80 mimicry.
ed4e215e83ef ST-80 mimicry
Claus Gittinger <cg@exept.de>
parents: 470
diff changeset
  2227
     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
  2228
     ST-80 code therefore uses 'Socket readStream' to access
781
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  2229
     the actual stream. 
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  2230
     In ST/X, sockets inherit from stream, so
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  2231
     this method returns the receiver, for transparency"
486
ed4e215e83ef ST-80 mimicry
Claus Gittinger <cg@exept.de>
parents: 470
diff changeset
  2232
ed4e215e83ef ST-80 mimicry
Claus Gittinger <cg@exept.de>
parents: 470
diff changeset
  2233
    ^ self
ed4e215e83ef ST-80 mimicry
Claus Gittinger <cg@exept.de>
parents: 470
diff changeset
  2234
ed4e215e83ef ST-80 mimicry
Claus Gittinger <cg@exept.de>
parents: 470
diff changeset
  2235
    "Created: 24.1.1997 / 23:52:57 / cg"
ed4e215e83ef ST-80 mimicry
Claus Gittinger <cg@exept.de>
parents: 470
diff changeset
  2236
!
ed4e215e83ef ST-80 mimicry
Claus Gittinger <cg@exept.de>
parents: 470
diff changeset
  2237
576
13acab81fad0 more ST80 compatibility
ca
parents: 572
diff changeset
  2238
shutdown:how
13acab81fad0 more ST80 compatibility
ca
parents: 572
diff changeset
  2239
    "ST-80 compatibility"
13acab81fad0 more ST80 compatibility
ca
parents: 572
diff changeset
  2240
13acab81fad0 more ST80 compatibility
ca
parents: 572
diff changeset
  2241
    self shutDown
13acab81fad0 more ST80 compatibility
ca
parents: 572
diff changeset
  2242
!
13acab81fad0 more ST80 compatibility
ca
parents: 572
diff changeset
  2243
486
ed4e215e83ef ST-80 mimicry
Claus Gittinger <cg@exept.de>
parents: 470
diff changeset
  2244
writeStream
ed4e215e83ef ST-80 mimicry
Claus Gittinger <cg@exept.de>
parents: 470
diff changeset
  2245
    "ST-80 mimicry.
ed4e215e83ef ST-80 mimicry
Claus Gittinger <cg@exept.de>
parents: 470
diff changeset
  2246
     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
  2247
     ST-80 code therefore uses 'Socket writeStream' to access
781
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  2248
     the actual stream. 
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  2249
     In ST/X, sockets inherit from stream, so
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  2250
     this method returns the receiver, for transparency"
486
ed4e215e83ef ST-80 mimicry
Claus Gittinger <cg@exept.de>
parents: 470
diff changeset
  2251
ed4e215e83ef ST-80 mimicry
Claus Gittinger <cg@exept.de>
parents: 470
diff changeset
  2252
    ^ self
ed4e215e83ef ST-80 mimicry
Claus Gittinger <cg@exept.de>
parents: 470
diff changeset
  2253
ed4e215e83ef ST-80 mimicry
Claus Gittinger <cg@exept.de>
parents: 470
diff changeset
  2254
    "Created: 24.1.1997 / 10:34:35 / cg"
ed4e215e83ef ST-80 mimicry
Claus Gittinger <cg@exept.de>
parents: 470
diff changeset
  2255
    "Modified: 24.1.1997 / 23:52:52 / cg"
71
claus
parents: 63
diff changeset
  2256
! !
claus
parents: 63
diff changeset
  2257
827
006dc4fe9dbd *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 823
diff changeset
  2258
!Socket methodsFor:'Compatibility - Squeak'!
771
74abb04ef57c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 752
diff changeset
  2259
74abb04ef57c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 752
diff changeset
  2260
peerName
74abb04ef57c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 752
diff changeset
  2261
    "return my peer (i.e. ipAddr + port);
74abb04ef57c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 752
diff changeset
  2262
     May return nil if not yet setup completely."
74abb04ef57c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 752
diff changeset
  2263
74abb04ef57c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 752
diff changeset
  2264
    ^ self getPeer
74abb04ef57c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 752
diff changeset
  2265
! !
74abb04ef57c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 752
diff changeset
  2266
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  2267
!Socket methodsFor:'datagram transmission'!
28
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  2268
915
3dc0e3cd838a added interface to send() and recv()
Claus Gittinger <cg@exept.de>
parents: 898
diff changeset
  2269
receiveBuffer:aDataBuffer start:startIndex for:nBytes
3dc0e3cd838a added interface to send() and recv()
Claus Gittinger <cg@exept.de>
parents: 898
diff changeset
  2270
    "receive data
3dc0e3cd838a added interface to send() and recv()
Claus Gittinger <cg@exept.de>
parents: 898
diff changeset
  2271
     Return the number of bytes received, or a negative number on error.
3dc0e3cd838a added interface to send() and recv()
Claus Gittinger <cg@exept.de>
parents: 898
diff changeset
  2272
     On error, the unix error code is left in the lastErrorNumber
3dc0e3cd838a added interface to send() and recv()
Claus Gittinger <cg@exept.de>
parents: 898
diff changeset
  2273
     instance variable.
3dc0e3cd838a added interface to send() and recv()
Claus Gittinger <cg@exept.de>
parents: 898
diff changeset
  2274
     The thread blocks until data arrives - you may want to wait before
3dc0e3cd838a added interface to send() and recv()
Claus Gittinger <cg@exept.de>
parents: 898
diff changeset
  2275
     receiving, using #readWait or #readWaitWithTimeout:."
3dc0e3cd838a added interface to send() and recv()
Claus Gittinger <cg@exept.de>
parents: 898
diff changeset
  2276
3dc0e3cd838a added interface to send() and recv()
Claus Gittinger <cg@exept.de>
parents: 898
diff changeset
  2277
3dc0e3cd838a added interface to send() and recv()
Claus Gittinger <cg@exept.de>
parents: 898
diff changeset
  2278
    |nReceived|
3dc0e3cd838a added interface to send() and recv()
Claus Gittinger <cg@exept.de>
parents: 898
diff changeset
  2279
3dc0e3cd838a added interface to send() and recv()
Claus Gittinger <cg@exept.de>
parents: 898
diff changeset
  2280
%{
3dc0e3cd838a added interface to send() and recv()
Claus Gittinger <cg@exept.de>
parents: 898
diff changeset
  2281
#ifndef NO_SOCKET
3dc0e3cd838a added interface to send() and recv()
Claus Gittinger <cg@exept.de>
parents: 898
diff changeset
  2282
    OBJ oClass, myDomain;
3dc0e3cd838a added interface to send() and recv()
Claus Gittinger <cg@exept.de>
parents: 898
diff changeset
  2283
    OBJ fp = __INST(filePointer);
3dc0e3cd838a added interface to send() and recv()
Claus Gittinger <cg@exept.de>
parents: 898
diff changeset
  2284
    int nInstVars, nInstBytes, objSize;
3dc0e3cd838a added interface to send() and recv()
Claus Gittinger <cg@exept.de>
parents: 898
diff changeset
  2285
    int sock;
3dc0e3cd838a added interface to send() and recv()
Claus Gittinger <cg@exept.de>
parents: 898
diff changeset
  2286
    int n;
3dc0e3cd838a added interface to send() and recv()
Claus Gittinger <cg@exept.de>
parents: 898
diff changeset
  2287
    char *cp;
3dc0e3cd838a added interface to send() and recv()
Claus Gittinger <cg@exept.de>
parents: 898
diff changeset
  2288
    int flags = 0;
3dc0e3cd838a added interface to send() and recv()
Claus Gittinger <cg@exept.de>
parents: 898
diff changeset
  2289
3dc0e3cd838a added interface to send() and recv()
Claus Gittinger <cg@exept.de>
parents: 898
diff changeset
  2290
    if (fp != nil) {
1009
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2291
	sock = fileno(__FILEVal(fp));
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2292
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2293
	oClass = __Class(aDataBuffer);
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2294
	switch (__intVal(__ClassInstPtr(oClass)->c_flags) & ARRAYMASK) {
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2295
	    case BYTEARRAY:
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2296
	    case WORDARRAY:
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2297
	    case SWORDARRAY:
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2298
	    case LONGARRAY:
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2299
	    case SLONGARRAY:
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2300
	    case FLOATARRAY:
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2301
	    case DOUBLEARRAY:
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2302
		break;
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2303
	    default:
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2304
		goto bad;
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2305
	}
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2306
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2307
	nInstVars = __intVal(__ClassInstPtr(oClass)->c_ninstvars);
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2308
	nInstBytes = OHDR_SIZE + nInstVars * sizeof(OBJ);
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2309
	objSize = _Size(aDataBuffer) - nInstBytes;
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2310
	cp = (char *)__InstPtr(aDataBuffer) + nInstBytes;
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2311
	if (__isSmallInteger(startIndex)) {
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2312
	    cp += __intVal(startIndex);
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2313
	    objSize -= __intVal(startIndex);
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2314
	}
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2315
	if (__isSmallInteger(nBytes)) {
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2316
	    if (__intVal(nBytes) < objSize) {
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2317
		objSize = __intVal(nBytes);
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2318
	    }
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2319
	}
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2320
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2321
	__BEGIN_INTERRUPTABLE__
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2322
	do {
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2323
	    n = recv(sock, cp, objSize, flags);
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2324
	} while ((n < 0) && (errno == EINTR));
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2325
	__END_INTERRUPTABLE__
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2326
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2327
	if (n < 0) {
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2328
	    __INST(lastErrorNumber) = __MKSMALLINT(errno);
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2329
	}
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2330
	nReceived = __MKSMALLINT(n);
915
3dc0e3cd838a added interface to send() and recv()
Claus Gittinger <cg@exept.de>
parents: 898
diff changeset
  2331
    }
3dc0e3cd838a added interface to send() and recv()
Claus Gittinger <cg@exept.de>
parents: 898
diff changeset
  2332
#endif
3dc0e3cd838a added interface to send() and recv()
Claus Gittinger <cg@exept.de>
parents: 898
diff changeset
  2333
bad: ;
3dc0e3cd838a added interface to send() and recv()
Claus Gittinger <cg@exept.de>
parents: 898
diff changeset
  2334
%}.
3dc0e3cd838a added interface to send() and recv()
Claus Gittinger <cg@exept.de>
parents: 898
diff changeset
  2335
    nReceived notNil ifTrue:[
1009
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2336
	nReceived < 0 ifTrue:[
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2337
	    'Socket [warning]: ' infoPrint.
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2338
	    (OperatingSystem errorTextForNumber:lastErrorNumber) infoPrintCR.
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2339
	].
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2340
	^ nReceived
915
3dc0e3cd838a added interface to send() and recv()
Claus Gittinger <cg@exept.de>
parents: 898
diff changeset
  2341
    ].
3dc0e3cd838a added interface to send() and recv()
Claus Gittinger <cg@exept.de>
parents: 898
diff changeset
  2342
    "
3dc0e3cd838a added interface to send() and recv()
Claus Gittinger <cg@exept.de>
parents: 898
diff changeset
  2343
     arrive here if you try to receive into an invalid buffer
3dc0e3cd838a added interface to send() and recv()
Claus Gittinger <cg@exept.de>
parents: 898
diff changeset
  2344
     (i.e. not ByteArray-like), 
3dc0e3cd838a added interface to send() and recv()
Claus Gittinger <cg@exept.de>
parents: 898
diff changeset
  2345
     or if the addressBuffer is nonNil AND not a ByteArray/String 
3dc0e3cd838a added interface to send() and recv()
Claus Gittinger <cg@exept.de>
parents: 898
diff changeset
  2346
     or if the addressBuffer is nonNil AND too small.
3dc0e3cd838a added interface to send() and recv()
Claus Gittinger <cg@exept.de>
parents: 898
diff changeset
  2347
    "
3dc0e3cd838a added interface to send() and recv()
Claus Gittinger <cg@exept.de>
parents: 898
diff changeset
  2348
    self primitiveFailed
3dc0e3cd838a added interface to send() and recv()
Claus Gittinger <cg@exept.de>
parents: 898
diff changeset
  2349
!
3dc0e3cd838a added interface to send() and recv()
Claus Gittinger <cg@exept.de>
parents: 898
diff changeset
  2350
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  2351
receiveFrom:anAddressBuffer buffer:aDataBuffer
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  2352
    "receive datagramm data - put address of originating host into
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  2353
     anAddressBuffer, data into aBuffer. 
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  2354
     Both must be ByteArray-like. The addressBuffer must
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  2355
     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
  2356
     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
  2357
     On error, the unix error code is left in the lastErrorNumber
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  2358
     instance variable."
28
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  2359
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  2360
    ^ 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
  2361
!
7d016cc30052 fixed & moved pingWalk from SNMPSession to here;
Claus Gittinger <cg@exept.de>
parents: 98
diff changeset
  2362
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  2363
receiveFrom:anAddressBuffer buffer:aDataBuffer start:startIndex for:nBytes
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  2364
    "receive datagramm data - put address of originating host into
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  2365
     anAddressBuffer, data into aBuffer. For ST-80 compatibility,
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  2366
     the addressBuffer may be a non-ByteArray; then, it must understand
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  2367
     the addressBytes-message (i.e. be a SocketAddress instance).
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  2368
     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
  2369
     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
  2370
     instance variable.
b8042ff0f82c udp receive: translate received address according to the domain
Claus Gittinger <cg@exept.de>
parents: 511
diff changeset
  2371
     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
  2372
     receiving, using #readWait or #readWaitWithTimeout:."
b8042ff0f82c udp receive: translate received address according to the domain
Claus Gittinger <cg@exept.de>
parents: 511
diff changeset
  2373
1009
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2374
    |addrBytes addrLen nReceived addrPort|
28
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  2375
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  2376
    addrBytes := ByteArray new:100.
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  2377
%{
418
317e55c6c281 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 403
diff changeset
  2378
#ifndef NO_SOCKET
513
b8042ff0f82c udp receive: translate received address according to the domain
Claus Gittinger <cg@exept.de>
parents: 511
diff changeset
  2379
    OBJ oClass, myDomain;
217
fcfbc9f71048 underscore cleanup
Claus Gittinger <cg@exept.de>
parents: 209
diff changeset
  2380
    OBJ fp = __INST(filePointer);
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  2381
    int nInstVars, nInstBytes, objSize;
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  2382
    int sock;
819
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
  2383
    union sockaddr_u sa;
1009
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2384
    int alen = 0;
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2385
    int n, offs, sIdx;
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  2386
    char *cp;
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  2387
    int flags = 0;
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  2388
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  2389
    if (fp != nil) {
1009
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2390
	sock = fileno(__FILEVal(fp));
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2391
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2392
	oClass = __Class(aDataBuffer);
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2393
	offs = 0;
1010
603216bbf89a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1009
diff changeset
  2394
	sIdx = 0;
603216bbf89a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1009
diff changeset
  2395
	if (__isSmallInteger(startIndex)) {
603216bbf89a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1009
diff changeset
  2396
	    sIdx = __intVal(startIndex) - 1;
603216bbf89a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1009
diff changeset
  2397
	}
1009
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2398
	switch (__intVal(__ClassInstPtr(oClass)->c_flags) & ARRAYMASK) {
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2399
	    case BYTEARRAY:
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2400
		offs = sIdx;
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2401
		break;
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2402
	    case WORDARRAY:
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2403
	    case SWORDARRAY:
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2404
		offs = sIdx * 2;
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2405
		break;
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2406
	    case LONGARRAY:
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2407
	    case SLONGARRAY:
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2408
		offs = sIdx * 4;
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2409
		break;
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2410
	    case LONGLONGARRAY:
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2411
	    case SLONGLONGARRAY:
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2412
		offs = sIdx * 8;
1003
0157b8af9a1e oops - datagram receive was wrong (startIndex handling)
Claus Gittinger <cg@exept.de>
parents: 969
diff changeset
  2413
# ifdef __NEED_LONGLONG_ALIGN
1009
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2414
		offs += 4;
1003
0157b8af9a1e oops - datagram receive was wrong (startIndex handling)
Claus Gittinger <cg@exept.de>
parents: 969
diff changeset
  2415
# endif
1010
603216bbf89a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1009
diff changeset
  2416
		break;
1009
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2417
	    case FLOATARRAY:
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2418
		offs = sIdx * sizeof(float);
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2419
		break;
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2420
	    case DOUBLEARRAY:
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2421
		offs = sIdx * sizeof(double);
1003
0157b8af9a1e oops - datagram receive was wrong (startIndex handling)
Claus Gittinger <cg@exept.de>
parents: 969
diff changeset
  2422
# ifdef __NEED_DOUBLE_ALIGN
1009
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2423
		offs += 4;
1003
0157b8af9a1e oops - datagram receive was wrong (startIndex handling)
Claus Gittinger <cg@exept.de>
parents: 969
diff changeset
  2424
# endif
1009
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2425
		break;
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2426
	    default:
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2427
		goto bad;
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2428
	}
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2429
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2430
	nInstVars = __intVal(__ClassInstPtr(oClass)->c_ninstvars);
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2431
	nInstBytes = OHDR_SIZE + nInstVars * sizeof(OBJ);
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2432
	objSize = _Size(aDataBuffer) - nInstBytes;
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2433
	objSize -= offs;
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2434
	if (__isSmallInteger(nBytes)) {
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2435
	    if (__intVal(nBytes) < objSize) {
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2436
		objSize = __intVal(nBytes);
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2437
	    }
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2438
	}
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2439
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2440
	__BEGIN_INTERRUPTABLE__
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2441
	do {
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2442
	    cp = (char *)__InstPtr(aDataBuffer) + nInstBytes + offs;
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2443
	    alen = sizeof(sa);
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2444
	    n = recvfrom(sock, cp, objSize, flags, (struct sockaddr *) &sa, &alen);
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2445
	} while ((n < 0) && (errno == EINTR));
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2446
	__END_INTERRUPTABLE__
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2447
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2448
	if (n >= 0) {
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2449
	    if (__isNonNilObject(addrBytes)) {
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2450
		oClass = __qClass(addrBytes);
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2451
		if ((__intVal(__ClassInstPtr(oClass)->c_flags) & ARRAYMASK) != BYTEARRAY) 
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2452
		    goto bad;
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2453
		nInstVars = __intVal(__ClassInstPtr(oClass)->c_ninstvars);
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2454
		nInstBytes = OHDR_SIZE + (nInstVars * sizeof(OBJ));
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2455
		objSize = __qSize(addrBytes) - nInstBytes;
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2456
		cp = (char *)__InstPtr(addrBytes) + nInstBytes;
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2457
		if (objSize < alen) 
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2458
		    goto bad;
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2459
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2460
		myDomain = __INST(domain);
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2461
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2462
		/*
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2463
		 * extract the datagrams address
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2464
		 */
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2465
		if (0) {
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2466
		    /* for else below */
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2467
		}
653
219b89f62113 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 650
diff changeset
  2468
# ifdef AF_INET
1009
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2469
		else if (myDomain == @symbol(inet)) {
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2470
		    if (objSize < 4) 
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2471
			goto bad;
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2472
#  ifdef DGRAM_DEBUG
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2473
		    printf("alen: %d s_addr:%x\n", alen, sa.in.sin_addr.s_addr);
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2474
#  endif /* DGRAM_DEBUG */
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2475
		    addrPort = __MKSMALLINT( ntohs(sa.in.sin_port) );
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2476
		    sa.in.sin_addr.s_addr = ntohl(sa.in.sin_addr.s_addr);    
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2477
		    cp[0] = (sa.in.sin_addr.s_addr >> 24) & 0xFF;
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2478
		    cp[1] = (sa.in.sin_addr.s_addr >> 16) & 0xFF;
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2479
		    cp[2] = (sa.in.sin_addr.s_addr >> 8) & 0xFF;
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2480
		    cp[3] = (sa.in.sin_addr.s_addr >> 0) & 0xFF;
1010
603216bbf89a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1009
diff changeset
  2481
		    alen = 4;
1009
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2482
#  ifdef DGRAM_DEBUG
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2483
		    printf("addr:%d.%d.%d.%d\n", cp[0], cp[1], cp[2], cp[3]);
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2484
#  endif /* DGRAM_DEBUG */
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2485
		}
653
219b89f62113 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 650
diff changeset
  2486
# endif /* AF_INET */
219b89f62113 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 650
diff changeset
  2487
812
c8101ea70e6c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 811
diff changeset
  2488
# ifdef AF_INET6
1009
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2489
		else if (myDomain == @symbol(inet6)) {
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2490
		    if (objSize < sizeof(sa.in6.sin6_addr.s6_addr)) 
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2491
			goto bad;
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2492
		    bcopy(sa.in6.sin6_addr.s6_addr, cp, sizeof(sa.in6.sin6_addr.s6_addr));
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2493
		    alen = sizeof(sa.in6.sin6_addr.s6_addr);
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2494
		}
812
c8101ea70e6c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 811
diff changeset
  2495
# endif /* AF_INET6 */
c8101ea70e6c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 811
diff changeset
  2496
c8101ea70e6c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 811
diff changeset
  2497
# ifdef AF_APPLETALK
1009
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2498
		else if (myDomain == @symbol(appletalk)) {
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2499
		    if (objSize < 3) 
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2500
			goto bad;
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2501
		    cp[0] = (sa.at.sat_addr.s_net >> 8) & 0xFF;
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2502
		    cp[1] = (sa.at.sat_addr.s_net) & 0xFF;
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2503
		    cp[2] = (sa.at.sat_addr.s_node) & 0xFF;
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2504
		    alen = 3;
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2505
		}
812
c8101ea70e6c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 811
diff changeset
  2506
# endif /* AF_APPLETALK */
c8101ea70e6c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 811
diff changeset
  2507
1009
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2508
		/*
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2509
		 * XXXX add addressing stuff for other domains here ...
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2510
		 */
513
b8042ff0f82c udp receive: translate received address according to the domain
Claus Gittinger <cg@exept.de>
parents: 511
diff changeset
  2511
# ifdef AF_X25
1009
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2512
		else if (myDomain == @symbol(x25)) {
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2513
		}
513
b8042ff0f82c udp receive: translate received address according to the domain
Claus Gittinger <cg@exept.de>
parents: 511
diff changeset
  2514
# endif
812
c8101ea70e6c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 811
diff changeset
  2515
c8101ea70e6c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 811
diff changeset
  2516
# ifdef AF_AX25
1009
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2517
		else if (myDomain == @symbol(ax25)) {
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2518
		}
513
b8042ff0f82c udp receive: translate received address according to the domain
Claus Gittinger <cg@exept.de>
parents: 511
diff changeset
  2519
# endif
812
c8101ea70e6c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 811
diff changeset
  2520
c8101ea70e6c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 811
diff changeset
  2521
# ifdef AF_NS
1009
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2522
		else if ((myDomain == @symbol(ns)) 
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2523
		 || (myDomain == @symbol(xns))) {
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2524
		}
513
b8042ff0f82c udp receive: translate received address according to the domain
Claus Gittinger <cg@exept.de>
parents: 511
diff changeset
  2525
# endif
812
c8101ea70e6c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 811
diff changeset
  2526
513
b8042ff0f82c udp receive: translate received address according to the domain
Claus Gittinger <cg@exept.de>
parents: 511
diff changeset
  2527
# ifdef AF_SNA
1009
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2528
		else if (myDomain == @symbol(sna)) {
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2529
		}
513
b8042ff0f82c udp receive: translate received address according to the domain
Claus Gittinger <cg@exept.de>
parents: 511
diff changeset
  2530
# endif
812
c8101ea70e6c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 811
diff changeset
  2531
513
b8042ff0f82c udp receive: translate received address according to the domain
Claus Gittinger <cg@exept.de>
parents: 511
diff changeset
  2532
# ifdef AF_RAW
1009
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2533
		else if (myDomain == @symbol(raw)) {
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2534
		}
524
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  2535
# endif
812
c8101ea70e6c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 811
diff changeset
  2536
524
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  2537
# ifdef AF_ISO
1009
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2538
		else if (myDomain == @symbol(iso)) {
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2539
		}
524
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  2540
# endif
812
c8101ea70e6c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 811
diff changeset
  2541
524
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  2542
# ifdef AF_DECnet
1009
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2543
		else if (myDomain == @symbol(decnet)) {
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2544
		}
513
b8042ff0f82c udp receive: translate received address according to the domain
Claus Gittinger <cg@exept.de>
parents: 511
diff changeset
  2545
# endif
812
c8101ea70e6c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 811
diff changeset
  2546
524
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  2547
# ifdef AF_NETBIOS
1009
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2548
		else if (myDomain == @symbol(netbios)) {
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2549
		}
530
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  2550
# endif
812
c8101ea70e6c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 811
diff changeset
  2551
653
219b89f62113 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 650
diff changeset
  2552
# ifdef AF_IPX
1009
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2553
		else if (myDomain == @symbol(ipx)) {
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2554
		}
530
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  2555
# endif
812
c8101ea70e6c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 811
diff changeset
  2556
653
219b89f62113 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 650
diff changeset
  2557
# ifdef AF_BRIDGE
1009
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2558
		else if (myDomain == @symbol(bridge)) {
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2559
		}
524
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  2560
# endif
812
c8101ea70e6c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 811
diff changeset
  2561
653
219b89f62113 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 650
diff changeset
  2562
# ifdef AF_BSC
1009
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2563
		else if (myDomain == @symbol(bsc)) {
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2564
		}
571
191b37534643 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 563
diff changeset
  2565
# endif
812
c8101ea70e6c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 811
diff changeset
  2566
c8101ea70e6c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 811
diff changeset
  2567
# ifdef AF_ROSE
1009
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2568
		else if (myDomain == @symbol(rose)) {
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2569
		}
812
c8101ea70e6c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 811
diff changeset
  2570
# endif
c8101ea70e6c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 811
diff changeset
  2571
869
a6e5cbe9f558 preps for AF_IRDA
Claus Gittinger <cg@exept.de>
parents: 867
diff changeset
  2572
# ifdef AF_IRDA
1009
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2573
		else if (myDomain == @symbol(irda)) {
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2574
		}
869
a6e5cbe9f558 preps for AF_IRDA
Claus Gittinger <cg@exept.de>
parents: 867
diff changeset
  2575
# endif
a6e5cbe9f558 preps for AF_IRDA
Claus Gittinger <cg@exept.de>
parents: 867
diff changeset
  2576
524
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  2577
# if defined(AF_CCITT) && (AF_CCITT != AF_X25)
1009
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2578
		else if (myDomain == @symbol(ccitt)) {
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2579
		}
524
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  2580
# endif
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  2581
1009
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2582
		addrLen = __MKSMALLINT(alen);
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2583
	    }
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2584
	}
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2585
	if (n < 0) {
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2586
	    __INST(lastErrorNumber) = __MKSMALLINT(errno);
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2587
	}
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2588
	nReceived = __MKSMALLINT(n);
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  2589
    }
418
317e55c6c281 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 403
diff changeset
  2590
#endif
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  2591
bad: ;
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  2592
%}.
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  2593
    nReceived notNil ifTrue:[
1009
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2594
	nReceived < 0 ifTrue:[
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2595
	    'Socket [warning]: ' infoPrint.
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2596
	    (OperatingSystem errorTextForNumber:lastErrorNumber) infoPrintCR.
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2597
	].
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2598
	addrLen notNil ifTrue:[
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2599
	   (anAddressBuffer isKindOf:SocketAddress) ifFalse:[
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2600
		"/ can be a ByteArray for ST/X compatibility
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2601
		anAddressBuffer replaceFrom:1 to:addrLen with:addrBytes
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2602
		domain == #inet ifTrue:[
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2603
		    addrBytes := anAddressBuffer copyFrom:1 to:4.
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2604
		    anAddressBuffer at:5 put:(addrPort digitByteAt:2).
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2605
		    anAddressBuffer at:6 put:(addrPort digitByteAt:1).
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2606
		] ifFalse:[
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2607
		    domain == #appletalk ifTrue:[
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2608
			addrBytes := anAddressBuffer copyFrom:1 to:3.
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2609
			anAddressBuffer at:4 put:(addrPort digitByteAt:2).
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2610
			anAddressBuffer at:5 put:(addrPort digitByteAt:1).
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2611
		    ] ifFalse:[
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2612
			self error:'please use a SocketAddress'
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2613
		    ]
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2614
		]
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2615
	    ] ifTrue:[
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2616
		"/ can be a SocketAddress for ST-80 compatibility
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2617
		anAddressBuffer hostAddress:(addrBytes copyTo:addrLen) port:addrPort.
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2618
	    ].
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2619
	].
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2620
	^ nReceived
28
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  2621
    ].
116
7789fb1c9fa2 more UD socket fixes (at least client side seems to work now)
Claus Gittinger <cg@exept.de>
parents: 115
diff changeset
  2622
    "
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  2623
     arrive here if you try to receive into an invalid buffer
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  2624
     (i.e. not ByteArray-like), 
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  2625
     or if the addressBuffer is nonNil AND not a ByteArray/String 
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  2626
     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
  2627
    "
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  2628
    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
  2629
!
7789fb1c9fa2 more UD socket fixes (at least client side seems to work now)
Claus Gittinger <cg@exept.de>
parents: 115
diff changeset
  2630
915
3dc0e3cd838a added interface to send() and recv()
Claus Gittinger <cg@exept.de>
parents: 898
diff changeset
  2631
sendBuffer:aDataBuffer start:startIndex for:count flags:flags
3dc0e3cd838a added interface to send() and recv()
Claus Gittinger <cg@exept.de>
parents: 898
diff changeset
  2632
    "send data. 
3dc0e3cd838a added interface to send() and recv()
Claus Gittinger <cg@exept.de>
parents: 898
diff changeset
  2633
     Both must be ByteArray-like. The bytes in the addressBuffer must
3dc0e3cd838a added interface to send() and recv()
Claus Gittinger <cg@exept.de>
parents: 898
diff changeset
  2634
     be a valid address for my domain (i.e. for inet, a 4-byte byteArray).
3dc0e3cd838a added interface to send() and recv()
Claus Gittinger <cg@exept.de>
parents: 898
diff changeset
  2635
     Return the number of bytes transmitted, or a negative number on error.
3dc0e3cd838a added interface to send() and recv()
Claus Gittinger <cg@exept.de>
parents: 898
diff changeset
  2636
     On error, the unix error code is left in the lastErrorNumber
3dc0e3cd838a added interface to send() and recv()
Claus Gittinger <cg@exept.de>
parents: 898
diff changeset
  2637
     instance variable."
3dc0e3cd838a added interface to send() and recv()
Claus Gittinger <cg@exept.de>
parents: 898
diff changeset
  2638
3dc0e3cd838a added interface to send() and recv()
Claus Gittinger <cg@exept.de>
parents: 898
diff changeset
  2639
    |nReceived portNo|
3dc0e3cd838a added interface to send() and recv()
Claus Gittinger <cg@exept.de>
parents: 898
diff changeset
  2640
3dc0e3cd838a added interface to send() and recv()
Claus Gittinger <cg@exept.de>
parents: 898
diff changeset
  2641
%{
3dc0e3cd838a added interface to send() and recv()
Claus Gittinger <cg@exept.de>
parents: 898
diff changeset
  2642
#ifndef NO_SOCKET
3dc0e3cd838a added interface to send() and recv()
Claus Gittinger <cg@exept.de>
parents: 898
diff changeset
  2643
    OBJ oClass;
3dc0e3cd838a added interface to send() and recv()
Claus Gittinger <cg@exept.de>
parents: 898
diff changeset
  2644
    OBJ fp = __INST(filePointer);
3dc0e3cd838a added interface to send() and recv()
Claus Gittinger <cg@exept.de>
parents: 898
diff changeset
  2645
    int nInstVars, nInstBytes, objSize;
3dc0e3cd838a added interface to send() and recv()
Claus Gittinger <cg@exept.de>
parents: 898
diff changeset
  2646
    int sock;
3dc0e3cd838a added interface to send() and recv()
Claus Gittinger <cg@exept.de>
parents: 898
diff changeset
  2647
    int n;
3dc0e3cd838a added interface to send() and recv()
Claus Gittinger <cg@exept.de>
parents: 898
diff changeset
  2648
    char *cp;
3dc0e3cd838a added interface to send() and recv()
Claus Gittinger <cg@exept.de>
parents: 898
diff changeset
  2649
    int _flags = 0;
1009
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2650
    int offs, nBytes, sIdx;
915
3dc0e3cd838a added interface to send() and recv()
Claus Gittinger <cg@exept.de>
parents: 898
diff changeset
  2651
    unsigned long norder;
3dc0e3cd838a added interface to send() and recv()
Claus Gittinger <cg@exept.de>
parents: 898
diff changeset
  2652
3dc0e3cd838a added interface to send() and recv()
Claus Gittinger <cg@exept.de>
parents: 898
diff changeset
  2653
    _flags = __longIntVal(flags);
3dc0e3cd838a added interface to send() and recv()
Claus Gittinger <cg@exept.de>
parents: 898
diff changeset
  2654
 
3dc0e3cd838a added interface to send() and recv()
Claus Gittinger <cg@exept.de>
parents: 898
diff changeset
  2655
    if ((fp != nil) 
3dc0e3cd838a added interface to send() and recv()
Claus Gittinger <cg@exept.de>
parents: 898
diff changeset
  2656
     && __isSmallInteger(startIndex)
3dc0e3cd838a added interface to send() and recv()
Claus Gittinger <cg@exept.de>
parents: 898
diff changeset
  2657
     && __isSmallInteger(count)) {
1009
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2658
	sock = fileno(__FILEVal(fp));
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2659
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2660
	oClass = __Class(aDataBuffer);
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2661
	sIdx = __intVal(startIndex) - 1;
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2662
	switch (__intVal(__ClassInstPtr(oClass)->c_flags) & ARRAYMASK) {
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2663
	    case BYTEARRAY:
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2664
		offs = sIdx;
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2665
		break;
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2666
	    case WORDARRAY:
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2667
	    case SWORDARRAY:
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2668
		offs = sIdx * 2;
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2669
		break;
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2670
	    case LONGARRAY:
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2671
	    case SLONGARRAY:
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2672
		offs = sIdx * 4;
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2673
		break;
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2674
	    case LONGLONGARRAY:
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2675
	    case SLONGLONGARRAY:
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2676
		offs = sIdx * 8;
915
3dc0e3cd838a added interface to send() and recv()
Claus Gittinger <cg@exept.de>
parents: 898
diff changeset
  2677
# ifdef __NEED_LONGLONG_ALIGN
1009
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2678
		offs += 4;
915
3dc0e3cd838a added interface to send() and recv()
Claus Gittinger <cg@exept.de>
parents: 898
diff changeset
  2679
# endif
1010
603216bbf89a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1009
diff changeset
  2680
		break;
1009
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2681
	    case FLOATARRAY:
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2682
		offs = sIdx * sizeof(float);
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2683
		break;
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2684
	    case DOUBLEARRAY:
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2685
		offs = sIdx * sizeof(double);
915
3dc0e3cd838a added interface to send() and recv()
Claus Gittinger <cg@exept.de>
parents: 898
diff changeset
  2686
# ifdef __NEED_DOUBLE_ALIGN
1009
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2687
		offs += 4;
915
3dc0e3cd838a added interface to send() and recv()
Claus Gittinger <cg@exept.de>
parents: 898
diff changeset
  2688
# endif
1009
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2689
		break;
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2690
	    default:
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2691
		goto bad;
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2692
	}
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2693
	nBytes = __intVal(count);
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2694
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2695
	nInstVars = __intVal(__ClassInstPtr(oClass)->c_ninstvars);
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2696
	nInstBytes = OHDR_SIZE + nInstVars * sizeof(OBJ);
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2697
	objSize = __qSize(aDataBuffer) - nInstBytes;
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2698
	cp = (char *)__InstPtr(aDataBuffer) + nInstBytes;
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2699
	cp += offs;
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2700
	if ((offs + nBytes) > objSize) {
915
3dc0e3cd838a added interface to send() and recv()
Claus Gittinger <cg@exept.de>
parents: 898
diff changeset
  2701
# ifdef DGRAM_DEBUG
1009
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2702
	    printf("cut off ...\n");
915
3dc0e3cd838a added interface to send() and recv()
Claus Gittinger <cg@exept.de>
parents: 898
diff changeset
  2703
# endif
1009
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2704
	    nBytes = objSize - offs;
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2705
	}
915
3dc0e3cd838a added interface to send() and recv()
Claus Gittinger <cg@exept.de>
parents: 898
diff changeset
  2706
3dc0e3cd838a added interface to send() and recv()
Claus Gittinger <cg@exept.de>
parents: 898
diff changeset
  2707
# ifdef DGRAM_DEBUG
1009
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2708
	printf("sending %d bytes ...\n", nBytes);
915
3dc0e3cd838a added interface to send() and recv()
Claus Gittinger <cg@exept.de>
parents: 898
diff changeset
  2709
# endif
3dc0e3cd838a added interface to send() and recv()
Claus Gittinger <cg@exept.de>
parents: 898
diff changeset
  2710
1009
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2711
	__BEGIN_INTERRUPTABLE__
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2712
	do {
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2713
	    n = send(sock, cp, nBytes, _flags);
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2714
	} while ((n < 0) && (errno == EINTR));
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2715
	__END_INTERRUPTABLE__
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2716
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2717
	if (n < 0) {
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2718
	    __INST(lastErrorNumber) = __MKSMALLINT(errno);
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2719
	}
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2720
	RETURN (__MKSMALLINT(n));
915
3dc0e3cd838a added interface to send() and recv()
Claus Gittinger <cg@exept.de>
parents: 898
diff changeset
  2721
    }
3dc0e3cd838a added interface to send() and recv()
Claus Gittinger <cg@exept.de>
parents: 898
diff changeset
  2722
#endif
3dc0e3cd838a added interface to send() and recv()
Claus Gittinger <cg@exept.de>
parents: 898
diff changeset
  2723
bad: ;
3dc0e3cd838a added interface to send() and recv()
Claus Gittinger <cg@exept.de>
parents: 898
diff changeset
  2724
%}.
3dc0e3cd838a added interface to send() and recv()
Claus Gittinger <cg@exept.de>
parents: 898
diff changeset
  2725
    "
3dc0e3cd838a added interface to send() and recv()
Claus Gittinger <cg@exept.de>
parents: 898
diff changeset
  2726
     arrive here if you try to send from an invalid buffer
3dc0e3cd838a added interface to send() and recv()
Claus Gittinger <cg@exept.de>
parents: 898
diff changeset
  2727
     (i.e. not ByteArray-like), 
3dc0e3cd838a added interface to send() and recv()
Claus Gittinger <cg@exept.de>
parents: 898
diff changeset
  2728
     or if the addressBuffer is nonNil AND not a ByteArray/String 
3dc0e3cd838a added interface to send() and recv()
Claus Gittinger <cg@exept.de>
parents: 898
diff changeset
  2729
     or if the addressBuffer is nonNil AND too small.
3dc0e3cd838a added interface to send() and recv()
Claus Gittinger <cg@exept.de>
parents: 898
diff changeset
  2730
    "
3dc0e3cd838a added interface to send() and recv()
Claus Gittinger <cg@exept.de>
parents: 898
diff changeset
  2731
    self primitiveFailed
3dc0e3cd838a added interface to send() and recv()
Claus Gittinger <cg@exept.de>
parents: 898
diff changeset
  2732
!
3dc0e3cd838a added interface to send() and recv()
Claus Gittinger <cg@exept.de>
parents: 898
diff changeset
  2733
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  2734
sendTo:anAddressBuffer buffer:buffer
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  2735
    "send datagramm data - fetch address of destination host from
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  2736
     anAddressBuffer, data from aDataBuffer. 
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  2737
     Both must be ByteArray-like. The bytes in the addressBuffer must
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  2738
     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
  2739
     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
  2740
     On error, the unix error code is left in the lastErrorNumber
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  2741
     instance variable.
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  2742
     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
  2743
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  2744
    ^ 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
  2745
!
7789fb1c9fa2 more UD socket fixes (at least client side seems to work now)
Claus Gittinger <cg@exept.de>
parents: 115
diff changeset
  2746
817
eda0065cbd47 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 814
diff changeset
  2747
sendTo:anAddressBuffer buffer:buffer start:startIndex for:count
eda0065cbd47 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 814
diff changeset
  2748
    "send datagramm data - fetch address of destination host from
eda0065cbd47 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 814
diff changeset
  2749
     anAddressBuffer, data from aDataBuffer. 
eda0065cbd47 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 814
diff changeset
  2750
     Both must be ByteArray-like. The bytes in the addressBuffer must
eda0065cbd47 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 814
diff changeset
  2751
     be a valid address for my domain (i.e. for inet, a 4-byte byteArray).
eda0065cbd47 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 814
diff changeset
  2752
     Return the number of bytes transmitted, or a negative number on error.
eda0065cbd47 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 814
diff changeset
  2753
     On error, the unix error code is left in the lastErrorNumber
eda0065cbd47 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 814
diff changeset
  2754
     instance variable.
eda0065cbd47 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 814
diff changeset
  2755
     Flags is currently ignored; it is there for ST-80 compatibility."
eda0065cbd47 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 814
diff changeset
  2756
eda0065cbd47 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 814
diff changeset
  2757
    ^ self sendTo:anAddressBuffer buffer:buffer start:startIndex for:count flags:0 
eda0065cbd47 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 814
diff changeset
  2758
!
eda0065cbd47 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 814
diff changeset
  2759
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  2760
sendTo:anAddressBuffer buffer:aDataBuffer start:startIndex for:count flags:flags
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  2761
    "send datagramm data - fetch address of destination host from
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  2762
     anAddressBuffer, data from aDataBuffer starting at startIndex,
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  2763
     sending count bytes. 
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  2764
     Both must be ByteArray-like. The bytes in the addressBuffer must
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  2765
     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
  2766
     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
  2767
     On error, the unix error code is left in the lastErrorNumber
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  2768
     instance variable."
0
1cf8d1747859 Initial revision
claus
parents:
diff changeset
  2769
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  2770
    |addrBytes addrLen nReceived portNo|
93
Claus Gittinger <cg@exept.de>
parents: 92
diff changeset
  2771
819
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
  2772
    "/ addressBuffer can be a byteArray (last 2 bytes are portNo, msb-first)
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
  2773
    "/ or (better) an instance of SocketAddress
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  2774
    "/
888
a868b0e54a2b ipAddress stuff
Claus Gittinger <cg@exept.de>
parents: 887
diff changeset
  2775
    (anAddressBuffer isKindOf:SocketAddress) ifFalse:[
1009
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2776
	domain == #inet ifTrue:[
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2777
	    addrBytes := anAddressBuffer copyFrom:1 to:4.
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2778
	    portNo := ((anAddressBuffer at:5) bitShift:8)
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2779
		      + (anAddressBuffer at:6).
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2780
	] ifFalse:[
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2781
	    domain == #appletalk ifTrue:[
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2782
		addrBytes := anAddressBuffer copyFrom:1 to:3.
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2783
		portNo := ((anAddressBuffer at:5) bitShift:8)
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2784
			  + (anAddressBuffer at:6).
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2785
	    ] ifFalse:[
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2786
		self error:'please use a SocketAddress'
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2787
	    ]
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2788
	].
888
a868b0e54a2b ipAddress stuff
Claus Gittinger <cg@exept.de>
parents: 887
diff changeset
  2789
    ] ifTrue:[
1009
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2790
	addrBytes := anAddressBuffer hostAddress.
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2791
	portNo := anAddressBuffer port.
28
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  2792
    ].
0
1cf8d1747859 Initial revision
claus
parents:
diff changeset
  2793
%{
418
317e55c6c281 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 403
diff changeset
  2794
#ifndef NO_SOCKET
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  2795
    OBJ oClass;
217
fcfbc9f71048 underscore cleanup
Claus Gittinger <cg@exept.de>
parents: 209
diff changeset
  2796
    OBJ fp = __INST(filePointer);
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  2797
    int nInstVars, nInstBytes, objSize;
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  2798
    int sock;
819
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
  2799
    union sockaddr_u sa;
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  2800
    struct sockaddr *saPtr = (struct sockaddr *)&sa;
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  2801
    int alen = sizeof(sa);
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  2802
    int n;
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  2803
    char *cp;
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  2804
    int _flags = 0;
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  2805
    int offs, nBytes;
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  2806
    unsigned long norder;
21
33eb5ffad09d *** empty log message ***
claus
parents: 8
diff changeset
  2807
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  2808
    _flags = __longIntVal(flags);
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  2809
 
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  2810
    if ((fp != nil) 
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  2811
     && __isSmallInteger(startIndex)
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  2812
     && __isSmallInteger(count)) {
1009
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2813
	sock = fileno(__FILEVal(fp));
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2814
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2815
	if (addrBytes == nil) {
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2816
	    alen = 0;
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2817
	    saPtr = (struct sockaddr *)0;
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2818
	} else {
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2819
	    if (! __isByteArray(addrBytes)) goto bad;
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2820
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2821
	    cp = (char *)__ByteArrayInstPtr(addrBytes)->ba_element;
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2822
	    n = __byteArraySize(addrBytes);
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2823
	    if (alen < n) n = alen;
790
6f58d65fac5e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 789
diff changeset
  2824
# ifdef DGRAM_DEBUG
1009
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2825
	    printf("address is %d bytes ... %d.%d.%d.%d\n", n, cp[0], cp[1], cp[2], cp[3]);
790
6f58d65fac5e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 789
diff changeset
  2826
# endif
1009
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2827
	    bcopy(cp, &sa.in.sin_addr.s_addr, n);
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2828
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2829
	    if (0) {
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2830
		/* for else below */
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2831
	    }
790
6f58d65fac5e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 789
diff changeset
  2832
# ifdef AF_INET
1009
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2833
	    else if (__INST(domain) == @symbol(inet)) {
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2834
		sa.in.sin_family = AF_INET;
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2835
		sa.in.sin_port = htons((u_short) __intVal(portNo)); 
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2836
	    }
790
6f58d65fac5e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 789
diff changeset
  2837
# endif
6f58d65fac5e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 789
diff changeset
  2838
# ifdef AF_INET6
1009
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2839
	    else if (__INST(domain) == @symbol(inet6)) {
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2840
		sa.in6.sin6_family = AF_INET6;
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2841
		sa.in6.sin6_port = htons((u_short) __intVal(portNo)); 
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2842
	    }
790
6f58d65fac5e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 789
diff changeset
  2843
# endif
6f58d65fac5e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 789
diff changeset
  2844
# ifdef AF_APPLETALK
1009
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2845
	    else if (__INST(domain) == @symbol(appletalk)) {
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2846
		sa.at.sat_family = AF_APPLETALK;
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2847
		sa.at.sat_port = __intVal(portNo);
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2848
	    }
790
6f58d65fac5e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 789
diff changeset
  2849
# endif
869
a6e5cbe9f558 preps for AF_IRDA
Claus Gittinger <cg@exept.de>
parents: 867
diff changeset
  2850
# ifdef AF_IRDA
1009
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2851
	    else if (__INST(domain) == @symbol(irda)) {
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2852
	    }
869
a6e5cbe9f558 preps for AF_IRDA
Claus Gittinger <cg@exept.de>
parents: 867
diff changeset
  2853
# endif
1009
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2854
	}
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2855
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2856
	oClass = __Class(aDataBuffer);
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2857
	switch (__intVal(__ClassInstPtr(oClass)->c_flags) & ARRAYMASK) {
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2858
	    case BYTEARRAY:
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2859
		offs = __intVal(startIndex) - 1;
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2860
		break;
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2861
	    case WORDARRAY:
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2862
	    case SWORDARRAY:
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2863
		offs = (__intVal(startIndex) - 1) * 2;
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2864
		break;
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2865
	    case LONGARRAY:
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2866
	    case SLONGARRAY:
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2867
		offs = (__intVal(startIndex) - 1) * 4;
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2868
		break;
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2869
	    case LONGLONGARRAY:
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2870
	    case SLONGLONGARRAY:
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2871
		offs = (__intVal(startIndex) - 1) * 8;
790
6f58d65fac5e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 789
diff changeset
  2872
# ifdef __NEED_LONGLONG_ALIGN
1009
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2873
		offs += 4;
790
6f58d65fac5e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 789
diff changeset
  2874
# endif
1010
603216bbf89a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1009
diff changeset
  2875
		break;
1009
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2876
	    case FLOATARRAY:
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2877
		offs = (__intVal(startIndex) - 1) * sizeof(float);
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2878
		break;
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2879
	    case DOUBLEARRAY:
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2880
		offs = (__intVal(startIndex) - 1) * sizeof(double);
790
6f58d65fac5e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 789
diff changeset
  2881
# ifdef __NEED_DOUBLE_ALIGN
1009
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2882
		offs += 4;
790
6f58d65fac5e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 789
diff changeset
  2883
# endif
1009
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2884
		break;
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2885
	    default:
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2886
		goto bad;
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2887
	}
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2888
	nBytes = __intVal(count);
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2889
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2890
	nInstVars = __intVal(__ClassInstPtr(oClass)->c_ninstvars);
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2891
	nInstBytes = OHDR_SIZE + nInstVars * sizeof(OBJ);
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2892
	objSize = __qSize(aDataBuffer) - nInstBytes;
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2893
	if ((offs + nBytes) > objSize) {
790
6f58d65fac5e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 789
diff changeset
  2894
# ifdef DGRAM_DEBUG
1009
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2895
	    printf("cut off ...\n");
790
6f58d65fac5e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 789
diff changeset
  2896
# endif
1009
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2897
	    nBytes = objSize - offs;
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2898
	}
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2899
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2900
	norder = htonl(sa.in.sin_addr.s_addr);
790
6f58d65fac5e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 789
diff changeset
  2901
# ifdef DGRAM_DEBUG
1009
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2902
	printf("sending %d bytes ... to ", nBytes);
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2903
	printf("%d.%d.%d.%d\n",
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2904
		    (norder >> 24) & 0xFF,
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2905
		    (norder >> 16) & 0xFF,
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2906
		    (norder >> 8) & 0xFF,
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2907
		    norder & 0xFF);
790
6f58d65fac5e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 789
diff changeset
  2908
# endif
0
1cf8d1747859 Initial revision
claus
parents:
diff changeset
  2909
1009
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2910
	__BEGIN_INTERRUPTABLE__
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2911
	do {
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2912
	    cp = (char *)__InstPtr(aDataBuffer) + nInstBytes + offs;
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2913
	    n = sendto(sock, cp, nBytes, _flags, saPtr, alen);
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2914
	} while ((n < 0) && (errno == EINTR));
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2915
	__END_INTERRUPTABLE__
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2916
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2917
	if (n < 0) {
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2918
	    __INST(lastErrorNumber) = __MKSMALLINT(errno);
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2919
	}
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2920
	RETURN (__MKSMALLINT(n));
0
1cf8d1747859 Initial revision
claus
parents:
diff changeset
  2921
    }
418
317e55c6c281 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 403
diff changeset
  2922
#endif
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  2923
bad: ;
42
506596f9a1a8 *** empty log message ***
claus
parents: 38
diff changeset
  2924
%}.
506596f9a1a8 *** empty log message ***
claus
parents: 38
diff changeset
  2925
    "
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  2926
     arrive here if you try to send from an invalid buffer
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  2927
     (i.e. not ByteArray-like), 
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  2928
     or if the addressBuffer is nonNil AND not a ByteArray/String 
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  2929
     or if the addressBuffer is nonNil AND too small.
42
506596f9a1a8 *** empty log message ***
claus
parents: 38
diff changeset
  2930
    "
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  2931
    self primitiveFailed
0
1cf8d1747859 Initial revision
claus
parents:
diff changeset
  2932
! !
1cf8d1747859 Initial revision
claus
parents:
diff changeset
  2933
1cf8d1747859 Initial revision
claus
parents:
diff changeset
  2934
!Socket methodsFor:'low level'!
1cf8d1747859 Initial revision
claus
parents:
diff changeset
  2935
507
91fb3dfd91a5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 506
diff changeset
  2936
bindAnonymously
91fb3dfd91a5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 506
diff changeset
  2937
    ^ self
91fb3dfd91a5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 506
diff changeset
  2938
	bindTo:0
91fb3dfd91a5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 506
diff changeset
  2939
	address:nil
509
eb5a2d5bab0b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 508
diff changeset
  2940
	reuseAddress:false
eb5a2d5bab0b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 508
diff changeset
  2941
!
eb5a2d5bab0b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 508
diff changeset
  2942
eb5a2d5bab0b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 508
diff changeset
  2943
bindAnonymouslyToAddress:addressString
eb5a2d5bab0b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 508
diff changeset
  2944
    ^ self
eb5a2d5bab0b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 508
diff changeset
  2945
	bindTo:0
eb5a2d5bab0b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 508
diff changeset
  2946
	address:addressString
eb5a2d5bab0b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 508
diff changeset
  2947
	reuseAddress:false
507
91fb3dfd91a5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 506
diff changeset
  2948
!
91fb3dfd91a5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 506
diff changeset
  2949
71
claus
parents: 63
diff changeset
  2950
bindTo:aSocketAddress 
425
eb8198e9f1b0 comment
Claus Gittinger <cg@exept.de>
parents: 421
diff changeset
  2951
    "ST80 compatible bind, expecting a socketAddress argument.
eb8198e9f1b0 comment
Claus Gittinger <cg@exept.de>
parents: 421
diff changeset
  2952
     The socketAddress object (an instance of SocketAddress)
eb8198e9f1b0 comment
Claus Gittinger <cg@exept.de>
parents: 421
diff changeset
  2953
     is supposed to respond to #portOrName and #address requests."
71
claus
parents: 63
diff changeset
  2954
claus
parents: 63
diff changeset
  2955
    ^ self bindTo:(aSocketAddress portOrName)
claus
parents: 63
diff changeset
  2956
	   address:(aSocketAddress address)
425
eb8198e9f1b0 comment
Claus Gittinger <cg@exept.de>
parents: 421
diff changeset
  2957
	   reuseAddress:true
71
claus
parents: 63
diff changeset
  2958
!
claus
parents: 63
diff changeset
  2959
425
eb8198e9f1b0 comment
Claus Gittinger <cg@exept.de>
parents: 421
diff changeset
  2960
bindTo:portNrOrNameString address:addressString
28
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  2961
    "low level bind - returns true if ok, false otherwise.
71
claus
parents: 63
diff changeset
  2962
     Currently only non-address binding is supported; 
425
eb8198e9f1b0 comment
Claus Gittinger <cg@exept.de>
parents: 421
diff changeset
  2963
     i.e. the address must always be nil.
71
claus
parents: 63
diff changeset
  2964
claus
parents: 63
diff changeset
  2965
     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
  2966
	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
  2967
	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
  2968
	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
  2969
     "
7789fb1c9fa2 more UD socket fixes (at least client side seems to work now)
Claus Gittinger <cg@exept.de>
parents: 115
diff changeset
  2970
425
eb8198e9f1b0 comment
Claus Gittinger <cg@exept.de>
parents: 421
diff changeset
  2971
    ^ self 
eb8198e9f1b0 comment
Claus Gittinger <cg@exept.de>
parents: 421
diff changeset
  2972
	bindTo:portNrOrNameString 
eb8198e9f1b0 comment
Claus Gittinger <cg@exept.de>
parents: 421
diff changeset
  2973
	address:addressString 
eb8198e9f1b0 comment
Claus Gittinger <cg@exept.de>
parents: 421
diff changeset
  2974
	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
  2975
!
7789fb1c9fa2 more UD socket fixes (at least client side seems to work now)
Claus Gittinger <cg@exept.de>
parents: 115
diff changeset
  2976
7789fb1c9fa2 more UD socket fixes (at least client side seems to work now)
Claus Gittinger <cg@exept.de>
parents: 115
diff changeset
  2977
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
  2978
    "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
  2979
     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
  2980
     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
  2981
7789fb1c9fa2 more UD socket fixes (at least client side seems to work now)
Claus Gittinger <cg@exept.de>
parents: 115
diff changeset
  2982
     The interpretation of portNrOrName depends on the domain:
789
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2983
	inet domain uses (4byte) byteArray like internet numbers,
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2984
	unix domain uses pathname strings,
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2985
	others use whatever will come up in the future
425
eb8198e9f1b0 comment
Claus Gittinger <cg@exept.de>
parents: 421
diff changeset
  2986
eb8198e9f1b0 comment
Claus Gittinger <cg@exept.de>
parents: 421
diff changeset
  2987
     The reuse boolean argument controls if the SO_REUSEADDR socket option
eb8198e9f1b0 comment
Claus Gittinger <cg@exept.de>
parents: 421
diff changeset
  2988
     is to be set (to avoid the 'bind: address in use' error).
eb8198e9f1b0 comment
Claus Gittinger <cg@exept.de>
parents: 421
diff changeset
  2989
    "
28
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  2990
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  2991
    filePointer isNil ifTrue:[
789
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2992
	^ self errorNotOpen
28
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  2993
    ].
1120
b43bcd84bca8 gethostbyname beeds more than 64kb stack
martin
parents: 1119
diff changeset
  2994
%{  /* STACK: 100000 */
418
317e55c6c281 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 403
diff changeset
  2995
#ifndef NO_SOCKET
217
fcfbc9f71048 underscore cleanup
Claus Gittinger <cg@exept.de>
parents: 209
diff changeset
  2996
    OBJ t = __INST(filePointer);
71
claus
parents: 63
diff changeset
  2997
    OBJ myDomain;
28
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  2998
    int sock;
819
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
  2999
    union sockaddr_u sa;
116
7789fb1c9fa2 more UD socket fixes (at least client side seems to work now)
Claus Gittinger <cg@exept.de>
parents: 115
diff changeset
  3000
    int sockaddr_size;
6
claus
parents: 4
diff changeset
  3001
    int ret;
25
996051271ce9 *** empty log message ***
claus
parents: 21
diff changeset
  3002
    int on = 1;
28
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  3003
    int ok;
0
1cf8d1747859 Initial revision
claus
parents:
diff changeset
  3004
217
fcfbc9f71048 underscore cleanup
Claus Gittinger <cg@exept.de>
parents: 209
diff changeset
  3005
    if (!__isString(__INST(domain)) && !__isSymbol(__INST(domain))) {
789
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3006
	DBGPRINTF(("SOCKET: invalid domain arg\n"));
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3007
	RETURN (false);
28
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  3008
    }
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  3009
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  3010
    ok = 0;
217
fcfbc9f71048 underscore cleanup
Claus Gittinger <cg@exept.de>
parents: 209
diff changeset
  3011
    myDomain = __INST(domain);
525
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  3012
1009
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  3013
    if (0) {
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  3014
	/* for else below */
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  3015
    }
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  3016
506
11ef93d12870 support anonymous (OS_specified) ports. (for FTP-protocol)
Claus Gittinger <cg@exept.de>
parents: 486
diff changeset
  3017
# ifdef AF_INET
1009
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  3018
    else if (myDomain == @symbol(inet)) {
789
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3019
	/*
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3020
	 * INET addresses - port must be a smallinteger or nil
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3021
	 */
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3022
	sa.in.sin_family = AF_INET;
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3023
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3024
	if (portNrOrName == nil) {
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3025
	    sa.in.sin_port = 0;
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3026
	} else {
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3027
	    if (! __isSmallInteger(portNrOrName)) {
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3028
		DBGPRINTF(("SOCKET: invalid port arg\n"));
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3029
		RETURN (false);
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3030
	    }
1009
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  3031
	    sa.in.sin_port = htons((u_short) __intVal(portNrOrName));
789
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3032
	}
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3033
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3034
	/*
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3035
	 * INET addresses - addr must be nil, integer or byteArray
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3036
	 */
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3037
	if (address == nil) {
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3038
	    sa.in.sin_addr.s_addr = htonl(INADDR_ANY);
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3039
	} else {
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3040
	    if (__isInteger(address)) {
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3041
		sa.in.sin_addr.s_addr = htonl(__longIntVal(address));
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3042
	    } else {
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3043
		if (__isByteArray(address)) {
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3044
		    unsigned char *cp;
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3045
		    int n;
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3046
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3047
		    cp = __ByteArrayInstPtr(address)->ba_element;
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3048
		    n = __byteArraySize(address);
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3049
		    if (n > 4) n = 4;
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3050
		    bcopy(cp, &sa.in.sin_addr.s_addr, n);
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3051
		} else {
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3052
		    unsigned addr;
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3053
		    struct hostent *hp ;
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3054
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3055
		    if (! __isString(address)) {
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3056
			DBGPRINTF(("SOCKET: invalid address arg in bind\n"));
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3057
			RETURN (false);
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3058
		    }
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3059
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3060
		    if ((addr = inet_addr(__stringVal(address))) != -1) {
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3061
			/* 
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3062
			 * is Internet addr in octet notation 
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3063
			 */
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3064
			bcopy(&addr, (char *) &sa.in.sin_addr, sizeof(addr)) ; /* set address */
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3065
		    } else {
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3066
			/* 
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3067
			 * do we know the host's address? 
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3068
			 */
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3069
			GETHOSTBYNAME(hp, __stringVal(address))
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3070
			if (hp == NULL) {
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3071
			    DBGPRINTF(("SOCKET: unknown host:%s\n", __stringVal(address)));
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3072
			    RETURN (false);
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3073
			}
812
c8101ea70e6c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 811
diff changeset
  3074
			if (hp->h_addrtype != AF_INET) {
c8101ea70e6c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 811
diff changeset
  3075
			    DBGPRINTF(("SOCKET: host:%s is not an inet host\n", __stringVal(address)));
c8101ea70e6c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 811
diff changeset
  3076
			    RETURN (false);
c8101ea70e6c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 811
diff changeset
  3077
			}
789
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3078
			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
  3079
			sa.in.sin_family = hp->h_addrtype;
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3080
		    }
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3081
		}
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3082
	    }
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3083
	}
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3084
	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
  3085
	sockaddr_size = sizeof(struct sockaddr_in);
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3086
	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
  3087
    }
530
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  3088
# endif /* AF_INET */
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  3089
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  3090
# ifdef AF_INET6
1009
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  3091
    else if (myDomain == @symbol(inet6)) {
789
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3092
	/*
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3093
	 * INET6 addresses - port must be a smallinteger or nil
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3094
	 */
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3095
	sa.in6.sin6_family = AF_INET6;
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3096
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3097
	if (portNrOrName == nil) {
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3098
	    sa.in6.sin6_port = 0;
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3099
	} else {
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3100
	    if (! __isSmallInteger(portNrOrName)) {
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3101
		DBGPRINTF(("SOCKET: invalid port arg\n"));
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3102
		RETURN (false);
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3103
	    }
1009
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  3104
	    sa.in6.sin6_port = htons((u_short) __intVal(portNrOrName));
789
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3105
	}
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
	/*
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3108
	 * INET6 addresses - addr must be nil or byteArray or string
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3109
	 */
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3110
	if (address == nil) {
812
c8101ea70e6c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 811
diff changeset
  3111
	    bzero(sa.in6.sin6_addr.s6_addr, sizeof(sa.in6.sin6_addr.s6_addr));
789
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3112
	} else {
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3113
	    if (__isByteArray(address)) {
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3114
		unsigned char *cp;
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3115
		int n;
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3116
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3117
		cp = __ByteArrayInstPtr(address)->ba_element;
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3118
		n = __byteArraySize(address);
812
c8101ea70e6c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 811
diff changeset
  3119
		if (n > sizeof(sa.in6.sin6_addr.s6_addr)) n = sizeof(sa.in6.sin6_addr.s6_addr);
c8101ea70e6c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 811
diff changeset
  3120
		bcopy(cp, sa.in6.sin6_addr.s6_addr, n);
789
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3121
	    } else {
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3122
		unsigned addr;
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3123
		struct hostent *hp ;
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3124
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3125
		if (! __isString(address)) {
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3126
		    DBGPRINTF(("SOCKET: invalid address arg in bind\n"));
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3127
		    RETURN (false);
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3128
		}
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3129
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3130
		/* 
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3131
		 * do we know the host's address? 
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3132
		 */
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3133
		GETHOSTBYNAME(hp, __stringVal(address))
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3134
		if (hp == NULL) {
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3135
		    DBGPRINTF(("SOCKET: unknown host:%s\n", __stringVal(address)));
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3136
		    RETURN (false);
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3137
		}
812
c8101ea70e6c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 811
diff changeset
  3138
		if (hp->h_addrtype != AF_INET6) {
c8101ea70e6c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 811
diff changeset
  3139
		    DBGPRINTF(("SOCKET: host:%s is not an ipv6 host\n", __stringVal(address)));
c8101ea70e6c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 811
diff changeset
  3140
		    RETURN (false);
c8101ea70e6c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 811
diff changeset
  3141
		}
789
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3142
		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
  3143
		sa.in.sin_family = hp->h_addrtype;
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3144
	    }
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3145
	}
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3146
812
c8101ea70e6c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 811
diff changeset
  3147
	DBGPRINTF(("SOCKET: bind addr: %x.%x.%x.%x.%x.%x... port: %x\n", 
789
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3148
			sa.in6.sin6_addr.s6_addr[0], 
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3149
			sa.in6.sin6_addr.s6_addr[1], 
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3150
			sa.in6.sin6_addr.s6_addr[2], 
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3151
			sa.in6.sin6_addr.s6_addr[3], 
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3152
			sa.in6.sin6_addr.s6_addr[4], 
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3153
			sa.in6.sin6_addr.s6_addr[5], 
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3154
			sa.in6.sin6_port));
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3155
	sockaddr_size = sizeof(struct sockaddr_in6);
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3156
	ok = 1;
530
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  3157
    }
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  3158
# endif /* AF_INET6 */
525
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  3159
506
11ef93d12870 support anonymous (OS_specified) ports. (for FTP-protocol)
Claus Gittinger <cg@exept.de>
parents: 486
diff changeset
  3160
# ifdef AF_UNIX
525
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  3161
    /*
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  3162
     * UNIX domain - port is ignored; address must be a string (path)
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  3163
     */
1009
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  3164
    else if (myDomain == @symbol(unix)) {
789
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3165
	char *pathName;
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3166
	int l;
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3167
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3168
	if (! __isString(portNrOrName)) {
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3169
	    DBGPRINTF(("SOCKET: invalid port (pathname) arg\n"));
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3170
	    RETURN (false);
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3171
	}
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3172
	pathName = (char *)__stringVal(portNrOrName);
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3173
	l = strlen(pathName);
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3174
	if ((l + sizeof ( sa.un.sun_family )) > sizeof(struct sockaddr_un)) {
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3175
	    DBGPRINTF(("SOCKET: pathname too long\n"));
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3176
	    RETURN (false);
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3177
	}
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3178
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3179
	strcpy(sa.un.sun_path, pathName);
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3180
	sa.un.sun_family = AF_UNIX;
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3181
	sockaddr_size = l + sizeof ( sa.un.sun_family );
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3182
	ok = 1;
28
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  3183
    }
530
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  3184
# endif /* AF_UNIX */
525
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  3185
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  3186
# ifdef AF_APPLETALK
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  3187
    /*
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  3188
     * this has never been tested ....
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  3189
     */
1009
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  3190
    else if (myDomain == @symbol(appletalk)) {
789
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3191
	/*
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3192
	 * APPLETALK addresses - port must be a smallinteger or nil
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3193
	 */
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3194
	sa.at.sat_family = AF_APPLETALK;
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3195
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3196
	if (portNrOrName == nil) {
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3197
	    sa.at.sat_port = 0;
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3198
	} else {
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3199
	    if (! __isSmallInteger(portNrOrName)) {
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3200
		DBGPRINTF(("SOCKET: invalid port arg\n"));
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3201
		RETURN (false);
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3202
	    }
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3203
	    sa.at.sat_port = __intVal(portNrOrName);
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3204
	}
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3205
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
	 * APPLETALK addresses - addr must be nil, integer or byteArray
819
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
  3208
	 * if integer, the first byte are the hi net bits, next byte are low net bits,
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
  3209
	 * last byte is node.
789
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 (address == nil) {
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3212
	    sa.at.sat_addr.s_net = ATADDR_ANYNET;
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3213
	    sa.at.sat_addr.s_node = ATADDR_ANYNODE;
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3214
	} else {
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3215
	    if (__isInteger(address)) {
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3216
		unsigned a = __longIntVal(address);
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3217
		sa.at.sat_addr.s_net = htons((a >> 8) & 0xFFFF);
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3218
		sa.at.sat_addr.s_node = htons(a & 0xFF);
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3219
	    } else {
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3220
		if (__isByteArray(address)) {
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3221
		    unsigned char *cp;
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3222
		    int n;
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3223
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3224
		    cp = __ByteArrayInstPtr(address)->ba_element;
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3225
		    n = __byteArraySize(address);
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3226
		    if (n > 3) n = 3;
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3227
		    bcopy(cp, &sa.at.sat_addr, n);
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3228
		} else {
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3229
		    unsigned addr;
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3230
		    struct hostent *hp ;
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
		    if (! __isString(address)) {
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3233
			DBGPRINTF(("SOCKET: invalid address arg in bind\n"));
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3234
			RETURN (false);
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3235
		    }
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
		    /* 
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3238
		     * do we know the host's address? 
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
		    GETHOSTBYNAME(hp, __stringVal(address))
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3241
		    if (hp == NULL) {
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3242
			DBGPRINTF(("SOCKET: unknown host: %s\n", __stringVal(address)));
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3243
			RETURN (false);
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3244
		    }
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3245
		    if (hp->h_addrtype != AF_APPLETALK) {
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3246
			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
  3247
			RETURN (false);
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3248
		    }
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3249
		    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
  3250
		    sa.at.sat_family = hp->h_addrtype;
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
	    }
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
	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
  3255
	sockaddr_size = sizeof(struct sockaddr_at);
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3256
	ok = 1;
525
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  3257
    }
530
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  3258
# endif /* AF_APPLETALK */
525
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  3259
28
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  3260
    /*
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  3261
     * XXXX add addressing stuff for other domains here ...
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  3262
     */
506
11ef93d12870 support anonymous (OS_specified) ports. (for FTP-protocol)
Claus Gittinger <cg@exept.de>
parents: 486
diff changeset
  3263
# ifdef AF_X25
1009
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  3264
    else if (myDomain == @symbol(x25)) {
28
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  3265
    }
506
11ef93d12870 support anonymous (OS_specified) ports. (for FTP-protocol)
Claus Gittinger <cg@exept.de>
parents: 486
diff changeset
  3266
# endif
819
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
  3267
# ifdef AF_AX25
1009
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  3268
    else if (myDomain == @symbol(ax25)) {
819
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
  3269
    }
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
  3270
# endif
506
11ef93d12870 support anonymous (OS_specified) ports. (for FTP-protocol)
Claus Gittinger <cg@exept.de>
parents: 486
diff changeset
  3271
# ifdef AF_NS
1009
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  3272
    else if ((myDomain == @symbol(ns)) 
812
c8101ea70e6c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 811
diff changeset
  3273
     || (myDomain == @symbol(xns))) {
28
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  3274
    }
506
11ef93d12870 support anonymous (OS_specified) ports. (for FTP-protocol)
Claus Gittinger <cg@exept.de>
parents: 486
diff changeset
  3275
# endif
524
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  3276
# ifdef AF_DECnet
1009
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  3277
    else if (myDomain == @symbol(decnet)) {
524
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  3278
    }
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  3279
# endif
506
11ef93d12870 support anonymous (OS_specified) ports. (for FTP-protocol)
Claus Gittinger <cg@exept.de>
parents: 486
diff changeset
  3280
# ifdef AF_SNA
1009
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  3281
    else if (myDomain == @symbol(sna)) {
93
Claus Gittinger <cg@exept.de>
parents: 92
diff changeset
  3282
    }
506
11ef93d12870 support anonymous (OS_specified) ports. (for FTP-protocol)
Claus Gittinger <cg@exept.de>
parents: 486
diff changeset
  3283
# endif
11ef93d12870 support anonymous (OS_specified) ports. (for FTP-protocol)
Claus Gittinger <cg@exept.de>
parents: 486
diff changeset
  3284
# ifdef AF_RAW
1009
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  3285
    else if (myDomain == @symbol(raw)) {
93
Claus Gittinger <cg@exept.de>
parents: 92
diff changeset
  3286
    }
506
11ef93d12870 support anonymous (OS_specified) ports. (for FTP-protocol)
Claus Gittinger <cg@exept.de>
parents: 486
diff changeset
  3287
# endif
524
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  3288
# ifdef AF_ISO
1009
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  3289
    else if (myDomain == @symbol(iso)) {
524
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  3290
    }
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  3291
# endif
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  3292
# ifdef AF_NETBIOS
1009
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  3293
    else if (myDomain == @symbol(netbios)) {
530
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  3294
    }
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  3295
# endif
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  3296
# ifdef AF_IPX
1009
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  3297
    else if (myDomain == @symbol(ipx)) {
530
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  3298
    }
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  3299
# endif
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  3300
# ifdef AF_BRIDGE
1009
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  3301
    else if (myDomain == @symbol(bridge)) {
524
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  3302
    }
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  3303
# endif
571
191b37534643 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 563
diff changeset
  3304
# ifdef AF_BSC
1009
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  3305
    else if (myDomain == @symbol(bsc)) {
571
191b37534643 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 563
diff changeset
  3306
    }
191b37534643 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 563
diff changeset
  3307
# endif
812
c8101ea70e6c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 811
diff changeset
  3308
# ifdef AF_ROSE
1009
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  3309
    else if (myDomain == @symbol(rose)) {
812
c8101ea70e6c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 811
diff changeset
  3310
    }
c8101ea70e6c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 811
diff changeset
  3311
# endif
869
a6e5cbe9f558 preps for AF_IRDA
Claus Gittinger <cg@exept.de>
parents: 867
diff changeset
  3312
# ifdef AF_IRDA
1009
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  3313
    else if (myDomain == @symbol(irda)) {
869
a6e5cbe9f558 preps for AF_IRDA
Claus Gittinger <cg@exept.de>
parents: 867
diff changeset
  3314
    }
a6e5cbe9f558 preps for AF_IRDA
Claus Gittinger <cg@exept.de>
parents: 867
diff changeset
  3315
# endif
524
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  3316
# if defined(AF_CCITT) && (AF_CCITT != AF_X25)
1009
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  3317
    else if (myDomain == @symbol(ccitt)) {
524
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  3318
    }
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  3319
# endif
0
1cf8d1747859 Initial revision
claus
parents:
diff changeset
  3320
28
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  3321
    if (! ok) {
789
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3322
	DBGPRINTF(("SOCKET: unsupported domain\n"));
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3323
	RETURN (false);
28
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  3324
    }
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  3325
110
7af19ae8693b use new FILE* wrapper macros (based on externalAddress)
Claus Gittinger <cg@exept.de>
parents: 106
diff changeset
  3326
    sock = fileno(__FILEVal(t));
28
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  3327
506
11ef93d12870 support anonymous (OS_specified) ports. (for FTP-protocol)
Claus Gittinger <cg@exept.de>
parents: 486
diff changeset
  3328
# 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
  3329
    if (reuse == true) {
789
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3330
	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
  3331
	    DBGPRINTF(("SOCKET: setsockopt - SO_REUSEADDR failed\n"));
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3332
	}
28
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  3333
    }
506
11ef93d12870 support anonymous (OS_specified) ports. (for FTP-protocol)
Claus Gittinger <cg@exept.de>
parents: 486
diff changeset
  3334
# endif /* SO_REUSEADDR */
28
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  3335
117
03cefad7e40b UD socket example & interruptable bind
Claus Gittinger <cg@exept.de>
parents: 116
diff changeset
  3336
    __BEGIN_INTERRUPTABLE__
28
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  3337
    do {
789
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3338
	ret = bind(sock, (struct sockaddr *)&sa, sockaddr_size);
28
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  3339
    } while ((ret < 0) && (errno == EINTR));
117
03cefad7e40b UD socket example & interruptable bind
Claus Gittinger <cg@exept.de>
parents: 116
diff changeset
  3340
    __END_INTERRUPTABLE__
28
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  3341
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  3342
    if (ret < 0) {
789
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3343
	DBGPRINTF(("SOCKET: bind failed errno=%d\n", errno));
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3344
	__INST(lastErrorNumber) = __MKSMALLINT(errno);
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3345
	RETURN (false);
0
1cf8d1747859 Initial revision
claus
parents:
diff changeset
  3346
    }
506
11ef93d12870 support anonymous (OS_specified) ports. (for FTP-protocol)
Claus Gittinger <cg@exept.de>
parents: 486
diff changeset
  3347
11ef93d12870 support anonymous (OS_specified) ports. (for FTP-protocol)
Claus Gittinger <cg@exept.de>
parents: 486
diff changeset
  3348
    __INST(port) = portNrOrName; __STORE(self, portNrOrName);
11ef93d12870 support anonymous (OS_specified) ports. (for FTP-protocol)
Claus Gittinger <cg@exept.de>
parents: 486
diff changeset
  3349
1009
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  3350
    if (0) {
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  3351
	/* for else below */
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  3352
    }
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  3353
506
11ef93d12870 support anonymous (OS_specified) ports. (for FTP-protocol)
Claus Gittinger <cg@exept.de>
parents: 486
diff changeset
  3354
# ifdef AF_INET
1009
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  3355
    else if (myDomain == @symbol(inet)) {
789
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3356
	if (! __isSmallInteger(portNrOrName)
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3357
	 || (portNrOrName == __MKSMALLINT(0))) {
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3358
	    int p;
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
	    /*
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3361
	     * INET anonymous port - get the actual portNr
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3362
	     */
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3363
	    if (getsockname(sock, (struct sockaddr *)&sa, &sockaddr_size) < 0) {
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3364
		DBGPRINTF(("SOCKET: cannot get peername\n"));
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3365
	    } else {
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3366
		DBGPRINTF(("SOCKET: anon port=%x\n", sa.in.sin_port));
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3367
		p = ntohs(sa.in.sin_port);
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3368
		__INST(port) = __MKSMALLINT(p);
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
	}
506
11ef93d12870 support anonymous (OS_specified) ports. (for FTP-protocol)
Claus Gittinger <cg@exept.de>
parents: 486
diff changeset
  3371
    }
11ef93d12870 support anonymous (OS_specified) ports. (for FTP-protocol)
Claus Gittinger <cg@exept.de>
parents: 486
diff changeset
  3372
# endif
819
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
  3373
530
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  3374
# ifdef AF_INET6
1009
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  3375
    else if (myDomain == @symbol(inet6)) {
789
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3376
	if (! __isSmallInteger(portNrOrName)
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3377
	 || (portNrOrName == __MKSMALLINT(0))) {
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3378
	    int p;
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3379
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3380
	    /*
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3381
	     * INET6 anonymous port - get the actual portNr
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
	    if (getsockname(sock, (struct sockaddr *)&sa, &sockaddr_size) < 0) {
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3384
		DBGPRINTF(("SOCKET: cannot get peername\n"));
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3385
	    } else {
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3386
		DBGPRINTF(("SOCKET: anon port=%x\n", sa.in.sin_port));
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3387
		p = ntohs(sa.in6.sin6_port);
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3388
		__INST(port) = __MKSMALLINT(p);
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3389
	    }
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3390
	}
530
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  3391
    }
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  3392
# endif
819
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
  3393
530
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  3394
# ifdef AF_APPLETALK
1009
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  3395
    else if (myDomain == @symbol(appletalk)) {
789
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3396
	if (! __isSmallInteger(portNrOrName)
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3397
	 || (portNrOrName == __MKSMALLINT(0))) {
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3398
	    int p;
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3399
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3400
	    /*
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3401
	     * APPLETALK anonymous port - get the actual portNr
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3402
	     */
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3403
	    if (getsockname(sock, (struct sockaddr *)&sa, &sockaddr_size) < 0) {
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3404
		DBGPRINTF(("SOCKET: cannot get peername\n"));
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3405
	    } else {
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3406
		DBGPRINTF(("SOCKET: anon port=%x\n", sa.in.sin_port));
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3407
		p = sa.at.sat_port;
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3408
		__INST(port) = __MKSMALLINT(p);
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3409
	    }
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3410
	}
530
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  3411
    }
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  3412
# endif
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  3413
506
11ef93d12870 support anonymous (OS_specified) ports. (for FTP-protocol)
Claus Gittinger <cg@exept.de>
parents: 486
diff changeset
  3414
#else /* NO_SOCKET */
418
317e55c6c281 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 403
diff changeset
  3415
    RETURN (false);
506
11ef93d12870 support anonymous (OS_specified) ports. (for FTP-protocol)
Claus Gittinger <cg@exept.de>
parents: 486
diff changeset
  3416
#endif /* NO_SOCKET */
42
506596f9a1a8 *** empty log message ***
claus
parents: 38
diff changeset
  3417
%}.
28
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  3418
    ^ true
0
1cf8d1747859 Initial revision
claus
parents:
diff changeset
  3419
28
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  3420
    "
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  3421
     (Socket domain:#inet type:#stream)
789
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3422
	 bindTo:9999
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3423
	 address:nil
28
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  3424
    "
0
1cf8d1747859 Initial revision
claus
parents:
diff changeset
  3425
!
1cf8d1747859 Initial revision
claus
parents:
diff changeset
  3426
781
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  3427
closeFile
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  3428
    "low level close"
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  3429
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  3430
%{  /* NOCONTEXT */
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  3431
#ifndef NO_SOCKET
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  3432
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  3433
    OBJ t;
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  3434
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  3435
    t = __INST(filePointer);
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  3436
    if (t != nil) {
812
c8101ea70e6c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 811
diff changeset
  3437
	FILE *fp;
c8101ea70e6c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 811
diff changeset
  3438
c8101ea70e6c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 811
diff changeset
  3439
	fp = __FILEVal(t);
821
40b0b69bf4b5 more debugs; fixed at-addresses
Claus Gittinger <cg@exept.de>
parents: 820
diff changeset
  3440
	DBGFPRINTF((stderr, "socket fclose %x (%d)\n", fp, fileno(fp)));
812
c8101ea70e6c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 811
diff changeset
  3441
	fflush(fp);
c8101ea70e6c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 811
diff changeset
  3442
	/* shutdown(fileno(fp), 2); */
1035
5b0605675dc6 @globalfor classvar stuff
Stefan Vogel <sv@exept.de>
parents: 1029
diff changeset
  3443
	if (@global(FileOpenTrace) == true) {
876
69c9ed48daba *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 875
diff changeset
  3444
	    fprintf(stderr, "fclose [Socket] %x\n", fp);
69c9ed48daba *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 875
diff changeset
  3445
	}
812
c8101ea70e6c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 811
diff changeset
  3446
	fclose(fp);
c8101ea70e6c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 811
diff changeset
  3447
	__INST(filePointer) = nil;
781
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  3448
    }
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  3449
#endif
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  3450
%}
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  3451
!
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  3452
896
2ca43149a20e Ask for possible error after async connect.
Stefan Vogel <sv@exept.de>
parents: 888
diff changeset
  3453
getSocketError
2ca43149a20e Ask for possible error after async connect.
Stefan Vogel <sv@exept.de>
parents: 888
diff changeset
  3454
    "get the SO_ERROR form the socket, which indicates the 
2ca43149a20e Ask for possible error after async connect.
Stefan Vogel <sv@exept.de>
parents: 888
diff changeset
  3455
     result of an asynchronous operation"
2ca43149a20e Ask for possible error after async connect.
Stefan Vogel <sv@exept.de>
parents: 888
diff changeset
  3456
2ca43149a20e Ask for possible error after async connect.
Stefan Vogel <sv@exept.de>
parents: 888
diff changeset
  3457
%{
2ca43149a20e Ask for possible error after async connect.
Stefan Vogel <sv@exept.de>
parents: 888
diff changeset
  3458
    OBJ t;
2ca43149a20e Ask for possible error after async connect.
Stefan Vogel <sv@exept.de>
parents: 888
diff changeset
  3459
    int err;
2ca43149a20e Ask for possible error after async connect.
Stefan Vogel <sv@exept.de>
parents: 888
diff changeset
  3460
2ca43149a20e Ask for possible error after async connect.
Stefan Vogel <sv@exept.de>
parents: 888
diff changeset
  3461
    t = __INST(filePointer);
2ca43149a20e Ask for possible error after async connect.
Stefan Vogel <sv@exept.de>
parents: 888
diff changeset
  3462
    if (t == nil)
1009
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  3463
	err = EBADF;
896
2ca43149a20e Ask for possible error after async connect.
Stefan Vogel <sv@exept.de>
parents: 888
diff changeset
  3464
    else {
1009
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  3465
	int sz, fd;
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  3466
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  3467
	fd = fileno(__FILEVal(t));
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  3468
	sz = sizeof(err);
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  3469
	if (getsockopt(fd, SOL_SOCKET, SO_ERROR, &err, &sz) < 0)
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  3470
	    err = errno;
896
2ca43149a20e Ask for possible error after async connect.
Stefan Vogel <sv@exept.de>
parents: 888
diff changeset
  3471
    }
2ca43149a20e Ask for possible error after async connect.
Stefan Vogel <sv@exept.de>
parents: 888
diff changeset
  3472
2ca43149a20e Ask for possible error after async connect.
Stefan Vogel <sv@exept.de>
parents: 888
diff changeset
  3473
    RETURN(__MKSMALLINT(err));
2ca43149a20e Ask for possible error after async connect.
Stefan Vogel <sv@exept.de>
parents: 888
diff changeset
  3474
%}
2ca43149a20e Ask for possible error after async connect.
Stefan Vogel <sv@exept.de>
parents: 888
diff changeset
  3475
2ca43149a20e Ask for possible error after async connect.
Stefan Vogel <sv@exept.de>
parents: 888
diff changeset
  3476
2ca43149a20e Ask for possible error after async connect.
Stefan Vogel <sv@exept.de>
parents: 888
diff changeset
  3477
!
2ca43149a20e Ask for possible error after async connect.
Stefan Vogel <sv@exept.de>
parents: 888
diff changeset
  3478
781
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  3479
listenFor:aNumber
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  3480
    "same as listenWithBacklog: - for ST-80 compatibility"
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  3481
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  3482
    ^ self listenWithBacklog:aNumber
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  3483
!
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  3484
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  3485
listenWithBacklog:aNumber
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  3486
    "start listening; return true if ok, false on error"
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  3487
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  3488
    filePointer isNil ifTrue:[
789
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3489
	^ self errorNotOpen
781
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  3490
    ].
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  3491
%{
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  3492
#ifndef NO_SOCKET
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  3493
    OBJ fp = __INST(filePointer);
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  3494
    int sock;
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  3495
    int ret;
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  3496
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  3497
    if (! __isSmallInteger(aNumber)) {
789
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3498
	DBGPRINTF(("SOCKET: invalid arg\n"));
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3499
	RETURN (false);
781
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  3500
    }
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  3501
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  3502
    sock = fileno(__FILEVal(fp));
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  3503
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  3504
    __BEGIN_INTERRUPTABLE__
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  3505
    do {
1009
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  3506
	ret = listen(sock, __intVal(aNumber));
781
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  3507
    } while ((ret < 0) && (errno == EINTR));
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  3508
    __END_INTERRUPTABLE__
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  3509
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  3510
    if (ret < 0) {
789
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3511
	DBGPRINTF(("SOCKET: listen call failed errno=%d\n", errno));
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3512
	__INST(lastErrorNumber) = __MKSMALLINT(errno);
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3513
	RETURN (false);
781
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  3514
    }
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  3515
#else
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  3516
    RETURN (false);
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  3517
#endif
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  3518
%}.
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  3519
    ^ true
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  3520
!
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  3521
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  3522
shutDown 
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  3523
    "shutDown without flushing "
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  3524
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  3525
    filePointer isNil ifTrue:[^ self].
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  3526
    Lobby unregister:self.
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  3527
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  3528
%{
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  3529
#ifndef NO_SOCKET
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  3530
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  3531
    OBJ fp;
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  3532
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  3533
    fp = __INST(filePointer);
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  3534
    if (fp != nil) {
812
c8101ea70e6c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 811
diff changeset
  3535
	FILE *f;
c8101ea70e6c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 811
diff changeset
  3536
	int fd;
c8101ea70e6c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 811
diff changeset
  3537
c8101ea70e6c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 811
diff changeset
  3538
	__INST(filePointer) = nil;
c8101ea70e6c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 811
diff changeset
  3539
	f = __FILEVal(fp);
c8101ea70e6c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 811
diff changeset
  3540
	fd = fileno(f);
c8101ea70e6c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 811
diff changeset
  3541
	__BEGIN_INTERRUPTABLE__
c8101ea70e6c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 811
diff changeset
  3542
	shutdown(fd, 2);
821
40b0b69bf4b5 more debugs; fixed at-addresses
Claus Gittinger <cg@exept.de>
parents: 820
diff changeset
  3543
	DBGFPRINTF((stderr, "socket fclose %x (%d)\n", fp, fd));
1035
5b0605675dc6 @globalfor classvar stuff
Stefan Vogel <sv@exept.de>
parents: 1029
diff changeset
  3544
	if (@global(FileOpenTrace) == true) {
876
69c9ed48daba *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 875
diff changeset
  3545
	    fprintf(stderr, "fclose [Socket] %x\n", f);
69c9ed48daba *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 875
diff changeset
  3546
	}
812
c8101ea70e6c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 811
diff changeset
  3547
	fclose(f);
c8101ea70e6c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 811
diff changeset
  3548
	/* close(fd); */
c8101ea70e6c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 811
diff changeset
  3549
	__END_INTERRUPTABLE__
781
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  3550
    }
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  3551
#endif
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  3552
%}
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  3553
! !
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  3554
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  3555
!Socket methodsFor:'low level-accepting'!
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  3556
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  3557
accept
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  3558
    "create a new TCP socket from accepting on the receiver.
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  3559
     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
  3560
     For ST-80 compatibility"
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  3561
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  3562
    |newSock|
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  3563
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  3564
    newSock := self class new.
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  3565
    (newSock acceptOn:self) ifFalse:[^ nil].
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  3566
    ^ newSock
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  3567
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  3568
    "
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  3569
     |sock newSock|
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  3570
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  3571
     sock := Socket provide:8004.
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  3572
     sock listenFor:5.
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  3573
     newSock := sock accept.
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  3574
    "
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  3575
!
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  3576
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  3577
acceptOn:aSocket
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  3578
    "accept a connection on a server port (created with:'Socket>>onIPPort:')
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  3579
     usage is: (Socket basicNew acceptOn:(Socket onIPPort:9999)).
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  3580
     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
  3581
     Return the true if ok; false if not."
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  3582
896
2ca43149a20e Ask for possible error after async connect.
Stefan Vogel <sv@exept.de>
parents: 888
diff changeset
  3583
    aSocket readWait.
2ca43149a20e Ask for possible error after async connect.
Stefan Vogel <sv@exept.de>
parents: 888
diff changeset
  3584
    ^ self primAcceptOn:aSocket
781
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  3585
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  3586
    "Modified: / 11.3.1996 / 14:21:31 / stefan"
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  3587
    "Modified: / 1.8.1998 / 23:39:10 / cg"
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  3588
!
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  3589
896
2ca43149a20e Ask for possible error after async connect.
Stefan Vogel <sv@exept.de>
parents: 888
diff changeset
  3590
primAcceptOn:aSocket
208
c3eca2cc16dc accept: do not wait for input on non-connected socket.
Stefan Vogel <sv@exept.de>
parents: 207
diff changeset
  3591
    "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
  3592
     usage is: (Socket basicNew acceptOn:(Socket onIPPort:9999)).
896
2ca43149a20e Ask for possible error after async connect.
Stefan Vogel <sv@exept.de>
parents: 888
diff changeset
  3593
     Return the true if ok; false if not."
208
c3eca2cc16dc accept: do not wait for input on non-connected socket.
Stefan Vogel <sv@exept.de>
parents: 207
diff changeset
  3594
c3eca2cc16dc accept: do not wait for input on non-connected socket.
Stefan Vogel <sv@exept.de>
parents: 207
diff changeset
  3595
    |serverSocketFd|
c3eca2cc16dc accept: do not wait for input on non-connected socket.
Stefan Vogel <sv@exept.de>
parents: 207
diff changeset
  3596
c3eca2cc16dc accept: do not wait for input on non-connected socket.
Stefan Vogel <sv@exept.de>
parents: 207
diff changeset
  3597
    filePointer notNil ifTrue:[
1009
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  3598
	^ self errorAlreadyOpen
208
c3eca2cc16dc accept: do not wait for input on non-connected socket.
Stefan Vogel <sv@exept.de>
parents: 207
diff changeset
  3599
    ].
c3eca2cc16dc accept: do not wait for input on non-connected socket.
Stefan Vogel <sv@exept.de>
parents: 207
diff changeset
  3600
c3eca2cc16dc accept: do not wait for input on non-connected socket.
Stefan Vogel <sv@exept.de>
parents: 207
diff changeset
  3601
    domain := aSocket domain.
c3eca2cc16dc accept: do not wait for input on non-connected socket.
Stefan Vogel <sv@exept.de>
parents: 207
diff changeset
  3602
    socketType := aSocket type.
c3eca2cc16dc accept: do not wait for input on non-connected socket.
Stefan Vogel <sv@exept.de>
parents: 207
diff changeset
  3603
    serverSocketFd := aSocket fileDescriptor.
c3eca2cc16dc accept: do not wait for input on non-connected socket.
Stefan Vogel <sv@exept.de>
parents: 207
diff changeset
  3604
    serverSocketFd isNil ifTrue:[
1009
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  3605
	^ 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
  3606
    ].
c3eca2cc16dc accept: do not wait for input on non-connected socket.
Stefan Vogel <sv@exept.de>
parents: 207
diff changeset
  3607
    (serverSocketFd isMemberOf:SmallInteger) ifFalse:[
1009
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  3608
	^ 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
  3609
    ].
1120
b43bcd84bca8 gethostbyname beeds more than 64kb stack
martin
parents: 1119
diff changeset
  3610
%{  /* STACK: 100000 */
418
317e55c6c281 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 403
diff changeset
  3611
#ifndef NO_SOCKET
208
c3eca2cc16dc accept: do not wait for input on non-connected socket.
Stefan Vogel <sv@exept.de>
parents: 207
diff changeset
  3612
    FILE *fp;
c3eca2cc16dc accept: do not wait for input on non-connected socket.
Stefan Vogel <sv@exept.de>
parents: 207
diff changeset
  3613
    int flags;
c3eca2cc16dc accept: do not wait for input on non-connected socket.
Stefan Vogel <sv@exept.de>
parents: 207
diff changeset
  3614
    int sock, newSock;
819
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
  3615
    union sockaddr_u sa;
464
600b101a7035 alen in accept
Claus Gittinger <cg@exept.de>
parents: 463
diff changeset
  3616
    int alen, alen0;
208
c3eca2cc16dc accept: do not wait for input on non-connected socket.
Stefan Vogel <sv@exept.de>
parents: 207
diff changeset
  3617
    struct hostent *he ;
c3eca2cc16dc accept: do not wait for input on non-connected socket.
Stefan Vogel <sv@exept.de>
parents: 207
diff changeset
  3618
    char dotted[20] ;
c3eca2cc16dc accept: do not wait for input on non-connected socket.
Stefan Vogel <sv@exept.de>
parents: 207
diff changeset
  3619
1009
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  3620
    if (0) {
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  3621
	/* for else below */
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  3622
    }
876
69c9ed48daba *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 875
diff changeset
  3623
# ifdef AF_INET
1009
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  3624
    else if (__INST(domain) == @symbol(inet)) {
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  3625
	alen0 = sizeof(sa.in);
464
600b101a7035 alen in accept
Claus Gittinger <cg@exept.de>
parents: 463
diff changeset
  3626
    }
876
69c9ed48daba *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 875
diff changeset
  3627
# endif
69c9ed48daba *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 875
diff changeset
  3628
# ifdef AF_INET6
1009
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  3629
    else if (__INST(domain) == @symbol(inet6)) {
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  3630
	alen0 = sizeof(sa.in6);
530
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  3631
    }
876
69c9ed48daba *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 875
diff changeset
  3632
# endif
69c9ed48daba *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 875
diff changeset
  3633
# ifdef AF_UNIX
1009
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  3634
    else if (__INST(domain) == @symbol(unix)) {
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  3635
	alen0 = sizeof(sa.un);
464
600b101a7035 alen in accept
Claus Gittinger <cg@exept.de>
parents: 463
diff changeset
  3636
    }
876
69c9ed48daba *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 875
diff changeset
  3637
# endif
530
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  3638
# ifdef AF_APPLETALK
1009
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  3639
    else if (__INST(domain) == @symbol(appletalk)) {
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  3640
	alen0 = sizeof(sa.at);
530
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  3641
    }
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  3642
# endif
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  3643
524
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  3644
    /*
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  3645
     * XXXX add addressing stuff for other domains here ...
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  3646
     */
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  3647
# ifdef AF_X25
1009
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  3648
    else if (__INST(domain) == @symbol(x25)) {
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  3649
	alen0 = sizeof(sa.x25);
819
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
  3650
    }
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
  3651
# endif
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
  3652
# ifdef AF_AX25
1009
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  3653
    else if (__INST(domain) == @symbol(ax25)) {
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  3654
	alen0 = sizeof(sa.ax25);
524
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  3655
    }
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  3656
# endif
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  3657
# ifdef AF_NS
1009
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  3658
    else if ((__INST(domain) == @symbol(ns)) 
812
c8101ea70e6c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 811
diff changeset
  3659
     || (__INST(domain) == @symbol(xns))) {
524
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  3660
    }
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  3661
# endif
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  3662
# ifdef AF_DECnet
1009
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  3663
    else if (__INST(domain) == @symbol(decnet)) {
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  3664
	alen0 = sizeof(sa.dn);
524
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  3665
    }
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  3666
# endif
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  3667
# ifdef AF_SNA
1009
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  3668
    else if (__INST(domain) == @symbol(sna)) {
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  3669
	alen0 = sizeof(sa.sna);
524
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  3670
    }
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  3671
# endif
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  3672
# ifdef AF_RAW
1009
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  3673
    else if (__INST(domain) == @symbol(raw)) {
524
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  3674
    }
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  3675
# endif
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  3676
# ifdef AF_ISO
1009
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  3677
    else if (__INST(domain) == @symbol(iso)) {
524
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  3678
    }
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  3679
# endif
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  3680
# ifdef AF_NETBIOS
1009
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  3681
    else if (__INST(domain) == @symbol(netbios)) {
530
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  3682
    }
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  3683
# endif
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  3684
# ifdef AF_IPX
1009
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  3685
    else if (__INST(domain) == @symbol(ipx)) {
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  3686
	alen0 = sizeof(sa.ipx);
530
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  3687
    }
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  3688
# endif
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  3689
# ifdef AF_BRIDGE
1009
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  3690
    else if (__INST(domain) == @symbol(bridge)) {
524
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  3691
    }
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  3692
# endif
571
191b37534643 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 563
diff changeset
  3693
# ifdef AF_BSC
1009
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  3694
    else if (__INST(domain) == @symbol(bsc)) {
571
191b37534643 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 563
diff changeset
  3695
    }
191b37534643 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 563
diff changeset
  3696
# endif
812
c8101ea70e6c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 811
diff changeset
  3697
# ifdef AF_ROSE
1009
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  3698
    else if (__INST(domain) == @symbol(rose)) {
812
c8101ea70e6c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 811
diff changeset
  3699
    }
c8101ea70e6c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 811
diff changeset
  3700
# endif
869
a6e5cbe9f558 preps for AF_IRDA
Claus Gittinger <cg@exept.de>
parents: 867
diff changeset
  3701
# ifdef AF_IRDA
1009
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  3702
    else if (__INST(domain) == @symbol(irda)) {
869
a6e5cbe9f558 preps for AF_IRDA
Claus Gittinger <cg@exept.de>
parents: 867
diff changeset
  3703
    }
a6e5cbe9f558 preps for AF_IRDA
Claus Gittinger <cg@exept.de>
parents: 867
diff changeset
  3704
# endif
524
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  3705
# if defined(AF_CCITT) && (AF_CCITT != AF_X25)
1009
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  3706
    else if (__INST(domain) == @symbol(ccitt)) {
524
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  3707
    }
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  3708
# endif
464
600b101a7035 alen in accept
Claus Gittinger <cg@exept.de>
parents: 463
diff changeset
  3709
896
2ca43149a20e Ask for possible error after async connect.
Stefan Vogel <sv@exept.de>
parents: 888
diff changeset
  3710
2ca43149a20e Ask for possible error after async connect.
Stefan Vogel <sv@exept.de>
parents: 888
diff changeset
  3711
    sock = __intVal(serverSocketFd);
2ca43149a20e Ask for possible error after async connect.
Stefan Vogel <sv@exept.de>
parents: 888
diff changeset
  3712
2ca43149a20e Ask for possible error after async connect.
Stefan Vogel <sv@exept.de>
parents: 888
diff changeset
  3713
# if defined(O_NDELAY) && defined(SET_NDELAY)
2ca43149a20e Ask for possible error after async connect.
Stefan Vogel <sv@exept.de>
parents: 888
diff changeset
  3714
    flags = ioctl(sock, F_GETFL, 0);
2ca43149a20e Ask for possible error after async connect.
Stefan Vogel <sv@exept.de>
parents: 888
diff changeset
  3715
    ioctl(sock, F_SETFL, flags | O_NDELAY);
2ca43149a20e Ask for possible error after async connect.
Stefan Vogel <sv@exept.de>
parents: 888
diff changeset
  3716
# endif
2ca43149a20e Ask for possible error after async connect.
Stefan Vogel <sv@exept.de>
parents: 888
diff changeset
  3717
208
c3eca2cc16dc accept: do not wait for input on non-connected socket.
Stefan Vogel <sv@exept.de>
parents: 207
diff changeset
  3718
    __BEGIN_INTERRUPTABLE__
c3eca2cc16dc accept: do not wait for input on non-connected socket.
Stefan Vogel <sv@exept.de>
parents: 207
diff changeset
  3719
    do {
1009
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  3720
	alen = alen0;
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  3721
	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
  3722
    } 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
  3723
    __END_INTERRUPTABLE__
821
40b0b69bf4b5 more debugs; fixed at-addresses
Claus Gittinger <cg@exept.de>
parents: 820
diff changeset
  3724
    DBGFPRINTF((stderr, "socket accept newSock=%d\n", newSock));
208
c3eca2cc16dc accept: do not wait for input on non-connected socket.
Stefan Vogel <sv@exept.de>
parents: 207
diff changeset
  3725
876
69c9ed48daba *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 875
diff changeset
  3726
# if defined(O_NDELAY) && defined(SET_NDELAY)
208
c3eca2cc16dc accept: do not wait for input on non-connected socket.
Stefan Vogel <sv@exept.de>
parents: 207
diff changeset
  3727
    ioctl(sock, F_SETFL, flags);
876
69c9ed48daba *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 875
diff changeset
  3728
# endif
208
c3eca2cc16dc accept: do not wait for input on non-connected socket.
Stefan Vogel <sv@exept.de>
parents: 207
diff changeset
  3729
c3eca2cc16dc accept: do not wait for input on non-connected socket.
Stefan Vogel <sv@exept.de>
parents: 207
diff changeset
  3730
    if (newSock < 0) {
1009
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  3731
	DBGPRINTF(("SOCKET: accept call failed errno=%d\n", errno));
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  3732
	__INST(lastErrorNumber) = __MKSMALLINT(errno);
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  3733
	RETURN (false);
208
c3eca2cc16dc accept: do not wait for input on non-connected socket.
Stefan Vogel <sv@exept.de>
parents: 207
diff changeset
  3734
    }
c3eca2cc16dc accept: do not wait for input on non-connected socket.
Stefan Vogel <sv@exept.de>
parents: 207
diff changeset
  3735
c3eca2cc16dc accept: do not wait for input on non-connected socket.
Stefan Vogel <sv@exept.de>
parents: 207
diff changeset
  3736
    /*
c3eca2cc16dc accept: do not wait for input on non-connected socket.
Stefan Vogel <sv@exept.de>
parents: 207
diff changeset
  3737
     * extract the partners address
c3eca2cc16dc accept: do not wait for input on non-connected socket.
Stefan Vogel <sv@exept.de>
parents: 207
diff changeset
  3738
     */
1009
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  3739
    if (0) {
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  3740
	/* for else below */
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  3741
    }
876
69c9ed48daba *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 875
diff changeset
  3742
# ifdef AF_INET
1009
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  3743
    else if (__INST(domain) == @symbol(inet)) {
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  3744
	GETHOSTBYADDR(he, (char *) &sa.in.sin_addr, sizeof(sa.in.sin_addr), AF_INET);
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  3745
	if (! he) {
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  3746
	    unsigned long norder;
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  3747
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  3748
	    norder = htonl(sa.in.sin_addr.s_addr) ;
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  3749
	    sprintf(dotted, "%d.%d.%d.%d",
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  3750
		    (norder >> 24) & 0xFF,
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  3751
		    (norder >> 16) & 0xFF,
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  3752
		    (norder >> 8) & 0xFF,
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  3753
		    norder & 0xFF);
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  3754
	}
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  3755
	DBGPRINTF(("SOCKET: accepted connection from host %s\n", (he ? he->h_name : dotted))) ;
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  3756
	__INST(peerName) = __MKSTRING((he ? he->h_name : dotted));
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  3757
	__STORESELF(peerName);
208
c3eca2cc16dc accept: do not wait for input on non-connected socket.
Stefan Vogel <sv@exept.de>
parents: 207
diff changeset
  3758
    }
876
69c9ed48daba *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 875
diff changeset
  3759
# endif
69c9ed48daba *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 875
diff changeset
  3760
69c9ed48daba *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 875
diff changeset
  3761
# ifdef AF_INET6
1009
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  3762
    else if (__INST(domain) == @symbol(inet6)) {
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  3763
	GETHOSTBYADDR(he, (char *) &sa.in6.sin6_addr, sizeof(sa.in6.sin6_addr), AF_INET6);
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  3764
	if (! he) {
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  3765
	    unsigned long norder;
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  3766
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  3767
	    /*
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  3768
	     * XXX: what is inet6's naming convention ?
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  3769
	     */
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  3770
	    norder = htonl(sa.in.sin_addr.s_addr) ;
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  3771
	    sprintf(dotted, "%d.%d.%d.%d.%d.%d...",
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  3772
		    sa.in6.sin6_addr.s6_addr[0],
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  3773
		    sa.in6.sin6_addr.s6_addr[1],
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  3774
		    sa.in6.sin6_addr.s6_addr[2],
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  3775
		    sa.in6.sin6_addr.s6_addr[3],
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  3776
		    sa.in6.sin6_addr.s6_addr[4],
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  3777
		    sa.in6.sin6_addr.s6_addr[5]);
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  3778
	}
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  3779
	DBGPRINTF(("SOCKET: accepted connection from host %s\n", (he ? he->h_name : dotted))) ;
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  3780
	__INST(peerName) = __MKSTRING((he ? he->h_name : dotted));
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  3781
	__STORESELF(peerName);
530
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  3782
    }
876
69c9ed48daba *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 875
diff changeset
  3783
# endif
69c9ed48daba *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 875
diff changeset
  3784
69c9ed48daba *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 875
diff changeset
  3785
# ifdef AF_UNIX
1009
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  3786
    else if (__INST(domain) == @symbol(unix)) {
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  3787
	DBGPRINTF(("SOCKET: accepted connection on unix socket\n")) ;
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  3788
	/* 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
  3789
    }
876
69c9ed48daba *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 875
diff changeset
  3790
# endif
69c9ed48daba *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 875
diff changeset
  3791
69c9ed48daba *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 875
diff changeset
  3792
# ifdef AF_APPLETALK
1009
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  3793
    else if (__INST(domain) == @symbol(appletalk)) {
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  3794
	GETHOSTBYADDR(he, (char *) &sa.at.sat_addr, sizeof(sa.at.sat_addr), AF_APPLETALK);
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  3795
	if (! he) {
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  3796
	    unsigned net;
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  3797
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  3798
	    /*
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  3799
	     * XXX: what is apples naming convention ?
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  3800
	     */
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  3801
	    net = htons(sa.at.sat_addr.s_net) ;
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  3802
	    sprintf(dotted, "%d.%d",
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  3803
		    net,
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  3804
		    sa.at.sat_addr.s_node);
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  3805
	}
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  3806
	DBGPRINTF(("SOCKET: accepted connection from host %s\n", (he ? he->h_name : dotted))) ;
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  3807
	__INST(peerName) = __MKSTRING((he ? he->h_name : dotted));
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  3808
	__STORESELF(peerName);
530
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  3809
    }
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  3810
# endif
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  3811
524
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  3812
    /*
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  3813
     * XXXX add addressing stuff for other domains here ...
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  3814
     */
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  3815
# ifdef AF_X25
1009
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  3816
    else if (__INST(domain) == @symbol(x25)) {
524
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  3817
    }
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  3818
# endif
819
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
  3819
# ifdef AF_AX25
1009
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  3820
    else if (__INST(domain) == @symbol(ax25)) {
819
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
  3821
    }
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
  3822
# endif
524
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  3823
# ifdef AF_NS
1009
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  3824
    else if ((__INST(domain) == @symbol(ns)) 
812
c8101ea70e6c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 811
diff changeset
  3825
     || (__INST(domain) == @symbol(xns))) {
524
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  3826
    }
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  3827
# endif
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  3828
# ifdef AF_DECnet
1009
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  3829
    else if (__INST(domain) == @symbol(decnet)) {
524
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  3830
    }
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  3831
# endif
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  3832
# ifdef AF_SNA
1009
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  3833
    else if (__INST(domain) == @symbol(sna)) {
524
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  3834
    }
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  3835
# endif
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  3836
# ifdef AF_RAW
1009
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  3837
    else if (__INST(domain) == @symbol(raw)) {
524
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  3838
    }
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  3839
# endif
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  3840
# ifdef AF_ISO
1009
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  3841
    else if (__INST(domain) == @symbol(iso)) {
524
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  3842
    }
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  3843
# endif
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  3844
# ifdef AF_NETBIOS
1009
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  3845
    else if (__INST(domain) == @symbol(netbios)) {
530
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  3846
    }
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  3847
# endif
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  3848
# ifdef AF_IPX
1009
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  3849
    else if (__INST(domain) == @symbol(ipx)) {
530
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  3850
    }
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  3851
# endif
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  3852
# ifdef AF_BRIDGE
1009
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  3853
    else if (__INST(domain) == @symbol(bridge)) {
524
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  3854
    }
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  3855
# endif
571
191b37534643 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 563
diff changeset
  3856
# ifdef AF_BSC
1009
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  3857
    else if (__INST(domain) == @symbol(bsc)) {
571
191b37534643 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 563
diff changeset
  3858
    }
191b37534643 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 563
diff changeset
  3859
# endif
812
c8101ea70e6c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 811
diff changeset
  3860
# ifdef AF_ROSE
1009
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  3861
    else if (__INST(domain) == @symbol(rose)) {
812
c8101ea70e6c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 811
diff changeset
  3862
    }
c8101ea70e6c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 811
diff changeset
  3863
# endif
869
a6e5cbe9f558 preps for AF_IRDA
Claus Gittinger <cg@exept.de>
parents: 867
diff changeset
  3864
# ifdef AF_IRDA
1009
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  3865
    else if (__INST(domain) == @symbol(irda)) {
869
a6e5cbe9f558 preps for AF_IRDA
Claus Gittinger <cg@exept.de>
parents: 867
diff changeset
  3866
    }
a6e5cbe9f558 preps for AF_IRDA
Claus Gittinger <cg@exept.de>
parents: 867
diff changeset
  3867
# endif
524
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  3868
# if defined(AF_CCITT) && (AF_CCITT != AF_X25)
1009
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  3869
    else if (__INST(domain) == @symbol(ccitt)) {
524
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  3870
    }
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  3871
# endif
208
c3eca2cc16dc accept: do not wait for input on non-connected socket.
Stefan Vogel <sv@exept.de>
parents: 207
diff changeset
  3872
c3eca2cc16dc accept: do not wait for input on non-connected socket.
Stefan Vogel <sv@exept.de>
parents: 207
diff changeset
  3873
    /* 
c3eca2cc16dc accept: do not wait for input on non-connected socket.
Stefan Vogel <sv@exept.de>
parents: 207
diff changeset
  3874
     * make it a FILE * 
c3eca2cc16dc accept: do not wait for input on non-connected socket.
Stefan Vogel <sv@exept.de>
parents: 207
diff changeset
  3875
     */
c3eca2cc16dc accept: do not wait for input on non-connected socket.
Stefan Vogel <sv@exept.de>
parents: 207
diff changeset
  3876
    fp = fdopen(newSock, "r+");
c3eca2cc16dc accept: do not wait for input on non-connected socket.
Stefan Vogel <sv@exept.de>
parents: 207
diff changeset
  3877
    if (! fp) {
1009
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  3878
	DBGPRINTF(("SOCKET: fdopen call failed\n"));
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  3879
	__INST(lastErrorNumber) = __MKSMALLINT(errno);
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  3880
	close(newSock);
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  3881
	DBGFPRINTF((stderr, "socket close (fdopen failed) (%d)\n", newSock));
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  3882
	RETURN (false);
876
69c9ed48daba *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 875
diff changeset
  3883
    }
1035
5b0605675dc6 @globalfor classvar stuff
Stefan Vogel <sv@exept.de>
parents: 1029
diff changeset
  3884
    if (@global(FileOpenTrace) == true) {
1009
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  3885
	fprintf(stderr, "fdopen [Socket] -> %x\n", fp);
208
c3eca2cc16dc accept: do not wait for input on non-connected socket.
Stefan Vogel <sv@exept.de>
parents: 207
diff changeset
  3886
    }
876
69c9ed48daba *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 875
diff changeset
  3887
69c9ed48daba *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 875
diff changeset
  3888
# ifdef BUGGY_STDIO_LIB
69c9ed48daba *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 875
diff changeset
  3889
    setbuf(fp, NULL);
69c9ed48daba *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 875
diff changeset
  3890
    __INST(buffered) = false;
69c9ed48daba *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 875
diff changeset
  3891
# endif
69c9ed48daba *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 875
diff changeset
  3892
69c9ed48daba *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 875
diff changeset
  3893
    __INST(filePointer) = __MKOBJ(fp);
69c9ed48daba *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 875
diff changeset
  3894
    __STORESELF(filePointer);
69c9ed48daba *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 875
diff changeset
  3895
#endif /* not NO_SOCKET */
208
c3eca2cc16dc accept: do not wait for input on non-connected socket.
Stefan Vogel <sv@exept.de>
parents: 207
diff changeset
  3896
%}.
c3eca2cc16dc accept: do not wait for input on non-connected socket.
Stefan Vogel <sv@exept.de>
parents: 207
diff changeset
  3897
    mode := #readwrite.
c3eca2cc16dc accept: do not wait for input on non-connected socket.
Stefan Vogel <sv@exept.de>
parents: 207
diff changeset
  3898
    Lobby register:self.
c3eca2cc16dc accept: do not wait for input on non-connected socket.
Stefan Vogel <sv@exept.de>
parents: 207
diff changeset
  3899
    binary := false.
c3eca2cc16dc accept: do not wait for input on non-connected socket.
Stefan Vogel <sv@exept.de>
parents: 207
diff changeset
  3900
    port := aSocket port.
c3eca2cc16dc accept: do not wait for input on non-connected socket.
Stefan Vogel <sv@exept.de>
parents: 207
diff changeset
  3901
    ^ true
c3eca2cc16dc accept: do not wait for input on non-connected socket.
Stefan Vogel <sv@exept.de>
parents: 207
diff changeset
  3902
!
c3eca2cc16dc accept: do not wait for input on non-connected socket.
Stefan Vogel <sv@exept.de>
parents: 207
diff changeset
  3903
781
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  3904
waitForNewConnectionOrDataOnAny:otherConnections timeout:timeoutSeconds
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  3905
    "suspend the current process, until either a new connection comes
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  3906
     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
  3907
     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
  3908
     For an old connection, that socket is returned.
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  3909
     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
  3910
     or nil, if a timeout occured.
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  3911
     This method implements the inner wait-primitive of a multi-connection 
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  3912
     server application."
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  3913
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  3914
    "/ first, a quick check if data is already available
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  3915
1035
5b0605675dc6 @globalfor classvar stuff
Stefan Vogel <sv@exept.de>
parents: 1029
diff changeset
  3916
    |wasBlocked sema|
781
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  3917
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  3918
    self canReadWithoutBlocking ifTrue:[
1170
270d76fc288f *** empty log message ***
penk
parents: 1146
diff changeset
  3919
	^ self accept.
781
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  3920
    ].
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  3921
    otherConnections do:[:aConnection |
1170
270d76fc288f *** empty log message ***
penk
parents: 1146
diff changeset
  3922
	aConnection canReadWithoutBlocking ifTrue:[
270d76fc288f *** empty log message ***
penk
parents: 1146
diff changeset
  3923
	    ^ aConnection
270d76fc288f *** empty log message ***
penk
parents: 1146
diff changeset
  3924
	]
781
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  3925
    ].
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  3926
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  3927
    [
1170
270d76fc288f *** empty log message ***
penk
parents: 1146
diff changeset
  3928
	"/ check again - prevent incoming interrupts from disturbing our setup
270d76fc288f *** empty log message ***
penk
parents: 1146
diff changeset
  3929
	wasBlocked := OperatingSystem blockInterrupts.
270d76fc288f *** empty log message ***
penk
parents: 1146
diff changeset
  3930
270d76fc288f *** empty log message ***
penk
parents: 1146
diff changeset
  3931
	self canReadWithoutBlocking ifTrue:[
270d76fc288f *** empty log message ***
penk
parents: 1146
diff changeset
  3932
	    ^ self accept.
270d76fc288f *** empty log message ***
penk
parents: 1146
diff changeset
  3933
	].
270d76fc288f *** empty log message ***
penk
parents: 1146
diff changeset
  3934
	otherConnections do:[:aConnection |
270d76fc288f *** empty log message ***
penk
parents: 1146
diff changeset
  3935
	    aConnection canReadWithoutBlocking ifTrue:[
270d76fc288f *** empty log message ***
penk
parents: 1146
diff changeset
  3936
		^ aConnection
270d76fc288f *** empty log message ***
penk
parents: 1146
diff changeset
  3937
	    ]
270d76fc288f *** empty log message ***
penk
parents: 1146
diff changeset
  3938
	].
270d76fc288f *** empty log message ***
penk
parents: 1146
diff changeset
  3939
270d76fc288f *** empty log message ***
penk
parents: 1146
diff changeset
  3940
	"/ nope - must wait.
270d76fc288f *** empty log message ***
penk
parents: 1146
diff changeset
  3941
270d76fc288f *** empty log message ***
penk
parents: 1146
diff changeset
  3942
	sema := Semaphore new name:'multiReadWait'.
270d76fc288f *** empty log message ***
penk
parents: 1146
diff changeset
  3943
	otherConnections do:[:aConnection |
270d76fc288f *** empty log message ***
penk
parents: 1146
diff changeset
  3944
	    Processor signal:sema onInput:(aConnection fileDescriptor).
270d76fc288f *** empty log message ***
penk
parents: 1146
diff changeset
  3945
	].
270d76fc288f *** empty log message ***
penk
parents: 1146
diff changeset
  3946
	Processor signal:sema onInput:(self fileDescriptor).
270d76fc288f *** empty log message ***
penk
parents: 1146
diff changeset
  3947
	timeoutSeconds notNil ifTrue:[
270d76fc288f *** empty log message ***
penk
parents: 1146
diff changeset
  3948
	    Processor signal:sema afterSeconds:timeoutSeconds 
270d76fc288f *** empty log message ***
penk
parents: 1146
diff changeset
  3949
	].
270d76fc288f *** empty log message ***
penk
parents: 1146
diff changeset
  3950
	Processor activeProcess state:#ioWait.
270d76fc288f *** empty log message ***
penk
parents: 1146
diff changeset
  3951
	sema wait.
1136
cda53253bd0f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1120
diff changeset
  3952
    ] ensure:[
1170
270d76fc288f *** empty log message ***
penk
parents: 1146
diff changeset
  3953
	sema notNil ifTrue:[Processor disableSemaphore:sema].
270d76fc288f *** empty log message ***
penk
parents: 1146
diff changeset
  3954
	wasBlocked ifFalse:[OperatingSystem unblockInterrupts].
781
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  3955
    ].
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  3956
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  3957
    "/ see who it was ...
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  3958
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  3959
    self canReadWithoutBlocking ifTrue:[
1170
270d76fc288f *** empty log message ***
penk
parents: 1146
diff changeset
  3960
	^ self accept.
781
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  3961
    ].
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  3962
    otherConnections do:[:aConnection |
1170
270d76fc288f *** empty log message ***
penk
parents: 1146
diff changeset
  3963
	aConnection canReadWithoutBlocking ifTrue:[
270d76fc288f *** empty log message ***
penk
parents: 1146
diff changeset
  3964
	    ^ aConnection
270d76fc288f *** empty log message ***
penk
parents: 1146
diff changeset
  3965
	]
781
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  3966
    ].
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  3967
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  3968
    "/ none - a timeout
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  3969
    ^ nil
867
56ca0cc52fa7 category renamining
Claus Gittinger <cg@exept.de>
parents: 859
diff changeset
  3970
!
56ca0cc52fa7 category renamining
Claus Gittinger <cg@exept.de>
parents: 859
diff changeset
  3971
56ca0cc52fa7 category renamining
Claus Gittinger <cg@exept.de>
parents: 859
diff changeset
  3972
waitForNewConnectionWithTimeout:timeoutSeconds
56ca0cc52fa7 category renamining
Claus Gittinger <cg@exept.de>
parents: 859
diff changeset
  3973
    "suspend the current process, until a new connection comes
56ca0cc52fa7 category renamining
Claus Gittinger <cg@exept.de>
parents: 859
diff changeset
  3974
     in at the receiver or a timeout occurs.
56ca0cc52fa7 category renamining
Claus Gittinger <cg@exept.de>
parents: 859
diff changeset
  3975
     For a new connection, an accept is performed and the new socket is returned.
56ca0cc52fa7 category renamining
Claus Gittinger <cg@exept.de>
parents: 859
diff changeset
  3976
     Returns nil, if a timeout occured.
56ca0cc52fa7 category renamining
Claus Gittinger <cg@exept.de>
parents: 859
diff changeset
  3977
     This method implements the inner wait-primitive of a single-connection 
56ca0cc52fa7 category renamining
Claus Gittinger <cg@exept.de>
parents: 859
diff changeset
  3978
     server application."
56ca0cc52fa7 category renamining
Claus Gittinger <cg@exept.de>
parents: 859
diff changeset
  3979
56ca0cc52fa7 category renamining
Claus Gittinger <cg@exept.de>
parents: 859
diff changeset
  3980
    (self readWaitWithTimeout:timeoutSeconds) ifTrue:[
56ca0cc52fa7 category renamining
Claus Gittinger <cg@exept.de>
parents: 859
diff changeset
  3981
	"/ a timeout occurred - no connection within timeout
56ca0cc52fa7 category renamining
Claus Gittinger <cg@exept.de>
parents: 859
diff changeset
  3982
	^ nil
56ca0cc52fa7 category renamining
Claus Gittinger <cg@exept.de>
parents: 859
diff changeset
  3983
    ].
56ca0cc52fa7 category renamining
Claus Gittinger <cg@exept.de>
parents: 859
diff changeset
  3984
    ^ self accept.
781
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  3985
! !
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  3986
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  3987
!Socket methodsFor:'low level-connecting'!
99
7d016cc30052 fixed & moved pingWalk from SNMPSession to here;
Claus Gittinger <cg@exept.de>
parents: 98
diff changeset
  3988
116
7789fb1c9fa2 more UD socket fixes (at least client side seems to work now)
Claus Gittinger <cg@exept.de>
parents: 115
diff changeset
  3989
connectTo:hostOrPathName port:portNrOrName
71
claus
parents: 63
diff changeset
  3990
    "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
  3991
     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
  3992
     Other sockets are not yet implemented.
71
claus
parents: 63
diff changeset
  3993
     Return true if ok, false otherwise.
99
7d016cc30052 fixed & moved pingWalk from SNMPSession to here;
Claus Gittinger <cg@exept.de>
parents: 98
diff changeset
  3994
     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
  3995
     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
  3996
     is established. 
7789fb1c9fa2 more UD socket fixes (at least client side seems to work now)
Claus Gittinger <cg@exept.de>
parents: 115
diff changeset
  3997
     See also: #connectTo:port:withTimeout: for a somewhat nicer interface."
28
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  3998
896
2ca43149a20e Ask for possible error after async connect.
Stefan Vogel <sv@exept.de>
parents: 888
diff changeset
  3999
    ^ self connectTo:hostOrPathName port:portNrOrName withTimeout:nil
649
1bc56594db85 fixed connect for sun/irix
Claus Gittinger <cg@exept.de>
parents: 648
diff changeset
  4000
!
1bc56594db85 fixed connect for sun/irix
Claus Gittinger <cg@exept.de>
parents: 648
diff changeset
  4001
896
2ca43149a20e Ask for possible error after async connect.
Stefan Vogel <sv@exept.de>
parents: 888
diff changeset
  4002
connectTo:hostOrPathName port:portNrOrName withTimeout:timeout
649
1bc56594db85 fixed connect for sun/irix
Claus Gittinger <cg@exept.de>
parents: 648
diff changeset
  4003
    "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
  4004
     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
  4005
     Other sockets are not yet implemented.
1bc56594db85 fixed connect for sun/irix
Claus Gittinger <cg@exept.de>
parents: 648
diff changeset
  4006
     Return true if ok, false otherwise.
1bc56594db85 fixed connect for sun/irix
Claus Gittinger <cg@exept.de>
parents: 648
diff changeset
  4007
     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
  4008
     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
  4009
     is established. 
1bc56594db85 fixed connect for sun/irix
Claus Gittinger <cg@exept.de>
parents: 648
diff changeset
  4010
     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
  4011
896
2ca43149a20e Ask for possible error after async connect.
Stefan Vogel <sv@exept.de>
parents: 888
diff changeset
  4012
    |isAsync err|
430
12d736316f69 Fix #connectTo:port: Do not call connect() when we get EINPROGRESS
Stefan Vogel <sv@exept.de>
parents: 429
diff changeset
  4013
28
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  4014
    filePointer isNil ifTrue:[
1009
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  4015
	^ self errorNotOpen
28
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  4016
    ].
1120
b43bcd84bca8 gethostbyname beeds more than 64kb stack
martin
parents: 1119
diff changeset
  4017
%{  /* STACK: 100000 */
649
1bc56594db85 fixed connect for sun/irix
Claus Gittinger <cg@exept.de>
parents: 648
diff changeset
  4018
418
317e55c6c281 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 403
diff changeset
  4019
#ifndef NO_SOCKET
217
fcfbc9f71048 underscore cleanup
Claus Gittinger <cg@exept.de>
parents: 209
diff changeset
  4020
    OBJ t = __INST(filePointer);
71
claus
parents: 63
diff changeset
  4021
    OBJ myDomain;
819
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
  4022
    union sockaddr_u sa;
28
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  4023
    struct hostent *hp ;
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  4024
    int a, sock ;
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  4025
    long addr;
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  4026
    FILE *fp;
649
1bc56594db85 fixed connect for sun/irix
Claus Gittinger <cg@exept.de>
parents: 648
diff changeset
  4027
    int ret, oldFlags;
28
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  4028
    int on = 1;
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  4029
    int ok;
115
a9d85df931c4 added Unix domain support
Claus Gittinger <cg@exept.de>
parents: 112
diff changeset
  4030
    int sockaddr_size;
28
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  4031
217
fcfbc9f71048 underscore cleanup
Claus Gittinger <cg@exept.de>
parents: 209
diff changeset
  4032
    if (!__isString(__INST(domain)) && !__isSymbol(__INST(domain))) {
1009
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  4033
	DBGPRINTF(("SOCKET: invalid domain arg\n"));
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  4034
	RETURN (false);
28
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  4035
    }
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  4036
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  4037
    ok = 0;
217
fcfbc9f71048 underscore cleanup
Claus Gittinger <cg@exept.de>
parents: 209
diff changeset
  4038
    myDomain = __INST(domain);
115
a9d85df931c4 added Unix domain support
Claus Gittinger <cg@exept.de>
parents: 112
diff changeset
  4039
    bzero((char *) &sa, sizeof(sa)) ;
508
55d1e49c7157 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 507
diff changeset
  4040
1009
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  4041
    if (0) {
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  4042
	/* for ese below */
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  4043
    }
28
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  4044
#ifdef AF_INET
1009
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  4045
    else if (myDomain == @symbol(inet)) {
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  4046
	/*
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  4047
	 * INET addressing: port must be a smallInteger;
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  4048
	 * hostOrPathName the name of the host (dot notation allowed)
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  4049
	 * or a byteArray containing the 4 address bytes.
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  4050
	 */
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  4051
	if (! __isSmallInteger(portNrOrName)) {
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  4052
	    DBGPRINTF(("SOCKET: invalid port arg\n"));
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  4053
	    RETURN (false);
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  4054
	}
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  4055
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  4056
	sa.in.sin_family = AF_INET;
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  4057
	sa.in.sin_port = htons((u_short) __intVal(portNrOrName)) ;
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  4058
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  4059
	if (__isByteArray(hostOrPathName)) {
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  4060
	    unsigned char *cp;
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  4061
	    int n;
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  4062
	    unsigned intAddr;
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  4063
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  4064
	    cp = __ByteArrayInstPtr(hostOrPathName)->ba_element;
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  4065
	    n = __byteArraySize(hostOrPathName);
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  4066
	    if (n < 4) {
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  4067
		DBGPRINTF(("SOCKET: invalid ipAddr arg\n"));
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  4068
		RETURN (false);
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  4069
	    }
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  4070
	    intAddr = cp[0];
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  4071
	    intAddr = (intAddr << 8) | cp[1];
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  4072
	    intAddr = (intAddr << 8) | cp[2];
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  4073
	    intAddr = (intAddr << 8) | cp[3];
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  4074
	    sa.in.sin_addr.s_addr = htonl(intAddr);
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  4075
	    /* bcopy(cp, &sa.in.sin_addr.s_addr, n); */
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  4076
	} else {
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  4077
	    if (! __isString(hostOrPathName)) {
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  4078
		DBGPRINTF(("SOCKET: invalid hostname arg\n"));
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  4079
		RETURN (false);
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  4080
	    }
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  4081
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  4082
	    if ((addr = inet_addr(__stringVal(hostOrPathName))) != -1) {
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  4083
		/* 
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  4084
		 * is Internet addr in octet notation 
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  4085
		 */
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  4086
		bcopy(&addr, (char *) &sa.in.sin_addr, sizeof(addr)) ; /* set address */
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  4087
	    } else {
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  4088
		/* 
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  4089
		 * do we know the host's address? 
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  4090
		 */
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  4091
		GETHOSTBYNAME(hp, __stringVal(hostOrPathName))
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  4092
		if (hp == NULL) {
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  4093
		    DBGPRINTF(("SOCKET: unknown host:%s\n", __stringVal(hostOrPathName)));
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  4094
		    RETURN (false);
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  4095
		}
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  4096
		bcopy(hp->h_addr, (char *) &sa.in.sin_addr, hp->h_length) ;
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  4097
		sa.in.sin_family = hp->h_addrtype;
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  4098
	    }
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  4099
	}
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  4100
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  4101
	DBGPRINTF(("SOCKET: connect addr:%d.%d.%d.%d port: %d\n", 
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  4102
			((unsigned char *)(&sa.in.sin_addr.s_addr))[0], 
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  4103
			((unsigned char *)(&sa.in.sin_addr.s_addr))[1], 
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  4104
			((unsigned char *)(&sa.in.sin_addr.s_addr))[2], 
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  4105
			((unsigned char *)(&sa.in.sin_addr.s_addr))[3], 
962
ab54bea0b102 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 961
diff changeset
  4106
			ntohs(sa.in.sin_port)));
896
2ca43149a20e Ask for possible error after async connect.
Stefan Vogel <sv@exept.de>
parents: 888
diff changeset
  4107
1009
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  4108
	sockaddr_size = sizeof(struct sockaddr_in);
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  4109
	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
  4110
    }
525
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  4111
#endif /* AF_INET */
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  4112
530
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  4113
#ifdef AF_INET6
1009
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  4114
    else if (myDomain == @symbol(inet6)) {
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  4115
	/*
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  4116
	 * INET6 addressing: port must be a smallInteger;
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  4117
	 * hostOrPathName the name of the host
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  4118
	 * or a byteArray containing the address bytes.
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  4119
	 */
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  4120
	if (! __isSmallInteger(portNrOrName)) {
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  4121
	    DBGPRINTF(("SOCKET: invalid port arg\n"));
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  4122
	    RETURN (false);
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  4123
	}
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  4124
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  4125
	sa.in6.sin6_family = AF_INET6;
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  4126
	sa.in6.sin6_port = htons((u_short) __intVal(portNrOrName)) ;
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  4127
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  4128
	if (__isByteArray(hostOrPathName)) {
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  4129
	    unsigned char *cp;
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  4130
	    int n;
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  4131
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  4132
	    cp = __ByteArrayInstPtr(hostOrPathName)->ba_element;
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  4133
	    n = __byteArraySize(hostOrPathName);
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  4134
	    if (n > sizeof(sa.in6.sin6_addr.s6_addr)) n = sizeof(sa.in6.sin6_addr.s6_addr);
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  4135
	    bcopy(cp, sa.in6.sin6_addr.s6_addr, n);
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  4136
	} else {
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  4137
	    if (! __isString(hostOrPathName)) {
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  4138
		DBGPRINTF(("SOCKET: invalid hostname arg\n"));
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  4139
		RETURN (false);
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  4140
	    }
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  4141
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  4142
	    /* 
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  4143
	     * do we know the host's address? 
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  4144
	     */
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  4145
	    GETHOSTBYNAME(hp, __stringVal(hostOrPathName))
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  4146
	    if (hp == NULL) {
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  4147
		DBGPRINTF(("SOCKET: unknown host:%s\n", __stringVal(hostOrPathName)));
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  4148
		RETURN (false);
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  4149
	    }
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  4150
	    bcopy(hp->h_addr, (char *) &sa.in.sin_addr, hp->h_length) ;
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  4151
	    sa.in.sin_family = hp->h_addrtype;
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  4152
	}
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  4153
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  4154
	DBGPRINTF(("SOCKET: connect addr: %x.%x.%x.%x.%x.%x... port: %d\n", 
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  4155
		sa.in6.sin6_addr.s6_addr[0],
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  4156
		sa.in6.sin6_addr.s6_addr[1],
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  4157
		sa.in6.sin6_addr.s6_addr[2],
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  4158
		sa.in6.sin6_addr.s6_addr[3],
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  4159
		sa.in6.sin6_addr.s6_addr[4],
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  4160
		sa.in6.sin6_addr.s6_addr[5],
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  4161
		sa.in6.sin6_port));
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  4162
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  4163
	sockaddr_size = sizeof(struct sockaddr_in6);
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  4164
	ok = 1;
530
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  4165
    }
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  4166
#endif /* AF_INET6 */
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  4167
116
7789fb1c9fa2 more UD socket fixes (at least client side seems to work now)
Claus Gittinger <cg@exept.de>
parents: 115
diff changeset
  4168
#ifdef AF_UNIX
1009
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  4169
    else if (myDomain == @symbol(unix)) {
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  4170
	char *pathName;
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  4171
	int l;
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  4172
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  4173
	/*
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  4174
	 * UNIX domain: port is ignored;
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  4175
	 * hostOrPathName is a pathName
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  4176
	 */
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  4177
	if (! __isString(hostOrPathName)) {
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  4178
	    DBGPRINTF(("SOCKET: invalid port (pathname) arg\n"));
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  4179
	    RETURN (false);
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  4180
	}
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  4181
	pathName = (char *) __stringVal(hostOrPathName);
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  4182
	l = strlen(pathName);
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  4183
	if ((l + sizeof ( sa.un.sun_family )) > sizeof(struct sockaddr_un)) {
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  4184
	    DBGPRINTF(("SOCKET: pathname too long\n"));
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  4185
	    RETURN (false);
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  4186
	}
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  4187
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  4188
	strcpy(sa.un.sun_path, pathName);
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  4189
	sa.un.sun_family = AF_UNIX;
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  4190
	sockaddr_size = l + sizeof ( sa.un.sun_family );
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  4191
	ok = 1;
28
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  4192
    }
525
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  4193
#endif /* AF_UNIX */
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  4194
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  4195
#ifdef AF_APPLETALK
1009
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  4196
    else if (myDomain == @symbol(appletalk)) {
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  4197
	/*
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  4198
	 * APPLETALK addressing: port must be a smallInteger;
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  4199
	 * hostOrPathName the name of the host
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  4200
	 * or a byteArray containing the 3 address bytes.
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  4201
	 */
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  4202
	if (! __isSmallInteger(portNrOrName)) {
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  4203
	    DBGPRINTF(("SOCKET: invalid port arg\n"));
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  4204
	    RETURN (false);
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  4205
	}
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  4206
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  4207
	sa.at.sat_family = AF_APPLETALK;
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  4208
	sa.at.sat_port = __intVal(portNrOrName);
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  4209
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  4210
	if (__isByteArray(hostOrPathName)) {
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  4211
	    unsigned char *cp;
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  4212
	    int n;
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  4213
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  4214
	    cp = __ByteArrayInstPtr(hostOrPathName)->ba_element;
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  4215
	    n = __byteArraySize(hostOrPathName);
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  4216
	    if (n > 3) n = 3;
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  4217
	    bcopy(cp, &sa.at.sat_addr, n);
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  4218
	} else {
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  4219
	    if (! __isString(hostOrPathName)) {
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  4220
		DBGPRINTF(("SOCKET: invalid hostname arg\n"));
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  4221
		RETURN (false);
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  4222
	    }
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  4223
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  4224
	    /* 
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  4225
	     * do we know the host's address? 
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  4226
	     */
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  4227
	    GETHOSTBYNAME(hp, __stringVal(hostOrPathName))
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  4228
	    if (hp == NULL) {
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  4229
		DBGPRINTF(("SOCKET: unknown host:%s\n", __stringVal(hostOrPathName)));
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  4230
		RETURN (false);
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  4231
	    }
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  4232
	    if (hp->h_addrtype != AF_APPLETALK) {
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  4233
		DBGPRINTF(("SOCKET: host:%s is not an appletalk host\n", __stringVal(hostOrPathName)));
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  4234
		RETURN (false);
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  4235
	    }
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  4236
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  4237
	    bcopy(hp->h_addr, (char *) &sa.at.sat_addr, hp->h_length) ;
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  4238
	    sa.at.sat_family = hp->h_addrtype;
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  4239
	}
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  4240
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  4241
	DBGPRINTF(("SOCKET: connect addr: %x port: %d\n", sa.in.sin_addr, sa.in.sin_port));
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  4242
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  4243
	sockaddr_size = sizeof(struct sockaddr_at);
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  4244
	ok = 1;
525
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  4245
    }
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  4246
#endif /* APPLETALK */
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  4247
28
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  4248
    /*
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  4249
     * XXXX add addressing stuff for other domains here ...
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  4250
     */
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  4251
#ifdef AF_X25
1009
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  4252
    else if (myDomain == @symbol(x25)) {
28
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  4253
    }
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  4254
#endif
819
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
  4255
#ifdef AF_AX25
1009
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  4256
    else if (myDomain == @symbol(ax25)) {
819
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
  4257
    }
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
  4258
#endif
28
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  4259
#ifdef AF_NS
1009
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  4260
    else if ((myDomain == @symbol(ns)) 
812
c8101ea70e6c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 811
diff changeset
  4261
     || (myDomain == @symbol(xns))) {
28
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  4262
    }
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  4263
#endif
524
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  4264
# ifdef AF_DECnet
1009
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  4265
    else if (myDomain == @symbol(decnet)) {
524
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  4266
    }
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  4267
# endif
93
Claus Gittinger <cg@exept.de>
parents: 92
diff changeset
  4268
#ifdef AF_SNA
1009
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  4269
    else if (myDomain == @symbol(sna)) {
93
Claus Gittinger <cg@exept.de>
parents: 92
diff changeset
  4270
    }
Claus Gittinger <cg@exept.de>
parents: 92
diff changeset
  4271
#endif
Claus Gittinger <cg@exept.de>
parents: 92
diff changeset
  4272
#ifdef AF_RAW 
1009
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  4273
    else if (myDomain == @symbol(raw)) {
93
Claus Gittinger <cg@exept.de>
parents: 92
diff changeset
  4274
    }
Claus Gittinger <cg@exept.de>
parents: 92
diff changeset
  4275
#endif
524
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  4276
# ifdef AF_ISO
1009
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  4277
    else if (myDomain == @symbol(iso)) {
524
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  4278
    }
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  4279
# endif
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  4280
# ifdef AF_NETBIOS
1009
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  4281
    else if (myDomain == @symbol(netbios)) {
530
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  4282
    }
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  4283
# endif
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  4284
# ifdef AF_IPX
1009
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  4285
    else if (myDomain == @symbol(ipx)) {
530
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  4286
    }
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  4287
# endif
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  4288
# ifdef AF_BRIDGE
1009
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  4289
    else if (myDomain == @symbol(bridge)) {
524
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  4290
    }
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  4291
# endif
571
191b37534643 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 563
diff changeset
  4292
# ifdef AF_BSC
1009
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  4293
    else if (myDomain == @symbol(bsc)) {
571
191b37534643 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 563
diff changeset
  4294
    }
191b37534643 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 563
diff changeset
  4295
# endif
812
c8101ea70e6c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 811
diff changeset
  4296
# ifdef AF_ROSE
1009
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  4297
    else if (myDomain == @symbol(rose)) {
812
c8101ea70e6c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 811
diff changeset
  4298
    }
c8101ea70e6c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 811
diff changeset
  4299
# endif
869
a6e5cbe9f558 preps for AF_IRDA
Claus Gittinger <cg@exept.de>
parents: 867
diff changeset
  4300
# ifdef AF_IRDA
1009
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  4301
    else if (__INST(domain) == @symbol(irda)) {
869
a6e5cbe9f558 preps for AF_IRDA
Claus Gittinger <cg@exept.de>
parents: 867
diff changeset
  4302
    }
a6e5cbe9f558 preps for AF_IRDA
Claus Gittinger <cg@exept.de>
parents: 867
diff changeset
  4303
# endif
524
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  4304
# if defined(AF_CCITT) && (AF_CCITT != AF_X25)
1009
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  4305
    else if (myDomain == @symbol(ccitt)) {
524
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  4306
    }
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  4307
# endif
28
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  4308
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  4309
    if (! ok) {
1009
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  4310
	DBGPRINTF(("SOCKET: unsupported domain\n"));
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  4311
	RETURN (false);
28
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  4312
    }
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  4313
110
7af19ae8693b use new FILE* wrapper macros (based on externalAddress)
Claus Gittinger <cg@exept.de>
parents: 106
diff changeset
  4314
    sock = fileno(__FILEVal(t));
28
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  4315
649
1bc56594db85 fixed connect for sun/irix
Claus Gittinger <cg@exept.de>
parents: 648
diff changeset
  4316
#if defined(O_NONBLOCK)
896
2ca43149a20e Ask for possible error after async connect.
Stefan Vogel <sv@exept.de>
parents: 888
diff changeset
  4317
    /*
2ca43149a20e Ask for possible error after async connect.
Stefan Vogel <sv@exept.de>
parents: 888
diff changeset
  4318
     * set to non-blocking and wait later
2ca43149a20e Ask for possible error after async connect.
Stefan Vogel <sv@exept.de>
parents: 888
diff changeset
  4319
     */
2ca43149a20e Ask for possible error after async connect.
Stefan Vogel <sv@exept.de>
parents: 888
diff changeset
  4320
    oldFlags = fcntl(sock, F_GETFL, 0);
2ca43149a20e Ask for possible error after async connect.
Stefan Vogel <sv@exept.de>
parents: 888
diff changeset
  4321
    /* on SUNOS4.x, would use fcntl(osfd, F_SETFL, flags | FNDELAY); */
2ca43149a20e Ask for possible error after async connect.
Stefan Vogel <sv@exept.de>
parents: 888
diff changeset
  4322
    fcntl(sock, F_SETFL, oldFlags | O_NONBLOCK);
649
1bc56594db85 fixed connect for sun/irix
Claus Gittinger <cg@exept.de>
parents: 648
diff changeset
  4323
#endif
1bc56594db85 fixed connect for sun/irix
Claus Gittinger <cg@exept.de>
parents: 648
diff changeset
  4324
28
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  4325
    /* 
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  4326
     * connect 
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  4327
     */
81
claus
parents: 79
diff changeset
  4328
    __BEGIN_INTERRUPTABLE__
28
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  4329
    do {
1009
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  4330
	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
  4331
    } while ((ret < 0) 
1009
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  4332
	     && ((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
  4333
#ifdef EAGAIN
1009
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  4334
		 || (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
  4335
#endif
1009
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  4336
		));
81
claus
parents: 79
diff changeset
  4337
    __END_INTERRUPTABLE__
28
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  4338
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  4339
    if (ret < 0) { 
649
1bc56594db85 fixed connect for sun/irix
Claus Gittinger <cg@exept.de>
parents: 648
diff changeset
  4340
#if defined(EINPROGRESS) || defined(EALREADY)
1009
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  4341
	if (0
649
1bc56594db85 fixed connect for sun/irix
Claus Gittinger <cg@exept.de>
parents: 648
diff changeset
  4342
# ifdef EINPROGRESS
1009
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  4343
	    || (errno == EINPROGRESS) 
649
1bc56594db85 fixed connect for sun/irix
Claus Gittinger <cg@exept.de>
parents: 648
diff changeset
  4344
# endif
1bc56594db85 fixed connect for sun/irix
Claus Gittinger <cg@exept.de>
parents: 648
diff changeset
  4345
# ifdef EALREADY
1009
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  4346
	    || (errno == EALREADY)
649
1bc56594db85 fixed connect for sun/irix
Claus Gittinger <cg@exept.de>
parents: 648
diff changeset
  4347
# endif
1009
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  4348
	) {
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  4349
	    /*
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  4350
	     * This was a nonblocking operation that will take some time.
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  4351
	     * Do a select on read to get informed when the operation is ready.
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  4352
	     */
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  4353
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  4354
	    isAsync = true;
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  4355
	} else
649
1bc56594db85 fixed connect for sun/irix
Claus Gittinger <cg@exept.de>
parents: 648
diff changeset
  4356
#endif /* EINPROGRESS or EALREADY */
1009
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  4357
	{
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  4358
	    DBGPRINTF(("SOCKET: connect failed errno=%d\n", errno));
117
03cefad7e40b UD socket example & interruptable bind
Claus Gittinger <cg@exept.de>
parents: 116
diff changeset
  4359
#ifdef DUMP_ADDRESS
1009
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  4360
	    {
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  4361
		char *cp = (char *)(&sa);
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  4362
		int i;
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  4363
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  4364
		printf("address data:\n");
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  4365
		for (i=0; i<sockaddr_size; i++) {
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  4366
		    printf(" %02x\n", *cp++);
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  4367
		}
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  4368
	    }
117
03cefad7e40b UD socket example & interruptable bind
Claus Gittinger <cg@exept.de>
parents: 116
diff changeset
  4369
#endif
1009
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  4370
	    __INST(lastErrorNumber) = __MKSMALLINT(errno);
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  4371
	    RETURN (false);
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  4372
	}
28
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  4373
    }
649
1bc56594db85 fixed connect for sun/irix
Claus Gittinger <cg@exept.de>
parents: 648
diff changeset
  4374
1bc56594db85 fixed connect for sun/irix
Claus Gittinger <cg@exept.de>
parents: 648
diff changeset
  4375
#if defined(O_NONBLOCK)
896
2ca43149a20e Ask for possible error after async connect.
Stefan Vogel <sv@exept.de>
parents: 888
diff changeset
  4376
    fcntl(sock, F_SETFL, oldFlags);
649
1bc56594db85 fixed connect for sun/irix
Claus Gittinger <cg@exept.de>
parents: 648
diff changeset
  4377
#endif
1bc56594db85 fixed connect for sun/irix
Claus Gittinger <cg@exept.de>
parents: 648
diff changeset
  4378
430
12d736316f69 Fix #connectTo:port: Do not call connect() when we get EINPROGRESS
Stefan Vogel <sv@exept.de>
parents: 429
diff changeset
  4379
#else /* NO_SOCKET */
418
317e55c6c281 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 403
diff changeset
  4380
    RETURN (false);
430
12d736316f69 Fix #connectTo:port: Do not call connect() when we get EINPROGRESS
Stefan Vogel <sv@exept.de>
parents: 429
diff changeset
  4381
#endif /* NO_SOCKET */
42
506596f9a1a8 *** empty log message ***
claus
parents: 38
diff changeset
  4382
%}.
430
12d736316f69 Fix #connectTo:port: Do not call connect() when we get EINPROGRESS
Stefan Vogel <sv@exept.de>
parents: 429
diff changeset
  4383
    isAsync == true ifTrue:[
1009
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  4384
	(self writeWaitWithTimeoutMs:timeout) ifTrue:[
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  4385
	    "/ a timeout occured
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  4386
	    "/ should cancel the connect?
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  4387
	    ^ false.
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  4388
	].
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  4389
	err := self getSocketError.
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  4390
	err ~~ 0 ifTrue:[
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  4391
	    lastErrorNumber := err.
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  4392
	    ^ false.
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  4393
	].
430
12d736316f69 Fix #connectTo:port: Do not call connect() when we get EINPROGRESS
Stefan Vogel <sv@exept.de>
parents: 429
diff changeset
  4394
    ].
71
claus
parents: 63
diff changeset
  4395
    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
  4396
    peerName := hostOrPathName.
28
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  4397
    ^ true
896
2ca43149a20e Ask for possible error after async connect.
Stefan Vogel <sv@exept.de>
parents: 888
diff changeset
  4398
2ca43149a20e Ask for possible error after async connect.
Stefan Vogel <sv@exept.de>
parents: 888
diff changeset
  4399
    "
2ca43149a20e Ask for possible error after async connect.
Stefan Vogel <sv@exept.de>
parents: 888
diff changeset
  4400
       |sock|
2ca43149a20e Ask for possible error after async connect.
Stefan Vogel <sv@exept.de>
parents: 888
diff changeset
  4401
       sock := Socket newTCP.
2ca43149a20e Ask for possible error after async connect.
Stefan Vogel <sv@exept.de>
parents: 888
diff changeset
  4402
       sock connectTo:'localhost' port:21 withTimeout:1000.
2ca43149a20e Ask for possible error after async connect.
Stefan Vogel <sv@exept.de>
parents: 888
diff changeset
  4403
       sock
2ca43149a20e Ask for possible error after async connect.
Stefan Vogel <sv@exept.de>
parents: 888
diff changeset
  4404
2ca43149a20e Ask for possible error after async connect.
Stefan Vogel <sv@exept.de>
parents: 888
diff changeset
  4405
       |sock|
2ca43149a20e Ask for possible error after async connect.
Stefan Vogel <sv@exept.de>
parents: 888
diff changeset
  4406
       sock := Socket newTCP.
2ca43149a20e Ask for possible error after async connect.
Stefan Vogel <sv@exept.de>
parents: 888
diff changeset
  4407
       sock connectTo:'localhost' port:9876 withTimeout:2000.
2ca43149a20e Ask for possible error after async connect.
Stefan Vogel <sv@exept.de>
parents: 888
diff changeset
  4408
       sock
2ca43149a20e Ask for possible error after async connect.
Stefan Vogel <sv@exept.de>
parents: 888
diff changeset
  4409
    "
25
996051271ce9 *** empty log message ***
claus
parents: 21
diff changeset
  4410
! !
996051271ce9 *** empty log message ***
claus
parents: 21
diff changeset
  4411
996051271ce9 *** empty log message ***
claus
parents: 21
diff changeset
  4412
!Socket methodsFor:'queries'!
996051271ce9 *** empty log message ***
claus
parents: 21
diff changeset
  4413
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4414
domain
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4415
    "return the sockets addressing domain (i.e. #inet, #unix, #x25, #appletalk)"
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4416
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4417
    ^ domain
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4418
!
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4419
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4420
getName
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4421
    "return the name; here, we return the ports name"
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4422
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4423
    ^ port printString
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4424
!
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4425
102
5dc264007513 added getPeer for ST-80 compatibility
Claus Gittinger <cg@exept.de>
parents: 99
diff changeset
  4426
getPeer
5dc264007513 added getPeer for ST-80 compatibility
Claus Gittinger <cg@exept.de>
parents: 99
diff changeset
  4427
    "ST-80 compatibility: return an IPSocketAddress instance representing
5dc264007513 added getPeer for ST-80 compatibility
Claus Gittinger <cg@exept.de>
parents: 99
diff changeset
  4428
     my hostname/port combination.
155
fcf846c707b7 interest is written with one 'r' (shame on me)
Claus Gittinger <cg@exept.de>
parents: 126
diff changeset
  4429
     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
  4430
116
7789fb1c9fa2 more UD socket fixes (at least client side seems to work now)
Claus Gittinger <cg@exept.de>
parents: 115
diff changeset
  4431
    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
  4432
	^ 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
  4433
    ].
819
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
  4434
    domain == #inet ifTrue:[
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
  4435
	^ IPSocketAddress hostAddress:(self class ipAddressOfHost:peerName) port:port
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
  4436
    ].
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
  4437
    domain == #inet6 ifTrue:[
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
  4438
	^ IPv6SocketAddress hostAddress:(self class ipV6AddressOfHost:peerName) port:port
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
  4439
    ].
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
  4440
    domain == #appletalk ifTrue:[
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
  4441
	^ AppletalkSocketAddress hostAddress:(self class appletalkAddressOfHost:peerName) port:port
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
  4442
    ].
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
  4443
    domain == #decnet ifTrue:[
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
  4444
	^ DecNetSocketAddress hostAddress:(self class decnetAddressOfHost:peerName) port:port
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
  4445
    ].
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
  4446
    self error:'unsupported domain'.
102
5dc264007513 added getPeer for ST-80 compatibility
Claus Gittinger <cg@exept.de>
parents: 99
diff changeset
  4447
5dc264007513 added getPeer for ST-80 compatibility
Claus Gittinger <cg@exept.de>
parents: 99
diff changeset
  4448
    "Created: 2.11.1995 / 11:22:39 / cg"
5dc264007513 added getPeer for ST-80 compatibility
Claus Gittinger <cg@exept.de>
parents: 99
diff changeset
  4449
!
5dc264007513 added getPeer for ST-80 compatibility
Claus Gittinger <cg@exept.de>
parents: 99
diff changeset
  4450
25
996051271ce9 *** empty log message ***
claus
parents: 21
diff changeset
  4451
getPeerName
996051271ce9 *** empty log message ***
claus
parents: 21
diff changeset
  4452
    "return the peer name; thats the hostname (or dotted name) of the
996051271ce9 *** empty log message ***
claus
parents: 21
diff changeset
  4453
     partners host after an accept."
996051271ce9 *** empty log message ***
claus
parents: 21
diff changeset
  4454
996051271ce9 *** empty log message ***
claus
parents: 21
diff changeset
  4455
    ^ peerName
28
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  4456
!
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  4457
1146
71a9df78ba9e bad spelling
Stefan Vogel <sv@exept.de>
parents: 1136
diff changeset
  4458
getSocketAddress
71a9df78ba9e bad spelling
Stefan Vogel <sv@exept.de>
parents: 1136
diff changeset
  4459
    "implemented for swazoo project primitive code cant load as extension
1170
270d76fc288f *** empty log message ***
penk
parents: 1146
diff changeset
  4460
     answer my own address (I am bound to this address).
1146
71a9df78ba9e bad spelling
Stefan Vogel <sv@exept.de>
parents: 1136
diff changeset
  4461
     Note that this address may change after connect or accept."
1029
5906977e62f0 implement getSocketName for swazoo as primitive cant load as extension
penk
parents: 1010
diff changeset
  4462
5906977e62f0 implement getSocketName for swazoo as primitive cant load as extension
penk
parents: 1010
diff changeset
  4463
    |socketAddress error|
5906977e62f0 implement getSocketName for swazoo as primitive cant load as extension
penk
parents: 1010
diff changeset
  4464
5906977e62f0 implement getSocketName for swazoo as primitive cant load as extension
penk
parents: 1010
diff changeset
  4465
    filePointer isNil ifTrue:[
1170
270d76fc288f *** empty log message ***
penk
parents: 1146
diff changeset
  4466
	^ self errorNotOpen
1029
5906977e62f0 implement getSocketName for swazoo as primitive cant load as extension
penk
parents: 1010
diff changeset
  4467
    ].
5906977e62f0 implement getSocketName for swazoo as primitive cant load as extension
penk
parents: 1010
diff changeset
  4468
    socketAddress := ByteArray new:16.
5906977e62f0 implement getSocketName for swazoo as primitive cant load as extension
penk
parents: 1010
diff changeset
  4469
5906977e62f0 implement getSocketName for swazoo as primitive cant load as extension
penk
parents: 1010
diff changeset
  4470
%{
5906977e62f0 implement getSocketName for swazoo as primitive cant load as extension
penk
parents: 1010
diff changeset
  4471
#ifndef NO_SOCKET
5906977e62f0 implement getSocketName for swazoo as primitive cant load as extension
penk
parents: 1010
diff changeset
  4472
    OBJ t = __INST(filePointer);
5906977e62f0 implement getSocketName for swazoo as primitive cant load as extension
penk
parents: 1010
diff changeset
  4473
    int sock;
5906977e62f0 implement getSocketName for swazoo as primitive cant load as extension
penk
parents: 1010
diff changeset
  4474
    int sockaddr_size;
5906977e62f0 implement getSocketName for swazoo as primitive cant load as extension
penk
parents: 1010
diff changeset
  4475
    int ret;
5906977e62f0 implement getSocketName for swazoo as primitive cant load as extension
penk
parents: 1010
diff changeset
  4476
5906977e62f0 implement getSocketName for swazoo as primitive cant load as extension
penk
parents: 1010
diff changeset
  4477
    if (!__isNonNilObject(socketAddress) ||
1170
270d76fc288f *** empty log message ***
penk
parents: 1146
diff changeset
  4478
	(__intVal(__ClassInstPtr(__qClass(socketAddress))->c_flags) & ARRAYMASK) != BYTEARRAY) {
270d76fc288f *** empty log message ***
penk
parents: 1146
diff changeset
  4479
	error = @symbol(badArgument1);
270d76fc288f *** empty log message ***
penk
parents: 1146
diff changeset
  4480
	goto err;
1029
5906977e62f0 implement getSocketName for swazoo as primitive cant load as extension
penk
parents: 1010
diff changeset
  4481
    }
5906977e62f0 implement getSocketName for swazoo as primitive cant load as extension
penk
parents: 1010
diff changeset
  4482
    sockaddr_size = __byteArraySize(socketAddress);
5906977e62f0 implement getSocketName for swazoo as primitive cant load as extension
penk
parents: 1010
diff changeset
  4483
5906977e62f0 implement getSocketName for swazoo as primitive cant load as extension
penk
parents: 1010
diff changeset
  4484
    sock = fileno(__FILEVal(t));
5906977e62f0 implement getSocketName for swazoo as primitive cant load as extension
penk
parents: 1010
diff changeset
  4485
    ret = getsockname(sock, (struct sockaddr *)__byteArrayVal(socketAddress), &sockaddr_size);
5906977e62f0 implement getSocketName for swazoo as primitive cant load as extension
penk
parents: 1010
diff changeset
  4486
    if (ret < 0) {
1170
270d76fc288f *** empty log message ***
penk
parents: 1146
diff changeset
  4487
	DBGPRINTF(("SOCKET: getsocketname failed errno=%d\n", errno));
270d76fc288f *** empty log message ***
penk
parents: 1146
diff changeset
  4488
	error = __MKSMALLINT(errno);
1029
5906977e62f0 implement getSocketName for swazoo as primitive cant load as extension
penk
parents: 1010
diff changeset
  4489
    }
5906977e62f0 implement getSocketName for swazoo as primitive cant load as extension
penk
parents: 1010
diff changeset
  4490
err:;
5906977e62f0 implement getSocketName for swazoo as primitive cant load as extension
penk
parents: 1010
diff changeset
  4491
#else /* NO_SOCKET */
5906977e62f0 implement getSocketName for swazoo as primitive cant load as extension
penk
parents: 1010
diff changeset
  4492
    error = @symbol(notImplemented);
5906977e62f0 implement getSocketName for swazoo as primitive cant load as extension
penk
parents: 1010
diff changeset
  4493
#endif /* NO_SOCKET */
5906977e62f0 implement getSocketName for swazoo as primitive cant load as extension
penk
parents: 1010
diff changeset
  4494
%}.
5906977e62f0 implement getSocketName for swazoo as primitive cant load as extension
penk
parents: 1010
diff changeset
  4495
    error notNil ifTrue:[
1170
270d76fc288f *** empty log message ***
penk
parents: 1146
diff changeset
  4496
	^ self errorReporter reportOn:error
1029
5906977e62f0 implement getSocketName for swazoo as primitive cant load as extension
penk
parents: 1010
diff changeset
  4497
    ].
5906977e62f0 implement getSocketName for swazoo as primitive cant load as extension
penk
parents: 1010
diff changeset
  4498
    ^ socketAddress copyFrom:5 to:8
5906977e62f0 implement getSocketName for swazoo as primitive cant load as extension
penk
parents: 1010
diff changeset
  4499
!
5906977e62f0 implement getSocketName for swazoo as primitive cant load as extension
penk
parents: 1010
diff changeset
  4500
1146
71a9df78ba9e bad spelling
Stefan Vogel <sv@exept.de>
parents: 1136
diff changeset
  4501
getSocketAdress
71a9df78ba9e bad spelling
Stefan Vogel <sv@exept.de>
parents: 1136
diff changeset
  4502
    "implemented for swazoo project primitive code cant load as extension
71a9df78ba9e bad spelling
Stefan Vogel <sv@exept.de>
parents: 1136
diff changeset
  4503
     answer the my own address (I am bound to this address).
71a9df78ba9e bad spelling
Stefan Vogel <sv@exept.de>
parents: 1136
diff changeset
  4504
     Note that this address may change after connect or accept.
71a9df78ba9e bad spelling
Stefan Vogel <sv@exept.de>
parents: 1136
diff changeset
  4505
71a9df78ba9e bad spelling
Stefan Vogel <sv@exept.de>
parents: 1136
diff changeset
  4506
     BAD SPELLING, kept for compatibility with swazoo"
71a9df78ba9e bad spelling
Stefan Vogel <sv@exept.de>
parents: 1136
diff changeset
  4507
71a9df78ba9e bad spelling
Stefan Vogel <sv@exept.de>
parents: 1136
diff changeset
  4508
71a9df78ba9e bad spelling
Stefan Vogel <sv@exept.de>
parents: 1136
diff changeset
  4509
    ^ self getSocketAddress
71a9df78ba9e bad spelling
Stefan Vogel <sv@exept.de>
parents: 1136
diff changeset
  4510
!
71a9df78ba9e bad spelling
Stefan Vogel <sv@exept.de>
parents: 1136
diff changeset
  4511
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4512
isActive
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4513
    "return true, if the receiver has a connection"
81
claus
parents: 79
diff changeset
  4514
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4515
    ^ filePointer notNil
81
claus
parents: 79
diff changeset
  4516
!
claus
parents: 79
diff changeset
  4517
1110
0876a3d30fd2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1035
diff changeset
  4518
isConnected
0876a3d30fd2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1035
diff changeset
  4519
    "return true, if the receiver has a connection"
0876a3d30fd2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1035
diff changeset
  4520
0876a3d30fd2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1035
diff changeset
  4521
    ^ self isActive
0876a3d30fd2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1035
diff changeset
  4522
      and:[port notNil
0876a3d30fd2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1035
diff changeset
  4523
      and:[peerName notNil]]
0876a3d30fd2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1035
diff changeset
  4524
!
0876a3d30fd2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1035
diff changeset
  4525
71
claus
parents: 63
diff changeset
  4526
port
claus
parents: 63
diff changeset
  4527
    "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
  4528
506
11ef93d12870 support anonymous (OS_specified) ports. (for FTP-protocol)
Claus Gittinger <cg@exept.de>
parents: 486
diff changeset
  4529
    |p|
11ef93d12870 support anonymous (OS_specified) ports. (for FTP-protocol)
Claus Gittinger <cg@exept.de>
parents: 486
diff changeset
  4530
11ef93d12870 support anonymous (OS_specified) ports. (for FTP-protocol)
Claus Gittinger <cg@exept.de>
parents: 486
diff changeset
  4531
    port == 0 ifTrue:[
524
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  4532
	p := self getPort.
506
11ef93d12870 support anonymous (OS_specified) ports. (for FTP-protocol)
Claus Gittinger <cg@exept.de>
parents: 486
diff changeset
  4533
	p notNil ifTrue:[
11ef93d12870 support anonymous (OS_specified) ports. (for FTP-protocol)
Claus Gittinger <cg@exept.de>
parents: 486
diff changeset
  4534
	    port := p
11ef93d12870 support anonymous (OS_specified) ports. (for FTP-protocol)
Claus Gittinger <cg@exept.de>
parents: 486
diff changeset
  4535
	]
11ef93d12870 support anonymous (OS_specified) ports. (for FTP-protocol)
Claus Gittinger <cg@exept.de>
parents: 486
diff changeset
  4536
    ].
71
claus
parents: 63
diff changeset
  4537
    ^ port
28
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  4538
!
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  4539
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  4540
type
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  4541
    "return the sockets connection type (i.e. #datagram, #stream etc)"
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  4542
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  4543
    ^ socketType
81
claus
parents: 79
diff changeset
  4544
! !
claus
parents: 79
diff changeset
  4545
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4546
!Socket methodsFor:'socket setup'!
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4547
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4548
domain:domainArg type:typeArg
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4549
    "set up socket with domain and type.
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4550
     This is a low level entry; no binding, listening or connect
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4551
     is done. Both arguments must be symbols from one of
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4552
     #inet,#unix, #appletalk, #x25 .. and #stream, #datagram, #raw resp."
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4553
649
1bc56594db85 fixed connect for sun/irix
Claus Gittinger <cg@exept.de>
parents: 648
diff changeset
  4554
    ^ self domain:domainArg type:typeArg protocol:0 reuseAddress:true
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4555
!
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4556
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4557
domain:domainArg type:typeArg protocol:protocolNumber
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4558
    "set up socket with domain, type and protocol number.
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4559
     This is a low level entry; no binding, listening or connect
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4560
     is done. Both arguments must be symbols from one of
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4561
     #inet,#unix, #appletalk, #x25 .. and #stream, #datagram, #raw resp."
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4562
649
1bc56594db85 fixed connect for sun/irix
Claus Gittinger <cg@exept.de>
parents: 648
diff changeset
  4563
    ^ self domain:domainArg type:typeArg protocol:protocolNumber reuseAddress:true
1bc56594db85 fixed connect for sun/irix
Claus Gittinger <cg@exept.de>
parents: 648
diff changeset
  4564
1bc56594db85 fixed connect for sun/irix
Claus Gittinger <cg@exept.de>
parents: 648
diff changeset
  4565
    "
1bc56594db85 fixed connect for sun/irix
Claus Gittinger <cg@exept.de>
parents: 648
diff changeset
  4566
     Socket new domain:#inet type:#stream
1bc56594db85 fixed connect for sun/irix
Claus Gittinger <cg@exept.de>
parents: 648
diff changeset
  4567
     Socket new domain:#unix type:#stream
1bc56594db85 fixed connect for sun/irix
Claus Gittinger <cg@exept.de>
parents: 648
diff changeset
  4568
    "
1bc56594db85 fixed connect for sun/irix
Claus Gittinger <cg@exept.de>
parents: 648
diff changeset
  4569
!
1bc56594db85 fixed connect for sun/irix
Claus Gittinger <cg@exept.de>
parents: 648
diff changeset
  4570
1bc56594db85 fixed connect for sun/irix
Claus Gittinger <cg@exept.de>
parents: 648
diff changeset
  4571
domain:domainArg type:typeArg protocol:protocolNumber reuseAddress:reuse
1bc56594db85 fixed connect for sun/irix
Claus Gittinger <cg@exept.de>
parents: 648
diff changeset
  4572
    "set up socket with domain, type and protocol number.
1bc56594db85 fixed connect for sun/irix
Claus Gittinger <cg@exept.de>
parents: 648
diff changeset
  4573
     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
  4574
     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
  4575
     #inet,#unix, #appletalk, #x25 .. and #stream, #datagram, #raw resp.
1bc56594db85 fixed connect for sun/irix
Claus Gittinger <cg@exept.de>
parents: 648
diff changeset
  4576
1bc56594db85 fixed connect for sun/irix
Claus Gittinger <cg@exept.de>
parents: 648
diff changeset
  4577
     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
  4578
     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
  4579
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4580
    |errorNr|
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4581
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4582
    filePointer notNil ifTrue:[
789
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  4583
	^ self errorAlreadyOpen
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4584
    ].
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4585
%{
649
1bc56594db85 fixed connect for sun/irix
Claus Gittinger <cg@exept.de>
parents: 648
diff changeset
  4586
418
317e55c6c281 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 403
diff changeset
  4587
#ifndef NO_SOCKET
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4588
    FILE *fp;
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4589
    int dom, typ, pf, proto = 0, sock;
649
1bc56594db85 fixed connect for sun/irix
Claus Gittinger <cg@exept.de>
parents: 648
diff changeset
  4590
    int on = 1;
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4591
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4592
    if (! __isSymbol(domainArg)) { 
789
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  4593
	DBGPRINTF(("SOCKET: bad domain\n"));
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  4594
	RETURN ( nil );
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4595
    }
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4596
    if (! __isSymbol(typeArg)) { 
789
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  4597
	DBGPRINTF(("SOCKET: bad type\n"));
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  4598
	RETURN ( nil );
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4599
    }
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4600
    if (protocolNumber != nil) {
789
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  4601
	if (!__isSmallInteger(protocolNumber)) {
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  4602
	    DBGPRINTF(("SOCKET: bad protocol\n"));
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  4603
	    RETURN ( nil );
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  4604
	}
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  4605
	proto = __intVal(protocolNumber);
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4606
    }
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4607
        
81
claus
parents: 79
diff changeset
  4608
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4609
    /*
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4610
     * get address and protocol-family
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4611
     */
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4612
#ifdef AF_UNIX
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4613
    if (domainArg == @symbol(unix)) {
789
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  4614
	dom = AF_UNIX;
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4615
    } else
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4616
#endif
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4617
#ifdef AF_INET
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4618
    if (domainArg == @symbol(inet)) {
789
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  4619
	dom = AF_INET;
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4620
    } else
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4621
#endif
530
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  4622
#ifdef AF_INET6
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  4623
    if (domainArg == @symbol(inet6)) {
789
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  4624
	dom = AF_INET6;
530
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  4625
    } else
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  4626
#endif
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4627
#ifdef AF_DECnet
819
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
  4628
    if (domainArg == @symbol(decnet)) {
789
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  4629
	dom = AF_DECnet;
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4630
    } else
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4631
#endif
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4632
#ifdef AF_APPLETALK
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4633
    if (domainArg == @symbol(appletalk)) {
789
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  4634
	dom = AF_APPLETALK;
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4635
    } else
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4636
#endif
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4637
#ifdef AF_X25
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4638
    if (domainArg == @symbol(x25)) {
789
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  4639
	dom = AF_X25;
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4640
    } else
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4641
#endif
819
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
  4642
#ifdef AF_AX25
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
  4643
    if (domainArg == @symbol(ax25)) {
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
  4644
	dom = AF_AX25;
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
  4645
    } else
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
  4646
#endif
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4647
#ifdef AF_NS
812
c8101ea70e6c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 811
diff changeset
  4648
    if ((domainArg == @symbol(xns))
c8101ea70e6c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 811
diff changeset
  4649
     || (domainArg == @symbol(ns))) {
789
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  4650
	dom = AF_NS;
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4651
    } else
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4652
#endif
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4653
#ifdef AF_SNA
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4654
    if (domainArg == @symbol(sna)) {
789
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  4655
	dom = AF_SNA;
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4656
    } else
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4657
#endif
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4658
#ifdef AF_RAW
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4659
    if (domainArg == @symbol(raw)) {
789
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  4660
	dom = AF_RAW;
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4661
    } else
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4662
#endif
524
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  4663
# ifdef AF_ISO
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  4664
    if (domainArg == @symbol(iso)) {
789
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  4665
	dom = AF_ISO;
874
Claus Gittinger <cg@exept.de>
parents: 870
diff changeset
  4666
    } else
524
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  4667
# endif
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  4668
# ifdef AF_NETBIOS
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  4669
    if (domainArg == @symbol(netbios)) {
789
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  4670
	dom = AF_NETBIOS;
874
Claus Gittinger <cg@exept.de>
parents: 870
diff changeset
  4671
    } else
524
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  4672
# endif
530
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  4673
# ifdef AF_IPX
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  4674
    if (domainArg == @symbol(ipx)) {
789
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  4675
	dom = AF_IPX;
874
Claus Gittinger <cg@exept.de>
parents: 870
diff changeset
  4676
    } else
530
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  4677
# endif
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  4678
# ifdef AF_BRIDGE
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  4679
    if (domainArg == @symbol(bridge)) {
789
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  4680
	dom = AF_BRIDGE;
874
Claus Gittinger <cg@exept.de>
parents: 870
diff changeset
  4681
    } else
530
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  4682
# endif
571
191b37534643 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 563
diff changeset
  4683
# ifdef AF_BSC
191b37534643 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 563
diff changeset
  4684
    if (domainArg == @symbol(bsc)) {
789
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  4685
	dom = AF_BSC;
874
Claus Gittinger <cg@exept.de>
parents: 870
diff changeset
  4686
    } else
571
191b37534643 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 563
diff changeset
  4687
# endif
812
c8101ea70e6c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 811
diff changeset
  4688
# ifdef AF_ROSE
c8101ea70e6c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 811
diff changeset
  4689
    if (domainArg == @symbol(rose)) {
c8101ea70e6c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 811
diff changeset
  4690
	dom = AF_ROSE;
874
Claus Gittinger <cg@exept.de>
parents: 870
diff changeset
  4691
    } else
812
c8101ea70e6c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 811
diff changeset
  4692
# endif
869
a6e5cbe9f558 preps for AF_IRDA
Claus Gittinger <cg@exept.de>
parents: 867
diff changeset
  4693
# ifdef AF_IRDA
a6e5cbe9f558 preps for AF_IRDA
Claus Gittinger <cg@exept.de>
parents: 867
diff changeset
  4694
    if (domainArg == @symbol(irda)) {
a6e5cbe9f558 preps for AF_IRDA
Claus Gittinger <cg@exept.de>
parents: 867
diff changeset
  4695
	dom = AF_IRDA;
874
Claus Gittinger <cg@exept.de>
parents: 870
diff changeset
  4696
    } else
869
a6e5cbe9f558 preps for AF_IRDA
Claus Gittinger <cg@exept.de>
parents: 867
diff changeset
  4697
# endif
524
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  4698
# if defined(AF_CCITT) && (AF_CCITT != AF_X25)
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  4699
    if (domainArg == @symbol(ccitt)) {
789
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  4700
	dom = AF_CCITT;
874
Claus Gittinger <cg@exept.de>
parents: 870
diff changeset
  4701
    } else
524
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  4702
# endif
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4703
    {
789
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  4704
	DBGPRINTF(("SOCKET: unknown domain <%s>\n", __stringVal(domainArg)));
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  4705
	RETURN ( nil );
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4706
    }
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4707
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4708
#ifdef SOCK_STREAM
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4709
    if (typeArg == @symbol(stream)) {
789
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  4710
	typ = SOCK_STREAM;
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4711
    } else
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4712
#endif
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4713
#ifdef SOCK_DGRAM
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4714
    if (typeArg == @symbol(datagram)) {
789
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  4715
	typ = SOCK_DGRAM;
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4716
    } else 
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4717
#endif
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4718
#ifdef SOCK_RAW
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4719
    if (typeArg == @symbol(raw))
789
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  4720
	typ = SOCK_RAW;
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4721
    else
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4722
#endif
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4723
#ifdef SOCK_SEQPACKET
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4724
    if (typeArg == @symbol(seqPacket))
789
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  4725
	typ = SOCK_SEQPACKET;
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4726
    else
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4727
#endif
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4728
    {
789
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  4729
	DBGPRINTF(("SOCKET: bad type <%s>\n", __stringVal(typeArg)));
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  4730
	RETURN ( nil );
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4731
    }
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4732
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4733
    __BEGIN_INTERRUPTABLE__
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4734
    do {
789
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  4735
	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
  4736
	sock = socket(dom, typ, proto);
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4737
#if defined(EPROTONOSUPPORT) /* for SGI */
789
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  4738
	if ((proto != 0) && (sock < 0) && (errno == EPROTONOSUPPORT)) {
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  4739
	    DBGPRINTF(("SOCKET: retry with UNSPEC protocol\n"));
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  4740
	    proto = 0;
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  4741
	    sock = socket(dom, typ, 0);
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  4742
	}
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4743
#endif
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4744
    } while ((sock < 0) && (errno == EINTR));
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4745
    __END_INTERRUPTABLE__
821
40b0b69bf4b5 more debugs; fixed at-addresses
Claus Gittinger <cg@exept.de>
parents: 820
diff changeset
  4746
    DBGFPRINTF((stderr, "socket create newSock=%d\n", sock));
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4747
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4748
    if (sock < 0) {
789
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  4749
	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
  4750
	__INST(lastErrorNumber) = __MKSMALLINT(errno);
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4751
    } else {
649
1bc56594db85 fixed connect for sun/irix
Claus Gittinger <cg@exept.de>
parents: 648
diff changeset
  4752
# ifdef SO_REUSEADDR
789
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  4753
	if (reuse == true) {
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  4754
	    DBGPRINTF(("SOCKET: setsockopt - SO_REUSEADDR\n"));
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  4755
	    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
  4756
		DBGPRINTF(("SOCKET: setsockopt - SO_REUSEADDR failed\n"));
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  4757
	    }
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  4758
	}
649
1bc56594db85 fixed connect for sun/irix
Claus Gittinger <cg@exept.de>
parents: 648
diff changeset
  4759
# endif /* SO_REUSEADDR */
711
487b2bff9d31 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 693
diff changeset
  4760
789
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  4761
	/* 
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  4762
	 * make it a FILE * 
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  4763
	 */
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  4764
	fp = fdopen(sock, "r+");
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  4765
	if (! fp) {
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  4766
	    DBGPRINTF(("SOCKET: fdopen call failed\n"));
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  4767
	    __INST(lastErrorNumber) = __MKSMALLINT(errno);
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  4768
	    __BEGIN_INTERRUPTABLE__
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  4769
	    close(sock);
821
40b0b69bf4b5 more debugs; fixed at-addresses
Claus Gittinger <cg@exept.de>
parents: 820
diff changeset
  4770
	    DBGFPRINTF((stderr, "socket close (fdopen failed) (%d)\n", sock));
789
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  4771
	    __END_INTERRUPTABLE__
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  4772
	} else {
1035
5b0605675dc6 @globalfor classvar stuff
Stefan Vogel <sv@exept.de>
parents: 1029
diff changeset
  4773
	    if (@global(FileOpenTrace) == true) {
1009
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  4774
		fprintf(stderr, "fdopen [Socket] -> %x\n", fp);
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  4775
	    }
876
69c9ed48daba *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 875
diff changeset
  4776
789
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  4777
	    __INST(filePointer) = __MKOBJ(fp);
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  4778
	    __STORESELF(filePointer);
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  4779
	}
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4780
    }
418
317e55c6c281 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 403
diff changeset
  4781
#endif
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4782
%}.
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4783
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4784
    "all ok?"
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4785
    filePointer notNil ifTrue:[
789
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  4786
	domain := domainArg.
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  4787
	socketType := typeArg.
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  4788
	Lobby register:self.
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4789
    ] ifFalse:[
789
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  4790
	^ nil
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4791
    ].
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4792
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4793
    "
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4794
     Socket new domain:#inet type:#stream
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4795
     Socket new domain:#unix type:#stream
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4796
    "
81
claus
parents: 79
diff changeset
  4797
!
claus
parents: 79
diff changeset
  4798
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4799
for:hostName port:portNr
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4800
    "setup for a TCP socket (i.e. inet domain, stream type) 
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4801
     If hostname is nil, a server port is opened,
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4802
     otherwise a client port to the server on host.
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4803
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4804
     HISTORIC LEFTOVER:
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4805
     This method will vanish, as soon as the low level
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4806
     connect/bind works,"
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4807
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4808
    self obsoleteMethodWarning.
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4809
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4810
    filePointer notNil ifTrue:[
789
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  4811
	^ self errorAlreadyOpen
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4812
    ].
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4813
    (portNr isMemberOf:SmallInteger) ifFalse:[
789
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  4814
	self error:'invalid portNr'
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4815
    ].
1120
b43bcd84bca8 gethostbyname beeds more than 64kb stack
martin
parents: 1119
diff changeset
  4816
%{  /* STACK: 100000 */
418
317e55c6c281 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 403
diff changeset
  4817
#ifndef NO_SOCKET
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4818
    struct sockaddr_in sa ;
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4819
    struct hostent *hp ;
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4820
    int a, sock ;
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4821
    long addr;
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4822
    FILE *fp;
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4823
    int ret;
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4824
    int on = 1;
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4825
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4826
    bzero((char *) &sa, sizeof(sa)) ;
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4827
    sa.sin_family = AF_INET;
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4828
    sa.sin_addr.s_addr = htonl(INADDR_ANY);
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4829
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4830
    if ((hostName != nil) && __isString(hostName)){
789
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  4831
	bzero(&sa, sizeof(sa)) ;
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  4832
	if ((addr = inet_addr((char *) __stringVal(hostName))) != -1) {
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  4833
	    /* 
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  4834
	     * is Internet addr in octet notation 
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  4835
	     */
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  4836
	    bcopy(&addr, (char *) &sa.sin_addr, sizeof(addr)) ; /* set address */
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  4837
	} else {
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  4838
	    /* 
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  4839
	     * do we know the host's address? 
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  4840
	     */
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  4841
	    GETHOSTBYNAME(hp, __stringVal(hostName))
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  4842
	    if (hp == NULL) {
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  4843
		DBGPRINTF(("SOCKET: unknown host: %s\n", __stringVal(hostName)));
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  4844
		RETURN ( nil );
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  4845
	    }
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  4846
	    bcopy(hp->h_addr, (char *) &sa.sin_addr, hp->h_length) ;
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  4847
	    sa.sin_family = hp->h_addrtype;
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  4848
	}
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4849
    }
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4850
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4851
    /*
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4852
     * create the socket
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4853
     */
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4854
    __BEGIN_INTERRUPTABLE__
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4855
    do {
789
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  4856
	sock = socket(sa.sin_family, SOCK_STREAM, 0);
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4857
    } while ((sock < 0) && (errno == EINTR));
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4858
    __END_INTERRUPTABLE__
821
40b0b69bf4b5 more debugs; fixed at-addresses
Claus Gittinger <cg@exept.de>
parents: 820
diff changeset
  4859
    DBGFPRINTF((stderr, "socket create newSock=%d\n", sock));
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4860
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4861
    if (sock < 0) {
789
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  4862
	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
  4863
	__INST(lastErrorNumber) = __MKSMALLINT(errno);
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4864
    } else {
789
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  4865
	/* 
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  4866
	 * connect/bind 
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  4867
	 */
1009
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  4868
	sa.sin_port = htons((u_short) __intVal(portNr)) ;
789
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  4869
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  4870
	__BEGIN_INTERRUPTABLE__
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  4871
	if (hostName != nil) {
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  4872
	    do {
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  4873
		ret = connect(sock, (struct sockaddr *)&sa, sizeof(sa));
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  4874
	    } while ((ret < 0) && (errno == EINTR));
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  4875
	} else {
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4876
#ifdef SO_REUSEADDR
789
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  4877
	    /*
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  4878
	     * should I also do this for DGRAM sockets ?
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  4879
	     */
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  4880
	    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
  4881
		DBGPRINTF(("SOCKET: setsockopt - SO_REUSEADDR failed\n"));
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  4882
	    }
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4883
#endif /* SO_REUSEADDR */
789
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  4884
	    sa.sin_addr.s_addr = htonl(INADDR_ANY);
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  4885
	    do {
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  4886
		ret = bind(sock, (struct sockaddr *)&sa, sizeof(sa));
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  4887
	    } while ((ret < 0) && (errno == EINTR));
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  4888
	}
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  4889
	__END_INTERRUPTABLE__
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  4890
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  4891
	if (ret < 0) { 
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  4892
	    DBGPRINTF(("SOCKET: bind/connect call failed errno=%d\n", errno));
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  4893
	    __INST(lastErrorNumber) = __MKSMALLINT(errno);
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  4894
	    __BEGIN_INTERRUPTABLE__
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  4895
	    close(sock) ;
821
40b0b69bf4b5 more debugs; fixed at-addresses
Claus Gittinger <cg@exept.de>
parents: 820
diff changeset
  4896
	    DBGFPRINTF((stderr, "socket close (fdopen failed) (%d)\n", sock));
789
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  4897
	    __END_INTERRUPTABLE__
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  4898
	} else {
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  4899
	    /* 
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  4900
	     * make it a FILE * 
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  4901
	     */
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  4902
	    fp = fdopen(sock, "r+");
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  4903
	    if (! fp) {
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  4904
		DBGPRINTF(("SOCKET: fdopen failed\n"));
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  4905
		__INST(lastErrorNumber) = __MKSMALLINT(errno);
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  4906
		__BEGIN_INTERRUPTABLE__
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  4907
		close(sock);
822
a08e230988fe *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 821
diff changeset
  4908
		DBGFPRINTF((stderr, "socket close (fdopen failed) (%d)\n", sock));
789
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  4909
		__END_INTERRUPTABLE__
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  4910
	    } else {
1035
5b0605675dc6 @globalfor classvar stuff
Stefan Vogel <sv@exept.de>
parents: 1029
diff changeset
  4911
		if (@global(FileOpenTrace) == true) {
1009
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  4912
		    fprintf(stderr, "fdopen [Socket] -> %x\n", fp);
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  4913
		}
876
69c9ed48daba *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 875
diff changeset
  4914
444
9ba31a1fba38 always unbuffered on linux
Claus Gittinger <cg@exept.de>
parents: 430
diff changeset
  4915
#ifdef BUGGY_STDIO_LIB
789
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  4916
		setbuf(fp, NULL);
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  4917
		__INST(buffered) = false;
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4918
#endif
789
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  4919
		__INST(filePointer) = __MKOBJ(fp);
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  4920
		__STORESELF(filePointer);
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  4921
	    }
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  4922
	}
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4923
    }
418
317e55c6c281 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 403
diff changeset
  4924
#endif
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4925
%}.
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4926
    filePointer isNil ifTrue:[
789
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  4927
	^ nil
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4928
    ].
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4929
    mode := #readwrite.
169
ba5dac089c64 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 168
diff changeset
  4930
    Lobby register:self.
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4931
    binary := false.
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4932
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4933
    domain := #inet.
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4934
    socketType := #stream.
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4935
    protocol := portNr.
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4936
    peerName := hostName.
81
claus
parents: 79
diff changeset
  4937
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4938
    "
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4939
     Socket new for:'clam' port:(Socket portOfService:'echo')
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4940
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4941
     Socket new for:nil port:9999
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4942
     Socket new for:(OperatingSystem getHostName) port:9999
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4943
    "
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4944
!
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4945
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4946
for:hostName udpPort:portNr
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4947
    "setup for a UDP socket (i.e. inet domain, datagram type) 
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4948
     if hostname is nil, a server port is opened;
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4949
     otherwise a client port to the server on host.
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4950
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4951
     HISTORIC LEFTOVER:
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4952
     This method will vanish, as soon as the low level
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4953
     connect/bind works,"
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4954
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4955
    self obsoleteMethodWarning.
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4956
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4957
    filePointer notNil ifTrue:[
789
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  4958
	^ self errorAlreadyOpen
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4959
    ].
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4960
    (portNr isMemberOf:SmallInteger) ifFalse:[
789
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  4961
	self error:'invalid portNr'
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4962
    ].
1120
b43bcd84bca8 gethostbyname beeds more than 64kb stack
martin
parents: 1119
diff changeset
  4963
%{  /* STACK: 100000 */
418
317e55c6c281 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 403
diff changeset
  4964
#ifndef NO_SOCKET
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4965
    struct sockaddr_in sa ;
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4966
    struct hostent *hp ;
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4967
    int a, sock ;
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4968
    long addr;
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4969
    FILE *fp;
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4970
    int ret;
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4971
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4972
    if (hostName != nil) {
789
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  4973
	bzero(&sa, sizeof(sa)) ;
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  4974
	if ((addr = inet_addr((char *) __stringVal(hostName))) != -1) {
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  4975
	    /* 
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  4976
	     * is Internet addr in octet notation 
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  4977
	     */
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  4978
	    bcopy(&addr, (char *) &sa.sin_addr, sizeof(addr)) ; /* set address */
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  4979
	    sa.sin_family = AF_INET ;
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  4980
	} else {
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  4981
	    /* 
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  4982
	     * is hostname - 
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  4983
	     * do we know the host's address? 
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  4984
	     */
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  4985
	    GETHOSTBYNAME(hp, __stringVal(hostName))
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  4986
	    if (hp == NULL) {
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  4987
		DBGPRINTF(("SOCKET: unknown host: %s\n", __stringVal(hostName)));
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  4988
		RETURN ( nil );
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  4989
	    }
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  4990
	    bcopy(hp->h_addr, (char *) &sa.sin_addr, hp->h_length) ;
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  4991
	    sa.sin_family = hp->h_addrtype ;
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  4992
	}
526
1748ab3892a3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 525
diff changeset
  4993
    } else {
789
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  4994
	sa.sin_family = AF_INET;
526
1748ab3892a3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 525
diff changeset
  4995
    }
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4996
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4997
    /*
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4998
     * create the socket
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4999
     */
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  5000
    __BEGIN_INTERRUPTABLE__
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  5001
    do {
789
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  5002
	sock = socket(sa.sin_family, SOCK_DGRAM, 0);
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  5003
    } while ((sock < 0) && (errno == EINTR));
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  5004
    __END_INTERRUPTABLE__
821
40b0b69bf4b5 more debugs; fixed at-addresses
Claus Gittinger <cg@exept.de>
parents: 820
diff changeset
  5005
    DBGFPRINTF((stderr, "socket create newSock=%d\n", sock));
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  5006
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  5007
    if (sock < 0) {
789
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  5008
	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
  5009
	__INST(lastErrorNumber) = __MKSMALLINT(errno);
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  5010
    } else {
789
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  5011
	/* 
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  5012
	 * ok,
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  5013
	 * connect/bind 
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  5014
	 */
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  5015
	__BEGIN_INTERRUPTABLE__
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  5016
	if (hostName == nil) {
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  5017
	    sa.sin_addr.s_addr = htonl(INADDR_ANY);
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  5018
	    do {
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  5019
		ret = bind(sock, (struct sockaddr *)&sa, sizeof(sa));
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  5020
	    } while ((ret < 0) && (errno == EINTR));
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  5021
	} else {
1009
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  5022
	    sa.sin_port = htons((u_short) __intVal(portNr)) ;
789
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  5023
	    do {
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  5024
		ret = connect(sock, (struct sockaddr *)&sa, sizeof(sa));
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  5025
	    } while ((ret < 0) && (errno == EINTR));
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  5026
	}
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  5027
	__END_INTERRUPTABLE__
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  5028
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  5029
	if (ret < 0) {
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  5030
	    DBGPRINTF(("SOCKET: bind/connect call failed\n"));
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  5031
	    __INST(lastErrorNumber) = __MKSMALLINT(errno);
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  5032
	    __BEGIN_INTERRUPTABLE__
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  5033
	    close(sock) ;
821
40b0b69bf4b5 more debugs; fixed at-addresses
Claus Gittinger <cg@exept.de>
parents: 820
diff changeset
  5034
	    DBGFPRINTF((stderr, "socket close (fdopen failed) (%d)\n", sock));
789
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  5035
	    __END_INTERRUPTABLE__
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  5036
	} else {
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  5037
	    /* 
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  5038
	     * make it a FILE * 
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  5039
	     */
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  5040
	    fp = fdopen(sock, "r+");
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  5041
	    if (! fp) {
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  5042
		DBGPRINTF(("SOCKET: fdopen call failed\n"));
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  5043
		__INST(lastErrorNumber) = __MKSMALLINT(errno);
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  5044
		__BEGIN_INTERRUPTABLE__
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  5045
		close(sock);
821
40b0b69bf4b5 more debugs; fixed at-addresses
Claus Gittinger <cg@exept.de>
parents: 820
diff changeset
  5046
		DBGFPRINTF((stderr, "socket close (fdopen failed) (%d)\n", sock));
789
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  5047
		__END_INTERRUPTABLE__
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  5048
	    } else {
1009
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  5049
		if (@global(ExternalStream:FileOpenTrace) == true) {
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  5050
		    fprintf(stderr, "fdopen [Socket] -> %x\n", fp);
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  5051
		}
876
69c9ed48daba *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 875
diff changeset
  5052
444
9ba31a1fba38 always unbuffered on linux
Claus Gittinger <cg@exept.de>
parents: 430
diff changeset
  5053
#ifdef BUGGY_STDIO_LIB
789
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  5054
		setbuf(fp, NULL);
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  5055
		__INST(buffered) = false;
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  5056
#endif
789
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  5057
		__INST(filePointer) = __MKOBJ(fp);
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  5058
		__STORESELF(filePointer);
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  5059
	    }
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  5060
	}
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  5061
    }
418
317e55c6c281 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 403
diff changeset
  5062
#endif
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  5063
%}.
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  5064
    filePointer isNil ifTrue:[
789
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  5065
	^ nil
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  5066
    ].
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  5067
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  5068
    mode := #readwrite.
169
ba5dac089c64 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 168
diff changeset
  5069
    Lobby register:self.
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  5070
    binary := false.
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  5071
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  5072
    domain := #inet.
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  5073
    socketType := #datagram.
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  5074
    protocol := portNr.
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  5075
    peerName := hostName.
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  5076
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  5077
    "
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  5078
     Socket new for:'clam' udpPort:(Socket portOfService:'echo')
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  5079
    "
28
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  5080
! !
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  5081
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  5082
!Socket methodsFor:'specials'!
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  5083
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  5084
receiveTimeout:seconds
71
claus
parents: 63
diff changeset
  5085
    "set the receive timeout - for special applications only.
claus
parents: 63
diff changeset
  5086
     Not all operatingSystems offer this functionality
claus
parents: 63
diff changeset
  5087
     (returns false, if unsupported)"
28
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  5088
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  5089
    |millis|
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  5090
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  5091
    filePointer isNil ifTrue:[
789
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  5092
	^ self errorNotOpen
28
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  5093
    ].
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  5094
    millis := (seconds * 1000) rounded.
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  5095
%{
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  5096
#if defined(SO_RCVTIMEO) && defined(SOL_SOCKET) && defined(HZ)
58
bd6753bf0401 *** empty log message ***
claus
parents: 51
diff changeset
  5097
    if (__isSmallInteger(millis)) {
789
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  5098
	OBJ fp = __INST(filePointer);
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  5099
	int sock;
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  5100
	int opt;
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  5101
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  5102
	sock = fileno(__FILEVal(fp));
1009
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  5103
	opt = __intVal(millis) / (1000 / HZ);
789
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  5104
	setsockopt(sock, SOL_SOCKET, SO_RCVTIMEO, (char *)&opt, sizeof(int));
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  5105
	RETURN(true);
28
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  5106
    }
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  5107
#endif
71
claus
parents: 63
diff changeset
  5108
%}.
28
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  5109
    ^ false
81
claus
parents: 79
diff changeset
  5110
!
claus
parents: 79
diff changeset
  5111
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  5112
sendTimeout:seconds
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  5113
    "set the send timeout - for special applications only.
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  5114
     Not all operatingSystems offer this functionality
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  5115
     (returns false, if unsupported)"
81
claus
parents: 79
diff changeset
  5116
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  5117
    |millis|
25
996051271ce9 *** empty log message ***
claus
parents: 21
diff changeset
  5118
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  5119
    filePointer isNil ifTrue:[
789
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  5120
	^ self errorNotOpen
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  5121
    ].
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  5122
    millis := (seconds * 1000) rounded.
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  5123
%{
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  5124
#if defined(SO_SNDTIMEO) && defined(SOL_SOCKET) && defined(HZ)
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  5125
    if (__isSmallInteger(millis)) {
789
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  5126
	OBJ fp = __INST(filePointer);
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  5127
	int sock;
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  5128
	int opt;
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  5129
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  5130
	sock = fileno(__FILEVal(fp));
1009
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  5131
	opt = __intVal(millis) / (1000 / HZ);
789
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  5132
	setsockopt(sock, SOL_SOCKET, SO_SNDTIMEO, (char *)&opt, sizeof(int));
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  5133
	RETURN(true);
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  5134
    }
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  5135
#endif
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  5136
%}.
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  5137
    ^ false
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  5138
! !
82
claus
parents: 81
diff changeset
  5139
464
600b101a7035 alen in accept
Claus Gittinger <cg@exept.de>
parents: 463
diff changeset
  5140
!Socket class methodsFor:'documentation'!
206
77166a6b3ee6 For ST80 style socket creation: register socket in Lobby.
Stefan Vogel <sv@exept.de>
parents: 203
diff changeset
  5141
77166a6b3ee6 For ST80 style socket creation: register socket in Lobby.
Stefan Vogel <sv@exept.de>
parents: 203
diff changeset
  5142
version
1170
270d76fc288f *** empty log message ***
penk
parents: 1146
diff changeset
  5143
    ^ '$Header: /cvs/stx/stx/libbasic2/Socket.st,v 1.169 2003-03-31 09:34:18 penk Exp $'
206
77166a6b3ee6 For ST80 style socket creation: register socket in Lobby.
Stefan Vogel <sv@exept.de>
parents: 203
diff changeset
  5144
! !