Socket.st
author Claus Gittinger <cg@exept.de>
Thu, 01 May 1997 20:25:54 +0200
changeset 530 067797c15b77
parent 529 fc7ec265717b
child 531 ca4c73813531
permissions -rw-r--r--
added support for 6-byte internet addresses (untested)
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
0
1cf8d1747859 Initial revision
claus
parents:
diff changeset
     1
"
4
1f66800df351 *** empty log message ***
claus
parents: 3
diff changeset
     2
 COPYRIGHT (c) 1992 by Claus Gittinger
42
506596f9a1a8 *** empty log message ***
claus
parents: 38
diff changeset
     3
	      All Rights Reserved
0
1cf8d1747859 Initial revision
claus
parents:
diff changeset
     4
1cf8d1747859 Initial revision
claus
parents:
diff changeset
     5
 This software is furnished under a license and may be used
1cf8d1747859 Initial revision
claus
parents:
diff changeset
     6
 only in accordance with the terms of that license and with the
1cf8d1747859 Initial revision
claus
parents:
diff changeset
     7
 inclusion of the above copyright notice.   This software may not
1cf8d1747859 Initial revision
claus
parents:
diff changeset
     8
 be provided or otherwise made available to, or used by, any
1cf8d1747859 Initial revision
claus
parents:
diff changeset
     9
 other person.  No title to or ownership of the software is
1cf8d1747859 Initial revision
claus
parents:
diff changeset
    10
 hereby transferred.
1cf8d1747859 Initial revision
claus
parents:
diff changeset
    11
"
1cf8d1747859 Initial revision
claus
parents:
diff changeset
    12
63
7dd3d5b7877e *** empty log message ***
claus
parents: 58
diff changeset
    13
NonPositionableExternalStream subclass:#Socket
206
77166a6b3ee6 For ST80 style socket creation: register socket in Lobby.
Stefan Vogel <sv@exept.de>
parents: 203
diff changeset
    14
	instanceVariableNames:'domain socketType protocol port serviceName peerName'
77166a6b3ee6 For ST80 style socket creation: register socket in Lobby.
Stefan Vogel <sv@exept.de>
parents: 203
diff changeset
    15
	classVariableNames:''
77166a6b3ee6 For ST80 style socket creation: register socket in Lobby.
Stefan Vogel <sv@exept.de>
parents: 203
diff changeset
    16
	poolDictionaries:''
77166a6b3ee6 For ST80 style socket creation: register socket in Lobby.
Stefan Vogel <sv@exept.de>
parents: 203
diff changeset
    17
	category:'Streams-External'
0
1cf8d1747859 Initial revision
claus
parents:
diff changeset
    18
!
1cf8d1747859 Initial revision
claus
parents:
diff changeset
    19
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
    20
!Socket primitiveDefinitions!
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
    21
%{
444
9ba31a1fba38 always unbuffered on linux
Claus Gittinger <cg@exept.de>
parents: 430
diff changeset
    22
9ba31a1fba38 always unbuffered on linux
Claus Gittinger <cg@exept.de>
parents: 430
diff changeset
    23
#ifdef LINUX
9ba31a1fba38 always unbuffered on linux
Claus Gittinger <cg@exept.de>
parents: 430
diff changeset
    24
# define BUGGY_STDIO_LIB
9ba31a1fba38 always unbuffered on linux
Claus Gittinger <cg@exept.de>
parents: 430
diff changeset
    25
#endif
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
    26
420
fe78522ed6e8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 419
diff changeset
    27
#ifdef WIN32
fe78522ed6e8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 419
diff changeset
    28
# undef INT
421
d4db572da862 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 420
diff changeset
    29
# undef Array
d4db572da862 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 420
diff changeset
    30
# undef Number
d4db572da862 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 420
diff changeset
    31
# undef Method
d4db572da862 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 420
diff changeset
    32
# undef Point
506
11ef93d12870 support anonymous (OS_specified) ports. (for FTP-protocol)
Claus Gittinger <cg@exept.de>
parents: 486
diff changeset
    33
# undef Rectangle
11ef93d12870 support anonymous (OS_specified) ports. (for FTP-protocol)
Claus Gittinger <cg@exept.de>
parents: 486
diff changeset
    34
# undef Block
11ef93d12870 support anonymous (OS_specified) ports. (for FTP-protocol)
Claus Gittinger <cg@exept.de>
parents: 486
diff changeset
    35
# undef Context
11ef93d12870 support anonymous (OS_specified) ports. (for FTP-protocol)
Claus Gittinger <cg@exept.de>
parents: 486
diff changeset
    36
# undef String
11ef93d12870 support anonymous (OS_specified) ports. (for FTP-protocol)
Claus Gittinger <cg@exept.de>
parents: 486
diff changeset
    37
# undef Message
463
45f3d67f9d58 win32 changes
Claus Gittinger <cg@exept.de>
parents: 448
diff changeset
    38
# undef Object
420
fe78522ed6e8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 419
diff changeset
    39
#endif
fe78522ed6e8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 419
diff changeset
    40
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
    41
#include <stdio.h>
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
    42
#include <errno.h>
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
    43
418
317e55c6c281 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 403
diff changeset
    44
#if defined(transputer) || defined(MSDOS_LIKE)
317e55c6c281 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 403
diff changeset
    45
# define NO_SOCKET
317e55c6c281 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 403
diff changeset
    46
#endif
317e55c6c281 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 403
diff changeset
    47
525
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
 * which protocols can we support ?
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
    50
 */
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
    51
#ifndef NO_SOCKET
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
    52
# define WANT__AF_INET
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
    53
#endif
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
    54
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
    55
#ifdef UNIX_LIKE
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
    56
# define WANT__AF_UNIX
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
    57
#endif
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
    58
527
f48fd11817e2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 526
diff changeset
    59
#ifdef LINUX
f48fd11817e2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 526
diff changeset
    60
# define WANT__AF_APPLETALK
530
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
    61
# define WANT__AF_INET6
527
f48fd11817e2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 526
diff changeset
    62
#endif
525
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
    63
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
    64
#ifdef LINUX
220
2cf88dc01a32 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 217
diff changeset
    65
/* use inline string macros ... */
2cf88dc01a32 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 217
diff changeset
    66
# define __STRINGDEFS__
2cf88dc01a32 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 217
diff changeset
    67
# include <linuxIntern.h>
2cf88dc01a32 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 217
diff changeset
    68
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
    69
/* kludge to avoid some redefines ... */
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
    70
# define _ARPA_NAMESER_H
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
    71
# define _NETINET_TCP_H
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
    72
#endif
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
    73
465
3673e44dbd2f remove windows ^M characters
Claus Gittinger <cg@exept.de>
parents: 464
diff changeset
    74
#ifdef WIN32
418
317e55c6c281 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 403
diff changeset
    75
# include <WINSOCK.H>
524
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
    76
# undef NO_SOCKET
527
f48fd11817e2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 526
diff changeset
    77
# define WANT__AF_INET
421
d4db572da862 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 420
diff changeset
    78
d4db572da862 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 420
diff changeset
    79
# ifdef __DEF_Array
d4db572da862 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 420
diff changeset
    80
#  define Array __DEF_Array
d4db572da862 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 420
diff changeset
    81
# endif
d4db572da862 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 420
diff changeset
    82
# ifdef __DEF_Number
d4db572da862 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 420
diff changeset
    83
#  define Number __DEF_Number
d4db572da862 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 420
diff changeset
    84
# endif
d4db572da862 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 420
diff changeset
    85
# ifdef __DEF_Method
d4db572da862 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 420
diff changeset
    86
#  define Method __DEF_Method
d4db572da862 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 420
diff changeset
    87
# endif
d4db572da862 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 420
diff changeset
    88
# ifdef __DEF_Point
d4db572da862 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 420
diff changeset
    89
#  define Point __DEF_Point
465
3673e44dbd2f remove windows ^M characters
Claus Gittinger <cg@exept.de>
parents: 464
diff changeset
    90
# endif
3673e44dbd2f remove windows ^M characters
Claus Gittinger <cg@exept.de>
parents: 464
diff changeset
    91
# ifdef __DEF_Block
3673e44dbd2f remove windows ^M characters
Claus Gittinger <cg@exept.de>
parents: 464
diff changeset
    92
#  define Block __DEF_Block
3673e44dbd2f remove windows ^M characters
Claus Gittinger <cg@exept.de>
parents: 464
diff changeset
    93
# endif
3673e44dbd2f remove windows ^M characters
Claus Gittinger <cg@exept.de>
parents: 464
diff changeset
    94
# ifdef __DEF_Context
3673e44dbd2f remove windows ^M characters
Claus Gittinger <cg@exept.de>
parents: 464
diff changeset
    95
#  define Context __DEF_Context
506
11ef93d12870 support anonymous (OS_specified) ports. (for FTP-protocol)
Claus Gittinger <cg@exept.de>
parents: 486
diff changeset
    96
# endif
465
3673e44dbd2f remove windows ^M characters
Claus Gittinger <cg@exept.de>
parents: 464
diff changeset
    97
# ifdef __DEF_String
3673e44dbd2f remove windows ^M characters
Claus Gittinger <cg@exept.de>
parents: 464
diff changeset
    98
#  define String __DEF_String
506
11ef93d12870 support anonymous (OS_specified) ports. (for FTP-protocol)
Claus Gittinger <cg@exept.de>
parents: 486
diff changeset
    99
# endif
465
3673e44dbd2f remove windows ^M characters
Claus Gittinger <cg@exept.de>
parents: 464
diff changeset
   100
# ifdef __DEF_Message
3673e44dbd2f remove windows ^M characters
Claus Gittinger <cg@exept.de>
parents: 464
diff changeset
   101
#  define Message __DEF_Message
506
11ef93d12870 support anonymous (OS_specified) ports. (for FTP-protocol)
Claus Gittinger <cg@exept.de>
parents: 486
diff changeset
   102
# endif
465
3673e44dbd2f remove windows ^M characters
Claus Gittinger <cg@exept.de>
parents: 464
diff changeset
   103
# ifdef __DEF_Object
3673e44dbd2f remove windows ^M characters
Claus Gittinger <cg@exept.de>
parents: 464
diff changeset
   104
#  define Object __DEF_Object
506
11ef93d12870 support anonymous (OS_specified) ports. (for FTP-protocol)
Claus Gittinger <cg@exept.de>
parents: 486
diff changeset
   105
# endif
421
d4db572da862 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 420
diff changeset
   106
418
317e55c6c281 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 403
diff changeset
   107
#else
317e55c6c281 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 403
diff changeset
   108
317e55c6c281 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 403
diff changeset
   109
# if !defined(NO_SOCKET)
317e55c6c281 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 403
diff changeset
   110
#  include <fcntl.h>
317e55c6c281 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 403
diff changeset
   111
#  include <sys/types.h>
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   112
418
317e55c6c281 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 403
diff changeset
   113
#  if defined(IRIS) && !defined(IRIX5)
317e55c6c281 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 403
diff changeset
   114
    /* no socket.h on 4.0.5h ?!?!? */
525
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
   115
#   ifndef AF_UNIX
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
   116
#    define AF_UNIX 1
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
   117
#   endif
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
   118
#   ifndef AF_INET
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
   119
#    define AF_INET 2
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
   120
#   endif
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
   121
#   ifndef SOCK_STREAM
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
   122
#    define SOCK_STREAM 1
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
   123
#   endif
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
   124
#   ifndef SOCK_DGRAM
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
   125
#    define SOCK_DGRAM  2
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
   126
#   endif
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
   127
#   ifndef SOCK_RAW
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
   128
#    define SOCK_RAW    3
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
   129
#   endif
418
317e55c6c281 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 403
diff changeset
   130
#  else
317e55c6c281 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 403
diff changeset
   131
#   include <sys/socket.h>
317e55c6c281 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 403
diff changeset
   132
#  endif
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   133
418
317e55c6c281 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 403
diff changeset
   134
#  ifdef NEXT3
317e55c6c281 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 403
diff changeset
   135
#   include <netinet/in_systm.h>
317e55c6c281 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 403
diff changeset
   136
#  endif
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   137
# endif
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   138
#endif
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   139
525
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
   140
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   141
/*
528
928f68d9c080 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 527
diff changeset
   142
 * see what we want ...
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   143
 */
525
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
   144
#ifdef WANT__AF_UNIX
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
   145
# ifdef AF_UNIX
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
   146
#  ifndef PF_UNIX
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
   147
#   define PF_UNIX AF_UNIX
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
   148
#  endif
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   149
# endif
525
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
   150
#else
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
   151
# undef AF_UNIX
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
   152
#endif
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
   153
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
   154
#ifdef WANT__AF_INET
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
   155
# ifdef AF_INET
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
   156
#  ifndef PF_INET
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
   157
#   define PF_INET AF_INET
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
   158
#  endif
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
   159
# endif
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
   160
#else
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
   161
# undef AF_INET
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   162
#endif
525
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
   163
530
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
   164
#ifdef WANT__AF_INET6
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
   165
# ifdef AF_INET6
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
   166
#  ifndef PF_INET6
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
   167
#   define PF_INET6 AF_INET6
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
   168
#  endif
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
   169
# endif
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
   170
#else
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
   171
# undef AF_INET6
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
   172
#endif
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
   173
525
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
   174
#ifdef WANT__AF_DECnet
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
   175
# ifdef AF_DECnet
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
   176
#  ifndef PF_DECnet
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
   177
#   define PF_DECnet AF_DECnet
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
   178
#  endif
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
   179
# endif
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
   180
#else
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
   181
# undef AF_DECnet
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
   182
#endif
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
   183
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
   184
#ifdef WANT__AF_APPLETALK
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
   185
# ifdef AF_APPLETALK
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
   186
#  ifndef PF_APPLETALK
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
   187
#   define PF_APPLETALK AF_APPLETALK
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
   188
#  endif
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   189
# endif
525
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
   190
#else
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
   191
# undef AF_APPLETALK
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   192
#endif
525
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
   193
530
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
   194
#ifdef WANT__AF_X25	/* X.25 */
525
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
   195
# ifdef AF_X25
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
   196
#  ifndef PF_X25
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
   197
#   define PF_X25 AF_X25
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
   198
#  endif
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
   199
# endif
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
   200
#else
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
   201
# undef AF_X25
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
   202
#endif
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
   203
530
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
   204
#ifdef WANT__AF_NS	/* Xerox XNS */
525
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
   205
# ifdef AF_NS
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
   206
#  ifndef PF_NS
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
   207
#   define PF_NS AF_NS
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
   208
#  endif
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   209
# endif
525
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
   210
#else
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
   211
# undef AF_NS
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   212
#endif
525
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
   213
530
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
   214
#ifdef WANT__AF_SNA	/* IBM SNA */
525
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
   215
# ifdef AF_SNA
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
   216
#  ifndef PF_SNA
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
   217
#   define PF_SNA AF_SNA
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
   218
#  endif
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   219
# endif
525
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
   220
#else
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
   221
# undef AF_SNA
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
   222
#endif
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
   223
530
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
   224
#ifdef WANT__AF_RAW	/* RAW packets */
525
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
   225
# ifdef AF_RAW
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
   226
#  ifndef PF_RAW
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
   227
#   define PF_RAW AF_RAW
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
   228
#  endif
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
   229
# endif
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
   230
#else
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
   231
# undef AF_RAW
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   232
#endif
525
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
   233
530
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
   234
#ifdef WANT__AF_ISO	/* ? */
525
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
   235
# ifdef AF_ISO
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
   236
#  ifndef PF_ISO
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
   237
#   define PF_ISO AF_ISO
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
   238
#  endif
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
   239
# endif
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
   240
#else
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
   241
# undef AF_ISO
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
   242
#endif
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
   243
530
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
   244
#ifdef WANT__AF_NETBIOS /* ? */
525
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
   245
# ifdef AF_NETBIOS
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
   246
#  ifndef PF_NETBIOS
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
   247
#   define PF_NETBIOS AF_NETBIOS
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
   248
#  endif
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   249
# endif
525
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
   250
#else
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
   251
# undef WANT_AF_NETBIOS
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   252
#endif
525
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
   253
530
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
   254
#ifdef WANT__AF_CCITT /* ? */
525
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
   255
# if defined(AF_CCITT) && (AF_CCITT != AF_X25)
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
   256
#  ifndef PF_CCITT
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
   257
#   define PF_CCITT AF_CCITT
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
   258
#  endif
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
   259
# endif
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
   260
#else
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
   261
# undef AF_CCITT
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
   262
#endif
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
   263
530
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
   264
#ifdef WANT__AF_IPX /* Novell IPX */
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
   265
# ifdef AF_IPX
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
   266
#  ifndef PF_IPX
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
   267
#   define PF_IPX AF_IPX
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
   268
#  endif
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
   269
# endif
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
   270
#else
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
   271
# undef WANT_AF_IPX
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
   272
#endif
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
   273
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
   274
#ifdef WANT__AF_AX25 /* Amateur radio ax25 */
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
   275
# ifdef AF_AX25
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
   276
#  ifndef PF_AX25
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
   277
#   define PF_AX25 AF_AX25
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
   278
#  endif
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
   279
# endif
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
   280
#else
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
   281
# undef WANT_AF_AX25
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
   282
#endif
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
   283
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
   284
#ifdef WANT__AF_NETROM /* Amateur radio NETROM */
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
   285
# ifdef AF_NETROM
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
   286
#  ifndef PF_NETROM
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
   287
#   define PF_NETROM AF_NETROM
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
   288
#  endif
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
   289
# endif
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
   290
#else
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
   291
# undef WANT_AF_NETROM
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
   292
#endif
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
   293
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
   294
#ifdef WANT__AF_BRIDGE /* multiprotocol bridge */
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
   295
# ifdef AF_BRIDGE
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
   296
#  ifndef PF_BRIDGE
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
   297
#   define PF_BRIDGE AF_BRIDGE
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
   298
#  endif
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
   299
# endif
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
   300
#else
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
   301
# undef WANT_AF_BRIDGE
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
   302
#endif
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
   303
528
928f68d9c080 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 527
diff changeset
   304
/*
928f68d9c080 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 527
diff changeset
   305
 * now, include what we have to ...
928f68d9c080 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 527
diff changeset
   306
 */
530
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
   307
#ifndef WIN32 /* win32 has all in winsock.h */
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
   308
528
928f68d9c080 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 527
diff changeset
   309
# ifdef AF_INET
928f68d9c080 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 527
diff changeset
   310
#  include <netdb.h>
928f68d9c080 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 527
diff changeset
   311
#  include <netinet/in.h>
928f68d9c080 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 527
diff changeset
   312
#  if ! (defined(SYSV3) && defined(mc88k))
928f68d9c080 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 527
diff changeset
   313
#   include <netinet/tcp.h>
928f68d9c080 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 527
diff changeset
   314
#  endif
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   315
# endif
528
928f68d9c080 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 527
diff changeset
   316
928f68d9c080 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 527
diff changeset
   317
# ifdef AF_UNIX
928f68d9c080 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 527
diff changeset
   318
#  include <sys/un.h>
465
3673e44dbd2f remove windows ^M characters
Claus Gittinger <cg@exept.de>
parents: 464
diff changeset
   319
# endif
528
928f68d9c080 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 527
diff changeset
   320
928f68d9c080 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 527
diff changeset
   321
# ifdef AF_APPLETALK
928f68d9c080 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 527
diff changeset
   322
#  ifdef LINUX
928f68d9c080 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 527
diff changeset
   323
#   include <linux/atalk.h>
928f68d9c080 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 527
diff changeset
   324
#  endif
928f68d9c080 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 527
diff changeset
   325
# endif
530
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
   326
528
928f68d9c080 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 527
diff changeset
   327
#endif /* WIN32 */
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   328
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   329
/*
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   330
 * on some systems errno is a macro ... check for it here
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   331
 */
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   332
#ifndef errno
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   333
 extern errno;
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   334
#endif
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   335
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   336
#ifdef DEBUG
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   337
# define DBGPRINTF(x)    { if (__debugging__) printf x; }
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   338
#else
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   339
# define DBGPRINTF(x)    /* as nothing */
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   340
#endif
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   341
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   342
%}
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   343
! !
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   344
511
c071e228cb24 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 510
diff changeset
   345
!Socket primitiveVariables!
c071e228cb24 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 510
diff changeset
   346
%{
c071e228cb24 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 510
diff changeset
   347
static int __debugging__ = 0;
c071e228cb24 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 510
diff changeset
   348
%}
c071e228cb24 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 510
diff changeset
   349
! !
c071e228cb24 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 510
diff changeset
   350
464
600b101a7035 alen in accept
Claus Gittinger <cg@exept.de>
parents: 463
diff changeset
   351
!Socket class methodsFor:'documentation'!
25
996051271ce9 *** empty log message ***
claus
parents: 21
diff changeset
   352
31
e223f3cf2995 *** empty log message ***
claus
parents: 28
diff changeset
   353
copyright
e223f3cf2995 *** empty log message ***
claus
parents: 28
diff changeset
   354
"
e223f3cf2995 *** empty log message ***
claus
parents: 28
diff changeset
   355
 COPYRIGHT (c) 1992 by Claus Gittinger
42
506596f9a1a8 *** empty log message ***
claus
parents: 38
diff changeset
   356
	      All Rights Reserved
31
e223f3cf2995 *** empty log message ***
claus
parents: 28
diff changeset
   357
e223f3cf2995 *** empty log message ***
claus
parents: 28
diff changeset
   358
 This software is furnished under a license and may be used
e223f3cf2995 *** empty log message ***
claus
parents: 28
diff changeset
   359
 only in accordance with the terms of that license and with the
e223f3cf2995 *** empty log message ***
claus
parents: 28
diff changeset
   360
 inclusion of the above copyright notice.   This software may not
e223f3cf2995 *** empty log message ***
claus
parents: 28
diff changeset
   361
 be provided or otherwise made available to, or used by, any
e223f3cf2995 *** empty log message ***
claus
parents: 28
diff changeset
   362
 other person.  No title to or ownership of the software is
e223f3cf2995 *** empty log message ***
claus
parents: 28
diff changeset
   363
 hereby transferred.
e223f3cf2995 *** empty log message ***
claus
parents: 28
diff changeset
   364
"
e223f3cf2995 *** empty log message ***
claus
parents: 28
diff changeset
   365
!
e223f3cf2995 *** empty log message ***
claus
parents: 28
diff changeset
   366
25
996051271ce9 *** empty log message ***
claus
parents: 21
diff changeset
   367
documentation
996051271ce9 *** empty log message ***
claus
parents: 21
diff changeset
   368
"
524
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
   369
    This class provides access to sockets for interprocess communication.
25
996051271ce9 *** empty log message ***
claus
parents: 21
diff changeset
   370
    The message protocol is preliminary, until someone tells me how
31
e223f3cf2995 *** empty log message ***
claus
parents: 28
diff changeset
   371
    other smalltalk's socket interfaces look like.
25
996051271ce9 *** empty log message ***
claus
parents: 21
diff changeset
   372
525
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
   373
    Currently, only IP and UNIX domain sockets are supported.
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
   374
    Code for appletalk is included, but was never tested ...
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
   375
    More may be added in the future.
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
   376
    (the code is prepared for things like SNA or decNet;
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
   377
     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
   378
     Implementing those is pretty straight forward, once the address
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
   379
     data structures are known.)
524
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
   380
28
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
   381
    Due to historic reasons (I started this class, before I got hold of some
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
   382
    code using ST-80 Sockets i.e. RemoteInvocation), there is some old interface
71
claus
parents: 63
diff changeset
   383
    still provided. 
524
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
   384
    This will vanish; use the #family:type: or #newTCPxxx and #newUDPxxx interfaces,
71
claus
parents: 63
diff changeset
   385
    together with the bind/listen and accept calls,
claus
parents: 63
diff changeset
   386
    which are meant to be compatible to ST-80's UnixSocketAccessor interface.
claus
parents: 63
diff changeset
   387
524
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
   388
    ST/X does not use IPSocketAddress, UDSocketAddress etc; all addressing
71
claus
parents: 63
diff changeset
   389
    is done by passing appropriate string- or byteArray objects containing
claus
parents: 63
diff changeset
   390
    the addresses. This may change, too.
claus
parents: 63
diff changeset
   391
claus
parents: 63
diff changeset
   392
    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
   393
	  (mhmh - how can I test those ?)
529
fc7ec265717b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   394
	  Help - could someone who has a linux machine connected to an appletalk
fc7ec265717b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   395
	         net please test this (and send bug fixes ...)
259
6d36f3ac42a2 documentation
Claus Gittinger <cg@exept.de>
parents: 220
diff changeset
   396
6d36f3ac42a2 documentation
Claus Gittinger <cg@exept.de>
parents: 220
diff changeset
   397
    [author:]
425
eb8198e9f1b0 comment
Claus Gittinger <cg@exept.de>
parents: 421
diff changeset
   398
	Claus Gittinger
48
18b9353c9d07 *** empty log message ***
claus
parents: 44
diff changeset
   399
"
18b9353c9d07 *** empty log message ***
claus
parents: 44
diff changeset
   400
!
28
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
   401
48
18b9353c9d07 *** empty log message ***
claus
parents: 44
diff changeset
   402
examples
18b9353c9d07 *** empty log message ***
claus
parents: 44
diff changeset
   403
"
28
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
   404
    example (get help info from an nntp server):
425
eb8198e9f1b0 comment
Claus Gittinger <cg@exept.de>
parents: 421
diff changeset
   405
									[exBegin]
eb8198e9f1b0 comment
Claus Gittinger <cg@exept.de>
parents: 421
diff changeset
   406
	|sock host|
209
2152fceba563 finger example
Claus Gittinger <cg@exept.de>
parents: 208
diff changeset
   407
425
eb8198e9f1b0 comment
Claus Gittinger <cg@exept.de>
parents: 421
diff changeset
   408
	host := OperatingSystem getEnvironment:'NNTPSERVER'.
28
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
   409
425
eb8198e9f1b0 comment
Claus Gittinger <cg@exept.de>
parents: 421
diff changeset
   410
	sock := Socket newTCPclientToHost:host port:'nntp'.
eb8198e9f1b0 comment
Claus Gittinger <cg@exept.de>
parents: 421
diff changeset
   411
	Transcript showCR:sock nextLine.
eb8198e9f1b0 comment
Claus Gittinger <cg@exept.de>
parents: 421
diff changeset
   412
	sock buffered:false.
93
Claus Gittinger <cg@exept.de>
parents: 92
diff changeset
   413
425
eb8198e9f1b0 comment
Claus Gittinger <cg@exept.de>
parents: 421
diff changeset
   414
	sock nextPutAll:'HELP'; cr.
eb8198e9f1b0 comment
Claus Gittinger <cg@exept.de>
parents: 421
diff changeset
   415
	[:exit |
eb8198e9f1b0 comment
Claus Gittinger <cg@exept.de>
parents: 421
diff changeset
   416
	    |line|
209
2152fceba563 finger example
Claus Gittinger <cg@exept.de>
parents: 208
diff changeset
   417
425
eb8198e9f1b0 comment
Claus Gittinger <cg@exept.de>
parents: 421
diff changeset
   418
	    line := sock nextLine.
eb8198e9f1b0 comment
Claus Gittinger <cg@exept.de>
parents: 421
diff changeset
   419
	    line = '.' ifTrue:[exit value:nil].
eb8198e9f1b0 comment
Claus Gittinger <cg@exept.de>
parents: 421
diff changeset
   420
	    Transcript showCR:line.
eb8198e9f1b0 comment
Claus Gittinger <cg@exept.de>
parents: 421
diff changeset
   421
	] loopWithExit.
eb8198e9f1b0 comment
Claus Gittinger <cg@exept.de>
parents: 421
diff changeset
   422
	sock close
eb8198e9f1b0 comment
Claus Gittinger <cg@exept.de>
parents: 421
diff changeset
   423
									[exEnd]
209
2152fceba563 finger example
Claus Gittinger <cg@exept.de>
parents: 208
diff changeset
   424
28
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
   425
209
2152fceba563 finger example
Claus Gittinger <cg@exept.de>
parents: 208
diff changeset
   426
    example (connect to finger daemon, get users entry):
425
eb8198e9f1b0 comment
Claus Gittinger <cg@exept.de>
parents: 421
diff changeset
   427
									[exBegin]
eb8198e9f1b0 comment
Claus Gittinger <cg@exept.de>
parents: 421
diff changeset
   428
	|sock host entry|
209
2152fceba563 finger example
Claus Gittinger <cg@exept.de>
parents: 208
diff changeset
   429
425
eb8198e9f1b0 comment
Claus Gittinger <cg@exept.de>
parents: 421
diff changeset
   430
	host := OperatingSystem getHostName.
28
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
   431
425
eb8198e9f1b0 comment
Claus Gittinger <cg@exept.de>
parents: 421
diff changeset
   432
	sock := Socket newTCPclientToHost:host port:'finger'.
eb8198e9f1b0 comment
Claus Gittinger <cg@exept.de>
parents: 421
diff changeset
   433
	sock useCRLF:true.
eb8198e9f1b0 comment
Claus Gittinger <cg@exept.de>
parents: 421
diff changeset
   434
	sock buffered:false.
eb8198e9f1b0 comment
Claus Gittinger <cg@exept.de>
parents: 421
diff changeset
   435
	sock isNil ifTrue:[
eb8198e9f1b0 comment
Claus Gittinger <cg@exept.de>
parents: 421
diff changeset
   436
	    Transcript showCR:'cannot connect to local finger daemon'
eb8198e9f1b0 comment
Claus Gittinger <cg@exept.de>
parents: 421
diff changeset
   437
	] ifFalse:[
eb8198e9f1b0 comment
Claus Gittinger <cg@exept.de>
parents: 421
diff changeset
   438
	    sock nextPutAll:(OperatingSystem getLoginName).
eb8198e9f1b0 comment
Claus Gittinger <cg@exept.de>
parents: 421
diff changeset
   439
	    sock cr.
28
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
   440
425
eb8198e9f1b0 comment
Claus Gittinger <cg@exept.de>
parents: 421
diff changeset
   441
	    entry := sock nextLine.
eb8198e9f1b0 comment
Claus Gittinger <cg@exept.de>
parents: 421
diff changeset
   442
	    Transcript showCR:entry.
209
2152fceba563 finger example
Claus Gittinger <cg@exept.de>
parents: 208
diff changeset
   443
425
eb8198e9f1b0 comment
Claus Gittinger <cg@exept.de>
parents: 421
diff changeset
   444
	    sock close
eb8198e9f1b0 comment
Claus Gittinger <cg@exept.de>
parents: 421
diff changeset
   445
	]
eb8198e9f1b0 comment
Claus Gittinger <cg@exept.de>
parents: 421
diff changeset
   446
									[exEnd]
99
7d016cc30052 fixed & moved pingWalk from SNMPSession to here;
Claus Gittinger <cg@exept.de>
parents: 98
diff changeset
   447
28
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
   448
    example (connect to an ftp server):
425
eb8198e9f1b0 comment
Claus Gittinger <cg@exept.de>
parents: 421
diff changeset
   449
									[exBegin]
eb8198e9f1b0 comment
Claus Gittinger <cg@exept.de>
parents: 421
diff changeset
   450
	|sock host|
28
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
   451
425
eb8198e9f1b0 comment
Claus Gittinger <cg@exept.de>
parents: 421
diff changeset
   452
	host := OperatingSystem getHostName.
eb8198e9f1b0 comment
Claus Gittinger <cg@exept.de>
parents: 421
diff changeset
   453
	sock := Socket newTCPclientToHost:host port:'ftp'.
28
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
   454
425
eb8198e9f1b0 comment
Claus Gittinger <cg@exept.de>
parents: 421
diff changeset
   455
	sock buffered:false.
eb8198e9f1b0 comment
Claus Gittinger <cg@exept.de>
parents: 421
diff changeset
   456
	Transcript showCR:sock nextLine.
eb8198e9f1b0 comment
Claus Gittinger <cg@exept.de>
parents: 421
diff changeset
   457
	sock nextPutAll:('USER ' , 'anonymous'); cr.
eb8198e9f1b0 comment
Claus Gittinger <cg@exept.de>
parents: 421
diff changeset
   458
	Transcript showCR:sock nextLine.
eb8198e9f1b0 comment
Claus Gittinger <cg@exept.de>
parents: 421
diff changeset
   459
	sock nextPutAll:('PASS ' , 'fooBar'); cr.
eb8198e9f1b0 comment
Claus Gittinger <cg@exept.de>
parents: 421
diff changeset
   460
	Transcript showCR:sock nextLine.
eb8198e9f1b0 comment
Claus Gittinger <cg@exept.de>
parents: 421
diff changeset
   461
	sock nextPutAll:'LIST'; cr.
eb8198e9f1b0 comment
Claus Gittinger <cg@exept.de>
parents: 421
diff changeset
   462
	Transcript showCR:sock nextLine.
eb8198e9f1b0 comment
Claus Gittinger <cg@exept.de>
parents: 421
diff changeset
   463
	sock close.
28
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
   464
425
eb8198e9f1b0 comment
Claus Gittinger <cg@exept.de>
parents: 421
diff changeset
   465
	'dont know enough of the ftp protocol to continue here ...'
eb8198e9f1b0 comment
Claus Gittinger <cg@exept.de>
parents: 421
diff changeset
   466
									[exEnd]
28
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
   467
99
7d016cc30052 fixed & moved pingWalk from SNMPSession to here;
Claus Gittinger <cg@exept.de>
parents: 98
diff changeset
   468
93
Claus Gittinger <cg@exept.de>
parents: 92
diff changeset
   469
    example (connect to an snmp server [UDP]):
425
eb8198e9f1b0 comment
Claus Gittinger <cg@exept.de>
parents: 421
diff changeset
   470
									[exBegin]
eb8198e9f1b0 comment
Claus Gittinger <cg@exept.de>
parents: 421
diff changeset
   471
	|sock port|
42
506596f9a1a8 *** empty log message ***
claus
parents: 38
diff changeset
   472
425
eb8198e9f1b0 comment
Claus Gittinger <cg@exept.de>
parents: 421
diff changeset
   473
	sock := Socket newUDP.
eb8198e9f1b0 comment
Claus Gittinger <cg@exept.de>
parents: 421
diff changeset
   474
	port := Socket portOfService:'snmp'.
eb8198e9f1b0 comment
Claus Gittinger <cg@exept.de>
parents: 421
diff changeset
   475
	sock connectTo:(OperatingSystem getHostName) port:port.
eb8198e9f1b0 comment
Claus Gittinger <cg@exept.de>
parents: 421
diff changeset
   476
	sock buffered:false.
eb8198e9f1b0 comment
Claus Gittinger <cg@exept.de>
parents: 421
diff changeset
   477
	Transcript showCR:'got it'.
eb8198e9f1b0 comment
Claus Gittinger <cg@exept.de>
parents: 421
diff changeset
   478
	sock close.
eb8198e9f1b0 comment
Claus Gittinger <cg@exept.de>
parents: 421
diff changeset
   479
									[exEnd]
