Index: include/libroar/socket.h
===================================================================
--- include/libroar/socket.h	(revision 5121)
+++ include/libroar/socket.h	(revision 5248)
@@ -54,13 +54,10 @@
 
 // TODO: those function should be made /static/.
-int roar_socket_new_tcp    (void) _LIBROAR_ATTR_TO_STATIC;
-int roar_socket_new_udp    (void) _LIBROAR_ATTR_TO_STATIC;
-int roar_socket_new_tcp6   (void) _LIBROAR_ATTR_TO_STATIC;
-int roar_socket_new_udp6   (void) _LIBROAR_ATTR_TO_STATIC;
-int roar_socket_new_unix   (void) _LIBROAR_ATTR_TO_STATIC;
+#if 0
 int roar_socket_new_decnet_seqpacket (void) _LIBROAR_ATTR_TO_STATIC;
-int roar_socket_new_decnet_stream (void) _LIBROAR_ATTR_TO_STATIC;
 int roar_socket_new_ipxspx (void) _LIBROAR_ATTR_TO_STATIC;
-int roar_socket_new_ipx    (void) _LIBROAR_ATTR_TO_STATIC;
+#endif
+
+int roar_socket_new        (int type);
 
 int roar_socket_open       (int mode, int type, char * host, int port);
Index: libroar/socket.c
===================================================================
--- libroar/socket.c	(revision 5210)
+++ libroar/socket.c	(revision 5248)
@@ -54,97 +54,4 @@
 #endif
 
-int roar_socket_new_tcp (void) {
-#ifdef ROAR_HAVE_IPV4
- int fh;
-#if defined(TCP_NODELAY) && !defined(ROAR_TARGET_WIN32)
- int t   = 1;
-#endif
-
- roar_socket_win32_init();
-
- fh = socket(AF_INET, SOCK_STREAM, 0);
-
- roar_socket_set_tos(fh);
-#if defined(TCP_NODELAY) && !defined(ROAR_TARGET_WIN32)
- setsockopt(fh, IPPROTO_TCP, TCP_NODELAY, &t, sizeof(int));
-#endif
-
- return fh;
-#else
- return -1;
-#endif
-}
-
-int roar_socket_new_udp (void) {
-#ifdef ROAR_HAVE_IPV4
- int fh;
-
- roar_socket_win32_init();
-
- fh = socket(AF_INET, SOCK_DGRAM, 0);
-
- roar_socket_set_tos(fh);
-
- return fh;
-#else
- return -1;
-#endif
-}
-
-int roar_socket_new_tcp6 (void) {
-#ifdef ROAR_HAVE_IPV6
- int fh;
-
- roar_socket_win32_init();
-
- fh = socket(AF_INET6, SOCK_STREAM, 0);
-
- roar_socket_set_tos(fh);
-
- return fh;
-#else
- return -1;
-#endif
-}
-
-int roar_socket_new_udp6 (void) {
-#ifdef ROAR_HAVE_IPV6
- int fh;
-
- roar_socket_win32_init();
-
- fh = socket(AF_INET6, SOCK_DGRAM, 0);
-
- roar_socket_set_tos(fh);
-
- return fh;
-#else
- return -1;
-#endif
-}
-
-int roar_socket_new_unix (void) {
-#ifdef ROAR_HAVE_UNIX
- int fh;
-/*
-#ifdef SO_PEERCRED
- int opt = 1;
-#endif
-*/
-
- fh = socket(AF_UNIX, SOCK_STREAM, 0);
-
-/*
-#ifdef SO_PEERCRED
-// setsockopt(fh, SOL_SOCKET, SO_PASSCRED, &opt, sizeof(int));
-#endif
-*/
-
- return fh;
-#else
- return -1;
-#endif
-}
-
 int roar_socket_decnet_set_timeout (int fh, time_t sec, int usec) {
 #ifdef ROAR_HAVE_LIBDNET
@@ -183,5 +90,6 @@
 }
 
