Socket.st
author Stefan Vogel <sv@exept.de>
Tue, 09 Apr 2002 16:58:01 +0200
changeset 1035 5b0605675dc6
parent 1029 5906977e62f0
child 1110 0876a3d30fd2
permissions -rw-r--r--
@globalfor classvar stuff
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
867
56ca0cc52fa7 category renamining
Claus Gittinger <cg@exept.de>
parents: 859
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: 
1009
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  1136
	create new client tcp socket, bind and connect; 
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
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'
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1147
     Socket connectTo:'finger' on:'clam'
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1148
     Socket connectTo:'ftp' on:'clam'
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1149
     Socket connectTo:'nntp' on:(OperatingSystem getEnvironment:'NNTPSERVER')
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1150
    "
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
provide:service
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1154
    "standard & easy server setup: 
811
72d9ac1a7f95 comments
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  1155
     create a new TCP server socket providing a service."
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1156
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1157
    |newSock|
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1158
968
c73180e4ab6a obsoleteMethodWarning
Claus Gittinger <cg@exept.de>
parents: 964
diff changeset
  1159
    self obsoleteMethodWarning:'use newTCP: / listen'.
c73180e4ab6a obsoleteMethodWarning
Claus Gittinger <cg@exept.de>
parents: 964
diff changeset
  1160
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1161
    newSock := (self new) for:nil port:(self portOfService:service).
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1162
    newSock notNil ifTrue:[
1009
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  1163
	newSock listenFor:5.
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1164
    ].
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1165
    ^ newSock
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1166
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
     Socket provide:9995
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1169
     (Socket provide:9996) accept
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1170
     Socket provide:'nntp'
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1171
    "
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
464
600b101a7035 alen in accept
Claus Gittinger <cg@exept.de>
parents: 463
diff changeset
  1174
!Socket class methodsFor:'general instance creation'!
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1175
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1176
domain:domainSymbol type:type
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1177
    "create a socket for domain and type -
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1178
     neither any connect nor binding is done.
819
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
  1179
     Domain must be one of the symbols: 
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
  1180
	#inet, #unix, #appletalk, #decnet, #xns, ...;
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
  1181
     Type must be:
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
  1182
	#stream, #datagram or #raw
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1183
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1184
     XXX: currently only the #inet domain is supported"
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1185
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1186
    ^ self new domain:domainSymbol type:type
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1187
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
     Socket domain:#inet type:#stream
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1190
     Socket domain:#inet type:#datagram
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1191
     Socket domain:#unix type:#stream
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1192
     Socket domain:#appletalk type:#stream
819
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
  1193
     Socket domain:#decnet type:#stream
869
a6e5cbe9f558 preps for AF_IRDA
Claus Gittinger <cg@exept.de>
parents: 867
diff changeset
  1194
     Socket domain:#irda type:#stream
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1195
    "
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
576
13acab81fad0 more ST80 compatibility
ca
parents: 572
diff changeset
  1198
new
13acab81fad0 more ST80 compatibility
ca
parents: 572
diff changeset
  1199
    "create a TCP socket"
13acab81fad0 more ST80 compatibility
ca
parents: 572
diff changeset
  1200
13acab81fad0 more ST80 compatibility
ca
parents: 572
diff changeset
  1201
    ^ super new buffered:false 
13acab81fad0 more ST80 compatibility
ca
parents: 572
diff changeset
  1202
!
13acab81fad0 more ST80 compatibility
ca
parents: 572
diff changeset
  1203
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1204
newTCP
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1205
    "create a TCP socket - no binding or other setup is done,
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1206
     neither connect nor connect-wait is done."
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1207
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1208
    ^ self new domain:#inet type:#stream 
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1209
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1210
    "Socket newUDP"
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1211
!
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
newTCP:aServiceOrNil
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1214
    "create a TCP socket for a service -
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1215
     neither connect nor connect-wait is done."
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1216
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1217
    |newSock|
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1218
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1219
    newSock := self newTCP.
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1220
    (newSock notNil and:[aServiceOrNil notNil]) ifTrue:[
819
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
  1221
	(newSock bindTo:(self portOfService:aServiceOrNil) address:nil) ifFalse:[
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
  1222
	    ^ nil
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
  1223
	]
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1224
    ].
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1225
    ^ newSock
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1226
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
    "Socket newTCP:'nntp'"
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1229
    "Socket newTCP:9995"
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1230
!
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1231
576
13acab81fad0 more ST80 compatibility
ca
parents: 572
diff changeset
  1232
newTCPclientToAddress:aHostAddress port:aService
13acab81fad0 more ST80 compatibility
ca
parents: 572
diff changeset
  1233
    "create a new TCP client socket connecting to a service.
13acab81fad0 more ST80 compatibility
ca
parents: 572
diff changeset
  1234
     Return a socket instance if ok, nil on failure.
13acab81fad0 more ST80 compatibility
ca
parents: 572
diff changeset
  1235
     Block until a connection is established (but only the current thread;
13acab81fad0 more ST80 compatibility
ca
parents: 572
diff changeset
  1236
     not the whole smalltalk). 
13acab81fad0 more ST80 compatibility
ca
parents: 572
diff changeset
  1237
     See also: #newTCPclientToAddress:port:withTimeout:"
13acab81fad0 more ST80 compatibility
ca
parents: 572
diff changeset
  1238
13acab81fad0 more ST80 compatibility
ca
parents: 572
diff changeset
  1239
    ^ self newTCPclientToAddress:aHostAddress port:aService withTimeout:nil
13acab81fad0 more ST80 compatibility
ca
parents: 572
diff changeset
  1240
!
13acab81fad0 more ST80 compatibility
ca
parents: 572
diff changeset
  1241
13acab81fad0 more ST80 compatibility
ca
parents: 572
diff changeset
  1242
newTCPclientToAddress:aHostAddress port:aService withTimeout:millis
13acab81fad0 more ST80 compatibility
ca
parents: 572
diff changeset
  1243
    "create a new TCP client socket connecting to a service.
13acab81fad0 more ST80 compatibility
ca
parents: 572
diff changeset
  1244
     Return a socket instance if ok, nil on failure.
13acab81fad0 more ST80 compatibility
ca
parents: 572
diff changeset
  1245
     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
  1246
     and return nil."
576
13acab81fad0 more ST80 compatibility
ca
parents: 572
diff changeset
  1247
13acab81fad0 more ST80 compatibility
ca
parents: 572
diff changeset
  1248
    ^ self newTCPclientToHost:aHostAddress port:aService withTimeout:millis
13acab81fad0 more ST80 compatibility
ca
parents: 572
diff changeset
  1249
!
13acab81fad0 more ST80 compatibility
ca
parents: 572
diff changeset
  1250
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1251
newTCPclientToHost:hostname port:aService
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1252
    "create a new TCP client socket connecting to a service.
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1253
     Return a socket instance if ok, nil on failure.
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1254
     Block until a connection is established (but only the current thread;
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1255
     not the whole smalltalk). 
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1256
     See also: #newTCPclientToHost:port:withTimeout:"
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1257
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1258
    ^ self newTCPclientToHost:hostname port:aService withTimeout:nil
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1259
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
      Socket newTCPclientToHost:'localhost' port:'nntp'
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1262
    "
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
    "Created: 31.10.1995 / 18:54:11 / cg"
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1265
!
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
newTCPclientToHost:hostname port:aService withTimeout:millis
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1268
    "create a new TCP client socket connecting to a service.
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1269
     Return a socket instance if ok, nil on failure.
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1270
     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
  1271
     and return nil.."
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1272
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1273
    |newSock|
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1274
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1275
    newSock := self newTCP.
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1276
    newSock notNil ifTrue:[
648
58e11a70ddaf gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents: 617
diff changeset
  1277
	(newSock connectTo:hostname 
58e11a70ddaf gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents: 617
diff changeset
  1278
		 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
  1279
		 withTimeout:millis
58e11a70ddaf gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents: 617
diff changeset
  1280
	) ifFalse:[
58e11a70ddaf gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents: 617
diff changeset
  1281
	    newSock close.
58e11a70ddaf gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents: 617
diff changeset
  1282
	    ^ nil
58e11a70ddaf gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents: 617
diff changeset
  1283
	]
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1284
    ].
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1285
    ^ newSock
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1286
"
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1287
same as:
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1288
    ^ (self new) for:hostname port:(self portOfService:aPort).
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1289
"
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
      Socket newTCPclientToHost:'slsv6bt' port:'nntp'
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1292
      Socket newTCPclientToHost:'localhost' port:'nntp' withTimeout:1000
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1293
    "
604
b302a21afece Remove redundant code.
Stefan Vogel <sv@exept.de>
parents: 589
diff changeset
  1294
b302a21afece Remove redundant code.
Stefan Vogel <sv@exept.de>
parents: 589
diff changeset
  1295
    "Modified: / 16.1.1998 / 09:47:06 / stefan"
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1296
!
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1297
506
11ef93d12870 support anonymous (OS_specified) ports. (for FTP-protocol)
Claus Gittinger <cg@exept.de>
parents: 486
diff changeset
  1298
newTCPserverAtAnonymousPort
11ef93d12870 support anonymous (OS_specified) ports. (for FTP-protocol)
Claus Gittinger <cg@exept.de>
parents: 486
diff changeset
  1299
    "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
  1300
     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
  1301
811
72d9ac1a7f95 comments
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  1302
    ^ self newTCPserverAtPort:0
506
11ef93d12870 support anonymous (OS_specified) ports. (for FTP-protocol)
Claus Gittinger <cg@exept.de>
parents: 486
diff changeset
  1303
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
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1306
newTCPserverAtPort:aService
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1307
    "create a new TCP server socket providing service."
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1308
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1309
    |newSock|
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1310
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1311
    newSock := self newTCP.
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1312
    newSock notNil ifTrue:[
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1313
	(newSock bindTo:(self portOfService:aService) address:nil) ifFalse:[
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1314
	    ^ nil
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1315
	]
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
    ^ newSock
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1318
"
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1319
same as:
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1320
    ^ (self new) for:nil port:aPort
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1321
"
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
newUDP
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1325
    "create a UDP socket - no binding or other setup is done,
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1326
     neither connect nor connect-wait is done."
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1327
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1328
    ^ self new domain:#inet type:#datagram
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1329
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1330
    "Socket newUDP"
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1331
!
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
newUDP:aServiceOrNil
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1334
    "create a UDP socket for a service -
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1335
     neither connect nor connect-wait is done."
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1336
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1337
    |newSock|
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1338
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1339
    newSock := self newUDP.
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1340
    (newSock notNil and:[aServiceOrNil notNil]) ifTrue:[
819
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
  1341
	(newSock bindTo:(self portOfService:aServiceOrNil) address:nil) ifFalse:[
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
  1342
	    ^ nil
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
  1343
	]
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1344
    ].
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1345
    ^ newSock
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1346
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1347
    "Socket newUDP:nil"
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1348
!
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
newUDPserverAtPort:aService
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1351
    "create a new UDP server socket providing service."
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1352
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1353
    |newSock|
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1354
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1355
    newSock := self newUDP.
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1356
    newSock notNil ifTrue:[
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1357
	(newSock bindTo:(self portOfService:aService) address:nil) ifFalse:[
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1358
	    ^ nil
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1359
	]
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
    ^ newSock
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1362
"
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1363
same as:
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1364
    ^ (self new) for:nil udpPort:aPort
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1365
"
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
newUNIX
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1369
    "create a UNIX domain socket - no binding or other setup is done,
811
72d9ac1a7f95 comments
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  1370
     neither connect nor connect-wait is done.
72d9ac1a7f95 comments
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  1371
     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
  1372
     return nil."
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1373
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1374
    ^ self new domain:#unix type:#stream 
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1375
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
     Socket newUNIX
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1378
    "
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
newUNIXclientTo:pathName 
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1382
    "create a new UNIX client socket connecting to a pathname.
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1383
     Return a socket instance if ok, nil on failure.
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1384
     Block until a connection is established (but only the current thread;
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1385
     not the whole smalltalk). 
811
72d9ac1a7f95 comments
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  1386
     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
  1387
     return nil.
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1388
     See also: #newUNIXclientTo:withTimeout:"
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1389
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1390
    ^ self newUNIXclientTo:pathName withTimeout:nil
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1391
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
newUNIXclientTo:pathName withTimeout:millis
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1395
    "create a new UNIX client socket connecting to a pathname.
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1396
     Return a socket instance if ok, nil on failure.
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1397
     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
  1398
     and return nil.
72d9ac1a7f95 comments
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  1399
     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
  1400
     return nil."
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1401
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1402
    |newSock|
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1403
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1404
    newSock := self newUNIX.
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1405
    newSock notNil ifTrue:[
812
c8101ea70e6c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 811
diff changeset
  1406
	(newSock connectTo:pathName port:nil withTimeout:millis) ifFalse:[
c8101ea70e6c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 811
diff changeset
  1407
	    newSock close.
c8101ea70e6c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 811
diff changeset
  1408
	    ^ nil
c8101ea70e6c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 811
diff changeset
  1409
	]
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1410
    ].
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1411
    ^ newSock
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1412
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
     |s|
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1415
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1416
     s := Socket newUNIXclientTo:'/tmp/foo'
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1417
    "
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
newUNIXserverAt:pathName
811
72d9ac1a7f95 comments
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  1421
    "create a new UNIX server socket providing service at a pathname.
72d9ac1a7f95 comments
Claus Gittinger <cg@exept.de>
parents: 809
diff changeset
  1422
     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
  1423
     return nil."
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1424
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1425
    |newSock|
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1426
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1427
    newSock := self newUNIX.
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1428
    newSock notNil ifTrue:[
812
c8101ea70e6c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 811
diff changeset
  1429
	(newSock bindTo:pathName address:nil) ifFalse:[
c8101ea70e6c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 811
diff changeset
  1430
	    ^ nil
c8101ea70e6c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 811
diff changeset
  1431
	]
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1432
    ].
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1433
    ^ newSock
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1434
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
     |s s2|
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1437
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1438
     s := Socket newUNIXserverAt:'/tmp/foo'.
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1439
     s listenFor:5.
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1440
     s2 := s accept.
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1441
    "
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
525
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  1444
!Socket class methodsFor:'host queries'!
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  1445
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  1446
appletalkAddressOfHost:aHostName
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  1447
    "return the APPLETALK address for a hostname as a byteArray,
819
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
  1448
     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
  1449
     followed by the node byte.
525
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  1450
     If the host is unknown, return nil.
812
c8101ea70e6c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 811
diff changeset
  1451
     This is the reverse operation to #hostWithAppletalkAddress:.
c8101ea70e6c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 811
diff changeset
  1452
     WARNING: untested code - I have no appletalk to test this."
525
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  1453
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  1454
%{
526
1748ab3892a3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 525
diff changeset
  1455
#if !defined(NO_SOCKET) && defined(AF_APPLETALK)
819
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
  1456
    struct sockaddr_at sa;
525
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  1457
    struct hostent *hp ;
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  1458
    long addr;
653
219b89f62113 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 650
diff changeset
  1459
    OBJ rslt;
525
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  1460
529
fc7ec265717b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
  1461
    sa.sat_family = -1;
525
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  1462
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  1463
    if (__isString(aHostName)) {
789
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  1464
	bzero(&sa, sizeof(sa)) ;
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  1465
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  1466
	/* do we know the host's address? */
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  1467
	GETHOSTBYNAME(hp, __stringVal(aHostName))
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  1468
	if (hp == NULL) {
819
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
  1469
	    DBGPRINTF(("SOCKET: unknown appletalk host: %s\n", __stringVal(aHostName)));
789
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  1470
	    RETURN ( nil );
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  1471
	}
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  1472
	bcopy(hp->h_addr, (char *) &sa.sat_addr, hp->h_length) ;
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  1473
	sa.sat_family = hp->h_addrtype;
525
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  1474
    }
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  1475
752
c4176e236d83 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 741
diff changeset
  1476
    /* if the addressing family is not AF_APPLETALK, Return nil */
812
c8101ea70e6c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 811
diff changeset
  1477
    if (sa.sat_family != AF_APPLETALK) {
789
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  1478
	DBGPRINTF(("SOCKET: not an appletalk host\n"));
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  1479
	RETURN ( nil );
525
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  1480
    }
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
    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
  1483
    rslt = __BYTEARRAY_NEW_INT(3);
219b89f62113 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 650
diff changeset
  1484
    if (rslt != nil) {
789
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  1485
	__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
  1486
	__ByteArrayInstPtr(rslt)->ba_element[1] = (sa.sat_addr.s_net) & 0xFF;
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  1487
	__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
  1488
       RETURN (rslt);
219b89f62113 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 650
diff changeset
  1489
    }
525
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  1490
#endif
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  1491
%}.
653
219b89f62113 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 650
diff changeset
  1492
    ^ nil
525
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  1493
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
hostWithAppletalkAddress:anAddress
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  1497
    "return the hostname for an APPLETALK address.
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  1498
     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
  1499
     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
  1500
     The last byte is the node number.
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  1501
     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
  1502
     This is is the reverse operation to #appletalkAddressOfHost:.
c8101ea70e6c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 811
diff changeset
  1503
     WARNING: untested code - I have no appletalk to test this."
525
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  1504
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  1505
    |b1 b2 b3 b4|
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  1506
812
c8101ea70e6c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 811
diff changeset
  1507
    b1 := anAddress at:1. "/ net-hi
c8101ea70e6c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 811
diff changeset
  1508
    b2 := anAddress at:2. "/ net-low
c8101ea70e6c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 811
diff changeset
  1509
    b3 := anAddress at:3. "/ node
525
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  1510
%{
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  1511
#if !defined(NO_SOCKET) && defined(AF_APPLETALK)
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  1512
    struct sockaddr_at sa ;
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  1513
    struct hostent *hp ;
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  1514
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  1515
    sa.sat_family = -1;
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
    if (__bothSmallInteger(b1, b2) && __bothSmallInteger(b3, b4)) {
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  1518
	bzero(&sa, sizeof(sa)) ;
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  1519
1009
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  1520
	sa.sat_addr.s_net = __intVal(b1) & 0xFF;
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  1521
	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
  1522
	sa.sat_addr.s_net = htons(sa.sat_addr.s_net);    
1009
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  1523
	sa.sat_addr.s_node = __intVal(b3) & 0xFF;
529
fc7ec265717b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
  1524
	sa.sat_family = AF_APPLETALK;
fc7ec265717b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
  1525
525
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  1526
	/* do we know the host's address? */
650
8c5616f17ed6 made gethostbyaddr interruptable
Claus Gittinger <cg@exept.de>
parents: 649
diff changeset
  1527
	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
  1528
	if (hp != NULL) {
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  1529
	    sa.sat_family = hp->h_addrtype;
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  1530
	} else {
819
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
  1531
	    DBGPRINTF(("SOCKET: unknown appletalk address: %d.%d.%d.%d\n", 
1009
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  1532
		       __intVal(b1), __intVal(b2), __intVal(b3)));
525
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  1533
	}
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  1534
    }
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  1535
752
c4176e236d83 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 741
diff changeset
  1536
    /* if the addressing family is not AF_APPLETALK, Return nil */
525
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  1537
    if (sa.sat_family != AF_APPLETALK) {
819
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
  1538
	DBGPRINTF(("SOCKET: not an appletalk host\n"));
525
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  1539
	RETURN ( nil );
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  1540
    }
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  1541
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  1542
    if (hp != NULL) {
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  1543
	RETURN (__MKSTRING(hp->h_name));
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  1544
    }
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  1545
#endif
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  1546
    RETURN (nil);
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  1547
%}.
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  1548
    "
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  1549
     Socket appletalkAddressOfHost:'clam'
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  1550
     Socket hostWithAppletalkAddress:#[1 2 3]  
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  1551
     "
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1552
!
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1553
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1554
hostWithIpAddress:anAddress
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1555
    "return the hostname for an IP (internet-) address.
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1556
     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
  1557
     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
  1558
     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
  1559
     This is the reverse operation to #ipAddressOfHost:."
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1560
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1561
    |b1 b2 b3 b4|
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 := anAddress at:1.
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1564
    b2 := anAddress at:2.
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1565
    b3 := anAddress at:3.
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1566
    b4 := anAddress at:4.
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1567
%{
525
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  1568
#if !defined(NO_SOCKET) && defined(AF_INET)
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1569
    struct sockaddr_in sa ;
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1570
    struct hostent *hp ;
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1571
525
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  1572
    sa.sin_family = -1;
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1573
    if (__bothSmallInteger(b1, b2) && __bothSmallInteger(b3, b4)) {
822
a08e230988fe *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 821
diff changeset
  1574
	bzero(&sa, sizeof(sa)) ;
1009
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  1575
	sa.sin_addr.s_addr = __intVal(b1) & 0xFF;
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  1576
	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
  1577
	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
  1578
	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
  1579
	sa.sin_addr.s_addr = htonl(sa.sin_addr.s_addr);    
a08e230988fe *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 821
diff changeset
  1580
	sa.sin_family = AF_INET;
a08e230988fe *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 821
diff changeset
  1581
	/* do we know the host's address? */
a08e230988fe *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 821
diff changeset
  1582
	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
  1583
        
822
a08e230988fe *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 821
diff changeset
  1584
	if (hp == NULL) {
a08e230988fe *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 821
diff changeset
  1585
	    DBGPRINTF(("SOCKET: unknown ip address: %d.%d.%d.%d\n", 
1009
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  1586
		       __intVal(b1), __intVal(b2), __intVal(b3), __intVal(b4)));
822
a08e230988fe *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 821
diff changeset
  1587
	} else {
a08e230988fe *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 821
diff changeset
  1588
	    sa.sin_family = hp->h_addrtype;
a08e230988fe *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 821
diff changeset
  1589
	}
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1590
    }
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1591
752
c4176e236d83 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 741
diff changeset
  1592
    /* if the addressing family is not AF_INET, Return nil */
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1593
    if (sa.sin_family != AF_INET) {
822
a08e230988fe *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 821
diff changeset
  1594
	RETURN ( nil );
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1595
    }
525
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  1596
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  1597
    if (hp != NULL) {
822
a08e230988fe *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 821
diff changeset
  1598
	RETURN (__MKSTRING(hp->h_name));
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
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  1601
    /*
752
c4176e236d83 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 741
diff changeset
  1602
     * Return it in dot-notation
525
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  1603
     */
448
2203a4bb620d removed all COMMA_CON / CON_COMMA uses
Claus Gittinger <cg@exept.de>
parents: 444
diff changeset
  1604
    RETURN (__MKSTRING(inet_ntoa(sa.sin_addr)));
418
317e55c6c281 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 403
diff changeset
  1605
#else
317e55c6c281 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 403
diff changeset
  1606
    RETURN (nil);
317e55c6c281 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 403
diff changeset
  1607
#endif
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1608
%}
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1609
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1610
    "
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1611
     Socket ipAddressOfHost:'clam'
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1612
     Socket hostWithIpAddress:(Socket ipAddressOfHost:'clam') 
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1613
     Socket ipAddressOfHost:'porty'
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1614
     Socket hostWithIpAddress:(Socket ipAddressOfHost:'porty') 
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1615
     Socket hostWithIpAddress:#[1 2 3 4]  
796
c9f6b3b667fb Fix ipAddressOfHost
Stefan Vogel <sv@exept.de>
parents: 790
diff changeset
  1616
     Socket hostWithIpAddress:#[127 0 0 1]  
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1617
     Socket hostWithIpAddress:(Socket ipAddressOfHost:'1.2.3.4')  
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1618
     "
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1619
!
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1620
820
b6860c3660c8 Fix address sizes when calling gethostbyaddr
Stefan Vogel <sv@exept.de>
parents: 819
diff changeset
  1621
hostWithIpV6Address:anAddress
b6860c3660c8 Fix address sizes when calling gethostbyaddr
Stefan Vogel <sv@exept.de>
parents: 819
diff changeset
  1622
    "return the hostname for an IPv6 (internet-) address.
b6860c3660c8 Fix address sizes when calling gethostbyaddr
Stefan Vogel <sv@exept.de>
parents: 819
diff changeset
  1623
     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
  1624
     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
  1625
     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
  1626
     This is the reverse operation to #ipV6AddressOfHost:."
b6860c3660c8 Fix address sizes when calling gethostbyaddr
Stefan Vogel <sv@exept.de>
parents: 819
diff changeset
  1627
b6860c3660c8 Fix address sizes when calling gethostbyaddr
Stefan Vogel <sv@exept.de>
parents: 819
diff changeset
  1628
%{
b6860c3660c8 Fix address sizes when calling gethostbyaddr
Stefan Vogel <sv@exept.de>
parents: 819
diff changeset
  1629
#if !defined(NO_SOCKET) && defined(AF_INET6)
b6860c3660c8 Fix address sizes when calling gethostbyaddr
Stefan Vogel <sv@exept.de>
parents: 819
diff changeset
  1630
    struct sockaddr_in6 sa ;
b6860c3660c8 Fix address sizes when calling gethostbyaddr
Stefan Vogel <sv@exept.de>
parents: 819
diff changeset
  1631
    struct hostent *hp ;
b6860c3660c8 Fix address sizes when calling gethostbyaddr
Stefan Vogel <sv@exept.de>
parents: 819
diff changeset
  1632
b6860c3660c8 Fix address sizes when calling gethostbyaddr
Stefan Vogel <sv@exept.de>
parents: 819
diff changeset
  1633
    sa.sin6_family = -1;
b6860c3660c8 Fix address sizes when calling gethostbyaddr
Stefan Vogel <sv@exept.de>
parents: 819
diff changeset
  1634
    if (__isByteArray(anAddress)) {
b6860c3660c8 Fix address sizes when calling gethostbyaddr
Stefan Vogel <sv@exept.de>
parents: 819
diff changeset
  1635
	bzero(&sa, sizeof(sa)) ;
b6860c3660c8 Fix address sizes when calling gethostbyaddr
Stefan Vogel <sv@exept.de>
parents: 819
diff changeset
  1636
	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
  1637
	    goto bad;
b6860c3660c8 Fix address sizes when calling gethostbyaddr
Stefan Vogel <sv@exept.de>
parents: 819
diff changeset
  1638
	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
  1639
b6860c3660c8 Fix address sizes when calling gethostbyaddr
Stefan Vogel <sv@exept.de>
parents: 819
diff changeset
  1640
	sa.sin6_family = AF_INET6;
b6860c3660c8 Fix address sizes when calling gethostbyaddr
Stefan Vogel <sv@exept.de>
parents: 819
diff changeset
  1641
	/* do we know the host's address? */
b6860c3660c8 Fix address sizes when calling gethostbyaddr
Stefan Vogel <sv@exept.de>
parents: 819
diff changeset
  1642
	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
  1643
	if (hp == NULL) {
b6860c3660c8 Fix address sizes when calling gethostbyaddr
Stefan Vogel <sv@exept.de>
parents: 819
diff changeset
  1644
	    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
  1645
		       sa.sin6_addr.s6_addr[0], 
b6860c3660c8 Fix address sizes when calling gethostbyaddr
Stefan Vogel <sv@exept.de>
parents: 819
diff changeset
  1646
		       sa.sin6_addr.s6_addr[1], 
b6860c3660c8 Fix address sizes when calling gethostbyaddr
Stefan Vogel <sv@exept.de>
parents: 819
diff changeset
  1647
		       sa.sin6_addr.s6_addr[2],
b6860c3660c8 Fix address sizes when calling gethostbyaddr
Stefan Vogel <sv@exept.de>
parents: 819
diff changeset
  1648
		       sa.sin6_addr.s6_addr[3] ));
b6860c3660c8 Fix address sizes when calling gethostbyaddr
Stefan Vogel <sv@exept.de>
parents: 819
diff changeset
  1649
	} else {
b6860c3660c8 Fix address sizes when calling gethostbyaddr
Stefan Vogel <sv@exept.de>
parents: 819
diff changeset
  1650
	    sa.sin6_family = hp->h_addrtype;
b6860c3660c8 Fix address sizes when calling gethostbyaddr
Stefan Vogel <sv@exept.de>
parents: 819
diff changeset
  1651
	}
b6860c3660c8 Fix address sizes when calling gethostbyaddr
Stefan Vogel <sv@exept.de>
parents: 819
diff changeset
  1652
    }
b6860c3660c8 Fix address sizes when calling gethostbyaddr
Stefan Vogel <sv@exept.de>
parents: 819
diff changeset
  1653
    bad: ;
b6860c3660c8 Fix address sizes when calling gethostbyaddr
Stefan Vogel <sv@exept.de>
parents: 819
diff changeset
  1654
    /* 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
  1655
    if (sa.sin6_family != AF_INET6) {
b6860c3660c8 Fix address sizes when calling gethostbyaddr
Stefan Vogel <sv@exept.de>
parents: 819
diff changeset
  1656
	DBGPRINTF(("SOCKET: not an ipv6 host\n")); 
b6860c3660c8 Fix address sizes when calling gethostbyaddr
Stefan Vogel <sv@exept.de>
parents: 819
diff changeset
  1657
	RETURN ( nil );
b6860c3660c8 Fix address sizes when calling gethostbyaddr
Stefan Vogel <sv@exept.de>
parents: 819
diff changeset
  1658
    }
b6860c3660c8 Fix address sizes when calling gethostbyaddr
Stefan Vogel <sv@exept.de>
parents: 819
diff changeset
  1659
b6860c3660c8 Fix address sizes when calling gethostbyaddr
Stefan Vogel <sv@exept.de>
parents: 819
diff changeset
  1660
    if (hp != NULL) {
b6860c3660c8 Fix address sizes when calling gethostbyaddr
Stefan Vogel <sv@exept.de>
parents: 819
diff changeset
  1661
	RETURN (__MKSTRING(hp->h_name));
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
b6860c3660c8 Fix address sizes when calling gethostbyaddr
Stefan Vogel <sv@exept.de>
parents: 819
diff changeset
  1664
    /*
b6860c3660c8 Fix address sizes when calling gethostbyaddr
Stefan Vogel <sv@exept.de>
parents: 819
diff changeset
  1665
     * Return it in dot-notation
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
    RETURN (__MKSTRING(inet_ntoa(sa.sin6_addr)));
b6860c3660c8 Fix address sizes when calling gethostbyaddr
Stefan Vogel <sv@exept.de>
parents: 819
diff changeset
  1668
#else
b6860c3660c8 Fix address sizes when calling gethostbyaddr
Stefan Vogel <sv@exept.de>
parents: 819
diff changeset
  1669
    RETURN (nil);
b6860c3660c8 Fix address sizes when calling gethostbyaddr
Stefan Vogel <sv@exept.de>
parents: 819
diff changeset
  1670
#endif
b6860c3660c8 Fix address sizes when calling gethostbyaddr
Stefan Vogel <sv@exept.de>
parents: 819
diff changeset
  1671
%}
b6860c3660c8 Fix address sizes when calling gethostbyaddr
Stefan Vogel <sv@exept.de>
parents: 819
diff changeset
  1672
b6860c3660c8 Fix address sizes when calling gethostbyaddr
Stefan Vogel <sv@exept.de>
parents: 819
diff changeset
  1673
    "
b6860c3660c8 Fix address sizes when calling gethostbyaddr
Stefan Vogel <sv@exept.de>
parents: 819
diff changeset
  1674
     Socket ipV6AddressOfHost:'clam'
b6860c3660c8 Fix address sizes when calling gethostbyaddr
Stefan Vogel <sv@exept.de>
parents: 819
diff changeset
  1675
     Socket hostWithIpV6Address:(Socket ipAddressOfHost:'clam') 
b6860c3660c8 Fix address sizes when calling gethostbyaddr
Stefan Vogel <sv@exept.de>
parents: 819
diff changeset
  1676
     Socket ipV6AddressOfHost:'porty'
b6860c3660c8 Fix address sizes when calling gethostbyaddr
Stefan Vogel <sv@exept.de>
parents: 819
diff changeset
  1677
     Socket hostWithIpV6Address:(Socket ipAddressOfHost:'porty') 
b6860c3660c8 Fix address sizes when calling gethostbyaddr
Stefan Vogel <sv@exept.de>
parents: 819
diff changeset
  1678
     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
  1679
     "
b6860c3660c8 Fix address sizes when calling gethostbyaddr
Stefan Vogel <sv@exept.de>
parents: 819
diff changeset
  1680
!
b6860c3660c8 Fix address sizes when calling gethostbyaddr
Stefan Vogel <sv@exept.de>
parents: 819
diff changeset
  1681
6
claus
parents: 4
diff changeset
  1682
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
  1683
    "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
  1684
     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
  1685
     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
  1686
     This is the reverse operation to #hostWithIpAddress:."
6
claus
parents: 4
diff changeset
  1687
claus
parents: 4
diff changeset
  1688
%{
525
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  1689
#if !defined(NO_SOCKET) && defined(AF_INET)
6
claus
parents: 4
diff changeset
  1690
    struct sockaddr_in sa ;
claus
parents: 4
diff changeset
  1691
    struct hostent *hp ;
claus
parents: 4
diff changeset
  1692
    long addr;
653
219b89f62113 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 650
diff changeset
  1693
    OBJ rslt;
6
claus
parents: 4
diff changeset
  1694
525
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  1695
    sa.sin_family = -1;
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  1696
21
33eb5ffad09d *** empty log message ***
claus
parents: 8
diff changeset
  1697
    if (__isString(aHostName)) {
812
c8101ea70e6c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 811
diff changeset
  1698
	bzero(&sa, sizeof(sa)) ;
c8101ea70e6c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 811
diff changeset
  1699
	if ((addr = inet_addr((char *) __stringVal(aHostName))) != -1) {
c8101ea70e6c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 811
diff changeset
  1700
	    /* is Internet addr in octet notation */
c8101ea70e6c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 811
diff changeset
  1701
	    bcopy(&addr, (char *) &sa.sin_addr, sizeof(addr)); 
c8101ea70e6c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 811
diff changeset
  1702
	    sa.sin_family = AF_INET;
c8101ea70e6c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 811
diff changeset
  1703
	} else {
c8101ea70e6c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 811
diff changeset
  1704
	    /* do we know the host's address? */
c8101ea70e6c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 811
diff changeset
  1705
	    GETHOSTBYNAME(hp, __stringVal(aHostName))
c8101ea70e6c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 811
diff changeset
  1706
	    if (hp == NULL) {
819
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
  1707
		DBGPRINTF(("SOCKET: unknown ip host: %s\n", __stringVal(aHostName)));
812
c8101ea70e6c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 811
diff changeset
  1708
		RETURN ( nil );
c8101ea70e6c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 811
diff changeset
  1709
	    }
c8101ea70e6c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 811
diff changeset
  1710
	    bcopy(hp->h_addr, (char *) &sa.sin_addr, hp->h_length) ;
c8101ea70e6c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 811
diff changeset
  1711
	    sa.sin_family = hp->h_addrtype;
c8101ea70e6c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 811
diff changeset
  1712
	}
6
claus
parents: 4
diff changeset
  1713
    }
