Index: configure
===================================================================
--- configure	(revision 5398)
+++ configure	(revision 5408)
@@ -1636,4 +1636,5 @@
 test_lib_defmake ROAR_HAVE_H_LINUX_REBOOT %            linux/reboot.h c        -- linux/reboot.h
 test_lib_defmake ROAR_HAVE_H_WINDOWS     %            windows.h     c          -- windows.h
+test_lib_defmake ROAR_HAVE_H_WINSOCK     %            winsock.h     c          -- winsock.h
 test_lib_defmake ROAR_HAVE_H_WINSOCK2    %            winsock2.h    c          -- winsock2.h
 MINIMAL=$OLD_MINIMAL
@@ -1830,6 +1831,6 @@
 test_func_defmake ROAR_HAVE_STAT      stat      'stat((char*)0, (void*)0)'   -- sys/types.h sys/stat.h unistd.h
 test_func_defmake ROAR_HAVE_SYSTEM    system    'system("")'                 -- stdlib.h
-test_func_defmake ROAR_HAVE_GETSOCKNAME getsockname 'getsockname(0, 0, 0)'   -- sys/socket.h
-test_func_defmake ROAR_HAVE_GETPEERNAME getpeername 'getpeername(0, 0, 0)'   -- sys/socket.h
+test_func_defmake ROAR_HAVE_GETSOCKNAME getsockname 'getsockname(0, 0, 0)'   $lib_wsock32 -- sys/socket.h winsock.h
+test_func_defmake ROAR_HAVE_GETPEERNAME getpeername 'getpeername(0, 0, 0)'   $lib_wsock32 -- sys/socket.h winsock.h
 test_func_defmake ROAR_HAVE_GETSOCKOPT getsockopt 'getsockopt(0, 0, 0, (void*)0, (void*)0)' -- sys/types.h sys/socket.h
 test_func_defmake ROAR_HAVE_SETSOCKOPT setsockopt 'setsockopt(0, 0, 0, (void*)0, (void*)0)' -- sys/types.h sys/socket.h
Index: libroar/vio.c
===================================================================
--- libroar/vio.c	(revision 5391)
+++ libroar/vio.c	(revision 5408)
@@ -93,5 +93,6 @@
  ssize_t ret;
 