-int roar_socket_new_decnet_seqpacket (void) {
+#if 0
+static int roar_socket_new_decnet_seqpacket (void) {
 #ifdef ROAR_HAVE_LIBDNET
  int fh;
@@ -196,30 +104,105 @@
 #endif
 }
-
-
-int roar_socket_new_decnet_stream (void) {
+#endif
+
+
+#if 0
+static int roar_socket_new_ipxspx (void) {
+ return -1;
+}
+#endif
+
+int roar_socket_new        (int type) {
+ int sys_domain = -1, sys_type = -1, sys_protocol = 0;
+ int fh;
+#if defined(ROAR_HAVE_IPV4) && defined(TCP_NODELAY) && !defined(ROAR_TARGET_WIN32)
+ int t   = 1;
+#endif
+
+ switch (type) {
+  case ROAR_SOCKET_TYPE_NONE:
+  case ROAR_SOCKET_TYPE_GENSTR:
+    roar_err_set(ROAR_ERROR_INVAL);
+    return -1;
+   break;
+  case ROAR_SOCKET_TYPE_FILE:
+  case ROAR_SOCKET_TYPE_FORK:
+    roar_err_set(ROAR_ERROR_PERM);
+    return -1;
+   break;
+#ifdef ROAR_HAVE_IPV4
+  case ROAR_SOCKET_TYPE_TCP:
+    sys_domain = AF_INET; sys_type = SOCK_STREAM;
+   break;
+  case ROAR_SOCKET_TYPE_UDP:
+    sys_domain = AF_INET; sys_type = SOCK_DGRAM;
+   break;
+#endif
+#ifdef ROAR_HAVE_UNIX
+  case ROAR_SOCKET_TYPE_UNIX:
+    sys_domain = AF_UNIX; sys_type = SOCK_STREAM;
+   break;
+#endif
 #ifdef ROAR_HAVE_LIBDNET
- int fh;
-
- fh = socket(AF_DECnet, SOCK_STREAM, DNPROTO_NSP);
-
- roar_socket_decnet_set_timeout(fh, 300, 0);
+  case ROAR_SOCKET_TYPE_DECNET:
+    sys_domain = AF_DECnet; sys_type = SOCK_STREAM; sys_protocol = DNPROTO_NSP;
+   break;
+#endif
+#ifdef ROAR_HAVE_IPV6
+  case ROAR_SOCKET_TYPE_TCP6:
+    sys_domain = AF_INET6; sys_type = SOCK_STREAM;
+   break;
+  case ROAR_SOCKET_TYPE_UDP6:
+    sys_domain = AF_INET6; sys_type = SOCK_DGRAM;
+   break;
+#endif
+#ifdef ROAR_HAVE_IPX
+  case ROAR_SOCKET_TYPE_IPX:
+    sys_domain = AF_IPX; sys_type = SOCK_DGRAM; sys_protocol = AF_IPX;
+   break;
+#endif
+  case ROAR_SOCKET_TYPE_IPXSPX:
+  case ROAR_SOCKET_TYPE_LAT_SERVICE:
+  case ROAR_SOCKET_TYPE_LAT_REVERSE_PORT:
+  default:
+    roar_err_set(ROAR_ERROR_AFNOTSUP);
+    return -1;
+   break;
+ }
+
+ roar_socket_win32_init();
+
+ roar_err_clear_all();
+ fh = socket(sys_domain, sys_type, sys_protocol);
+ if ( fh == -1 ) {
+  roar_err_update();
+  return -1;
+ }
+
+ // do the extra work we need to do for some socket types:
+ switch (type) {
+#ifdef ROAR_HAVE_IPV4
+  case ROAR_SOCKET_TYPE_TCP:
+#if defined(TCP_NODELAY) && !defined(ROAR_TARGET_WIN32)
+   setsockopt(fh, IPPROTO_TCP, TCP_NODELAY, &t, sizeof(int));
+#endif
+  case ROAR_SOCKET_TYPE_UDP:
+#endif
+#ifdef ROAR_HAVE_IPV6
+  case ROAR_SOCKET_TYPE_TCP6:
+  case ROAR_SOCKET_TYPE_UDP6:
+#endif
+#if defined(ROAR_HAVE_IPV4) || defined(ROAR_HAVE_IPV6)
+    roar_socket_set_tos(fh);
+   break;
+#endif
+#ifdef ROAR_HAVE_LIBDNET
+  case ROAR_SOCKET_TYPE_DECNET:
+    roar_socket_decnet_set_timeout(fh, 300, 0);
+   break;
+#endif
+ }
 
  return fh;
-#else
- return -1;
-#endif
-}
-
-int roar_socket_new_ipxspx (void) {
- return -1;
-}
-
-int roar_socket_new_ipx    (void) {
-#ifdef ROAR_HAVE_IPX
- return socket(AF_IPX, SOCK_DGRAM, AF_IPX);
-#else
- return -1;
-#endif
 }
 
@@ -280,5 +263,5 @@
  }
 
- n = roar_socket_new_udp();
+ n = roar_socket_new(ROAR_SOCKET_TYPE_UDP);
 
  if ( n == -1 )
@@ -424,5 +407,5 @@
 int roar_socket_listen_decnet (char * object, int num) {
 #ifdef ROAR_HAVE_LIBDNET
- int fh = roar_socket_new_decnet_stream();
+ int fh = roar_socket_new(ROAR_SOCKET_TYPE_DECNET);
  struct sockaddr_dn bind_sockaddr;
 
@@ -695,7 +678,7 @@
 
   if ( type == ROAR_SOCKET_TYPE_INET ) {
-   fh = roar_socket_new_tcp();
+   fh = roar_socket_new(ROAR_SOCKET_TYPE_TCP);
   } else {
-   fh = roar_socket_new_tcp6();
+   fh = roar_socket_new(ROAR_SOCKET_TYPE_TCP6);
   }
 
@@ -721,5 +704,5 @@
    socket_addr.in.sin_port   = ROAR_HOST2NET16(port);
 
-  fh = roar_socket_new_tcp();
+  fh = roar_socket_new(ROAR_SOCKET_TYPE_TCP);
   addrlen = sizeof(struct sockaddr_in);
 #endif
@@ -763,5 +746,5 @@
   }
 
-  fh = roar_socket_new_unix();
+  fh = roar_socket_new(ROAR_SOCKET_TYPE_UNIX);
 
   if ( mode_func(fh, (struct sockaddr *)&socket_addr.un, sizeof(struct sockaddr_un)) == -1 ) {
@@ -795,8 +778,8 @@
    return -1;
 
-  fh = roar_socket_new_ipx();
+  fh = roar_socket_new(ROAR_SOCKET_TYPE_IPX);
 
   close(fh);
-  roar_err_set(ROAR_ERROR_NOSYS);
+  roar_err_set(ROAR_ERROR_AFNOTSUP);
   return -1;
 #else
Index: libroar/vio_socket.c
===================================================================
--- libroar/vio_socket.c	(revision 5033)
+++ libroar/vio_socket.c	(revision 5248)
@@ -72,8 +72,8 @@
     switch (def->d.socket.type) {
      case SOCK_STREAM:
-       fh = roar_socket_new_tcp();
+       fh = roar_socket_new(ROAR_SOCKET_TYPE_TCP);
       break;
      case SOCK_DGRAM:
-       fh = roar_socket_new_udp();
+       fh = roar_socket_new(ROAR_SOCKET_TYPE_UDP);
        connection_less = 1;
       break;
@@ -89,5 +89,5 @@
     switch (def->d.socket.type) {
      case SOCK_STREAM:
-       fh = roar_socket_new_unix();
+       fh = roar_socket_new(ROAR_SOCKET_TYPE_UNIX);
       break;
      case SOCK_DGRAM:
@@ -109,5 +109,5 @@
     switch (def->d.socket.type) {
      case SOCK_STREAM:
-       fh = roar_socket_new_decnet_stream();
+       fh = roar_socket_new(ROAR_SOCKET_TYPE_DECNET);
       break;
      default:
@@ -122,8 +122,8 @@
     switch (def->d.socket.type) {
      case SOCK_STREAM:
-       fh = roar_socket_new_tcp6();
+       fh = roar_socket_new(ROAR_SOCKET_TYPE_TCP6);
       break;
      case SOCK_DGRAM:
-       fh = roar_socket_new_udp6();
+       fh = roar_socket_new(ROAR_SOCKET_TYPE_UDP6);
        connection_less = 1;
       break;