525
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  1714
752
c4176e236d83 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 741
diff changeset
  1715
    /* if the addressing family is not AF_INET, Return nil */
6
claus
parents: 4
diff changeset
  1716
    if (sa.sin_family != AF_INET) {
819
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
  1717
	DBGPRINTF(("SOCKET: not an ip host\n"));
812
c8101ea70e6c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 811
diff changeset
  1718
	RETURN ( nil );
6
claus
parents: 4
diff changeset
  1719
    }
98
5e787ba2cb31 use common byteOrder when representing IP numbers as byteArrays (always network-first)
Claus Gittinger <cg@exept.de>
parents: 96
diff changeset
  1720
5e787ba2cb31 use common byteOrder when representing IP numbers as byteArrays (always network-first)
Claus Gittinger <cg@exept.de>
parents: 96
diff changeset
  1721
    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
  1722
    rslt = __BYTEARRAY_NEW_INT(4);
219b89f62113 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 650
diff changeset
  1723
    if (rslt != nil) {
812
c8101ea70e6c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 811
diff changeset
  1724
	__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
  1725
	__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
  1726
	__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
  1727
	__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
  1728
       RETURN (rslt);
219b89f62113 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 650
diff changeset
  1729
    }
418
317e55c6c281 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 403
diff changeset
  1730
#endif
525
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  1731
%}.
653
219b89f62113 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 650
diff changeset
  1732
    ^ nil
21
33eb5ffad09d *** empty log message ***
claus
parents: 8
diff changeset
  1733
71
claus
parents: 63
diff changeset
  1734
    "
796
c9f6b3b667fb Fix ipAddressOfHost
Stefan Vogel <sv@exept.de>
parents: 790
diff changeset
  1735
     Socket ipAddressOfHost:'localhost' 
c9f6b3b667fb Fix ipAddressOfHost
Stefan Vogel <sv@exept.de>
parents: 790
diff changeset
  1736
     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
  1737
     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
  1738
     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
  1739
     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
  1740
     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
  1741
     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
  1742
     Socket ipAddressOfHost:(Socket hostWithIpAddress:'127.0.0.1') 
71
claus
parents: 63
diff changeset
  1743
    "
819
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
  1744
!
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
  1745
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
  1746
ipV6AddressOfHost:aHostName
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
  1747
    "return the IPv6 (internet-) number for a hostname as a byteArray,
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
  1748
     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
  1749
     If the host is unknown, return nil.
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
  1750
     This is the reverse operation to #hostWithIpV6Address:."
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
  1751
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
  1752
