--- a/SocketAddress.st Thu May 29 12:59:23 2014 +0200
+++ b/SocketAddress.st Fri May 30 11:37:23 2014 +0200
@@ -116,15 +116,28 @@
^ self hostAddress:self anyAddress
!
-fromBytes:bytes
+fromBytes:bytesArg
"create a socket address from bytes (ByteArray),
returned by the primitive syscalls.
Raises an error, if the domainType is not supported by this Smalltalk
(i.e. if libbasic was compiled without support for the corresponding AF_xxx support)"
- |domainNr domainSymbol|
+ |domainNr domainSymbol bytes|
+
+ bytes := bytesArg asByteArray.
- domainNr := bytes unsignedShortAt:1.
+ "/ cg: code used to be:
+ "/ domainNr := bytes unsignedShortAt:1.
+ "/ however, some systems use a different structure, which includes the struct length
+ "/ in byte 1 (APPLE).
+ "/ so better let the C-compiler figure out how things are layed out...
+%{
+ if (__isByteArrayLike(bytes)) {
+ struct sockaddr *s = (struct sockaddr *)(__ByteArrayInstPtr(bytes)->ba_element);
+
+ domainNr = __mkSmallInteger(s->sa_family);
+ }
+%}.
domainSymbol := OperatingSystem domainSymbolOf:domainNr.
domainSymbol isNil ifTrue:[
self error:('unsupported domain (type=%1)' bindWith:domainNr)
@@ -816,10 +829,10 @@
!SocketAddress class methodsFor:'documentation'!
version
- ^ '$Header: /cvs/stx/stx/libbasic2/SocketAddress.st,v 1.44 2014-05-28 17:16:00 cg Exp $'
+ ^ '$Header: /cvs/stx/stx/libbasic2/SocketAddress.st,v 1.45 2014-05-30 09:37:23 cg Exp $'
!
version_CVS
- ^ '$Header: /cvs/stx/stx/libbasic2/SocketAddress.st,v 1.44 2014-05-28 17:16:00 cg Exp $'
+ ^ '$Header: /cvs/stx/stx/libbasic2/SocketAddress.st,v 1.45 2014-05-30 09:37:23 cg Exp $'
! !