42
506596f9a1a8 *** empty log message ***
claus
parents: 38
diff changeset
   480
99
7d016cc30052 fixed & moved pingWalk from SNMPSession to here;
Claus Gittinger <cg@exept.de>
parents: 98
diff changeset
   481
42
506596f9a1a8 *** empty log message ***
claus
parents: 38
diff changeset
   482
    example (await connection from a client and read some data):
425
eb8198e9f1b0 comment
Claus Gittinger <cg@exept.de>
parents: 421
diff changeset
   483
	|connectSock sock|
28
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
   484
425
eb8198e9f1b0 comment
Claus Gittinger <cg@exept.de>
parents: 421
diff changeset
   485
	connectSock := Socket newTCPserverAtPort:9998.  
eb8198e9f1b0 comment
Claus Gittinger <cg@exept.de>
parents: 421
diff changeset
   486
	connectSock isNil ifTrue:[
eb8198e9f1b0 comment
Claus Gittinger <cg@exept.de>
parents: 421
diff changeset
   487
	    Transcript showCR:'socket setup failed.'.
eb8198e9f1b0 comment
Claus Gittinger <cg@exept.de>
parents: 421
diff changeset
   488
	] ifFalse:[
eb8198e9f1b0 comment
Claus Gittinger <cg@exept.de>
parents: 421
diff changeset
   489
	    Transcript showCR:'listen ..'.
eb8198e9f1b0 comment
Claus Gittinger <cg@exept.de>
parents: 421
diff changeset
   490
	    (connectSock listenFor:5) ifFalse:[
eb8198e9f1b0 comment
Claus Gittinger <cg@exept.de>
parents: 421
diff changeset
   491
		Transcript showCR:'listen failed.'.
eb8198e9f1b0 comment
Claus Gittinger <cg@exept.de>
parents: 421
diff changeset
   492
	    ] ifTrue:[
eb8198e9f1b0 comment
Claus Gittinger <cg@exept.de>
parents: 421
diff changeset
   493
		Transcript showCR:'wait'.
eb8198e9f1b0 comment
Claus Gittinger <cg@exept.de>
parents: 421
diff changeset
   494
		connectSock readWait.  
eb8198e9f1b0 comment
Claus Gittinger <cg@exept.de>
parents: 421
diff changeset
   495
		Transcript showCR:'accept'.
eb8198e9f1b0 comment
Claus Gittinger <cg@exept.de>
parents: 421
diff changeset
   496
		sock := connectSock accept.
eb8198e9f1b0 comment
Claus Gittinger <cg@exept.de>
parents: 421
diff changeset
   497
		sock isNil ifTrue:[
eb8198e9f1b0 comment
Claus Gittinger <cg@exept.de>
parents: 421
diff changeset
   498
		    Transcript showCR:'accept failed.'.
eb8198e9f1b0 comment
Claus Gittinger <cg@exept.de>
parents: 421
diff changeset
   499
		] ifFalse:[
eb8198e9f1b0 comment
Claus Gittinger <cg@exept.de>
parents: 421
diff changeset
   500
		    sock buffered:false.
eb8198e9f1b0 comment
Claus Gittinger <cg@exept.de>
parents: 421
diff changeset
   501
		    Transcript showCR:'server: got it'.
eb8198e9f1b0 comment
Claus Gittinger <cg@exept.de>
parents: 421
diff changeset
   502
		    'can now do transfer via sock'.
eb8198e9f1b0 comment
Claus Gittinger <cg@exept.de>
parents: 421
diff changeset
   503
		    Transcript showCR:'read'.
eb8198e9f1b0 comment
Claus Gittinger <cg@exept.de>
parents: 421
diff changeset
   504
		    Transcript showCR:('got: ' , sock nextLine).
93
Claus Gittinger <cg@exept.de>
parents: 92
diff changeset
   505
425
eb8198e9f1b0 comment
Claus Gittinger <cg@exept.de>
parents: 421
diff changeset
   506
		    Transcript showCR:'close'.
eb8198e9f1b0 comment
Claus Gittinger <cg@exept.de>
parents: 421
diff changeset
   507
		    sock close
eb8198e9f1b0 comment
Claus Gittinger <cg@exept.de>
parents: 421
diff changeset
   508
		].
eb8198e9f1b0 comment
Claus Gittinger <cg@exept.de>
parents: 421
diff changeset
   509
		connectSock close.
eb8198e9f1b0 comment
Claus Gittinger <cg@exept.de>
parents: 421
diff changeset
   510
	    ]
eb8198e9f1b0 comment
Claus Gittinger <cg@exept.de>
parents: 421
diff changeset
   511
	]
42
506596f9a1a8 *** empty log message ***
claus
parents: 38
diff changeset
   512
99
7d016cc30052 fixed & moved pingWalk from SNMPSession to here;
Claus Gittinger <cg@exept.de>
parents: 98
diff changeset
   513
42
506596f9a1a8 *** empty log message ***
claus
parents: 38
diff changeset
   514
    example (connect to above server and send some data):
425
eb8198e9f1b0 comment
Claus Gittinger <cg@exept.de>
parents: 421
diff changeset
   515
	|sock|
42
506596f9a1a8 *** empty log message ***
claus
parents: 38
diff changeset
   516
425
eb8198e9f1b0 comment
Claus Gittinger <cg@exept.de>
parents: 421
diff changeset
   517
	sock := Socket newTCPclientToHost:(OperatingSystem getHostName) port:9998.
eb8198e9f1b0 comment
Claus Gittinger <cg@exept.de>
parents: 421
diff changeset
   518
	sock isNil ifTrue:[
eb8198e9f1b0 comment
Claus Gittinger <cg@exept.de>
parents: 421
diff changeset
   519
	    Transcript showCR:'nope'
eb8198e9f1b0 comment
Claus Gittinger <cg@exept.de>
parents: 421
diff changeset
   520
	] ifFalse:[
eb8198e9f1b0 comment
Claus Gittinger <cg@exept.de>
parents: 421
diff changeset
   521
	    sock buffered:false.
eb8198e9f1b0 comment
Claus Gittinger <cg@exept.de>
parents: 421
diff changeset
   522
	    Transcript showCR:'client: got it'.
eb8198e9f1b0 comment
Claus Gittinger <cg@exept.de>
parents: 421
diff changeset
   523
	    'can now do transfer via sock'.
eb8198e9f1b0 comment
Claus Gittinger <cg@exept.de>
parents: 421
diff changeset
   524
	    Transcript showCR:'sending <hello>'.
eb8198e9f1b0 comment
Claus Gittinger <cg@exept.de>
parents: 421
diff changeset
   525
	    sock nextPutLine:'hello'.
eb8198e9f1b0 comment
Claus Gittinger <cg@exept.de>
parents: 421
diff changeset
   526
	    sock close
eb8198e9f1b0 comment
Claus Gittinger <cg@exept.de>
parents: 421
diff changeset
   527
	]
117
03cefad7e40b UD socket example & interruptable bind
Claus Gittinger <cg@exept.de>
parents: 116
diff changeset
   528
03cefad7e40b UD socket example & interruptable bind
Claus Gittinger <cg@exept.de>
parents: 116
diff changeset
   529
    example: UNIX domain socket (await connection from a client and read some data):
03cefad7e40b UD socket example & interruptable bind
Claus Gittinger <cg@exept.de>
parents: 116
diff changeset
   530
425
eb8198e9f1b0 comment
Claus Gittinger <cg@exept.de>
parents: 421
diff changeset
   531
	|connectSock sock|
99
7d016cc30052 fixed & moved pingWalk from SNMPSession to here;
Claus Gittinger <cg@exept.de>
parents: 98
diff changeset
   532
425
eb8198e9f1b0 comment
Claus Gittinger <cg@exept.de>
parents: 421
diff changeset
   533
	'/tmp/ud_socket' asFilename remove.
eb8198e9f1b0 comment
Claus Gittinger <cg@exept.de>
parents: 421
diff changeset
   534
	connectSock := Socket newUNIXserverAt:'/tmp/ud_socket'.  
eb8198e9f1b0 comment
Claus Gittinger <cg@exept.de>
parents: 421
diff changeset
   535
	connectSock isNil ifTrue:[
eb8198e9f1b0 comment
Claus Gittinger <cg@exept.de>
parents: 421
diff changeset
   536
	    Transcript showCR:'socket setup failed.'.
eb8198e9f1b0 comment
Claus Gittinger <cg@exept.de>
parents: 421
diff changeset
   537
	] ifFalse:[
eb8198e9f1b0 comment
Claus Gittinger <cg@exept.de>
parents: 421
diff changeset
   538
	    Transcript showCR:'listen ..'.
eb8198e9f1b0 comment
Claus Gittinger <cg@exept.de>
parents: 421
diff changeset
   539
	    (connectSock listenFor:5) ifFalse:[
eb8198e9f1b0 comment
Claus Gittinger <cg@exept.de>
parents: 421
diff changeset
   540
		Transcript showCR:'listen failed.'.
eb8198e9f1b0 comment
Claus Gittinger <cg@exept.de>
parents: 421
diff changeset
   541
	    ] ifTrue:[
eb8198e9f1b0 comment
Claus Gittinger <cg@exept.de>
parents: 421
diff changeset
   542
		Transcript showCR:'wait'.
eb8198e9f1b0 comment
Claus Gittinger <cg@exept.de>
parents: 421
diff changeset
   543
		connectSock buffered:false.
eb8198e9f1b0 comment
Claus Gittinger <cg@exept.de>
parents: 421
diff changeset
   544
		connectSock readWait.  
eb8198e9f1b0 comment
Claus Gittinger <cg@exept.de>
parents: 421
diff changeset
   545
		Transcript showCR:'accept'.
eb8198e9f1b0 comment
Claus Gittinger <cg@exept.de>
parents: 421
diff changeset
   546
		sock := connectSock accept.
eb8198e9f1b0 comment
Claus Gittinger <cg@exept.de>
parents: 421
diff changeset
   547
		sock isNil ifTrue:[
eb8198e9f1b0 comment
Claus Gittinger <cg@exept.de>
parents: 421
diff changeset
   548
		    Transcript showCR:'accept failed.'.
eb8198e9f1b0 comment
Claus Gittinger <cg@exept.de>
parents: 421
diff changeset
   549
		] ifFalse:[
eb8198e9f1b0 comment
Claus Gittinger <cg@exept.de>
parents: 421
diff changeset
   550
		    sock buffered:false.
eb8198e9f1b0 comment
Claus Gittinger <cg@exept.de>
parents: 421
diff changeset
   551
		    Transcript showCR:'server: got it'.
eb8198e9f1b0 comment
Claus Gittinger <cg@exept.de>
parents: 421
diff changeset
   552
		    'can now do transfer via sock'.
eb8198e9f1b0 comment
Claus Gittinger <cg@exept.de>
parents: 421
diff changeset
   553
		    Transcript showCR:'read'.
eb8198e9f1b0 comment
Claus Gittinger <cg@exept.de>
parents: 421
diff changeset
   554
		    Transcript showCR:('got: ' , sock nextLine).
117
03cefad7e40b UD socket example & interruptable bind
Claus Gittinger <cg@exept.de>
parents: 116
diff changeset
   555
425
eb8198e9f1b0 comment
Claus Gittinger <cg@exept.de>
parents: 421
diff changeset
   556
		    Transcript showCR:'close'.
eb8198e9f1b0 comment
Claus Gittinger <cg@exept.de>
parents: 421
diff changeset
   557
		    sock close
eb8198e9f1b0 comment
Claus Gittinger <cg@exept.de>
parents: 421
diff changeset
   558
		].
eb8198e9f1b0 comment
Claus Gittinger <cg@exept.de>
parents: 421
diff changeset
   559
		connectSock close.
eb8198e9f1b0 comment
Claus Gittinger <cg@exept.de>
parents: 421
diff changeset
   560
	    ]
eb8198e9f1b0 comment
Claus Gittinger <cg@exept.de>
parents: 421
diff changeset
   561
	]
117
03cefad7e40b UD socket example & interruptable bind
Claus Gittinger <cg@exept.de>
parents: 116
diff changeset
   562
03cefad7e40b UD socket example & interruptable bind
Claus Gittinger <cg@exept.de>
parents: 116
diff changeset
   563
