Changeset - 8af872d2fe8d
[Not reviewed]
default
0 2 0
Nathan Brink (binki) - 16 years ago 2009-10-30 17:37:48
ohnobinki@ohnopublishing.net
remoteio socket open() support
2 files changed with 41 insertions and 1 deletions:
0 comments (0 inline, 0 general)
src/common/libremoteio.h
Show inline comments
 
@@ -55,12 +55,15 @@ struct remoteio_opts
 
};
 

	
 
struct remoteio {
 
  enum remoteio_method method;
 
  struct remoteio_opts *opts;
 
  struct execio *execio;
 
#ifndef WINDOWS
 
  int sock;
 
#endif
 
};
 

	
 

	
 
/* lookup table */
 
typedef int remoteio_open_func_t(struct remoteio *rem, struct remoteio_server *server);
 
typedef int remoteio_read_func_t(struct remoteio *rem, void *buf, size_t len, size_t *bytesread);
src/common/remoteio.c
Show inline comments
 
@@ -22,12 +22,16 @@
 
#include "execio.h"
 
#include "asprintf.h"
 

	
 
#include <stdlib.h>
 
#include <stdio.h>
 
#include <string.h>
 
#ifndef WINDOWS
 
#include <sys/socket.h>
 
#include <sys/un.h>
 
#endif
 

	
 
/* local */
 

	
 
int _remoteio_ssh_open(struct remoteio *rem, struct remoteio_server *server);
 
int _remoteio_ssh_read(struct remoteio *rem, void *buf, size_t len, size_t *bytesread);
 
int _remoteio_ssh_write(struct remoteio *rem, void *buf, size_t len, size_t *byteswritten);
 
@@ -267,14 +271,47 @@ int _remoteio_ssh_close(struct remoteio 
 
#ifndef WINDOWS
 
/*
 
  local sockets implementation (``named pipes''), unix-only
 
 */
 
int _remoteio_sock_open(struct remoteio *rem, struct remoteio_server *server)
 
{
 
  int sock;
 
  struct sockaddr_un sockaddr;
 
  /*
 
    The POSIX docs pretty much say that I can't depend on sockpath being able to be longer than 
 
    some proprietary length. So, if the compiler specifies a long path for RUNSTATEDIR, it could
 
    cause a buffer overflow.
 
   */
 
  char *sockpath = RUNSTATEDIR "/distrend.sock";
 
  unsigned int sockaddr_len;
 

	
 
  return 1;
 
  sock = socket(AF_UNIX, SOCK_STREAM, 0);
 
  if(sock == -1)
 
    {
 
      perror("socket");
 
      return 1;
 
    }
 

	
 
  sockaddr.sun_family = AF_UNIX;
 
  /*
 
    The terminating NULL should not be included in what's copied to sun_path,
 
    although it won't hurt as long as strlen(sockpath) < max socket length
 
   */
 
  for(sockaddr_len = 0; sockpath[sockaddr_len]; sockaddr_len ++)
 
    sockaddr.sun_path[sockaddr_len] = sockpath[sockaddr_len];
 

	
 
  if(connect(sock, (struct sockaddr *)&sockaddr, sockaddr_len) == -1)
 
    {
 
      perror("connect");
 
      close(sock);
 
      return 1;
 
    }
 

	
 
  rem->sock = sock;
 

	
 
  return 0;
 
}
 

	
 
int _remoteio_sock_read(struct remoteio *rem, void *buf, size_t len, size_t *bytesread)
 
{
 

	
 
  return 1;
0 comments (0 inline, 0 general)