Hello,

the attached patch fixes abstract sockets for Linux. It least it tries
as it does not work:

strace output from dbus-monitor:
socket(PF_FILE, SOCK_STREAM, 0)         = 3
connect(3, {sa_family=AF_FILE, path=@"/tmp/dbus-RhgMDI9FXg"...}, 23) = 0

strace output from my app using iolib:
socket(PF_FILE, SOCK_STREAM, 0)         = 5
connect(5, {sa_family=AF_FILE, path=@"/tmp/dbus-RhgMDI9FXg"...}, 110) = -1 
ECONNREFUSED (Connection refused)

It seems as if connect (and bind) have to be passed "exact" sizes as
addrlen parameter. But what is a good (i.e. portable) way to compute
these? Using (+ 3 (length address)) (counting the address family word,
the zero byte, and the string) would be quite a hack...

Regards,
-- 
Julian Stecklina

Well, take it from an old hand: the only reason it would be easier to
program in C is that you can't easily express complex problems in C,
so you don't. - Erik Naggum (in comp.lang.lisp)
diff --git a/src/sockets/common.lisp b/src/sockets/common.lisp
index eca179d..9cba454 100644
--- a/src/sockets/common.lisp
+++ b/src/sockets/common.lisp
@@ -120,20 +120,27 @@
      (make-sockaddr-in6 ,var ,address ,port)
      ,@body))
 
-(defun make-sockaddr-un (sun string)
+(defun make-sockaddr-un (sun string abstract)
   (declare (type string string))
   (isys:%sys-bzero sun size-of-sockaddr-un)
   (with-foreign-slots ((family path) sun sockaddr-un)
     (setf family af-local)
-    (with-foreign-string (c-string string)
-      (loop :for off :below (1- unix-path-max)
-            :do (setf (mem-aref path :uint8 off)
-                      (mem-aref c-string :uint8 off)))))
+    (let ((address-string (concatenate 'string 
+                                       (when abstract
+                                         (string (code-char 0)))
+                                       string
+                                       (unless abstract
+                                         (string (code-char 0))))))
+      (with-foreign-string (c-string address-string :null-terminated-p nil)
+        (loop :for off :below (min (length address-string) (1- unix-path-max))
+           :do (setf (mem-aref path :uint8 off)
+                     (print (mem-aref c-string :uint8 off)))))))
   (values sun))
 
-(defmacro with-sockaddr-un ((var address) &body body)
+
+(defmacro with-sockaddr-un ((var address abstract) &body body)
   `(with-foreign-object (,var 'sockaddr-un)
-     (make-sockaddr-un ,var ,address)
+     (make-sockaddr-un ,var ,address ,abstract)
      ,@body))
 
 (defmacro with-sockaddr-storage ((var) &body body)
diff --git a/src/sockets/socket-methods.lisp b/src/sockets/socket-methods.lisp
index 0aad96b..aa947f2 100644
--- a/src/sockets/socket-methods.lisp
+++ b/src/sockets/socket-methods.lisp
@@ -259,7 +259,7 @@
   (values socket))
 
 (defmethod bind-address ((socket local-socket) (address local-address) &key)
-  (with-sockaddr-un (sun (address-name address))
+  (with-sockaddr-un (sun (address-name address) (abstract-address-p address))
     (%bind (fd-of socket) sun size-of-sockaddr-un))
   (values socket))
 
@@ -352,7 +352,7 @@
   (values socket))
 
 (defmethod connect ((socket local-socket) (address local-address) &key)
-  (with-sockaddr-un (sun (address-name address))
+  (with-sockaddr-un (sun (address-name address) (abstract-address-p address))
     (%connect (fd-of socket) sun size-of-sockaddr-un))
   (values socket))
 
_______________________________________________
IOLib-devel mailing list
[email protected]
http://common-lisp.net/cgi-bin/mailman/listinfo/iolib-devel

Reply via email to