%{
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
  1753
#if !defined(NO_SOCKET) && defined(AF_INET6)
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
  1754
    struct sockaddr_in6 sa;
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
  1755
    struct hostent *hp ;
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
  1756
    long addr;
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
  1757
    OBJ rslt;
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
  1758
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
  1759
    sa.sin6_family = -1;
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
  1760
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
  1761
    if (__isString(aHostName)) {
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
  1762
	bzero(&sa, sizeof(sa)) ;
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
  1763
#if 0
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
  1764
	if ((addr = inet_addr((char *) __stringVal(aHostName))) != -1) {
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
  1765
	    /* is Internet addr in octet notation */
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
  1766
	    bcopy(&addr, (char *) &sa.sin_addr, sizeof(addr)); 
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
  1767
	    sa.sin_family = AF_INET;
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
  1768
	} else 
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
  1769
#endif
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
  1770
	{
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
  1771
	    /* do we know the host's address? */
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
  1772
	    GETHOSTBYNAME(hp, __stringVal(aHostName))
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
  1773
	    if (hp == NULL) {
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
  1774
		DBGPRINTF(("SOCKET: unknown host: %s\n", __stringVal(aHostName)));
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
  1775
		RETURN ( nil );
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
  1776
	    }
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
  1777
	    bcopy(hp->h_addr, (char *) &sa.sin6_addr, hp->h_length) ;
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
  1778
	    sa.sin6_family = hp->h_addrtype;
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
    }
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
  1781
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
  1782
    /* if the addressing family is not AF_INET, Return nil */
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
  1783
    if (sa.sin6_family != AF_INET) {
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
  1784
	DBGPRINTF(("SOCKET: not an ipv6 host\n"));
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
  1785
	RETURN ( nil );
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
  1786
    }
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
  1787
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
  1788
    rslt = __BYTEARRAY_NEW_INT(hp->h_length);
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
  1789
    if (rslt != nil) {
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
  1790
	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
  1791
       RETURN (rslt);
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
  1792
    }
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
  1793
#endif
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
  1794
%}.
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
  1795
    ^ nil
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
  1796
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
     Socket ipV6AddressOfHost:'localhost' 
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
  1799
     Socket ipV6AddressOfHost:'exept'    
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
  1800
     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
  1801
     Socket ipV6AddressOfHost:'193.15.16.17'    
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
  1802
     Socket ipV6AddressOfHost:'josef'     
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
  1803
     Socket ipV6AddressOfHost:'styx.com'  
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
  1804
     Socket hostWithIpV6Address:(Socket ipV6AddressOfHost:'localhost') 
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
  1805
     Socket ipV6AddressOfHost:(Socket hostV6WithIpAddress:'127.0.0.1') 
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
  1806
    "
531
ca4c73813531 category changes
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1807
! !
ca4c73813531 category changes
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1808
ca4c73813531 category changes
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1809
!Socket class methodsFor:'queries'!
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
domainOfProtocol:aProtocol
ca4c73813531 category changes
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1812
    "given a protocols name (i.e. tcp, udp etc) return the domain.
ca4c73813531 category changes
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1813
     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
  1814
ca4c73813531 category changes
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1815
    "
ca4c73813531 category changes
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1816
     tcp/ip stuff
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
    (aProtocol = 'tcp') ifTrue:[^ #inet].
ca4c73813531 category changes
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1819
    (aProtocol = 'udp') ifTrue:[^ #inet].
ca4c73813531 category changes
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1820
    (aProtocol = 'ip')  ifTrue:[^ #inet].
ca4c73813531 category changes
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1821
    "
ca4c73813531 category changes
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1822
     unix domain
ca4c73813531 category changes
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1823
    "
ca4c73813531 category changes
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1824
    (aProtocol = 'ud')  ifTrue:[^ #unix].
ca4c73813531 category changes
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1825
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
     add x25 stuff (if any) here ...
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 appletalk 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 other 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
    ^ nil
ca4c73813531 category changes
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1836
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
     Socket domainOfProtocol:'tcp'
ca4c73813531 category changes
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1839
     Socket domainOfProtocol:'ucp'
ca4c73813531 category changes
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1840
     Socket domainOfProtocol:(Socket protocolOfService:'nntp')
ca4c73813531 category changes
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1841
     Socket domainOfProtocol:(Socket protocolOfService:'echo')
ca4c73813531 category changes
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1842
    "
6
claus
parents: 4
diff changeset
  1843
!
claus
parents: 4
diff changeset
  1844
206
77166a6b3ee6 For ST80 style socket creation: register socket in Lobby.
Stefan Vogel <sv@exept.de>
parents: 203
diff changeset
  1845
networkLongOrderIsMSB
964
a11c607f1a3e checkin from browser
ca
parents: 962
diff changeset
  1846
    "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
  1847
     To be used as in:
1009
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  1848
	'aStream nextPutLong:someValue MSB:(Socket networkLongOrderIsMSB)'."
964
a11c607f1a3e checkin from browser
ca
parents: 962
diff changeset
  1849
a11c607f1a3e checkin from browser
ca
parents: 962
diff changeset
  1850
    ^ true
206
77166a6b3ee6 For ST80 style socket creation: register socket in Lobby.
Stefan Vogel <sv@exept.de>
parents: 203
diff changeset
  1851
77166a6b3ee6 For ST80 style socket creation: register socket in Lobby.
Stefan Vogel <sv@exept.de>
parents: 203
diff changeset
  1852
    "
77166a6b3ee6 For ST80 style socket creation: register socket in Lobby.
Stefan Vogel <sv@exept.de>
parents: 203
diff changeset
  1853
     Socket networkLongOrderIsMSB
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
77166a6b3ee6 For ST80 style socket creation: register socket in Lobby.
Stefan Vogel <sv@exept.de>
parents: 203
diff changeset
  1857
networkShortOrderIsMSB
77166a6b3ee6 For ST80 style socket creation: register socket in Lobby.
Stefan Vogel <sv@exept.de>
parents: 203
diff changeset
  1858
    "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
  1859
     To be used as in:
77166a6b3ee6 For ST80 style socket creation: register socket in Lobby.
Stefan Vogel <sv@exept.de>
parents: 203
diff changeset
  1860
	'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
  1861
77166a6b3ee6 For ST80 style socket creation: register socket in Lobby.
Stefan Vogel <sv@exept.de>
parents: 203
diff changeset
  1862
%{  /* NOCONTEXT */
418
317e55c6c281 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 403
diff changeset
  1863
#ifndef NO_SOCKET
206
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
     * 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
  1866
     */
77166a6b3ee6 For ST80 style socket creation: register socket in Lobby.
Stefan Vogel <sv@exept.de>
parents: 203
diff changeset
  1867
    if (htons(0x3210) == 0x3210) {
77166a6b3ee6 For ST80 style socket creation: register socket in Lobby.
Stefan Vogel <sv@exept.de>
parents: 203
diff changeset
  1868
	RETURN (true);
77166a6b3ee6 For ST80 style socket creation: register socket in Lobby.
Stefan Vogel <sv@exept.de>
parents: 203
diff changeset
  1869
    }
418
317e55c6c281 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 403
diff changeset
  1870
#endif
206
77166a6b3ee6 For ST80 style socket creation: register socket in Lobby.
Stefan Vogel <sv@exept.de>
parents: 203
diff changeset
  1871
%}.
77166a6b3ee6 For ST80 style socket creation: register socket in Lobby.
Stefan Vogel <sv@exept.de>
parents: 203
diff changeset
  1872
    ^ false
77166a6b3ee6 For ST80 style socket creation: register socket in Lobby.
Stefan Vogel <sv@exept.de>
parents: 203
diff changeset
  1873
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
     Socket networkShortOrderIsMSB
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
0
1cf8d1747859 Initial revision
claus
parents:
diff changeset
  1879
portOfService:aNameOrNumber
819
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
  1880
    "returns the port-number for a given IP-service
0
1cf8d1747859 Initial revision
claus
parents:
diff changeset
  1881
     or nil if no such service exists;
1cf8d1747859 Initial revision
claus
parents:
diff changeset
  1882
     - used to convert service names to portNumbers"
1cf8d1747859 Initial revision
claus
parents:
diff changeset
  1883
91
Claus Gittinger <cg@exept.de>
parents: 85
diff changeset
  1884
    ^ self portOfService:aNameOrNumber protocol:nil
Claus Gittinger <cg@exept.de>
parents: 85
diff changeset
  1885
28
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  1886
    "
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  1887
     Socket portOfService:'finger'
74
claus
parents: 71
diff changeset
  1888
     Socket portOfService:'nntp'  
claus
parents: 71
diff changeset
  1889
     Socket portOfService:'echo' 
claus
parents: 71
diff changeset
  1890
     Socket portOfService:'snmp' 
28
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  1891
    "
0
1cf8d1747859 Initial revision
claus
parents:
diff changeset
  1892
!
1cf8d1747859 Initial revision
claus
parents:
diff changeset
  1893
91
Claus Gittinger <cg@exept.de>
parents: 85
diff changeset
  1894
portOfService:aNameOrNumber protocol:aProtocol
819
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
  1895
    "returns the port-number for a given IP-service
91
Claus Gittinger <cg@exept.de>
parents: 85
diff changeset
  1896
     or nil if no such service exists;
Claus Gittinger <cg@exept.de>
parents: 85
diff changeset
  1897
     - used to convert service names to portNumbers"
Claus Gittinger <cg@exept.de>
parents: 85
diff changeset
  1898
604
b302a21afece Remove redundant code.
Stefan Vogel <sv@exept.de>
parents: 589
diff changeset
  1899
%{ /* NOCONTEXT */
418
317e55c6c281 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 403
diff changeset
  1900
#ifndef NO_SOCKET
91
Claus Gittinger <cg@exept.de>
parents: 85
diff changeset
  1901
    struct servent *servent = NULL;
Claus Gittinger <cg@exept.de>
parents: 85
diff changeset
  1902
    char *protocol;
Claus Gittinger <cg@exept.de>
parents: 85
diff changeset
  1903
    int tryBoth = 0;
524
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  1904
    short portNo;
91
Claus Gittinger <cg@exept.de>
parents: 85
diff changeset
  1905
604
b302a21afece Remove redundant code.
Stefan Vogel <sv@exept.de>
parents: 589
diff changeset
  1906
    if (__isSmallInteger(aNameOrNumber)) {
648
58e11a70ddaf gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents: 617
diff changeset
  1907
	RETURN ( aNameOrNumber );
92
Claus Gittinger <cg@exept.de>
parents: 91
diff changeset
  1908
    }
Claus Gittinger <cg@exept.de>
parents: 91
diff changeset
  1909
604
b302a21afece Remove redundant code.
Stefan Vogel <sv@exept.de>
parents: 589
diff changeset
  1910
    if (__isString(aProtocol)) {
648
58e11a70ddaf gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents: 617
diff changeset
  1911
	protocol = (char *)__stringVal(aProtocol);
604
b302a21afece Remove redundant code.
Stefan Vogel <sv@exept.de>
parents: 589
diff changeset
  1912
    } else {
648
58e11a70ddaf gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents: 617
diff changeset
  1913
	protocol = "tcp";
58e11a70ddaf gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents: 617
diff changeset
  1914
	tryBoth = 1;
91
Claus Gittinger <cg@exept.de>
parents: 85
diff changeset
  1915
    }
524
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  1916
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  1917
    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
  1918
	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
  1919
	if (servent != NULL) {
58e11a70ddaf gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents: 617
diff changeset
  1920
	    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
  1921
	}
58e11a70ddaf gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents: 617
diff changeset
  1922
	if (tryBoth) {
58e11a70ddaf gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents: 617
diff changeset
  1923
	    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
  1924
	    if (servent != NULL) {
58e11a70ddaf gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents: 617
diff changeset
  1925
		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
  1926
	    }
58e11a70ddaf gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents: 617
diff changeset
  1927
	}
58e11a70ddaf gethostbyname behaves strange, if a name-server lookup is involved.
Claus Gittinger <cg@exept.de>
parents: 617
diff changeset
  1928
	RETURN ( nil );
91
Claus Gittinger <cg@exept.de>
parents: 85
diff changeset
  1929
    }
418
317e55c6c281 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 403
diff changeset
  1930
#endif
91
Claus Gittinger <cg@exept.de>
parents: 85
diff changeset
  1931
    RETURN ( nil );
Claus Gittinger <cg@exept.de>
parents: 85
diff changeset
  1932
%}
Claus Gittinger <cg@exept.de>
parents: 85
diff changeset
  1933
    "
Claus Gittinger <cg@exept.de>
parents: 85
diff changeset
  1934
     Socket portOfService:'echo' protocol:'udp'
Claus Gittinger <cg@exept.de>
parents: 85
diff changeset
  1935
     Socket portOfService:'echo' protocol:'tcp'
Claus Gittinger <cg@exept.de>
parents: 85
diff changeset
  1936
    "
Claus Gittinger <cg@exept.de>
parents: 85
diff changeset
  1937
!
Claus Gittinger <cg@exept.de>
parents: 85
diff changeset
  1938
0
1cf8d1747859 Initial revision
claus
parents:
diff changeset
  1939
protocolOfService:aNameOrNumber
819
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
  1940
    "returns the protocol (as string) for a given IP-service
28
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  1941
     or nil if no such service exists."
0
1cf8d1747859 Initial revision
claus
parents:
diff changeset
  1942
%{
418
317e55c6c281 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 403
diff changeset
  1943
#ifndef NO_SOCKET
0
1cf8d1747859 Initial revision
claus
parents:
diff changeset
  1944
    struct servent *servent = NULL;
524
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  1945
    short portNo;
0
1cf8d1747859 Initial revision
claus
parents:
diff changeset
  1946
58
bd6753bf0401 *** empty log message ***
claus
parents: 51
diff changeset
  1947
    if (__isSmallInteger(aNameOrNumber)) {
524
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  1948
	portNo = __intVal(aNameOrNumber);
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  1949
	servent = getservbyport(htons(portNo), "tcp") ;
42
506596f9a1a8 *** empty log message ***
claus
parents: 38
diff changeset
  1950
	if (servent == NULL) {
524
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  1951
	    servent = getservbyport(htons(portNo), "udp") ;
42
506596f9a1a8 *** empty log message ***
claus
parents: 38
diff changeset
  1952
	    if (servent == NULL) {
506596f9a1a8 *** empty log message ***
claus
parents: 38
diff changeset
  1953
		RETURN ( nil );
506596f9a1a8 *** empty log message ***
claus
parents: 38
diff changeset
  1954
	    }
506596f9a1a8 *** empty log message ***
claus
parents: 38
diff changeset
  1955
	}
0
1cf8d1747859 Initial revision
claus
parents:
diff changeset
  1956
    } else {
42
506596f9a1a8 *** empty log message ***
claus
parents: 38
diff changeset
  1957
	if (__isString(aNameOrNumber)) {
524
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  1958
	    servent = getservbyname((char *) __stringVal(aNameOrNumber), "tcp");
42
506596f9a1a8 *** empty log message ***
claus
parents: 38
diff changeset
  1959
	    if (servent == NULL) {
524
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  1960
		servent = getservbyname((char *) __stringVal(aNameOrNumber), "udp");
42
506596f9a1a8 *** empty log message ***
claus
parents: 38
diff changeset
  1961
		if (servent == NULL) {
506596f9a1a8 *** empty log message ***
claus
parents: 38
diff changeset
  1962
		    RETURN ( nil );
506596f9a1a8 *** empty log message ***
claus
parents: 38
diff changeset
  1963
		}
506596f9a1a8 *** empty log message ***
claus
parents: 38
diff changeset
  1964
	    }
506596f9a1a8 *** empty log message ***
claus
parents: 38
diff changeset
  1965
	}
0
1cf8d1747859 Initial revision
claus
parents:
diff changeset
  1966
    }
1cf8d1747859 Initial revision
claus
parents:
diff changeset
  1967
    if (servent) {
448
2203a4bb620d removed all COMMA_CON / CON_COMMA uses
Claus Gittinger <cg@exept.de>
parents: 444
diff changeset
  1968
	RETURN ( __MKSTRING(servent->s_proto) );
0
1cf8d1747859 Initial revision
claus
parents:
diff changeset
  1969
    }
418
317e55c6c281 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 403
diff changeset
  1970
#endif
0
1cf8d1747859 Initial revision
claus
parents:
diff changeset
  1971
    RETURN ( nil );
1cf8d1747859 Initial revision
claus
parents:
diff changeset
  1972
%}
28
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  1973
    "
74
claus
parents: 71
diff changeset
  1974
     Socket protocolOfService:'finger' 
claus
parents: 71
diff changeset
  1975
     Socket protocolOfService:'nntp'  
28
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  1976
     Socket protocolOfService:'xxx'
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  1977
     Socket protocolOfService:79
74
claus
parents: 71
diff changeset
  1978
     Socket protocolOfService:'snmp' 
28
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  1979
    "
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  1980
!
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  1981
532
f997c3873602 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 531
diff changeset
  1982
supportedProtocolFamilies
f997c3873602 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 531
diff changeset
  1983
    "return a collection of supported protocol families.
f997c3873602 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 531
diff changeset
  1984
     This list specifies what the Socket class supports -
f997c3873602 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 531
diff changeset
  1985
     socket creation may still fail, if your system was built
f997c3873602 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 531
diff changeset
  1986
     without it."
f997c3873602 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 531
diff changeset
  1987
f997c3873602 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 531
diff changeset
  1988
    |list hasIt|
f997c3873602 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 531
diff changeset
  1989
f997c3873602 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 531
diff changeset
  1990
    list := OrderedCollection new.
f997c3873602 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 531
diff changeset
  1991
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
#ifdef AF_INET
812
c8101ea70e6c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 811
diff changeset
  1994
%}.
c8101ea70e6c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 811
diff changeset
  1995
    list add:#inet.
c8101ea70e6c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 811
diff changeset
  1996
%{
532
f997c3873602 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 531
diff changeset
  1997
#endif
f997c3873602 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 531
diff changeset
  1998
%}.
f997c3873602 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 531
diff changeset
  1999
f997c3873602 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 531
diff changeset
  2000
%{
f997c3873602 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 531
diff changeset
  2001
#ifdef AF_UNIX
812
c8101ea70e6c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 811
diff changeset
  2002
%}.
c8101ea70e6c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 811
diff changeset
  2003
    list add:#unix.
c8101ea70e6c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 811
diff changeset
  2004
%{
532
f997c3873602 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 531
diff changeset
  2005
#endif
f997c3873602 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 531
diff changeset
  2006
%}.
f997c3873602 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 531
diff changeset
  2007
f997c3873602 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 531
diff changeset
  2008
%{
f997c3873602 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 531
diff changeset
  2009
#ifdef AF_INET6
812
c8101ea70e6c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 811
diff changeset
  2010
%}.
c8101ea70e6c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 811
diff changeset
  2011
    list add:#inet6.   "/ internet v6
c8101ea70e6c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 811
diff changeset
  2012
%{
532
f997c3873602 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 531
diff changeset
  2013
#endif
f997c3873602 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 531
diff changeset
  2014
%}.
f997c3873602 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 531
diff changeset
  2015
f997c3873602 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 531
diff changeset
  2016
%{
f997c3873602 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 531
diff changeset
  2017
#ifdef AF_APPLETALK
812
c8101ea70e6c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 811
diff changeset
  2018
%}.
c8101ea70e6c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 811
diff changeset
  2019
    list add:#appletalk.  "/ appletalk
c8101ea70e6c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 811
diff changeset
  2020
%{
532
f997c3873602 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 531
diff changeset
  2021
#endif
f997c3873602 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 531
diff changeset
  2022
%}.
f997c3873602 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 531
diff changeset
  2023
f997c3873602 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 531
diff changeset
  2024
%{
f997c3873602 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 531
diff changeset
  2025
#ifdef AF_DECnet
812
c8101ea70e6c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 811
diff changeset
  2026
%}.
c8101ea70e6c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 811
diff changeset
  2027
    list add:#decnet.  "/ dec net
c8101ea70e6c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 811
diff changeset
  2028
%{
532
f997c3873602 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 531
diff changeset
  2029
#endif
f997c3873602 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 531
diff changeset
  2030
%}.
f997c3873602 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 531
diff changeset
  2031
f997c3873602 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 531
diff changeset
  2032
%{
f997c3873602 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 531
diff changeset
  2033
#ifdef AF_NS
812
c8101ea70e6c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 811
diff changeset
  2034
%}.
c8101ea70e6c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 811
diff changeset
  2035
    list add:#xns.     "/ Xerox XNS
c8101ea70e6c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 811
diff changeset
  2036
%{
532
f997c3873602 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 531
diff changeset
  2037
#endif
f997c3873602 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 531
diff changeset
  2038
%}.
f997c3873602 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 531
diff changeset
  2039
f997c3873602 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 531
diff changeset
  2040
%{
812
c8101ea70e6c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 811
diff changeset
  2041
#ifdef AF_X25
c8101ea70e6c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 811
diff changeset
  2042
%}.
c8101ea70e6c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 811
diff changeset
  2043
    list add:#x25.     "/ X.25
c8101ea70e6c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 811
diff changeset
  2044
%{
532
f997c3873602 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 531
diff changeset
  2045
#endif
f997c3873602 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 531
diff changeset
  2046
%}.
f997c3873602 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 531
diff changeset
  2047
f997c3873602 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 531
diff changeset
  2048
%{
f997c3873602 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 531
diff changeset
  2049
#ifdef AF_SNA
812
c8101ea70e6c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 811
diff changeset
  2050
%}.
c8101ea70e6c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 811
diff changeset
  2051
    list add:#sna.     "/ IBM SNA
c8101ea70e6c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 811
diff changeset
  2052
%{
532
f997c3873602 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 531
diff changeset
  2053
#endif
f997c3873602 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 531
diff changeset
  2054
%}.
f997c3873602 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 531
diff changeset
  2055
f997c3873602 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 531
diff changeset
  2056
%{
f997c3873602 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 531
diff changeset
  2057
#ifdef AF_RAW
812
c8101ea70e6c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 811
diff changeset
  2058
%}.
c8101ea70e6c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 811
diff changeset
  2059
    list add:#raw.     "/ ?? RAW packets
c8101ea70e6c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 811
diff changeset
  2060
%{
532
f997c3873602 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 531
diff changeset
  2061
#endif
f997c3873602 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 531
diff changeset
  2062
%}.
f997c3873602 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 531
diff changeset
  2063
f997c3873602 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 531
diff changeset
  2064
%{
f997c3873602 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 531
diff changeset
  2065
#ifdef AF_ISO
812
c8101ea70e6c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 811
diff changeset
  2066
%}.
c8101ea70e6c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 811
diff changeset
  2067
    list add:#iso.     "/ ??
c8101ea70e6c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 811
diff changeset
  2068
%{
532
f997c3873602 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 531
diff changeset
  2069
#endif
f997c3873602 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 531
diff changeset
  2070
%}.
f997c3873602 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 531
diff changeset
  2071
f997c3873602 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 531
diff changeset
  2072
%{
f997c3873602 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 531
diff changeset
  2073
#ifdef AF_NETBIOS
812
c8101ea70e6c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 811
diff changeset
  2074
%}.
c8101ea70e6c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 811
diff changeset
  2075
    list add:#netbios. "/ ??
c8101ea70e6c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 811
diff changeset
  2076
%{
532
f997c3873602 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 531
diff changeset
  2077
#endif
f997c3873602 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 531
diff changeset
  2078
%}.
f997c3873602 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 531
diff changeset
  2079
f997c3873602 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 531
diff changeset
  2080
%{
f997c3873602 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 531
diff changeset
  2081
#ifdef AF_IPX
812
c8101ea70e6c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 811
diff changeset
  2082
%}.
c8101ea70e6c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 811
diff changeset
  2083
    list add:#ipx.     "/ Novell IPX
c8101ea70e6c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 811
diff changeset
  2084
%{
532
f997c3873602 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 531
diff changeset
  2085
#endif
f997c3873602 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 531
diff changeset
  2086
%}.
f997c3873602 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 531
diff changeset
  2087
f997c3873602 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 531
diff changeset
  2088
%{
f997c3873602 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 531
diff changeset
  2089
#ifdef AF_AX25
812
c8101ea70e6c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 811
diff changeset
  2090
%}.
c8101ea70e6c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 811
diff changeset
  2091
    list add:#ax25.    "/ Amateur Radio AX.25
c8101ea70e6c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 811
diff changeset
  2092
%{
532
f997c3873602 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 531
diff changeset
  2093
#endif
f997c3873602 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 531
diff changeset
  2094
%}.
f997c3873602 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 531
diff changeset
  2095
f997c3873602 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 531
diff changeset
  2096
%{
f997c3873602 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 531
diff changeset
  2097
#ifdef AF_NETROM
812
c8101ea70e6c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 811
diff changeset
  2098
%}.
c8101ea70e6c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 811
diff changeset
  2099
    list add:#netrom.  "/ Amateur Radio NET/ROM
c8101ea70e6c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 811
diff changeset
  2100
%{
532
f997c3873602 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 531
diff changeset
  2101
#endif
f997c3873602 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 531
diff changeset
  2102
%}.
f997c3873602 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 531
diff changeset
  2103
f997c3873602 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 531
diff changeset
  2104
%{
f997c3873602 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 531
diff changeset
  2105
#ifdef AF_BRIDGE
812
c8101ea70e6c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 811
diff changeset
  2106
%}.
c8101ea70e6c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 811
diff changeset
  2107
    list add:#bridge.  "/ multiprotocol bridge
c8101ea70e6c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 811
diff changeset
  2108
%{
532
f997c3873602 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 531
diff changeset
  2109
#endif
f997c3873602 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 531
diff changeset
  2110
%}.
f997c3873602 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 531
diff changeset
  2111
571
191b37534643 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 563
diff changeset
  2112
%{
191b37534643 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 563
diff changeset
  2113
#ifdef AF_BSC
812
c8101ea70e6c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 811
diff changeset
  2114
%}.
c8101ea70e6c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 811
diff changeset
  2115
    list add:#bsc.     "/ BISYNC 2780/3780
c8101ea70e6c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 811
diff changeset
  2116
%{
571
191b37534643 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 563
diff changeset
  2117
#endif
191b37534643 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 563
diff changeset
  2118
%}.
812
c8101ea70e6c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 811
diff changeset
  2119
c8101ea70e6c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 811
diff changeset
  2120
%{
c8101ea70e6c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 811
diff changeset
  2121
#ifdef AF_ROSE
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
    list add:#rose.    "/ Amateur Radio X.25 PLP
c8101ea70e6c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 811
diff changeset
  2124
%{
c8101ea70e6c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 811
diff changeset
  2125
#endif
c8101ea70e6c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 811
diff changeset
  2126
%}.
571
191b37534643 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 563
diff changeset
  2127
869
a6e5cbe9f558 preps for AF_IRDA
Claus Gittinger <cg@exept.de>
parents: 867
diff changeset
  2128
%{
a6e5cbe9f558 preps for AF_IRDA
Claus Gittinger <cg@exept.de>
parents: 867
diff changeset
  2129
#ifdef AF_IRDA
a6e5cbe9f558 preps for AF_IRDA
Claus Gittinger <cg@exept.de>
parents: 867
diff changeset
  2130
%}.
a6e5cbe9f558 preps for AF_IRDA
Claus Gittinger <cg@exept.de>
parents: 867
diff changeset
  2131
    list add:#irda.  "/ infrared
a6e5cbe9f558 preps for AF_IRDA
Claus Gittinger <cg@exept.de>
parents: 867
diff changeset
  2132
%{
a6e5cbe9f558 preps for AF_IRDA
Claus Gittinger <cg@exept.de>
parents: 867
diff changeset
  2133
#endif
a6e5cbe9f558 preps for AF_IRDA
Claus Gittinger <cg@exept.de>
parents: 867
diff changeset
  2134
%}.
a6e5cbe9f558 preps for AF_IRDA
Claus Gittinger <cg@exept.de>
parents: 867
diff changeset
  2135
571
191b37534643 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 563
diff changeset
  2136
532
f997c3873602 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 531
diff changeset
  2137
    ^ list
f997c3873602 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 531
diff changeset
  2138
f997c3873602 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 531
diff changeset
  2139
    "
f997c3873602 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 531
diff changeset
  2140
     Socket supportedProtocolFamilies
f997c3873602 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 531
diff changeset
  2141
    "
559
61012867ebed cleanup if #connect is interrupted
Claus Gittinger <cg@exept.de>
parents: 551
diff changeset
  2142
!
61012867ebed cleanup if #connect is interrupted
Claus Gittinger <cg@exept.de>
parents: 551
diff changeset
  2143
61012867ebed cleanup if #connect is interrupted
Claus Gittinger <cg@exept.de>
parents: 551
diff changeset
  2144
typeOfProtocol:aProtocol
61012867ebed cleanup if #connect is interrupted
Claus Gittinger <cg@exept.de>
parents: 551
diff changeset
  2145
    "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
  2146
     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
  2147
61012867ebed cleanup if #connect is interrupted
Claus Gittinger <cg@exept.de>
parents: 551
diff changeset
  2148
    (aProtocol = 'tcp') ifTrue:[^ #stream].
61012867ebed cleanup if #connect is interrupted
Claus Gittinger <cg@exept.de>
parents: 551
diff changeset
  2149
    (aProtocol = 'udp') ifTrue:[^ #datagram].
61012867ebed cleanup if #connect is interrupted
Claus Gittinger <cg@exept.de>
parents: 551
diff changeset
  2150
    (aProtocol = 'ip')  ifTrue:[^ #raw].
61012867ebed cleanup if #connect is interrupted
Claus Gittinger <cg@exept.de>
parents: 551
diff changeset
  2151
    "
61012867ebed cleanup if #connect is interrupted
Claus Gittinger <cg@exept.de>
parents: 551
diff changeset
  2152
     unix domain
61012867ebed cleanup if #connect is interrupted
Claus Gittinger <cg@exept.de>
parents: 551
diff changeset
  2153
    "
61012867ebed cleanup if #connect is interrupted
Claus Gittinger <cg@exept.de>
parents: 551
diff changeset
  2154
    (aProtocol = 'ud')  ifTrue:[^ #stream].
61012867ebed cleanup if #connect is interrupted
Claus Gittinger <cg@exept.de>
parents: 551
diff changeset
  2155
    "
61012867ebed cleanup if #connect is interrupted
Claus Gittinger <cg@exept.de>
parents: 551
diff changeset
  2156
     add x25 stuff (if any) here ...
61012867ebed cleanup if #connect is interrupted
Claus Gittinger <cg@exept.de>
parents: 551
diff changeset
  2157
    "
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 appletalk 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 other 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
    ^ nil
61012867ebed cleanup if #connect is interrupted
Claus Gittinger <cg@exept.de>
parents: 551
diff changeset
  2165
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
     Socket typeOfProtocol:'tcp'
61012867ebed cleanup if #connect is interrupted
Claus Gittinger <cg@exept.de>
parents: 551
diff changeset
  2168
     Socket typeOfProtocol:'ucp'
61012867ebed cleanup if #connect is interrupted
Claus Gittinger <cg@exept.de>
parents: 551
diff changeset
  2169
     Socket typeOfProtocol:(Socket protocolOfService:'nntp')
61012867ebed cleanup if #connect is interrupted
Claus Gittinger <cg@exept.de>
parents: 551
diff changeset
  2170
     Socket typeOfProtocol:(Socket protocolOfService:'echo')
61012867ebed cleanup if #connect is interrupted
Claus Gittinger <cg@exept.de>
parents: 551
diff changeset
  2171
    "
28
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  2172
! !
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  2173
867
56ca0cc52fa7 category renamining
Claus Gittinger <cg@exept.de>
parents: 859
diff changeset
  2174
!Socket methodsFor:'Compatibility - ST80'!
28
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  2175
887
2b2dc6b59b5a more VW compatibility
Claus Gittinger <cg@exept.de>
parents: 876
diff changeset
  2176
acceptNonBlock
2b2dc6b59b5a more VW compatibility
Claus Gittinger <cg@exept.de>
parents: 876
diff changeset
  2177
    ^ self accept
2b2dc6b59b5a more VW compatibility
Claus Gittinger <cg@exept.de>
parents: 876
diff changeset
  2178
!
2b2dc6b59b5a more VW compatibility
Claus Gittinger <cg@exept.de>
parents: 876
diff changeset
  2179
870
452fc695de34 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 869
diff changeset
  2180
connectTo:aSocketAddress
452fc695de34 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 869
diff changeset
  2181
    ^ self connectTo:aSocketAddress hostAddress port:aSocketAddress port
452fc695de34 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 869
diff changeset
  2182
!
452fc695de34 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 869
diff changeset
  2183
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  2184
errorReporter
781
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  2185
    "ST-80 mimicry."
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  2186
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  2187
    ^ self
28
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  2188
!
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  2189
887
2b2dc6b59b5a more VW compatibility
Claus Gittinger <cg@exept.de>
parents: 876
diff changeset
  2190
ioConnection 
2b2dc6b59b5a more VW compatibility
Claus Gittinger <cg@exept.de>
parents: 876
diff changeset
  2191
    ^ self
2b2dc6b59b5a more VW compatibility
Claus Gittinger <cg@exept.de>
parents: 876
diff changeset
  2192
!
2b2dc6b59b5a more VW compatibility
Claus Gittinger <cg@exept.de>
parents: 876
diff changeset
  2193
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  2194
notReadySignal
781
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  2195
    "ST-80 mimicry.
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  2196
     for now - this is not yet raised"
71
claus
parents: 63
diff changeset
  2197
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  2198
    ^ Signal new
486
ed4e215e83ef ST-80 mimicry
Claus Gittinger <cg@exept.de>
parents: 470
diff changeset
  2199
!
ed4e215e83ef ST-80 mimicry
Claus Gittinger <cg@exept.de>
parents: 470
diff changeset
  2200
576
13acab81fad0 more ST80 compatibility
ca
parents: 572
diff changeset
  2201
readAppendStream
781
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  2202
    "ST-80 mimicry.
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  2203
     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
  2204
     ST-80 code therefore uses 'Socket readWriteStream' to access
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  2205
     the actual stream. 
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  2206
     In ST/X, sockets inherit from stream, so
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  2207
     this method returns the receiver, for transparency"
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  2208
576
13acab81fad0 more ST80 compatibility
ca
parents: 572
diff changeset
  2209
    ^ self
13acab81fad0 more ST80 compatibility
ca
parents: 572
diff changeset
  2210
!
13acab81fad0 more ST80 compatibility
ca
parents: 572
diff changeset
  2211
486
ed4e215e83ef ST-80 mimicry
Claus Gittinger <cg@exept.de>
parents: 470
diff changeset
  2212
readStream
ed4e215e83ef ST-80 mimicry
Claus Gittinger <cg@exept.de>
parents: 470
diff changeset
  2213
    "ST-80 mimicry.
ed4e215e83ef ST-80 mimicry
Claus Gittinger <cg@exept.de>
parents: 470
diff changeset
  2214
     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
  2215
     ST-80 code therefore uses 'Socket readStream' to access
781
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  2216
     the actual stream. 
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  2217
     In ST/X, sockets inherit from stream, so
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  2218
     this method returns the receiver, for transparency"
486
ed4e215e83ef ST-80 mimicry
Claus Gittinger <cg@exept.de>
parents: 470
diff changeset
  2219
ed4e215e83ef ST-80 mimicry
Claus Gittinger <cg@exept.de>
parents: 470
diff changeset
  2220
    ^ self
ed4e215e83ef ST-80 mimicry
Claus Gittinger <cg@exept.de>
parents: 470
diff changeset
  2221
ed4e215e83ef ST-80 mimicry
Claus Gittinger <cg@exept.de>
parents: 470
diff changeset
  2222
    "Created: 24.1.1997 / 23:52:57 / cg"
ed4e215e83ef ST-80 mimicry
Claus Gittinger <cg@exept.de>
parents: 470
diff changeset
  2223
!
ed4e215e83ef ST-80 mimicry
Claus Gittinger <cg@exept.de>
parents: 470
diff changeset
  2224
576
13acab81fad0 more ST80 compatibility
ca
parents: 572
diff changeset
  2225
shutdown:how
13acab81fad0 more ST80 compatibility
ca
parents: 572
diff changeset
  2226
    "ST-80 compatibility"
13acab81fad0 more ST80 compatibility
ca
parents: 572
diff changeset
  2227
13acab81fad0 more ST80 compatibility
ca
parents: 572
diff changeset
  2228
    self shutDown
13acab81fad0 more ST80 compatibility
ca
parents: 572
diff changeset
  2229
!
13acab81fad0 more ST80 compatibility
ca
parents: 572
diff changeset
  2230
486
ed4e215e83ef ST-80 mimicry
Claus Gittinger <cg@exept.de>
parents: 470
diff changeset
  2231
writeStream
ed4e215e83ef ST-80 mimicry
Claus Gittinger <cg@exept.de>
parents: 470
diff changeset
  2232
    "ST-80 mimicry.
ed4e215e83ef ST-80 mimicry
Claus Gittinger <cg@exept.de>
parents: 470
diff changeset
  2233
     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
  2234
     ST-80 code therefore uses 'Socket writeStream' to access
781
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  2235
     the actual stream. 
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  2236
     In ST/X, sockets inherit from stream, so
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  2237
     this method returns the receiver, for transparency"
486
ed4e215e83ef ST-80 mimicry
Claus Gittinger <cg@exept.de>
parents: 470
diff changeset
  2238
ed4e215e83ef ST-80 mimicry
Claus Gittinger <cg@exept.de>
parents: 470
diff changeset
  2239
    ^ self
ed4e215e83ef ST-80 mimicry
Claus Gittinger <cg@exept.de>
parents: 470
diff changeset
  2240
ed4e215e83ef ST-80 mimicry
Claus Gittinger <cg@exept.de>
parents: 470
diff changeset
  2241
    "Created: 24.1.1997 / 10:34:35 / cg"
ed4e215e83ef ST-80 mimicry
Claus Gittinger <cg@exept.de>
parents: 470
diff changeset
  2242
    "Modified: 24.1.1997 / 23:52:52 / cg"
71
claus
parents: 63
diff changeset
  2243
! !
claus
parents: 63
diff changeset
  2244
827
006dc4fe9dbd *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 823
diff changeset
  2245
!Socket methodsFor:'Compatibility - Squeak'!
771
74abb04ef57c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 752
diff changeset
  2246
74abb04ef57c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 752
diff changeset
  2247
peerName
74abb04ef57c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 752
diff changeset
  2248
    "return my peer (i.e. ipAddr + port);
74abb04ef57c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 752
diff changeset
  2249
     May return nil if not yet setup completely."
74abb04ef57c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 752
diff changeset
  2250
74abb04ef57c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 752
diff changeset
  2251
    ^ self getPeer
74abb04ef57c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 752
diff changeset
  2252
! !
74abb04ef57c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 752
diff changeset
  2253
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  2254
!Socket methodsFor:'datagram transmission'!
28
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  2255
915
3dc0e3cd838a added interface to send() and recv()
Claus Gittinger <cg@exept.de>
parents: 898
diff changeset
  2256
receiveBuffer:aDataBuffer start:startIndex for:nBytes
3dc0e3cd838a added interface to send() and recv()
Claus Gittinger <cg@exept.de>
parents: 898
diff changeset
  2257
    "receive data
3dc0e3cd838a added interface to send() and recv()
Claus Gittinger <cg@exept.de>
parents: 898
diff changeset
  2258
     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
  2259
     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
  2260
     instance variable.
3dc0e3cd838a added interface to send() and recv()
Claus Gittinger <cg@exept.de>
parents: 898
diff changeset
  2261
     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
  2262
     receiving, using #readWait or #readWaitWithTimeout:."
3dc0e3cd838a added interface to send() and recv()
Claus Gittinger <cg@exept.de>
parents: 898
diff changeset
  2263
3dc0e3cd838a added interface to send() and recv()
Claus Gittinger <cg@exept.de>
parents: 898
diff changeset
  2264
3dc0e3cd838a added interface to send() and recv()
Claus Gittinger <cg@exept.de>
parents: 898
diff changeset
  2265
    |nReceived|
3dc0e3cd838a added interface to send() and recv()
Claus Gittinger <cg@exept.de>
parents: 898
diff changeset
  2266
3dc0e3cd838a added interface to send() and recv()
Claus Gittinger <cg@exept.de>
parents: 898
diff changeset
  2267
%{
3dc0e3cd838a added interface to send() and recv()
Claus Gittinger <cg@exept.de>
parents: 898
diff changeset
  2268
#ifndef NO_SOCKET
3dc0e3cd838a added interface to send() and recv()
Claus Gittinger <cg@exept.de>
parents: 898
diff changeset
  2269
    OBJ oClass, myDomain;
3dc0e3cd838a added interface to send() and recv()
Claus Gittinger <cg@exept.de>
parents: 898
diff changeset
  2270
    OBJ fp = __INST(filePointer);
3dc0e3cd838a added interface to send() and recv()
Claus Gittinger <cg@exept.de>
parents: 898
diff changeset
  2271
    int nInstVars, nInstBytes, objSize;
3dc0e3cd838a added interface to send() and recv()
Claus Gittinger <cg@exept.de>
parents: 898
diff changeset
  2272
    int sock;
3dc0e3cd838a added interface to send() and recv()
Claus Gittinger <cg@exept.de>
parents: 898
diff changeset
  2273
    int n;
3dc0e3cd838a added interface to send() and recv()
Claus Gittinger <cg@exept.de>
parents: 898
diff changeset
  2274
    char *cp;
3dc0e3cd838a added interface to send() and recv()
Claus Gittinger <cg@exept.de>
parents: 898
diff changeset
  2275
    int flags = 0;
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
    if (fp != nil) {
1009
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2278
	sock = fileno(__FILEVal(fp));
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2279
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2280
	oClass = __Class(aDataBuffer);
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2281
	switch (__intVal(__ClassInstPtr(oClass)->c_flags) & ARRAYMASK) {
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2282
	    case BYTEARRAY:
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2283
	    case WORDARRAY:
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2284
	    case SWORDARRAY:
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2285
	    case LONGARRAY:
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2286
	    case SLONGARRAY:
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2287
	    case FLOATARRAY:
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2288
	    case DOUBLEARRAY:
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2289
		break;
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2290
	    default:
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2291
		goto bad;
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
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2294
	nInstVars = __intVal(__ClassInstPtr(oClass)->c_ninstvars);
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2295
	nInstBytes = OHDR_SIZE + nInstVars * sizeof(OBJ);
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2296
	objSize = _Size(aDataBuffer) - nInstBytes;
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2297
	cp = (char *)__InstPtr(aDataBuffer) + nInstBytes;
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2298
	if (__isSmallInteger(startIndex)) {
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2299
	    cp += __intVal(startIndex);
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2300
	    objSize -= __intVal(startIndex);
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2301
	}
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2302
	if (__isSmallInteger(nBytes)) {
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2303
	    if (__intVal(nBytes) < objSize) {
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2304
		objSize = __intVal(nBytes);
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
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2308
	__BEGIN_INTERRUPTABLE__
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2309
	do {
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2310
	    n = recv(sock, cp, objSize, flags);
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2311
	} while ((n < 0) && (errno == EINTR));
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2312
	__END_INTERRUPTABLE__
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2313
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2314
	if (n < 0) {
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2315
	    __INST(lastErrorNumber) = __MKSMALLINT(errno);
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2316
	}
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2317
	nReceived = __MKSMALLINT(n);
915
3dc0e3cd838a added interface to send() and recv()
Claus Gittinger <cg@exept.de>
parents: 898
diff changeset
  2318
    }
3dc0e3cd838a added interface to send() and recv()
Claus Gittinger <cg@exept.de>
parents: 898
diff changeset
  2319
#endif
3dc0e3cd838a added interface to send() and recv()
Claus Gittinger <cg@exept.de>
parents: 898
diff changeset
  2320
bad: ;
3dc0e3cd838a added interface to send() and recv()
Claus Gittinger <cg@exept.de>
parents: 898
diff changeset
  2321
%}.
3dc0e3cd838a added interface to send() and recv()
Claus Gittinger <cg@exept.de>
parents: 898
diff changeset
  2322
    nReceived notNil ifTrue:[
1009
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2323
	nReceived < 0 ifTrue:[
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2324
	    'Socket [warning]: ' infoPrint.
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2325
	    (OperatingSystem errorTextForNumber:lastErrorNumber) infoPrintCR.
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
	^ nReceived
915
3dc0e3cd838a added interface to send() and recv()
Claus Gittinger <cg@exept.de>
parents: 898
diff changeset
  2328
    ].
3dc0e3cd838a added interface to send() and recv()
Claus Gittinger <cg@exept.de>
parents: 898
diff changeset
  2329
    "
3dc0e3cd838a added interface to send() and recv()
Claus Gittinger <cg@exept.de>
parents: 898
diff changeset
  2330
     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
  2331
     (i.e. not ByteArray-like), 
3dc0e3cd838a added interface to send() and recv()
Claus Gittinger <cg@exept.de>
parents: 898
diff changeset
  2332
     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
  2333
     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
  2334
    "
3dc0e3cd838a added interface to send() and recv()
Claus Gittinger <cg@exept.de>
parents: 898
diff changeset
  2335
    self primitiveFailed
3dc0e3cd838a added interface to send() and recv()
Claus Gittinger <cg@exept.de>
parents: 898
diff changeset
  2336
!
3dc0e3cd838a added interface to send() and recv()
Claus Gittinger <cg@exept.de>
parents: 898
diff changeset
  2337
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  2338
receiveFrom:anAddressBuffer buffer:aDataBuffer
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  2339
    "receive datagramm data - put address of originating host into
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  2340
     anAddressBuffer, data into aBuffer. 
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  2341
     Both must be ByteArray-like. The addressBuffer must
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  2342
     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
  2343
     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
  2344
     On error, the unix error code is left in the lastErrorNumber
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  2345
     instance variable."
28
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  2346
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  2347
    ^ 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
  2348
!
7d016cc30052 fixed & moved pingWalk from SNMPSession to here;
Claus Gittinger <cg@exept.de>
parents: 98
diff changeset
  2349
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  2350
receiveFrom:anAddressBuffer buffer:aDataBuffer start:startIndex for:nBytes
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  2351
    "receive datagramm data - put address of originating host into
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  2352
     anAddressBuffer, data into aBuffer. For ST-80 compatibility,
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  2353
     the addressBuffer may be a non-ByteArray; then, it must understand
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  2354
     the addressBytes-message (i.e. be a SocketAddress instance).
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  2355
     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
  2356
     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
  2357
     instance variable.
b8042ff0f82c udp receive: translate received address according to the domain
Claus Gittinger <cg@exept.de>
parents: 511
diff changeset
  2358
     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
  2359
     receiving, using #readWait or #readWaitWithTimeout:."
b8042ff0f82c udp receive: translate received address according to the domain
Claus Gittinger <cg@exept.de>
parents: 511
diff changeset
  2360
1009
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2361
    |addrBytes addrLen nReceived addrPort|
28
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  2362
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  2363
    addrBytes := ByteArray new:100.
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  2364
%{
418
317e55c6c281 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 403
diff changeset
  2365
#ifndef NO_SOCKET
513
b8042ff0f82c udp receive: translate received address according to the domain
Claus Gittinger <cg@exept.de>
parents: 511
diff changeset
  2366
    OBJ oClass, myDomain;
217
fcfbc9f71048 underscore cleanup
Claus Gittinger <cg@exept.de>
parents: 209
diff changeset
  2367
    OBJ fp = __INST(filePointer);
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  2368
    int nInstVars, nInstBytes, objSize;
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  2369
    int sock;
819
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
  2370
    union sockaddr_u sa;
1009
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2371
    int alen = 0;
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2372
    int n, offs, sIdx;
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  2373
    char *cp;
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  2374
    int flags = 0;
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  2375
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  2376
    if (fp != nil) {
1009
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2377
	sock = fileno(__FILEVal(fp));
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2378
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2379
	oClass = __Class(aDataBuffer);
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2380
	offs = 0;
1010
603216bbf89a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1009
diff changeset
  2381
	sIdx = 0;
603216bbf89a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1009
diff changeset
  2382
	if (__isSmallInteger(startIndex)) {
603216bbf89a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1009
diff changeset
  2383
	    sIdx = __intVal(startIndex) - 1;
603216bbf89a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1009
diff changeset
  2384
	}
1009
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2385
	switch (__intVal(__ClassInstPtr(oClass)->c_flags) & ARRAYMASK) {
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2386
	    case BYTEARRAY:
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2387
		offs = sIdx;
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2388
		break;
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2389
	    case WORDARRAY:
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2390
	    case SWORDARRAY:
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2391
		offs = sIdx * 2;
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2392
		break;
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2393
	    case LONGARRAY:
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2394
	    case SLONGARRAY:
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2395
		offs = sIdx * 4;
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2396
		break;
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2397
	    case LONGLONGARRAY:
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2398
	    case SLONGLONGARRAY:
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2399
		offs = sIdx * 8;
1003
0157b8af9a1e oops - datagram receive was wrong (startIndex handling)
Claus Gittinger <cg@exept.de>
parents: 969
diff changeset
  2400
# ifdef __NEED_LONGLONG_ALIGN
1009
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2401
		offs += 4;
1003
0157b8af9a1e oops - datagram receive was wrong (startIndex handling)
Claus Gittinger <cg@exept.de>
parents: 969
diff changeset
  2402
# endif
1010
603216bbf89a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1009
diff changeset
  2403
		break;
1009
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2404
	    case FLOATARRAY:
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2405
		offs = sIdx * sizeof(float);
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2406
		break;
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2407
	    case DOUBLEARRAY:
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2408
		offs = sIdx * sizeof(double);
1003
0157b8af9a1e oops - datagram receive was wrong (startIndex handling)
Claus Gittinger <cg@exept.de>
parents: 969
diff changeset
  2409
# ifdef __NEED_DOUBLE_ALIGN
1009
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2410
		offs += 4;
1003
0157b8af9a1e oops - datagram receive was wrong (startIndex handling)
Claus Gittinger <cg@exept.de>
parents: 969
diff changeset
  2411
# endif
1009
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2412
		break;
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2413
	    default:
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2414
		goto bad;
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2415
	}
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2416
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2417
	nInstVars = __intVal(__ClassInstPtr(oClass)->c_ninstvars);
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2418
	nInstBytes = OHDR_SIZE + nInstVars * sizeof(OBJ);
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2419
	objSize = _Size(aDataBuffer) - nInstBytes;
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2420
	objSize -= offs;
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2421
	if (__isSmallInteger(nBytes)) {
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2422
	    if (__intVal(nBytes) < objSize) {
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2423
		objSize = __intVal(nBytes);
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2424
	    }
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2425
	}
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2426
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2427
	__BEGIN_INTERRUPTABLE__
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2428
	do {
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2429
	    cp = (char *)__InstPtr(aDataBuffer) + nInstBytes + offs;
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2430
	    alen = sizeof(sa);
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2431
	    n = recvfrom(sock, cp, objSize, flags, (struct sockaddr *) &sa, &alen);
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2432
	} while ((n < 0) && (errno == EINTR));
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2433
	__END_INTERRUPTABLE__
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2434
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2435
	if (n >= 0) {
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2436
	    if (__isNonNilObject(addrBytes)) {
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2437
		oClass = __qClass(addrBytes);
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2438
		if ((__intVal(__ClassInstPtr(oClass)->c_flags) & ARRAYMASK) != BYTEARRAY) 
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2439
		    goto bad;
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2440
		nInstVars = __intVal(__ClassInstPtr(oClass)->c_ninstvars);
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2441
		nInstBytes = OHDR_SIZE + (nInstVars * sizeof(OBJ));
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2442
		objSize = __qSize(addrBytes) - nInstBytes;
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2443
		cp = (char *)__InstPtr(addrBytes) + nInstBytes;
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2444
		if (objSize < alen) 
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2445
		    goto bad;
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2446
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2447
		myDomain = __INST(domain);
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2448
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2449
		/*
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2450
		 * extract the datagrams address
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2451
		 */
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2452
		if (0) {
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2453
		    /* for else below */
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2454
		}
653
219b89f62113 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 650
diff changeset
  2455
# ifdef AF_INET
1009
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2456
		else if (myDomain == @symbol(inet)) {
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2457
		    if (objSize < 4) 
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
#  ifdef DGRAM_DEBUG
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2460
		    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
  2461
#  endif /* DGRAM_DEBUG */
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2462
		    addrPort = __MKSMALLINT( ntohs(sa.in.sin_port) );
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2463
		    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
  2464
		    cp[0] = (sa.in.sin_addr.s_addr >> 24) & 0xFF;
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2465
		    cp[1] = (sa.in.sin_addr.s_addr >> 16) & 0xFF;
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2466
		    cp[2] = (sa.in.sin_addr.s_addr >> 8) & 0xFF;
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2467
		    cp[3] = (sa.in.sin_addr.s_addr >> 0) & 0xFF;
1010
603216bbf89a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1009
diff changeset
  2468
		    alen = 4;
1009
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2469
#  ifdef DGRAM_DEBUG
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2470
		    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
  2471
#  endif /* DGRAM_DEBUG */
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2472
		}
653
219b89f62113 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 650
diff changeset
  2473
# endif /* AF_INET */
219b89f62113 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 650
diff changeset
  2474
812
c8101ea70e6c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 811
diff changeset
  2475
# ifdef AF_INET6
1009
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2476
		else if (myDomain == @symbol(inet6)) {
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2477
		    if (objSize < sizeof(sa.in6.sin6_addr.s6_addr)) 
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2478
			goto bad;
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2479
		    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
  2480
		    alen = sizeof(sa.in6.sin6_addr.s6_addr);
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2481
		}
812
c8101ea70e6c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 811
diff changeset
  2482
# endif /* AF_INET6 */
c8101ea70e6c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 811
diff changeset
  2483
c8101ea70e6c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 811
diff changeset
  2484
# ifdef AF_APPLETALK
1009
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2485
		else if (myDomain == @symbol(appletalk)) {
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2486
		    if (objSize < 3) 
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2487
			goto bad;
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2488
		    cp[0] = (sa.at.sat_addr.s_net >> 8) & 0xFF;
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2489
		    cp[1] = (sa.at.sat_addr.s_net) & 0xFF;
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2490
		    cp[2] = (sa.at.sat_addr.s_node) & 0xFF;
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2491
		    alen = 3;
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2492
		}
812
c8101ea70e6c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 811
diff changeset
  2493
# endif /* AF_APPLETALK */
c8101ea70e6c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 811
diff changeset
  2494
1009
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2495
		/*
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2496
		 * XXXX add addressing stuff for other domains here ...
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2497
		 */
513
b8042ff0f82c udp receive: translate received address according to the domain
Claus Gittinger <cg@exept.de>
parents: 511
diff changeset
  2498
# ifdef AF_X25
1009
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2499
		else if (myDomain == @symbol(x25)) {
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2500
		}
513
b8042ff0f82c udp receive: translate received address according to the domain
Claus Gittinger <cg@exept.de>
parents: 511
diff changeset
  2501
# endif
812
c8101ea70e6c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 811
diff changeset
  2502
c8101ea70e6c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 811
diff changeset
  2503
# ifdef AF_AX25
1009
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2504
		else if (myDomain == @symbol(ax25)) {
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2505
		}
513
b8042ff0f82c udp receive: translate received address according to the domain
Claus Gittinger <cg@exept.de>
parents: 511
diff changeset
  2506
# endif
812
c8101ea70e6c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 811
diff changeset
  2507
c8101ea70e6c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 811
diff changeset
  2508
# ifdef AF_NS
1009
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2509
		else if ((myDomain == @symbol(ns)) 
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2510
		 || (myDomain == @symbol(xns))) {
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2511
		}
513
b8042ff0f82c udp receive: translate received address according to the domain
Claus Gittinger <cg@exept.de>
parents: 511
diff changeset
  2512
# endif
812
c8101ea70e6c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 811
diff changeset
  2513
513
b8042ff0f82c udp receive: translate received address according to the domain
Claus Gittinger <cg@exept.de>
parents: 511
diff changeset
  2514
# ifdef AF_SNA
1009
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2515
		else if (myDomain == @symbol(sna)) {
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2516
		}
513
b8042ff0f82c udp receive: translate received address according to the domain
Claus Gittinger <cg@exept.de>
parents: 511
diff changeset
  2517
# endif
812
c8101ea70e6c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 811
diff changeset
  2518
513
b8042ff0f82c udp receive: translate received address according to the domain
Claus Gittinger <cg@exept.de>
parents: 511
diff changeset
  2519
# ifdef AF_RAW
1009
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2520
		else if (myDomain == @symbol(raw)) {
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2521
		}
524
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  2522
# endif
812
c8101ea70e6c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 811
diff changeset
  2523
524
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  2524
# ifdef AF_ISO
1009
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2525
		else if (myDomain == @symbol(iso)) {
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2526
		}
524
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  2527
# endif
812
c8101ea70e6c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 811
diff changeset
  2528
524
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  2529
# ifdef AF_DECnet
1009
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2530
		else if (myDomain == @symbol(decnet)) {
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2531
		}
513
b8042ff0f82c udp receive: translate received address according to the domain
Claus Gittinger <cg@exept.de>
parents: 511
diff changeset
  2532
# endif
812
c8101ea70e6c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 811
diff changeset
  2533
524
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  2534
# ifdef AF_NETBIOS
1009
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2535
		else if (myDomain == @symbol(netbios)) {
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2536
		}
530
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  2537
# endif
812
c8101ea70e6c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 811
diff changeset
  2538
653
219b89f62113 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 650
diff changeset
  2539
# ifdef AF_IPX
1009
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2540
		else if (myDomain == @symbol(ipx)) {
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2541
		}
530
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  2542
# endif
812
c8101ea70e6c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 811
diff changeset
  2543
653
219b89f62113 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 650
diff changeset
  2544
# ifdef AF_BRIDGE
1009
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2545
		else if (myDomain == @symbol(bridge)) {
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2546
		}
524
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  2547
# endif
812
c8101ea70e6c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 811
diff changeset
  2548
653
219b89f62113 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 650
diff changeset
  2549
# ifdef AF_BSC
1009
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2550
		else if (myDomain == @symbol(bsc)) {
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2551
		}
571
191b37534643 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 563
diff changeset
  2552
# endif
812
c8101ea70e6c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 811
diff changeset
  2553
c8101ea70e6c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 811
diff changeset
  2554
# ifdef AF_ROSE
1009
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2555
		else if (myDomain == @symbol(rose)) {
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2556
		}
812
c8101ea70e6c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 811
diff changeset
  2557
# endif
c8101ea70e6c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 811
diff changeset
  2558
869
a6e5cbe9f558 preps for AF_IRDA
Claus Gittinger <cg@exept.de>
parents: 867
diff changeset
  2559
# ifdef AF_IRDA
1009
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2560
		else if (myDomain == @symbol(irda)) {
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2561
		}
869
a6e5cbe9f558 preps for AF_IRDA
Claus Gittinger <cg@exept.de>
parents: 867
diff changeset
  2562
# endif
a6e5cbe9f558 preps for AF_IRDA
Claus Gittinger <cg@exept.de>
parents: 867
diff changeset
  2563
524
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  2564
# if defined(AF_CCITT) && (AF_CCITT != AF_X25)
1009
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2565
		else if (myDomain == @symbol(ccitt)) {
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2566
		}
524
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  2567
# endif
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  2568
1009
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2569
		addrLen = __MKSMALLINT(alen);
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2570
	    }
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2571
	}
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2572
	if (n < 0) {
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2573
	    __INST(lastErrorNumber) = __MKSMALLINT(errno);
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2574
	}
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2575
	nReceived = __MKSMALLINT(n);
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  2576
    }
418
317e55c6c281 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 403
diff changeset
  2577
#endif
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  2578
bad: ;
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  2579
%}.
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  2580
    nReceived notNil ifTrue:[
1009
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2581
	nReceived < 0 ifTrue:[
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2582
	    'Socket [warning]: ' infoPrint.
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2583
	    (OperatingSystem errorTextForNumber:lastErrorNumber) infoPrintCR.
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
	addrLen notNil ifTrue:[
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2586
	   (anAddressBuffer isKindOf:SocketAddress) ifFalse:[
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2587
		"/ can be a ByteArray for ST/X compatibility
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2588
		anAddressBuffer replaceFrom:1 to:addrLen with:addrBytes
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2589
		domain == #inet ifTrue:[
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2590
		    addrBytes := anAddressBuffer copyFrom:1 to:4.
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2591
		    anAddressBuffer at:5 put:(addrPort digitByteAt:2).
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2592
		    anAddressBuffer at:6 put:(addrPort digitByteAt:1).
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2593
		] ifFalse:[
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2594
		    domain == #appletalk ifTrue:[
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2595
			addrBytes := anAddressBuffer copyFrom:1 to:3.
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2596
			anAddressBuffer at:4 put:(addrPort digitByteAt:2).
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2597
			anAddressBuffer at:5 put:(addrPort digitByteAt:1).
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2598
		    ] ifFalse:[
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2599
			self error:'please use a SocketAddress'
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2600
		    ]
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2601
		]
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2602
	    ] ifTrue:[
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2603
		"/ can be a SocketAddress for ST-80 compatibility
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2604
		anAddressBuffer hostAddress:(addrBytes copyTo:addrLen) port:addrPort.
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2605
	    ].
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2606
	].
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2607
	^ nReceived
28
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  2608
    ].
116
7789fb1c9fa2 more UD socket fixes (at least client side seems to work now)
Claus Gittinger <cg@exept.de>
parents: 115
diff changeset
  2609
    "
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  2610
     arrive here if you try to receive into an invalid buffer
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  2611
     (i.e. not ByteArray-like), 
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  2612
     or if the addressBuffer is nonNil AND not a ByteArray/String 
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  2613
     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
  2614
    "
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  2615
    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
  2616
!
7789fb1c9fa2 more UD socket fixes (at least client side seems to work now)
Claus Gittinger <cg@exept.de>
parents: 115
diff changeset
  2617
915
3dc0e3cd838a added interface to send() and recv()
Claus Gittinger <cg@exept.de>
parents: 898
diff changeset
  2618
sendBuffer:aDataBuffer start:startIndex for:count flags:flags
3dc0e3cd838a added interface to send() and recv()
Claus Gittinger <cg@exept.de>
parents: 898
diff changeset
  2619
    "send data. 
3dc0e3cd838a added interface to send() and recv()
Claus Gittinger <cg@exept.de>
parents: 898
diff changeset
  2620
     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
  2621
     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
  2622
     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
  2623
     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
  2624
     instance variable."
3dc0e3cd838a added interface to send() and recv()
Claus Gittinger <cg@exept.de>
parents: 898
diff changeset
  2625
3dc0e3cd838a added interface to send() and recv()
Claus Gittinger <cg@exept.de>
parents: 898
diff changeset
  2626
    |nReceived portNo|
3dc0e3cd838a added interface to send() and recv()
Claus Gittinger <cg@exept.de>
parents: 898
diff changeset
  2627
3dc0e3cd838a added interface to send() and recv()
Claus Gittinger <cg@exept.de>
parents: 898
diff changeset
  2628
%{
3dc0e3cd838a added interface to send() and recv()
Claus Gittinger <cg@exept.de>
parents: 898
diff changeset
  2629
#ifndef NO_SOCKET
3dc0e3cd838a added interface to send() and recv()
Claus Gittinger <cg@exept.de>
parents: 898
diff changeset
  2630
    OBJ oClass;
3dc0e3cd838a added interface to send() and recv()
Claus Gittinger <cg@exept.de>
parents: 898
diff changeset
  2631
    OBJ fp = __INST(filePointer);
3dc0e3cd838a added interface to send() and recv()
Claus Gittinger <cg@exept.de>
parents: 898
diff changeset
  2632
    int nInstVars, nInstBytes, objSize;
3dc0e3cd838a added interface to send() and recv()
Claus Gittinger <cg@exept.de>
parents: 898
diff changeset
  2633
    int sock;
3dc0e3cd838a added interface to send() and recv()
Claus Gittinger <cg@exept.de>
parents: 898
diff changeset
  2634
    int n;
3dc0e3cd838a added interface to send() and recv()
Claus Gittinger <cg@exept.de>
parents: 898
diff changeset
  2635
    char *cp;
3dc0e3cd838a added interface to send() and recv()
Claus Gittinger <cg@exept.de>
parents: 898
diff changeset
  2636
    int _flags = 0;
1009
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2637
    int offs, nBytes, sIdx;
915
3dc0e3cd838a added interface to send() and recv()
Claus Gittinger <cg@exept.de>
parents: 898
diff changeset
  2638
    unsigned long norder;
3dc0e3cd838a added interface to send() and recv()
Claus Gittinger <cg@exept.de>
parents: 898
diff changeset
  2639
3dc0e3cd838a added interface to send() and recv()
Claus Gittinger <cg@exept.de>
parents: 898
diff changeset
  2640
    _flags = __longIntVal(flags);
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
    if ((fp != nil) 
3dc0e3cd838a added interface to send() and recv()
Claus Gittinger <cg@exept.de>
parents: 898
diff changeset
  2643
     && __isSmallInteger(startIndex)
3dc0e3cd838a added interface to send() and recv()
Claus Gittinger <cg@exept.de>
parents: 898
diff changeset
  2644
     && __isSmallInteger(count)) {
1009
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2645
	sock = fileno(__FILEVal(fp));
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2646
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2647
	oClass = __Class(aDataBuffer);
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2648
	sIdx = __intVal(startIndex) - 1;
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2649
	switch (__intVal(__ClassInstPtr(oClass)->c_flags) & ARRAYMASK) {
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2650
	    case BYTEARRAY:
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2651
		offs = sIdx;
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2652
		break;
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2653
	    case WORDARRAY:
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2654
	    case SWORDARRAY:
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2655
		offs = sIdx * 2;
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2656
		break;
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2657
	    case LONGARRAY:
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2658
	    case SLONGARRAY:
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2659
		offs = sIdx * 4;
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2660
		break;
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2661
	    case LONGLONGARRAY:
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2662
	    case SLONGLONGARRAY:
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2663
		offs = sIdx * 8;
915
3dc0e3cd838a added interface to send() and recv()
Claus Gittinger <cg@exept.de>
parents: 898
diff changeset
  2664
# ifdef __NEED_LONGLONG_ALIGN
1009
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2665
		offs += 4;
915
3dc0e3cd838a added interface to send() and recv()
Claus Gittinger <cg@exept.de>
parents: 898
diff changeset
  2666
# endif
1010
603216bbf89a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1009
diff changeset
  2667
		break;
1009
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2668
	    case FLOATARRAY:
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2669
		offs = sIdx * sizeof(float);
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2670
		break;
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2671
	    case DOUBLEARRAY:
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2672
		offs = sIdx * sizeof(double);
915
3dc0e3cd838a added interface to send() and recv()
Claus Gittinger <cg@exept.de>
parents: 898
diff changeset
  2673
# ifdef __NEED_DOUBLE_ALIGN
1009
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2674
		offs += 4;
915
3dc0e3cd838a added interface to send() and recv()
Claus Gittinger <cg@exept.de>
parents: 898
diff changeset
  2675
# endif
1009
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2676
		break;
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2677
	    default:
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2678
		goto bad;
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2679
	}
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2680
	nBytes = __intVal(count);
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2681
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2682
	nInstVars = __intVal(__ClassInstPtr(oClass)->c_ninstvars);
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2683
	nInstBytes = OHDR_SIZE + nInstVars * sizeof(OBJ);
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2684
	objSize = __qSize(aDataBuffer) - nInstBytes;
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2685
	cp = (char *)__InstPtr(aDataBuffer) + nInstBytes;
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2686
	cp += offs;
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2687
	if ((offs + nBytes) > objSize) {
915
3dc0e3cd838a added interface to send() and recv()
Claus Gittinger <cg@exept.de>
parents: 898
diff changeset
  2688
# ifdef DGRAM_DEBUG
1009
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2689
	    printf("cut off ...\n");
915
3dc0e3cd838a added interface to send() and recv()
Claus Gittinger <cg@exept.de>
parents: 898
diff changeset
  2690
# endif
1009
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2691
	    nBytes = objSize - offs;
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2692
	}
915
3dc0e3cd838a added interface to send() and recv()
Claus Gittinger <cg@exept.de>
parents: 898
diff changeset
  2693
3dc0e3cd838a added interface to send() and recv()
Claus Gittinger <cg@exept.de>
parents: 898
diff changeset
  2694
# ifdef DGRAM_DEBUG
1009
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2695
	printf("sending %d bytes ...\n", nBytes);
915
3dc0e3cd838a added interface to send() and recv()
Claus Gittinger <cg@exept.de>
parents: 898
diff changeset
  2696
# endif
3dc0e3cd838a added interface to send() and recv()
Claus Gittinger <cg@exept.de>
parents: 898
diff changeset
  2697
1009
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2698
	__BEGIN_INTERRUPTABLE__
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2699
	do {
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2700
	    n = send(sock, cp, nBytes, _flags);
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2701
	} while ((n < 0) && (errno == EINTR));
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2702
	__END_INTERRUPTABLE__
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2703
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2704
	if (n < 0) {
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2705
	    __INST(lastErrorNumber) = __MKSMALLINT(errno);
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2706
	}
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2707
	RETURN (__MKSMALLINT(n));
915
3dc0e3cd838a added interface to send() and recv()
Claus Gittinger <cg@exept.de>
parents: 898
diff changeset
  2708
    }
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
bad: ;
3dc0e3cd838a added interface to send() and recv()
Claus Gittinger <cg@exept.de>
parents: 898
diff changeset
  2711
%}.
3dc0e3cd838a added interface to send() and recv()
Claus Gittinger <cg@exept.de>
parents: 898
diff changeset
  2712
    "
3dc0e3cd838a added interface to send() and recv()
Claus Gittinger <cg@exept.de>
parents: 898
diff changeset
  2713
     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
  2714
     (i.e. not ByteArray-like), 
3dc0e3cd838a added interface to send() and recv()
Claus Gittinger <cg@exept.de>
parents: 898
diff changeset
  2715
     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
  2716
     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
  2717
    "
3dc0e3cd838a added interface to send() and recv()
Claus Gittinger <cg@exept.de>
parents: 898
diff changeset
  2718
    self primitiveFailed
3dc0e3cd838a added interface to send() and recv()
Claus Gittinger <cg@exept.de>
parents: 898
diff changeset
  2719
!
3dc0e3cd838a added interface to send() and recv()
Claus Gittinger <cg@exept.de>
parents: 898
diff changeset
  2720
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  2721
sendTo:anAddressBuffer buffer:buffer
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  2722
    "send datagramm data - fetch address of destination host from
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  2723
     anAddressBuffer, data from aDataBuffer. 
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  2724
     Both must be ByteArray-like. The bytes in the addressBuffer must
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  2725
     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
  2726
     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
  2727
     On error, the unix error code is left in the lastErrorNumber
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  2728
     instance variable.
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  2729
     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
  2730
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  2731
    ^ 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
  2732
!
7789fb1c9fa2 more UD socket fixes (at least client side seems to work now)
Claus Gittinger <cg@exept.de>
parents: 115
diff changeset
  2733
817
eda0065cbd47 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 814
diff changeset
  2734
sendTo:anAddressBuffer buffer:buffer start:startIndex for:count
eda0065cbd47 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 814
diff changeset
  2735
    "send datagramm data - fetch address of destination host from
eda0065cbd47 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 814
diff changeset
  2736
     anAddressBuffer, data from aDataBuffer. 
eda0065cbd47 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 814
diff changeset
  2737
     Both must be ByteArray-like. The bytes in the addressBuffer must
eda0065cbd47 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 814
diff changeset
  2738
     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
  2739
     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
  2740
     On error, the unix error code is left in the lastErrorNumber
eda0065cbd47 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 814
diff changeset
  2741
     instance variable.
eda0065cbd47 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 814
diff changeset
  2742
     Flags is currently ignored; it is there for ST-80 compatibility."
eda0065cbd47 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 814
diff changeset
  2743
eda0065cbd47 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 814
diff changeset
  2744
    ^ self sendTo:anAddressBuffer buffer:buffer start:startIndex for:count flags:0 
eda0065cbd47 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 814
diff changeset
  2745
!
eda0065cbd47 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 814
diff changeset
  2746
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  2747
sendTo:anAddressBuffer buffer:aDataBuffer start:startIndex for:count flags:flags
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  2748
    "send datagramm data - fetch address of destination host from
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  2749
     anAddressBuffer, data from aDataBuffer starting at startIndex,
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  2750
     sending count bytes. 
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  2751
     Both must be ByteArray-like. The bytes in the addressBuffer must
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  2752
     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
  2753
     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
  2754
     On error, the unix error code is left in the lastErrorNumber
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  2755
     instance variable."
0
1cf8d1747859 Initial revision
claus
parents:
diff changeset
  2756
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  2757
    |addrBytes addrLen nReceived portNo|
93
Claus Gittinger <cg@exept.de>
parents: 92
diff changeset
  2758
819
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
  2759
    "/ 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
  2760
    "/ or (better) an instance of SocketAddress
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  2761
    "/
888
a868b0e54a2b ipAddress stuff
Claus Gittinger <cg@exept.de>
parents: 887
diff changeset
  2762
    (anAddressBuffer isKindOf:SocketAddress) ifFalse:[
1009
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2763
	domain == #inet ifTrue:[
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2764
	    addrBytes := anAddressBuffer copyFrom:1 to:4.
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2765
	    portNo := ((anAddressBuffer at:5) bitShift:8)
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2766
		      + (anAddressBuffer at:6).
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2767
	] ifFalse:[
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2768
	    domain == #appletalk ifTrue:[
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2769
		addrBytes := anAddressBuffer copyFrom:1 to:3.
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2770
		portNo := ((anAddressBuffer at:5) bitShift:8)
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2771
			  + (anAddressBuffer at:6).
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2772
	    ] ifFalse:[
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2773
		self error:'please use a SocketAddress'
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2774
	    ]
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2775
	].
888
a868b0e54a2b ipAddress stuff
Claus Gittinger <cg@exept.de>
parents: 887
diff changeset
  2776
    ] ifTrue:[
1009
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2777
	addrBytes := anAddressBuffer hostAddress.
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2778
	portNo := anAddressBuffer port.
28
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  2779
    ].
0
1cf8d1747859 Initial revision
claus
parents:
diff changeset
  2780
%{
418
317e55c6c281 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 403
diff changeset
  2781
#ifndef NO_SOCKET
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  2782
    OBJ oClass;
217
fcfbc9f71048 underscore cleanup
Claus Gittinger <cg@exept.de>
parents: 209
diff changeset
  2783
    OBJ fp = __INST(filePointer);
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  2784
    int nInstVars, nInstBytes, objSize;
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  2785
    int sock;
819
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
  2786
    union sockaddr_u sa;
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  2787
    struct sockaddr *saPtr = (struct sockaddr *)&sa;
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  2788
    int alen = sizeof(sa);
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  2789
    int n;
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  2790
    char *cp;
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  2791
    int _flags = 0;
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  2792
    int offs, nBytes;
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  2793
    unsigned long norder;
21
33eb5ffad09d *** empty log message ***
claus
parents: 8
diff changeset
  2794
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  2795
    _flags = __longIntVal(flags);
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  2796
 
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  2797
    if ((fp != nil) 
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  2798
     && __isSmallInteger(startIndex)
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  2799
     && __isSmallInteger(count)) {
1009
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2800
	sock = fileno(__FILEVal(fp));
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2801
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2802
	if (addrBytes == nil) {
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2803
	    alen = 0;
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2804
	    saPtr = (struct sockaddr *)0;
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2805
	} else {
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2806
	    if (! __isByteArray(addrBytes)) goto bad;
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2807
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2808
	    cp = (char *)__ByteArrayInstPtr(addrBytes)->ba_element;
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2809
	    n = __byteArraySize(addrBytes);
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2810
	    if (alen < n) n = alen;
790
6f58d65fac5e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 789
diff changeset
  2811
# ifdef DGRAM_DEBUG
1009
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2812
	    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
  2813
# endif
1009
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2814
	    bcopy(cp, &sa.in.sin_addr.s_addr, n);
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2815
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2816
	    if (0) {
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2817
		/* for else below */
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2818
	    }
790
6f58d65fac5e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 789
diff changeset
  2819
# ifdef AF_INET
1009
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2820
	    else if (__INST(domain) == @symbol(inet)) {
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2821
		sa.in.sin_family = AF_INET;
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2822
		sa.in.sin_port = htons((u_short) __intVal(portNo)); 
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2823
	    }
790
6f58d65fac5e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 789
diff changeset
  2824
# endif
6f58d65fac5e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 789
diff changeset
  2825
# ifdef AF_INET6
1009
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2826
	    else if (__INST(domain) == @symbol(inet6)) {
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2827
		sa.in6.sin6_family = AF_INET6;
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2828
		sa.in6.sin6_port = htons((u_short) __intVal(portNo)); 
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2829
	    }
790
6f58d65fac5e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 789
diff changeset
  2830
# endif
6f58d65fac5e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 789
diff changeset
  2831
# ifdef AF_APPLETALK
1009
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2832
	    else if (__INST(domain) == @symbol(appletalk)) {
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2833
		sa.at.sat_family = AF_APPLETALK;
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2834
		sa.at.sat_port = __intVal(portNo);
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2835
	    }
790
6f58d65fac5e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 789
diff changeset
  2836
# endif
869
a6e5cbe9f558 preps for AF_IRDA
Claus Gittinger <cg@exept.de>
parents: 867
diff changeset
  2837
# ifdef AF_IRDA
1009
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2838
	    else if (__INST(domain) == @symbol(irda)) {
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2839
	    }
869
a6e5cbe9f558 preps for AF_IRDA
Claus Gittinger <cg@exept.de>
parents: 867
diff changeset
  2840
# endif
1009
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2841
	}
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2842
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2843
	oClass = __Class(aDataBuffer);
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2844
	switch (__intVal(__ClassInstPtr(oClass)->c_flags) & ARRAYMASK) {
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2845
	    case BYTEARRAY:
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2846
		offs = __intVal(startIndex) - 1;
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2847
		break;
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2848
	    case WORDARRAY:
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2849
	    case SWORDARRAY:
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2850
		offs = (__intVal(startIndex) - 1) * 2;
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2851
		break;
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2852
	    case LONGARRAY:
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2853
	    case SLONGARRAY:
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2854
		offs = (__intVal(startIndex) - 1) * 4;
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2855
		break;
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2856
	    case LONGLONGARRAY:
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2857
	    case SLONGLONGARRAY:
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2858
		offs = (__intVal(startIndex) - 1) * 8;
790
6f58d65fac5e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 789
diff changeset
  2859
# ifdef __NEED_LONGLONG_ALIGN
1009
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2860
		offs += 4;
790
6f58d65fac5e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 789
diff changeset
  2861
# endif
1010
603216bbf89a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1009
diff changeset
  2862
		break;
1009
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2863
	    case FLOATARRAY:
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2864
		offs = (__intVal(startIndex) - 1) * sizeof(float);
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2865
		break;
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2866
	    case DOUBLEARRAY:
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2867
		offs = (__intVal(startIndex) - 1) * sizeof(double);
790
6f58d65fac5e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 789
diff changeset
  2868
# ifdef __NEED_DOUBLE_ALIGN
1009
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2869
		offs += 4;
790
6f58d65fac5e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 789
diff changeset
  2870
# endif
1009
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2871
		break;
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2872
	    default:
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2873
		goto bad;
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2874
	}
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2875
	nBytes = __intVal(count);
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2876
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2877
	nInstVars = __intVal(__ClassInstPtr(oClass)->c_ninstvars);
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2878
	nInstBytes = OHDR_SIZE + nInstVars * sizeof(OBJ);
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2879
	objSize = __qSize(aDataBuffer) - nInstBytes;
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2880
	if ((offs + nBytes) > objSize) {
790
6f58d65fac5e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 789
diff changeset
  2881
# ifdef DGRAM_DEBUG
1009
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2882
	    printf("cut off ...\n");
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
	    nBytes = objSize - offs;
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2885
	}
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2886
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2887
	norder = htonl(sa.in.sin_addr.s_addr);
790
6f58d65fac5e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 789
diff changeset
  2888
# ifdef DGRAM_DEBUG
1009
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2889
	printf("sending %d bytes ... to ", nBytes);
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2890
	printf("%d.%d.%d.%d\n",
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2891
		    (norder >> 24) & 0xFF,
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2892
		    (norder >> 16) & 0xFF,
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2893
		    (norder >> 8) & 0xFF,
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2894
		    norder & 0xFF);
790
6f58d65fac5e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 789
diff changeset
  2895
# endif
0
1cf8d1747859 Initial revision
claus
parents:
diff changeset
  2896
1009
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2897
	__BEGIN_INTERRUPTABLE__
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2898
	do {
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2899
	    cp = (char *)__InstPtr(aDataBuffer) + nInstBytes + offs;
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2900
	    n = sendto(sock, cp, nBytes, _flags, saPtr, alen);
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2901
	} while ((n < 0) && (errno == EINTR));
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2902
	__END_INTERRUPTABLE__
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2903
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2904
	if (n < 0) {
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2905
	    __INST(lastErrorNumber) = __MKSMALLINT(errno);
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2906
	}
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  2907
	RETURN (__MKSMALLINT(n));
0
1cf8d1747859 Initial revision
claus
parents:
diff changeset
  2908
    }
418
317e55c6c281 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 403
diff changeset
  2909
#endif
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  2910
bad: ;
42
506596f9a1a8 *** empty log message ***
claus
parents: 38
diff changeset
  2911
%}.
506596f9a1a8 *** empty log message ***
claus
parents: 38
diff changeset
  2912
    "
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  2913
     arrive here if you try to send from an invalid buffer
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  2914
     (i.e. not ByteArray-like), 
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  2915
     or if the addressBuffer is nonNil AND not a ByteArray/String 
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  2916
     or if the addressBuffer is nonNil AND too small.
42
506596f9a1a8 *** empty log message ***
claus
parents: 38
diff changeset
  2917
    "
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  2918
    self primitiveFailed
0
1cf8d1747859 Initial revision
claus
parents:
diff changeset
  2919
! !
1cf8d1747859 Initial revision
claus
parents:
diff changeset
  2920
1cf8d1747859 Initial revision
claus
parents:
diff changeset
  2921
!Socket methodsFor:'low level'!
1cf8d1747859 Initial revision
claus
parents:
diff changeset
  2922
507
91fb3dfd91a5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 506
diff changeset
  2923
bindAnonymously
91fb3dfd91a5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 506
diff changeset
  2924
    ^ self
91fb3dfd91a5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 506
diff changeset
  2925
	bindTo:0
91fb3dfd91a5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 506
diff changeset
  2926
	address:nil
509
eb5a2d5bab0b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 508
diff changeset
  2927
	reuseAddress:false
eb5a2d5bab0b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 508
diff changeset
  2928
!
eb5a2d5bab0b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 508
diff changeset
  2929
eb5a2d5bab0b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 508
diff changeset
  2930
bindAnonymouslyToAddress:addressString
eb5a2d5bab0b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 508
diff changeset
  2931
    ^ self
eb5a2d5bab0b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 508
diff changeset
  2932
	bindTo:0
eb5a2d5bab0b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 508
diff changeset
  2933
	address:addressString
eb5a2d5bab0b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 508
diff changeset
  2934
	reuseAddress:false
507
91fb3dfd91a5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 506
diff changeset
  2935
!
91fb3dfd91a5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 506
diff changeset
  2936
71
claus
parents: 63
diff changeset
  2937
bindTo:aSocketAddress 
425
eb8198e9f1b0 comment
Claus Gittinger <cg@exept.de>
parents: 421
diff changeset
  2938
    "ST80 compatible bind, expecting a socketAddress argument.
eb8198e9f1b0 comment
Claus Gittinger <cg@exept.de>
parents: 421
diff changeset
  2939
     The socketAddress object (an instance of SocketAddress)
eb8198e9f1b0 comment
Claus Gittinger <cg@exept.de>
parents: 421
diff changeset
  2940
     is supposed to respond to #portOrName and #address requests."
71
claus
parents: 63
diff changeset
  2941
claus
parents: 63
diff changeset
  2942
    ^ self bindTo:(aSocketAddress portOrName)
claus
parents: 63
diff changeset
  2943
	   address:(aSocketAddress address)
425
eb8198e9f1b0 comment
Claus Gittinger <cg@exept.de>
parents: 421
diff changeset
  2944
	   reuseAddress:true
71
claus
parents: 63
diff changeset
  2945
!
claus
parents: 63
diff changeset
  2946
425
eb8198e9f1b0 comment
Claus Gittinger <cg@exept.de>
parents: 421
diff changeset
  2947
bindTo:portNrOrNameString address:addressString
28
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  2948
    "low level bind - returns true if ok, false otherwise.
71
claus
parents: 63
diff changeset
  2949
     Currently only non-address binding is supported; 
425
eb8198e9f1b0 comment
Claus Gittinger <cg@exept.de>
parents: 421
diff changeset
  2950
     i.e. the address must always be nil.
71
claus
parents: 63
diff changeset
  2951
claus
parents: 63
diff changeset
  2952
     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
  2953
	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
  2954
	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
  2955
	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
  2956
     "
7789fb1c9fa2 more UD socket fixes (at least client side seems to work now)
Claus Gittinger <cg@exept.de>
parents: 115
diff changeset
  2957
425
eb8198e9f1b0 comment
Claus Gittinger <cg@exept.de>
parents: 421
diff changeset
  2958
    ^ self 
eb8198e9f1b0 comment
Claus Gittinger <cg@exept.de>
parents: 421
diff changeset
  2959
	bindTo:portNrOrNameString 
eb8198e9f1b0 comment
Claus Gittinger <cg@exept.de>
parents: 421
diff changeset
  2960
	address:addressString 
eb8198e9f1b0 comment
Claus Gittinger <cg@exept.de>
parents: 421
diff changeset
  2961
	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
  2962
!
7789fb1c9fa2 more UD socket fixes (at least client side seems to work now)
Claus Gittinger <cg@exept.de>
parents: 115
diff changeset
  2963
7789fb1c9fa2 more UD socket fixes (at least client side seems to work now)
Claus Gittinger <cg@exept.de>
parents: 115
diff changeset
  2964
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
  2965
    "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
  2966
     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
  2967
     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
  2968
7789fb1c9fa2 more UD socket fixes (at least client side seems to work now)
Claus Gittinger <cg@exept.de>
parents: 115
diff changeset
  2969
     The interpretation of portNrOrName depends on the domain:
789
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2970
	inet domain uses (4byte) byteArray like internet numbers,
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2971
	unix domain uses pathname strings,
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2972
	others use whatever will come up in the future
425
eb8198e9f1b0 comment
Claus Gittinger <cg@exept.de>
parents: 421
diff changeset
  2973
eb8198e9f1b0 comment
Claus Gittinger <cg@exept.de>
parents: 421
diff changeset
  2974
     The reuse boolean argument controls if the SO_REUSEADDR socket option
eb8198e9f1b0 comment
Claus Gittinger <cg@exept.de>
parents: 421
diff changeset
  2975
     is to be set (to avoid the 'bind: address in use' error).
eb8198e9f1b0 comment
Claus Gittinger <cg@exept.de>
parents: 421
diff changeset
  2976
    "
28
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  2977
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  2978
    filePointer isNil ifTrue:[
789
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2979
	^ self errorNotOpen
28
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  2980
    ].
0
1cf8d1747859 Initial revision
claus
parents:
diff changeset
  2981
%{
418
317e55c6c281 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 403
diff changeset
  2982
#ifndef NO_SOCKET
217
fcfbc9f71048 underscore cleanup
Claus Gittinger <cg@exept.de>
parents: 209
diff changeset
  2983
    OBJ t = __INST(filePointer);
71
claus
parents: 63
diff changeset
  2984
    OBJ myDomain;
28
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  2985
    int sock;
819
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
  2986
    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
  2987
    int sockaddr_size;
6
claus
parents: 4
diff changeset
  2988
    int ret;
25
996051271ce9 *** empty log message ***
claus
parents: 21
diff changeset
  2989
    int on = 1;
28
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  2990
    int ok;
0
1cf8d1747859 Initial revision
claus
parents:
diff changeset
  2991
217
fcfbc9f71048 underscore cleanup
Claus Gittinger <cg@exept.de>
parents: 209
diff changeset
  2992
    if (!__isString(__INST(domain)) && !__isSymbol(__INST(domain))) {
789
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2993
	DBGPRINTF(("SOCKET: invalid domain arg\n"));
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  2994
	RETURN (false);
28
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  2995
    }
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  2996
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  2997
    ok = 0;
217
fcfbc9f71048 underscore cleanup
Claus Gittinger <cg@exept.de>
parents: 209
diff changeset
  2998
    myDomain = __INST(domain);
525
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  2999
1009
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  3000
    if (0) {
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  3001
	/* for else below */
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  3002
    }
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  3003
506
11ef93d12870 support anonymous (OS_specified) ports. (for FTP-protocol)
Claus Gittinger <cg@exept.de>
parents: 486
diff changeset
  3004
# ifdef AF_INET
1009
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  3005
    else if (myDomain == @symbol(inet)) {
789
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3006
	/*
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3007
	 * INET addresses - port must be a smallinteger or nil
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3008
	 */
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3009
	sa.in.sin_family = AF_INET;
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3010
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3011
	if (portNrOrName == nil) {
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3012
	    sa.in.sin_port = 0;
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3013
	} else {
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3014
	    if (! __isSmallInteger(portNrOrName)) {
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3015
		DBGPRINTF(("SOCKET: invalid port arg\n"));
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3016
		RETURN (false);
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3017
	    }
1009
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  3018
	    sa.in.sin_port = htons((u_short) __intVal(portNrOrName));
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
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
	 * INET addresses - addr must be nil, integer or byteArray
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 (address == nil) {
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3025
	    sa.in.sin_addr.s_addr = htonl(INADDR_ANY);
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 (__isInteger(address)) {
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3028
		sa.in.sin_addr.s_addr = htonl(__longIntVal(address));
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3029
	    } else {
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3030
		if (__isByteArray(address)) {
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3031
		    unsigned char *cp;
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3032
		    int n;
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
		    cp = __ByteArrayInstPtr(address)->ba_element;
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3035
		    n = __byteArraySize(address);
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3036
		    if (n > 4) n = 4;
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3037
		    bcopy(cp, &sa.in.sin_addr.s_addr, n);
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3038
		} else {
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3039
		    unsigned addr;
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3040
		    struct hostent *hp ;
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3041
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3042
		    if (! __isString(address)) {
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3043
			DBGPRINTF(("SOCKET: invalid address arg in bind\n"));
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3044
			RETURN (false);
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3045
		    }
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
		    if ((addr = inet_addr(__stringVal(address))) != -1) {
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3048
			/* 
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3049
			 * is Internet addr in octet notation 
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3050
			 */
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3051
			bcopy(&addr, (char *) &sa.in.sin_addr, sizeof(addr)) ; /* set address */
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3052
		    } else {
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3053
			/* 
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3054
			 * do we know the host's address? 
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3055
			 */
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3056
			GETHOSTBYNAME(hp, __stringVal(address))
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3057
			if (hp == NULL) {
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3058
			    DBGPRINTF(("SOCKET: unknown host:%s\n", __stringVal(address)));
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3059
			    RETURN (false);
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3060
			}
812
c8101ea70e6c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 811
diff changeset
  3061
			if (hp->h_addrtype != AF_INET) {
c8101ea70e6c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 811
diff changeset
  3062
			    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
  3063
			    RETURN (false);
c8101ea70e6c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 811
diff changeset
  3064
			}
789
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3065
			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
  3066
			sa.in.sin_family = hp->h_addrtype;
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3067
		    }
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
	    }
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3070
	}
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3071
	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
  3072
	sockaddr_size = sizeof(struct sockaddr_in);
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3073
	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
  3074
    }
530
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  3075
# endif /* AF_INET */
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  3076
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  3077
# ifdef AF_INET6
1009
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  3078
    else if (myDomain == @symbol(inet6)) {
789
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3079
	/*
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3080
	 * INET6 addresses - port must be a smallinteger or nil
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
	sa.in6.sin6_family = AF_INET6;
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
	if (portNrOrName == nil) {
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3085
	    sa.in6.sin6_port = 0;
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3086
	} else {
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3087
	    if (! __isSmallInteger(portNrOrName)) {
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3088
		DBGPRINTF(("SOCKET: invalid port arg\n"));
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3089
		RETURN (false);
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3090
	    }
1009
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  3091
	    sa.in6.sin6_port = htons((u_short) __intVal(portNrOrName));
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
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
	 * INET6 addresses - addr must be nil or byteArray or string
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 (address == nil) {
812
c8101ea70e6c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 811
diff changeset
  3098
	    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
  3099
	} else {
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3100
	    if (__isByteArray(address)) {
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3101
		unsigned char *cp;
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3102
		int n;
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3103
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3104
		cp = __ByteArrayInstPtr(address)->ba_element;
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3105
		n = __byteArraySize(address);
812
c8101ea70e6c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 811
diff changeset
  3106
		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
  3107
		bcopy(cp, sa.in6.sin6_addr.s6_addr, n);
789
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3108
	    } else {
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3109
		unsigned addr;
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3110
		struct hostent *hp ;
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3111
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3112
		if (! __isString(address)) {
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3113
		    DBGPRINTF(("SOCKET: invalid address arg in bind\n"));
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3114
		    RETURN (false);
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3115
		}
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
		/* 
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3118
		 * do we know the host's address? 
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3119
		 */
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3120
		GETHOSTBYNAME(hp, __stringVal(address))
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3121
		if (hp == NULL) {
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3122
		    DBGPRINTF(("SOCKET: unknown host:%s\n", __stringVal(address)));
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3123
		    RETURN (false);
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3124
		}
812
c8101ea70e6c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 811
diff changeset
  3125
		if (hp->h_addrtype != AF_INET6) {
c8101ea70e6c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 811
diff changeset
  3126
		    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
  3127
		    RETURN (false);
c8101ea70e6c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 811
diff changeset
  3128
		}
789
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3129
		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
  3130
		sa.in.sin_family = hp->h_addrtype;
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3131
	    }
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
812
c8101ea70e6c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 811
diff changeset
  3134
	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
  3135
			sa.in6.sin6_addr.s6_addr[0], 
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3136
			sa.in6.sin6_addr.s6_addr[1], 
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3137
			sa.in6.sin6_addr.s6_addr[2], 
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3138
			sa.in6.sin6_addr.s6_addr[3], 
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3139
			sa.in6.sin6_addr.s6_addr[4], 
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3140
			sa.in6.sin6_addr.s6_addr[5], 
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3141
			sa.in6.sin6_port));
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3142
	sockaddr_size = sizeof(struct sockaddr_in6);
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3143
	ok = 1;
530
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  3144
    }
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  3145
# endif /* AF_INET6 */
525
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  3146
506
11ef93d12870 support anonymous (OS_specified) ports. (for FTP-protocol)
Claus Gittinger <cg@exept.de>
parents: 486
diff changeset
  3147
# ifdef AF_UNIX
525
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  3148
    /*
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  3149
     * UNIX domain - port is ignored; address must be a string (path)
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  3150
     */
1009
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  3151
    else if (myDomain == @symbol(unix)) {
789
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3152
	char *pathName;
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3153
	int l;
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3154
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3155
	if (! __isString(portNrOrName)) {
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3156
	    DBGPRINTF(("SOCKET: invalid port (pathname) arg\n"));
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3157
	    RETURN (false);
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3158
	}
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3159
	pathName = (char *)__stringVal(portNrOrName);
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3160
	l = strlen(pathName);
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3161
	if ((l + sizeof ( sa.un.sun_family )) > sizeof(struct sockaddr_un)) {
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3162
	    DBGPRINTF(("SOCKET: pathname too long\n"));
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3163
	    RETURN (false);
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3164
	}
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3165
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3166
	strcpy(sa.un.sun_path, pathName);
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3167
	sa.un.sun_family = AF_UNIX;
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3168
	sockaddr_size = l + sizeof ( sa.un.sun_family );
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3169
	ok = 1;
28
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  3170
    }
530
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  3171
# endif /* AF_UNIX */
525
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  3172
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  3173
# ifdef AF_APPLETALK
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  3174
    /*
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  3175
     * this has never been tested ....
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  3176
     */
1009
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  3177
    else if (myDomain == @symbol(appletalk)) {
789
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
	 * APPLETALK addresses - port must be a smallinteger or nil
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3180
	 */
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3181
	sa.at.sat_family = AF_APPLETALK;
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3182
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3183
	if (portNrOrName == nil) {
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3184
	    sa.at.sat_port = 0;
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3185
	} else {
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3186
	    if (! __isSmallInteger(portNrOrName)) {
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3187
		DBGPRINTF(("SOCKET: invalid port arg\n"));
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3188
		RETURN (false);
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3189
	    }
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3190
	    sa.at.sat_port = __intVal(portNrOrName);
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
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
	 * APPLETALK addresses - addr must be nil, integer or byteArray
819
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
  3195
	 * 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
  3196
	 * last byte is node.
789
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3197
	 */
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3198
	if (address == nil) {
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3199
	    sa.at.sat_addr.s_net = ATADDR_ANYNET;
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3200
	    sa.at.sat_addr.s_node = ATADDR_ANYNODE;
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3201
	} else {
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3202
	    if (__isInteger(address)) {
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3203
		unsigned a = __longIntVal(address);
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3204
		sa.at.sat_addr.s_net = htons((a >> 8) & 0xFFFF);
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3205
		sa.at.sat_addr.s_node = htons(a & 0xFF);
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3206
	    } else {
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3207
		if (__isByteArray(address)) {
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3208
		    unsigned char *cp;
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3209
		    int n;
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
		    cp = __ByteArrayInstPtr(address)->ba_element;
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3212
		    n = __byteArraySize(address);
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3213
		    if (n > 3) n = 3;
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3214
		    bcopy(cp, &sa.at.sat_addr, n);
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3215
		} else {
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3216
		    unsigned addr;
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3217
		    struct hostent *hp ;
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3218
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3219
		    if (! __isString(address)) {
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3220
			DBGPRINTF(("SOCKET: invalid address arg in bind\n"));
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3221
			RETURN (false);
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3222
		    }
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3223
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3224
		    /* 
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3225
		     * do we know the host's address? 
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3226
		     */
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3227
		    GETHOSTBYNAME(hp, __stringVal(address))
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3228
		    if (hp == NULL) {
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3229
			DBGPRINTF(("SOCKET: unknown host: %s\n", __stringVal(address)));
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3230
			RETURN (false);
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3231
		    }
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3232
		    if (hp->h_addrtype != AF_APPLETALK) {
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3233
			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
  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
		    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
  3237
		    sa.at.sat_family = hp->h_addrtype;
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3238
		}
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
	}
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3241
	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
  3242
	sockaddr_size = sizeof(struct sockaddr_at);
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3243
	ok = 1;
525
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  3244
    }
530
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  3245
# endif /* AF_APPLETALK */
525
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  3246
28
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  3247
    /*
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  3248
     * XXXX add addressing stuff for other domains here ...
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  3249
     */
506
11ef93d12870 support anonymous (OS_specified) ports. (for FTP-protocol)
Claus Gittinger <cg@exept.de>
parents: 486
diff changeset
  3250
# ifdef AF_X25
1009
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  3251
    else if (myDomain == @symbol(x25)) {
28
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  3252
    }
506
11ef93d12870 support anonymous (OS_specified) ports. (for FTP-protocol)
Claus Gittinger <cg@exept.de>
parents: 486
diff changeset
  3253
# endif
819
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
  3254
# ifdef AF_AX25
1009
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  3255
    else if (myDomain == @symbol(ax25)) {
819
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
  3256
    }
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
  3257
# endif
506
11ef93d12870 support anonymous (OS_specified) ports. (for FTP-protocol)
Claus Gittinger <cg@exept.de>
parents: 486
diff changeset
  3258
# ifdef AF_NS
1009
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  3259
    else if ((myDomain == @symbol(ns)) 
812
c8101ea70e6c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 811
diff changeset
  3260
     || (myDomain == @symbol(xns))) {
28
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  3261
    }
506
11ef93d12870 support anonymous (OS_specified) ports. (for FTP-protocol)
Claus Gittinger <cg@exept.de>
parents: 486
diff changeset
  3262
# endif
524
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  3263
# ifdef AF_DECnet
1009
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  3264
    else if (myDomain == @symbol(decnet)) {
524
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  3265
    }
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  3266
# endif
506
11ef93d12870 support anonymous (OS_specified) ports. (for FTP-protocol)
Claus Gittinger <cg@exept.de>
parents: 486
diff changeset
  3267
# ifdef AF_SNA
1009
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  3268
    else if (myDomain == @symbol(sna)) {
93
Claus Gittinger <cg@exept.de>
parents: 92
diff changeset
  3269
    }
506
11ef93d12870 support anonymous (OS_specified) ports. (for FTP-protocol)
Claus Gittinger <cg@exept.de>
parents: 486
diff changeset
  3270
# endif
11ef93d12870 support anonymous (OS_specified) ports. (for FTP-protocol)
Claus Gittinger <cg@exept.de>
parents: 486
diff changeset
  3271
# ifdef AF_RAW
1009
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  3272
    else if (myDomain == @symbol(raw)) {
93
Claus Gittinger <cg@exept.de>
parents: 92
diff changeset
  3273
    }
506
11ef93d12870 support anonymous (OS_specified) ports. (for FTP-protocol)
Claus Gittinger <cg@exept.de>
parents: 486
diff changeset
  3274
# endif
524
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  3275
# ifdef AF_ISO
1009
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  3276
    else if (myDomain == @symbol(iso)) {
524
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  3277
    }
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  3278
# endif
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  3279
# ifdef AF_NETBIOS
1009
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  3280
    else if (myDomain == @symbol(netbios)) {
530
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  3281
    }
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  3282
# endif
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  3283
# ifdef AF_IPX
1009
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  3284
    else if (myDomain == @symbol(ipx)) {
530
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  3285
    }
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  3286
# endif
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  3287
# ifdef AF_BRIDGE
1009
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  3288
    else if (myDomain == @symbol(bridge)) {
524
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  3289
    }
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  3290
# endif
571
191b37534643 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 563
diff changeset
  3291
# ifdef AF_BSC
1009
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  3292
    else if (myDomain == @symbol(bsc)) {
571
191b37534643 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 563
diff changeset
  3293
    }
191b37534643 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 563
diff changeset
  3294
# endif
812
c8101ea70e6c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 811
diff changeset
  3295
# ifdef AF_ROSE
1009
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  3296
    else if (myDomain == @symbol(rose)) {
812
c8101ea70e6c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 811
diff changeset
  3297
    }
c8101ea70e6c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 811
diff changeset
  3298
# endif
869
a6e5cbe9f558 preps for AF_IRDA
Claus Gittinger <cg@exept.de>
parents: 867
diff changeset
  3299
# ifdef AF_IRDA
1009
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  3300
    else if (myDomain == @symbol(irda)) {
869
a6e5cbe9f558 preps for AF_IRDA
Claus Gittinger <cg@exept.de>
parents: 867
diff changeset
  3301
    }
a6e5cbe9f558 preps for AF_IRDA
Claus Gittinger <cg@exept.de>
parents: 867
diff changeset
  3302
# endif
524
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  3303
# if defined(AF_CCITT) && (AF_CCITT != AF_X25)
1009
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  3304
    else if (myDomain == @symbol(ccitt)) {
524
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  3305
    }
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  3306
# endif
0
1cf8d1747859 Initial revision
claus
parents:
diff changeset
  3307
28
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  3308
    if (! ok) {
789
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3309
	DBGPRINTF(("SOCKET: unsupported domain\n"));
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3310
	RETURN (false);
28
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  3311
    }
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  3312
110
7af19ae8693b use new FILE* wrapper macros (based on externalAddress)
Claus Gittinger <cg@exept.de>
parents: 106
diff changeset
  3313
    sock = fileno(__FILEVal(t));
28
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  3314
506
11ef93d12870 support anonymous (OS_specified) ports. (for FTP-protocol)
Claus Gittinger <cg@exept.de>
parents: 486
diff changeset
  3315
# 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
  3316
    if (reuse == true) {
789
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3317
	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
  3318
	    DBGPRINTF(("SOCKET: setsockopt - SO_REUSEADDR failed\n"));
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3319
	}
28
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  3320
    }
506
11ef93d12870 support anonymous (OS_specified) ports. (for FTP-protocol)
Claus Gittinger <cg@exept.de>
parents: 486
diff changeset
  3321
# endif /* SO_REUSEADDR */
28
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  3322
117
03cefad7e40b UD socket example & interruptable bind
Claus Gittinger <cg@exept.de>
parents: 116
diff changeset
  3323
    __BEGIN_INTERRUPTABLE__
28
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  3324
    do {
789
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3325
	ret = bind(sock, (struct sockaddr *)&sa, sockaddr_size);
28
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  3326
    } while ((ret < 0) && (errno == EINTR));
117
03cefad7e40b UD socket example & interruptable bind
Claus Gittinger <cg@exept.de>
parents: 116
diff changeset
  3327
    __END_INTERRUPTABLE__
28
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  3328
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  3329
    if (ret < 0) {
789
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3330
	DBGPRINTF(("SOCKET: bind failed errno=%d\n", errno));
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3331
	__INST(lastErrorNumber) = __MKSMALLINT(errno);
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3332
	RETURN (false);
0
1cf8d1747859 Initial revision
claus
parents:
diff changeset
  3333
    }
506
11ef93d12870 support anonymous (OS_specified) ports. (for FTP-protocol)
Claus Gittinger <cg@exept.de>
parents: 486
diff changeset
  3334
11ef93d12870 support anonymous (OS_specified) ports. (for FTP-protocol)
Claus Gittinger <cg@exept.de>
parents: 486
diff changeset
  3335
    __INST(port) = portNrOrName; __STORE(self, portNrOrName);
11ef93d12870 support anonymous (OS_specified) ports. (for FTP-protocol)
Claus Gittinger <cg@exept.de>
parents: 486
diff changeset
  3336
1009
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  3337
    if (0) {
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  3338
	/* for else below */
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  3339
    }
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  3340
506
11ef93d12870 support anonymous (OS_specified) ports. (for FTP-protocol)
Claus Gittinger <cg@exept.de>
parents: 486
diff changeset
  3341
# ifdef AF_INET
1009
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  3342
    else if (myDomain == @symbol(inet)) {
789
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3343
	if (! __isSmallInteger(portNrOrName)
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3344
	 || (portNrOrName == __MKSMALLINT(0))) {
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3345
	    int p;
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3346
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3347
	    /*
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3348
	     * INET anonymous port - get the actual portNr
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3349
	     */
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3350
	    if (getsockname(sock, (struct sockaddr *)&sa, &sockaddr_size) < 0) {
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3351
		DBGPRINTF(("SOCKET: cannot get peername\n"));
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3352
	    } else {
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3353
		DBGPRINTF(("SOCKET: anon port=%x\n", sa.in.sin_port));
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3354
		p = ntohs(sa.in.sin_port);
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3355
		__INST(port) = __MKSMALLINT(p);
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3356
	    }
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3357
	}
506
11ef93d12870 support anonymous (OS_specified) ports. (for FTP-protocol)
Claus Gittinger <cg@exept.de>
parents: 486
diff changeset
  3358
    }
11ef93d12870 support anonymous (OS_specified) ports. (for FTP-protocol)
Claus Gittinger <cg@exept.de>
parents: 486
diff changeset
  3359
# endif
819
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
  3360
530
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  3361
# ifdef AF_INET6
1009
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  3362
    else if (myDomain == @symbol(inet6)) {
789
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3363
	if (! __isSmallInteger(portNrOrName)
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3364
	 || (portNrOrName == __MKSMALLINT(0))) {
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3365
	    int p;
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3366
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3367
	    /*
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3368
	     * INET6 anonymous port - get the actual portNr
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
	    if (getsockname(sock, (struct sockaddr *)&sa, &sockaddr_size) < 0) {
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3371
		DBGPRINTF(("SOCKET: cannot get peername\n"));
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3372
	    } else {
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3373
		DBGPRINTF(("SOCKET: anon port=%x\n", sa.in.sin_port));
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3374
		p = ntohs(sa.in6.sin6_port);
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3375
		__INST(port) = __MKSMALLINT(p);
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3376
	    }
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3377
	}
530
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  3378
    }
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  3379
# endif
819
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
  3380
530
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  3381
# ifdef AF_APPLETALK
1009
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  3382
    else if (myDomain == @symbol(appletalk)) {
789
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3383
	if (! __isSmallInteger(portNrOrName)
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3384
	 || (portNrOrName == __MKSMALLINT(0))) {
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3385
	    int p;
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3386
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3387
	    /*
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3388
	     * APPLETALK anonymous port - get the actual portNr
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
	    if (getsockname(sock, (struct sockaddr *)&sa, &sockaddr_size) < 0) {
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3391
		DBGPRINTF(("SOCKET: cannot get peername\n"));
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3392
	    } else {
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3393
		DBGPRINTF(("SOCKET: anon port=%x\n", sa.in.sin_port));
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3394
		p = sa.at.sat_port;
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3395
		__INST(port) = __MKSMALLINT(p);
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3396
	    }
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3397
	}
530
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  3398
    }
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  3399
# endif
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  3400
506
11ef93d12870 support anonymous (OS_specified) ports. (for FTP-protocol)
Claus Gittinger <cg@exept.de>
parents: 486
diff changeset
  3401
#else /* NO_SOCKET */
418
317e55c6c281 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 403
diff changeset
  3402
    RETURN (false);
506
11ef93d12870 support anonymous (OS_specified) ports. (for FTP-protocol)
Claus Gittinger <cg@exept.de>
parents: 486
diff changeset
  3403
#endif /* NO_SOCKET */
42
506596f9a1a8 *** empty log message ***
claus
parents: 38
diff changeset
  3404
%}.
28
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  3405
    ^ true
0
1cf8d1747859 Initial revision
claus
parents:
diff changeset
  3406
28
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  3407
    "
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  3408
     (Socket domain:#inet type:#stream)
789
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3409
	 bindTo:9999
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3410
	 address:nil
28
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  3411
    "
0
1cf8d1747859 Initial revision
claus
parents:
diff changeset
  3412
!
1cf8d1747859 Initial revision
claus
parents:
diff changeset
  3413
781
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  3414
closeFile
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  3415
    "low level close"
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  3416
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  3417
%{  /* NOCONTEXT */
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  3418
#ifndef NO_SOCKET
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  3419
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  3420
    OBJ t;
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  3421
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  3422
    t = __INST(filePointer);
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  3423
    if (t != nil) {
812
c8101ea70e6c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 811
diff changeset
  3424
	FILE *fp;
c8101ea70e6c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 811
diff changeset
  3425
c8101ea70e6c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 811
diff changeset
  3426
	fp = __FILEVal(t);
821
40b0b69bf4b5 more debugs; fixed at-addresses
Claus Gittinger <cg@exept.de>
parents: 820
diff changeset
  3427
	DBGFPRINTF((stderr, "socket fclose %x (%d)\n", fp, fileno(fp)));
812
c8101ea70e6c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 811
diff changeset
  3428
	fflush(fp);
c8101ea70e6c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 811
diff changeset
  3429
	/* shutdown(fileno(fp), 2); */
1035
5b0605675dc6 @globalfor classvar stuff
Stefan Vogel <sv@exept.de>
parents: 1029
diff changeset
  3430
	if (@global(FileOpenTrace) == true) {
876
69c9ed48daba *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 875
diff changeset
  3431
	    fprintf(stderr, "fclose [Socket] %x\n", fp);
69c9ed48daba *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 875
diff changeset
  3432
	}
812
c8101ea70e6c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 811
diff changeset
  3433
	fclose(fp);
c8101ea70e6c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 811
diff changeset
  3434
	__INST(filePointer) = nil;
781
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  3435
    }
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  3436
#endif
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  3437
%}
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  3438
!
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  3439
896
2ca43149a20e Ask for possible error after async connect.
Stefan Vogel <sv@exept.de>
parents: 888
diff changeset
  3440
getSocketError
2ca43149a20e Ask for possible error after async connect.
Stefan Vogel <sv@exept.de>
parents: 888
diff changeset
  3441
    "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
  3442
     result of an asynchronous operation"
2ca43149a20e Ask for possible error after async connect.
Stefan Vogel <sv@exept.de>
parents: 888
diff changeset
  3443
2ca43149a20e Ask for possible error after async connect.
Stefan Vogel <sv@exept.de>
parents: 888
diff changeset
  3444
%{
2ca43149a20e Ask for possible error after async connect.
Stefan Vogel <sv@exept.de>
parents: 888
diff changeset
  3445
    OBJ t;
2ca43149a20e Ask for possible error after async connect.
Stefan Vogel <sv@exept.de>
parents: 888
diff changeset
  3446
    int err;
2ca43149a20e Ask for possible error after async connect.
Stefan Vogel <sv@exept.de>
parents: 888
diff changeset
  3447
2ca43149a20e Ask for possible error after async connect.
Stefan Vogel <sv@exept.de>
parents: 888
diff changeset
  3448
    t = __INST(filePointer);
2ca43149a20e Ask for possible error after async connect.
Stefan Vogel <sv@exept.de>
parents: 888
diff changeset
  3449
    if (t == nil)
1009
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  3450
	err = EBADF;
896
2ca43149a20e Ask for possible error after async connect.
Stefan Vogel <sv@exept.de>
parents: 888
diff changeset
  3451
    else {
1009
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  3452
	int sz, fd;
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  3453
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  3454
	fd = fileno(__FILEVal(t));
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  3455
	sz = sizeof(err);
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  3456
	if (getsockopt(fd, SOL_SOCKET, SO_ERROR, &err, &sz) < 0)
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  3457
	    err = errno;
896
2ca43149a20e Ask for possible error after async connect.
Stefan Vogel <sv@exept.de>
parents: 888
diff changeset
  3458
    }
2ca43149a20e Ask for possible error after async connect.
Stefan Vogel <sv@exept.de>
parents: 888
diff changeset
  3459
2ca43149a20e Ask for possible error after async connect.
Stefan Vogel <sv@exept.de>
parents: 888
diff changeset
  3460
    RETURN(__MKSMALLINT(err));
2ca43149a20e Ask for possible error after async connect.
Stefan Vogel <sv@exept.de>
parents: 888
diff changeset
  3461
%}
2ca43149a20e Ask for possible error after async connect.
Stefan Vogel <sv@exept.de>
parents: 888
diff changeset
  3462
2ca43149a20e Ask for possible error after async connect.
Stefan Vogel <sv@exept.de>
parents: 888
diff changeset
  3463
2ca43149a20e Ask for possible error after async connect.
Stefan Vogel <sv@exept.de>
parents: 888
diff changeset
  3464
!
2ca43149a20e Ask for possible error after async connect.
Stefan Vogel <sv@exept.de>
parents: 888
diff changeset
  3465
781
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  3466
listenFor:aNumber
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  3467
    "same as listenWithBacklog: - for ST-80 compatibility"
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  3468
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  3469
    ^ self listenWithBacklog:aNumber
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  3470
!
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  3471
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  3472
listenWithBacklog:aNumber
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  3473
    "start listening; return true if ok, false on error"
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  3474
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  3475
    filePointer isNil ifTrue:[
789
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3476
	^ self errorNotOpen
781
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  3477
    ].
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  3478
%{
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  3479
#ifndef NO_SOCKET
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  3480
    OBJ fp = __INST(filePointer);
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  3481
    int sock;
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  3482
    int ret;
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
    if (! __isSmallInteger(aNumber)) {
789
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3485
	DBGPRINTF(("SOCKET: invalid arg\n"));
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3486
	RETURN (false);
781
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
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  3489
    sock = fileno(__FILEVal(fp));
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
    __BEGIN_INTERRUPTABLE__
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  3492
    do {
1009
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  3493
	ret = listen(sock, __intVal(aNumber));
781
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  3494
    } while ((ret < 0) && (errno == EINTR));
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  3495
    __END_INTERRUPTABLE__
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 (ret < 0) {
789
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3498
	DBGPRINTF(("SOCKET: listen call failed errno=%d\n", errno));
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3499
	__INST(lastErrorNumber) = __MKSMALLINT(errno);
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3500
	RETURN (false);
781
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
#else
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  3503
    RETURN (false);
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  3504
#endif
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  3505
%}.
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  3506
    ^ true
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  3507
!
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  3508
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  3509
shutDown 
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  3510
    "shutDown without flushing "
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  3511
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  3512
    filePointer isNil ifTrue:[^ self].
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  3513
    Lobby unregister:self.
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
%{
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  3516
#ifndef NO_SOCKET
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  3517
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  3518
    OBJ fp;
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  3519
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  3520
    fp = __INST(filePointer);
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  3521
    if (fp != nil) {
812
c8101ea70e6c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 811
diff changeset
  3522
	FILE *f;
c8101ea70e6c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 811
diff changeset
  3523
	int fd;
c8101ea70e6c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 811
diff changeset
  3524
c8101ea70e6c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 811
diff changeset
  3525
	__INST(filePointer) = nil;
c8101ea70e6c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 811
diff changeset
  3526
	f = __FILEVal(fp);
c8101ea70e6c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 811
diff changeset
  3527
	fd = fileno(f);
c8101ea70e6c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 811
diff changeset
  3528
	__BEGIN_INTERRUPTABLE__
c8101ea70e6c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 811
diff changeset
  3529
	shutdown(fd, 2);
821
40b0b69bf4b5 more debugs; fixed at-addresses
Claus Gittinger <cg@exept.de>
parents: 820
diff changeset
  3530
	DBGFPRINTF((stderr, "socket fclose %x (%d)\n", fp, fd));
1035
5b0605675dc6 @globalfor classvar stuff
Stefan Vogel <sv@exept.de>
parents: 1029
diff changeset
  3531
	if (@global(FileOpenTrace) == true) {
876
69c9ed48daba *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 875
diff changeset
  3532
	    fprintf(stderr, "fclose [Socket] %x\n", f);
69c9ed48daba *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 875
diff changeset
  3533
	}
812
c8101ea70e6c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 811
diff changeset
  3534
	fclose(f);
c8101ea70e6c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 811
diff changeset
  3535
	/* close(fd); */
c8101ea70e6c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 811
diff changeset
  3536
	__END_INTERRUPTABLE__
781
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  3537
    }
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  3538
#endif
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  3539
%}
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  3540
! !
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  3541
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  3542
!Socket methodsFor:'low level-accepting'!
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  3543
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  3544
accept
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  3545
    "create a new TCP socket from accepting on the receiver.
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  3546
     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
  3547
     For ST-80 compatibility"
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  3548
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  3549
    |newSock|
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
    newSock := self class new.
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  3552
    (newSock acceptOn:self) ifFalse:[^ nil].
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  3553
    ^ newSock
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
    "
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  3556
     |sock newSock|
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  3557
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  3558
     sock := Socket provide:8004.
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  3559
     sock listenFor:5.
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  3560
     newSock := sock accept.
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
!
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
acceptOn:aSocket
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  3565
    "accept a connection on a server port (created with:'Socket>>onIPPort:')
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  3566
     usage is: (Socket basicNew acceptOn:(Socket onIPPort:9999)).
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  3567
     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
  3568
     Return the true if ok; false if not."
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  3569
896
2ca43149a20e Ask for possible error after async connect.
Stefan Vogel <sv@exept.de>
parents: 888
diff changeset
  3570
    aSocket readWait.
2ca43149a20e Ask for possible error after async connect.
Stefan Vogel <sv@exept.de>
parents: 888
diff changeset
  3571
    ^ self primAcceptOn:aSocket
781
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  3572
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  3573
    "Modified: / 11.3.1996 / 14:21:31 / stefan"
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  3574
    "Modified: / 1.8.1998 / 23:39:10 / cg"
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
896
2ca43149a20e Ask for possible error after async connect.
Stefan Vogel <sv@exept.de>
parents: 888
diff changeset
  3577
primAcceptOn:aSocket
208
c3eca2cc16dc accept: do not wait for input on non-connected socket.
Stefan Vogel <sv@exept.de>
parents: 207
diff changeset
  3578
    "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
  3579
     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
  3580
     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
  3581
c3eca2cc16dc accept: do not wait for input on non-connected socket.
Stefan Vogel <sv@exept.de>
parents: 207
diff changeset
  3582
    |serverSocketFd|
c3eca2cc16dc accept: do not wait for input on non-connected socket.
Stefan Vogel <sv@exept.de>
parents: 207
diff changeset
  3583
c3eca2cc16dc accept: do not wait for input on non-connected socket.
Stefan Vogel <sv@exept.de>
parents: 207
diff changeset
  3584
    filePointer notNil ifTrue:[
1009
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  3585
	^ self errorAlreadyOpen
208
c3eca2cc16dc accept: do not wait for input on non-connected socket.
Stefan Vogel <sv@exept.de>
parents: 207
diff changeset
  3586
    ].
c3eca2cc16dc accept: do not wait for input on non-connected socket.
Stefan Vogel <sv@exept.de>
parents: 207
diff changeset
  3587
c3eca2cc16dc accept: do not wait for input on non-connected socket.
Stefan Vogel <sv@exept.de>
parents: 207
diff changeset
  3588
    domain := aSocket domain.
c3eca2cc16dc accept: do not wait for input on non-connected socket.
Stefan Vogel <sv@exept.de>
parents: 207
diff changeset
  3589
    socketType := aSocket type.
c3eca2cc16dc accept: do not wait for input on non-connected socket.
Stefan Vogel <sv@exept.de>
parents: 207
diff changeset
  3590
    serverSocketFd := aSocket fileDescriptor.
c3eca2cc16dc accept: do not wait for input on non-connected socket.
Stefan Vogel <sv@exept.de>
parents: 207
diff changeset
  3591
    serverSocketFd isNil ifTrue:[
1009
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  3592
	^ 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
  3593
    ].
c3eca2cc16dc accept: do not wait for input on non-connected socket.
Stefan Vogel <sv@exept.de>
parents: 207
diff changeset
  3594
    (serverSocketFd isMemberOf:SmallInteger) ifFalse:[
1009
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  3595
	^ 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
  3596
    ].
c3eca2cc16dc accept: do not wait for input on non-connected socket.
Stefan Vogel <sv@exept.de>
parents: 207
diff changeset
  3597
%{
418
317e55c6c281 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 403
diff changeset
  3598
#ifndef NO_SOCKET
208
c3eca2cc16dc accept: do not wait for input on non-connected socket.
Stefan Vogel <sv@exept.de>
parents: 207
diff changeset
  3599
    FILE *fp;
c3eca2cc16dc accept: do not wait for input on non-connected socket.
Stefan Vogel <sv@exept.de>
parents: 207
diff changeset
  3600
    int flags;
c3eca2cc16dc accept: do not wait for input on non-connected socket.
Stefan Vogel <sv@exept.de>
parents: 207
diff changeset
  3601
    int sock, newSock;
819
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
  3602
    union sockaddr_u sa;
464
600b101a7035 alen in accept
Claus Gittinger <cg@exept.de>
parents: 463
diff changeset
  3603
    int alen, alen0;
208
c3eca2cc16dc accept: do not wait for input on non-connected socket.
Stefan Vogel <sv@exept.de>
parents: 207
diff changeset
  3604
    struct hostent *he ;
c3eca2cc16dc accept: do not wait for input on non-connected socket.
Stefan Vogel <sv@exept.de>
parents: 207
diff changeset
  3605
    char dotted[20] ;
c3eca2cc16dc accept: do not wait for input on non-connected socket.
Stefan Vogel <sv@exept.de>
parents: 207
diff changeset
  3606
1009
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  3607
    if (0) {
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  3608
	/* for else below */
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  3609
    }
876
69c9ed48daba *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 875
diff changeset
  3610
# ifdef AF_INET
1009
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  3611
    else if (__INST(domain) == @symbol(inet)) {
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  3612
	alen0 = sizeof(sa.in);
464
600b101a7035 alen in accept
Claus Gittinger <cg@exept.de>
parents: 463
diff changeset
  3613
    }
876
69c9ed48daba *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 875
diff changeset
  3614
# endif
69c9ed48daba *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 875
diff changeset
  3615
# ifdef AF_INET6
1009
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  3616
    else if (__INST(domain) == @symbol(inet6)) {
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  3617
	alen0 = sizeof(sa.in6);
530
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  3618
    }
876
69c9ed48daba *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 875
diff changeset
  3619
# endif
69c9ed48daba *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 875
diff changeset
  3620
# ifdef AF_UNIX
1009
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  3621
    else if (__INST(domain) == @symbol(unix)) {
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  3622
	alen0 = sizeof(sa.un);
464
600b101a7035 alen in accept
Claus Gittinger <cg@exept.de>
parents: 463
diff changeset
  3623
    }
876
69c9ed48daba *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 875
diff changeset
  3624
# endif
530
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  3625
# ifdef AF_APPLETALK
1009
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  3626
    else if (__INST(domain) == @symbol(appletalk)) {
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  3627
	alen0 = sizeof(sa.at);
530
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  3628
    }
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  3629
# endif
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  3630
524
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  3631
    /*
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  3632
     * XXXX add addressing stuff for other domains here ...
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  3633
     */
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  3634
# ifdef AF_X25
1009
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  3635
    else if (__INST(domain) == @symbol(x25)) {
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  3636
	alen0 = sizeof(sa.x25);
819
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
  3637
    }
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
  3638
# endif
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
  3639
# ifdef AF_AX25
1009
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  3640
    else if (__INST(domain) == @symbol(ax25)) {
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  3641
	alen0 = sizeof(sa.ax25);
524
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  3642
    }
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  3643
# endif
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  3644
# ifdef AF_NS
1009
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  3645
    else if ((__INST(domain) == @symbol(ns)) 
812
c8101ea70e6c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 811
diff changeset
  3646
     || (__INST(domain) == @symbol(xns))) {
524
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  3647
    }
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  3648
# endif
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  3649
# ifdef AF_DECnet
1009
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  3650
    else if (__INST(domain) == @symbol(decnet)) {
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  3651
	alen0 = sizeof(sa.dn);
524
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  3652
    }
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  3653
# endif
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  3654
# ifdef AF_SNA
1009
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  3655
    else if (__INST(domain) == @symbol(sna)) {
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  3656
	alen0 = sizeof(sa.sna);
524
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  3657
    }
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  3658
# endif
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  3659
# ifdef AF_RAW
1009
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  3660
    else if (__INST(domain) == @symbol(raw)) {
524
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  3661
    }
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  3662
# endif
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  3663
# ifdef AF_ISO
1009
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  3664
    else if (__INST(domain) == @symbol(iso)) {
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_NETBIOS
1009
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  3668
    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
  3669
    }
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  3670
# endif
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  3671
# ifdef AF_IPX
1009
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  3672
    else if (__INST(domain) == @symbol(ipx)) {
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  3673
	alen0 = sizeof(sa.ipx);
530
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  3674
    }
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  3675
# endif
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  3676
# ifdef AF_BRIDGE
1009
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  3677
    else if (__INST(domain) == @symbol(bridge)) {
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
571
191b37534643 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 563
diff changeset
  3680
# ifdef AF_BSC
1009
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  3681
    else if (__INST(domain) == @symbol(bsc)) {
571
191b37534643 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 563
diff changeset
  3682
    }
191b37534643 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 563
diff changeset
  3683
# endif
812
c8101ea70e6c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 811
diff changeset
  3684
# ifdef AF_ROSE
1009
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  3685
    else if (__INST(domain) == @symbol(rose)) {
812
c8101ea70e6c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 811
diff changeset
  3686
    }
c8101ea70e6c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 811
diff changeset
  3687
# endif
869
a6e5cbe9f558 preps for AF_IRDA
Claus Gittinger <cg@exept.de>
parents: 867
diff changeset
  3688
# ifdef AF_IRDA
1009
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  3689
    else if (__INST(domain) == @symbol(irda)) {
869
a6e5cbe9f558 preps for AF_IRDA
Claus Gittinger <cg@exept.de>
parents: 867
diff changeset
  3690
    }
a6e5cbe9f558 preps for AF_IRDA
Claus Gittinger <cg@exept.de>
parents: 867
diff changeset
  3691
# endif
524
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  3692
# if defined(AF_CCITT) && (AF_CCITT != AF_X25)
1009
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  3693
    else if (__INST(domain) == @symbol(ccitt)) {
524
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  3694
    }
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  3695
# endif
464
600b101a7035 alen in accept
Claus Gittinger <cg@exept.de>
parents: 463
diff changeset
  3696
896
2ca43149a20e Ask for possible error after async connect.
Stefan Vogel <sv@exept.de>
parents: 888
diff changeset
  3697
2ca43149a20e Ask for possible error after async connect.
Stefan Vogel <sv@exept.de>
parents: 888
diff changeset
  3698
    sock = __intVal(serverSocketFd);
2ca43149a20e Ask for possible error after async connect.
Stefan Vogel <sv@exept.de>
parents: 888
diff changeset
  3699
2ca43149a20e Ask for possible error after async connect.
Stefan Vogel <sv@exept.de>
parents: 888
diff changeset
  3700
# if defined(O_NDELAY) && defined(SET_NDELAY)
2ca43149a20e Ask for possible error after async connect.
Stefan Vogel <sv@exept.de>
parents: 888
diff changeset
  3701
    flags = ioctl(sock, F_GETFL, 0);
2ca43149a20e Ask for possible error after async connect.
Stefan Vogel <sv@exept.de>
parents: 888
diff changeset
  3702
    ioctl(sock, F_SETFL, flags | O_NDELAY);
2ca43149a20e Ask for possible error after async connect.
Stefan Vogel <sv@exept.de>
parents: 888
diff changeset
  3703
# endif
2ca43149a20e Ask for possible error after async connect.
Stefan Vogel <sv@exept.de>
parents: 888
diff changeset
  3704
208
c3eca2cc16dc accept: do not wait for input on non-connected socket.
Stefan Vogel <sv@exept.de>
parents: 207
diff changeset
  3705
    __BEGIN_INTERRUPTABLE__
c3eca2cc16dc accept: do not wait for input on non-connected socket.
Stefan Vogel <sv@exept.de>
parents: 207
diff changeset
  3706
    do {
1009
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  3707
	alen = alen0;
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  3708
	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
  3709
    } 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
  3710
    __END_INTERRUPTABLE__
821
40b0b69bf4b5 more debugs; fixed at-addresses
Claus Gittinger <cg@exept.de>
parents: 820
diff changeset
  3711
    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
  3712
876
69c9ed48daba *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 875
diff changeset
  3713
# 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
  3714
    ioctl(sock, F_SETFL, flags);
876
69c9ed48daba *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 875
diff changeset
  3715
# endif
208
c3eca2cc16dc accept: do not wait for input on non-connected socket.
Stefan Vogel <sv@exept.de>
parents: 207
diff changeset
  3716
c3eca2cc16dc accept: do not wait for input on non-connected socket.
Stefan Vogel <sv@exept.de>
parents: 207
diff changeset
  3717
    if (newSock < 0) {
1009
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  3718
	DBGPRINTF(("SOCKET: accept call failed errno=%d\n", errno));
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  3719
	__INST(lastErrorNumber) = __MKSMALLINT(errno);
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  3720
	RETURN (false);
208
c3eca2cc16dc accept: do not wait for input on non-connected socket.
Stefan Vogel <sv@exept.de>
parents: 207
diff changeset
  3721
    }
c3eca2cc16dc accept: do not wait for input on non-connected socket.
Stefan Vogel <sv@exept.de>
parents: 207
diff changeset
  3722
c3eca2cc16dc accept: do not wait for input on non-connected socket.
Stefan Vogel <sv@exept.de>
parents: 207
diff changeset
  3723
    /*
c3eca2cc16dc accept: do not wait for input on non-connected socket.
Stefan Vogel <sv@exept.de>
parents: 207
diff changeset
  3724
     * extract the partners address
c3eca2cc16dc accept: do not wait for input on non-connected socket.
Stefan Vogel <sv@exept.de>
parents: 207
diff changeset
  3725
     */
1009
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  3726
    if (0) {
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  3727
	/* for else below */
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  3728
    }
876
69c9ed48daba *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 875
diff changeset
  3729
# ifdef AF_INET
1009
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  3730
    else if (__INST(domain) == @symbol(inet)) {
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  3731
	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
  3732
	if (! he) {
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  3733
	    unsigned long norder;
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  3734
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  3735
	    norder = htonl(sa.in.sin_addr.s_addr) ;
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  3736
	    sprintf(dotted, "%d.%d.%d.%d",
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  3737
		    (norder >> 24) & 0xFF,
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  3738
		    (norder >> 16) & 0xFF,
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  3739
		    (norder >> 8) & 0xFF,
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  3740
		    norder & 0xFF);
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  3741
	}
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  3742
	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
  3743
	__INST(peerName) = __MKSTRING((he ? he->h_name : dotted));
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  3744
	__STORESELF(peerName);
208
c3eca2cc16dc accept: do not wait for input on non-connected socket.
Stefan Vogel <sv@exept.de>
parents: 207
diff changeset
  3745
    }
876
69c9ed48daba *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 875
diff changeset
  3746
# endif
69c9ed48daba *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 875
diff changeset
  3747
69c9ed48daba *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 875
diff changeset
  3748
# ifdef AF_INET6
1009
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  3749
    else if (__INST(domain) == @symbol(inet6)) {
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  3750
	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
  3751
	if (! he) {
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  3752
	    unsigned long norder;
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  3753
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
	     * XXX: what is inet6's naming convention ?
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  3756
	     */
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  3757
	    norder = htonl(sa.in.sin_addr.s_addr) ;
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  3758
	    sprintf(dotted, "%d.%d.%d.%d.%d.%d...",
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  3759
		    sa.in6.sin6_addr.s6_addr[0],
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  3760
		    sa.in6.sin6_addr.s6_addr[1],
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  3761
		    sa.in6.sin6_addr.s6_addr[2],
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  3762
		    sa.in6.sin6_addr.s6_addr[3],
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  3763
		    sa.in6.sin6_addr.s6_addr[4],
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  3764
		    sa.in6.sin6_addr.s6_addr[5]);
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  3765
	}
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  3766
	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
  3767
	__INST(peerName) = __MKSTRING((he ? he->h_name : dotted));
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  3768
	__STORESELF(peerName);
530
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  3769
    }
876
69c9ed48daba *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 875
diff changeset
  3770
# endif
69c9ed48daba *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 875
diff changeset
  3771
69c9ed48daba *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 875
diff changeset
  3772
# ifdef AF_UNIX
1009
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  3773
    else if (__INST(domain) == @symbol(unix)) {
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  3774
	DBGPRINTF(("SOCKET: accepted connection on unix socket\n")) ;
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  3775
	/* 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
  3776
    }
876
69c9ed48daba *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 875
diff changeset
  3777
# endif
69c9ed48daba *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 875
diff changeset
  3778
69c9ed48daba *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 875
diff changeset
  3779
# ifdef AF_APPLETALK
1009
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  3780
    else if (__INST(domain) == @symbol(appletalk)) {
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  3781
	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
  3782
	if (! he) {
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  3783
	    unsigned net;
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  3784
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  3785
	    /*
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  3786
	     * XXX: what is apples naming convention ?
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  3787
	     */
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  3788
	    net = htons(sa.at.sat_addr.s_net) ;
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  3789
	    sprintf(dotted, "%d.%d",
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  3790
		    net,
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  3791
		    sa.at.sat_addr.s_node);
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  3792
	}
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  3793
	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
  3794
	__INST(peerName) = __MKSTRING((he ? he->h_name : dotted));
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  3795
	__STORESELF(peerName);
530
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  3796
    }
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  3797
# endif
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  3798
524
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  3799
    /*
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  3800
     * XXXX add addressing stuff for other domains here ...
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  3801
     */
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  3802
# ifdef AF_X25
1009
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  3803
    else if (__INST(domain) == @symbol(x25)) {
524
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  3804
    }
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  3805
# endif
819
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
  3806
# ifdef AF_AX25
1009
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  3807
    else if (__INST(domain) == @symbol(ax25)) {
819
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
  3808
    }
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
  3809
# endif
524
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  3810
# ifdef AF_NS
1009
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  3811
    else if ((__INST(domain) == @symbol(ns)) 
812
c8101ea70e6c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 811
diff changeset
  3812
     || (__INST(domain) == @symbol(xns))) {
524
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  3813
    }
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  3814
# endif
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  3815
# ifdef AF_DECnet
1009
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  3816
    else if (__INST(domain) == @symbol(decnet)) {
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
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  3819
# ifdef AF_SNA
1009
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  3820
    else if (__INST(domain) == @symbol(sna)) {
524
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  3821
    }
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  3822
# endif
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  3823
# ifdef AF_RAW
1009
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  3824
    else if (__INST(domain) == @symbol(raw)) {
524
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  3825
    }
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  3826
# endif
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  3827
# ifdef AF_ISO
1009
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  3828
    else if (__INST(domain) == @symbol(iso)) {
524
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  3829
    }
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  3830
# endif
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  3831
# ifdef AF_NETBIOS
1009
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  3832
    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
  3833
    }
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  3834
# endif
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  3835
# ifdef AF_IPX
1009
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  3836
    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
  3837
    }
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  3838
# endif
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  3839
# ifdef AF_BRIDGE
1009
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  3840
    else if (__INST(domain) == @symbol(bridge)) {
524
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  3841
    }
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  3842
# endif
571
191b37534643 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 563
diff changeset
  3843
# ifdef AF_BSC
1009
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  3844
    else if (__INST(domain) == @symbol(bsc)) {
571
191b37534643 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 563
diff changeset
  3845
    }
191b37534643 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 563
diff changeset
  3846
# endif
812
c8101ea70e6c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 811
diff changeset
  3847
# ifdef AF_ROSE
1009
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  3848
    else if (__INST(domain) == @symbol(rose)) {
812
c8101ea70e6c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 811
diff changeset
  3849
    }
c8101ea70e6c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 811
diff changeset
  3850
# endif
869
a6e5cbe9f558 preps for AF_IRDA
Claus Gittinger <cg@exept.de>
parents: 867
diff changeset
  3851
# ifdef AF_IRDA
1009
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  3852
    else if (__INST(domain) == @symbol(irda)) {
869
a6e5cbe9f558 preps for AF_IRDA
Claus Gittinger <cg@exept.de>
parents: 867
diff changeset
  3853
    }
a6e5cbe9f558 preps for AF_IRDA
Claus Gittinger <cg@exept.de>
parents: 867
diff changeset
  3854
# endif
524
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  3855
# if defined(AF_CCITT) && (AF_CCITT != AF_X25)
1009
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  3856
    else if (__INST(domain) == @symbol(ccitt)) {
524
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  3857
    }
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  3858
# endif
208
c3eca2cc16dc accept: do not wait for input on non-connected socket.
Stefan Vogel <sv@exept.de>
parents: 207
diff changeset
  3859
c3eca2cc16dc accept: do not wait for input on non-connected socket.
Stefan Vogel <sv@exept.de>
parents: 207
diff changeset
  3860
    /* 
c3eca2cc16dc accept: do not wait for input on non-connected socket.
Stefan Vogel <sv@exept.de>
parents: 207
diff changeset
  3861
     * make it a FILE * 
c3eca2cc16dc accept: do not wait for input on non-connected socket.
Stefan Vogel <sv@exept.de>
parents: 207
diff changeset
  3862
     */
c3eca2cc16dc accept: do not wait for input on non-connected socket.
Stefan Vogel <sv@exept.de>
parents: 207
diff changeset
  3863
    fp = fdopen(newSock, "r+");
c3eca2cc16dc accept: do not wait for input on non-connected socket.
Stefan Vogel <sv@exept.de>
parents: 207
diff changeset
  3864
    if (! fp) {
1009
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  3865
	DBGPRINTF(("SOCKET: fdopen call failed\n"));
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  3866
	__INST(lastErrorNumber) = __MKSMALLINT(errno);
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  3867
	close(newSock);
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  3868
	DBGFPRINTF((stderr, "socket close (fdopen failed) (%d)\n", newSock));
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  3869
	RETURN (false);
876
69c9ed48daba *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 875
diff changeset
  3870
    }
1035
5b0605675dc6 @globalfor classvar stuff
Stefan Vogel <sv@exept.de>
parents: 1029
diff changeset
  3871
    if (@global(FileOpenTrace) == true) {
1009
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  3872
	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
  3873
    }
876
69c9ed48daba *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 875
diff changeset
  3874
69c9ed48daba *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 875
diff changeset
  3875
# ifdef BUGGY_STDIO_LIB
69c9ed48daba *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 875
diff changeset
  3876
    setbuf(fp, NULL);
69c9ed48daba *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 875
diff changeset
  3877
    __INST(buffered) = false;
69c9ed48daba *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 875
diff changeset
  3878
# endif
69c9ed48daba *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 875
diff changeset
  3879
69c9ed48daba *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 875
diff changeset
  3880
    __INST(filePointer) = __MKOBJ(fp);
69c9ed48daba *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 875
diff changeset
  3881
    __STORESELF(filePointer);
69c9ed48daba *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 875
diff changeset
  3882
#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
  3883
%}.
c3eca2cc16dc accept: do not wait for input on non-connected socket.
Stefan Vogel <sv@exept.de>
parents: 207
diff changeset
  3884
    mode := #readwrite.
c3eca2cc16dc accept: do not wait for input on non-connected socket.
Stefan Vogel <sv@exept.de>
parents: 207
diff changeset
  3885
    Lobby register:self.
c3eca2cc16dc accept: do not wait for input on non-connected socket.
Stefan Vogel <sv@exept.de>
parents: 207
diff changeset
  3886
    binary := false.
c3eca2cc16dc accept: do not wait for input on non-connected socket.
Stefan Vogel <sv@exept.de>
parents: 207
diff changeset
  3887
    port := aSocket port.
c3eca2cc16dc accept: do not wait for input on non-connected socket.
Stefan Vogel <sv@exept.de>
parents: 207
diff changeset
  3888
    ^ true
c3eca2cc16dc accept: do not wait for input on non-connected socket.
Stefan Vogel <sv@exept.de>
parents: 207
diff changeset
  3889
!
c3eca2cc16dc accept: do not wait for input on non-connected socket.
Stefan Vogel <sv@exept.de>
parents: 207
diff changeset
  3890
781
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  3891
waitForNewConnectionOrDataOnAny:otherConnections timeout:timeoutSeconds
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  3892
    "suspend the current process, until either a new connection comes
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  3893
     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
  3894
     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
  3895
     For an old connection, that socket is returned.
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  3896
     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
  3897
     or nil, if a timeout occured.
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  3898
     This method implements the inner wait-primitive of a multi-connection 
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  3899
     server application."
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  3900
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  3901
    "/ first, a quick check if data is already available
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  3902
1035
5b0605675dc6 @globalfor classvar stuff
Stefan Vogel <sv@exept.de>
parents: 1029
diff changeset
  3903
    |wasBlocked sema|
781
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  3904
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  3905
    self canReadWithoutBlocking ifTrue:[
789
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3906
	^ self accept.
781
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  3907
    ].
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  3908
    otherConnections do:[:aConnection |
789
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3909
	aConnection canReadWithoutBlocking ifTrue:[
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3910
	    ^ aConnection
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3911
	]
781
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  3912
    ].
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
    [
789
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3915
	"/ check again - prevent incoming interrupts from disturbing our setup
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3916
	wasBlocked := OperatingSystem blockInterrupts.
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3917
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3918
	self canReadWithoutBlocking ifTrue:[
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3919
	    wasBlocked ifFalse:[OperatingSystem unblockInterrupts].
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3920
	    ^ self accept.
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3921
	].
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3922
	otherConnections do:[:aConnection |
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3923
	    aConnection canReadWithoutBlocking ifTrue:[
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3924
		wasBlocked ifFalse:[OperatingSystem unblockInterrupts].
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3925
		^ aConnection
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3926
	    ]
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3927
	].
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3928
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3929
	"/ nope - must wait.
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3930
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3931
	sema := Semaphore new name:'multiReadWait'.
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3932
	otherConnections do:[:aConnection |
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3933
	    Processor signal:sema onInput:(aConnection fileDescriptor).
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3934
	].
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3935
	Processor signal:sema onInput:(self fileDescriptor).
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3936
	timeoutSeconds notNil ifTrue:[
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3937
	    Processor signal:sema afterSeconds:timeoutSeconds 
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3938
	].
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3939
	Processor activeProcess state:#ioWait.
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3940
	sema wait.
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3941
	Processor disableSemaphore:sema.
781
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  3942
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  3943
    ] valueOnUnwindDo:[
789
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3944
	Processor disableSemaphore:sema.
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3945
	wasBlocked ifFalse:[OperatingSystem unblockInterrupts].
781
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  3946
    ].
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  3947
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  3948
    "/ see who it was ...
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  3949
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  3950
    self canReadWithoutBlocking ifTrue:[
789
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3951
	^ self accept.
781
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  3952
    ].
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  3953
    otherConnections do:[:aConnection |
789
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3954
	aConnection canReadWithoutBlocking ifTrue:[
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3955
	    ^ aConnection
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  3956
	]
781
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  3957
    ].
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
    "/ none - a timeout
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  3960
    ^ nil
867
56ca0cc52fa7 category renamining
Claus Gittinger <cg@exept.de>
parents: 859
diff changeset
  3961
!
56ca0cc52fa7 category renamining
Claus Gittinger <cg@exept.de>
parents: 859
diff changeset
  3962
56ca0cc52fa7 category renamining
Claus Gittinger <cg@exept.de>
parents: 859
diff changeset
  3963
waitForNewConnectionWithTimeout:timeoutSeconds
56ca0cc52fa7 category renamining
Claus Gittinger <cg@exept.de>
parents: 859
diff changeset
  3964
    "suspend the current process, until a new connection comes
56ca0cc52fa7 category renamining
Claus Gittinger <cg@exept.de>
parents: 859
diff changeset
  3965
     in at the receiver or a timeout occurs.
56ca0cc52fa7 category renamining
Claus Gittinger <cg@exept.de>
parents: 859
diff changeset
  3966
     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
  3967
     Returns nil, if a timeout occured.
56ca0cc52fa7 category renamining
Claus Gittinger <cg@exept.de>
parents: 859
diff changeset
  3968
     This method implements the inner wait-primitive of a single-connection 
56ca0cc52fa7 category renamining
Claus Gittinger <cg@exept.de>
parents: 859
diff changeset
  3969
     server application."
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
    (self readWaitWithTimeout:timeoutSeconds) ifTrue:[
56ca0cc52fa7 category renamining
Claus Gittinger <cg@exept.de>
parents: 859
diff changeset
  3972
	"/ a timeout occurred - no connection within timeout
56ca0cc52fa7 category renamining
Claus Gittinger <cg@exept.de>
parents: 859
diff changeset
  3973
	^ nil
56ca0cc52fa7 category renamining
Claus Gittinger <cg@exept.de>
parents: 859
diff changeset
  3974
    ].
56ca0cc52fa7 category renamining
Claus Gittinger <cg@exept.de>
parents: 859
diff changeset
  3975
    ^ self accept.
781
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  3976
! !
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  3977
4d61e7588ff3 added #waitForNewConnectionOrDataOnAny:timeout:
Claus Gittinger <cg@exept.de>
parents: 776
diff changeset
  3978
!Socket methodsFor:'low level-connecting'!
99
7d016cc30052 fixed & moved pingWalk from SNMPSession to here;
Claus Gittinger <cg@exept.de>
parents: 98
diff changeset
  3979
116
7789fb1c9fa2 more UD socket fixes (at least client side seems to work now)
Claus Gittinger <cg@exept.de>
parents: 115
diff changeset
  3980
connectTo:hostOrPathName port:portNrOrName
71
claus
parents: 63
diff changeset
  3981
    "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
  3982
     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
  3983
     Other sockets are not yet implemented.
71
claus
parents: 63
diff changeset
  3984
     Return true if ok, false otherwise.
99
7d016cc30052 fixed & moved pingWalk from SNMPSession to here;
Claus Gittinger <cg@exept.de>
parents: 98
diff changeset
  3985
     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
  3986
     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
  3987
     is established. 
7789fb1c9fa2 more UD socket fixes (at least client side seems to work now)
Claus Gittinger <cg@exept.de>
parents: 115
diff changeset
  3988
     See also: #connectTo:port:withTimeout: for a somewhat nicer interface."
28
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  3989
896
2ca43149a20e Ask for possible error after async connect.
Stefan Vogel <sv@exept.de>
parents: 888
diff changeset
  3990
    ^ self connectTo:hostOrPathName port:portNrOrName withTimeout:nil
649
1bc56594db85 fixed connect for sun/irix
Claus Gittinger <cg@exept.de>
parents: 648
diff changeset
  3991
!
1bc56594db85 fixed connect for sun/irix
Claus Gittinger <cg@exept.de>
parents: 648
diff changeset
  3992
896
2ca43149a20e Ask for possible error after async connect.
Stefan Vogel <sv@exept.de>
parents: 888
diff changeset
  3993
connectTo:hostOrPathName port:portNrOrName withTimeout:timeout
649
1bc56594db85 fixed connect for sun/irix
Claus Gittinger <cg@exept.de>
parents: 648
diff changeset
  3994
    "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
  3995
     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
  3996
     Other sockets are not yet implemented.
1bc56594db85 fixed connect for sun/irix
Claus Gittinger <cg@exept.de>
parents: 648
diff changeset
  3997
     Return true if ok, false otherwise.
1bc56594db85 fixed connect for sun/irix
Claus Gittinger <cg@exept.de>
parents: 648
diff changeset
  3998
     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
  3999
     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
  4000
     is established. 
1bc56594db85 fixed connect for sun/irix
Claus Gittinger <cg@exept.de>
parents: 648
diff changeset
  4001
     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
  4002
896
2ca43149a20e Ask for possible error after async connect.
Stefan Vogel <sv@exept.de>
parents: 888
diff changeset
  4003
    |isAsync err|
430
12d736316f69 Fix #connectTo:port: Do not call connect() when we get EINPROGRESS
Stefan Vogel <sv@exept.de>
parents: 429
diff changeset
  4004
28
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  4005
    filePointer isNil ifTrue:[
1009
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  4006
	^ self errorNotOpen
28
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  4007
    ].
0
1cf8d1747859 Initial revision
claus
parents:
diff changeset
  4008
%{
649
1bc56594db85 fixed connect for sun/irix
Claus Gittinger <cg@exept.de>
parents: 648
diff changeset
  4009
418
317e55c6c281 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 403
diff changeset
  4010
#ifndef NO_SOCKET
217
fcfbc9f71048 underscore cleanup
Claus Gittinger <cg@exept.de>
parents: 209
diff changeset
  4011
    OBJ t = __INST(filePointer);
71
claus
parents: 63
diff changeset
  4012
    OBJ myDomain;
819
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
  4013
    union sockaddr_u sa;
28
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  4014
    struct hostent *hp ;
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  4015
    int a, sock ;
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  4016
    long addr;
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  4017
    FILE *fp;
649
1bc56594db85 fixed connect for sun/irix
Claus Gittinger <cg@exept.de>
parents: 648
diff changeset
  4018
    int ret, oldFlags;
28
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  4019
    int on = 1;
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  4020
    int ok;
115
a9d85df931c4 added Unix domain support
Claus Gittinger <cg@exept.de>
parents: 112
diff changeset
  4021
    int sockaddr_size;
28
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  4022
217
fcfbc9f71048 underscore cleanup
Claus Gittinger <cg@exept.de>
parents: 209
diff changeset
  4023
    if (!__isString(__INST(domain)) && !__isSymbol(__INST(domain))) {
1009
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  4024
	DBGPRINTF(("SOCKET: invalid domain arg\n"));
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  4025
	RETURN (false);
28
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  4026
    }
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  4027
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  4028
    ok = 0;
217
fcfbc9f71048 underscore cleanup
Claus Gittinger <cg@exept.de>
parents: 209
diff changeset
  4029
    myDomain = __INST(domain);
115
a9d85df931c4 added Unix domain support
Claus Gittinger <cg@exept.de>
parents: 112
diff changeset
  4030
    bzero((char *) &sa, sizeof(sa)) ;
508
55d1e49c7157 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 507
diff changeset
  4031
1009
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  4032
    if (0) {
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  4033
	/* for ese below */
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  4034
    }
28
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  4035
#ifdef AF_INET
1009
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  4036
    else if (myDomain == @symbol(inet)) {
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  4037
	/*
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  4038
	 * INET addressing: port must be a smallInteger;
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  4039
	 * hostOrPathName the name of the host (dot notation allowed)
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  4040
	 * or a byteArray containing the 4 address bytes.
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  4041
	 */
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  4042
	if (! __isSmallInteger(portNrOrName)) {
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  4043
	    DBGPRINTF(("SOCKET: invalid port arg\n"));
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  4044
	    RETURN (false);
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  4045
	}
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
	sa.in.sin_family = AF_INET;
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  4048
	sa.in.sin_port = htons((u_short) __intVal(portNrOrName)) ;
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  4049
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  4050
	if (__isByteArray(hostOrPathName)) {
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  4051
	    unsigned char *cp;
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  4052
	    int n;
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  4053
	    unsigned intAddr;
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
	    cp = __ByteArrayInstPtr(hostOrPathName)->ba_element;
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  4056
	    n = __byteArraySize(hostOrPathName);
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  4057
	    if (n < 4) {
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  4058
		DBGPRINTF(("SOCKET: invalid ipAddr arg\n"));
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  4059
		RETURN (false);
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  4060
	    }
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  4061
	    intAddr = cp[0];
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  4062
	    intAddr = (intAddr << 8) | cp[1];
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  4063
	    intAddr = (intAddr << 8) | cp[2];
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  4064
	    intAddr = (intAddr << 8) | cp[3];
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  4065
	    sa.in.sin_addr.s_addr = htonl(intAddr);
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  4066
	    /* bcopy(cp, &sa.in.sin_addr.s_addr, n); */
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  4067
	} else {
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  4068
	    if (! __isString(hostOrPathName)) {
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  4069
		DBGPRINTF(("SOCKET: invalid hostname arg\n"));
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  4070
		RETURN (false);
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  4071
	    }
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  4072
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  4073
	    if ((addr = inet_addr(__stringVal(hostOrPathName))) != -1) {
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  4074
		/* 
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  4075
		 * is Internet addr in octet notation 
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  4076
		 */
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  4077
		bcopy(&addr, (char *) &sa.in.sin_addr, sizeof(addr)) ; /* set address */
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  4078
	    } else {
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  4079
		/* 
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  4080
		 * do we know the host's address? 
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
		GETHOSTBYNAME(hp, __stringVal(hostOrPathName))
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  4083
		if (hp == NULL) {
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  4084
		    DBGPRINTF(("SOCKET: unknown host:%s\n", __stringVal(hostOrPathName)));
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  4085
		    RETURN (false);
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  4086
		}
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  4087
		bcopy(hp->h_addr, (char *) &sa.in.sin_addr, hp->h_length) ;
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  4088
		sa.in.sin_family = hp->h_addrtype;
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  4089
	    }
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
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  4092
	DBGPRINTF(("SOCKET: connect addr:%d.%d.%d.%d port: %d\n", 
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  4093
			((unsigned char *)(&sa.in.sin_addr.s_addr))[0], 
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  4094
			((unsigned char *)(&sa.in.sin_addr.s_addr))[1], 
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  4095
			((unsigned char *)(&sa.in.sin_addr.s_addr))[2], 
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  4096
			((unsigned char *)(&sa.in.sin_addr.s_addr))[3], 
962
ab54bea0b102 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 961
diff changeset
  4097
			ntohs(sa.in.sin_port)));
896
2ca43149a20e Ask for possible error after async connect.
Stefan Vogel <sv@exept.de>
parents: 888
diff changeset
  4098
1009
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  4099
	sockaddr_size = sizeof(struct sockaddr_in);
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  4100
	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
  4101
    }
525
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  4102
#endif /* AF_INET */
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  4103
530
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  4104
#ifdef AF_INET6
1009
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  4105
    else if (myDomain == @symbol(inet6)) {
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  4106
	/*
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  4107
	 * INET6 addressing: port must be a smallInteger;
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  4108
	 * hostOrPathName the name of the host
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  4109
	 * or a byteArray containing the address bytes.
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  4110
	 */
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  4111
	if (! __isSmallInteger(portNrOrName)) {
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  4112
	    DBGPRINTF(("SOCKET: invalid port arg\n"));
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  4113
	    RETURN (false);
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  4114
	}
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
	sa.in6.sin6_family = AF_INET6;
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  4117
	sa.in6.sin6_port = htons((u_short) __intVal(portNrOrName)) ;
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  4118
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  4119
	if (__isByteArray(hostOrPathName)) {
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  4120
	    unsigned char *cp;
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  4121
	    int n;
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  4122
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  4123
	    cp = __ByteArrayInstPtr(hostOrPathName)->ba_element;
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  4124
	    n = __byteArraySize(hostOrPathName);
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  4125
	    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
  4126
	    bcopy(cp, sa.in6.sin6_addr.s6_addr, n);
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  4127
	} else {
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  4128
	    if (! __isString(hostOrPathName)) {
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  4129
		DBGPRINTF(("SOCKET: invalid hostname arg\n"));
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  4130
		RETURN (false);
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
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  4133
	    /* 
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  4134
	     * do we know the host's address? 
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  4135
	     */
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  4136
	    GETHOSTBYNAME(hp, __stringVal(hostOrPathName))
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  4137
	    if (hp == NULL) {
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  4138
		DBGPRINTF(("SOCKET: unknown host:%s\n", __stringVal(hostOrPathName)));
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
	    bcopy(hp->h_addr, (char *) &sa.in.sin_addr, hp->h_length) ;
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  4142
	    sa.in.sin_family = hp->h_addrtype;
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  4143
	}
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
	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
  4146
		sa.in6.sin6_addr.s6_addr[0],
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  4147
		sa.in6.sin6_addr.s6_addr[1],
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  4148
		sa.in6.sin6_addr.s6_addr[2],
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  4149
		sa.in6.sin6_addr.s6_addr[3],
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  4150
		sa.in6.sin6_addr.s6_addr[4],
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  4151
		sa.in6.sin6_addr.s6_addr[5],
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  4152
		sa.in6.sin6_port));
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
	sockaddr_size = sizeof(struct sockaddr_in6);
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  4155
	ok = 1;
530
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  4156
    }
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  4157
#endif /* AF_INET6 */
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  4158
116
7789fb1c9fa2 more UD socket fixes (at least client side seems to work now)
Claus Gittinger <cg@exept.de>
parents: 115
diff changeset
  4159
#ifdef AF_UNIX
1009
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  4160
    else if (myDomain == @symbol(unix)) {
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  4161
	char *pathName;
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  4162
	int l;
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  4163
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  4164
	/*
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  4165
	 * UNIX domain: port is ignored;
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  4166
	 * hostOrPathName is a pathName
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  4167
	 */
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  4168
	if (! __isString(hostOrPathName)) {
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  4169
	    DBGPRINTF(("SOCKET: invalid port (pathname) arg\n"));
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  4170
	    RETURN (false);
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  4171
	}
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  4172
	pathName = (char *) __stringVal(hostOrPathName);
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  4173
	l = strlen(pathName);
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  4174
	if ((l + sizeof ( sa.un.sun_family )) > sizeof(struct sockaddr_un)) {
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  4175
	    DBGPRINTF(("SOCKET: pathname too long\n"));
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  4176
	    RETURN (false);
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  4177
	}
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  4178
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  4179
	strcpy(sa.un.sun_path, pathName);
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  4180
	sa.un.sun_family = AF_UNIX;
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  4181
	sockaddr_size = l + sizeof ( sa.un.sun_family );
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  4182
	ok = 1;
28
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  4183
    }
525
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  4184
#endif /* AF_UNIX */
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  4185
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  4186
#ifdef AF_APPLETALK
1009
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  4187
    else if (myDomain == @symbol(appletalk)) {
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  4188
	/*
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  4189
	 * APPLETALK addressing: port must be a smallInteger;
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  4190
	 * hostOrPathName the name of the host
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  4191
	 * or a byteArray containing the 3 address bytes.
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  4192
	 */
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  4193
	if (! __isSmallInteger(portNrOrName)) {
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  4194
	    DBGPRINTF(("SOCKET: invalid port arg\n"));
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  4195
	    RETURN (false);
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  4196
	}
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
	sa.at.sat_family = AF_APPLETALK;
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  4199
	sa.at.sat_port = __intVal(portNrOrName);
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  4200
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  4201
	if (__isByteArray(hostOrPathName)) {
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  4202
	    unsigned char *cp;
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  4203
	    int n;
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  4204
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  4205
	    cp = __ByteArrayInstPtr(hostOrPathName)->ba_element;
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  4206
	    n = __byteArraySize(hostOrPathName);
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  4207
	    if (n > 3) n = 3;
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  4208
	    bcopy(cp, &sa.at.sat_addr, n);
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  4209
	} else {
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  4210
	    if (! __isString(hostOrPathName)) {
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  4211
		DBGPRINTF(("SOCKET: invalid hostname arg\n"));
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  4212
		RETURN (false);
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
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  4215
	    /* 
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  4216
	     * do we know the host's address? 
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  4217
	     */
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  4218
	    GETHOSTBYNAME(hp, __stringVal(hostOrPathName))
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  4219
	    if (hp == NULL) {
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  4220
		DBGPRINTF(("SOCKET: unknown host:%s\n", __stringVal(hostOrPathName)));
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
	    if (hp->h_addrtype != AF_APPLETALK) {
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  4224
		DBGPRINTF(("SOCKET: host:%s is not an appletalk host\n", __stringVal(hostOrPathName)));
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  4225
		RETURN (false);
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
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  4228
	    bcopy(hp->h_addr, (char *) &sa.at.sat_addr, hp->h_length) ;
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  4229
	    sa.at.sat_family = hp->h_addrtype;
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  4230
	}
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
	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
  4233
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  4234
	sockaddr_size = sizeof(struct sockaddr_at);
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  4235
	ok = 1;
525
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  4236
    }
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  4237
#endif /* APPLETALK */
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  4238
28
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  4239
    /*
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  4240
     * XXXX add addressing stuff for other domains here ...
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  4241
     */
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  4242
#ifdef AF_X25
1009
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  4243
    else if (myDomain == @symbol(x25)) {
28
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  4244
    }
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  4245
#endif
819
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
  4246
#ifdef AF_AX25
1009
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  4247
    else if (myDomain == @symbol(ax25)) {
819
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
  4248
    }
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
  4249
#endif
28
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  4250
#ifdef AF_NS
1009
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  4251
    else if ((myDomain == @symbol(ns)) 
812
c8101ea70e6c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 811
diff changeset
  4252
     || (myDomain == @symbol(xns))) {
28
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  4253
    }
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  4254
#endif
524
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  4255
# ifdef AF_DECnet
1009
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  4256
    else if (myDomain == @symbol(decnet)) {
524
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  4257
    }
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  4258
# endif
93
Claus Gittinger <cg@exept.de>
parents: 92
diff changeset
  4259
#ifdef AF_SNA
1009
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  4260
    else if (myDomain == @symbol(sna)) {
93
Claus Gittinger <cg@exept.de>
parents: 92
diff changeset
  4261
    }
Claus Gittinger <cg@exept.de>
parents: 92
diff changeset
  4262
#endif
Claus Gittinger <cg@exept.de>
parents: 92
diff changeset
  4263
#ifdef AF_RAW 
1009
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  4264
    else if (myDomain == @symbol(raw)) {
93
Claus Gittinger <cg@exept.de>
parents: 92
diff changeset
  4265
    }
Claus Gittinger <cg@exept.de>
parents: 92
diff changeset
  4266
#endif
524
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  4267
# ifdef AF_ISO
1009
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  4268
    else if (myDomain == @symbol(iso)) {
524
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  4269
    }
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  4270
# endif
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  4271
# ifdef AF_NETBIOS
1009
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  4272
    else if (myDomain == @symbol(netbios)) {
530
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  4273
    }
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  4274
# endif
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  4275
# ifdef AF_IPX
1009
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  4276
    else if (myDomain == @symbol(ipx)) {
530
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  4277
    }
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  4278
# endif
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  4279
# ifdef AF_BRIDGE
1009
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  4280
    else if (myDomain == @symbol(bridge)) {
524
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  4281
    }
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  4282
# endif
571
191b37534643 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 563
diff changeset
  4283
# ifdef AF_BSC
1009
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  4284
    else if (myDomain == @symbol(bsc)) {
571
191b37534643 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 563
diff changeset
  4285
    }
191b37534643 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 563
diff changeset
  4286
# endif
812
c8101ea70e6c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 811
diff changeset
  4287
# ifdef AF_ROSE
1009
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  4288
    else if (myDomain == @symbol(rose)) {
812
c8101ea70e6c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 811
diff changeset
  4289
    }
c8101ea70e6c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 811
diff changeset
  4290
# endif
869
a6e5cbe9f558 preps for AF_IRDA
Claus Gittinger <cg@exept.de>
parents: 867
diff changeset
  4291
# ifdef AF_IRDA
1009
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  4292
    else if (__INST(domain) == @symbol(irda)) {
869
a6e5cbe9f558 preps for AF_IRDA
Claus Gittinger <cg@exept.de>
parents: 867
diff changeset
  4293
    }
a6e5cbe9f558 preps for AF_IRDA
Claus Gittinger <cg@exept.de>
parents: 867
diff changeset
  4294
# endif
524
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  4295
# if defined(AF_CCITT) && (AF_CCITT != AF_X25)
1009
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  4296
    else if (myDomain == @symbol(ccitt)) {
524
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  4297
    }
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  4298
# endif
28
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  4299
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  4300
    if (! ok) {
1009
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  4301
	DBGPRINTF(("SOCKET: unsupported domain\n"));
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  4302
	RETURN (false);
28
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  4303
    }
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  4304
110
7af19ae8693b use new FILE* wrapper macros (based on externalAddress)
Claus Gittinger <cg@exept.de>
parents: 106
diff changeset
  4305
    sock = fileno(__FILEVal(t));
28
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  4306
649
1bc56594db85 fixed connect for sun/irix
Claus Gittinger <cg@exept.de>
parents: 648
diff changeset
  4307
#if defined(O_NONBLOCK)
896
2ca43149a20e Ask for possible error after async connect.
Stefan Vogel <sv@exept.de>
parents: 888
diff changeset
  4308
    /*
2ca43149a20e Ask for possible error after async connect.
Stefan Vogel <sv@exept.de>
parents: 888
diff changeset
  4309
     * set to non-blocking and wait later
2ca43149a20e Ask for possible error after async connect.
Stefan Vogel <sv@exept.de>
parents: 888
diff changeset
  4310
     */
2ca43149a20e Ask for possible error after async connect.
Stefan Vogel <sv@exept.de>
parents: 888
diff changeset
  4311
    oldFlags = fcntl(sock, F_GETFL, 0);
2ca43149a20e Ask for possible error after async connect.
Stefan Vogel <sv@exept.de>
parents: 888
diff changeset
  4312
    /* 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
  4313
    fcntl(sock, F_SETFL, oldFlags | O_NONBLOCK);
649
1bc56594db85 fixed connect for sun/irix
Claus Gittinger <cg@exept.de>
parents: 648
diff changeset
  4314
#endif
1bc56594db85 fixed connect for sun/irix
Claus Gittinger <cg@exept.de>
parents: 648
diff changeset
  4315
28
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  4316
    /* 
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  4317
     * connect 
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  4318
     */
81
claus
parents: 79
diff changeset
  4319
    __BEGIN_INTERRUPTABLE__
28
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  4320
    do {
1009
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  4321
	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
  4322
    } while ((ret < 0) 
1009
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  4323
	     && ((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
  4324
#ifdef EAGAIN
1009
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  4325
		 || (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
  4326
#endif
1009
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  4327
		));
81
claus
parents: 79
diff changeset
  4328
    __END_INTERRUPTABLE__
28
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  4329
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  4330
    if (ret < 0) { 
649
1bc56594db85 fixed connect for sun/irix
Claus Gittinger <cg@exept.de>
parents: 648
diff changeset
  4331
#if defined(EINPROGRESS) || defined(EALREADY)
1009
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  4332
	if (0
649
1bc56594db85 fixed connect for sun/irix
Claus Gittinger <cg@exept.de>
parents: 648
diff changeset
  4333
# ifdef EINPROGRESS
1009
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  4334
	    || (errno == EINPROGRESS) 
649
1bc56594db85 fixed connect for sun/irix
Claus Gittinger <cg@exept.de>
parents: 648
diff changeset
  4335
# endif
1bc56594db85 fixed connect for sun/irix
Claus Gittinger <cg@exept.de>
parents: 648
diff changeset
  4336
# ifdef EALREADY
1009
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  4337
	    || (errno == EALREADY)
649
1bc56594db85 fixed connect for sun/irix
Claus Gittinger <cg@exept.de>
parents: 648
diff changeset
  4338
# endif
1009
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  4339
	) {
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  4340
	    /*
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  4341
	     * This was a nonblocking operation that will take some time.
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  4342
	     * 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
  4343
	     */
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  4344
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  4345
	    isAsync = true;
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  4346
	} else
649
1bc56594db85 fixed connect for sun/irix
Claus Gittinger <cg@exept.de>
parents: 648
diff changeset
  4347
#endif /* EINPROGRESS or EALREADY */
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
	    DBGPRINTF(("SOCKET: connect failed errno=%d\n", errno));
117
03cefad7e40b UD socket example & interruptable bind
Claus Gittinger <cg@exept.de>
parents: 116
diff changeset
  4350
#ifdef DUMP_ADDRESS
1009
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  4351
	    {
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  4352
		char *cp = (char *)(&sa);
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  4353
		int i;
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  4354
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  4355
		printf("address data:\n");
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  4356
		for (i=0; i<sockaddr_size; i++) {
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  4357
		    printf(" %02x\n", *cp++);
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  4358
		}
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  4359
	    }
117
03cefad7e40b UD socket example & interruptable bind
Claus Gittinger <cg@exept.de>
parents: 116
diff changeset
  4360
#endif
1009
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  4361
	    __INST(lastErrorNumber) = __MKSMALLINT(errno);
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  4362
	    RETURN (false);
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  4363
	}
28
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  4364
    }
649
1bc56594db85 fixed connect for sun/irix
Claus Gittinger <cg@exept.de>
parents: 648
diff changeset
  4365
1bc56594db85 fixed connect for sun/irix
Claus Gittinger <cg@exept.de>
parents: 648
diff changeset
  4366
#if defined(O_NONBLOCK)
896
2ca43149a20e Ask for possible error after async connect.
Stefan Vogel <sv@exept.de>
parents: 888
diff changeset
  4367
    fcntl(sock, F_SETFL, oldFlags);
649
1bc56594db85 fixed connect for sun/irix
Claus Gittinger <cg@exept.de>
parents: 648
diff changeset
  4368
#endif
1bc56594db85 fixed connect for sun/irix
Claus Gittinger <cg@exept.de>
parents: 648
diff changeset
  4369
430
12d736316f69 Fix #connectTo:port: Do not call connect() when we get EINPROGRESS
Stefan Vogel <sv@exept.de>
parents: 429
diff changeset
  4370
#else /* NO_SOCKET */
418
317e55c6c281 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 403
diff changeset
  4371
    RETURN (false);
430
12d736316f69 Fix #connectTo:port: Do not call connect() when we get EINPROGRESS
Stefan Vogel <sv@exept.de>
parents: 429
diff changeset
  4372
#endif /* NO_SOCKET */
42
506596f9a1a8 *** empty log message ***
claus
parents: 38
diff changeset
  4373
%}.
430
12d736316f69 Fix #connectTo:port: Do not call connect() when we get EINPROGRESS
Stefan Vogel <sv@exept.de>
parents: 429
diff changeset
  4374
    isAsync == true ifTrue:[
1009
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  4375
	(self writeWaitWithTimeoutMs:timeout) ifTrue:[
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  4376
	    "/ a timeout occured
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  4377
	    "/ should cancel the connect?
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  4378
	    ^ false.
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  4379
	].
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  4380
	err := self getSocketError.
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  4381
	err ~~ 0 ifTrue:[
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  4382
	    lastErrorNumber := err.
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  4383
	    ^ false.
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  4384
	].
430
12d736316f69 Fix #connectTo:port: Do not call connect() when we get EINPROGRESS
Stefan Vogel <sv@exept.de>
parents: 429
diff changeset
  4385
    ].
71
claus
parents: 63
diff changeset
  4386
    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
  4387
    peerName := hostOrPathName.
28
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  4388
    ^ true
896
2ca43149a20e Ask for possible error after async connect.
Stefan Vogel <sv@exept.de>
parents: 888
diff changeset
  4389
2ca43149a20e Ask for possible error after async connect.
Stefan Vogel <sv@exept.de>
parents: 888
diff changeset
  4390
    "
2ca43149a20e Ask for possible error after async connect.
Stefan Vogel <sv@exept.de>
parents: 888
diff changeset
  4391
       |sock|
2ca43149a20e Ask for possible error after async connect.
Stefan Vogel <sv@exept.de>
parents: 888
diff changeset
  4392
       sock := Socket newTCP.
2ca43149a20e Ask for possible error after async connect.
Stefan Vogel <sv@exept.de>
parents: 888
diff changeset
  4393
       sock connectTo:'localhost' port:21 withTimeout:1000.
2ca43149a20e Ask for possible error after async connect.
Stefan Vogel <sv@exept.de>
parents: 888
diff changeset
  4394
       sock
2ca43149a20e Ask for possible error after async connect.
Stefan Vogel <sv@exept.de>
parents: 888
diff changeset
  4395
2ca43149a20e Ask for possible error after async connect.
Stefan Vogel <sv@exept.de>
parents: 888
diff changeset
  4396
       |sock|
2ca43149a20e Ask for possible error after async connect.
Stefan Vogel <sv@exept.de>
parents: 888
diff changeset
  4397
       sock := Socket newTCP.
2ca43149a20e Ask for possible error after async connect.
Stefan Vogel <sv@exept.de>
parents: 888
diff changeset
  4398
       sock connectTo:'localhost' port:9876 withTimeout:2000.
2ca43149a20e Ask for possible error after async connect.
Stefan Vogel <sv@exept.de>
parents: 888
diff changeset
  4399
       sock
2ca43149a20e Ask for possible error after async connect.
Stefan Vogel <sv@exept.de>
parents: 888
diff changeset
  4400
    "
25
996051271ce9 *** empty log message ***
claus
parents: 21
diff changeset
  4401
! !
996051271ce9 *** empty log message ***
claus
parents: 21
diff changeset
  4402
996051271ce9 *** empty log message ***
claus
parents: 21
diff changeset
  4403
!Socket methodsFor:'queries'!
996051271ce9 *** empty log message ***
claus
parents: 21
diff changeset
  4404
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4405
domain
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4406
    "return the sockets addressing domain (i.e. #inet, #unix, #x25, #appletalk)"
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4407
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4408
    ^ domain
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4409
!
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4410
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4411
getName
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4412
    "return the name; here, we return the ports name"
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4413
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4414
    ^ port printString
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4415
!
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4416
102
5dc264007513 added getPeer for ST-80 compatibility
Claus Gittinger <cg@exept.de>
parents: 99
diff changeset
  4417
getPeer
5dc264007513 added getPeer for ST-80 compatibility
Claus Gittinger <cg@exept.de>
parents: 99
diff changeset
  4418
    "ST-80 compatibility: return an IPSocketAddress instance representing
5dc264007513 added getPeer for ST-80 compatibility
Claus Gittinger <cg@exept.de>
parents: 99
diff changeset
  4419
     my hostname/port combination.
155
fcf846c707b7 interest is written with one 'r' (shame on me)
Claus Gittinger <cg@exept.de>
parents: 126
diff changeset
  4420
     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
  4421
116
7789fb1c9fa2 more UD socket fixes (at least client side seems to work now)
Claus Gittinger <cg@exept.de>
parents: 115
diff changeset
  4422
    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
  4423
	^ 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
  4424
    ].
819
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
  4425
    domain == #inet ifTrue:[
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
  4426
	^ IPSocketAddress hostAddress:(self class ipAddressOfHost:peerName) port:port
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
  4427
    ].
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
  4428
    domain == #inet6 ifTrue:[
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
  4429
	^ IPv6SocketAddress hostAddress:(self class ipV6AddressOfHost:peerName) port:port
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
  4430
    ].
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
  4431
    domain == #appletalk ifTrue:[
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
  4432
	^ AppletalkSocketAddress hostAddress:(self class appletalkAddressOfHost:peerName) port:port
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
  4433
    ].
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
  4434
    domain == #decnet ifTrue:[
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
  4435
	^ DecNetSocketAddress hostAddress:(self class decnetAddressOfHost: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
    self error:'unsupported domain'.
102
5dc264007513 added getPeer for ST-80 compatibility
Claus Gittinger <cg@exept.de>
parents: 99
diff changeset
  4438
5dc264007513 added getPeer for ST-80 compatibility
Claus Gittinger <cg@exept.de>
parents: 99
diff changeset
  4439
    "Created: 2.11.1995 / 11:22:39 / cg"
5dc264007513 added getPeer for ST-80 compatibility
Claus Gittinger <cg@exept.de>
parents: 99
diff changeset
  4440
!
5dc264007513 added getPeer for ST-80 compatibility
Claus Gittinger <cg@exept.de>
parents: 99
diff changeset
  4441
25
996051271ce9 *** empty log message ***
claus
parents: 21
diff changeset
  4442
getPeerName
996051271ce9 *** empty log message ***
claus
parents: 21
diff changeset
  4443
    "return the peer name; thats the hostname (or dotted name) of the
996051271ce9 *** empty log message ***
claus
parents: 21
diff changeset
  4444
     partners host after an accept."
996051271ce9 *** empty log message ***
claus
parents: 21
diff changeset
  4445
996051271ce9 *** empty log message ***
claus
parents: 21
diff changeset
  4446
    ^ peerName
28
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  4447
!
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  4448
1029
5906977e62f0 implement getSocketName for swazoo as primitive cant load as extension
penk
parents: 1010
diff changeset
  4449
getSocketAdress
5906977e62f0 implement getSocketName for swazoo as primitive cant load as extension
penk
parents: 1010
diff changeset
  4450
"
5906977e62f0 implement getSocketName for swazoo as primitive cant load as extension
penk
parents: 1010
diff changeset
  4451
    implemented for swazoo project primitive code cant load as extension
5906977e62f0 implement getSocketName for swazoo as primitive cant load as extension
penk
parents: 1010
diff changeset
  4452
    answer the my own address (I am bound to this address).
5906977e62f0 implement getSocketName for swazoo as primitive cant load as extension
penk
parents: 1010
diff changeset
  4453
    Note that this address may change after connect or accept.
5906977e62f0 implement getSocketName for swazoo as primitive cant load as extension
penk
parents: 1010
diff changeset
  4454
"
5906977e62f0 implement getSocketName for swazoo as primitive cant load as extension
penk
parents: 1010
diff changeset
  4455
5906977e62f0 implement getSocketName for swazoo as primitive cant load as extension
penk
parents: 1010
diff changeset
  4456
    |socketAddress error|
5906977e62f0 implement getSocketName for swazoo as primitive cant load as extension
penk
parents: 1010
diff changeset
  4457
5906977e62f0 implement getSocketName for swazoo as primitive cant load as extension
penk
parents: 1010
diff changeset
  4458
    filePointer isNil ifTrue:[
5906977e62f0 implement getSocketName for swazoo as primitive cant load as extension
penk
parents: 1010
diff changeset
  4459
        ^ self errorNotOpen
5906977e62f0 implement getSocketName for swazoo as primitive cant load as extension
penk
parents: 1010
diff changeset
  4460
    ].
5906977e62f0 implement getSocketName for swazoo as primitive cant load as extension
penk
parents: 1010
diff changeset
  4461
    socketAddress := ByteArray new:16.
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
%{
5906977e62f0 implement getSocketName for swazoo as primitive cant load as extension
penk
parents: 1010
diff changeset
  4464
#ifndef NO_SOCKET
5906977e62f0 implement getSocketName for swazoo as primitive cant load as extension
penk
parents: 1010
diff changeset
  4465
    OBJ t = __INST(filePointer);
5906977e62f0 implement getSocketName for swazoo as primitive cant load as extension
penk
parents: 1010
diff changeset
  4466
    int sock;
5906977e62f0 implement getSocketName for swazoo as primitive cant load as extension
penk
parents: 1010
diff changeset
  4467
    int sockaddr_size;
5906977e62f0 implement getSocketName for swazoo as primitive cant load as extension
penk
parents: 1010
diff changeset
  4468
    int ret;
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
    if (!__isNonNilObject(socketAddress) ||
5906977e62f0 implement getSocketName for swazoo as primitive cant load as extension
penk
parents: 1010
diff changeset
  4471
        (__intVal(__ClassInstPtr(__qClass(socketAddress))->c_flags) & ARRAYMASK) != BYTEARRAY) {
5906977e62f0 implement getSocketName for swazoo as primitive cant load as extension
penk
parents: 1010
diff changeset
  4472
        error = @symbol(badArgument1);
5906977e62f0 implement getSocketName for swazoo as primitive cant load as extension
penk
parents: 1010
diff changeset
  4473
        goto err;
5906977e62f0 implement getSocketName for swazoo as primitive cant load as extension
penk
parents: 1010
diff changeset
  4474
    }
5906977e62f0 implement getSocketName for swazoo as primitive cant load as extension
penk
parents: 1010
diff changeset
  4475
    sockaddr_size = __byteArraySize(socketAddress);
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
    sock = fileno(__FILEVal(t));
5906977e62f0 implement getSocketName for swazoo as primitive cant load as extension
penk
parents: 1010
diff changeset
  4478
    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
  4479
    if (ret < 0) {
5906977e62f0 implement getSocketName for swazoo as primitive cant load as extension
penk
parents: 1010
diff changeset
  4480
        DBGPRINTF(("SOCKET: getsocketname failed errno=%d\n", errno));
5906977e62f0 implement getSocketName for swazoo as primitive cant load as extension
penk
parents: 1010
diff changeset
  4481
        error = __MKSMALLINT(errno);
5906977e62f0 implement getSocketName for swazoo as primitive cant load as extension
penk
parents: 1010
diff changeset
  4482
    }
5906977e62f0 implement getSocketName for swazoo as primitive cant load as extension
penk
parents: 1010
diff changeset
  4483
err:;
5906977e62f0 implement getSocketName for swazoo as primitive cant load as extension
penk
parents: 1010
diff changeset
  4484
#else /* NO_SOCKET */
5906977e62f0 implement getSocketName for swazoo as primitive cant load as extension
penk
parents: 1010
diff changeset
  4485
    error = @symbol(notImplemented);
5906977e62f0 implement getSocketName for swazoo as primitive cant load as extension
penk
parents: 1010
diff changeset
  4486
#endif /* NO_SOCKET */
5906977e62f0 implement getSocketName for swazoo as primitive cant load as extension
penk
parents: 1010
diff changeset
  4487
%}.
5906977e62f0 implement getSocketName for swazoo as primitive cant load as extension
penk
parents: 1010
diff changeset
  4488
    error notNil ifTrue:[
5906977e62f0 implement getSocketName for swazoo as primitive cant load as extension
penk
parents: 1010
diff changeset
  4489
        ^ self errorReporter reportOn:error
5906977e62f0 implement getSocketName for swazoo as primitive cant load as extension
penk
parents: 1010
diff changeset
  4490
    ].
5906977e62f0 implement getSocketName for swazoo as primitive cant load as extension
penk
parents: 1010
diff changeset
  4491
    ^ socketAddress copyFrom:5 to:8
5906977e62f0 implement getSocketName for swazoo as primitive cant load as extension
penk
parents: 1010
diff changeset
  4492
!
5906977e62f0 implement getSocketName for swazoo as primitive cant load as extension
penk
parents: 1010
diff changeset
  4493
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4494
isActive
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4495
    "return true, if the receiver has a connection"
81
claus
parents: 79
diff changeset
  4496
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4497
    ^ filePointer notNil
81
claus
parents: 79
diff changeset
  4498
!
claus
parents: 79
diff changeset
  4499
71
claus
parents: 63
diff changeset
  4500
port
claus
parents: 63
diff changeset
  4501
    "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
  4502
506
11ef93d12870 support anonymous (OS_specified) ports. (for FTP-protocol)
Claus Gittinger <cg@exept.de>
parents: 486
diff changeset
  4503
    |p|
11ef93d12870 support anonymous (OS_specified) ports. (for FTP-protocol)
Claus Gittinger <cg@exept.de>
parents: 486
diff changeset
  4504
11ef93d12870 support anonymous (OS_specified) ports. (for FTP-protocol)
Claus Gittinger <cg@exept.de>
parents: 486
diff changeset
  4505
    port == 0 ifTrue:[
524
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  4506
	p := self getPort.
506
11ef93d12870 support anonymous (OS_specified) ports. (for FTP-protocol)
Claus Gittinger <cg@exept.de>
parents: 486
diff changeset
  4507
	p notNil ifTrue:[
11ef93d12870 support anonymous (OS_specified) ports. (for FTP-protocol)
Claus Gittinger <cg@exept.de>
parents: 486
diff changeset
  4508
	    port := p
11ef93d12870 support anonymous (OS_specified) ports. (for FTP-protocol)
Claus Gittinger <cg@exept.de>
parents: 486
diff changeset
  4509
	]
11ef93d12870 support anonymous (OS_specified) ports. (for FTP-protocol)
Claus Gittinger <cg@exept.de>
parents: 486
diff changeset
  4510
    ].
71
claus
parents: 63
diff changeset
  4511
    ^ port
28
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  4512
!
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  4513
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  4514
type
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  4515
    "return the sockets connection type (i.e. #datagram, #stream etc)"
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  4516
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  4517
    ^ socketType
81
claus
parents: 79
diff changeset
  4518
! !
claus
parents: 79
diff changeset
  4519
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4520
!Socket methodsFor:'socket setup'!
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4521
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4522
domain:domainArg type:typeArg
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4523
    "set up socket with domain and type.
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4524
     This is a low level entry; no binding, listening or connect
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4525
     is done. Both arguments must be symbols from one of
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4526
     #inet,#unix, #appletalk, #x25 .. and #stream, #datagram, #raw resp."
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4527
649
1bc56594db85 fixed connect for sun/irix
Claus Gittinger <cg@exept.de>
parents: 648
diff changeset
  4528
    ^ self domain:domainArg type:typeArg protocol:0 reuseAddress:true
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4529
!
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4530
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4531
domain:domainArg type:typeArg protocol:protocolNumber
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4532
    "set up socket with domain, type and protocol number.
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4533
     This is a low level entry; no binding, listening or connect
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4534
     is done. Both arguments must be symbols from one of
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4535
     #inet,#unix, #appletalk, #x25 .. and #stream, #datagram, #raw resp."
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4536
649
1bc56594db85 fixed connect for sun/irix
Claus Gittinger <cg@exept.de>
parents: 648
diff changeset
  4537
    ^ self domain:domainArg type:typeArg protocol:protocolNumber reuseAddress:true
1bc56594db85 fixed connect for sun/irix
Claus Gittinger <cg@exept.de>
parents: 648
diff changeset
  4538
1bc56594db85 fixed connect for sun/irix
Claus Gittinger <cg@exept.de>
parents: 648
diff changeset
  4539
    "
1bc56594db85 fixed connect for sun/irix
Claus Gittinger <cg@exept.de>
parents: 648
diff changeset
  4540
     Socket new domain:#inet type:#stream
1bc56594db85 fixed connect for sun/irix
Claus Gittinger <cg@exept.de>
parents: 648
diff changeset
  4541
     Socket new domain:#unix type:#stream
1bc56594db85 fixed connect for sun/irix
Claus Gittinger <cg@exept.de>
parents: 648
diff changeset
  4542
    "
1bc56594db85 fixed connect for sun/irix
Claus Gittinger <cg@exept.de>
parents: 648
diff changeset
  4543
!
1bc56594db85 fixed connect for sun/irix
Claus Gittinger <cg@exept.de>
parents: 648
diff changeset
  4544
1bc56594db85 fixed connect for sun/irix
Claus Gittinger <cg@exept.de>
parents: 648
diff changeset
  4545
domain:domainArg type:typeArg protocol:protocolNumber reuseAddress:reuse
1bc56594db85 fixed connect for sun/irix
Claus Gittinger <cg@exept.de>
parents: 648
diff changeset
  4546
    "set up socket with domain, type and protocol number.
1bc56594db85 fixed connect for sun/irix
Claus Gittinger <cg@exept.de>
parents: 648
diff changeset
  4547
     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
  4548
     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
  4549
     #inet,#unix, #appletalk, #x25 .. and #stream, #datagram, #raw resp.
1bc56594db85 fixed connect for sun/irix
Claus Gittinger <cg@exept.de>
parents: 648
diff changeset
  4550
1bc56594db85 fixed connect for sun/irix
Claus Gittinger <cg@exept.de>
parents: 648
diff changeset
  4551
     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
  4552
     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
  4553
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4554
    |errorNr|
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
    filePointer notNil ifTrue:[
789
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  4557
	^ self errorAlreadyOpen
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4558
    ].
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4559
%{
649
1bc56594db85 fixed connect for sun/irix
Claus Gittinger <cg@exept.de>
parents: 648
diff changeset
  4560
418
317e55c6c281 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 403
diff changeset
  4561
#ifndef NO_SOCKET
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4562
    FILE *fp;
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4563
    int dom, typ, pf, proto = 0, sock;
649
1bc56594db85 fixed connect for sun/irix
Claus Gittinger <cg@exept.de>
parents: 648
diff changeset
  4564
    int on = 1;
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4565
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4566
    if (! __isSymbol(domainArg)) { 
789
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  4567
	DBGPRINTF(("SOCKET: bad domain\n"));
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  4568
	RETURN ( nil );
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4569
    }
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4570
    if (! __isSymbol(typeArg)) { 
789
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  4571
	DBGPRINTF(("SOCKET: bad type\n"));
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  4572
	RETURN ( nil );
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4573
    }
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4574
    if (protocolNumber != nil) {
789
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  4575
	if (!__isSmallInteger(protocolNumber)) {
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  4576
	    DBGPRINTF(("SOCKET: bad protocol\n"));
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  4577
	    RETURN ( nil );
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  4578
	}
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  4579
	proto = __intVal(protocolNumber);
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4580
    }
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4581
        
81
claus
parents: 79
diff changeset
  4582
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4583
    /*
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4584
     * get address and protocol-family
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4585
     */
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4586
#ifdef AF_UNIX
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4587
    if (domainArg == @symbol(unix)) {
789
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  4588
	dom = AF_UNIX;
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4589
    } else
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4590
#endif
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4591
#ifdef AF_INET
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4592
    if (domainArg == @symbol(inet)) {
789
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  4593
	dom = AF_INET;
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4594
    } else
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4595
#endif
530
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  4596
#ifdef AF_INET6
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  4597
    if (domainArg == @symbol(inet6)) {
789
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  4598
	dom = AF_INET6;
530
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  4599
    } else
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  4600
#endif
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4601
#ifdef AF_DECnet
819
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
  4602
    if (domainArg == @symbol(decnet)) {
789
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  4603
	dom = AF_DECnet;
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4604
    } else
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4605
#endif
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4606
#ifdef AF_APPLETALK
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4607
    if (domainArg == @symbol(appletalk)) {
789
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  4608
	dom = AF_APPLETALK;
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4609
    } else
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4610
#endif
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4611
#ifdef AF_X25
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4612
    if (domainArg == @symbol(x25)) {
789
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  4613
	dom = AF_X25;
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4614
    } else
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4615
#endif
819
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
  4616
#ifdef AF_AX25
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
  4617
    if (domainArg == @symbol(ax25)) {
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
  4618
	dom = AF_AX25;
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
  4619
    } else
4cc15700d123 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
  4620
#endif
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4621
#ifdef AF_NS
812
c8101ea70e6c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 811
diff changeset
  4622
    if ((domainArg == @symbol(xns))
c8101ea70e6c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 811
diff changeset
  4623
     || (domainArg == @symbol(ns))) {
789
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  4624
	dom = AF_NS;
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4625
    } else
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4626
#endif
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4627
#ifdef AF_SNA
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4628
    if (domainArg == @symbol(sna)) {
789
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  4629
	dom = AF_SNA;
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_RAW
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4633
    if (domainArg == @symbol(raw)) {
789
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  4634
	dom = AF_RAW;
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
524
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  4637
# ifdef AF_ISO
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  4638
    if (domainArg == @symbol(iso)) {
789
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  4639
	dom = AF_ISO;
874
Claus Gittinger <cg@exept.de>
parents: 870
diff changeset
  4640
    } else
524
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  4641
# endif
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  4642
# ifdef AF_NETBIOS
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  4643
    if (domainArg == @symbol(netbios)) {
789
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  4644
	dom = AF_NETBIOS;
874
Claus Gittinger <cg@exept.de>
parents: 870
diff changeset
  4645
    } else
524
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  4646
# endif
530
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  4647
# ifdef AF_IPX
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  4648
    if (domainArg == @symbol(ipx)) {
789
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  4649
	dom = AF_IPX;
874
Claus Gittinger <cg@exept.de>
parents: 870
diff changeset
  4650
    } else
530
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  4651
# endif
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  4652
# ifdef AF_BRIDGE
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  4653
    if (domainArg == @symbol(bridge)) {
789
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  4654
	dom = AF_BRIDGE;
874
Claus Gittinger <cg@exept.de>
parents: 870
diff changeset
  4655
    } else
530
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  4656
# endif
571
191b37534643 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 563
diff changeset
  4657
# ifdef AF_BSC
191b37534643 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 563
diff changeset
  4658
    if (domainArg == @symbol(bsc)) {
789
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  4659
	dom = AF_BSC;
874
Claus Gittinger <cg@exept.de>
parents: 870
diff changeset
  4660
    } else
571
191b37534643 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 563
diff changeset
  4661
# endif
812
c8101ea70e6c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 811
diff changeset
  4662
# ifdef AF_ROSE
c8101ea70e6c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 811
diff changeset
  4663
    if (domainArg == @symbol(rose)) {
c8101ea70e6c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 811
diff changeset
  4664
	dom = AF_ROSE;
874
Claus Gittinger <cg@exept.de>
parents: 870
diff changeset
  4665
    } else
812
c8101ea70e6c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 811
diff changeset
  4666
# endif
869
a6e5cbe9f558 preps for AF_IRDA
Claus Gittinger <cg@exept.de>
parents: 867
diff changeset
  4667
# ifdef AF_IRDA
a6e5cbe9f558 preps for AF_IRDA
Claus Gittinger <cg@exept.de>
parents: 867
diff changeset
  4668
    if (domainArg == @symbol(irda)) {
a6e5cbe9f558 preps for AF_IRDA
Claus Gittinger <cg@exept.de>
parents: 867
diff changeset
  4669
	dom = AF_IRDA;
874
Claus Gittinger <cg@exept.de>
parents: 870
diff changeset
  4670
    } else
869
a6e5cbe9f558 preps for AF_IRDA
Claus Gittinger <cg@exept.de>
parents: 867
diff changeset
  4671
# endif
524
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  4672
# if defined(AF_CCITT) && (AF_CCITT != AF_X25)
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  4673
    if (domainArg == @symbol(ccitt)) {
789
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  4674
	dom = AF_CCITT;
874
Claus Gittinger <cg@exept.de>
parents: 870
diff changeset
  4675
    } else
524
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  4676
# endif
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4677
    {
789
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  4678
	DBGPRINTF(("SOCKET: unknown domain <%s>\n", __stringVal(domainArg)));
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  4679
	RETURN ( nil );
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4680
    }
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4681
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4682
#ifdef SOCK_STREAM
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4683
    if (typeArg == @symbol(stream)) {
789
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  4684
	typ = SOCK_STREAM;
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4685
    } else
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4686
#endif
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4687
#ifdef SOCK_DGRAM
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4688
    if (typeArg == @symbol(datagram)) {
789
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  4689
	typ = SOCK_DGRAM;
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4690
    } else 
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4691
#endif
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4692
#ifdef SOCK_RAW
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4693
    if (typeArg == @symbol(raw))
789
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  4694
	typ = SOCK_RAW;
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4695
    else
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4696
#endif
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4697
#ifdef SOCK_SEQPACKET
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4698
    if (typeArg == @symbol(seqPacket))
789
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  4699
	typ = SOCK_SEQPACKET;
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4700
    else
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4701
#endif
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4702
    {
789
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  4703
	DBGPRINTF(("SOCKET: bad type <%s>\n", __stringVal(typeArg)));
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  4704
	RETURN ( nil );
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4705
    }
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
    __BEGIN_INTERRUPTABLE__
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4708
    do {
789
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  4709
	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
  4710
	sock = socket(dom, typ, proto);
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4711
#if defined(EPROTONOSUPPORT) /* for SGI */
789
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  4712
	if ((proto != 0) && (sock < 0) && (errno == EPROTONOSUPPORT)) {
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  4713
	    DBGPRINTF(("SOCKET: retry with UNSPEC protocol\n"));
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  4714
	    proto = 0;
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  4715
	    sock = socket(dom, typ, 0);
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  4716
	}
126
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
    } while ((sock < 0) && (errno == EINTR));
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4719
    __END_INTERRUPTABLE__
821
40b0b69bf4b5 more debugs; fixed at-addresses
Claus Gittinger <cg@exept.de>
parents: 820
diff changeset
  4720
    DBGFPRINTF((stderr, "socket create newSock=%d\n", sock));
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4721
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4722
    if (sock < 0) {
789
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  4723
	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
  4724
	__INST(lastErrorNumber) = __MKSMALLINT(errno);
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4725
    } else {
649
1bc56594db85 fixed connect for sun/irix
Claus Gittinger <cg@exept.de>
parents: 648
diff changeset
  4726
# ifdef SO_REUSEADDR
789
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  4727
	if (reuse == true) {
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  4728
	    DBGPRINTF(("SOCKET: setsockopt - SO_REUSEADDR\n"));
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  4729
	    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
  4730
		DBGPRINTF(("SOCKET: setsockopt - SO_REUSEADDR failed\n"));
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  4731
	    }
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  4732
	}
649
1bc56594db85 fixed connect for sun/irix
Claus Gittinger <cg@exept.de>
parents: 648
diff changeset
  4733
# endif /* SO_REUSEADDR */
711
487b2bff9d31 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 693
diff changeset
  4734
789
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  4735
	/* 
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  4736
	 * make it a FILE * 
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  4737
	 */
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  4738
	fp = fdopen(sock, "r+");
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  4739
	if (! fp) {
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  4740
	    DBGPRINTF(("SOCKET: fdopen call failed\n"));
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  4741
	    __INST(lastErrorNumber) = __MKSMALLINT(errno);
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  4742
	    __BEGIN_INTERRUPTABLE__
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  4743
	    close(sock);
821
40b0b69bf4b5 more debugs; fixed at-addresses
Claus Gittinger <cg@exept.de>
parents: 820
diff changeset
  4744
	    DBGFPRINTF((stderr, "socket close (fdopen failed) (%d)\n", sock));
789
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  4745
	    __END_INTERRUPTABLE__
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  4746
	} else {
1035
5b0605675dc6 @globalfor classvar stuff
Stefan Vogel <sv@exept.de>
parents: 1029
diff changeset
  4747
	    if (@global(FileOpenTrace) == true) {
1009
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  4748
		fprintf(stderr, "fdopen [Socket] -> %x\n", fp);
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  4749
	    }
876
69c9ed48daba *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 875
diff changeset
  4750
789
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  4751
	    __INST(filePointer) = __MKOBJ(fp);
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  4752
	    __STORESELF(filePointer);
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  4753
	}
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4754
    }
418
317e55c6c281 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 403
diff changeset
  4755
#endif
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4756
%}.
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4757
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4758
    "all ok?"
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4759
    filePointer notNil ifTrue:[
789
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  4760
	domain := domainArg.
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  4761
	socketType := typeArg.
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  4762
	Lobby register:self.
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4763
    ] ifFalse:[
789
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  4764
	^ nil
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4765
    ].
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4766
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4767
    "
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4768
     Socket new domain:#inet type:#stream
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4769
     Socket new domain:#unix type:#stream
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4770
    "
81
claus
parents: 79
diff changeset
  4771
!
claus
parents: 79
diff changeset
  4772
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4773
for:hostName port:portNr
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4774
    "setup for a TCP socket (i.e. inet domain, stream type) 
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4775
     If hostname is nil, a server port is opened,
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4776
     otherwise a client port to the server on host.
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4777
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4778
     HISTORIC LEFTOVER:
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4779
     This method will vanish, as soon as the low level
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4780
     connect/bind works,"
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4781
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4782
    self obsoleteMethodWarning.
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
    filePointer notNil ifTrue:[
789
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  4785
	^ self errorAlreadyOpen
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4786
    ].
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4787
    (portNr isMemberOf:SmallInteger) ifFalse:[
789
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  4788
	self error:'invalid portNr'
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4789
    ].
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4790
%{
418
317e55c6c281 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 403
diff changeset
  4791
#ifndef NO_SOCKET
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4792
    struct sockaddr_in sa ;
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4793
    struct hostent *hp ;
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4794
    int a, sock ;
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4795
    long addr;
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4796
    FILE *fp;
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4797
    int ret;
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4798
    int on = 1;
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4799
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4800
    bzero((char *) &sa, sizeof(sa)) ;
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4801
    sa.sin_family = AF_INET;
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4802
    sa.sin_addr.s_addr = htonl(INADDR_ANY);
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
    if ((hostName != nil) && __isString(hostName)){
789
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  4805
	bzero(&sa, sizeof(sa)) ;
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  4806
	if ((addr = inet_addr((char *) __stringVal(hostName))) != -1) {
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  4807
	    /* 
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  4808
	     * is Internet addr in octet notation 
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  4809
	     */
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  4810
	    bcopy(&addr, (char *) &sa.sin_addr, sizeof(addr)) ; /* set address */
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  4811
	} else {
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  4812
	    /* 
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  4813
	     * do we know the host's address? 
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  4814
	     */
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  4815
	    GETHOSTBYNAME(hp, __stringVal(hostName))
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  4816
	    if (hp == NULL) {
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  4817
		DBGPRINTF(("SOCKET: unknown host: %s\n", __stringVal(hostName)));
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  4818
		RETURN ( nil );
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  4819
	    }
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  4820
	    bcopy(hp->h_addr, (char *) &sa.sin_addr, hp->h_length) ;
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  4821
	    sa.sin_family = hp->h_addrtype;
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  4822
	}
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4823
    }
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4824
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
     * create the socket
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4827
     */
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4828
    __BEGIN_INTERRUPTABLE__
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4829
    do {
789
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  4830
	sock = socket(sa.sin_family, SOCK_STREAM, 0);
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4831
    } while ((sock < 0) && (errno == EINTR));
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4832
    __END_INTERRUPTABLE__
821
40b0b69bf4b5 more debugs; fixed at-addresses
Claus Gittinger <cg@exept.de>
parents: 820
diff changeset
  4833
    DBGFPRINTF((stderr, "socket create newSock=%d\n", sock));
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4834
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4835
    if (sock < 0) {
789
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  4836
	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
  4837
	__INST(lastErrorNumber) = __MKSMALLINT(errno);
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4838
    } else {
789
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  4839
	/* 
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  4840
	 * connect/bind 
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  4841
	 */
1009
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  4842
	sa.sin_port = htons((u_short) __intVal(portNr)) ;
789
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  4843
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  4844
	__BEGIN_INTERRUPTABLE__
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  4845
	if (hostName != nil) {
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  4846
	    do {
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  4847
		ret = connect(sock, (struct sockaddr *)&sa, sizeof(sa));
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  4848
	    } while ((ret < 0) && (errno == EINTR));
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  4849
	} else {
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4850
#ifdef SO_REUSEADDR
789
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  4851
	    /*
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  4852
	     * should I also do this for DGRAM sockets ?
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  4853
	     */
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  4854
	    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
  4855
		DBGPRINTF(("SOCKET: setsockopt - SO_REUSEADDR failed\n"));
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  4856
	    }
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4857
#endif /* SO_REUSEADDR */
789
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  4858
	    sa.sin_addr.s_addr = htonl(INADDR_ANY);
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  4859
	    do {
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  4860
		ret = bind(sock, (struct sockaddr *)&sa, sizeof(sa));
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  4861
	    } while ((ret < 0) && (errno == EINTR));
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  4862
	}
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  4863
	__END_INTERRUPTABLE__
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  4864
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  4865
	if (ret < 0) { 
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  4866
	    DBGPRINTF(("SOCKET: bind/connect call failed errno=%d\n", errno));
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  4867
	    __INST(lastErrorNumber) = __MKSMALLINT(errno);
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  4868
	    __BEGIN_INTERRUPTABLE__
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  4869
	    close(sock) ;
821
40b0b69bf4b5 more debugs; fixed at-addresses
Claus Gittinger <cg@exept.de>
parents: 820
diff changeset
  4870
	    DBGFPRINTF((stderr, "socket close (fdopen failed) (%d)\n", sock));
789
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  4871
	    __END_INTERRUPTABLE__
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  4872
	} else {
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  4873
	    /* 
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  4874
	     * make it a FILE * 
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  4875
	     */
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  4876
	    fp = fdopen(sock, "r+");
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  4877
	    if (! fp) {
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  4878
		DBGPRINTF(("SOCKET: fdopen failed\n"));
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  4879
		__INST(lastErrorNumber) = __MKSMALLINT(errno);
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  4880
		__BEGIN_INTERRUPTABLE__
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  4881
		close(sock);
822
a08e230988fe *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 821
diff changeset
  4882
		DBGFPRINTF((stderr, "socket close (fdopen failed) (%d)\n", sock));
789
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  4883
		__END_INTERRUPTABLE__
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  4884
	    } else {
1035
5b0605675dc6 @globalfor classvar stuff
Stefan Vogel <sv@exept.de>
parents: 1029
diff changeset
  4885
		if (@global(FileOpenTrace) == true) {
1009
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  4886
		    fprintf(stderr, "fdopen [Socket] -> %x\n", fp);
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  4887
		}
876
69c9ed48daba *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 875
diff changeset
  4888
444
9ba31a1fba38 always unbuffered on linux
Claus Gittinger <cg@exept.de>
parents: 430
diff changeset
  4889
#ifdef BUGGY_STDIO_LIB
789
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  4890
		setbuf(fp, NULL);
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  4891
		__INST(buffered) = false;
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4892
#endif
789
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  4893
		__INST(filePointer) = __MKOBJ(fp);
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  4894
		__STORESELF(filePointer);
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  4895
	    }
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  4896
	}
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4897
    }
418
317e55c6c281 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 403
diff changeset
  4898
#endif
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4899
%}.
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4900
    filePointer isNil ifTrue:[
789
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  4901
	^ nil
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4902
    ].
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4903
    mode := #readwrite.
169
ba5dac089c64 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 168
diff changeset
  4904
    Lobby register:self.
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4905
    binary := false.
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4906
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4907
    domain := #inet.
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4908
    socketType := #stream.
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4909
    protocol := portNr.
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4910
    peerName := hostName.
81
claus
parents: 79
diff changeset
  4911
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4912
    "
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4913
     Socket new for:'clam' port:(Socket portOfService:'echo')
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4914
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4915
     Socket new for:nil port:9999
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4916
     Socket new for:(OperatingSystem getHostName) port:9999
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4917
    "
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4918
!
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4919
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4920
for:hostName udpPort:portNr
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4921
    "setup for a UDP socket (i.e. inet domain, datagram type) 
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4922
     if hostname is nil, a server port is opened;
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4923
     otherwise a client port to the server on host.
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4924
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4925
     HISTORIC LEFTOVER:
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4926
     This method will vanish, as soon as the low level
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4927
     connect/bind works,"
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
    self obsoleteMethodWarning.
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4930
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4931
    filePointer notNil ifTrue:[
789
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  4932
	^ self errorAlreadyOpen
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4933
    ].
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4934
    (portNr isMemberOf:SmallInteger) ifFalse:[
789
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  4935
	self error:'invalid portNr'
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4936
    ].
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4937
%{
418
317e55c6c281 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 403
diff changeset
  4938
#ifndef NO_SOCKET
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4939
    struct sockaddr_in sa ;
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4940
    struct hostent *hp ;
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4941
    int a, sock ;
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4942
    long addr;
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4943
    FILE *fp;
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4944
    int ret;
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
    if (hostName != nil) {
789
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  4947
	bzero(&sa, sizeof(sa)) ;
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  4948
	if ((addr = inet_addr((char *) __stringVal(hostName))) != -1) {
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  4949
	    /* 
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  4950
	     * is Internet addr in octet notation 
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  4951
	     */
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  4952
	    bcopy(&addr, (char *) &sa.sin_addr, sizeof(addr)) ; /* set address */
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  4953
	    sa.sin_family = AF_INET ;
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  4954
	} else {
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  4955
	    /* 
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  4956
	     * is hostname - 
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  4957
	     * do we know the host's address? 
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  4958
	     */
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  4959
	    GETHOSTBYNAME(hp, __stringVal(hostName))
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  4960
	    if (hp == NULL) {
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  4961
		DBGPRINTF(("SOCKET: unknown host: %s\n", __stringVal(hostName)));
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  4962
		RETURN ( nil );
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  4963
	    }
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  4964
	    bcopy(hp->h_addr, (char *) &sa.sin_addr, hp->h_length) ;
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  4965
	    sa.sin_family = hp->h_addrtype ;
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  4966
	}
526
1748ab3892a3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 525
diff changeset
  4967
    } else {
789
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  4968
	sa.sin_family = AF_INET;
526
1748ab3892a3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 525
diff changeset
  4969
    }
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4970
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
     * create the socket
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4973
     */
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4974
    __BEGIN_INTERRUPTABLE__
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4975
    do {
789
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  4976
	sock = socket(sa.sin_family, SOCK_DGRAM, 0);
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4977
    } while ((sock < 0) && (errno == EINTR));
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4978
    __END_INTERRUPTABLE__
821
40b0b69bf4b5 more debugs; fixed at-addresses
Claus Gittinger <cg@exept.de>
parents: 820
diff changeset
  4979
    DBGFPRINTF((stderr, "socket create newSock=%d\n", sock));
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4980
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4981
    if (sock < 0) {
789
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  4982
	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
  4983
	__INST(lastErrorNumber) = __MKSMALLINT(errno);
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  4984
    } else {
789
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  4985
	/* 
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  4986
	 * ok,
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  4987
	 * connect/bind 
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  4988
	 */
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  4989
	__BEGIN_INTERRUPTABLE__
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  4990
	if (hostName == nil) {
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  4991
	    sa.sin_addr.s_addr = htonl(INADDR_ANY);
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  4992
	    do {
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  4993
		ret = bind(sock, (struct sockaddr *)&sa, sizeof(sa));
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  4994
	    } while ((ret < 0) && (errno == EINTR));
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  4995
	} else {
1009
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  4996
	    sa.sin_port = htons((u_short) __intVal(portNr)) ;
789
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  4997
	    do {
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  4998
		ret = connect(sock, (struct sockaddr *)&sa, sizeof(sa));
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  4999
	    } while ((ret < 0) && (errno == EINTR));
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  5000
	}
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  5001
	__END_INTERRUPTABLE__
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  5002
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  5003
	if (ret < 0) {
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  5004
	    DBGPRINTF(("SOCKET: bind/connect call failed\n"));
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  5005
	    __INST(lastErrorNumber) = __MKSMALLINT(errno);
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  5006
	    __BEGIN_INTERRUPTABLE__
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  5007
	    close(sock) ;
821
40b0b69bf4b5 more debugs; fixed at-addresses
Claus Gittinger <cg@exept.de>
parents: 820
diff changeset
  5008
	    DBGFPRINTF((stderr, "socket close (fdopen failed) (%d)\n", sock));
789
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  5009
	    __END_INTERRUPTABLE__
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  5010
	} else {
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
	     * make it a FILE * 
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  5013
	     */
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  5014
	    fp = fdopen(sock, "r+");
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  5015
	    if (! fp) {
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  5016
		DBGPRINTF(("SOCKET: fdopen call failed\n"));
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  5017
		__INST(lastErrorNumber) = __MKSMALLINT(errno);
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  5018
		__BEGIN_INTERRUPTABLE__
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  5019
		close(sock);
821
40b0b69bf4b5 more debugs; fixed at-addresses
Claus Gittinger <cg@exept.de>
parents: 820
diff changeset
  5020
		DBGFPRINTF((stderr, "socket close (fdopen failed) (%d)\n", sock));
789
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  5021
		__END_INTERRUPTABLE__
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  5022
	    } else {
1009
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  5023
		if (@global(ExternalStream:FileOpenTrace) == true) {
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  5024
		    fprintf(stderr, "fdopen [Socket] -> %x\n", fp);
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  5025
		}
876
69c9ed48daba *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 875
diff changeset
  5026
444
9ba31a1fba38 always unbuffered on linux
Claus Gittinger <cg@exept.de>
parents: 430
diff changeset
  5027
#ifdef BUGGY_STDIO_LIB
789
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  5028
		setbuf(fp, NULL);
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  5029
		__INST(buffered) = false;
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  5030
#endif
789
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  5031
		__INST(filePointer) = __MKOBJ(fp);
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  5032
		__STORESELF(filePointer);
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  5033
	    }
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  5034
	}
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  5035
    }
418
317e55c6c281 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 403
diff changeset
  5036
#endif
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  5037
%}.
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  5038
    filePointer isNil ifTrue:[
789
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  5039
	^ nil
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  5040
    ].
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  5041
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  5042
    mode := #readwrite.
169
ba5dac089c64 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 168
diff changeset
  5043
    Lobby register:self.
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  5044
    binary := false.
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  5045
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  5046
    domain := #inet.
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  5047
    socketType := #datagram.
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  5048
    protocol := portNr.
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  5049
    peerName := hostName.
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  5050
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  5051
    "
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  5052
     Socket new for:'clam' udpPort:(Socket portOfService:'echo')
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  5053
    "
28
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  5054
! !
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  5055
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  5056
!Socket methodsFor:'specials'!
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  5057
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  5058
receiveTimeout:seconds
71
claus
parents: 63
diff changeset
  5059
    "set the receive timeout - for special applications only.
claus
parents: 63
diff changeset
  5060
     Not all operatingSystems offer this functionality
claus
parents: 63
diff changeset
  5061
     (returns false, if unsupported)"
28
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  5062
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  5063
    |millis|
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  5064
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  5065
    filePointer isNil ifTrue:[
789
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  5066
	^ self errorNotOpen
28
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  5067
    ].
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  5068
    millis := (seconds * 1000) rounded.
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  5069
%{
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  5070
#if defined(SO_RCVTIMEO) && defined(SOL_SOCKET) && defined(HZ)
58
bd6753bf0401 *** empty log message ***
claus
parents: 51
diff changeset
  5071
    if (__isSmallInteger(millis)) {
789
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  5072
	OBJ fp = __INST(filePointer);
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  5073
	int sock;
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  5074
	int opt;
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  5075
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  5076
	sock = fileno(__FILEVal(fp));
1009
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  5077
	opt = __intVal(millis) / (1000 / HZ);
789
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  5078
	setsockopt(sock, SOL_SOCKET, SO_RCVTIMEO, (char *)&opt, sizeof(int));
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  5079
	RETURN(true);
28
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  5080
    }
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  5081
#endif
71
claus
parents: 63
diff changeset
  5082
%}.
28
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  5083
    ^ false
81
claus
parents: 79
diff changeset
  5084
!
claus
parents: 79
diff changeset
  5085
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  5086
sendTimeout:seconds
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  5087
    "set the send timeout - for special applications only.
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  5088
     Not all operatingSystems offer this functionality
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  5089
     (returns false, if unsupported)"
81
claus
parents: 79
diff changeset
  5090
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  5091
    |millis|
25
996051271ce9 *** empty log message ***
claus
parents: 21
diff changeset
  5092
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  5093
    filePointer isNil ifTrue:[
789
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  5094
	^ self errorNotOpen
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  5095
    ].
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  5096
    millis := (seconds * 1000) rounded.
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  5097
%{
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  5098
#if defined(SO_SNDTIMEO) && defined(SOL_SOCKET) && defined(HZ)
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  5099
    if (__isSmallInteger(millis)) {
789
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  5100
	OBJ fp = __INST(filePointer);
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  5101
	int sock;
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  5102
	int opt;
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  5103
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  5104
	sock = fileno(__FILEVal(fp));
1009
e0839f923a3c double underlines;
Claus Gittinger <cg@exept.de>
parents: 1007
diff changeset
  5105
	opt = __intVal(millis) / (1000 / HZ);
789
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  5106
	setsockopt(sock, SOL_SOCKET, SO_SNDTIMEO, (char *)&opt, sizeof(int));
3c8cac1a92f5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 787
diff changeset
  5107
	RETURN(true);
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  5108
    }
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  5109
#endif
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  5110
%}.
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  5111
    ^ false
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  5112
! !
82
claus
parents: 81
diff changeset
  5113
464
600b101a7035 alen in accept
Claus Gittinger <cg@exept.de>
parents: 463
diff changeset
  5114
!Socket class methodsFor:'documentation'!
206
77166a6b3ee6 For ST80 style socket creation: register socket in Lobby.
Stefan Vogel <sv@exept.de>
parents: 203
diff changeset
  5115
77166a6b3ee6 For ST80 style socket creation: register socket in Lobby.
Stefan Vogel <sv@exept.de>
parents: 203
diff changeset
  5116
version
1035
5b0605675dc6 @globalfor classvar stuff
Stefan Vogel <sv@exept.de>
parents: 1029
diff changeset
  5117
    ^ '$Header: /cvs/stx/stx/libbasic2/Socket.st,v 1.162 2002-04-09 14:58:01 stefan Exp $'
206
77166a6b3ee6 For ST80 style socket creation: register socket in Lobby.
Stefan Vogel <sv@exept.de>
parents: 203
diff changeset
  5118
! !