118
142d5c273454 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 117
diff changeset
   564
    example (connect to above server and send some data;
425
eb8198e9f1b0 comment
Claus Gittinger <cg@exept.de>
parents: 421
diff changeset
   565
	     Notice, this fails, if above server code is executed in the same ST/X image
eb8198e9f1b0 comment
Claus Gittinger <cg@exept.de>
parents: 421
diff changeset
   566
		     (at least on LINUX), since the OS does not correctly handle
eb8198e9f1b0 comment
Claus Gittinger <cg@exept.de>
parents: 421
diff changeset
   567
		     a connect from within an interrupted accept system call
eb8198e9f1b0 comment
Claus Gittinger <cg@exept.de>
parents: 421
diff changeset
   568
		     On SGI's SVR4, this works ok
117
03cefad7e40b UD socket example & interruptable bind
Claus Gittinger <cg@exept.de>
parents: 116
diff changeset
   569
425
eb8198e9f1b0 comment
Claus Gittinger <cg@exept.de>
parents: 421
diff changeset
   570
	|sock|
117
03cefad7e40b UD socket example & interruptable bind
Claus Gittinger <cg@exept.de>
parents: 116
diff changeset
   571
425
eb8198e9f1b0 comment
Claus Gittinger <cg@exept.de>
parents: 421
diff changeset
   572
	sock := Socket newUNIXclientTo:'/tmp/ud_socket'.
eb8198e9f1b0 comment
Claus Gittinger <cg@exept.de>
parents: 421
diff changeset
   573
	sock isNil ifTrue:[
eb8198e9f1b0 comment
Claus Gittinger <cg@exept.de>
parents: 421
diff changeset
   574
	    Transcript showCR:'nope'
eb8198e9f1b0 comment
Claus Gittinger <cg@exept.de>
parents: 421
diff changeset
   575
	] ifFalse:[
eb8198e9f1b0 comment
Claus Gittinger <cg@exept.de>
parents: 421
diff changeset
   576
	    sock buffered:false.
eb8198e9f1b0 comment
Claus Gittinger <cg@exept.de>
parents: 421
diff changeset
   577
	    Transcript showCR:'client: got it'.
eb8198e9f1b0 comment
Claus Gittinger <cg@exept.de>
parents: 421
diff changeset
   578
	    'can now do transfer via sock'.
eb8198e9f1b0 comment
Claus Gittinger <cg@exept.de>
parents: 421
diff changeset
   579
	    Transcript showCR:'sending <hello>'.
eb8198e9f1b0 comment
Claus Gittinger <cg@exept.de>
parents: 421
diff changeset
   580
	    sock nextPutLine:'hello'.
eb8198e9f1b0 comment
Claus Gittinger <cg@exept.de>
parents: 421
diff changeset
   581
	    sock close
eb8198e9f1b0 comment
Claus Gittinger <cg@exept.de>
parents: 421
diff changeset
   582
	]
99
7d016cc30052 fixed & moved pingWalk from SNMPSession to here;
Claus Gittinger <cg@exept.de>
parents: 98
diff changeset
   583
7d016cc30052 fixed & moved pingWalk from SNMPSession to here;
Claus Gittinger <cg@exept.de>
parents: 98
diff changeset
   584
7d016cc30052 fixed & moved pingWalk from SNMPSession to here;
Claus Gittinger <cg@exept.de>
parents: 98
diff changeset
   585
    example: pingWalk (try to ping hosts on the local network)
425
eb8198e9f1b0 comment
Claus Gittinger <cg@exept.de>
parents: 421
diff changeset
   586
									[exBegin]
eb8198e9f1b0 comment
Claus Gittinger <cg@exept.de>
parents: 421
diff changeset
   587
	|myName myAddress list top hosts walkProcess port|
99
7d016cc30052 fixed & moved pingWalk from SNMPSession to here;
Claus Gittinger <cg@exept.de>
parents: 98
diff changeset
   588
425
eb8198e9f1b0 comment
Claus Gittinger <cg@exept.de>
parents: 421
diff changeset
   589
	myName := OperatingSystem getHostName.
eb8198e9f1b0 comment
Claus Gittinger <cg@exept.de>
parents: 421
diff changeset
   590
	myAddress := Socket ipAddressOfHost:myName.
99
7d016cc30052 fixed & moved pingWalk from SNMPSession to here;
Claus Gittinger <cg@exept.de>
parents: 98
diff changeset
   591
425
eb8198e9f1b0 comment
Claus Gittinger <cg@exept.de>
parents: 421
diff changeset
   592
	port := Socket portOfService:'echo'.
eb8198e9f1b0 comment
Claus Gittinger <cg@exept.de>
parents: 421
diff changeset
   593
	port isNil ifTrue:[
eb8198e9f1b0 comment
Claus Gittinger <cg@exept.de>
parents: 421
diff changeset
   594
	    self error:'dont know echo port'.
eb8198e9f1b0 comment
Claus Gittinger <cg@exept.de>
parents: 421
diff changeset
   595
	    ^ self
eb8198e9f1b0 comment
Claus Gittinger <cg@exept.de>
parents: 421
diff changeset
   596
	].
99
7d016cc30052 fixed & moved pingWalk from SNMPSession to here;
Claus Gittinger <cg@exept.de>
parents: 98
diff changeset
   597
425
eb8198e9f1b0 comment
Claus Gittinger <cg@exept.de>
parents: 421
diff changeset
   598
	top := StandardSystemView new.
eb8198e9f1b0 comment
Claus Gittinger <cg@exept.de>
parents: 421
diff changeset
   599
	top label:'PING net walk'.
99
7d016cc30052 fixed & moved pingWalk from SNMPSession to here;
Claus Gittinger <cg@exept.de>
parents: 98
diff changeset
   600
425
eb8198e9f1b0 comment
Claus Gittinger <cg@exept.de>
parents: 421
diff changeset
   601
	list := ScrollableView for:ListView in:top.
eb8198e9f1b0 comment
Claus Gittinger <cg@exept.de>
parents: 421
diff changeset
   602
	list origin:0.0@0.0 corner:1.0@1.0.
99
7d016cc30052 fixed & moved pingWalk from SNMPSession to here;
Claus Gittinger <cg@exept.de>
parents: 98
diff changeset
   603
425
eb8198e9f1b0 comment
Claus Gittinger <cg@exept.de>
parents: 421
diff changeset
   604
	top openAndWait.
99
7d016cc30052 fixed & moved pingWalk from SNMPSession to here;
Claus Gittinger <cg@exept.de>
parents: 98
diff changeset
   605
425
eb8198e9f1b0 comment
Claus Gittinger <cg@exept.de>
parents: 421
diff changeset
   606
	walkProcess := [
eb8198e9f1b0 comment
Claus Gittinger <cg@exept.de>
parents: 421
diff changeset
   607
	    |l low hi direction tryHostID dottedName hostName conn addr|
99
7d016cc30052 fixed & moved pingWalk from SNMPSession to here;
Claus Gittinger <cg@exept.de>
parents: 98
diff changeset
   608
425
eb8198e9f1b0 comment
Claus Gittinger <cg@exept.de>
parents: 421
diff changeset
   609
	    l := SortedCollection new.
99
7d016cc30052 fixed & moved pingWalk from SNMPSession to here;
Claus Gittinger <cg@exept.de>
parents: 98
diff changeset
   610
425
eb8198e9f1b0 comment
Claus Gittinger <cg@exept.de>
parents: 421
diff changeset
   611
	    ' only works with type C-net
eb8198e9f1b0 comment
Claus Gittinger <cg@exept.de>
parents: 421
diff changeset
   612
	      the code below could simply do 1 to:254 do:[:hostID }
eb8198e9f1b0 comment
Claus Gittinger <cg@exept.de>
parents: 421
diff changeset
   613
	      but, to probe likely hosts earlier, the probing is done
eb8198e9f1b0 comment
Claus Gittinger <cg@exept.de>
parents: 421
diff changeset
   614
	      ping-pong like around my ip-address (assuming, that other machines
eb8198e9f1b0 comment
Claus Gittinger <cg@exept.de>
parents: 421
diff changeset
   615
	      have numbers around my own)'.
99
7d016cc30052 fixed & moved pingWalk from SNMPSession to here;
Claus Gittinger <cg@exept.de>
parents: 98
diff changeset
   616
425
eb8198e9f1b0 comment
Claus Gittinger <cg@exept.de>
parents: 421
diff changeset
   617
	    low := hi := (myAddress at:4).
eb8198e9f1b0 comment
Claus Gittinger <cg@exept.de>
parents: 421
diff changeset
   618
	    direction := 1.
99
7d016cc30052 fixed & moved pingWalk from SNMPSession to here;
Claus Gittinger <cg@exept.de>
parents: 98
diff changeset
   619
425
eb8198e9f1b0 comment
Claus Gittinger <cg@exept.de>
parents: 421
diff changeset
   620
	    [low > 0 or:[hi < 255]] whileTrue:[
eb8198e9f1b0 comment
Claus Gittinger <cg@exept.de>
parents: 421
diff changeset
   621
		direction > 0 ifTrue:[
eb8198e9f1b0 comment
Claus Gittinger <cg@exept.de>
parents: 421
diff changeset
   622
		    hi := hi + 1.
eb8198e9f1b0 comment
Claus Gittinger <cg@exept.de>
parents: 421
diff changeset
   623
		    tryHostID := hi.
eb8198e9f1b0 comment
Claus Gittinger <cg@exept.de>
parents: 421
diff changeset
   624
		    direction := -1.
eb8198e9f1b0 comment
Claus Gittinger <cg@exept.de>
parents: 421
diff changeset
   625
		] ifFalse:[
eb8198e9f1b0 comment
Claus Gittinger <cg@exept.de>
parents: 421
diff changeset
   626
		    low := low - 1.
eb8198e9f1b0 comment
Claus Gittinger <cg@exept.de>
parents: 421
diff changeset
   627
		    tryHostID := low.
eb8198e9f1b0 comment
Claus Gittinger <cg@exept.de>
parents: 421
diff changeset
   628
		    direction := 1.
eb8198e9f1b0 comment
Claus Gittinger <cg@exept.de>
parents: 421
diff changeset
   629
		].
eb8198e9f1b0 comment
Claus Gittinger <cg@exept.de>
parents: 421
diff changeset
   630
		(tryHostID between:1 and:254) ifTrue:[
eb8198e9f1b0 comment
Claus Gittinger <cg@exept.de>
parents: 421
diff changeset
   631
		    dottedName := (myAddress at:1) printString
eb8198e9f1b0 comment
Claus Gittinger <cg@exept.de>
parents: 421
diff changeset
   632
				  , '.' , (myAddress at:2) printString
eb8198e9f1b0 comment
Claus Gittinger <cg@exept.de>
parents: 421
diff changeset
   633
				  , '.' , (myAddress at:3) printString
eb8198e9f1b0 comment
Claus Gittinger <cg@exept.de>
parents: 421
diff changeset
   634
				  , '.' , tryHostID printString.
99
7d016cc30052 fixed & moved pingWalk from SNMPSession to here;
Claus Gittinger <cg@exept.de>
parents: 98
diff changeset
   635
425
eb8198e9f1b0 comment
Claus Gittinger <cg@exept.de>
parents: 421
diff changeset
   636
		    top label:'PING net walk - trying ' , dottedName.
99
7d016cc30052 fixed & moved pingWalk from SNMPSession to here;
Claus Gittinger <cg@exept.de>
parents: 98
diff changeset
   637
425
eb8198e9f1b0 comment
Claus Gittinger <cg@exept.de>
parents: 421
diff changeset
   638
		    top windowGroup withCursor:Cursor wait do:[
eb8198e9f1b0 comment
Claus Gittinger <cg@exept.de>
parents: 421
diff changeset
   639
			conn := Socket newTCPclientToHost:dottedName port:port withTimeout:1000.
eb8198e9f1b0 comment
Claus Gittinger <cg@exept.de>
parents: 421
diff changeset
   640
			conn notNil ifTrue:[
eb8198e9f1b0 comment
Claus Gittinger <cg@exept.de>
parents: 421
diff changeset
   641
			    addr := Socket ipAddressOfHost:dottedName.
eb8198e9f1b0 comment
Claus Gittinger <cg@exept.de>
parents: 421
diff changeset
   642
			    hostName := Socket hostWithIpAddress:addr.
eb8198e9f1b0 comment
Claus Gittinger <cg@exept.de>
parents: 421
diff changeset
   643
			    hostName isNil ifTrue:[
eb8198e9f1b0 comment
Claus Gittinger <cg@exept.de>
parents: 421
diff changeset
   644
				hostName :='?'
eb8198e9f1b0 comment
Claus Gittinger <cg@exept.de>
parents: 421
diff changeset
   645
			    ].
eb8198e9f1b0 comment
Claus Gittinger <cg@exept.de>
parents: 421
diff changeset
   646
			    l add:(dottedName paddedTo:15 with:Character space) 
eb8198e9f1b0 comment
Claus Gittinger <cg@exept.de>
parents: 421
diff changeset
   647
				   , ' ' 
eb8198e9f1b0 comment
Claus Gittinger <cg@exept.de>
parents: 421
diff changeset
   648
				   , (hostName paddedTo:15 with:Character space)
eb8198e9f1b0 comment
Claus Gittinger <cg@exept.de>
parents: 421
diff changeset
   649
				   , ' up & reachable'.
eb8198e9f1b0 comment
Claus Gittinger <cg@exept.de>
parents: 421
diff changeset
   650
			    list list:l.
eb8198e9f1b0 comment
Claus Gittinger <cg@exept.de>
parents: 421
diff changeset
   651
			    conn close.
eb8198e9f1b0 comment
Claus Gittinger <cg@exept.de>
parents: 421
diff changeset
   652
			]
eb8198e9f1b0 comment
Claus Gittinger <cg@exept.de>
parents: 421
diff changeset
   653
		    ].
eb8198e9f1b0 comment
Claus Gittinger <cg@exept.de>
parents: 421
diff changeset
   654
		].
eb8198e9f1b0 comment
Claus Gittinger <cg@exept.de>
parents: 421
diff changeset
   655
	    ].
eb8198e9f1b0 comment
Claus Gittinger <cg@exept.de>
parents: 421
diff changeset
   656
	    top label:'PING reachable hosts'.
eb8198e9f1b0 comment
Claus Gittinger <cg@exept.de>
parents: 421
diff changeset
   657
	] forkAt:(Processor userBackgroundPriority).
eb8198e9f1b0 comment
Claus Gittinger <cg@exept.de>
parents: 421
diff changeset
   658
	walkProcess name:'ping net walker'.
eb8198e9f1b0 comment
Claus Gittinger <cg@exept.de>
parents: 421
diff changeset
   659
									[exEnd]
25
996051271ce9 *** empty log message ***
claus
parents: 21
diff changeset
   660
"
996051271ce9 *** empty log message ***
claus
parents: 21
diff changeset
   661
! !
996051271ce9 *** empty log message ***
claus
parents: 21
diff changeset
   662
464
600b101a7035 alen in accept
Claus Gittinger <cg@exept.de>
parents: 463
diff changeset
   663
!Socket class methodsFor:'ST80 instance creation'!
91
Claus Gittinger <cg@exept.de>
parents: 85
diff changeset
   664
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   665
family:domainSymbol type:typeSymbol
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   666
    "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
   667
     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
   668
     Type must be #stream, #datagram or #raw
91
Claus Gittinger <cg@exept.de>
parents: 85
diff changeset
   669
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   670
     XXX: currently only the #inet domain is supported"
91
Claus Gittinger <cg@exept.de>
parents: 85
diff changeset
   671
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   672
    ^ self domain:domainSymbol type:typeSymbol
51
24f978f1d849 *** empty log message ***
claus
parents: 48
diff changeset
   673
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   674
    "
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   675
     Socket family:#inet type:#stream
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   676
     Socket family:#inet type:#datagram
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   677
     Socket family:#unix type:#stream
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   678
    "
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   679
! !
93
Claus Gittinger <cg@exept.de>
parents: 92
diff changeset
   680
464
600b101a7035 alen in accept
Claus Gittinger <cg@exept.de>
parents: 463
diff changeset
   681
!Socket class methodsFor:'ST80 queries'!
115
a9d85df931c4 added Unix domain support
Claus Gittinger <cg@exept.de>
parents: 112
diff changeset
   682
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   683
sockStream
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   684
    "return the type code for stream sockets"
51
24f978f1d849 *** empty log message ***
claus
parents: 48
diff changeset
   685
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   686
    ^ #stream
44
b4db396f9255 EINTR stuff
claus
parents: 42
diff changeset
   687
! !
b4db396f9255 EINTR stuff
claus
parents: 42
diff changeset
   688
464
600b101a7035 alen in accept
Claus Gittinger <cg@exept.de>
parents: 463
diff changeset
   689
!Socket class methodsFor:'Signal constants'!
21
33eb5ffad09d *** empty log message ***
claus
parents: 8
diff changeset
   690
33eb5ffad09d *** empty log message ***
claus
parents: 8
diff changeset
   691
brokenConnectionSignal
33eb5ffad09d *** empty log message ***
claus
parents: 8
diff changeset
   692
    "return the signal used to tell broken connections.
33eb5ffad09d *** empty log message ***
claus
parents: 8
diff changeset
   693
     Since in unix, this is the same as the broken pipe signal,
33eb5ffad09d *** empty log message ***
claus
parents: 8
diff changeset
   694
     return that one.
33eb5ffad09d *** empty log message ***
claus
parents: 8
diff changeset
   695
     (for other Operatingsystems, this may change ..)"
33eb5ffad09d *** empty log message ***
claus
parents: 8
diff changeset
   696
33eb5ffad09d *** empty log message ***
claus
parents: 8
diff changeset
   697
    ^ PipeStream brokenPipeSignal
33eb5ffad09d *** empty log message ***
claus
parents: 8
diff changeset
   698
! !
33eb5ffad09d *** empty log message ***
claus
parents: 8
diff changeset
   699
464
600b101a7035 alen in accept
Claus Gittinger <cg@exept.de>
parents: 463
diff changeset
   700
!Socket class methodsFor:'debugging'!
71
claus
parents: 63
diff changeset
   701
claus
parents: 63
diff changeset
   702
debug:aBoolean
claus
parents: 63
diff changeset
   703
    "turn on/off internal debugprints.
claus
parents: 63
diff changeset
   704
     This method is for ST/X debugging only and
claus
parents: 63
diff changeset
   705
     may  be removed in later versions"
claus
parents: 63
diff changeset
   706
claus
parents: 63
diff changeset
   707
%{  /* NOCONTEXT */
claus
parents: 63
diff changeset
   708
claus
parents: 63
diff changeset
   709
    __debugging__ = (aBoolean == true);
claus
parents: 63
diff changeset
   710
%}
93
Claus Gittinger <cg@exept.de>
parents: 92
diff changeset
   711
    "
Claus Gittinger <cg@exept.de>
parents: 92
diff changeset
   712
     Socket debug:true
Claus Gittinger <cg@exept.de>
parents: 92
diff changeset
   713
     Socket debug:false
Claus Gittinger <cg@exept.de>
parents: 92
diff changeset
   714
    "
71
claus
parents: 63
diff changeset
   715
! !
claus
parents: 63
diff changeset
   716
464
600b101a7035 alen in accept
Claus Gittinger <cg@exept.de>
parents: 463
diff changeset
   717
!Socket class methodsFor:'easy tcp/ip instance creation'!
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   718
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   719
connectTo:service on:host
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   720
    "standard & easy client setup: 
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   721
	create new client tcp socket, bind and connect; 
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   722
	return the socket.
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   723
     The system may block (interruptable), until the connection is 
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   724
     established."
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   725
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   726
    ^ (self new) for:host port:(self portOfService:service).
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   727
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   728
    "
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   729
     Socket connectTo:9995 on:'clam'
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   730
     Socket connectTo:'finger' on:'clam'
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   731
     Socket connectTo:'ftp' on:'clam'
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   732
     Socket connectTo:'nntp' on:(OperatingSystem getEnvironment:'NNTPSERVER')
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   733
    "
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   734
!
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   735
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   736
provide:service
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   737
    "standard & easy server setup: 
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   738
	create a new TCP server socket providing a service."
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   739
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   740
    |newSock|
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   741
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   742
    newSock := (self new) for:nil port:(self portOfService:service).
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   743
    newSock notNil ifTrue:[
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   744
	newSock listenFor:5.
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   745
    ].
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   746
    ^ newSock
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   747
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   748
    "
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   749
     Socket provide:9995
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   750
     (Socket provide:9996) accept
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   751
     Socket provide:'nntp'
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   752
    "
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   753
! !
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   754
464
600b101a7035 alen in accept
Claus Gittinger <cg@exept.de>
parents: 463
diff changeset
   755
!Socket class methodsFor:'general instance creation'!
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   756
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   757
domain:domainSymbol type:type
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   758
    "create a socket for domain and type -
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   759
     neither any connect nor binding is done.
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   760
     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
   761
     Type must be #stream, #datagram or #raw
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   762
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   763
     XXX: currently only the #inet domain is supported"
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   764
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   765
    ^ self new domain:domainSymbol type:type
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   766
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   767
    "
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   768
     Socket domain:#inet type:#stream
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   769
     Socket domain:#inet type:#datagram
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   770
     Socket domain:#unix type:#stream
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   771
     Socket domain:#appletalk type:#stream
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   772
     Socket domain:#DECnet type:#stream
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   773
    "
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   774
!
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   775
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   776
newTCP
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   777
    "create a TCP socket - no binding or other setup is done,
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   778
     neither connect nor connect-wait is done."
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   779
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   780
    ^ self new domain:#inet type:#stream 
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   781
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   782
    "Socket newUDP"
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   783
!
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   784
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   785
newTCP:aServiceOrNil
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   786
    "create a TCP socket for a service -
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   787
     neither connect nor connect-wait is done."
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   788
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   789
    |newSock|
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   790
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   791
    newSock := self newTCP.
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   792
    (newSock notNil and:[aServiceOrNil notNil]) ifTrue:[
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   793
	newSock bindTo:(self portOfService:aServiceOrNil) address:nil
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   794
    ].
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   795
    ^ newSock
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   796
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   797
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   798
    "Socket newTCP:'nntp'"
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   799
    "Socket newTCP:9995"
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   800
!
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   801
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   802
newTCPclientToHost:hostname port:aService
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   803
    "create a new TCP client socket connecting to a service.
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   804
     Return a socket instance if ok, nil on failure.
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   805
     Block until a connection is established (but only the current thread;
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   806
     not the whole smalltalk). 
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   807
     See also: #newTCPclientToHost:port:withTimeout:"
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   808
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   809
    ^ self newTCPclientToHost:hostname port:aService withTimeout:nil
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   810
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   811
    "
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   812
      Socket newTCPclientToHost:'localhost' port:'nntp'
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   813
    "
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   814
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   815
    "Created: 31.10.1995 / 18:54:11 / cg"
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   816
!
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   817
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   818
newTCPclientToHost:hostname port:aService withTimeout:millis
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   819
    "create a new TCP client socket connecting to a service.
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   820
     Return a socket instance if ok, nil on failure.
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   821
     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
   822
     and return nil.."
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   823
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   824
    |newSock|
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   825
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   826
    newSock := self newTCP.
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   827
    newSock notNil ifTrue:[
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   828
	(newSock connectTo:hostname port:(self portOfService:aService) withTimeout:millis) ifFalse:[
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   829
	    newSock close.
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   830
	    ^ nil
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   831
	]
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   832
    ].
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   833
    ^ newSock
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   834
"
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   835
same as:
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   836
    ^ (self new) for:hostname port:(self portOfService:aPort).
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   837
"
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   838
    "
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   839
      Socket newTCPclientToHost:'slsv6bt' port:'nntp'
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   840
      Socket newTCPclientToHost:'localhost' port:'nntp' withTimeout:1000
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   841
    "
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   842
!
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   843
506
11ef93d12870 support anonymous (OS_specified) ports. (for FTP-protocol)
Claus Gittinger <cg@exept.de>
parents: 486
diff changeset
   844
newTCPserverAtAnonymousPort
11ef93d12870 support anonymous (OS_specified) ports. (for FTP-protocol)
Claus Gittinger <cg@exept.de>
parents: 486
diff changeset
   845
    "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
   846
     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
   847
11ef93d12870 support anonymous (OS_specified) ports. (for FTP-protocol)
Claus Gittinger <cg@exept.de>
parents: 486
diff changeset
   848
    ^ self
11ef93d12870 support anonymous (OS_specified) ports. (for FTP-protocol)
Claus Gittinger <cg@exept.de>
parents: 486
diff changeset
   849
	newTCPserverAtPort:0
11ef93d12870 support anonymous (OS_specified) ports. (for FTP-protocol)
Claus Gittinger <cg@exept.de>
parents: 486
diff changeset
   850
11ef93d12870 support anonymous (OS_specified) ports. (for FTP-protocol)
Claus Gittinger <cg@exept.de>
parents: 486
diff changeset
   851
!
11ef93d12870 support anonymous (OS_specified) ports. (for FTP-protocol)
Claus Gittinger <cg@exept.de>
parents: 486
diff changeset
   852
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   853
newTCPserverAtPort:aService
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   854
    "create a new TCP server socket providing service."
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   855
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   856
    |newSock|
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   857
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   858
    newSock := self newTCP.
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   859
    newSock notNil ifTrue:[
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   860
	(newSock bindTo:(self portOfService:aService) address:nil) ifFalse:[
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   861
	    ^ nil
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   862
	]
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   863
    ].
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   864
    ^ newSock
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   865
"
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   866
same as:
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   867
    ^ (self new) for:nil port:aPort
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   868
"
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   869
!
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   870
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   871
newUDP
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   872
    "create a UDP socket - no binding or other setup is done,
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   873
     neither connect nor connect-wait is done."
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   874
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   875
    ^ self new domain:#inet type:#datagram
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   876
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   877
    "Socket newUDP"
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   878
!
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   879
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   880
newUDP:aServiceOrNil
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   881
    "create a UDP socket for a service -
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   882
     neither connect nor connect-wait is done."
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   883
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   884
    |newSock|
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   885
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   886
    newSock := self newUDP.
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   887
    (newSock notNil and:[aServiceOrNil notNil]) ifTrue:[
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   888
	newSock bindTo:(self portOfService:aServiceOrNil) address:nil
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   889
    ].
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   890
    ^ newSock
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   891
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   892
    "Socket newUDP:nil"
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   893
!
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   894
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   895
newUDPserverAtPort:aService
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   896
    "create a new UDP server socket providing service."
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   897
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   898
    |newSock|
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   899
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   900
    newSock := self newUDP.
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   901
    newSock notNil ifTrue:[
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   902
	(newSock bindTo:(self portOfService:aService) address:nil) ifFalse:[
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   903
	    ^ nil
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   904
	]
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   905
    ].
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   906
    ^ newSock
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   907
"
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   908
same as:
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   909
    ^ (self new) for:nil udpPort:aPort
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   910
"
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   911
!
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   912
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   913
newUNIX
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   914
    "create a UNIX domain socket - no binding or other setup is done,
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   915
     neither connect nor connect-wait is done."
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   916
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   917
    ^ self new domain:#unix type:#stream 
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   918
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   919
    "
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   920
     Socket newUNIX
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   921
    "
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   922
!
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   923
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   924
newUNIXclientTo:pathName 
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   925
    "create a new UNIX client socket connecting to a pathname.
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   926
     Return a socket instance if ok, nil on failure.
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   927
     Block until a connection is established (but only the current thread;
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   928
     not the whole smalltalk). 
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   929
     See also: #newUNIXclientTo:withTimeout:"
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   930
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   931
    ^ self newUNIXclientTo:pathName withTimeout:nil
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   932
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   933
!
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   934
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   935
newUNIXclientTo:pathName withTimeout:millis
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   936
    "create a new UNIX client socket connecting to a pathname.
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   937
     Return a socket instance if ok, nil on failure.
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   938
     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
   939
     and return nil.."
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   940
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   941
    |newSock|
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   942
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   943
    newSock := self newUNIX.
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   944
    newSock notNil ifTrue:[
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   945
	(newSock connectTo:pathName port:nil withTimeout:millis) ifFalse:[
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   946
	    newSock close.
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   947
	    ^ nil
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   948
	]
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   949
    ].
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   950
    ^ newSock
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   951
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   952
    "
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   953
     |s|
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   954
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   955
     s := Socket newUNIXclientTo:'/tmp/foo'
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   956
    "
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   957
!
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   958
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   959
newUNIXserverAt:pathName
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   960
    "create a new UNIX server socket providing service at a pathname."
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   961
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   962
    |newSock|
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   963
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   964
    newSock := self newUNIX.
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   965
    newSock notNil ifTrue:[
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   966
	(newSock bindTo:pathName address:nil) ifFalse:[
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   967
	    ^ nil
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   968
	]
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   969
    ].
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   970
    ^ newSock
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   971
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   972
    "
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   973
     |s s2|
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   974
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   975
     s := Socket newUNIXserverAt:'/tmp/foo'.
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   976
     s listenFor:5.
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   977
     s2 := s accept.
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   978
    "
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   979
! !
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   980
464
600b101a7035 alen in accept
Claus Gittinger <cg@exept.de>
parents: 463
diff changeset
   981
!Socket class methodsFor:'queries'!
0
1cf8d1747859 Initial revision
claus
parents:
diff changeset
   982
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   983
domainOfProtocol:aProtocol
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   984
    "given a protocols name (i.e. tcp, udp etc) return the domain.
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   985
     This method needs more ... - or is there a way to get this from the system ?"
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   986
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   987
    "
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   988
     tcp/ip stuff
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   989
    "
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   990
    (aProtocol = 'tcp') ifTrue:[^ #inet].
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   991
    (aProtocol = 'udp') ifTrue:[^ #inet].
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   992
    (aProtocol = 'ip')  ifTrue:[^ #inet].
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   993
    "
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   994
     unix domain
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   995
    "
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   996
    (aProtocol = 'ud')  ifTrue:[^ #unix].
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   997
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   998
    "
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
   999
     add x25 stuff (if any) here ...
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1000
    "
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1001
    "
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1002
     add appletalk stuff (if any) here ...
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1003
    "
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1004
    "
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1005
     add other stuff (if any) here ...
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1006
    "
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1007
    ^ nil
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1008
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1009
    "
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1010
     Socket domainOfProtocol:'tcp'
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1011
     Socket domainOfProtocol:'ucp'
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1012
     Socket domainOfProtocol:(Socket protocolOfService:'nntp')
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1013
     Socket domainOfProtocol:(Socket protocolOfService:'echo')
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1014
    "
525
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  1015
! !
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  1016
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  1017
!Socket class methodsFor:'host queries'!
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  1018
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  1019
appletalkAddressOfHost:aHostName
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  1020
    "return the APPLETALK address for a hostname as a byteArray,
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  1021
     where the network bytes come first followed by the node.
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  1022
     If the host is unknown, return nil.
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  1023
     This is the reverse operation to #hostWithAppletalkAddress:."
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  1024
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  1025
    |b1 b2 b3|
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  1026
%{
526
1748ab3892a3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 525
diff changeset
  1027
#if !defined(NO_SOCKET) && defined(AF_APPLETALK)
525
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  1028
    struct sockaddr_at sa ;
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  1029
    struct hostent *hp ;
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  1030
    long addr;
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  1031
529
fc7ec265717b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
  1032
    sa.sat_family = -1;
525
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  1033
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  1034
    if (__isString(aHostName)) {
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  1035
	bzero(&sa, sizeof(sa)) ;
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  1036
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  1037
	/* do we know the host's address? */
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  1038
	if ((hp = gethostbyname((char *) __stringVal(aHostName))) == NULL) {
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  1039
	    DBGPRINTF(("SOCKET: unknown host: %s\n", __stringVal(aHostName)));
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  1040
	    RETURN ( nil );
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  1041
	}
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  1042
	bcopy(hp->h_addr, (char *) &sa.sat_addr, hp->h_length) ;
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  1043
	sa.sat_family = hp->h_addrtype;
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  1044
    }
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  1045
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  1046
    /* if the addressing family is not AF_APPLETALK, return nil */
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  1047
    if (sa.sat_family != AF_INET) {
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  1048
	DBGPRINTF(("SOCKET: not an appletalk host\n"));
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  1049
	RETURN ( nil );
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  1050
    }
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  1051
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  1052
    sa.sat_addr.s_net = ntohs(sa.sat_addr.s_net);    
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  1053
    b1 = __MKSMALLINT((sa.sat_addr.s_net >> 8) & 0xFF);
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  1054
    b2 = __MKSMALLINT((sa.sat_addr.s_net) & 0xFF);
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  1055
    b3 = __MKSMALLINT((sa.sat_addr.s_node) & 0xFF);
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  1056
#else
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  1057
    RETURN (nil);
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  1058
#endif
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  1059
%}.
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  1060
    ^ ByteArray with:b1 with:b2 with:b3
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  1061
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  1062
!
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  1063
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  1064
hostWithAppletalkAddress:anAddress
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  1065
    "return the hostname for an APPLETALK address.
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  1066
     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
  1067
     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
  1068
     The last byte is the node number.
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  1069
     Nil is returned for an unknown host or if its not an appletalk host.
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  1070
     This is is the reverse operation to #appletalkAddressOfHost:."
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  1071
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  1072
    |b1 b2 b3 b4|
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  1073
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  1074
    b1 := anAddress at:1.
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  1075
    b2 := anAddress at:2.
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  1076
    b3 := anAddress at:3.
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  1077
    b4 := anAddress at:4.
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  1078
%{
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  1079
#if !defined(NO_SOCKET) && defined(AF_APPLETALK)
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  1080
    struct sockaddr_at sa ;
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  1081
    struct hostent *hp ;
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  1082
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  1083
    sa.sat_family = -1;
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  1084
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  1085
    if (__bothSmallInteger(b1, b2) && __bothSmallInteger(b3, b4)) {
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  1086
	bzero(&sa, sizeof(sa)) ;
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  1087
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  1088
	sa.sat_addr.s_net = _intVal(b1) & 0xFF;
529
fc7ec265717b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
  1089
	sa.sat_addr.s_net = (sa.sat_addr.s_net << 8) | (_intVal(b2) & 0xFF);
fc7ec265717b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
  1090
	sa.sat_addr.s_net = htons(sa.sat_addr.s_net);    
fc7ec265717b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
  1091
	sa.sat_addr.s_node = _intVal(b3) & 0xFF;
fc7ec265717b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
  1092
	sa.sat_family = AF_APPLETALK;
fc7ec265717b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
  1093
525
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  1094
	/* do we know the host's address? */
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  1095
	hp = gethostbyaddr((char *) &sa.sat_addr, sizeof(sa.sat_addr), AF_APPLETALK);
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  1096
	if (hp != NULL) {
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  1097
	    sa.sat_family = hp->h_addrtype;
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  1098
	} else {
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  1099
	    DBGPRINTF(("SOCKET: unknown address: %d.%d.%d.%d\n", 
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  1100
		       _intVal(b1), _intVal(b2), _intVal(b3)));
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  1101
	}
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  1102
    }
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  1103
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  1104
    /* if the addressing family is not AF_APPLETALK, return nil */
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  1105
    if (sa.sat_family != AF_APPLETALK) {
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  1106
	RETURN ( nil );
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  1107
    }
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  1108
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  1109
    if (hp != NULL) {
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  1110
	RETURN (__MKSTRING(hp->h_name));
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  1111
    }
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  1112
#endif
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  1113
    RETURN (nil);
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  1114
%}.
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  1115
    "
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  1116
     Socket appletalkAddressOfHost:'clam'
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  1117
     Socket hostWithAppletalkAddress:#[1 2 3]  
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  1118
     "
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1119
!
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1120
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1121
hostWithIpAddress:anAddress
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1122
    "return the hostname for an IP (internet-) address.
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1123
     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
  1124
     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
  1125
     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
  1126
     This is the reverse operation to #ipAddressOfHost:."
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1127
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1128
    |b1 b2 b3 b4|
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1129
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1130
    b1 := anAddress at:1.
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1131
    b2 := anAddress at:2.
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1132
    b3 := anAddress at:3.
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1133
    b4 := anAddress at:4.
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1134
%{
525
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  1135
#if !defined(NO_SOCKET) && defined(AF_INET)
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1136
    struct sockaddr_in sa ;
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1137
    struct hostent *hp ;
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1138
525
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  1139
    sa.sin_family = -1;
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1140
    if (__bothSmallInteger(b1, b2) && __bothSmallInteger(b3, b4)) {
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1141
	bzero(&sa, sizeof(sa)) ;
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1142
	sa.sin_addr.s_addr = _intVal(b1) & 0xFF;
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1143
	sa.sin_addr.s_addr = (sa.sin_addr.s_addr << 8) | (_intVal(b2) & 0xFF);
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1144
	sa.sin_addr.s_addr = (sa.sin_addr.s_addr << 8) | (_intVal(b3) & 0xFF);
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1145
	sa.sin_addr.s_addr = (sa.sin_addr.s_addr << 8) | (_intVal(b4) & 0xFF);
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1146
	sa.sin_addr.s_addr = htonl(sa.sin_addr.s_addr);    
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1147
	sa.sin_family = AF_INET;
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1148
	/* do we know the host's address? */
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1149
	hp = gethostbyaddr((char *) &sa.sin_addr.s_addr, sizeof(sa.sin_addr.s_addr), AF_INET);
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1150
	if (hp == NULL) {
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1151
	    DBGPRINTF(("SOCKET: unknown address: %d.%d.%d.%d\n", 
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1152
		       _intVal(b1), _intVal(b2), _intVal(b3), _intVal(b4)));
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1153
	} else {
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1154
	    sa.sin_family = hp->h_addrtype;
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1155
	}
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
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1158
    /* if the addressing family is not AF_INET, return nil */
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1159
    if (sa.sin_family != AF_INET) {
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1160
	RETURN ( nil );
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1161
    }
525
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  1162
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  1163
    if (hp != NULL) {
448
2203a4bb620d removed all COMMA_CON / CON_COMMA uses
Claus Gittinger <cg@exept.de>
parents: 444
diff changeset
  1164
	RETURN (__MKSTRING(hp->h_name));
525
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  1165
    }
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  1166
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  1167
    /*
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  1168
     * return it in dot-notation
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  1169
     */
448
2203a4bb620d removed all COMMA_CON / CON_COMMA uses
Claus Gittinger <cg@exept.de>
parents: 444
diff changeset
  1170
    RETURN (__MKSTRING(inet_ntoa(sa.sin_addr)));
418
317e55c6c281 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 403
diff changeset
  1171
#else
317e55c6c281 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 403
diff changeset
  1172
    RETURN (nil);
317e55c6c281 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 403
diff changeset
  1173
#endif
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1174
%}
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
    "
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1177
     Socket ipAddressOfHost:'clam'
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1178
     Socket hostWithIpAddress:(Socket ipAddressOfHost:'clam') 
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1179
     Socket ipAddressOfHost:'porty'
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1180
     Socket hostWithIpAddress:(Socket ipAddressOfHost:'porty') 
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1181
     Socket hostWithIpAddress:#[1 2 3 4]  
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1182
     Socket hostWithIpAddress:(Socket ipAddressOfHost:'1.2.3.4')  
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1183
     "
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1184
!
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1185
6
claus
parents: 4
diff changeset
  1186
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
  1187
    "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
  1188
     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
  1189
     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
  1190
     This is the reverse operation to #hostWithIpAddress:."
6
claus
parents: 4
diff changeset
  1191
claus
parents: 4
diff changeset
  1192
    |b1 b2 b3 b4|
claus
parents: 4
diff changeset
  1193
claus
parents: 4
diff changeset
  1194
%{
525
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  1195
#if !defined(NO_SOCKET) && defined(AF_INET)
6
claus
parents: 4
diff changeset
  1196
    struct sockaddr_in sa ;
claus
parents: 4
diff changeset
  1197
    struct hostent *hp ;
claus
parents: 4
diff changeset
  1198
    long addr;
claus
parents: 4
diff changeset
  1199
525
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  1200
    sa.sin_family = -1;
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  1201
21
33eb5ffad09d *** empty log message ***
claus
parents: 8
diff changeset
  1202
    if (__isString(aHostName)) {
42
506596f9a1a8 *** empty log message ***
claus
parents: 38
diff changeset
  1203
	bzero(&sa, sizeof(sa)) ;
524
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  1204
	if ((addr = inet_addr((char *) __stringVal(aHostName))) != -1) {
42
506596f9a1a8 *** empty log message ***
claus
parents: 38
diff changeset
  1205
	    /* is Internet addr in octet notation */
506596f9a1a8 *** empty log message ***
claus
parents: 38
diff changeset
  1206
	    bcopy(&addr, (char *) &sa.sin_addr, sizeof(addr)); 
506596f9a1a8 *** empty log message ***
claus
parents: 38
diff changeset
  1207
	    sa.sin_family = AF_INET;
506596f9a1a8 *** empty log message ***
claus
parents: 38
diff changeset
  1208
	} else {
506596f9a1a8 *** empty log message ***
claus
parents: 38
diff changeset
  1209
	    /* do we know the host's address? */
524
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  1210
	    if ((hp = gethostbyname((char *) __stringVal(aHostName))) == NULL) {
98
5e787ba2cb31 use common byteOrder when representing IP numbers as byteArrays (always network-first)
Claus Gittinger <cg@exept.de>
parents: 96
diff changeset
  1211
		DBGPRINTF(("SOCKET: unknown host\n"));
42
506596f9a1a8 *** empty log message ***
claus
parents: 38
diff changeset
  1212
		RETURN ( nil );
506596f9a1a8 *** empty log message ***
claus
parents: 38
diff changeset
  1213
	    }
506596f9a1a8 *** empty log message ***
claus
parents: 38
diff changeset
  1214
	    bcopy(hp->h_addr, (char *) &sa.sin_addr, hp->h_length) ;
506596f9a1a8 *** empty log message ***
claus
parents: 38
diff changeset
  1215
	    sa.sin_family = hp->h_addrtype;
506596f9a1a8 *** empty log message ***
claus
parents: 38
diff changeset
  1216
	}
6
claus
parents: 4
diff changeset
  1217
    }
525
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  1218
6
claus
parents: 4
diff changeset
  1219
    /* if the addressing family is not AF_INET, return nil */
claus
parents: 4
diff changeset
  1220
    if (sa.sin_family != AF_INET) {
525
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  1221
	DBGPRINTF(("SOCKET: not an internet host\n"));
42
506596f9a1a8 *** empty log message ***
claus
parents: 38
diff changeset
  1222
	RETURN ( nil );
6
claus
parents: 4
diff changeset
  1223
    }
98
5e787ba2cb31 use common byteOrder when representing IP numbers as byteArrays (always network-first)
Claus Gittinger <cg@exept.de>
parents: 96
diff changeset
  1224
5e787ba2cb31 use common byteOrder when representing IP numbers as byteArrays (always network-first)
Claus Gittinger <cg@exept.de>
parents: 96
diff changeset
  1225
    sa.sin_addr.s_addr = ntohl(sa.sin_addr.s_addr);    
217
fcfbc9f71048 underscore cleanup
Claus Gittinger <cg@exept.de>
parents: 209
diff changeset
  1226
    b1 = __MKSMALLINT((sa.sin_addr.s_addr >> 24) & 0xFF);
fcfbc9f71048 underscore cleanup
Claus Gittinger <cg@exept.de>
parents: 209
diff changeset
  1227
    b2 = __MKSMALLINT((sa.sin_addr.s_addr >> 16) & 0xFF);
fcfbc9f71048 underscore cleanup
Claus Gittinger <cg@exept.de>
parents: 209
diff changeset
  1228
    b3 = __MKSMALLINT((sa.sin_addr.s_addr >> 8) & 0xFF);
fcfbc9f71048 underscore cleanup
Claus Gittinger <cg@exept.de>
parents: 209
diff changeset
  1229
    b4 = __MKSMALLINT((sa.sin_addr.s_addr >> 0) & 0xFF);
418
317e55c6c281 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 403
diff changeset
  1230
#else
317e55c6c281 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 403
diff changeset
  1231
    RETURN (nil);
317e55c6c281 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 403
diff changeset
  1232
#endif
525
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  1233
%}.
6
claus
parents: 4
diff changeset
  1234
    ^ ByteArray with:b1 with:b2 with:b3 with:b4
21
33eb5ffad09d *** empty log message ***
claus
parents: 8
diff changeset
  1235
71
claus
parents: 63
diff changeset
  1236
    "
98
5e787ba2cb31 use common byteOrder when representing IP numbers as byteArrays (always network-first)
Claus Gittinger <cg@exept.de>
parents: 96
diff changeset
  1237
     Socket ipAddressOfHost:'clam' 
5e787ba2cb31 use common byteOrder when representing IP numbers as byteArrays (always network-first)
Claus Gittinger <cg@exept.de>
parents: 96
diff changeset
  1238
     Socket ipAddressOfHost:'porty'    
5e787ba2cb31 use common byteOrder when representing IP numbers as byteArrays (always network-first)
Claus Gittinger <cg@exept.de>
parents: 96
diff changeset
  1239
     Socket ipAddressOfHost:'axept'    
5e787ba2cb31 use common byteOrder when representing IP numbers as byteArrays (always network-first)
Claus Gittinger <cg@exept.de>
parents: 96
diff changeset
  1240
     Socket ipAddressOfHost:'axept'    
5e787ba2cb31 use common byteOrder when representing IP numbers as byteArrays (always network-first)
Claus Gittinger <cg@exept.de>
parents: 96
diff changeset
  1241
     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
  1242
     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
  1243
     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
  1244
     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
  1245
     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
  1246
     Socket ipAddressOfHost:(Socket hostWithIpAddress:'127.0.0.1') 
71
claus
parents: 63
diff changeset
  1247
    "
6
claus
parents: 4
diff changeset
  1248
!
claus
parents: 4
diff changeset
  1249
206
77166a6b3ee6 For ST80 style socket creation: register socket in Lobby.
Stefan Vogel <sv@exept.de>
parents: 203
diff changeset
  1250
networkLongOrderIsMSB
77166a6b3ee6 For ST80 style socket creation: register socket in Lobby.
Stefan Vogel <sv@exept.de>
parents: 203
diff changeset
  1251
    "return true, if the network-byte-order of longs is MSB.
77166a6b3ee6 For ST80 style socket creation: register socket in Lobby.
Stefan Vogel <sv@exept.de>
parents: 203
diff changeset
  1252
     To be used as in:
77166a6b3ee6 For ST80 style socket creation: register socket in Lobby.
Stefan Vogel <sv@exept.de>
parents: 203
diff changeset
  1253
	'aStream nextPutLong:someValue MSB:(Socket networkLongOrderIsMSB)'."
77166a6b3ee6 For ST80 style socket creation: register socket in Lobby.
Stefan Vogel <sv@exept.de>
parents: 203
diff changeset
  1254
77166a6b3ee6 For ST80 style socket creation: register socket in Lobby.
Stefan Vogel <sv@exept.de>
parents: 203
diff changeset
  1255
%{  /* NOCONTEXT */
418
317e55c6c281 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 403
diff changeset
  1256
#ifndef NO_SOCKET
206
77166a6b3ee6 For ST80 style socket creation: register socket in Lobby.
Stefan Vogel <sv@exept.de>
parents: 203
diff changeset
  1257
    /*
77166a6b3ee6 For ST80 style socket creation: register socket in Lobby.
Stefan Vogel <sv@exept.de>
parents: 203
diff changeset
  1258
     * 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
  1259
     */
77166a6b3ee6 For ST80 style socket creation: register socket in Lobby.
Stefan Vogel <sv@exept.de>
parents: 203
diff changeset
  1260
    if (htonl(0x76543210) == 0x76543210) {
77166a6b3ee6 For ST80 style socket creation: register socket in Lobby.
Stefan Vogel <sv@exept.de>
parents: 203
diff changeset
  1261
	RETURN (true);
77166a6b3ee6 For ST80 style socket creation: register socket in Lobby.
Stefan Vogel <sv@exept.de>
parents: 203
diff changeset
  1262
    }
418
317e55c6c281 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 403
diff changeset
  1263
#endif
206
77166a6b3ee6 For ST80 style socket creation: register socket in Lobby.
Stefan Vogel <sv@exept.de>
parents: 203
diff changeset
  1264
%}.
77166a6b3ee6 For ST80 style socket creation: register socket in Lobby.
Stefan Vogel <sv@exept.de>
parents: 203
diff changeset
  1265
    ^ false
77166a6b3ee6 For ST80 style socket creation: register socket in Lobby.
Stefan Vogel <sv@exept.de>
parents: 203
diff changeset
  1266
77166a6b3ee6 For ST80 style socket creation: register socket in Lobby.
Stefan Vogel <sv@exept.de>
parents: 203
diff changeset
  1267
    "
77166a6b3ee6 For ST80 style socket creation: register socket in Lobby.
Stefan Vogel <sv@exept.de>
parents: 203
diff changeset
  1268
     Socket networkLongOrderIsMSB
77166a6b3ee6 For ST80 style socket creation: register socket in Lobby.
Stefan Vogel <sv@exept.de>
parents: 203
diff changeset
  1269
    "
77166a6b3ee6 For ST80 style socket creation: register socket in Lobby.
Stefan Vogel <sv@exept.de>
parents: 203
diff changeset
  1270
!
77166a6b3ee6 For ST80 style socket creation: register socket in Lobby.
Stefan Vogel <sv@exept.de>
parents: 203
diff changeset
  1271
77166a6b3ee6 For ST80 style socket creation: register socket in Lobby.
Stefan Vogel <sv@exept.de>
parents: 203
diff changeset
  1272
networkShortOrderIsMSB
77166a6b3ee6 For ST80 style socket creation: register socket in Lobby.
Stefan Vogel <sv@exept.de>
parents: 203
diff changeset
  1273
    "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
  1274
     To be used as in:
77166a6b3ee6 For ST80 style socket creation: register socket in Lobby.
Stefan Vogel <sv@exept.de>
parents: 203
diff changeset
  1275
	'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
  1276
77166a6b3ee6 For ST80 style socket creation: register socket in Lobby.
Stefan Vogel <sv@exept.de>
parents: 203
diff changeset
  1277
%{  /* NOCONTEXT */
418
317e55c6c281 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 403
diff changeset
  1278
#ifndef NO_SOCKET
206
77166a6b3ee6 For ST80 style socket creation: register socket in Lobby.
Stefan Vogel <sv@exept.de>
parents: 203
diff changeset
  1279
    /*
77166a6b3ee6 For ST80 style socket creation: register socket in Lobby.
Stefan Vogel <sv@exept.de>
parents: 203
diff changeset
  1280
     * 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
  1281
     */
77166a6b3ee6 For ST80 style socket creation: register socket in Lobby.
Stefan Vogel <sv@exept.de>
parents: 203
diff changeset
  1282
    if (htons(0x3210) == 0x3210) {
77166a6b3ee6 For ST80 style socket creation: register socket in Lobby.
Stefan Vogel <sv@exept.de>
parents: 203
diff changeset
  1283
	RETURN (true);
77166a6b3ee6 For ST80 style socket creation: register socket in Lobby.
Stefan Vogel <sv@exept.de>
parents: 203
diff changeset
  1284
    }
418
317e55c6c281 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 403
diff changeset
  1285
#endif
206
77166a6b3ee6 For ST80 style socket creation: register socket in Lobby.
Stefan Vogel <sv@exept.de>
parents: 203
diff changeset
  1286
%}.
77166a6b3ee6 For ST80 style socket creation: register socket in Lobby.
Stefan Vogel <sv@exept.de>
parents: 203
diff changeset
  1287
    ^ false
77166a6b3ee6 For ST80 style socket creation: register socket in Lobby.
Stefan Vogel <sv@exept.de>
parents: 203
diff changeset
  1288
77166a6b3ee6 For ST80 style socket creation: register socket in Lobby.
Stefan Vogel <sv@exept.de>
parents: 203
diff changeset
  1289
    "
77166a6b3ee6 For ST80 style socket creation: register socket in Lobby.
Stefan Vogel <sv@exept.de>
parents: 203
diff changeset
  1290
     Socket networkShortOrderIsMSB
77166a6b3ee6 For ST80 style socket creation: register socket in Lobby.
Stefan Vogel <sv@exept.de>
parents: 203
diff changeset
  1291
    "
77166a6b3ee6 For ST80 style socket creation: register socket in Lobby.
Stefan Vogel <sv@exept.de>
parents: 203
diff changeset
  1292
!
77166a6b3ee6 For ST80 style socket creation: register socket in Lobby.
Stefan Vogel <sv@exept.de>
parents: 203
diff changeset
  1293
0
1cf8d1747859 Initial revision
claus
parents:
diff changeset
  1294
portOfService:aNameOrNumber
1cf8d1747859 Initial revision
claus
parents:
diff changeset
  1295
    "returns the port-number for a given service
1cf8d1747859 Initial revision
claus
parents:
diff changeset
  1296
     or nil if no such service exists;
1cf8d1747859 Initial revision
claus
parents:
diff changeset
  1297
     - used to convert service names to portNumbers"
1cf8d1747859 Initial revision
claus
parents:
diff changeset
  1298
91
Claus Gittinger <cg@exept.de>
parents: 85
diff changeset
  1299
    ^ self portOfService:aNameOrNumber protocol:nil
Claus Gittinger <cg@exept.de>
parents: 85
diff changeset
  1300
28
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  1301
    "
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  1302
     Socket portOfService:'finger'
74
claus
parents: 71
diff changeset
  1303
     Socket portOfService:'nntp'  
claus
parents: 71
diff changeset
  1304
     Socket portOfService:'echo' 
claus
parents: 71
diff changeset
  1305
     Socket portOfService:'snmp' 
28
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  1306
    "
0
1cf8d1747859 Initial revision
claus
parents:
diff changeset
  1307
!
1cf8d1747859 Initial revision
claus
parents:
diff changeset
  1308
91
Claus Gittinger <cg@exept.de>
parents: 85
diff changeset
  1309
portOfService:aNameOrNumber protocol:aProtocol
Claus Gittinger <cg@exept.de>
parents: 85
diff changeset
  1310
    "returns the port-number for a given service
Claus Gittinger <cg@exept.de>
parents: 85
diff changeset
  1311
     or nil if no such service exists;
Claus Gittinger <cg@exept.de>
parents: 85
diff changeset
  1312
     - used to convert service names to portNumbers"
Claus Gittinger <cg@exept.de>
parents: 85
diff changeset
  1313
Claus Gittinger <cg@exept.de>
parents: 85
diff changeset
  1314
%{
418
317e55c6c281 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 403
diff changeset
  1315
#ifndef NO_SOCKET
91
Claus Gittinger <cg@exept.de>
parents: 85
diff changeset
  1316
    struct servent *servent = NULL;
Claus Gittinger <cg@exept.de>
parents: 85
diff changeset
  1317
    char *protocol;
Claus Gittinger <cg@exept.de>
parents: 85
diff changeset
  1318
    int tryBoth = 0;
524
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  1319
    short portNo;
91
Claus Gittinger <cg@exept.de>
parents: 85
diff changeset
  1320
92
Claus Gittinger <cg@exept.de>
parents: 91
diff changeset
  1321
    if (__isString(aProtocol)) {
93
Claus Gittinger <cg@exept.de>
parents: 92
diff changeset
  1322
	protocol = __stringVal(aProtocol);
92
Claus Gittinger <cg@exept.de>
parents: 91
diff changeset
  1323
    } else {
93
Claus Gittinger <cg@exept.de>
parents: 92
diff changeset
  1324
	protocol = "tcp";
Claus Gittinger <cg@exept.de>
parents: 92
diff changeset
  1325
	tryBoth = 1;
92
Claus Gittinger <cg@exept.de>
parents: 91
diff changeset
  1326
    }
Claus Gittinger <cg@exept.de>
parents: 91
diff changeset
  1327
91
Claus Gittinger <cg@exept.de>
parents: 85
diff changeset
  1328
    if (__isSmallInteger(aNameOrNumber)) {
524
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  1329
	portNo = __intVal(aNameOrNumber);
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  1330
	servent = getservbyport(htons(portNo), protocol);
93
Claus Gittinger <cg@exept.de>
parents: 92
diff changeset
  1331
	if (servent != NULL) {
Claus Gittinger <cg@exept.de>
parents: 92
diff changeset
  1332
	    RETURN ( aNameOrNumber );
Claus Gittinger <cg@exept.de>
parents: 92
diff changeset
  1333
	}
Claus Gittinger <cg@exept.de>
parents: 92
diff changeset
  1334
	if (tryBoth) {
524
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  1335
	    servent = getservbyport(htons(portNo), "udp");
93
Claus Gittinger <cg@exept.de>
parents: 92
diff changeset
  1336
	    if (servent != NULL) {
Claus Gittinger <cg@exept.de>
parents: 92
diff changeset
  1337
		RETURN ( aNameOrNumber );
Claus Gittinger <cg@exept.de>
parents: 92
diff changeset
  1338
	    }
Claus Gittinger <cg@exept.de>
parents: 92
diff changeset
  1339
	}
Claus Gittinger <cg@exept.de>
parents: 92
diff changeset
  1340
	RETURN ( aNameOrNumber );
91
Claus Gittinger <cg@exept.de>
parents: 85
diff changeset
  1341
    }
524
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  1342
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  1343
    if (__isString(aNameOrNumber) || __isSymbol(aNameOrNumber)) {
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  1344
	servent = getservbyname((char *) __stringVal(aNameOrNumber), protocol);
93
Claus Gittinger <cg@exept.de>
parents: 92
diff changeset
  1345
	if (servent != NULL) {
217
fcfbc9f71048 underscore cleanup
Claus Gittinger <cg@exept.de>
parents: 209
diff changeset
  1346
	    RETURN ( __MKSMALLINT(ntohs(servent->s_port)) );
93
Claus Gittinger <cg@exept.de>
parents: 92
diff changeset
  1347
	}
Claus Gittinger <cg@exept.de>
parents: 92
diff changeset
  1348
	if (tryBoth) {
524
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  1349
	    servent = getservbyname((char *) __stringVal(aNameOrNumber), "udp");
93
Claus Gittinger <cg@exept.de>
parents: 92
diff changeset
  1350
	    if (servent != NULL) {
217
fcfbc9f71048 underscore cleanup
Claus Gittinger <cg@exept.de>
parents: 209
diff changeset
  1351
		RETURN ( __MKSMALLINT(ntohs(servent->s_port)) );
93
Claus Gittinger <cg@exept.de>
parents: 92
diff changeset
  1352
	    }
Claus Gittinger <cg@exept.de>
parents: 92
diff changeset
  1353
	}
Claus Gittinger <cg@exept.de>
parents: 92
diff changeset
  1354
	RETURN ( nil );
91
Claus Gittinger <cg@exept.de>
parents: 85
diff changeset
  1355
    }
418
317e55c6c281 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 403
diff changeset
  1356
#endif
91
Claus Gittinger <cg@exept.de>
parents: 85
diff changeset
  1357
    RETURN ( nil );
Claus Gittinger <cg@exept.de>
parents: 85
diff changeset
  1358
%}
Claus Gittinger <cg@exept.de>
parents: 85
diff changeset
  1359
    "
Claus Gittinger <cg@exept.de>
parents: 85
diff changeset
  1360
     Socket portOfService:'echo' protocol:'udp'
Claus Gittinger <cg@exept.de>
parents: 85
diff changeset
  1361
     Socket portOfService:'echo' protocol:'tcp'
Claus Gittinger <cg@exept.de>
parents: 85
diff changeset
  1362
    "
Claus Gittinger <cg@exept.de>
parents: 85
diff changeset
  1363
!
Claus Gittinger <cg@exept.de>
parents: 85
diff changeset
  1364
0
1cf8d1747859 Initial revision
claus
parents:
diff changeset
  1365
protocolOfService:aNameOrNumber
1cf8d1747859 Initial revision
claus
parents:
diff changeset
  1366
    "returns the protocol (as string) for a given service
28
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  1367
     or nil if no such service exists."
0
1cf8d1747859 Initial revision
claus
parents:
diff changeset
  1368
%{
418
317e55c6c281 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 403
diff changeset
  1369
#ifndef NO_SOCKET
0
1cf8d1747859 Initial revision
claus
parents:
diff changeset
  1370
    struct servent *servent = NULL;
524
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  1371
    short portNo;
0
1cf8d1747859 Initial revision
claus
parents:
diff changeset
  1372
58
bd6753bf0401 *** empty log message ***
claus
parents: 51
diff changeset
  1373
    if (__isSmallInteger(aNameOrNumber)) {
524
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  1374
	portNo = __intVal(aNameOrNumber);
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  1375
	servent = getservbyport(htons(portNo), "tcp") ;
42
506596f9a1a8 *** empty log message ***
claus
parents: 38
diff changeset
  1376
	if (servent == NULL) {
524
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  1377
	    servent = getservbyport(htons(portNo), "udp") ;
42
506596f9a1a8 *** empty log message ***
claus
parents: 38
diff changeset
  1378
	    if (servent == NULL) {
506596f9a1a8 *** empty log message ***
claus
parents: 38
diff changeset
  1379
		RETURN ( nil );
506596f9a1a8 *** empty log message ***
claus
parents: 38
diff changeset
  1380
	    }
506596f9a1a8 *** empty log message ***
claus
parents: 38
diff changeset
  1381
	}
0
1cf8d1747859 Initial revision
claus
parents:
diff changeset
  1382
    } else {
42
506596f9a1a8 *** empty log message ***
claus
parents: 38
diff changeset
  1383
	if (__isString(aNameOrNumber)) {
524
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  1384
	    servent = getservbyname((char *) __stringVal(aNameOrNumber), "tcp");
42
506596f9a1a8 *** empty log message ***
claus
parents: 38
diff changeset
  1385
	    if (servent == NULL) {
524
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  1386
		servent = getservbyname((char *) __stringVal(aNameOrNumber), "udp");
42
506596f9a1a8 *** empty log message ***
claus
parents: 38
diff changeset
  1387
		if (servent == NULL) {
506596f9a1a8 *** empty log message ***
claus
parents: 38
diff changeset
  1388
		    RETURN ( nil );
506596f9a1a8 *** empty log message ***
claus
parents: 38
diff changeset
  1389
		}
506596f9a1a8 *** empty log message ***
claus
parents: 38
diff changeset
  1390
	    }
506596f9a1a8 *** empty log message ***
claus
parents: 38
diff changeset
  1391
	}
0
1cf8d1747859 Initial revision
claus
parents:
diff changeset
  1392
    }
1cf8d1747859 Initial revision
claus
parents:
diff changeset
  1393
    if (servent) {
448
2203a4bb620d removed all COMMA_CON / CON_COMMA uses
Claus Gittinger <cg@exept.de>
parents: 444
diff changeset
  1394
	RETURN ( __MKSTRING(servent->s_proto) );
0
1cf8d1747859 Initial revision
claus
parents:
diff changeset
  1395
    }
418
317e55c6c281 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 403
diff changeset
  1396
#endif
0
1cf8d1747859 Initial revision
claus
parents:
diff changeset
  1397
    RETURN ( nil );
1cf8d1747859 Initial revision
claus
parents:
diff changeset
  1398
%}
28
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  1399
    "
74
claus
parents: 71
diff changeset
  1400
     Socket protocolOfService:'finger' 
claus
parents: 71
diff changeset
  1401
     Socket protocolOfService:'nntp'  
28
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  1402
     Socket protocolOfService:'xxx'
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  1403
     Socket protocolOfService:79
74
claus
parents: 71
diff changeset
  1404
     Socket protocolOfService:'snmp' 
28
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  1405
    "
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  1406
!
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  1407
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  1408
typeOfProtocol:aProtocol
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  1409
    "given a protocols name (i.e. tcp, udp etc) return the connection type.
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  1410
     This method needs more ... - or is there a way to get this from the system ?"
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  1411
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  1412
    (aProtocol = 'tcp') ifTrue:[^ #stream].
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  1413
    (aProtocol = 'udp') ifTrue:[^ #datagram].
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  1414
    (aProtocol = 'ip')  ifTrue:[^ #raw].
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  1415
    "
71
claus
parents: 63
diff changeset
  1416
     unix domain
claus
parents: 63
diff changeset
  1417
    "
claus
parents: 63
diff changeset
  1418
    (aProtocol = 'ud')  ifTrue:[^ #stream].
claus
parents: 63
diff changeset
  1419
    "
91
Claus Gittinger <cg@exept.de>
parents: 85
diff changeset
  1420
     add x25 stuff (if any) here ...
Claus Gittinger <cg@exept.de>
parents: 85
diff changeset
  1421
    "
Claus Gittinger <cg@exept.de>
parents: 85
diff changeset
  1422
    "
Claus Gittinger <cg@exept.de>
parents: 85
diff changeset
  1423
     add appletalk stuff (if any) here ...
Claus Gittinger <cg@exept.de>
parents: 85
diff changeset
  1424
    "
Claus Gittinger <cg@exept.de>
parents: 85
diff changeset
  1425
    "
Claus Gittinger <cg@exept.de>
parents: 85
diff changeset
  1426
     add other stuff (if any) here ...
28
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  1427
    "
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  1428
    ^ nil
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  1429
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  1430
    "
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  1431
     Socket typeOfProtocol:'tcp'
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  1432
     Socket typeOfProtocol:'ucp'
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  1433
     Socket typeOfProtocol:(Socket protocolOfService:'nntp')
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  1434
     Socket typeOfProtocol:(Socket protocolOfService:'echo')
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  1435
    "
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  1436
! !
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  1437
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1438
!Socket methodsFor:'ST-80 mimicri'!
28
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  1439
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1440
errorReporter
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1441
    ^ self
28
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  1442
!
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  1443
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1444
notReadySignal
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1445
    "for now - this is not yet raised"
71
claus
parents: 63
diff changeset
  1446
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1447
    ^ Signal new
486
ed4e215e83ef ST-80 mimicry
Claus Gittinger <cg@exept.de>
parents: 470
diff changeset
  1448
!
ed4e215e83ef ST-80 mimicry
Claus Gittinger <cg@exept.de>
parents: 470
diff changeset
  1449
ed4e215e83ef ST-80 mimicry
Claus Gittinger <cg@exept.de>
parents: 470
diff changeset
  1450
readStream
ed4e215e83ef ST-80 mimicry
Claus Gittinger <cg@exept.de>
parents: 470
diff changeset
  1451
    "ST-80 mimicry.
ed4e215e83ef ST-80 mimicry
Claus Gittinger <cg@exept.de>
parents: 470
diff changeset
  1452
     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
  1453
     ST-80 code therefore uses 'Socket readStream' to access
ed4e215e83ef ST-80 mimicry
Claus Gittinger <cg@exept.de>
parents: 470
diff changeset
  1454
     the actual stream. This method returns the receiver, for transparency"
ed4e215e83ef ST-80 mimicry
Claus Gittinger <cg@exept.de>
parents: 470
diff changeset
  1455
ed4e215e83ef ST-80 mimicry
Claus Gittinger <cg@exept.de>
parents: 470
diff changeset
  1456
    ^ self
ed4e215e83ef ST-80 mimicry
Claus Gittinger <cg@exept.de>
parents: 470
diff changeset
  1457
ed4e215e83ef ST-80 mimicry
Claus Gittinger <cg@exept.de>
parents: 470
diff changeset
  1458
    "Created: 24.1.1997 / 23:52:57 / cg"
ed4e215e83ef ST-80 mimicry
Claus Gittinger <cg@exept.de>
parents: 470
diff changeset
  1459
!
ed4e215e83ef ST-80 mimicry
Claus Gittinger <cg@exept.de>
parents: 470
diff changeset
  1460
ed4e215e83ef ST-80 mimicry
Claus Gittinger <cg@exept.de>
parents: 470
diff changeset
  1461
writeStream
ed4e215e83ef ST-80 mimicry
Claus Gittinger <cg@exept.de>
parents: 470
diff changeset
  1462
    "ST-80 mimicry.
ed4e215e83ef ST-80 mimicry
Claus Gittinger <cg@exept.de>
parents: 470
diff changeset
  1463
     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
  1464
     ST-80 code therefore uses 'Socket writeStream' to access
ed4e215e83ef ST-80 mimicry
Claus Gittinger <cg@exept.de>
parents: 470
diff changeset
  1465
     the actual stream. This method returns the receiver, for transparency"
ed4e215e83ef ST-80 mimicry
Claus Gittinger <cg@exept.de>
parents: 470
diff changeset
  1466
ed4e215e83ef ST-80 mimicry
Claus Gittinger <cg@exept.de>
parents: 470
diff changeset
  1467
    ^ self
ed4e215e83ef ST-80 mimicry
Claus Gittinger <cg@exept.de>
parents: 470
diff changeset
  1468
ed4e215e83ef ST-80 mimicry
Claus Gittinger <cg@exept.de>
parents: 470
diff changeset
  1469
    "Created: 24.1.1997 / 10:34:35 / cg"
ed4e215e83ef ST-80 mimicry
Claus Gittinger <cg@exept.de>
parents: 470
diff changeset
  1470
    "Modified: 24.1.1997 / 23:52:52 / cg"
71
claus
parents: 63
diff changeset
  1471
! !
claus
parents: 63
diff changeset
  1472
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1473
!Socket methodsFor:'datagram transmission'!
28
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  1474
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1475
receiveFrom:anAddressBuffer buffer:aDataBuffer
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1476
    "receive datagramm data - put address of originating host into
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1477
     anAddressBuffer, data into aBuffer. 
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1478
     Both must be ByteArray-like. The addressBuffer must
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1479
     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
  1480
     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
  1481
     On error, the unix error code is left in the lastErrorNumber
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1482
     instance variable."
28
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  1483
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1484
    ^ 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
  1485
!
7d016cc30052 fixed & moved pingWalk from SNMPSession to here;
Claus Gittinger <cg@exept.de>
parents: 98
diff changeset
  1486
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1487
receiveFrom:anAddressBuffer buffer:aDataBuffer start:startIndex for:nBytes
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1488
    "receive datagramm data - put address of originating host into
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1489
     anAddressBuffer, data into aBuffer. For ST-80 compatibility,
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1490
     the addressBuffer may be a non-ByteArray; then, it must understand
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1491
     the addressBytes-message (i.e. be a SocketAddress instance).
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1492
     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
  1493
     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
  1494
     instance variable.
b8042ff0f82c udp receive: translate received address according to the domain
Claus Gittinger <cg@exept.de>
parents: 511
diff changeset
  1495
     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
  1496
     receiving, using #readWait or #readWaitWithTimeout:."
b8042ff0f82c udp receive: translate received address according to the domain
Claus Gittinger <cg@exept.de>
parents: 511
diff changeset
  1497
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1498
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1499
    |addrBytes addrLen nReceived|
28
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  1500
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1501
    addrBytes := ByteArray new:100.
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1502
%{
418
317e55c6c281 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 403
diff changeset
  1503
#ifndef NO_SOCKET
513
b8042ff0f82c udp receive: translate received address according to the domain
Claus Gittinger <cg@exept.de>
parents: 511
diff changeset
  1504
    OBJ oClass, myDomain;
217
fcfbc9f71048 underscore cleanup
Claus Gittinger <cg@exept.de>
parents: 209
diff changeset
  1505
    OBJ fp = __INST(filePointer);
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1506
    int nInstVars, nInstBytes, objSize;
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1507
    int sock;
513
b8042ff0f82c udp receive: translate received address according to the domain
Claus Gittinger <cg@exept.de>
parents: 511
diff changeset
  1508
    union {
526
1748ab3892a3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 525
diff changeset
  1509
# ifdef AF_INET
530
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  1510
	struct sockaddr_in in;
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  1511
# endif
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  1512
# ifdef AF_INET6
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  1513
	struct sockaddr_in6 in6;
526
1748ab3892a3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 525
diff changeset
  1514
# endif
1748ab3892a3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 525
diff changeset
  1515
# ifdef AF_UNIX
1748ab3892a3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 525
diff changeset
  1516
	struct sockaddr_un un;
1748ab3892a3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 525
diff changeset
  1517
# endif
1748ab3892a3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 525
diff changeset
  1518
# ifdef AF_APPLETALK
1748ab3892a3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 525
diff changeset
  1519
	struct sockaddr_at at;
1748ab3892a3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 525
diff changeset
  1520
# endif
513
b8042ff0f82c udp receive: translate received address according to the domain
Claus Gittinger <cg@exept.de>
parents: 511
diff changeset
  1521
    } sa;
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1522
    int alen;
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1523
    int n;
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1524
    char *cp;
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1525
    int flags = 0;
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1526
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1527
    if (fp != nil) {
524
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  1528
	sock = fileno(__FILEVal(fp));
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  1529
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  1530
	oClass = __Class(aDataBuffer);
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  1531
	switch (_intVal(_ClassInstPtr(oClass)->c_flags) & ARRAYMASK) {
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  1532
	    case BYTEARRAY:
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  1533
	    case WORDARRAY:
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  1534
	    case LONGARRAY:
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  1535
	    case FLOATARRAY:
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  1536
	    case DOUBLEARRAY:
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  1537
		break;
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  1538
	    default:
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  1539
		goto bad;
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  1540
	}
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  1541
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  1542
	nInstVars = _intVal(_ClassInstPtr(oClass)->c_ninstvars);
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  1543
	nInstBytes = OHDR_SIZE + nInstVars * sizeof(OBJ);
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  1544
	objSize = _Size(aDataBuffer) - nInstBytes;
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  1545
	cp = (char *)__InstPtr(aDataBuffer) + nInstBytes;
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  1546
	if (__isSmallInteger(startIndex)) {
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  1547
	    cp += __intVal(startIndex);
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  1548
	    objSize -= __intVal(startIndex);
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  1549
	}
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  1550
	if (__isSmallInteger(nBytes)) {
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  1551
	    if (__intVal(nBytes) < objSize) {
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  1552
		objSize = __intVal(nBytes);
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  1553
	    }
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  1554
	}
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  1555
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  1556
	__BEGIN_INTERRUPTABLE__
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  1557
	do {
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  1558
	    if (addrBytes == nil) {
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  1559
		n = recvfrom(sock, cp, objSize, flags, (struct sockaddr *) 0, 0);
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  1560
	    } else {
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  1561
		n = recvfrom(sock, cp, objSize, flags, (struct sockaddr *) &sa, &alen);
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  1562
	    }
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  1563
	} while ((n < 0) && (errno == EINTR));
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  1564
	__END_INTERRUPTABLE__
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  1565
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  1566
	if (n >= 0) {
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  1567
	    if (addrBytes != nil) {
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  1568
		oClass = __Class(addrBytes);
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  1569
		if ((_intVal(_ClassInstPtr(oClass)->c_flags) & ARRAYMASK) != BYTEARRAY) 
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  1570
		    goto bad;
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  1571
		nInstVars = _intVal(_ClassInstPtr(oClass)->c_ninstvars);
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  1572
		nInstBytes = OHDR_SIZE + nInstVars * sizeof(OBJ);
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  1573
		objSize = _Size(addrBytes) - nInstBytes;
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  1574
		cp = (char *)__InstPtr(addrBytes) + nInstBytes;
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  1575
		if (objSize < alen) 
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  1576
		    goto bad;
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  1577
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  1578
		myDomain = __INST(domain);
525
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  1579
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  1580
		/*
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  1581
		 * extract the datagrams address
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  1582
		 */
513
b8042ff0f82c udp receive: translate received address according to the domain
Claus Gittinger <cg@exept.de>
parents: 511
diff changeset
  1583
# ifdef AF_UNIX
530
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  1584
                if (myDomain == @symbol(unix)) {
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  1585
                    cp[0] = (sa.in.sin_addr.s_addr >> 24) & 0xFF;
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  1586
                    cp[2] = (sa.in.sin_addr.s_addr >> 16) & 0xFF;
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  1587
                    cp[3] = (sa.in.sin_addr.s_addr >> 8) & 0xFF;
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  1588
                    cp[4] = (sa.in.sin_addr.s_addr >> 0) & 0xFF;
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  1589
                    alen = 4;
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  1590
                }
525
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  1591
# endif /* AF_UNIX */
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  1592
524
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  1593
		/*
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  1594
		 * XXXX add addressing stuff for other domains here ...
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  1595
		 */
513
b8042ff0f82c udp receive: translate received address according to the domain
Claus Gittinger <cg@exept.de>
parents: 511
diff changeset
  1596
# ifdef AF_X25
524
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  1597
		if (myDomain == @symbol(x25)) {
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  1598
		}
513
b8042ff0f82c udp receive: translate received address according to the domain
Claus Gittinger <cg@exept.de>
parents: 511
diff changeset
  1599
# endif
b8042ff0f82c udp receive: translate received address according to the domain
Claus Gittinger <cg@exept.de>
parents: 511
diff changeset
  1600
# ifdef AF_NS
524
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  1601
		if (myDomain == @symbol(ns)) {
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  1602
		}
513
b8042ff0f82c udp receive: translate received address according to the domain
Claus Gittinger <cg@exept.de>
parents: 511
diff changeset
  1603
# endif
b8042ff0f82c udp receive: translate received address according to the domain
Claus Gittinger <cg@exept.de>
parents: 511
diff changeset
  1604
# ifdef AF_APPLETALK
524
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  1605
		if (myDomain == @symbol(appletalk)) {
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  1606
		}
513
b8042ff0f82c udp receive: translate received address according to the domain
Claus Gittinger <cg@exept.de>
parents: 511
diff changeset
  1607
# endif
b8042ff0f82c udp receive: translate received address according to the domain
Claus Gittinger <cg@exept.de>
parents: 511
diff changeset
  1608
# ifdef AF_SNA
524
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  1609
		if (myDomain == @symbol(sna)) {
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  1610
		}
513
b8042ff0f82c udp receive: translate received address according to the domain
Claus Gittinger <cg@exept.de>
parents: 511
diff changeset
  1611
# endif
b8042ff0f82c udp receive: translate received address according to the domain
Claus Gittinger <cg@exept.de>
parents: 511
diff changeset
  1612
# ifdef AF_NS
524
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  1613
		if (myDomain == @symbol(xns)) {
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  1614
		}
513
b8042ff0f82c udp receive: translate received address according to the domain
Claus Gittinger <cg@exept.de>
parents: 511
diff changeset
  1615
# endif
b8042ff0f82c udp receive: translate received address according to the domain
Claus Gittinger <cg@exept.de>
parents: 511
diff changeset
  1616
# ifdef AF_RAW
524
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  1617
		if (myDomain == @symbol(raw)) {
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  1618
		}
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  1619
# endif
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  1620
# ifdef AF_ISO
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  1621
		if (myDomain == @symbol(iso)) {
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  1622
		}
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  1623
# endif
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  1624
# ifdef AF_DECnet
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  1625
		if (myDomain == @symbol(decnet)) {
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  1626
		}
513
b8042ff0f82c udp receive: translate received address according to the domain
Claus Gittinger <cg@exept.de>
parents: 511
diff changeset
  1627
# endif
524
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  1628
# ifdef AF_NETBIOS
530
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  1629
		if (myDomain == @symbol(netbios)) {
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  1630
		}
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  1631
# endif
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  1632
# if defined(AF_IPX)
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  1633
		if (myDomain == @symbol(ipx)) {
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  1634
		}
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  1635
# endif
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  1636
# if defined(AF_BRIDGE)
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  1637
		if (myDomain == @symbol(bridge)) {
524
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  1638
		}
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  1639
# endif
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  1640
# if defined(AF_CCITT) && (AF_CCITT != AF_X25)
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  1641
		if (myDomain == @symbol(ccitt)) {
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  1642
		}
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  1643
# endif
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  1644
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  1645
		addrLen = __MKSMALLINT(alen);
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  1646
	    }
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  1647
	}
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  1648
	if (n < 0) {
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  1649
	    __INST(lastErrorNumber) = __MKSMALLINT(errno);
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  1650
	}
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  1651
	nReceived = __MKSMALLINT(n);
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1652
    }
418
317e55c6c281 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 403
diff changeset
  1653
#endif
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1654
bad: ;
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1655
%}.
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1656
    nReceived notNil ifTrue:[
524
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  1657
	nReceived < 0 ifTrue:[
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  1658
	    'Socket [warning]: ' infoPrint.
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  1659
	    (OperatingSystem errorTextForNumber:lastErrorNumber) infoPrintCR.
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  1660
	].
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  1661
	addrLen notNil ifTrue:[
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  1662
	    anAddressBuffer class isBytes ifTrue:[
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  1663
		anAddressBuffer replaceFrom:1 to:addrLen with:addrBytes
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  1664
	    ] ifFalse:[
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  1665
		"/ can be SocketAddress for ST-80 compatibility
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  1666
		anAddressBuffer hostAddress:(addrBytes copyTo:addrLen)
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  1667
	    ].
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  1668
	].
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  1669
	^ nReceived
28
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  1670
    ].
116
7789fb1c9fa2 more UD socket fixes (at least client side seems to work now)
Claus Gittinger <cg@exept.de>
parents: 115
diff changeset
  1671
    "
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1672
     arrive here if you try to receive into an invalid buffer
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1673
     (i.e. not ByteArray-like), 
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1674
     or if the addressBuffer is nonNil AND not a ByteArray/String 
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1675
     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
  1676
    "
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1677
    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
  1678
!
7789fb1c9fa2 more UD socket fixes (at least client side seems to work now)
Claus Gittinger <cg@exept.de>
parents: 115
diff changeset
  1679
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1680
sendTo:anAddressBuffer buffer:buffer
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1681
    "send datagramm data - fetch address of destination host from
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1682
     anAddressBuffer, data from aDataBuffer. 
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1683
     Both must be ByteArray-like. The bytes in the addressBuffer must
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1684
     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
  1685
     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
  1686
     On error, the unix error code is left in the lastErrorNumber
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1687
     instance variable.
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1688
     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
  1689
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1690
    ^ 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
  1691
!
7789fb1c9fa2 more UD socket fixes (at least client side seems to work now)
Claus Gittinger <cg@exept.de>
parents: 115
diff changeset
  1692
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1693
sendTo:anAddressBuffer buffer:aDataBuffer start:startIndex for:count flags:flags
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1694
    "send datagramm data - fetch address of destination host from
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1695
     anAddressBuffer, data from aDataBuffer starting at startIndex,
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1696
     sending count bytes. 
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1697
     Both must be ByteArray-like. The bytes in the addressBuffer must
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1698
     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
  1699
     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
  1700
     On error, the unix error code is left in the lastErrorNumber
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1701
     instance variable."
0
1cf8d1747859 Initial revision
claus
parents:
diff changeset
  1702
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1703
    |addrBytes addrLen nReceived portNo|
93
Claus Gittinger <cg@exept.de>
parents: 92
diff changeset
  1704
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1705
    "/ addressBuffer can be a 6-byte byteArray (last 2 bytes are portNo, msb-first)
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1706
    "/ or an instance of IPSocketAddress
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1707
    "/
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1708
    anAddressBuffer class isBytes ifTrue:[
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1709
	addrBytes := anAddressBuffer copyFrom:1 to:4.
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1710
	portNo := ((anAddressBuffer at:5) bitShift:8)
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1711
		  + (anAddressBuffer at:6).
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1712
    ] ifFalse:[
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1713
	addrBytes := anAddressBuffer hostAddress.
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1714
	portNo := anAddressBuffer port.
28
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  1715
    ].
0
1cf8d1747859 Initial revision
claus
parents:
diff changeset
  1716
%{
418
317e55c6c281 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 403
diff changeset
  1717
#ifndef NO_SOCKET
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1718
    OBJ oClass;
217
fcfbc9f71048 underscore cleanup
Claus Gittinger <cg@exept.de>
parents: 209
diff changeset
  1719
    OBJ fp = __INST(filePointer);
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1720
    int nInstVars, nInstBytes, objSize;
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1721
    int sock;
526
1748ab3892a3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 525
diff changeset
  1722
    union {
1748ab3892a3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 525
diff changeset
  1723
# ifdef AF_INET
530
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  1724
	struct sockaddr_in in;
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  1725
# endif
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  1726
# ifdef AF_INET6
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  1727
	struct sockaddr_in6 in6;
526
1748ab3892a3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 525
diff changeset
  1728
# endif
1748ab3892a3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 525
diff changeset
  1729
# ifdef AF_UNIX
1748ab3892a3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 525
diff changeset
  1730
	struct sockaddr_un un;
1748ab3892a3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 525
diff changeset
  1731
# endif
1748ab3892a3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 525
diff changeset
  1732
# ifdef AF_APPLETALK
1748ab3892a3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 525
diff changeset
  1733
	struct sockaddr_at at;
1748ab3892a3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 525
diff changeset
  1734
# endif
1748ab3892a3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 525
diff changeset
  1735
    } sa;
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1736
    struct sockaddr *saPtr = (struct sockaddr *)&sa;
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1737
    int alen = sizeof(sa);
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1738
    int n;
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1739
    char *cp;
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1740
    int _flags = 0;
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1741
    int offs, nBytes;
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1742
    unsigned long norder;
21
33eb5ffad09d *** empty log message ***
claus
parents: 8
diff changeset
  1743
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1744
    _flags = __longIntVal(flags);
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1745
 
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1746
    if ((fp != nil) 
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1747
     && __isSmallInteger(startIndex)
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1748
     && __isSmallInteger(count)) {
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1749
	sock = fileno(__FILEVal(fp));
0
1cf8d1747859 Initial revision
claus
parents:
diff changeset
  1750
525
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  1751
	if (addrBytes == nil) {
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  1752
	    alen = 0;
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  1753
	    saPtr = (struct sockaddr *)0;
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  1754
	} else {
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1755
	    if (! __isByteArray(addrBytes)) goto bad;
525
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  1756
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1757
	    cp = __ByteArrayInstPtr(addrBytes)->ba_element;
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1758
	    n = __byteArraySize(addrBytes);
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1759
	    if (alen < n) n = alen;
526
1748ab3892a3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 525
diff changeset
  1760
#ifdef DGRAM_DEBUG
1748ab3892a3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 525
diff changeset
  1761
	    printf("address is %d bytes ... %d.%d.%d.%d", n, cp[0], cp[1], cp[2], cp[3]);
1748ab3892a3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 525
diff changeset
  1762
#endif
1748ab3892a3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 525
diff changeset
  1763
	    bcopy(cp, &sa.in.sin_addr.s_addr, n);
525
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  1764
#ifdef AF_INET
526
1748ab3892a3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 525
diff changeset
  1765
	    if (__INST(domain) == @symbol(inet)) {
1748ab3892a3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 525
diff changeset
  1766
	        sa.in.sin_family = AF_INET;
1748ab3892a3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 525
diff changeset
  1767
	        sa.in.sin_port = htons((u_short) __intVal(portNo)); 
1748ab3892a3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 525
diff changeset
  1768
	    }
1748ab3892a3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 525
diff changeset
  1769
#endif
530
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  1770
#ifdef AF_INET6
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  1771
            if (__INST(domain) == @symbol(inet6)) {
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  1772
                sa.in6.sin6_family = AF_INET;
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  1773
                sa.in6.sin6_port = htons((u_short) __intVal(portNo)); 
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  1774
            }
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  1775
#endif
526
1748ab3892a3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 525
diff changeset
  1776
#ifdef AF_APPLETALK
1748ab3892a3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 525
diff changeset
  1777
	    if (__INST(domain) == @symbol(appletalk)) {
1748ab3892a3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 525
diff changeset
  1778
                sa.at.sat_family = AF_INET;
1748ab3892a3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 525
diff changeset
  1779
                sa.at.sat_port = __intVal(portNo);
1748ab3892a3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 525
diff changeset
  1780
            }
1748ab3892a3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 525
diff changeset
  1781
#endif
93
Claus Gittinger <cg@exept.de>
parents: 92
diff changeset
  1782
	}
6
claus
parents: 4
diff changeset
  1783
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1784
	oClass = __Class(aDataBuffer);
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1785
	switch (_intVal(_ClassInstPtr(oClass)->c_flags) & ARRAYMASK) {
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1786
	    case BYTEARRAY:
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1787
		offs = __intVal(startIndex) - 1;
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1788
		break;
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1789
	    case WORDARRAY:
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1790
		offs = (__intVal(startIndex) - 1) * sizeof(short);
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1791
		break;
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1792
	    case LONGARRAY:
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1793
		offs = (__intVal(startIndex) - 1) * sizeof(long);
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1794
		break;
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1795
	    case FLOATARRAY:
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1796
		offs = (__intVal(startIndex) - 1) * sizeof(float);
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1797
		break;
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1798
	    case DOUBLEARRAY:
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1799
		offs = (__intVal(startIndex) - 1) * sizeof(double);
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1800
#ifdef NEED_DOUBLE_ALIGN
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1801
		offs += sizeof(long);
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1802
#endif
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1803
		break;
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1804
	    default:
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1805
		goto bad;
42
506596f9a1a8 *** empty log message ***
claus
parents: 38
diff changeset
  1806
	}
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1807
	nBytes = __intVal(count);
71
claus
parents: 63
diff changeset
  1808
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1809
	nInstVars = _intVal(_ClassInstPtr(oClass)->c_ninstvars);
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1810
	nInstBytes = OHDR_SIZE + nInstVars * sizeof(OBJ);
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1811
	objSize = __qSize(aDataBuffer) - nInstBytes;
217
fcfbc9f71048 underscore cleanup
Claus Gittinger <cg@exept.de>
parents: 209
diff changeset
  1812
	cp = (char *)__InstPtr(aDataBuffer) + nInstBytes;
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1813
	cp += offs;
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1814
	if ((offs + nBytes) > objSize) {
526
1748ab3892a3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 525
diff changeset
  1815
#ifdef DGRAM_DEBUG
1748ab3892a3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 525
diff changeset
  1816
	    printf("cut off ...\n");
1748ab3892a3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 525
diff changeset
  1817
#endif
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1818
	    nBytes = objSize - offs;
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1819
	}
0
1cf8d1747859 Initial revision
claus
parents:
diff changeset
  1820
526
1748ab3892a3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 525
diff changeset
  1821
	norder = htonl(sa.in.sin_addr.s_addr);
1748ab3892a3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 525
diff changeset
  1822
#ifdef DGRAM_DEBUG
1748ab3892a3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 525
diff changeset
  1823
	printf("sending %d bytes ... to ", nBytes);
1748ab3892a3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 525
diff changeset
  1824
	printf("%d.%d.%d.%d\n",
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1825
		    (norder >> 24) & 0xFF,
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1826
		    (norder >> 16) & 0xFF,
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1827
		    (norder >> 8) & 0xFF,
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1828
		    norder & 0xFF);
526
1748ab3892a3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 525
diff changeset
  1829
#endif
0
1cf8d1747859 Initial revision
claus
parents:
diff changeset
  1830
81
claus
parents: 79
diff changeset
  1831
	__BEGIN_INTERRUPTABLE__
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1832
	do {
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1833
	    n = sendto(sock, cp, nBytes, _flags, saPtr, alen);
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1834
	} while ((n < 0) && (errno == EINTR));
81
claus
parents: 79
diff changeset
  1835
	__END_INTERRUPTABLE__
0
1cf8d1747859 Initial revision
claus
parents:
diff changeset
  1836
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1837
	if (n < 0) {
217
fcfbc9f71048 underscore cleanup
Claus Gittinger <cg@exept.de>
parents: 209
diff changeset
  1838
	    __INST(lastErrorNumber) = __MKSMALLINT(errno);
42
506596f9a1a8 *** empty log message ***
claus
parents: 38
diff changeset
  1839
	}
217
fcfbc9f71048 underscore cleanup
Claus Gittinger <cg@exept.de>
parents: 209
diff changeset
  1840
	RETURN (__MKSMALLINT(n));
0
1cf8d1747859 Initial revision
claus
parents:
diff changeset
  1841
    }
418
317e55c6c281 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 403
diff changeset
  1842
#endif
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1843
bad: ;
42
506596f9a1a8 *** empty log message ***
claus
parents: 38
diff changeset
  1844
%}.
506596f9a1a8 *** empty log message ***
claus
parents: 38
diff changeset
  1845
    "
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1846
     arrive here if you try to send from an invalid buffer
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1847
     (i.e. not ByteArray-like), 
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1848
     or if the addressBuffer is nonNil AND not a ByteArray/String 
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1849
     or if the addressBuffer is nonNil AND too small.
42
506596f9a1a8 *** empty log message ***
claus
parents: 38
diff changeset
  1850
    "
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1851
    self primitiveFailed
0
1cf8d1747859 Initial revision
claus
parents:
diff changeset
  1852
! !
1cf8d1747859 Initial revision
claus
parents:
diff changeset
  1853
1cf8d1747859 Initial revision
claus
parents:
diff changeset
  1854
!Socket methodsFor:'low level'!
1cf8d1747859 Initial revision
claus
parents:
diff changeset
  1855
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1856
accept
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1857
    "create a new TCP socket from accepting on the receiver.
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1858
     This method will suspend the current process if no connection is waiting.
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1859
     For ST-80 compatibility"
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1860
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1861
    |newSock|
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1862
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1863
    newSock := self class new.
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1864
    (newSock acceptOn:self) ifFalse:[^ nil].
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1865
    ^ newSock
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1866
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1867
    "
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1868
     |sock newSock|
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1869
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1870
     sock := Socket provide:8004.
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1871
     sock listenFor:5.
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1872
     newSock := sock accept.
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1873
    "
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1874
!
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1875
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1876
acceptOn:aSocket
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1877
    "accept a connection on a server port (created with:'Socket>>onIPPort:')
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1878
     usage is: (Socket basicNew acceptOn:(Socket onIPPort:9999)).
207
e9f6913dc380 split: #accept is nonBlock; the old accept is not called #blockingAccept
Claus Gittinger <cg@exept.de>
parents: 206
diff changeset
  1879
     This method will suspend the current process if no connection is waiting.
e9f6913dc380 split: #accept is nonBlock; the old accept is not called #blockingAccept
Claus Gittinger <cg@exept.de>
parents: 206
diff changeset
  1880
     Return the true if ok; false if not."
e9f6913dc380 split: #accept is nonBlock; the old accept is not called #blockingAccept
Claus Gittinger <cg@exept.de>
parents: 206
diff changeset
  1881
208
c3eca2cc16dc accept: do not wait for input on non-connected socket.
Stefan Vogel <sv@exept.de>
parents: 207
diff changeset
  1882
    aSocket readWait.
207
e9f6913dc380 split: #accept is nonBlock; the old accept is not called #blockingAccept
Claus Gittinger <cg@exept.de>
parents: 206
diff changeset
  1883
    ^ self blockingAcceptOn:aSocket
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  1884
208
c3eca2cc16dc accept: do not wait for input on non-connected socket.
Stefan Vogel <sv@exept.de>
parents: 207
diff changeset
  1885
    "Modified: 11.3.1996 / 14:21:31 / stefan"
8
8c365abe1ffe *** empty log message ***
claus
parents: 6
diff changeset
  1886
!
8c365abe1ffe *** empty log message ***
claus
parents: 6
diff changeset
  1887
507
91fb3dfd91a5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 506
diff changeset
  1888
bindAnonymously
91fb3dfd91a5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 506
diff changeset
  1889
    ^ self
91fb3dfd91a5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 506
diff changeset
  1890
	bindTo:0
91fb3dfd91a5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 506
diff changeset
  1891
	address:nil
509
eb5a2d5bab0b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 508
diff changeset
  1892
	reuseAddress:false
eb5a2d5bab0b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 508
diff changeset
  1893
!
eb5a2d5bab0b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 508
diff changeset
  1894
eb5a2d5bab0b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 508
diff changeset
  1895
bindAnonymouslyToAddress:addressString
eb5a2d5bab0b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 508
diff changeset
  1896
    ^ self
eb5a2d5bab0b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 508
diff changeset
  1897
	bindTo:0
eb5a2d5bab0b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 508
diff changeset
  1898
	address:addressString
eb5a2d5bab0b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 508
diff changeset
  1899
	reuseAddress:false
507
91fb3dfd91a5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 506
diff changeset
  1900
!
91fb3dfd91a5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 506
diff changeset
  1901
71
claus
parents: 63
diff changeset
  1902
bindTo:aSocketAddress 
425
eb8198e9f1b0 comment
Claus Gittinger <cg@exept.de>
parents: 421
diff changeset
  1903
    "ST80 compatible bind, expecting a socketAddress argument.
eb8198e9f1b0 comment
Claus Gittinger <cg@exept.de>
parents: 421
diff changeset
  1904
     The socketAddress object (an instance of SocketAddress)
eb8198e9f1b0 comment
Claus Gittinger <cg@exept.de>
parents: 421
diff changeset
  1905
     is supposed to respond to #portOrName and #address requests."
71
claus
parents: 63
diff changeset
  1906
claus
parents: 63
diff changeset
  1907
    ^ self bindTo:(aSocketAddress portOrName)
claus
parents: 63
diff changeset
  1908
	   address:(aSocketAddress address)
425
eb8198e9f1b0 comment
Claus Gittinger <cg@exept.de>
parents: 421
diff changeset
  1909
	   reuseAddress:true
71
claus
parents: 63
diff changeset
  1910
!
claus
parents: 63
diff changeset
  1911
425
eb8198e9f1b0 comment
Claus Gittinger <cg@exept.de>
parents: 421
diff changeset
  1912
bindTo:portNrOrNameString address:addressString
28
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  1913
    "low level bind - returns true if ok, false otherwise.
71
claus
parents: 63
diff changeset
  1914
     Currently only non-address binding is supported; 
425
eb8198e9f1b0 comment
Claus Gittinger <cg@exept.de>
parents: 421
diff changeset
  1915
     i.e. the address must always be nil.
71
claus
parents: 63
diff changeset
  1916
claus
parents: 63
diff changeset
  1917
     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
  1918
	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
  1919
	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
  1920
	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
  1921
     "
7789fb1c9fa2 more UD socket fixes (at least client side seems to work now)
Claus Gittinger <cg@exept.de>
parents: 115
diff changeset
  1922
425
eb8198e9f1b0 comment
Claus Gittinger <cg@exept.de>
parents: 421
diff changeset
  1923
    ^ self 
eb8198e9f1b0 comment
Claus Gittinger <cg@exept.de>
parents: 421
diff changeset
  1924
	bindTo:portNrOrNameString 
eb8198e9f1b0 comment
Claus Gittinger <cg@exept.de>
parents: 421
diff changeset
  1925
	address:addressString 
eb8198e9f1b0 comment
Claus Gittinger <cg@exept.de>
parents: 421
diff changeset
  1926
	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
  1927
!
7789fb1c9fa2 more UD socket fixes (at least client side seems to work now)
Claus Gittinger <cg@exept.de>
parents: 115
diff changeset
  1928
7789fb1c9fa2 more UD socket fixes (at least client side seems to work now)
Claus Gittinger <cg@exept.de>
parents: 115
diff changeset
  1929
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
  1930
    "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
  1931
     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
  1932
     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
  1933
7789fb1c9fa2 more UD socket fixes (at least client side seems to work now)
Claus Gittinger <cg@exept.de>
parents: 115
diff changeset
  1934
     The interpretation of portNrOrName depends on the domain:
524
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  1935
	inet domain uses (4byte) byteArray like internet numbers,
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  1936
	unix domain uses pathname strings,
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  1937
	others use whatever will come up in the future
425
eb8198e9f1b0 comment
Claus Gittinger <cg@exept.de>
parents: 421
diff changeset
  1938
eb8198e9f1b0 comment
Claus Gittinger <cg@exept.de>
parents: 421
diff changeset
  1939
     The reuse boolean argument controls if the SO_REUSEADDR socket option
eb8198e9f1b0 comment
Claus Gittinger <cg@exept.de>
parents: 421
diff changeset
  1940
     is to be set (to avoid the 'bind: address in use' error).
eb8198e9f1b0 comment
Claus Gittinger <cg@exept.de>
parents: 421
diff changeset
  1941
    "
28
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  1942
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  1943
    filePointer isNil ifTrue:[
524
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  1944
	^ self error:'not a valid socket'
28
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  1945
    ].
0
1cf8d1747859 Initial revision
claus
parents:
diff changeset
  1946
%{
418
317e55c6c281 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 403
diff changeset
  1947
#ifndef NO_SOCKET
217
fcfbc9f71048 underscore cleanup
Claus Gittinger <cg@exept.de>
parents: 209
diff changeset
  1948
    OBJ t = __INST(filePointer);
71
claus
parents: 63
diff changeset
  1949
    OBJ myDomain;
28
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  1950
    int sock;
116
7789fb1c9fa2 more UD socket fixes (at least client side seems to work now)
Claus Gittinger <cg@exept.de>
parents: 115
diff changeset
  1951
    union {
525
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  1952
# ifdef AF_INET
524
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  1953
	struct sockaddr_in in;
525
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  1954
# endif
530
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  1955
# ifdef AF_INET6
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  1956
	struct sockaddr_in6 in6;
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  1957
# endif
524
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  1958
# ifdef AF_UNIX
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  1959
	struct sockaddr_un un;
525
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  1960
# endif
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  1961
# ifdef AF_APPLETALK
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  1962
	struct sockaddr_at at;
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  1963
# endif
116
7789fb1c9fa2 more UD socket fixes (at least client side seems to work now)
Claus Gittinger <cg@exept.de>
parents: 115
diff changeset
  1964
    } sa;
7789fb1c9fa2 more UD socket fixes (at least client side seems to work now)
Claus Gittinger <cg@exept.de>
parents: 115
diff changeset
  1965
    int sockaddr_size;
6
claus
parents: 4
diff changeset
  1966
    int ret;
25
996051271ce9 *** empty log message ***
claus
parents: 21
diff changeset
  1967
    int on = 1;
28
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  1968
    int ok;
0
1cf8d1747859 Initial revision
claus
parents:
diff changeset
  1969
217
fcfbc9f71048 underscore cleanup
Claus Gittinger <cg@exept.de>
parents: 209
diff changeset
  1970
    if (!__isString(__INST(domain)) && !__isSymbol(__INST(domain))) {
524
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  1971
	DBGPRINTF(("SOCKET: invalid domain arg\n"));
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  1972
	RETURN (false);
28
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  1973
    }
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  1974
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  1975
    ok = 0;
217
fcfbc9f71048 underscore cleanup
Claus Gittinger <cg@exept.de>
parents: 209
diff changeset
  1976
    myDomain = __INST(domain);
525
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  1977
506
11ef93d12870 support anonymous (OS_specified) ports. (for FTP-protocol)
Claus Gittinger <cg@exept.de>
parents: 486
diff changeset
  1978
# ifdef AF_INET
71
claus
parents: 63
diff changeset
  1979
    if (myDomain == @symbol(inet)) {
524
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  1980
	/*
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  1981
	 * INET addresses - port must be a smallinteger or nil
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  1982
	 */
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  1983
	sa.in.sin_family = AF_INET;
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  1984
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  1985
	if (portNrOrName == nil) {
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  1986
	    sa.in.sin_port = 0;
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  1987
	} else {
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  1988
	    if (! __isSmallInteger(portNrOrName)) {
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  1989
		DBGPRINTF(("SOCKET: invalid port arg\n"));
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  1990
		RETURN (false);
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  1991
	    }
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  1992
	    sa.in.sin_port = htons((u_short) _intVal(portNrOrName));
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  1993
	}
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  1994
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  1995
	/*
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  1996
	 * INET addresses - addr must be nil, integer or byteArray
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  1997
	 */
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  1998
	if (address == nil) {
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  1999
	    sa.in.sin_addr.s_addr = htonl(INADDR_ANY);
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  2000
	} else {
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  2001
	    if (__isInteger(address)) {
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  2002
		sa.in.sin_addr.s_addr = htonl(__longIntVal(address));
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  2003
	    } else {
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  2004
		if (__isByteArray(address)) {
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  2005
		    unsigned char *cp;
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  2006
		    int n;
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  2007
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  2008
		    cp = __ByteArrayInstPtr(address)->ba_element;
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  2009
		    n = __byteArraySize(address);
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  2010
		    if (n > 4) n = 4;
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  2011
		    bcopy(cp, &sa.in.sin_addr.s_addr, n);
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  2012
		} else {
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  2013
		    char *hostName;
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  2014
		    unsigned addr;
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  2015
		    struct hostent *hp ;
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  2016
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  2017
		    if (! __isString(address)) {
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  2018
			DBGPRINTF(("SOCKET: invalid address arg in bind\n"));
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  2019
			RETURN (false);
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  2020
		    }
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  2021
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  2022
		    hostName = (char *) __stringVal(address);
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  2023
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  2024
		    if ((addr = inet_addr(hostName)) != -1) {
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  2025
			/* 
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  2026
			 * is Internet addr in octet notation 
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  2027
			 */
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  2028
			bcopy(&addr, (char *) &sa.in.sin_addr, sizeof(addr)) ; /* set address */
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  2029
		    } else {
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  2030
			/* 
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  2031
			 * do we know the host's address? 
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  2032
			 */
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  2033
			if ((hp = gethostbyname(hostName)) == NULL) {
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  2034
			    DBGPRINTF(("SOCKET: unknown host:%s\n", hostName));
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  2035
			    RETURN (false);
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  2036
			}
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  2037
			bcopy(hp->h_addr, (char *) &sa.in.sin_addr, hp->h_length) ;
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  2038
			sa.in.sin_family = hp->h_addrtype;
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  2039
		    }
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  2040
		}
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  2041
	    }
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  2042
	}
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  2043
	DBGPRINTF(("SOCKET: bind addr: %x port: %x\n", sa.in.sin_addr.s_addr, sa.in.sin_port));
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  2044
	sockaddr_size = sizeof(struct sockaddr_in);
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  2045
	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
  2046
    }
530
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  2047
# endif /* AF_INET */
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  2048
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  2049
# ifdef AF_INET6
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  2050
    if (myDomain == @symbol(inet6)) {
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  2051
	/*
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  2052
	 * INET6 addresses - port must be a smallinteger or nil
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  2053
	 */
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  2054
	sa.in6.sin6_family = AF_INET6;
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  2055
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  2056
	if (portNrOrName == nil) {
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  2057
	    sa.in6.sin6_port = 0;
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  2058
	} else {
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  2059
	    if (! __isSmallInteger(portNrOrName)) {
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  2060
		DBGPRINTF(("SOCKET: invalid port arg\n"));
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  2061
		RETURN (false);
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  2062
	    }
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  2063
	    sa.in6.sin6_port = htons((u_short) _intVal(portNrOrName));
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  2064
	}
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  2065
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  2066
	/*
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  2067
	 * INET6 addresses - addr must be nil or byteArray or string
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  2068
	 */
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  2069
	if (address == nil) {
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  2070
	    sa.in6.sin6_addr.s6_addr[0] = 0;
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  2071
	    sa.in6.sin6_addr.s6_addr[1] = 0;
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  2072
	    sa.in6.sin6_addr.s6_addr[2] = 0;
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  2073
	    sa.in6.sin6_addr.s6_addr[3] = 0;
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  2074
	    sa.in6.sin6_addr.s6_addr[4] = 0;
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  2075
	    sa.in6.sin6_addr.s6_addr[5] = 0;
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  2076
	} else {
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  2077
	    if (__isByteArray(address)) {
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  2078
		unsigned char *cp;
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  2079
		int n;
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  2080
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  2081
		cp = __ByteArrayInstPtr(address)->ba_element;
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  2082
		n = __byteArraySize(address);
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  2083
		if (n > 6) n = 6;
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  2084
		bcopy(cp, &sa.in6.sin6_addr.s6_addr, n);
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  2085
	    } else {
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  2086
		char *hostName;
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  2087
		unsigned addr;
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  2088
		struct hostent *hp ;
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  2089
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  2090
		if (! __isString(address)) {
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  2091
		    DBGPRINTF(("SOCKET: invalid address arg in bind\n"));
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  2092
		    RETURN (false);
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  2093
		}
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  2094
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  2095
		hostName = (char *) __stringVal(address);
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  2096
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  2097
		/* 
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  2098
		 * do we know the host's address? 
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  2099
		 */
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  2100
		if ((hp = gethostbyname(hostName)) == NULL) {
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  2101
		    DBGPRINTF(("SOCKET: unknown host:%s\n", hostName));
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  2102
		    RETURN (false);
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  2103
		}
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  2104
		bcopy(hp->h_addr, (char *) &sa.in6.sin6_addr, hp->h_length) ;
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  2105
		sa.in.sin_family = hp->h_addrtype;
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  2106
	    }
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  2107
	}
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  2108
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  2109
	DBGPRINTF(("SOCKET: bind addr: %x.%x.%x.%x.%x.%x port: %x\n", 
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  2110
			sa.in6.sin6_addr.s6_addr[0], 
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  2111
			sa.in6.sin6_addr.s6_addr[1], 
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  2112
			sa.in6.sin6_addr.s6_addr[2], 
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  2113
			sa.in6.sin6_addr.s6_addr[3], 
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  2114
			sa.in6.sin6_addr.s6_addr[4], 
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  2115
			sa.in6.sin6_addr.s6_addr[5], 
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  2116
			sa.in6.sin6_port));
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  2117
	sockaddr_size = sizeof(struct sockaddr_in6);
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  2118
	ok = 1;
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  2119
    }
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  2120
# endif /* AF_INET6 */
525
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  2121
506
11ef93d12870 support anonymous (OS_specified) ports. (for FTP-protocol)
Claus Gittinger <cg@exept.de>
parents: 486
diff changeset
  2122
# ifdef AF_UNIX
525
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  2123
    /*
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  2124
     * UNIX domain - port is ignored; address must be a string (path)
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  2125
     */
116
7789fb1c9fa2 more UD socket fixes (at least client side seems to work now)
Claus Gittinger <cg@exept.de>
parents: 115
diff changeset
  2126
    if (myDomain == @symbol(unix)) {
524
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  2127
	char *pathName;
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  2128
	int l;
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  2129
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  2130
	if (! __isString(portNrOrName)) {
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  2131
	    DBGPRINTF(("SOCKET: invalid port (pathname) arg\n"));
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  2132
	    RETURN (false);
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  2133
	}
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  2134
	pathName = __stringVal(portNrOrName);
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  2135
	l = strlen(pathName);
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  2136
	if ((l + sizeof ( sa.un.sun_family )) > sizeof(struct sockaddr_un)) {
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  2137
	    DBGPRINTF(("SOCKET: pathname too long\n"));
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  2138
	    RETURN (false);
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  2139
	}
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  2140
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  2141
	strcpy(sa.un.sun_path, pathName);
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  2142
	sa.un.sun_family = AF_UNIX;
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  2143
	sockaddr_size = l + sizeof ( sa.un.sun_family );
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  2144
	ok = 1;
28
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  2145
    }
530
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  2146
# endif /* AF_UNIX */
525
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  2147
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  2148
# ifdef AF_APPLETALK
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  2149
    /*
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  2150
     * this has never been tested ....
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  2151
     */
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  2152
    if (myDomain == @symbol(appletalk)) {
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  2153
	/*
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  2154
	 * APPLETALK addresses - port must be a smallinteger or nil
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  2155
	 */
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  2156
	sa.at.sat_family = AF_APPLETALK;
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  2157
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  2158
	if (portNrOrName == nil) {
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  2159
	    sa.at.sat_port = 0;
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  2160
	} else {
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  2161
	    if (! __isSmallInteger(portNrOrName)) {
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  2162
		DBGPRINTF(("SOCKET: invalid port arg\n"));
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  2163
		RETURN (false);
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  2164
	    }
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  2165
	    sa.at.sat_port = __intVal(portNrOrName);
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  2166
	}
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  2167
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  2168
	/*
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  2169
	 * APPLETALK addresses - addr must be nil, integer or byteArray
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  2170
	 * if integer, the low 8 bits are the node, the next higher 16
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  2171
	 * bit are the net.
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  2172
	 */
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  2173
	if (address == nil) {
529
fc7ec265717b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
  2174
	    sa.at.sat_addr.s_net = ATADDR_ANYNET;
fc7ec265717b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
  2175
	    sa.at.sat_addr.s_node = ATADDR_ANYNODE;
525
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  2176
	} else {
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  2177
	    if (__isInteger(address)) {
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  2178
		unsigned a = __longIntVal(address);
529
fc7ec265717b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
  2179
		sa.at.sat_addr.s_net = htons((a >> 8) & 0xFFFF);
fc7ec265717b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
  2180
		sa.at.sat_addr.s_node = htons(a & 0xFF);
525
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  2181
	    } else {
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  2182
		if (__isByteArray(address)) {
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  2183
		    unsigned char *cp;
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  2184
		    int n;
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  2185
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  2186
		    cp = __ByteArrayInstPtr(address)->ba_element;
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  2187
		    n = __byteArraySize(address);
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  2188
		    if (n > 3) n = 3;
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  2189
		    bcopy(cp, &sa.at.sat_addr, n);
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  2190
		} else {
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  2191
		    char *hostName;
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  2192
		    unsigned addr;
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  2193
		    struct hostent *hp ;
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  2194
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  2195
		    if (! __isString(address)) {
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  2196
			DBGPRINTF(("SOCKET: invalid address arg in bind\n"));
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  2197
			RETURN (false);
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  2198
		    }
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  2199
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  2200
		    hostName = (char *) __stringVal(address);
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  2201
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  2202
		    /* 
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  2203
		     * do we know the host's address? 
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  2204
		     */
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  2205
		    if ((hp = gethostbyname(hostName)) == NULL) {
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  2206
			DBGPRINTF(("SOCKET: unknown host:%s\n", hostName));
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  2207
			RETURN (false);
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  2208
		    }
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  2209
		    if (hp->h_addrtype != AF_APPLETALK) {
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  2210
			DBGPRINTF(("SOCKET: host:%s is not an appletalk host\n", hostName));
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  2211
			RETURN (false);
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  2212
		    }
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  2213
		    bcopy(hp->h_addr, (char *) &sa.at.sat_addr, hp->h_length) ;
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  2214
		    sa.at.sat_family = hp->h_addrtype;
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  2215
		}
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  2216
	    }
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  2217
	}
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  2218
	DBGPRINTF(("SOCKET: bind addr: %x port: %x\n", sa.in.sin_addr.s_addr, sa.in.sin_port));
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  2219
	sockaddr_size = sizeof(struct sockaddr_at);
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  2220
	ok = 1;
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  2221
    }
530
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  2222
# endif /* AF_APPLETALK */
525
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  2223
28
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  2224
    /*
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  2225
     * XXXX add addressing stuff for other domains here ...
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  2226
     */
506
11ef93d12870 support anonymous (OS_specified) ports. (for FTP-protocol)
Claus Gittinger <cg@exept.de>
parents: 486
diff changeset
  2227
# ifdef AF_X25
71
claus
parents: 63
diff changeset
  2228
    if (myDomain == @symbol(x25)) {
28
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  2229
    }
506
11ef93d12870 support anonymous (OS_specified) ports. (for FTP-protocol)
Claus Gittinger <cg@exept.de>
parents: 486
diff changeset
  2230
# endif
11ef93d12870 support anonymous (OS_specified) ports. (for FTP-protocol)
Claus Gittinger <cg@exept.de>
parents: 486
diff changeset
  2231
# ifdef AF_NS
71
claus
parents: 63
diff changeset
  2232
    if (myDomain == @symbol(ns)) {
28
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  2233
    }
506
11ef93d12870 support anonymous (OS_specified) ports. (for FTP-protocol)
Claus Gittinger <cg@exept.de>
parents: 486
diff changeset
  2234
# endif
524
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  2235
# ifdef AF_DECnet
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  2236
    if (myDomain == @symbol(decnet)) {
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  2237
    }
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  2238
# endif
506
11ef93d12870 support anonymous (OS_specified) ports. (for FTP-protocol)
Claus Gittinger <cg@exept.de>
parents: 486
diff changeset
  2239
# ifdef AF_SNA
93
Claus Gittinger <cg@exept.de>
parents: 92
diff changeset
  2240
    if (myDomain == @symbol(sna)) {
Claus Gittinger <cg@exept.de>
parents: 92
diff changeset
  2241
    }
506
11ef93d12870 support anonymous (OS_specified) ports. (for FTP-protocol)
Claus Gittinger <cg@exept.de>
parents: 486
diff changeset
  2242
# endif
11ef93d12870 support anonymous (OS_specified) ports. (for FTP-protocol)
Claus Gittinger <cg@exept.de>
parents: 486
diff changeset
  2243
# ifdef AF_NS
93
Claus Gittinger <cg@exept.de>
parents: 92
diff changeset
  2244
    if (myDomain == @symbol(xns)) {
Claus Gittinger <cg@exept.de>
parents: 92
diff changeset
  2245
    }
506
11ef93d12870 support anonymous (OS_specified) ports. (for FTP-protocol)
Claus Gittinger <cg@exept.de>
parents: 486
diff changeset
  2246
# endif
11ef93d12870 support anonymous (OS_specified) ports. (for FTP-protocol)
Claus Gittinger <cg@exept.de>
parents: 486
diff changeset
  2247
# ifdef AF_RAW
93
Claus Gittinger <cg@exept.de>
parents: 92
diff changeset
  2248
    if (myDomain == @symbol(raw)) {
Claus Gittinger <cg@exept.de>
parents: 92
diff changeset
  2249
    }
506
11ef93d12870 support anonymous (OS_specified) ports. (for FTP-protocol)
Claus Gittinger <cg@exept.de>
parents: 486
diff changeset
  2250
# endif
524
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  2251
# ifdef AF_ISO
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  2252
    if (myDomain == @symbol(iso)) {
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  2253
    }
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  2254
# endif
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  2255
# ifdef AF_NETBIOS
530
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  2256
    if (myDomain == @symbol(netbios)) {
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  2257
    }
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  2258
# endif
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  2259
# ifdef AF_IPX
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  2260
    if (myDomain == @symbol(ipx)) {
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  2261
    }
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  2262
# endif
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  2263
# ifdef AF_BRIDGE
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  2264
    if (myDomain == @symbol(bridge)) {
524
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  2265
    }
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  2266
# endif
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  2267
# if defined(AF_CCITT) && (AF_CCITT != AF_X25)
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  2268
    if (myDomain == @symbol(ccitt)) {
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  2269
    }
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  2270
# endif
0
1cf8d1747859 Initial revision
claus
parents:
diff changeset
  2271
28
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  2272
    if (! ok) {
524
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  2273
	DBGPRINTF(("SOCKET: unsupported domain\n"));
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  2274
	RETURN (false);
28
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  2275
    }
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  2276
110
7af19ae8693b use new FILE* wrapper macros (based on externalAddress)
Claus Gittinger <cg@exept.de>
parents: 106
diff changeset
  2277
    sock = fileno(__FILEVal(t));
28
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  2278
506
11ef93d12870 support anonymous (OS_specified) ports. (for FTP-protocol)
Claus Gittinger <cg@exept.de>
parents: 486
diff changeset
  2279
# 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
  2280
    if (reuse == true) {
524
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  2281
	if (setsockopt(sock, SOL_SOCKET, SO_REUSEADDR, (char *) &on, sizeof (on)) < 0) {
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  2282
	    DBGPRINTF(("SOCKET: setsockopt - SO_REUSEADDR failed\n"));
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  2283
	}
28
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  2284
    }
506
11ef93d12870 support anonymous (OS_specified) ports. (for FTP-protocol)
Claus Gittinger <cg@exept.de>
parents: 486
diff changeset
  2285
# endif /* SO_REUSEADDR */
28
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  2286
117
03cefad7e40b UD socket example & interruptable bind
Claus Gittinger <cg@exept.de>
parents: 116
diff changeset
  2287
    __BEGIN_INTERRUPTABLE__
28
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  2288
    do {
524
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  2289
	ret = bind(sock, (struct sockaddr *)&sa, sockaddr_size);
28
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  2290
    } while ((ret < 0) && (errno == EINTR));
117
03cefad7e40b UD socket example & interruptable bind
Claus Gittinger <cg@exept.de>
parents: 116
diff changeset
  2291
    __END_INTERRUPTABLE__
28
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  2292
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  2293
    if (ret < 0) {
524
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  2294
	DBGPRINTF(("SOCKET: bind failed errno=%d\n", errno));
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  2295
	__INST(lastErrorNumber) = __MKSMALLINT(errno);
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  2296
	RETURN (false);
0
1cf8d1747859 Initial revision
claus
parents:
diff changeset
  2297
    }
506
11ef93d12870 support anonymous (OS_specified) ports. (for FTP-protocol)
Claus Gittinger <cg@exept.de>
parents: 486
diff changeset
  2298
11ef93d12870 support anonymous (OS_specified) ports. (for FTP-protocol)
Claus Gittinger <cg@exept.de>
parents: 486
diff changeset
  2299
    __INST(port) = portNrOrName; __STORE(self, portNrOrName);
11ef93d12870 support anonymous (OS_specified) ports. (for FTP-protocol)
Claus Gittinger <cg@exept.de>
parents: 486
diff changeset
  2300
11ef93d12870 support anonymous (OS_specified) ports. (for FTP-protocol)
Claus Gittinger <cg@exept.de>
parents: 486
diff changeset
  2301
# ifdef AF_INET
11ef93d12870 support anonymous (OS_specified) ports. (for FTP-protocol)
Claus Gittinger <cg@exept.de>
parents: 486
diff changeset
  2302
    if (myDomain == @symbol(inet)) {
524
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  2303
	if (! __isSmallInteger(portNrOrName)
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  2304
	 || (portNrOrName == __MKSMALLINT(0))) {
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  2305
	    int p;
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  2306
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  2307
	    /*
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  2308
	     * INET anonymous port - get the actual portNr
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  2309
	     */
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  2310
	    if (getsockname(sock, (struct sockaddr *)&sa, &sockaddr_size) < 0) {
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  2311
		DBGPRINTF(("SOCKET: cannot get peername\n"));
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  2312
	    } else {
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  2313
		DBGPRINTF(("SOCKET: anon port=%x\n", sa.in.sin_port));
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  2314
		p = ntohs(sa.in.sin_port);
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  2315
		__INST(port) = __MKSMALLINT(p);
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  2316
	    }
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  2317
	}
506
11ef93d12870 support anonymous (OS_specified) ports. (for FTP-protocol)
Claus Gittinger <cg@exept.de>
parents: 486
diff changeset
  2318
    }
11ef93d12870 support anonymous (OS_specified) ports. (for FTP-protocol)
Claus Gittinger <cg@exept.de>
parents: 486
diff changeset
  2319
# endif
530
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  2320
# ifdef AF_INET6
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  2321
    if (myDomain == @symbol(inet6)) {
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  2322
        if (! __isSmallInteger(portNrOrName)
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  2323
         || (portNrOrName == __MKSMALLINT(0))) {
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  2324
            int p;
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  2325
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  2326
            /*
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  2327
             * INET6 anonymous port - get the actual portNr
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  2328
             */
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  2329
            if (getsockname(sock, (struct sockaddr *)&sa, &sockaddr_size) < 0) {
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  2330
                DBGPRINTF(("SOCKET: cannot get peername\n"));
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  2331
            } else {
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  2332
                DBGPRINTF(("SOCKET: anon port=%x\n", sa.in.sin_port));
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  2333
                p = ntohs(sa.in6.sin6_port);
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  2334
                __INST(port) = __MKSMALLINT(p);
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  2335
            }
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  2336
        }
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  2337
    }
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  2338
# endif
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  2339
# ifdef AF_APPLETALK
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  2340
    if (myDomain == @symbol(appletalk)) {
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  2341
        if (! __isSmallInteger(portNrOrName)
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  2342
         || (portNrOrName == __MKSMALLINT(0))) {
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  2343
            int p;
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  2344
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  2345
            /*
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  2346
             * APPLETALK anonymous port - get the actual portNr
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  2347
             */
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  2348
            if (getsockname(sock, (struct sockaddr *)&sa, &sockaddr_size) < 0) {
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  2349
                DBGPRINTF(("SOCKET: cannot get peername\n"));
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  2350
            } else {
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  2351
                DBGPRINTF(("SOCKET: anon port=%x\n", sa.in.sin_port));
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  2352
                p = sa.at.sat_port;
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  2353
                __INST(port) = __MKSMALLINT(p);
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  2354
            }
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  2355
        }
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  2356
    }
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  2357
# endif
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  2358
506
11ef93d12870 support anonymous (OS_specified) ports. (for FTP-protocol)
Claus Gittinger <cg@exept.de>
parents: 486
diff changeset
  2359
#else /* NO_SOCKET */
418
317e55c6c281 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 403
diff changeset
  2360
    RETURN (false);
506
11ef93d12870 support anonymous (OS_specified) ports. (for FTP-protocol)
Claus Gittinger <cg@exept.de>
parents: 486
diff changeset
  2361
#endif /* NO_SOCKET */
42
506596f9a1a8 *** empty log message ***
claus
parents: 38
diff changeset
  2362
%}.
28
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  2363
    ^ true
0
1cf8d1747859 Initial revision
claus
parents:
diff changeset
  2364
28
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  2365
    "
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  2366
     (Socket domain:#inet type:#stream)
524
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  2367
	 bindTo:9999
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  2368
	 address:nil
28
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  2369
    "
0
1cf8d1747859 Initial revision
claus
parents:
diff changeset
  2370
!
1cf8d1747859 Initial revision
claus
parents:
diff changeset
  2371
208
c3eca2cc16dc accept: do not wait for input on non-connected socket.
Stefan Vogel <sv@exept.de>
parents: 207
diff changeset
  2372
blockingAcceptOn:aSocket
c3eca2cc16dc accept: do not wait for input on non-connected socket.
Stefan Vogel <sv@exept.de>
parents: 207
diff changeset
  2373
    "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
  2374
     usage is: (Socket basicNew acceptOn:(Socket onIPPort:9999)).
c3eca2cc16dc accept: do not wait for input on non-connected socket.
Stefan Vogel <sv@exept.de>
parents: 207
diff changeset
  2375
     Return the true if ok; false if not.
c3eca2cc16dc accept: do not wait for input on non-connected socket.
Stefan Vogel <sv@exept.de>
parents: 207
diff changeset
  2376
c3eca2cc16dc accept: do not wait for input on non-connected socket.
Stefan Vogel <sv@exept.de>
parents: 207
diff changeset
  2377
     NOTICE: this method will block, if no connection is already pending.
506
11ef93d12870 support anonymous (OS_specified) ports. (for FTP-protocol)
Claus Gittinger <cg@exept.de>
parents: 486
diff changeset
  2378
	     use readWait or Socket>>accept."
208
c3eca2cc16dc accept: do not wait for input on non-connected socket.
Stefan Vogel <sv@exept.de>
parents: 207
diff changeset
  2379
c3eca2cc16dc accept: do not wait for input on non-connected socket.
Stefan Vogel <sv@exept.de>
parents: 207
diff changeset
  2380
    |serverSocketFd|
c3eca2cc16dc accept: do not wait for input on non-connected socket.
Stefan Vogel <sv@exept.de>
parents: 207
diff changeset
  2381
c3eca2cc16dc accept: do not wait for input on non-connected socket.
Stefan Vogel <sv@exept.de>
parents: 207
diff changeset
  2382
    filePointer notNil ifTrue:[
506
11ef93d12870 support anonymous (OS_specified) ports. (for FTP-protocol)
Claus Gittinger <cg@exept.de>
parents: 486
diff changeset
  2383
	^ self error:'already connected'
208
c3eca2cc16dc accept: do not wait for input on non-connected socket.
Stefan Vogel <sv@exept.de>
parents: 207
diff changeset
  2384
    ].
c3eca2cc16dc accept: do not wait for input on non-connected socket.
Stefan Vogel <sv@exept.de>
parents: 207
diff changeset
  2385
c3eca2cc16dc accept: do not wait for input on non-connected socket.
Stefan Vogel <sv@exept.de>
parents: 207
diff changeset
  2386
    domain := aSocket domain.
c3eca2cc16dc accept: do not wait for input on non-connected socket.
Stefan Vogel <sv@exept.de>
parents: 207
diff changeset
  2387
    socketType := aSocket type.
c3eca2cc16dc accept: do not wait for input on non-connected socket.
Stefan Vogel <sv@exept.de>
parents: 207
diff changeset
  2388
    serverSocketFd := aSocket fileDescriptor.
c3eca2cc16dc accept: do not wait for input on non-connected socket.
Stefan Vogel <sv@exept.de>
parents: 207
diff changeset
  2389
    serverSocketFd isNil ifTrue:[
506
11ef93d12870 support anonymous (OS_specified) ports. (for FTP-protocol)
Claus Gittinger <cg@exept.de>
parents: 486
diff changeset
  2390
	^ 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
  2391
    ].
c3eca2cc16dc accept: do not wait for input on non-connected socket.
Stefan Vogel <sv@exept.de>
parents: 207
diff changeset
  2392
    (serverSocketFd isMemberOf:SmallInteger) ifFalse:[
506
11ef93d12870 support anonymous (OS_specified) ports. (for FTP-protocol)
Claus Gittinger <cg@exept.de>
parents: 486
diff changeset
  2393
	^ 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
  2394
    ].
c3eca2cc16dc accept: do not wait for input on non-connected socket.
Stefan Vogel <sv@exept.de>
parents: 207
diff changeset
  2395
%{
418
317e55c6c281 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 403
diff changeset
  2396
#ifndef NO_SOCKET
208
c3eca2cc16dc accept: do not wait for input on non-connected socket.
Stefan Vogel <sv@exept.de>
parents: 207
diff changeset
  2397
    FILE *fp;
c3eca2cc16dc accept: do not wait for input on non-connected socket.
Stefan Vogel <sv@exept.de>
parents: 207
diff changeset
  2398
    int flags;
c3eca2cc16dc accept: do not wait for input on non-connected socket.
Stefan Vogel <sv@exept.de>
parents: 207
diff changeset
  2399
    int sock, newSock;
c3eca2cc16dc accept: do not wait for input on non-connected socket.
Stefan Vogel <sv@exept.de>
parents: 207
diff changeset
  2400
    union {
525
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  2401
#ifdef AF_INET
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  2402
	struct sockaddr_in in;
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  2403
#endif
530
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  2404
# ifdef AF_INET6
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  2405
	struct sockaddr_in6 in6;
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  2406
# endif
524
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  2407
# ifdef AF_UNIX
525
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  2408
	struct sockaddr_un un;
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  2409
# endif
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  2410
# ifdef AF_APPLETALK
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  2411
	struct sockaddr_at at;
524
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  2412
# endif
208
c3eca2cc16dc accept: do not wait for input on non-connected socket.
Stefan Vogel <sv@exept.de>
parents: 207
diff changeset
  2413
    } sa;
464
600b101a7035 alen in accept
Claus Gittinger <cg@exept.de>
parents: 463
diff changeset
  2414
    int alen, alen0;
208
c3eca2cc16dc accept: do not wait for input on non-connected socket.
Stefan Vogel <sv@exept.de>
parents: 207
diff changeset
  2415
    struct hostent *he ;
c3eca2cc16dc accept: do not wait for input on non-connected socket.
Stefan Vogel <sv@exept.de>
parents: 207
diff changeset
  2416
    char dotted[20] ;
c3eca2cc16dc accept: do not wait for input on non-connected socket.
Stefan Vogel <sv@exept.de>
parents: 207
diff changeset
  2417
c3eca2cc16dc accept: do not wait for input on non-connected socket.
Stefan Vogel <sv@exept.de>
parents: 207
diff changeset
  2418
    sock = _intVal(serverSocketFd);
c3eca2cc16dc accept: do not wait for input on non-connected socket.
Stefan Vogel <sv@exept.de>
parents: 207
diff changeset
  2419
c3eca2cc16dc accept: do not wait for input on non-connected socket.
Stefan Vogel <sv@exept.de>
parents: 207
diff changeset
  2420
#if defined(O_NDELAY) && defined(SET_NDELAY)
c3eca2cc16dc accept: do not wait for input on non-connected socket.
Stefan Vogel <sv@exept.de>
parents: 207
diff changeset
  2421
    flags = ioctl(sock, F_GETFL, 0);
c3eca2cc16dc accept: do not wait for input on non-connected socket.
Stefan Vogel <sv@exept.de>
parents: 207
diff changeset
  2422
    ioctl(sock, F_SETFL, flags | O_NDELAY);
c3eca2cc16dc accept: do not wait for input on non-connected socket.
Stefan Vogel <sv@exept.de>
parents: 207
diff changeset
  2423
#endif
464
600b101a7035 alen in accept
Claus Gittinger <cg@exept.de>
parents: 463
diff changeset
  2424
600b101a7035 alen in accept
Claus Gittinger <cg@exept.de>
parents: 463
diff changeset
  2425
#ifdef AF_INET
600b101a7035 alen in accept
Claus Gittinger <cg@exept.de>
parents: 463
diff changeset
  2426
    if (__INST(domain) == @symbol(inet)) {
506
11ef93d12870 support anonymous (OS_specified) ports. (for FTP-protocol)
Claus Gittinger <cg@exept.de>
parents: 486
diff changeset
  2427
	alen0 = sizeof(sa.in);
464
600b101a7035 alen in accept
Claus Gittinger <cg@exept.de>
parents: 463
diff changeset
  2428
    }
600b101a7035 alen in accept
Claus Gittinger <cg@exept.de>
parents: 463
diff changeset
  2429
#endif
530
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  2430
#ifdef AF_INET6
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  2431
    if (__INST(domain) == @symbol(inet6)) {
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  2432
        alen0 = sizeof(sa.in6);
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  2433
    }
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  2434
#endif
464
600b101a7035 alen in accept
Claus Gittinger <cg@exept.de>
parents: 463
diff changeset
  2435
#ifdef AF_UNIX
600b101a7035 alen in accept
Claus Gittinger <cg@exept.de>
parents: 463
diff changeset
  2436
    if (__INST(domain) == @symbol(unix)) {
506
11ef93d12870 support anonymous (OS_specified) ports. (for FTP-protocol)
Claus Gittinger <cg@exept.de>
parents: 486
diff changeset
  2437
	alen0 = sizeof(sa.un);
464
600b101a7035 alen in accept
Claus Gittinger <cg@exept.de>
parents: 463
diff changeset
  2438
    }
600b101a7035 alen in accept
Claus Gittinger <cg@exept.de>
parents: 463
diff changeset
  2439
#endif
530
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  2440
# ifdef AF_APPLETALK
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  2441
    if (__INST(domain) == @symbol(appletalk)) {
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  2442
	alen0 = sizeof(sa.at);
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  2443
    }
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  2444
# endif
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  2445
524
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  2446
    /*
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  2447
     * XXXX add addressing stuff for other domains here ...
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  2448
     */
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  2449
# ifdef AF_X25
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  2450
    if (__INST(domain) == @symbol(x25)) {
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  2451
    }
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  2452
# endif
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  2453
# ifdef AF_NS
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  2454
    if (__INST(domain) == @symbol(ns)) {
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  2455
    }
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  2456
# endif
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  2457
# ifdef AF_DECnet
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  2458
    if (__INST(domain) == @symbol(decnet)) {
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  2459
    }
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  2460
# endif
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  2461
# ifdef AF_SNA
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  2462
    if (__INST(domain) == @symbol(sna)) {
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  2463
    }
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  2464
# endif
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  2465
# ifdef AF_NS
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  2466
    if (__INST(domain) == @symbol(xns)) {
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  2467
    }
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  2468
# endif
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  2469
# ifdef AF_RAW
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  2470
    if (__INST(domain) == @symbol(raw)) {
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  2471
    }
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  2472
# endif
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  2473
# ifdef AF_ISO
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  2474
    if (__INST(domain) == @symbol(iso)) {
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  2475
    }
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  2476
# endif
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  2477
# ifdef AF_NETBIOS
530
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  2478
    if (__INST(domain) == @symbol(netbios)) {
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  2479
    }
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  2480
# endif
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  2481
# ifdef AF_IPX
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  2482
    if (__INST(domain) == @symbol(ipx)) {
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  2483
    }
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  2484
# endif
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  2485
# ifdef AF_BRIDGE
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  2486
    if (__INST(domain) == @symbol(bridge)) {
524
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  2487
    }
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  2488
# endif
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  2489
# if defined(AF_CCITT) && (AF_CCITT != AF_X25)
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  2490
    if (__INST(domain) == @symbol(ccitt)) {
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  2491
    }
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  2492
# endif
464
600b101a7035 alen in accept
Claus Gittinger <cg@exept.de>
parents: 463
diff changeset
  2493
208
c3eca2cc16dc accept: do not wait for input on non-connected socket.
Stefan Vogel <sv@exept.de>
parents: 207
diff changeset
  2494
    __BEGIN_INTERRUPTABLE__
c3eca2cc16dc accept: do not wait for input on non-connected socket.
Stefan Vogel <sv@exept.de>
parents: 207
diff changeset
  2495
    do {
506
11ef93d12870 support anonymous (OS_specified) ports. (for FTP-protocol)
Claus Gittinger <cg@exept.de>
parents: 486
diff changeset
  2496
	alen = alen0;
11ef93d12870 support anonymous (OS_specified) ports. (for FTP-protocol)
Claus Gittinger <cg@exept.de>
parents: 486
diff changeset
  2497
	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
  2498
    } 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
  2499
    __END_INTERRUPTABLE__
c3eca2cc16dc accept: do not wait for input on non-connected socket.
Stefan Vogel <sv@exept.de>
parents: 207
diff changeset
  2500
c3eca2cc16dc accept: do not wait for input on non-connected socket.
Stefan Vogel <sv@exept.de>
parents: 207
diff changeset
  2501
#if defined(O_NDELAY) && defined(SET_NDELAY)
c3eca2cc16dc accept: do not wait for input on non-connected socket.
Stefan Vogel <sv@exept.de>
parents: 207
diff changeset
  2502
    ioctl(sock, F_SETFL, flags);
c3eca2cc16dc accept: do not wait for input on non-connected socket.
Stefan Vogel <sv@exept.de>
parents: 207
diff changeset
  2503
#endif
c3eca2cc16dc accept: do not wait for input on non-connected socket.
Stefan Vogel <sv@exept.de>
parents: 207
diff changeset
  2504
c3eca2cc16dc accept: do not wait for input on non-connected socket.
Stefan Vogel <sv@exept.de>
parents: 207
diff changeset
  2505
    if (newSock < 0) {
506
11ef93d12870 support anonymous (OS_specified) ports. (for FTP-protocol)
Claus Gittinger <cg@exept.de>
parents: 486
diff changeset
  2506
	DBGPRINTF(("SOCKET: accept call failed errno=%d\n", errno));
11ef93d12870 support anonymous (OS_specified) ports. (for FTP-protocol)
Claus Gittinger <cg@exept.de>
parents: 486
diff changeset
  2507
	__INST(lastErrorNumber) = __MKSMALLINT(errno);
11ef93d12870 support anonymous (OS_specified) ports. (for FTP-protocol)
Claus Gittinger <cg@exept.de>
parents: 486
diff changeset
  2508
	RETURN (false);
208
c3eca2cc16dc accept: do not wait for input on non-connected socket.
Stefan Vogel <sv@exept.de>
parents: 207
diff changeset
  2509
    }
c3eca2cc16dc accept: do not wait for input on non-connected socket.
Stefan Vogel <sv@exept.de>
parents: 207
diff changeset
  2510
c3eca2cc16dc accept: do not wait for input on non-connected socket.
Stefan Vogel <sv@exept.de>
parents: 207
diff changeset
  2511
    /*
c3eca2cc16dc accept: do not wait for input on non-connected socket.
Stefan Vogel <sv@exept.de>
parents: 207
diff changeset
  2512
     * extract the partners address
c3eca2cc16dc accept: do not wait for input on non-connected socket.
Stefan Vogel <sv@exept.de>
parents: 207
diff changeset
  2513
     */
c3eca2cc16dc accept: do not wait for input on non-connected socket.
Stefan Vogel <sv@exept.de>
parents: 207
diff changeset
  2514
#ifdef AF_INET
217
fcfbc9f71048 underscore cleanup
Claus Gittinger <cg@exept.de>
parents: 209
diff changeset
  2515
    if (__INST(domain) == @symbol(inet)) {
506
11ef93d12870 support anonymous (OS_specified) ports. (for FTP-protocol)
Claus Gittinger <cg@exept.de>
parents: 486
diff changeset
  2516
	he = gethostbyaddr((char *) &sa.in.sin_addr.s_addr, alen, AF_INET) ;
11ef93d12870 support anonymous (OS_specified) ports. (for FTP-protocol)
Claus Gittinger <cg@exept.de>
parents: 486
diff changeset
  2517
	if (! he) {
11ef93d12870 support anonymous (OS_specified) ports. (for FTP-protocol)
Claus Gittinger <cg@exept.de>
parents: 486
diff changeset
  2518
	    unsigned long norder;
11ef93d12870 support anonymous (OS_specified) ports. (for FTP-protocol)
Claus Gittinger <cg@exept.de>
parents: 486
diff changeset
  2519
11ef93d12870 support anonymous (OS_specified) ports. (for FTP-protocol)
Claus Gittinger <cg@exept.de>
parents: 486
diff changeset
  2520
	    norder = htonl(sa.in.sin_addr.s_addr) ;
11ef93d12870 support anonymous (OS_specified) ports. (for FTP-protocol)
Claus Gittinger <cg@exept.de>
parents: 486
diff changeset
  2521
	    sprintf(dotted, "%d.%d.%d.%d",
11ef93d12870 support anonymous (OS_specified) ports. (for FTP-protocol)
Claus Gittinger <cg@exept.de>
parents: 486
diff changeset
  2522
		    (norder >> 24) & 0xFF,
11ef93d12870 support anonymous (OS_specified) ports. (for FTP-protocol)
Claus Gittinger <cg@exept.de>
parents: 486
diff changeset
  2523
		    (norder >> 16) & 0xFF,
11ef93d12870 support anonymous (OS_specified) ports. (for FTP-protocol)
Claus Gittinger <cg@exept.de>
parents: 486
diff changeset
  2524
		    (norder >> 8) & 0xFF,
11ef93d12870 support anonymous (OS_specified) ports. (for FTP-protocol)
Claus Gittinger <cg@exept.de>
parents: 486
diff changeset
  2525
		    norder & 0xFF);
11ef93d12870 support anonymous (OS_specified) ports. (for FTP-protocol)
Claus Gittinger <cg@exept.de>
parents: 486
diff changeset
  2526
	}
11ef93d12870 support anonymous (OS_specified) ports. (for FTP-protocol)
Claus Gittinger <cg@exept.de>
parents: 486
diff changeset
  2527
	DBGPRINTF(("SOCKET: accepted connection from host %s\n", (he ? he->h_name : dotted))) ;
11ef93d12870 support anonymous (OS_specified) ports. (for FTP-protocol)
Claus Gittinger <cg@exept.de>
parents: 486
diff changeset
  2528
	__INST(peerName) = __MKSTRING((he ? he->h_name : dotted));
11ef93d12870 support anonymous (OS_specified) ports. (for FTP-protocol)
Claus Gittinger <cg@exept.de>
parents: 486
diff changeset
  2529
	__STORESELF(peerName);
208
c3eca2cc16dc accept: do not wait for input on non-connected socket.
Stefan Vogel <sv@exept.de>
parents: 207
diff changeset
  2530
    }
c3eca2cc16dc accept: do not wait for input on non-connected socket.
Stefan Vogel <sv@exept.de>
parents: 207
diff changeset
  2531
#endif
530
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  2532
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  2533
#ifdef AF_INET6
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  2534
    if (__INST(domain) == @symbol(inet6)) {
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  2535
        he = gethostbyaddr((char *) &sa.in6.sin6_addr.s6_addr, alen, AF_INET6) ;
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  2536
        if (! he) {
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  2537
            unsigned long norder;
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  2538
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  2539
	    /*
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  2540
	     * XXX: what is inet6's naming convention ?
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  2541
	     */
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  2542
            norder = htonl(sa.in.sin_addr.s_addr) ;
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  2543
            sprintf(dotted, "%d.%d.%d.%d",
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  2544
                    sa.in6.sin6_addr.s6_addr[0],
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  2545
                    sa.in6.sin6_addr.s6_addr[1],
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  2546
                    sa.in6.sin6_addr.s6_addr[2],
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  2547
                    sa.in6.sin6_addr.s6_addr[3],
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  2548
                    sa.in6.sin6_addr.s6_addr[4],
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  2549
                    sa.in6.sin6_addr.s6_addr[5]);
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  2550
        }
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  2551
        DBGPRINTF(("SOCKET: accepted connection from host %s\n", (he ? he->h_name : dotted))) ;
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  2552
        __INST(peerName) = __MKSTRING((he ? he->h_name : dotted));
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  2553
        __STORESELF(peerName);
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  2554
    }
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  2555
#endif
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  2556
208
c3eca2cc16dc accept: do not wait for input on non-connected socket.
Stefan Vogel <sv@exept.de>
parents: 207
diff changeset
  2557
#ifdef AF_UNIX
217
fcfbc9f71048 underscore cleanup
Claus Gittinger <cg@exept.de>
parents: 209
diff changeset
  2558
    if (__INST(domain) == @symbol(unix)) {
506
11ef93d12870 support anonymous (OS_specified) ports. (for FTP-protocol)
Claus Gittinger <cg@exept.de>
parents: 486
diff changeset
  2559
	DBGPRINTF(("SOCKET: accepted connection on unix socket\n")) ;
11ef93d12870 support anonymous (OS_specified) ports. (for FTP-protocol)
Claus Gittinger <cg@exept.de>
parents: 486
diff changeset
  2560
	/* 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
  2561
    }
c3eca2cc16dc accept: do not wait for input on non-connected socket.
Stefan Vogel <sv@exept.de>
parents: 207
diff changeset
  2562
#endif
530
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  2563
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  2564
#ifdef AF_APPLETALK
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  2565
    if (__INST(domain) == @symbol(appletalk)) {
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  2566
        he = gethostbyaddr((char *) &sa.at.sat_addr, alen, AF_APPLETALK) ;
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  2567
        if (! he) {
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  2568
            unsigned net;
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  2569
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  2570
	    /*
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  2571
	     * XXX: what is apples naming convention ?
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  2572
	     */
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  2573
            net = htons(sa.at.sat_addr.s_net) ;
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  2574
            sprintf(dotted, "%d.%d",
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  2575
                    net,
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  2576
                    sa.at.sat_addr.s_node);
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  2577
        }
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  2578
        DBGPRINTF(("SOCKET: accepted connection from host %s\n", (he ? he->h_name : dotted))) ;
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  2579
        __INST(peerName) = __MKSTRING((he ? he->h_name : dotted));
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  2580
        __STORESELF(peerName);
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  2581
    }
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  2582
# endif
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  2583
524
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  2584
    /*
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  2585
     * XXXX add addressing stuff for other domains here ...
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  2586
     */
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  2587
# ifdef AF_X25
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  2588
    if (__INST(domain) == @symbol(x25)) {
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  2589
    }
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  2590
# endif
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  2591
# ifdef AF_NS
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  2592
    if (__INST(domain) == @symbol(ns)) {
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  2593
    }
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  2594
# endif
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  2595
# ifdef AF_DECnet
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  2596
    if (__INST(domain) == @symbol(decnet)) {
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  2597
    }
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  2598
# endif
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  2599
# ifdef AF_SNA
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  2600
    if (__INST(domain) == @symbol(sna)) {
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  2601
    }
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  2602
# endif
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  2603
# ifdef AF_NS
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  2604
    if (__INST(domain) == @symbol(xns)) {
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  2605
    }
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  2606
# endif
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  2607
# ifdef AF_RAW
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  2608
    if (__INST(domain) == @symbol(raw)) {
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  2609
    }
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  2610
# endif
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  2611
# ifdef AF_ISO
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  2612
    if (__INST(domain) == @symbol(iso)) {
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  2613
    }
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  2614
# endif
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  2615
# ifdef AF_NETBIOS
530
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  2616
    if (__INST(domain) == @symbol(netbios)) {
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  2617
    }
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  2618
# endif
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  2619
# ifdef AF_IPX
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  2620
    if (__INST(domain) == @symbol(ipx)) {
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  2621
    }
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  2622
# endif
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  2623
# ifdef AF_BRIDGE
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  2624
    if (__INST(domain) == @symbol(bridge)) {
524
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  2625
    }
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  2626
# endif
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  2627
# if defined(AF_CCITT) && (AF_CCITT != AF_X25)
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  2628
    if (__INST(domain) == @symbol(ccitt)) {
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  2629
    }
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  2630
# endif
208
c3eca2cc16dc accept: do not wait for input on non-connected socket.
Stefan Vogel <sv@exept.de>
parents: 207
diff changeset
  2631
c3eca2cc16dc accept: do not wait for input on non-connected socket.
Stefan Vogel <sv@exept.de>
parents: 207
diff changeset
  2632
    /* 
c3eca2cc16dc accept: do not wait for input on non-connected socket.
Stefan Vogel <sv@exept.de>
parents: 207
diff changeset
  2633
     * make it a FILE * 
c3eca2cc16dc accept: do not wait for input on non-connected socket.
Stefan Vogel <sv@exept.de>
parents: 207
diff changeset
  2634
     */
c3eca2cc16dc accept: do not wait for input on non-connected socket.
Stefan Vogel <sv@exept.de>
parents: 207
diff changeset
  2635
    fp = fdopen(newSock, "r+");
c3eca2cc16dc accept: do not wait for input on non-connected socket.
Stefan Vogel <sv@exept.de>
parents: 207
diff changeset
  2636
    if (! fp) {
506
11ef93d12870 support anonymous (OS_specified) ports. (for FTP-protocol)
Claus Gittinger <cg@exept.de>
parents: 486
diff changeset
  2637
	DBGPRINTF(("SOCKET: fdopen call failed\n"));
11ef93d12870 support anonymous (OS_specified) ports. (for FTP-protocol)
Claus Gittinger <cg@exept.de>
parents: 486
diff changeset
  2638
	__INST(lastErrorNumber) = __MKSMALLINT(errno);
11ef93d12870 support anonymous (OS_specified) ports. (for FTP-protocol)
Claus Gittinger <cg@exept.de>
parents: 486
diff changeset
  2639
	close(newSock);
11ef93d12870 support anonymous (OS_specified) ports. (for FTP-protocol)
Claus Gittinger <cg@exept.de>
parents: 486
diff changeset
  2640
	RETURN (false);
208
c3eca2cc16dc accept: do not wait for input on non-connected socket.
Stefan Vogel <sv@exept.de>
parents: 207
diff changeset
  2641
    } else {
444
9ba31a1fba38 always unbuffered on linux
Claus Gittinger <cg@exept.de>
parents: 430
diff changeset
  2642
#ifdef BUGGY_STDIO_LIB
506
11ef93d12870 support anonymous (OS_specified) ports. (for FTP-protocol)
Claus Gittinger <cg@exept.de>
parents: 486
diff changeset
  2643
	setbuf(fp, NULL);
11ef93d12870 support anonymous (OS_specified) ports. (for FTP-protocol)
Claus Gittinger <cg@exept.de>
parents: 486
diff changeset
  2644
	__INST(buffered) = false;
208
c3eca2cc16dc accept: do not wait for input on non-connected socket.
Stefan Vogel <sv@exept.de>
parents: 207
diff changeset
  2645
#endif
506
11ef93d12870 support anonymous (OS_specified) ports. (for FTP-protocol)
Claus Gittinger <cg@exept.de>
parents: 486
diff changeset
  2646
	__INST(filePointer) = __MKOBJ(fp);
11ef93d12870 support anonymous (OS_specified) ports. (for FTP-protocol)
Claus Gittinger <cg@exept.de>
parents: 486
diff changeset
  2647
	__STORESELF(filePointer);
208
c3eca2cc16dc accept: do not wait for input on non-connected socket.
Stefan Vogel <sv@exept.de>
parents: 207
diff changeset
  2648
    }
418
317e55c6c281 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 403
diff changeset
  2649
#endif
208
c3eca2cc16dc accept: do not wait for input on non-connected socket.
Stefan Vogel <sv@exept.de>
parents: 207
diff changeset
  2650
%}.
c3eca2cc16dc accept: do not wait for input on non-connected socket.
Stefan Vogel <sv@exept.de>
parents: 207
diff changeset
  2651
    mode := #readwrite.
c3eca2cc16dc accept: do not wait for input on non-connected socket.
Stefan Vogel <sv@exept.de>
parents: 207
diff changeset
  2652
    Lobby register:self.
c3eca2cc16dc accept: do not wait for input on non-connected socket.
Stefan Vogel <sv@exept.de>
parents: 207
diff changeset
  2653
    binary := false.
c3eca2cc16dc accept: do not wait for input on non-connected socket.
Stefan Vogel <sv@exept.de>
parents: 207
diff changeset
  2654
    port := aSocket port.
c3eca2cc16dc accept: do not wait for input on non-connected socket.
Stefan Vogel <sv@exept.de>
parents: 207
diff changeset
  2655
    ^ true
c3eca2cc16dc accept: do not wait for input on non-connected socket.
Stefan Vogel <sv@exept.de>
parents: 207
diff changeset
  2656
!
c3eca2cc16dc accept: do not wait for input on non-connected socket.
Stefan Vogel <sv@exept.de>
parents: 207
diff changeset
  2657
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  2658
closeFile
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  2659
    "low level close"
99
7d016cc30052 fixed & moved pingWalk from SNMPSession to here;
Claus Gittinger <cg@exept.de>
parents: 98
diff changeset
  2660
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  2661
%{  /* NOCONTEXT */
418
317e55c6c281 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 403
diff changeset
  2662
#ifndef NO_SOCKET
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  2663
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  2664
    OBJ t;
99
7d016cc30052 fixed & moved pingWalk from SNMPSession to here;
Claus Gittinger <cg@exept.de>
parents: 98
diff changeset
  2665
217
fcfbc9f71048 underscore cleanup
Claus Gittinger <cg@exept.de>
parents: 209
diff changeset
  2666
    t = __INST(filePointer);
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  2667
    if (t != nil) {
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  2668
	FILE *fp;
99
7d016cc30052 fixed & moved pingWalk from SNMPSession to here;
Claus Gittinger <cg@exept.de>
parents: 98
diff changeset
  2669
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  2670
	fp = __FILEVal(t);
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  2671
	fflush(fp);
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  2672
	shutdown(fileno(fp), 2);
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  2673
	fclose(fp);
217
fcfbc9f71048 underscore cleanup
Claus Gittinger <cg@exept.de>
parents: 209
diff changeset
  2674
	__INST(filePointer) = nil;
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  2675
    }
418
317e55c6c281 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 403
diff changeset
  2676
#endif
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  2677
%}
99
7d016cc30052 fixed & moved pingWalk from SNMPSession to here;
Claus Gittinger <cg@exept.de>
parents: 98
diff changeset
  2678
!
7d016cc30052 fixed & moved pingWalk from SNMPSession to here;
Claus Gittinger <cg@exept.de>
parents: 98
diff changeset
  2679
116
7789fb1c9fa2 more UD socket fixes (at least client side seems to work now)
Claus Gittinger <cg@exept.de>
parents: 115
diff changeset
  2680
connectTo:hostOrPathName port:portNrOrName
71
claus
parents: 63
diff changeset
  2681
    "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
  2682
     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
  2683
     Other sockets are not yet implemented.
71
claus
parents: 63
diff changeset
  2684
     Return true if ok, false otherwise.
99
7d016cc30052 fixed & moved pingWalk from SNMPSession to here;
Claus Gittinger <cg@exept.de>
parents: 98
diff changeset
  2685
     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
  2686
     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
  2687
     is established. 
7789fb1c9fa2 more UD socket fixes (at least client side seems to work now)
Claus Gittinger <cg@exept.de>
parents: 115
diff changeset
  2688
     See also: #connectTo:port:withTimeout: for a somewhat nicer interface."
28
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  2689
430
12d736316f69 Fix #connectTo:port: Do not call connect() when we get EINPROGRESS
Stefan Vogel <sv@exept.de>
parents: 429
diff changeset
  2690
    |isAsync|
12d736316f69 Fix #connectTo:port: Do not call connect() when we get EINPROGRESS
Stefan Vogel <sv@exept.de>
parents: 429
diff changeset
  2691
28
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  2692
    filePointer isNil ifTrue:[
506
11ef93d12870 support anonymous (OS_specified) ports. (for FTP-protocol)
Claus Gittinger <cg@exept.de>
parents: 486
diff changeset
  2693
	^ self error:'not a valid socket'
28
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  2694
    ].
0
1cf8d1747859 Initial revision
claus
parents:
diff changeset
  2695
%{
418
317e55c6c281 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 403
diff changeset
  2696
#ifndef NO_SOCKET
217
fcfbc9f71048 underscore cleanup
Claus Gittinger <cg@exept.de>
parents: 209
diff changeset
  2697
    OBJ t = __INST(filePointer);
71
claus
parents: 63
diff changeset
  2698
    OBJ myDomain;
115
a9d85df931c4 added Unix domain support
Claus Gittinger <cg@exept.de>
parents: 112
diff changeset
  2699
    union {
525
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  2700
# ifdef AF_INET
506
11ef93d12870 support anonymous (OS_specified) ports. (for FTP-protocol)
Claus Gittinger <cg@exept.de>
parents: 486
diff changeset
  2701
	struct sockaddr_in in ;
525
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  2702
# endif
530
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  2703
# ifdef AF_INET6
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  2704
	struct sockaddr_in6 in6;
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  2705
# endif
524
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  2706
# ifdef AF_UNIX
506
11ef93d12870 support anonymous (OS_specified) ports. (for FTP-protocol)
Claus Gittinger <cg@exept.de>
parents: 486
diff changeset
  2707
	struct sockaddr_un un;
524
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  2708
# endif
525
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  2709
# ifdef AF_APPLETALK
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  2710
	struct sockaddr_at at;
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  2711
# endif
115
a9d85df931c4 added Unix domain support
Claus Gittinger <cg@exept.de>
parents: 112
diff changeset
  2712
    } sa;
28
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  2713
    struct hostent *hp ;
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  2714
    int a, sock ;
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  2715
    long addr;
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  2716
    FILE *fp;
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  2717
    int ret;
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  2718
    int on = 1;
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  2719
    int ok;
115
a9d85df931c4 added Unix domain support
Claus Gittinger <cg@exept.de>
parents: 112
diff changeset
  2720
    int sockaddr_size;
28
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  2721
217
fcfbc9f71048 underscore cleanup
Claus Gittinger <cg@exept.de>
parents: 209
diff changeset
  2722
    if (!__isString(__INST(domain)) && !__isSymbol(__INST(domain))) {
506
11ef93d12870 support anonymous (OS_specified) ports. (for FTP-protocol)
Claus Gittinger <cg@exept.de>
parents: 486
diff changeset
  2723
	DBGPRINTF(("SOCKET: invalid domain arg\n"));
11ef93d12870 support anonymous (OS_specified) ports. (for FTP-protocol)
Claus Gittinger <cg@exept.de>
parents: 486
diff changeset
  2724
	RETURN (false);
28
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  2725
    }
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  2726
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  2727
    ok = 0;
217
fcfbc9f71048 underscore cleanup
Claus Gittinger <cg@exept.de>
parents: 209
diff changeset
  2728
    myDomain = __INST(domain);
115
a9d85df931c4 added Unix domain support
Claus Gittinger <cg@exept.de>
parents: 112
diff changeset
  2729
    bzero((char *) &sa, sizeof(sa)) ;
508
55d1e49c7157 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 507
diff changeset
  2730
28
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  2731
#ifdef AF_INET
71
claus
parents: 63
diff changeset
  2732
    if (myDomain == @symbol(inet)) {
506
11ef93d12870 support anonymous (OS_specified) ports. (for FTP-protocol)
Claus Gittinger <cg@exept.de>
parents: 486
diff changeset
  2733
	char *hostName;
11ef93d12870 support anonymous (OS_specified) ports. (for FTP-protocol)
Claus Gittinger <cg@exept.de>
parents: 486
diff changeset
  2734
525
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  2735
	/*
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  2736
	 * INET addressing: port must be a smallInteger;
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  2737
	 * hostOrPathName the name of the host (dot notation allowed)
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  2738
	 * or a byteArray containing the 4 address bytes.
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  2739
	 */
506
11ef93d12870 support anonymous (OS_specified) ports. (for FTP-protocol)
Claus Gittinger <cg@exept.de>
parents: 486
diff changeset
  2740
	if (! __isSmallInteger(portNrOrName)) {
11ef93d12870 support anonymous (OS_specified) ports. (for FTP-protocol)
Claus Gittinger <cg@exept.de>
parents: 486
diff changeset
  2741
	    DBGPRINTF(("SOCKET: invalid port arg\n"));
11ef93d12870 support anonymous (OS_specified) ports. (for FTP-protocol)
Claus Gittinger <cg@exept.de>
parents: 486
diff changeset
  2742
	    RETURN (false);
11ef93d12870 support anonymous (OS_specified) ports. (for FTP-protocol)
Claus Gittinger <cg@exept.de>
parents: 486
diff changeset
  2743
	}
11ef93d12870 support anonymous (OS_specified) ports. (for FTP-protocol)
Claus Gittinger <cg@exept.de>
parents: 486
diff changeset
  2744
11ef93d12870 support anonymous (OS_specified) ports. (for FTP-protocol)
Claus Gittinger <cg@exept.de>
parents: 486
diff changeset
  2745
	sa.in.sin_family = AF_INET;
11ef93d12870 support anonymous (OS_specified) ports. (for FTP-protocol)
Claus Gittinger <cg@exept.de>
parents: 486
diff changeset
  2746
	sa.in.sin_port = htons((u_short) _intVal(portNrOrName)) ;
11ef93d12870 support anonymous (OS_specified) ports. (for FTP-protocol)
Claus Gittinger <cg@exept.de>
parents: 486
diff changeset
  2747
508
55d1e49c7157 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 507
diff changeset
  2748
	if (__isByteArray(hostOrPathName)) {
55d1e49c7157 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 507
diff changeset
  2749
	    unsigned char *cp;
55d1e49c7157 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 507
diff changeset
  2750
	    int n;
55d1e49c7157 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 507
diff changeset
  2751
55d1e49c7157 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 507
diff changeset
  2752
	    cp = __ByteArrayInstPtr(hostOrPathName)->ba_element;
55d1e49c7157 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 507
diff changeset
  2753
	    n = __byteArraySize(hostOrPathName);
55d1e49c7157 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 507
diff changeset
  2754
	    if (n > 4) n = 4;
55d1e49c7157 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 507
diff changeset
  2755
	    bcopy(cp, &sa.in.sin_addr.s_addr, n);
506
11ef93d12870 support anonymous (OS_specified) ports. (for FTP-protocol)
Claus Gittinger <cg@exept.de>
parents: 486
diff changeset
  2756
	} else {
508
55d1e49c7157 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 507
diff changeset
  2757
	    if (! __isString(hostOrPathName)) {
524
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  2758
		DBGPRINTF(("SOCKET: invalid hostname arg\n"));
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  2759
		RETURN (false);
506
11ef93d12870 support anonymous (OS_specified) ports. (for FTP-protocol)
Claus Gittinger <cg@exept.de>
parents: 486
diff changeset
  2760
	    }
508
55d1e49c7157 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 507
diff changeset
  2761
524
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  2762
	    hostName = (char *) __stringVal(hostOrPathName);
508
55d1e49c7157 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 507
diff changeset
  2763
55d1e49c7157 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 507
diff changeset
  2764
	    if ((addr = inet_addr(hostName)) != -1) {
524
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  2765
		/* 
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  2766
		 * is Internet addr in octet notation 
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  2767
		 */
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  2768
		bcopy(&addr, (char *) &sa.in.sin_addr, sizeof(addr)) ; /* set address */
508
55d1e49c7157 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 507
diff changeset
  2769
	    } else {
524
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  2770
		/* 
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  2771
		 * do we know the host's address? 
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  2772
		 */
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  2773
		if ((hp = gethostbyname(hostName)) == NULL) {
508
55d1e49c7157 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 507
diff changeset
  2774
		    DBGPRINTF(("SOCKET: unknown host:%s\n", hostName));
55d1e49c7157 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 507
diff changeset
  2775
		    RETURN (false);
524
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  2776
		}
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  2777
		bcopy(hp->h_addr, (char *) &sa.in.sin_addr, hp->h_length) ;
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  2778
		sa.in.sin_family = hp->h_addrtype;
508
55d1e49c7157 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 507
diff changeset
  2779
	    }
506
11ef93d12870 support anonymous (OS_specified) ports. (for FTP-protocol)
Claus Gittinger <cg@exept.de>
parents: 486
diff changeset
  2780
	}
508
55d1e49c7157 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 507
diff changeset
  2781
55d1e49c7157 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 507
diff changeset
  2782
	DBGPRINTF(("SOCKET: connect addr: %x port: %d\n", sa.in.sin_addr, sa.in.sin_port));
55d1e49c7157 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 507
diff changeset
  2783
506
11ef93d12870 support anonymous (OS_specified) ports. (for FTP-protocol)
Claus Gittinger <cg@exept.de>
parents: 486
diff changeset
  2784
	sockaddr_size = sizeof(struct sockaddr_in);
11ef93d12870 support anonymous (OS_specified) ports. (for FTP-protocol)
Claus Gittinger <cg@exept.de>
parents: 486
diff changeset
  2785
	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
  2786
    }
525
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  2787
#endif /* AF_INET */
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  2788
530
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  2789
#ifdef AF_INET6
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  2790
    if (myDomain == @symbol(inet6)) {
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  2791
	char *hostName;
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  2792
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  2793
	/*
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  2794
	 * INET6 addressing: port must be a smallInteger;
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  2795
	 * hostOrPathName the name of the host
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  2796
	 * or a byteArray containing the 6 address bytes.
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  2797
	 */
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  2798
	if (! __isSmallInteger(portNrOrName)) {
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  2799
	    DBGPRINTF(("SOCKET: invalid port arg\n"));
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  2800
	    RETURN (false);
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  2801
	}
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  2802
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  2803
	sa.in6.sin6_family = AF_INET6;
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  2804
	sa.in6.sin6_port = htons((u_short) _intVal(portNrOrName)) ;
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  2805
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  2806
	if (__isByteArray(hostOrPathName)) {
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  2807
	    unsigned char *cp;
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  2808
	    int n;
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  2809
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  2810
	    cp = __ByteArrayInstPtr(hostOrPathName)->ba_element;
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  2811
	    n = __byteArraySize(hostOrPathName);
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  2812
	    if (n > 6) n = 6;
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  2813
	    bcopy(cp, &sa.in6.sin6_addr.s6_addr, n);
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  2814
	} else {
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  2815
	    if (! __isString(hostOrPathName)) {
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  2816
		DBGPRINTF(("SOCKET: invalid hostname arg\n"));
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  2817
		RETURN (false);
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  2818
	    }
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  2819
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  2820
	    hostName = (char *) __stringVal(hostOrPathName);
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  2821
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  2822
	    /* 
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  2823
	     * do we know the host's address? 
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  2824
	     */
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  2825
	    if ((hp = gethostbyname(hostName)) == NULL) {
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  2826
		DBGPRINTF(("SOCKET: unknown host:%s\n", hostName));
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  2827
		RETURN (false);
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  2828
	    }
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  2829
	    bcopy(hp->h_addr, (char *) &sa.in.sin_addr, hp->h_length) ;
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  2830
	    sa.in.sin_family = hp->h_addrtype;
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  2831
	}
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  2832
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  2833
	DBGPRINTF(("SOCKET: connect addr: %x.%x.%x.%x.%x.%x port: %d\n", 
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  2834
		sa.in6.sin6_addr.s6_addr[0],
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  2835
		sa.in6.sin6_addr.s6_addr[1],
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  2836
		sa.in6.sin6_addr.s6_addr[2],
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  2837
		sa.in6.sin6_addr.s6_addr[3],
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  2838
		sa.in6.sin6_addr.s6_addr[4],
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  2839
		sa.in6.sin6_addr.s6_addr[5],
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  2840
		sa.in6.sin6_port));
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  2841
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  2842
	sockaddr_size = sizeof(struct sockaddr_in6);
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  2843
	ok = 1;
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  2844
    }
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  2845
#endif /* AF_INET6 */
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  2846
116
7789fb1c9fa2 more UD socket fixes (at least client side seems to work now)
Claus Gittinger <cg@exept.de>
parents: 115
diff changeset
  2847
#ifdef AF_UNIX
7789fb1c9fa2 more UD socket fixes (at least client side seems to work now)
Claus Gittinger <cg@exept.de>
parents: 115
diff changeset
  2848
    if (myDomain == @symbol(unix)) {
506
11ef93d12870 support anonymous (OS_specified) ports. (for FTP-protocol)
Claus Gittinger <cg@exept.de>
parents: 486
diff changeset
  2849
	char *pathName;
11ef93d12870 support anonymous (OS_specified) ports. (for FTP-protocol)
Claus Gittinger <cg@exept.de>
parents: 486
diff changeset
  2850
	int l;
11ef93d12870 support anonymous (OS_specified) ports. (for FTP-protocol)
Claus Gittinger <cg@exept.de>
parents: 486
diff changeset
  2851
525
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  2852
	/*
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  2853
	 * UNIX domain: port is ignored;
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  2854
	 * hostOrPathName is a pathName
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  2855
	 */
506
11ef93d12870 support anonymous (OS_specified) ports. (for FTP-protocol)
Claus Gittinger <cg@exept.de>
parents: 486
diff changeset
  2856
	if (! __isString(hostOrPathName)) {
11ef93d12870 support anonymous (OS_specified) ports. (for FTP-protocol)
Claus Gittinger <cg@exept.de>
parents: 486
diff changeset
  2857
	    DBGPRINTF(("SOCKET: invalid port (pathname) arg\n"));
11ef93d12870 support anonymous (OS_specified) ports. (for FTP-protocol)
Claus Gittinger <cg@exept.de>
parents: 486
diff changeset
  2858
	    RETURN (false);
11ef93d12870 support anonymous (OS_specified) ports. (for FTP-protocol)
Claus Gittinger <cg@exept.de>
parents: 486
diff changeset
  2859
	}
11ef93d12870 support anonymous (OS_specified) ports. (for FTP-protocol)
Claus Gittinger <cg@exept.de>
parents: 486
diff changeset
  2860
	pathName = (char *) __stringVal(hostOrPathName);
11ef93d12870 support anonymous (OS_specified) ports. (for FTP-protocol)
Claus Gittinger <cg@exept.de>
parents: 486
diff changeset
  2861
	l = strlen(pathName);
11ef93d12870 support anonymous (OS_specified) ports. (for FTP-protocol)
Claus Gittinger <cg@exept.de>
parents: 486
diff changeset
  2862
	if ((l + sizeof ( sa.un.sun_family )) > sizeof(struct sockaddr_un)) {
11ef93d12870 support anonymous (OS_specified) ports. (for FTP-protocol)
Claus Gittinger <cg@exept.de>
parents: 486
diff changeset
  2863
	    DBGPRINTF(("SOCKET: pathname too long\n"));
11ef93d12870 support anonymous (OS_specified) ports. (for FTP-protocol)
Claus Gittinger <cg@exept.de>
parents: 486
diff changeset
  2864
	    RETURN (false);
11ef93d12870 support anonymous (OS_specified) ports. (for FTP-protocol)
Claus Gittinger <cg@exept.de>
parents: 486
diff changeset
  2865
	}
11ef93d12870 support anonymous (OS_specified) ports. (for FTP-protocol)
Claus Gittinger <cg@exept.de>
parents: 486
diff changeset
  2866
11ef93d12870 support anonymous (OS_specified) ports. (for FTP-protocol)
Claus Gittinger <cg@exept.de>
parents: 486
diff changeset
  2867
	strcpy(sa.un.sun_path, pathName);
11ef93d12870 support anonymous (OS_specified) ports. (for FTP-protocol)
Claus Gittinger <cg@exept.de>
parents: 486
diff changeset
  2868
	sa.un.sun_family = AF_UNIX;
11ef93d12870 support anonymous (OS_specified) ports. (for FTP-protocol)
Claus Gittinger <cg@exept.de>
parents: 486
diff changeset
  2869
	sockaddr_size = l + sizeof ( sa.un.sun_family );
11ef93d12870 support anonymous (OS_specified) ports. (for FTP-protocol)
Claus Gittinger <cg@exept.de>
parents: 486
diff changeset
  2870
	ok = 1;
28
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  2871
    }
525
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  2872
#endif /* AF_UNIX */
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  2873
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  2874
#ifdef AF_APPLETALK
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  2875
    if (myDomain == @symbol(appletalk)) {
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  2876
	char *hostName;
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  2877
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  2878
	/*
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  2879
	 * APPLETALK addressing: port must be a smallInteger;
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  2880
	 * hostOrPathName the name of the host
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  2881
	 * or a byteArray containing the 3 address bytes.
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  2882
	 */
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  2883
	if (! __isSmallInteger(portNrOrName)) {
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  2884
	    DBGPRINTF(("SOCKET: invalid port arg\n"));
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  2885
	    RETURN (false);
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  2886
	}
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  2887
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  2888
	sa.at.sat_family = AF_APPLETALK;
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  2889
	sa.at.sat_port = __intVal(portNrOrName);
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  2890
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  2891
	if (__isByteArray(hostOrPathName)) {
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  2892
	    unsigned char *cp;
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  2893
	    int n;
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  2894
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  2895
	    cp = __ByteArrayInstPtr(hostOrPathName)->ba_element;
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  2896
	    n = __byteArraySize(hostOrPathName);
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  2897
	    if (n > 3) n = 3;
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  2898
	    bcopy(cp, &sa.at.sat_addr, n);
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  2899
	} else {
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  2900
	    if (! __isString(hostOrPathName)) {
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  2901
		DBGPRINTF(("SOCKET: invalid hostname arg\n"));
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  2902
		RETURN (false);
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  2903
	    }
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  2904
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  2905
	    hostName = (char *) __stringVal(hostOrPathName);
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  2906
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  2907
	    /* 
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  2908
	     * do we know the host's address? 
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  2909
	     */
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  2910
	    if ((hp = gethostbyname(hostName)) == NULL) {
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  2911
		DBGPRINTF(("SOCKET: unknown host:%s\n", hostName));
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  2912
		RETURN (false);
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  2913
	    }
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  2914
	    if (hp->h_addrtype != AF_APPLETALK) {
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  2915
		DBGPRINTF(("SOCKET: host:%s is not an appletalk host\n", hostName));
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  2916
		RETURN (false);
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  2917
	    }
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  2918
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  2919
	    bcopy(hp->h_addr, (char *) &sa.at.sat_addr, hp->h_length) ;
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  2920
	    sa.at.sat_family = hp->h_addrtype;
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  2921
	}
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  2922
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  2923
	DBGPRINTF(("SOCKET: connect addr: %x port: %d\n", sa.in.sin_addr, sa.in.sin_port));
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  2924
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  2925
	sockaddr_size = sizeof(struct sockaddr_at);
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  2926
	ok = 1;
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  2927
    }
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  2928
#endif /* APPLETALK */
5891518d17a3 appletalk support - untested
Claus Gittinger <cg@exept.de>
parents: 524
diff changeset
  2929
28
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  2930
    /*
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  2931
     * XXXX add addressing stuff for other domains here ...
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  2932
     */
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  2933
#ifdef AF_X25
71
claus
parents: 63
diff changeset
  2934
    if (myDomain == @symbol(x25)) {
28
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  2935
    }
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  2936
#endif
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  2937
#ifdef AF_NS
71
claus
parents: 63
diff changeset
  2938
    if (myDomain == @symbol(ns)) {
28
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  2939
    }
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  2940
#endif
524
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  2941
# ifdef AF_DECnet
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  2942
    if (myDomain == @symbol(decnet)) {
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  2943
    }
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  2944
# endif
93
Claus Gittinger <cg@exept.de>
parents: 92
diff changeset
  2945
#ifdef AF_NS 
Claus Gittinger <cg@exept.de>
parents: 92
diff changeset
  2946
    if (myDomain == @symbol(xns)) {
Claus Gittinger <cg@exept.de>
parents: 92
diff changeset
  2947
    }
Claus Gittinger <cg@exept.de>
parents: 92
diff changeset
  2948
#endif
Claus Gittinger <cg@exept.de>
parents: 92
diff changeset
  2949
#ifdef AF_SNA
Claus Gittinger <cg@exept.de>
parents: 92
diff changeset
  2950
    if (myDomain == @symbol(sna)) {
Claus Gittinger <cg@exept.de>
parents: 92
diff changeset
  2951
    }
Claus Gittinger <cg@exept.de>
parents: 92
diff changeset
  2952
#endif
Claus Gittinger <cg@exept.de>
parents: 92
diff changeset
  2953
#ifdef AF_RAW 
Claus Gittinger <cg@exept.de>
parents: 92
diff changeset
  2954
    if (myDomain == @symbol(raw)) {
Claus Gittinger <cg@exept.de>
parents: 92
diff changeset
  2955
    }
Claus Gittinger <cg@exept.de>
parents: 92
diff changeset
  2956
#endif
524
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  2957
# ifdef AF_ISO
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  2958
    if (myDomain == @symbol(iso)) {
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  2959
    }
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  2960
# endif
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  2961
# ifdef AF_NETBIOS
530
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  2962
    if (myDomain == @symbol(netbios)) {
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  2963
    }
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  2964
# endif
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  2965
# ifdef AF_IPX
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  2966
    if (myDomain == @symbol(ipx)) {
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  2967
    }
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  2968
# endif
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  2969
# ifdef AF_BRIDGE
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  2970
    if (myDomain == @symbol(bridge)) {
524
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  2971
    }
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  2972
# endif
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  2973
# if defined(AF_CCITT) && (AF_CCITT != AF_X25)
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  2974
    if (myDomain == @symbol(ccitt)) {
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  2975
    }
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  2976
# endif
28
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  2977
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  2978
    if (! ok) {
506
11ef93d12870 support anonymous (OS_specified) ports. (for FTP-protocol)
Claus Gittinger <cg@exept.de>
parents: 486
diff changeset
  2979
	DBGPRINTF(("SOCKET: unsupported domain\n"));
11ef93d12870 support anonymous (OS_specified) ports. (for FTP-protocol)
Claus Gittinger <cg@exept.de>
parents: 486
diff changeset
  2980
	RETURN (false);
28
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  2981
    }
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  2982
110
7af19ae8693b use new FILE* wrapper macros (based on externalAddress)
Claus Gittinger <cg@exept.de>
parents: 106
diff changeset
  2983
    sock = fileno(__FILEVal(t));
28
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  2984
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  2985
    /* 
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  2986
     * connect 
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  2987
     */
81
claus
parents: 79
diff changeset
  2988
    __BEGIN_INTERRUPTABLE__
28
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  2989
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  2990
    do {
506
11ef93d12870 support anonymous (OS_specified) ports. (for FTP-protocol)
Claus Gittinger <cg@exept.de>
parents: 486
diff changeset
  2991
	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
  2992
    } while ((ret < 0) 
506
11ef93d12870 support anonymous (OS_specified) ports. (for FTP-protocol)
Claus Gittinger <cg@exept.de>
parents: 486
diff changeset
  2993
	     && ((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
  2994
#ifdef EAGAIN
506
11ef93d12870 support anonymous (OS_specified) ports. (for FTP-protocol)
Claus Gittinger <cg@exept.de>
parents: 486
diff changeset
  2995
		 || (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
  2996
#endif
506
11ef93d12870 support anonymous (OS_specified) ports. (for FTP-protocol)
Claus Gittinger <cg@exept.de>
parents: 486
diff changeset
  2997
		));
81
claus
parents: 79
diff changeset
  2998
    __END_INTERRUPTABLE__
28
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  2999
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  3000
    if (ret < 0) { 
430
12d736316f69 Fix #connectTo:port: Do not call connect() when we get EINPROGRESS
Stefan Vogel <sv@exept.de>
parents: 429
diff changeset
  3001
#ifdef EINPROGRESS
506
11ef93d12870 support anonymous (OS_specified) ports. (for FTP-protocol)
Claus Gittinger <cg@exept.de>
parents: 486
diff changeset
  3002
	if (errno == EINPROGRESS || errno == EALREADY) {
11ef93d12870 support anonymous (OS_specified) ports. (for FTP-protocol)
Claus Gittinger <cg@exept.de>
parents: 486
diff changeset
  3003
	    /*
11ef93d12870 support anonymous (OS_specified) ports. (for FTP-protocol)
Claus Gittinger <cg@exept.de>
parents: 486
diff changeset
  3004
	     * We were interrupted. Do not call connect again
11ef93d12870 support anonymous (OS_specified) ports. (for FTP-protocol)
Claus Gittinger <cg@exept.de>
parents: 486
diff changeset
  3005
	     * (we will get an EALREADY.
11ef93d12870 support anonymous (OS_specified) ports. (for FTP-protocol)
Claus Gittinger <cg@exept.de>
parents: 486
diff changeset
  3006
	     * Do a select on write instead.
11ef93d12870 support anonymous (OS_specified) ports. (for FTP-protocol)
Claus Gittinger <cg@exept.de>
parents: 486
diff changeset
  3007
	     */
11ef93d12870 support anonymous (OS_specified) ports. (for FTP-protocol)
Claus Gittinger <cg@exept.de>
parents: 486
diff changeset
  3008
11ef93d12870 support anonymous (OS_specified) ports. (for FTP-protocol)
Claus Gittinger <cg@exept.de>
parents: 486
diff changeset
  3009
	    isAsync = true;
11ef93d12870 support anonymous (OS_specified) ports. (for FTP-protocol)
Claus Gittinger <cg@exept.de>
parents: 486
diff changeset
  3010
	} else
430
12d736316f69 Fix #connectTo:port: Do not call connect() when we get EINPROGRESS
Stefan Vogel <sv@exept.de>
parents: 429
diff changeset
  3011
#endif
506
11ef93d12870 support anonymous (OS_specified) ports. (for FTP-protocol)
Claus Gittinger <cg@exept.de>
parents: 486
diff changeset
  3012
	{
11ef93d12870 support anonymous (OS_specified) ports. (for FTP-protocol)
Claus Gittinger <cg@exept.de>
parents: 486
diff changeset
  3013
	    DBGPRINTF(("SOCKET: connect failed errno=%d\n", errno));
117
03cefad7e40b UD socket example & interruptable bind
Claus Gittinger <cg@exept.de>
parents: 116
diff changeset
  3014
#ifdef DUMP_ADDRESS
506
11ef93d12870 support anonymous (OS_specified) ports. (for FTP-protocol)
Claus Gittinger <cg@exept.de>
parents: 486
diff changeset
  3015
	    {
11ef93d12870 support anonymous (OS_specified) ports. (for FTP-protocol)
Claus Gittinger <cg@exept.de>
parents: 486
diff changeset
  3016
		char *cp = (char *)(&sa);
11ef93d12870 support anonymous (OS_specified) ports. (for FTP-protocol)
Claus Gittinger <cg@exept.de>
parents: 486
diff changeset
  3017
		int i;
11ef93d12870 support anonymous (OS_specified) ports. (for FTP-protocol)
Claus Gittinger <cg@exept.de>
parents: 486
diff changeset
  3018
11ef93d12870 support anonymous (OS_specified) ports. (for FTP-protocol)
Claus Gittinger <cg@exept.de>
parents: 486
diff changeset
  3019
		printf("address data:\n");
11ef93d12870 support anonymous (OS_specified) ports. (for FTP-protocol)
Claus Gittinger <cg@exept.de>
parents: 486
diff changeset
  3020
		for (i=0; i<sockaddr_size; i++) {
11ef93d12870 support anonymous (OS_specified) ports. (for FTP-protocol)
Claus Gittinger <cg@exept.de>
parents: 486
diff changeset
  3021
		    printf(" %02x\n", *cp++);
11ef93d12870 support anonymous (OS_specified) ports. (for FTP-protocol)
Claus Gittinger <cg@exept.de>
parents: 486
diff changeset
  3022
		}
11ef93d12870 support anonymous (OS_specified) ports. (for FTP-protocol)
Claus Gittinger <cg@exept.de>
parents: 486
diff changeset
  3023
	    }
117
03cefad7e40b UD socket example & interruptable bind
Claus Gittinger <cg@exept.de>
parents: 116
diff changeset
  3024
#endif
506
11ef93d12870 support anonymous (OS_specified) ports. (for FTP-protocol)
Claus Gittinger <cg@exept.de>
parents: 486
diff changeset
  3025
	    __INST(lastErrorNumber) = __MKSMALLINT(errno);
11ef93d12870 support anonymous (OS_specified) ports. (for FTP-protocol)
Claus Gittinger <cg@exept.de>
parents: 486
diff changeset
  3026
	    RETURN (false);
11ef93d12870 support anonymous (OS_specified) ports. (for FTP-protocol)
Claus Gittinger <cg@exept.de>
parents: 486
diff changeset
  3027
	}
28
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  3028
    }
430
12d736316f69 Fix #connectTo:port: Do not call connect() when we get EINPROGRESS
Stefan Vogel <sv@exept.de>
parents: 429
diff changeset
  3029
#else /* NO_SOCKET */
418
317e55c6c281 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 403
diff changeset
  3030
    RETURN (false);
430
12d736316f69 Fix #connectTo:port: Do not call connect() when we get EINPROGRESS
Stefan Vogel <sv@exept.de>
parents: 429
diff changeset
  3031
#endif /* NO_SOCKET */
42
506596f9a1a8 *** empty log message ***
claus
parents: 38
diff changeset
  3032
%}.
430
12d736316f69 Fix #connectTo:port: Do not call connect() when we get EINPROGRESS
Stefan Vogel <sv@exept.de>
parents: 429
diff changeset
  3033
    isAsync == true ifTrue:[
506
11ef93d12870 support anonymous (OS_specified) ports. (for FTP-protocol)
Claus Gittinger <cg@exept.de>
parents: 486
diff changeset
  3034
	self writeWait.
430
12d736316f69 Fix #connectTo:port: Do not call connect() when we get EINPROGRESS
Stefan Vogel <sv@exept.de>
parents: 429
diff changeset
  3035
    ].
71
claus
parents: 63
diff changeset
  3036
    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
  3037
    peerName := hostOrPathName.
28
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  3038
    ^ true
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  3039
!
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  3040
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3041
connectTo:hostOrPathName port:portNrOrName withTimeout:millis
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3042
    "connect to port, portNrOrName on host, hostName.
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3043
     Or path (UNIX socket), where portNrOrName is ignored.
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3044
     Return true if ok, false otherwise.
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3045
     Hostname must be a string, portNrOrName an integer port number (in inet domain).
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3046
     If a non-nil timeout is given, stop trying after that time and return false as well."
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3047
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3048
    |stopSignal stopMe connection|
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3049
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3050
    millis isNil ifTrue:[
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3051
	^ self connectTo:hostOrPathName port:portNrOrName
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3052
    ].
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3053
    stopSignal := Signal new.
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3054
    stopMe := [stopSignal raise].
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3055
    stopSignal handle:[:ex |
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3056
"/        'timeout on connect' infoPrintNL.
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3057
	^ false
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3058
    ] do:[
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3059
	Processor addTimedBlock:stopMe afterMilliseconds:millis.
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3060
	connection := self connectTo:hostOrPathName port:portNrOrName.
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3061
	Processor removeTimedBlock:stopMe.
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3062
    ].
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3063
    ^ connection
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3064
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3065
    "Created: 31.10.1995 / 18:52:49 / cg"
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3066
!
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3067
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3068
listenFor:aNumber
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3069
    "same as listenWithBacklog: - for ST-80 compatibility"
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3070
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3071
    ^ self listenWithBacklog:aNumber
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3072
!
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3073
28
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  3074
listenWithBacklog:aNumber
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  3075
    "start listening; return true if ok, false on error"
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  3076
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  3077
    filePointer isNil ifTrue:[
42
506596f9a1a8 *** empty log message ***
claus
parents: 38
diff changeset
  3078
	^ self error:'not a valid socket'
28
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  3079
    ].
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  3080
%{
418
317e55c6c281 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 403
diff changeset
  3081
#ifndef NO_SOCKET
217
fcfbc9f71048 underscore cleanup
Claus Gittinger <cg@exept.de>
parents: 209
diff changeset
  3082
    OBJ fp = __INST(filePointer);
28
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  3083
    int sock;
6
claus
parents: 4
diff changeset
  3084
    int ret;
0
1cf8d1747859 Initial revision
claus
parents:
diff changeset
  3085
58
bd6753bf0401 *** empty log message ***
claus
parents: 51
diff changeset
  3086
    if (! __isSmallInteger(aNumber)) {
98
5e787ba2cb31 use common byteOrder when representing IP numbers as byteArrays (always network-first)
Claus Gittinger <cg@exept.de>
parents: 96
diff changeset
  3087
	DBGPRINTF(("SOCKET: invalid arg\n"));
42
506596f9a1a8 *** empty log message ***
claus
parents: 38
diff changeset
  3088
	RETURN (false);
28
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  3089
    }
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  3090
110
7af19ae8693b use new FILE* wrapper macros (based on externalAddress)
Claus Gittinger <cg@exept.de>
parents: 106
diff changeset
  3091
    sock = fileno(__FILEVal(fp));
28
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  3092
81
claus
parents: 79
diff changeset
  3093
    __BEGIN_INTERRUPTABLE__
28
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  3094
    do {
42
506596f9a1a8 *** empty log message ***
claus
parents: 38
diff changeset
  3095
	ret = listen(sock, _intVal(aNumber));
28
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  3096
    } while ((ret < 0) && (errno == EINTR));
81
claus
parents: 79
diff changeset
  3097
    __END_INTERRUPTABLE__
28
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  3098
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  3099
    if (ret < 0) {
98
5e787ba2cb31 use common byteOrder when representing IP numbers as byteArrays (always network-first)
Claus Gittinger <cg@exept.de>
parents: 96
diff changeset
  3100
	DBGPRINTF(("SOCKET: listen call failed errno=%d\n", errno));
217
fcfbc9f71048 underscore cleanup
Claus Gittinger <cg@exept.de>
parents: 209
diff changeset
  3101
	__INST(lastErrorNumber) = __MKSMALLINT(errno);
42
506596f9a1a8 *** empty log message ***
claus
parents: 38
diff changeset
  3102
	RETURN (false);
28
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  3103
    }
418
317e55c6c281 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 403
diff changeset
  3104
#else
317e55c6c281 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 403
diff changeset
  3105
    RETURN (false);
317e55c6c281 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 403
diff changeset
  3106
#endif
42
506596f9a1a8 *** empty log message ***
claus
parents: 38
diff changeset
  3107
%}.
28
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  3108
    ^ true
206
77166a6b3ee6 For ST80 style socket creation: register socket in Lobby.
Stefan Vogel <sv@exept.de>
parents: 203
diff changeset
  3109
!
77166a6b3ee6 For ST80 style socket creation: register socket in Lobby.
Stefan Vogel <sv@exept.de>
parents: 203
diff changeset
  3110
77166a6b3ee6 For ST80 style socket creation: register socket in Lobby.
Stefan Vogel <sv@exept.de>
parents: 203
diff changeset
  3111
shutDown 
77166a6b3ee6 For ST80 style socket creation: register socket in Lobby.
Stefan Vogel <sv@exept.de>
parents: 203
diff changeset
  3112
    "shutDown without flushing "
77166a6b3ee6 For ST80 style socket creation: register socket in Lobby.
Stefan Vogel <sv@exept.de>
parents: 203
diff changeset
  3113
429
197dee9342a3 when shutting down, also tell the Lobby
Claus Gittinger <cg@exept.de>
parents: 425
diff changeset
  3114
    filePointer isNil ifTrue:[^ self].
197dee9342a3 when shutting down, also tell the Lobby
Claus Gittinger <cg@exept.de>
parents: 425
diff changeset
  3115
    Lobby unregister:self.
197dee9342a3 when shutting down, also tell the Lobby
Claus Gittinger <cg@exept.de>
parents: 425
diff changeset
  3116
197dee9342a3 when shutting down, also tell the Lobby
Claus Gittinger <cg@exept.de>
parents: 425
diff changeset
  3117
%{
418
317e55c6c281 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 403
diff changeset
  3118
#ifndef NO_SOCKET
206
77166a6b3ee6 For ST80 style socket creation: register socket in Lobby.
Stefan Vogel <sv@exept.de>
parents: 203
diff changeset
  3119
77166a6b3ee6 For ST80 style socket creation: register socket in Lobby.
Stefan Vogel <sv@exept.de>
parents: 203
diff changeset
  3120
    OBJ fp;
77166a6b3ee6 For ST80 style socket creation: register socket in Lobby.
Stefan Vogel <sv@exept.de>
parents: 203
diff changeset
  3121
217
fcfbc9f71048 underscore cleanup
Claus Gittinger <cg@exept.de>
parents: 209
diff changeset
  3122
    fp = __INST(filePointer);
206
77166a6b3ee6 For ST80 style socket creation: register socket in Lobby.
Stefan Vogel <sv@exept.de>
parents: 203
diff changeset
  3123
    if (fp != nil) {
506
11ef93d12870 support anonymous (OS_specified) ports. (for FTP-protocol)
Claus Gittinger <cg@exept.de>
parents: 486
diff changeset
  3124
	FILE *f;
11ef93d12870 support anonymous (OS_specified) ports. (for FTP-protocol)
Claus Gittinger <cg@exept.de>
parents: 486
diff changeset
  3125
	int fd;
11ef93d12870 support anonymous (OS_specified) ports. (for FTP-protocol)
Claus Gittinger <cg@exept.de>
parents: 486
diff changeset
  3126
11ef93d12870 support anonymous (OS_specified) ports. (for FTP-protocol)
Claus Gittinger <cg@exept.de>
parents: 486
diff changeset
  3127
	__INST(filePointer) = nil;
11ef93d12870 support anonymous (OS_specified) ports. (for FTP-protocol)
Claus Gittinger <cg@exept.de>
parents: 486
diff changeset
  3128
	f = __FILEVal(fp);
11ef93d12870 support anonymous (OS_specified) ports. (for FTP-protocol)
Claus Gittinger <cg@exept.de>
parents: 486
diff changeset
  3129
	fd = fileno(f);
11ef93d12870 support anonymous (OS_specified) ports. (for FTP-protocol)
Claus Gittinger <cg@exept.de>
parents: 486
diff changeset
  3130
	__BEGIN_INTERRUPTABLE__
11ef93d12870 support anonymous (OS_specified) ports. (for FTP-protocol)
Claus Gittinger <cg@exept.de>
parents: 486
diff changeset
  3131
	shutdown(fd, 2);
11ef93d12870 support anonymous (OS_specified) ports. (for FTP-protocol)
Claus Gittinger <cg@exept.de>
parents: 486
diff changeset
  3132
	close(fd);
11ef93d12870 support anonymous (OS_specified) ports. (for FTP-protocol)
Claus Gittinger <cg@exept.de>
parents: 486
diff changeset
  3133
	__END_INTERRUPTABLE__
206
77166a6b3ee6 For ST80 style socket creation: register socket in Lobby.
Stefan Vogel <sv@exept.de>
parents: 203
diff changeset
  3134
    }
77166a6b3ee6 For ST80 style socket creation: register socket in Lobby.
Stefan Vogel <sv@exept.de>
parents: 203
diff changeset
  3135
#endif
77166a6b3ee6 For ST80 style socket creation: register socket in Lobby.
Stefan Vogel <sv@exept.de>
parents: 203
diff changeset
  3136
%}
25
996051271ce9 *** empty log message ***
claus
parents: 21
diff changeset
  3137
! !
996051271ce9 *** empty log message ***
claus
parents: 21
diff changeset
  3138
996051271ce9 *** empty log message ***
claus
parents: 21
diff changeset
  3139
!Socket methodsFor:'queries'!
996051271ce9 *** empty log message ***
claus
parents: 21
diff changeset
  3140
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3141
domain
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3142
    "return the sockets addressing domain (i.e. #inet, #unix, #x25, #appletalk)"
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3143
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3144
    ^ domain
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3145
!
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3146
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3147
getName
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3148
    "return the name; here, we return the ports name"
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3149
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3150
    ^ port printString
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3151
!
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3152
102
5dc264007513 added getPeer for ST-80 compatibility
Claus Gittinger <cg@exept.de>
parents: 99
diff changeset
  3153
getPeer
5dc264007513 added getPeer for ST-80 compatibility
Claus Gittinger <cg@exept.de>
parents: 99
diff changeset
  3154
    "ST-80 compatibility: return an IPSocketAddress instance representing
5dc264007513 added getPeer for ST-80 compatibility
Claus Gittinger <cg@exept.de>
parents: 99
diff changeset
  3155
     my hostname/port combination.
155
fcf846c707b7 interest is written with one 'r' (shame on me)
Claus Gittinger <cg@exept.de>
parents: 126
diff changeset
  3156
     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
  3157
116
7789fb1c9fa2 more UD socket fixes (at least client side seems to work now)
Claus Gittinger <cg@exept.de>
parents: 115
diff changeset
  3158
    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
  3159
	^ 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
  3160
    ].
102
5dc264007513 added getPeer for ST-80 compatibility
Claus Gittinger <cg@exept.de>
parents: 99
diff changeset
  3161
    ^ IPSocketAddress hostAddress:(self class ipAddressOfHost:peerName) port:port
5dc264007513 added getPeer for ST-80 compatibility
Claus Gittinger <cg@exept.de>
parents: 99
diff changeset
  3162
5dc264007513 added getPeer for ST-80 compatibility
Claus Gittinger <cg@exept.de>
parents: 99
diff changeset
  3163
    "Created: 2.11.1995 / 11:22:39 / cg"
5dc264007513 added getPeer for ST-80 compatibility
Claus Gittinger <cg@exept.de>
parents: 99
diff changeset
  3164
!
5dc264007513 added getPeer for ST-80 compatibility
Claus Gittinger <cg@exept.de>
parents: 99
diff changeset
  3165
25
996051271ce9 *** empty log message ***
claus
parents: 21
diff changeset
  3166
getPeerName
996051271ce9 *** empty log message ***
claus
parents: 21
diff changeset
  3167
    "return the peer name; thats the hostname (or dotted name) of the
996051271ce9 *** empty log message ***
claus
parents: 21
diff changeset
  3168
     partners host after an accept."
996051271ce9 *** empty log message ***
claus
parents: 21
diff changeset
  3169
996051271ce9 *** empty log message ***
claus
parents: 21
diff changeset
  3170
    ^ peerName
28
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  3171
!
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  3172
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3173
isActive
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3174
    "return true, if the receiver has a connection"
81
claus
parents: 79
diff changeset
  3175
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3176
    ^ filePointer notNil
81
claus
parents: 79
diff changeset
  3177
!
claus
parents: 79
diff changeset
  3178
71
claus
parents: 63
diff changeset
  3179
port
claus
parents: 63
diff changeset
  3180
    "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
  3181
506
11ef93d12870 support anonymous (OS_specified) ports. (for FTP-protocol)
Claus Gittinger <cg@exept.de>
parents: 486
diff changeset
  3182
    |p|
11ef93d12870 support anonymous (OS_specified) ports. (for FTP-protocol)
Claus Gittinger <cg@exept.de>
parents: 486
diff changeset
  3183
11ef93d12870 support anonymous (OS_specified) ports. (for FTP-protocol)
Claus Gittinger <cg@exept.de>
parents: 486
diff changeset
  3184
    port == 0 ifTrue:[
524
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  3185
	p := self getPort.
506
11ef93d12870 support anonymous (OS_specified) ports. (for FTP-protocol)
Claus Gittinger <cg@exept.de>
parents: 486
diff changeset
  3186
	p notNil ifTrue:[
11ef93d12870 support anonymous (OS_specified) ports. (for FTP-protocol)
Claus Gittinger <cg@exept.de>
parents: 486
diff changeset
  3187
	    port := p
11ef93d12870 support anonymous (OS_specified) ports. (for FTP-protocol)
Claus Gittinger <cg@exept.de>
parents: 486
diff changeset
  3188
	]
11ef93d12870 support anonymous (OS_specified) ports. (for FTP-protocol)
Claus Gittinger <cg@exept.de>
parents: 486
diff changeset
  3189
    ].
71
claus
parents: 63
diff changeset
  3190
    ^ port
28
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  3191
!
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  3192
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  3193
type
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  3194
    "return the sockets connection type (i.e. #datagram, #stream etc)"
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  3195
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  3196
    ^ socketType
81
claus
parents: 79
diff changeset
  3197
! !
claus
parents: 79
diff changeset
  3198
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3199
!Socket methodsFor:'socket setup'!
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3200
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3201
domain:domainArg type:typeArg
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3202
    "set up socket with domain and type.
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3203
     This is a low level entry; no binding, listening or connect
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3204
     is done. Both arguments must be symbols from one of
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3205
     #inet,#unix, #appletalk, #x25 .. and #stream, #datagram, #raw resp."
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3206
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3207
    ^ self domain:domainArg type:typeArg protocol:0
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3208
!
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3209
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3210
domain:domainArg type:typeArg protocol:protocolNumber
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3211
    "set up socket with domain, type and protocol number.
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3212
     This is a low level entry; no binding, listening or connect
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3213
     is done. Both arguments must be symbols from one of
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3214
     #inet,#unix, #appletalk, #x25 .. and #stream, #datagram, #raw resp."
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3215
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3216
    |errorNr|
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3217
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3218
    filePointer notNil ifTrue:[
425
eb8198e9f1b0 comment
Claus Gittinger <cg@exept.de>
parents: 421
diff changeset
  3219
	^ self error:'already created'
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3220
    ].
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3221
%{
418
317e55c6c281 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 403
diff changeset
  3222
#ifndef NO_SOCKET
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3223
    FILE *fp;
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3224
    int dom, typ, pf, proto = 0, sock;
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3225
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3226
    if (! __isSymbol(domainArg)) { 
425
eb8198e9f1b0 comment
Claus Gittinger <cg@exept.de>
parents: 421
diff changeset
  3227
	DBGPRINTF(("SOCKET: bad domain\n"));
eb8198e9f1b0 comment
Claus Gittinger <cg@exept.de>
parents: 421
diff changeset
  3228
	RETURN ( nil );
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3229
    }
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3230
    if (! __isSymbol(typeArg)) { 
425
eb8198e9f1b0 comment
Claus Gittinger <cg@exept.de>
parents: 421
diff changeset
  3231
	DBGPRINTF(("SOCKET: bad type\n"));
eb8198e9f1b0 comment
Claus Gittinger <cg@exept.de>
parents: 421
diff changeset
  3232
	RETURN ( nil );
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3233
    }
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3234
    if (protocolNumber != nil) {
425
eb8198e9f1b0 comment
Claus Gittinger <cg@exept.de>
parents: 421
diff changeset
  3235
	if (!__isSmallInteger(protocolNumber)) {
eb8198e9f1b0 comment
Claus Gittinger <cg@exept.de>
parents: 421
diff changeset
  3236
	    DBGPRINTF(("SOCKET: bad protocol\n"));
eb8198e9f1b0 comment
Claus Gittinger <cg@exept.de>
parents: 421
diff changeset
  3237
	    RETURN ( nil );
eb8198e9f1b0 comment
Claus Gittinger <cg@exept.de>
parents: 421
diff changeset
  3238
	}
eb8198e9f1b0 comment
Claus Gittinger <cg@exept.de>
parents: 421
diff changeset
  3239
	proto = __intVal(protocolNumber);
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3240
    }
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3241
        
81
claus
parents: 79
diff changeset
  3242
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3243
    /*
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3244
     * get address and protocol-family
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3245
     */
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3246
#ifdef AF_UNIX
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3247
    if (domainArg == @symbol(unix)) {
425
eb8198e9f1b0 comment
Claus Gittinger <cg@exept.de>
parents: 421
diff changeset
  3248
	dom = AF_UNIX;
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3249
    } else
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3250
#endif
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3251
#ifdef AF_INET
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3252
    if (domainArg == @symbol(inet)) {
425
eb8198e9f1b0 comment
Claus Gittinger <cg@exept.de>
parents: 421
diff changeset
  3253
	dom = AF_INET;
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3254
    } else
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3255
#endif
530
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  3256
#ifdef AF_INET6
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  3257
    if (domainArg == @symbol(inet6)) {
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  3258
	dom = AF_INET6;
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  3259
    } else
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  3260
#endif
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3261
#ifdef AF_DECnet
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3262
    if (domainArg == @symbol(DECnet)) {
425
eb8198e9f1b0 comment
Claus Gittinger <cg@exept.de>
parents: 421
diff changeset
  3263
	dom = AF_DECnet;
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3264
    } else
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3265
#endif
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3266
#ifdef AF_APPLETALK
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3267
    if (domainArg == @symbol(appletalk)) {
425
eb8198e9f1b0 comment
Claus Gittinger <cg@exept.de>
parents: 421
diff changeset
  3268
	dom = AF_APPLETALK;
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3269
    } else
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3270
#endif
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3271
#ifdef AF_X25
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3272
    if (domainArg == @symbol(x25)) {
425
eb8198e9f1b0 comment
Claus Gittinger <cg@exept.de>
parents: 421
diff changeset
  3273
	dom = AF_X25;
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3274
    } else
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3275
#endif
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3276
#ifdef AF_NS
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3277
    if (domainArg == @symbol(xns)) {
425
eb8198e9f1b0 comment
Claus Gittinger <cg@exept.de>
parents: 421
diff changeset
  3278
	dom = AF_NS;
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3279
    } else
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3280
#endif
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3281
#ifdef AF_SNA
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3282
    if (domainArg == @symbol(sna)) {
425
eb8198e9f1b0 comment
Claus Gittinger <cg@exept.de>
parents: 421
diff changeset
  3283
	dom = AF_SNA;
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3284
    } else
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3285
#endif
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3286
#ifdef AF_RAW
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3287
    if (domainArg == @symbol(raw)) {
425
eb8198e9f1b0 comment
Claus Gittinger <cg@exept.de>
parents: 421
diff changeset
  3288
	dom = AF_RAW;
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3289
    } else
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3290
#endif
524
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  3291
# ifdef AF_ISO
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  3292
    if (domainArg == @symbol(iso)) {
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  3293
	dom = AF_ISO;
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  3294
    }
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  3295
# endif
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  3296
# ifdef AF_NETBIOS
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  3297
    if (domainArg == @symbol(netbios)) {
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  3298
	dom = AF_NETBIOS;
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  3299
    }
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  3300
# endif
530
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  3301
# ifdef AF_IPX
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  3302
    if (domainArg == @symbol(ipx)) {
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  3303
	dom = AF_IPX;
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  3304
    }
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  3305
# endif
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  3306
# ifdef AF_BRIDGE
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  3307
    if (domainArg == @symbol(bridge)) {
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  3308
	dom = AF_BRIDGE;
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  3309
    }
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  3310
# endif
524
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  3311
# if defined(AF_CCITT) && (AF_CCITT != AF_X25)
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  3312
    if (domainArg == @symbol(ccitt)) {
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  3313
	dom = AF_CCITT;
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  3314
    }
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  3315
# endif
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3316
    {
524
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  3317
	DBGPRINTF(("SOCKET: unknown domain <%s>\n", __stringVal(domainArg)));
425
eb8198e9f1b0 comment
Claus Gittinger <cg@exept.de>
parents: 421
diff changeset
  3318
	RETURN ( nil );
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3319
    }
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3320
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3321
#ifdef SOCK_STREAM
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3322
    if (typeArg == @symbol(stream)) {
425
eb8198e9f1b0 comment
Claus Gittinger <cg@exept.de>
parents: 421
diff changeset
  3323
	typ = SOCK_STREAM;
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3324
    } else
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3325
#endif
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3326
#ifdef SOCK_DGRAM
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3327
    if (typeArg == @symbol(datagram)) {
425
eb8198e9f1b0 comment
Claus Gittinger <cg@exept.de>
parents: 421
diff changeset
  3328
	typ = SOCK_DGRAM;
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3329
    } else 
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3330
#endif
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3331
#ifdef SOCK_RAW
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3332
    if (typeArg == @symbol(raw))
425
eb8198e9f1b0 comment
Claus Gittinger <cg@exept.de>
parents: 421
diff changeset
  3333
	typ = SOCK_RAW;
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3334
    else
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3335
#endif
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3336
#ifdef SOCK_SEQPACKET
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3337
    if (typeArg == @symbol(seqPacket))
425
eb8198e9f1b0 comment
Claus Gittinger <cg@exept.de>
parents: 421
diff changeset
  3338
	typ = SOCK_SEQPACKET;
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3339
    else
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3340
#endif
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3341
    {
524
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  3342
	DBGPRINTF(("SOCKET: bad type <%s>\n", __stringVal(typeArg)));
425
eb8198e9f1b0 comment
Claus Gittinger <cg@exept.de>
parents: 421
diff changeset
  3343
	RETURN ( nil );
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3344
    }
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3345
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3346
    __BEGIN_INTERRUPTABLE__
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3347
    do {
425
eb8198e9f1b0 comment
Claus Gittinger <cg@exept.de>
parents: 421
diff changeset
  3348
	DBGPRINTF(("SOCKET: opening socket domain=%d type=%d proto=%d\n", dom, typ, proto));
eb8198e9f1b0 comment
Claus Gittinger <cg@exept.de>
parents: 421
diff changeset
  3349
	sock = socket(dom, typ, proto);
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3350
#if defined(EPROTONOSUPPORT) /* for SGI */
425
eb8198e9f1b0 comment
Claus Gittinger <cg@exept.de>
parents: 421
diff changeset
  3351
	if ((proto != 0) && (sock < 0) && (errno == EPROTONOSUPPORT)) {
eb8198e9f1b0 comment
Claus Gittinger <cg@exept.de>
parents: 421
diff changeset
  3352
	    DBGPRINTF(("SOCKET: retry with UNSPEC protocol\n"));
eb8198e9f1b0 comment
Claus Gittinger <cg@exept.de>
parents: 421
diff changeset
  3353
	    proto = 0;
eb8198e9f1b0 comment
Claus Gittinger <cg@exept.de>
parents: 421
diff changeset
  3354
	    sock = socket(dom, typ, 0);
eb8198e9f1b0 comment
Claus Gittinger <cg@exept.de>
parents: 421
diff changeset
  3355
	}
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3356
#endif
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3357
    } while ((sock < 0) && (errno == EINTR));
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3358
    __END_INTERRUPTABLE__
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3359
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3360
    if (sock < 0) {
425
eb8198e9f1b0 comment
Claus Gittinger <cg@exept.de>
parents: 421
diff changeset
  3361
	DBGPRINTF(("SOCKET: socket(dom=%d typ=%d proto=%d) call failed errno=%d\n", dom, typ, proto, errno));
eb8198e9f1b0 comment
Claus Gittinger <cg@exept.de>
parents: 421
diff changeset
  3362
	__INST(lastErrorNumber) = __MKSMALLINT(errno);
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3363
    } else {
425
eb8198e9f1b0 comment
Claus Gittinger <cg@exept.de>
parents: 421
diff changeset
  3364
	/* 
eb8198e9f1b0 comment
Claus Gittinger <cg@exept.de>
parents: 421
diff changeset
  3365
	 * make it a FILE * 
eb8198e9f1b0 comment
Claus Gittinger <cg@exept.de>
parents: 421
diff changeset
  3366
	 */
eb8198e9f1b0 comment
Claus Gittinger <cg@exept.de>
parents: 421
diff changeset
  3367
	fp = fdopen(sock, "r+");
eb8198e9f1b0 comment
Claus Gittinger <cg@exept.de>
parents: 421
diff changeset
  3368
	if (! fp) {
eb8198e9f1b0 comment
Claus Gittinger <cg@exept.de>
parents: 421
diff changeset
  3369
	    DBGPRINTF(("SOCKET: fdopen call failed\n"));
eb8198e9f1b0 comment
Claus Gittinger <cg@exept.de>
parents: 421
diff changeset
  3370
	    __INST(lastErrorNumber) = __MKSMALLINT(errno);
eb8198e9f1b0 comment
Claus Gittinger <cg@exept.de>
parents: 421
diff changeset
  3371
	    __BEGIN_INTERRUPTABLE__
eb8198e9f1b0 comment
Claus Gittinger <cg@exept.de>
parents: 421
diff changeset
  3372
	    close(sock);
eb8198e9f1b0 comment
Claus Gittinger <cg@exept.de>
parents: 421
diff changeset
  3373
	    __END_INTERRUPTABLE__
eb8198e9f1b0 comment
Claus Gittinger <cg@exept.de>
parents: 421
diff changeset
  3374
	} else {
eb8198e9f1b0 comment
Claus Gittinger <cg@exept.de>
parents: 421
diff changeset
  3375
	    __INST(filePointer) = __MKOBJ(fp);
eb8198e9f1b0 comment
Claus Gittinger <cg@exept.de>
parents: 421
diff changeset
  3376
	    __STORESELF(filePointer);
eb8198e9f1b0 comment
Claus Gittinger <cg@exept.de>
parents: 421
diff changeset
  3377
	}
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3378
    }
418
317e55c6c281 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 403
diff changeset
  3379
#endif
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3380
%}.
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3381
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3382
    "all ok?"
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3383
    filePointer notNil ifTrue:[
425
eb8198e9f1b0 comment
Claus Gittinger <cg@exept.de>
parents: 421
diff changeset
  3384
	domain := domainArg.
eb8198e9f1b0 comment
Claus Gittinger <cg@exept.de>
parents: 421
diff changeset
  3385
	socketType := typeArg.
eb8198e9f1b0 comment
Claus Gittinger <cg@exept.de>
parents: 421
diff changeset
  3386
	Lobby register:self.
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3387
    ] ifFalse:[
425
eb8198e9f1b0 comment
Claus Gittinger <cg@exept.de>
parents: 421
diff changeset
  3388
	^ nil
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3389
    ].
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3390
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3391
    "
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3392
     Socket new domain:#inet type:#stream
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3393
     Socket new domain:#unix type:#stream
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3394
    "
81
claus
parents: 79
diff changeset
  3395
!
claus
parents: 79
diff changeset
  3396
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3397
for:hostName port:portNr
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3398
    "setup for a TCP socket (i.e. inet domain, stream type) 
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3399
     If hostname is nil, a server port is opened,
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3400
     otherwise a client port to the server on host.
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3401
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3402
     HISTORIC LEFTOVER:
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3403
     This method will vanish, as soon as the low level
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3404
     connect/bind works,"
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3405
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3406
    self obsoleteMethodWarning.
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3407
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3408
    filePointer notNil ifTrue:[
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3409
	^ self error:'already created'
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3410
    ].
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3411
    (portNr isMemberOf:SmallInteger) ifFalse:[
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3412
	^ self error:'invalid portNr'
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3413
    ].
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3414
%{
418
317e55c6c281 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 403
diff changeset
  3415
#ifndef NO_SOCKET
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3416
    struct sockaddr_in sa ;
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3417
    struct hostent *hp ;
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3418
    int a, sock ;
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3419
    long addr;
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3420
    FILE *fp;
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3421
    int ret;
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3422
    int on = 1;
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3423
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3424
    bzero((char *) &sa, sizeof(sa)) ;
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3425
    sa.sin_family = AF_INET;
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3426
    sa.sin_addr.s_addr = htonl(INADDR_ANY);
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3427
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3428
    if ((hostName != nil) && __isString(hostName)){
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3429
	bzero(&sa, sizeof(sa)) ;
524
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  3430
	if ((addr = inet_addr((char *) __stringVal(hostName))) != -1) {
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3431
	    /* 
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3432
	     * is Internet addr in octet notation 
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3433
	     */
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3434
	    bcopy(&addr, (char *) &sa.sin_addr, sizeof(addr)) ; /* set address */
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3435
	} else {
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3436
	    /* 
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3437
	     * do we know the host's address? 
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3438
	     */
524
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  3439
	    if ((hp = gethostbyname((char *) __stringVal(hostName))) == NULL) {
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3440
		DBGPRINTF(("SOCKET: unknown host\n"));
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3441
		RETURN ( nil );
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3442
	    }
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3443
	    bcopy(hp->h_addr, (char *) &sa.sin_addr, hp->h_length) ;
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3444
	    sa.sin_family = hp->h_addrtype;
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3445
	}
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3446
    }
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3447
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3448
    /*
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3449
     * create the socket
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3450
     */
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3451
    __BEGIN_INTERRUPTABLE__
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3452
    do {
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3453
	sock = socket(sa.sin_family, SOCK_STREAM, 0);
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3454
    } while ((sock < 0) && (errno == EINTR));
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3455
    __END_INTERRUPTABLE__
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3456
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3457
    if (sock < 0) {
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3458
	DBGPRINTF(("SOCKET: socket(dom=%d typ=%d proto=0) call failed errno=%d\n", sa.sin_family, SOCK_STREAM, errno));
217
fcfbc9f71048 underscore cleanup
Claus Gittinger <cg@exept.de>
parents: 209
diff changeset
  3459
	__INST(lastErrorNumber) = __MKSMALLINT(errno);
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3460
    } else {
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3461
	/* 
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3462
	 * connect/bind 
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3463
	 */
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3464
	sa.sin_port = htons((u_short) _intVal(portNr)) ;
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3465
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3466
	__BEGIN_INTERRUPTABLE__
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3467
	if (hostName != nil) {
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3468
	    do {
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3469
		ret = connect(sock, (struct sockaddr *)&sa, sizeof(sa));
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3470
	    } while ((ret < 0) && (errno == EINTR));
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3471
	} else {
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3472
#ifdef SO_REUSEADDR
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3473
	    /*
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3474
	     * should I also do this for DGRAM sockets ?
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3475
	     */
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3476
	    if (setsockopt(sock, SOL_SOCKET, SO_REUSEADDR, (char *) &on, sizeof (on)) < 0) {
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3477
		DBGPRINTF(("SOCKET: setsockopt - SO_REUSEADDR failed\n"));
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3478
	    }
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3479
#endif /* SO_REUSEADDR */
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3480
	    sa.sin_addr.s_addr = htonl(INADDR_ANY);
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3481
	    do {
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3482
		ret = bind(sock, (struct sockaddr *)&sa, sizeof(sa));
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3483
	    } while ((ret < 0) && (errno == EINTR));
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3484
	}
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3485
	__END_INTERRUPTABLE__
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3486
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3487
	if (ret < 0) { 
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3488
	    DBGPRINTF(("SOCKET: bind/connect call failed errno=%d\n", errno));
217
fcfbc9f71048 underscore cleanup
Claus Gittinger <cg@exept.de>
parents: 209
diff changeset
  3489
	    __INST(lastErrorNumber) = __MKSMALLINT(errno);
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3490
	    __BEGIN_INTERRUPTABLE__
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3491
	    close(sock) ;
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3492
	    __END_INTERRUPTABLE__
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3493
	} else {
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3494
	    /* 
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3495
	     * make it a FILE * 
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3496
	     */
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3497
	    fp = fdopen(sock, "r+");
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3498
	    if (! fp) {
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3499
		DBGPRINTF(("SOCKET: fdopen failed\n"));
217
fcfbc9f71048 underscore cleanup
Claus Gittinger <cg@exept.de>
parents: 209
diff changeset
  3500
		__INST(lastErrorNumber) = __MKSMALLINT(errno);
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3501
		__BEGIN_INTERRUPTABLE__
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3502
		close(sock);
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3503
		__END_INTERRUPTABLE__
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3504
	    } else {
444
9ba31a1fba38 always unbuffered on linux
Claus Gittinger <cg@exept.de>
parents: 430
diff changeset
  3505
#ifdef BUGGY_STDIO_LIB
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3506
		setbuf(fp, NULL);
217
fcfbc9f71048 underscore cleanup
Claus Gittinger <cg@exept.de>
parents: 209
diff changeset
  3507
		__INST(buffered) = false;
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3508
#endif
217
fcfbc9f71048 underscore cleanup
Claus Gittinger <cg@exept.de>
parents: 209
diff changeset
  3509
		__INST(filePointer) = __MKOBJ(fp);
425
eb8198e9f1b0 comment
Claus Gittinger <cg@exept.de>
parents: 421
diff changeset
  3510
		__STORESELF(filePointer);
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3511
	    }
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3512
	}
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3513
    }
418
317e55c6c281 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 403
diff changeset
  3514
#endif
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3515
%}.
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3516
    filePointer isNil ifTrue:[
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3517
	^ nil
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3518
    ].
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3519
    mode := #readwrite.
169
ba5dac089c64 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 168
diff changeset
  3520
    Lobby register:self.
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3521
    binary := false.
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3522
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3523
    domain := #inet.
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3524
    socketType := #stream.
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3525
    protocol := portNr.
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3526
    peerName := hostName.
81
claus
parents: 79
diff changeset
  3527
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3528
    "
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3529
     Socket new for:'clam' port:(Socket portOfService:'echo')
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3530
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3531
     Socket new for:nil port:9999
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3532
     Socket new for:(OperatingSystem getHostName) port:9999
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3533
    "
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3534
!
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3535
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3536
for:hostName udpPort:portNr
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3537
    "setup for a UDP socket (i.e. inet domain, datagram type) 
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3538
     if hostname is nil, a server port is opened;
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3539
     otherwise a client port to the server on host.
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3540
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3541
     HISTORIC LEFTOVER:
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3542
     This method will vanish, as soon as the low level
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3543
     connect/bind works,"
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3544
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3545
    self obsoleteMethodWarning.
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3546
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3547
    filePointer notNil ifTrue:[
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3548
	^ self error:'already created'
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3549
    ].
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3550
    (portNr isMemberOf:SmallInteger) ifFalse:[
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3551
	^ self error:'invalid portNr'
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3552
    ].
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3553
%{
418
317e55c6c281 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 403
diff changeset
  3554
#ifndef NO_SOCKET
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3555
    struct sockaddr_in sa ;
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3556
    struct hostent *hp ;
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3557
    int a, sock ;
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3558
    long addr;
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3559
    FILE *fp;
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3560
    int ret;
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3561
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3562
    if (hostName != nil) {
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3563
	bzero(&sa, sizeof(sa)) ;
524
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  3564
	if ((addr = inet_addr((char *) __stringVal(hostName))) != -1) {
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3565
	    /* 
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3566
	     * is Internet addr in octet notation 
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3567
	     */
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3568
	    bcopy(&addr, (char *) &sa.sin_addr, sizeof(addr)) ; /* set address */
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3569
	    sa.sin_family = AF_INET ;
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3570
	} else {
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3571
	    /* 
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3572
	     * is hostname - 
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3573
	     * do we know the host's address? 
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3574
	     */
524
8287da54eccf more empty code for other domains;
Claus Gittinger <cg@exept.de>
parents: 513
diff changeset
  3575
	    if ((hp = gethostbyname((char *) __stringVal(hostName))) == NULL) {
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3576
		DBGPRINTF(("SOCKET: unknown host\n"));
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3577
		RETURN ( nil );
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3578
	    }
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3579
	    bcopy(hp->h_addr, (char *) &sa.sin_addr, hp->h_length) ;
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3580
	    sa.sin_family = hp->h_addrtype ;
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3581
	}
526
1748ab3892a3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 525
diff changeset
  3582
    } else {
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3583
	sa.sin_family = AF_INET;
526
1748ab3892a3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 525
diff changeset
  3584
    }
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3585
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3586
    /*
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3587
     * create the socket
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3588
     */
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3589
    __BEGIN_INTERRUPTABLE__
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3590
    do {
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3591
	sock = socket(sa.sin_family, SOCK_DGRAM, 0);
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3592
    } while ((sock < 0) && (errno == EINTR));
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3593
    __END_INTERRUPTABLE__
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3594
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3595
    if (sock < 0) {
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3596
	DBGPRINTF(("SOCKET: socket(dom=%d typ=%d proto=0) call failed errno=%d\n", sa.sin_family, SOCK_DGRAM, errno));
217
fcfbc9f71048 underscore cleanup
Claus Gittinger <cg@exept.de>
parents: 209
diff changeset
  3597
	__INST(lastErrorNumber) = __MKSMALLINT(errno);
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3598
    } else {
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3599
	/* 
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3600
	 * ok,
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3601
	 * connect/bind 
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3602
	 */
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3603
	__BEGIN_INTERRUPTABLE__
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3604
	if (hostName == nil) {
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3605
	    sa.sin_addr.s_addr = htonl(INADDR_ANY);
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3606
	    do {
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3607
		ret = bind(sock, (struct sockaddr *)&sa, sizeof(sa));
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3608
	    } while ((ret < 0) && (errno == EINTR));
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3609
	} else {
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3610
	    sa.sin_port = htons((u_short) _intVal(portNr)) ;
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3611
	    do {
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3612
		ret = connect(sock, (struct sockaddr *)&sa, sizeof(sa));
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3613
	    } while ((ret < 0) && (errno == EINTR));
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3614
	}
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3615
	__END_INTERRUPTABLE__
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3616
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3617
	if (ret < 0) {
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3618
	    DBGPRINTF(("SOCKET: bind/connect call failed\n"));
217
fcfbc9f71048 underscore cleanup
Claus Gittinger <cg@exept.de>
parents: 209
diff changeset
  3619
	    __INST(lastErrorNumber) = __MKSMALLINT(errno);
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3620
	    __BEGIN_INTERRUPTABLE__
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3621
	    close(sock) ;
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3622
	    __END_INTERRUPTABLE__
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3623
	} else {
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3624
	    /* 
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3625
	     * make it a FILE * 
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3626
	     */
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3627
	    fp = fdopen(sock, "r+");
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3628
	    if (! fp) {
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3629
		DBGPRINTF(("SOCKET: fdopen call failed\n"));
217
fcfbc9f71048 underscore cleanup
Claus Gittinger <cg@exept.de>
parents: 209
diff changeset
  3630
		__INST(lastErrorNumber) = __MKSMALLINT(errno);
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3631
		__BEGIN_INTERRUPTABLE__
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3632
		close(sock);
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3633
		__END_INTERRUPTABLE__
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3634
	    } else {
444
9ba31a1fba38 always unbuffered on linux
Claus Gittinger <cg@exept.de>
parents: 430
diff changeset
  3635
#ifdef BUGGY_STDIO_LIB
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3636
		setbuf(fp, NULL);
217
fcfbc9f71048 underscore cleanup
Claus Gittinger <cg@exept.de>
parents: 209
diff changeset
  3637
		__INST(buffered) = false;
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3638
#endif
217
fcfbc9f71048 underscore cleanup
Claus Gittinger <cg@exept.de>
parents: 209
diff changeset
  3639
		__INST(filePointer) = __MKOBJ(fp);
425
eb8198e9f1b0 comment
Claus Gittinger <cg@exept.de>
parents: 421
diff changeset
  3640
		__STORESELF(filePointer);
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3641
	    }
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3642
	}
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3643
    }
418
317e55c6c281 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 403
diff changeset
  3644
#endif
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3645
%}.
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3646
    filePointer isNil ifTrue:[
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3647
	^ nil
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3648
    ].
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3649
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3650
    mode := #readwrite.
169
ba5dac089c64 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 168
diff changeset
  3651
    Lobby register:self.
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3652
    binary := false.
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3653
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3654
    domain := #inet.
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3655
    socketType := #datagram.
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3656
    protocol := portNr.
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3657
    peerName := hostName.
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3658
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3659
    "
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3660
     Socket new for:'clam' udpPort:(Socket portOfService:'echo')
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3661
    "
28
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  3662
! !
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  3663
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  3664
!Socket methodsFor:'specials'!
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  3665
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  3666
receiveTimeout:seconds
71
claus
parents: 63
diff changeset
  3667
    "set the receive timeout - for special applications only.
claus
parents: 63
diff changeset
  3668
     Not all operatingSystems offer this functionality
claus
parents: 63
diff changeset
  3669
     (returns false, if unsupported)"
28
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  3670
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  3671
    |millis|
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  3672
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  3673
    filePointer isNil ifTrue:[
42
506596f9a1a8 *** empty log message ***
claus
parents: 38
diff changeset
  3674
	^ self error:'not a valid socket'
28
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  3675
    ].
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  3676
    millis := (seconds * 1000) rounded.
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  3677
%{
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  3678
#if defined(SO_RCVTIMEO) && defined(SOL_SOCKET) && defined(HZ)
58
bd6753bf0401 *** empty log message ***
claus
parents: 51
diff changeset
  3679
    if (__isSmallInteger(millis)) {
217
fcfbc9f71048 underscore cleanup
Claus Gittinger <cg@exept.de>
parents: 209
diff changeset
  3680
	OBJ fp = __INST(filePointer);
42
506596f9a1a8 *** empty log message ***
claus
parents: 38
diff changeset
  3681
	int sock;
506596f9a1a8 *** empty log message ***
claus
parents: 38
diff changeset
  3682
	int opt;
28
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  3683
110
7af19ae8693b use new FILE* wrapper macros (based on externalAddress)
Claus Gittinger <cg@exept.de>
parents: 106
diff changeset
  3684
	sock = fileno(__FILEVal(fp));
42
506596f9a1a8 *** empty log message ***
claus
parents: 38
diff changeset
  3685
	opt = _intVal(millis) / (1000 / HZ);
506596f9a1a8 *** empty log message ***
claus
parents: 38
diff changeset
  3686
	setsockopt(sock, SOL_SOCKET, SO_RCVTIMEO, (char *)&opt, sizeof(int));
506596f9a1a8 *** empty log message ***
claus
parents: 38
diff changeset
  3687
	RETURN(true);
28
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  3688
    }
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  3689
#endif
71
claus
parents: 63
diff changeset
  3690
%}.
28
350f8e9493a4 *** empty log message ***
claus
parents: 25
diff changeset
  3691
    ^ false
81
claus
parents: 79
diff changeset
  3692
!
claus
parents: 79
diff changeset
  3693
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3694
sendTimeout:seconds
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3695
    "set the send timeout - for special applications only.
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3696
     Not all operatingSystems offer this functionality
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3697
     (returns false, if unsupported)"
81
claus
parents: 79
diff changeset
  3698
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3699
    |millis|
25
996051271ce9 *** empty log message ***
claus
parents: 21
diff changeset
  3700
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3701
    filePointer isNil ifTrue:[
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3702
	^ self error:'not a valid socket'
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3703
    ].
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3704
    millis := (seconds * 1000) rounded.
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3705
%{
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3706
#if defined(SO_SNDTIMEO) && defined(SOL_SOCKET) && defined(HZ)
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3707
    if (__isSmallInteger(millis)) {
217
fcfbc9f71048 underscore cleanup
Claus Gittinger <cg@exept.de>
parents: 209
diff changeset
  3708
	OBJ fp = __INST(filePointer);
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3709
	int sock;
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3710
	int opt;
81
claus
parents: 79
diff changeset
  3711
126
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3712
	sock = fileno(__FILEVal(fp));
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3713
	opt = _intVal(millis) / (1000 / HZ);
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3714
	setsockopt(sock, SOL_SOCKET, SO_SNDTIMEO, (char *)&opt, sizeof(int));
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3715
	RETURN(true);
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3716
    }
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3717
#endif
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3718
%}.
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3719
    ^ false
fca9404da9d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 119
diff changeset
  3720
! !
82
claus
parents: 81
diff changeset
  3721
464
600b101a7035 alen in accept
Claus Gittinger <cg@exept.de>
parents: 463
diff changeset
  3722
!Socket class methodsFor:'documentation'!
206
77166a6b3ee6 For ST80 style socket creation: register socket in Lobby.
Stefan Vogel <sv@exept.de>
parents: 203
diff changeset
  3723
77166a6b3ee6 For ST80 style socket creation: register socket in Lobby.
Stefan Vogel <sv@exept.de>
parents: 203
diff changeset
  3724
version
530
067797c15b77 added support for 6-byte internet addresses (untested)
Claus Gittinger <cg@exept.de>
parents: 529
diff changeset
  3725
    ^ '$Header: /cvs/stx/stx/libbasic2/Socket.st,v 1.90 1997-05-01 18:25:54 cg Exp $'
206
77166a6b3ee6 For ST80 style socket creation: register socket in Lobby.
Stefan Vogel <sv@exept.de>
parents: 203
diff changeset
  3726
! !