- ROAR_DBG("roar_vio_write(vio=%p, buf=%p, count=%u) = ?", vio, buf, (unsigned int)count);
+ // This function MUST NOT call ROAR_{DBG,WARN,ERR,INFO}() because that would result
+ // in an infinit loop.
 
  if ( vio == NULL ) {
@@ -148,5 +149,6 @@
  int ret;
 
- ROAR_DBG("roar_vio_sync(vio=%p) = ?", vio);
+ // This function MUST NOT call ROAR_{DBG,WARN,ERR,INFO}() because that would result
+ // in an infinit loop.
 
  if ( vio == NULL ) {
@@ -170,5 +172,5 @@
  int ret;
 
- ROAR_DBG("roar_vio_ctl(vio=%p, cmd=%i, data=%p) = ?", vio, cmd, data);
+ ROAR_DBG("roar_vio_ctl(vio=%p, cmd=%i(0x%.8x), data=%p) = ?", vio, cmd, cmd, data);
 
  if ( vio == NULL ) {
@@ -514,4 +516,5 @@
 
     if ( cmd == ROAR_VIO_CTL_GET_SOCKNAME ) {
+     ROAR_DBG("roar_vio_basic_ctl(vio=%p, cmd=ROAR_VIO_CTL_GET_SOCKNAME, data=%p) = ?", vio, data);
 #ifdef ROAR_HAVE_GETSOCKNAME
      tmp = getsockname(roar_vio_get_fh(vio), &(sockaddr.sa), &socklen);
@@ -521,4 +524,5 @@
 #endif
     } else if ( cmd == ROAR_VIO_CTL_GET_PEERNAME ) {
+     ROAR_DBG("roar_vio_basic_ctl(vio=%p, cmd=ROAR_VIO_CTL_GET_PEERNAME, data=%p) = ?", vio, data);
 #ifdef ROAR_HAVE_GETPEERNAME
      tmp = getpeername(roar_vio_get_fh(vio), &(sockaddr.sa), &socklen);
@@ -534,4 +538,5 @@
     }
 
+    ROAR_DBG("roar_vio_basic_ctl(vio=%p, cmd=0x%.8x, data=%p): tmp=%i", vio, cmd, data, tmp);
     if ( tmp == -1 )
      return -1;
Index: libroar/vio_dstr.c
===================================================================
--- libroar/vio_dstr.c	(revision 5388)
+++ libroar/vio_dstr.c	(revision 5408)
@@ -336,4 +336,5 @@
 #endif
 
+ ROAR_DBG("_open_file(calls=%p, filename='%s', flags=0x%x, mode=%i) = ?", calls, filename, flags, (int)mode);
  roar_err_clear_all();
  if ( (fh = open(filename, flags, mode)) == -1 ) {
Index: libroar/vio_stream.c
===================================================================
--- libroar/vio_stream.c	(revision 5381)
+++ libroar/vio_stream.c	(revision 5408)
@@ -183,4 +183,5 @@
  int socks[2]; // for socketpair()
 #endif
+ struct roar_sockname sockname;
 
  // make valgrind happy
@@ -190,4 +191,6 @@
 #endif
 
+ ROAR_DBG("_roar_simple_new_stream_obj(con=%p, s=%p, rate=%i, channels=%i, bits=%i, codec=%i, dir=%i, mixer=%i) = ?", con, s, (int)rate, (int)channels, (int)bits, (int)codec, dir, mixer);
+
  if ( config != NULL ) {
   if ( config->workaround.workarounds & ROAR_LIBROAR_CONFIG_WAS_USE_EXECED ) {
@@ -196,40 +199,22 @@
  }
 
-#ifdef ROAR_HAVE_BSDSOCKETS
+ ROAR_DBG("_roar_simple_new_stream_obj(con=%p, s=%p, rate=%i, channels=%i, bits=%i, codec=%i, dir=%i, mixer=%i) = ?", con, s, (int)rate, (int)channels, (int)bits, (int)codec, dir, mixer);
+
  roar_libroar_nowarn();
- if ( getsockname(roar_get_connection_fh(con), (struct sockaddr *)&socket_addr, &len) == -1 ) {
+ if ( roar_vio_ctl(roar_get_connection_vio2(con), ROAR_VIO_CTL_GET_SOCKNAME, &sockname) == -1 ) {
   roar_libroar_warn();
-  return -1;
+#ifdef ROAR_OS_OPENBSD
+  sockname.type = ROAR_SOCKET_TYPE_UNIX;
+#else
+  ROAR_DBG("_roar_simple_new_stream_obj(con=%p, s=%p, rate=%i, channels=%i, bits=%i, codec=%i, dir=%i, mixer=%i) = -1", con, s, (int)rate, (int)channels, (int)bits, (int)codec, dir, mixer);
+
+  return -1;
+#endif
  }
  roar_libroar_warn();
-#else
- return -1;
-#endif
-
- if ( len == 0 ) {
-#ifdef ROAR_OS_OPENBSD
-  ROAR_WARN("roar_simple_new_stream_obj(*): Unknown address family: guess AF_UNIX because OS is OpenBSD");
-  ((struct sockaddr*)&socket_addr)->sa_family = AF_UNIX;
-#else
-  return -1;
-#endif
- }
-
- switch (((struct sockaddr*)&socket_addr)->sa_family) {
-#ifdef ROAR_HAVE_UNIX
-  case AF_UNIX:   type = ROAR_SOCKET_TYPE_UNIX; break;
-#endif
-#ifdef ROAR_HAVE_IPV4
-  case AF_INET:   type = ROAR_SOCKET_TYPE_INET; break;
-#endif
-#ifdef ROAR_HAVE_LIBDNET
-  case AF_DECnet: type = ROAR_SOCKET_TYPE_DECNET; break;
-#endif
-  default:
-    return -1;
-   break;
- }
-
- if ( type == ROAR_SOCKET_TYPE_DECNET ) {
+
+ ROAR_DBG("_roar_simple_new_stream_obj(con=%p, s=%p, rate=%i, channels=%i, bits=%i, codec=%i, dir=%i, mixer=%i) = ?", con, s, (int)rate, (int)channels, (int)bits, (int)codec, dir, mixer);
+
+ if ( sockname.type == ROAR_SOCKET_TYPE_DECNET ) {
   if ( roar_socket_get_local_nodename() ) {
    snprintf(file, 24, "%s::roar$TMP%04x%02x", roar_socket_get_local_nodename(), getpid(), count++);
@@ -243,11 +228,11 @@
  }
 
- if ( type != ROAR_SOCKET_TYPE_UNIX ) {
-  if ( (listen = roar_socket_listen(type, file, port)) == -1 ) {
+ if ( sockname.type != ROAR_SOCKET_TYPE_UNIX ) {
+  if ( (listen = roar_socket_listen(sockname.type, file, port)) == -1 ) {
    return -1;
   }
  }
 
- if ( type == ROAR_SOCKET_TYPE_INET ) {
+ if ( sockname.type == ROAR_SOCKET_TYPE_INET ) {
 #ifdef ROAR_HAVE_IPV4
   setsockopt(listen, SOL_SOCKET, SO_REUSEADDR, (void*)&opt, sizeof(int));
@@ -262,5 +247,5 @@
   return -1;
 #endif
- } else if ( type == ROAR_SOCKET_TYPE_DECNET ) {
+ } else if ( sockname.type == ROAR_SOCKET_TYPE_DECNET ) {
 #ifdef ROAR_HAVE_LIBDNET
   setsockopt(listen, SOL_SOCKET, SO_REUSEADDR, &opt, sizeof(int));
@@ -278,7 +263,7 @@
  }
 
- if ( type != ROAR_SOCKET_TYPE_UNIX ) {
+ if ( sockname.type != ROAR_SOCKET_TYPE_UNIX ) {
 #ifdef ROAR_HAVE_SELECT
-  if ( roar_stream_connect_to_ask(con, s, type, file, port) != -1 ) {
+  if ( roar_stream_connect_to_ask(con, s, sockname.type, file, port) != -1 ) {
 
    FD_ZERO(&fds);
@@ -354,5 +339,5 @@
   return -1;
 #endif
- } else { // this is type == ROAR_SOCKET_TYPE_UNIX
+ } else { // this is sockname.type == ROAR_SOCKET_TYPE_UNIX
 #ifdef ROAR_HAVE_UNIX
   if ( socketpair(AF_UNIX, SOCK_STREAM, 0, socks) == -1 ) {
@@ -388,4 +373,5 @@
  s->fh = fh;
 
+ ROAR_DBG("_roar_simple_new_stream_obj(con=%p, s=%p, rate=%i, channels=%i, bits=%i, codec=%i, dir=%i, mixer=%i) = %i", con, s, (int)rate, (int)channels, (int)bits, (int)codec, dir, mixer, fh);
  return fh;
 }
Index: libroar/vio_winsock.c
===================================================================
--- libroar/vio_winsock.c	(revision 5407)
+++ libroar/vio_winsock.c	(revision 5408)
@@ -128,4 +128,8 @@
     return shutdown(_get_fh(vio), tmp);
    break;
+  case ROAR_VIO_CTL_GET_SOCKNAME:
+  case ROAR_VIO_CTL_GET_PEERNAME:
+    return roar_vio_basic_ctl(vio, cmd, data);
+   break;
  }
 
