Mike McCormack : rpcrt4: Add support for the ncacn_ip_tcp transport layer.

Alexandre Julliard julliard at wine.codeweavers.com
Fri Apr 21 05:02:43 CDT 2006


Module: wine
Branch: refs/heads/master
Commit: 3d5e517e5b8c049eabad5fe4e3adaf0e2a2a078c
URL:    http://source.winehq.org/git/?p=wine.git;a=commit;h=3d5e517e5b8c049eabad5fe4e3adaf0e2a2a078c

Author: Mike McCormack <mike at codeweavers.com>
Date:   Fri Apr 21 18:20:16 2006 +0900

rpcrt4: Add support for the ncacn_ip_tcp transport layer.

---

 dlls/rpcrt4/rpc_transport.c |   88 ++++++++++++++++++++++++++++++++++++++++---
 1 files changed, 82 insertions(+), 6 deletions(-)

diff --git a/dlls/rpcrt4/rpc_transport.c b/dlls/rpcrt4/rpc_transport.c
index 98d8006..4faad59 100644
--- a/dlls/rpcrt4/rpc_transport.c
+++ b/dlls/rpcrt4/rpc_transport.c
@@ -22,11 +22,29 @@
  *
  */
 
+#include "config.h"
+
 #include <stdarg.h>
 #include <stdio.h>
 #include <string.h>
 #include <assert.h>
 
+#include <unistd.h>
+#include <fcntl.h>
+#include <stdlib.h>
+#ifdef HAVE_SYS_TYPES
+#include <sys/types.h>
+#endif
+#ifdef HAVE_SYS_SOCKET_H
+#include <sys/socket.h>
+#endif
+#ifdef HAVE_NETINET_IN_H
+#include <netinet/in.h>
+#endif
+#ifdef HAVE_ARPA_INET_H
+#include <arpa/inet.h>
+#endif
+
 #include "windef.h"
 #include "winbase.h"
 #include "winnls.h"
@@ -45,6 +63,8 @@ #include "rpc_message.h"
 
 WINE_DEFAULT_DEBUG_CHANNEL(rpc);
 
+/**** ncacn_np support ****/
+
 typedef struct _RpcConnection_np
 {
   RpcConnection common;
@@ -180,7 +200,7 @@ static RPC_STATUS rpcrt4_conn_np_handoff
   RpcConnection_np *new_npc = (RpcConnection_np *) new_conn;
   /* because of the way named pipes work, we'll transfer the connected pipe
    * to the child, then reopen the server binding to continue listening */
-  
+
   new_npc->pipe = old_npc->pipe;
   new_npc->ovl = old_npc->ovl;
   old_npc->pipe = 0;
@@ -224,9 +244,12 @@ static int rpcrt4_conn_np_close(RpcConne
   return 0;
 }
 
+/**** ncacn_ip_tcp support ****/
+
 typedef struct _RpcConnection_tcp
 {
   RpcConnection common;
+  int sock;
 } RpcConnection_tcp;
 
 static RpcConnection *rpcrt4_conn_tcp_alloc(void)
@@ -236,35 +259,86 @@ static RpcConnection *rpcrt4_conn_tcp_al
 
 static RPC_STATUS rpcrt4_ncacn_ip_tcp_open(RpcConnection* Connection)
 {
-  FIXME("(%s, %s) unimplemented\n", Connection->NetworkAddr, Connection->Endpoint);
+  RpcConnection_tcp *tcpc = (RpcConnection_tcp *) Connection;
+  struct sockaddr_in sa;
+  int sock;
+
+  TRACE("(%s, %s)\n", Connection->NetworkAddr, Connection->Endpoint);
+
+  if (Connection->server)
+  {
+    ERR("ncacn_ip_tcp servers not supported yet\n");
+    return RPC_S_SERVER_UNAVAILABLE;
+  }
+
+  if (tcpc->sock)
+    return RPC_S_OK;
+
+  sa.sin_family = AF_INET;
+  inet_pton(AF_INET, Connection->NetworkAddr, &sa.sin_addr);
+  sa.sin_port = htons(atoi(Connection->Endpoint));
+
+  sock = socket(PF_INET, SOCK_STREAM, IPPROTO_TCP);
+  if (sock < 0)
+  {
+    ERR("socket() failed\n");
+    goto error;
+  }
+
+  if (0>connect(sock, (struct sockaddr*) &sa, sizeof (sa)))
+  {
+    ERR("connect() failed\n");
+    goto error;
+  }
+
+  tcpc->sock = sock;
+
+  return RPC_S_OK;
+
+error:
+  close(sock);
   return RPC_S_SERVER_UNAVAILABLE;
 }
 
 static HANDLE rpcrt4_conn_tcp_get_wait_handle(RpcConnection *Connection)
 {
-  return NULL;
+  assert(0);
+  return 0;
 }
 
 static RPC_STATUS rpcrt4_conn_tcp_handoff(RpcConnection *old_conn, RpcConnection *new_conn)
 {
+  assert(0);
   return RPC_S_SERVER_UNAVAILABLE;
 }
 
 static int rpcrt4_conn_tcp_read(RpcConnection *Connection,
                                 void *buffer, unsigned int count)
 {
-  return -1;
+  RpcConnection_tcp *tcpc = (RpcConnection_tcp *) Connection;
+  int r = read(tcpc->sock, buffer, count);
+  TRACE("%d %p %u -> %d\n", tcpc->sock, buffer, count, r);
+  return r;
 }
 
 static int rpcrt4_conn_tcp_write(RpcConnection *Connection,
                                  const void *buffer, unsigned int count)
 {
-  return -1;
+  RpcConnection_tcp *tcpc = (RpcConnection_tcp *) Connection;
+  int r = write(tcpc->sock, buffer, count);
+  TRACE("%d %p %u -> %d\n", tcpc->sock, buffer, count, r);
+  return r;
 }
 
 static int rpcrt4_conn_tcp_close(RpcConnection *Connection)
 {
-  return -1;
+  RpcConnection_tcp *tcpc = (RpcConnection_tcp *) Connection;
+
+  TRACE("%d\n", tcpc->sock);
+  if (tcpc->sock)
+    close(tcpc->sock);
+  tcpc->sock = 0;
+  return 0;
 }
 
 struct protseq_ops protseq_list[] = {
@@ -308,6 +382,8 @@ static struct protseq_ops *rpcrt4_get_pr
   return NULL;
 }
 
+/**** interface to rest of code ****/
+
 RPC_STATUS RPCRT4_OpenConnection(RpcConnection* Connection)
 {
   TRACE("(Connection == ^%p)\n", Connection);




More information about the wine-cvs mailing list