]> code.citadel.org Git - citadel.git/blobdiff - citadel/ipc_c_tcp.c
* The size constant "256" which shows up everywhere as a buffer size has now
[citadel.git] / citadel / ipc_c_tcp.c
index 009c69722c977e305fe7ed9376d8474e38df25a2..b49c6f1f2f5cf47074edd473486a32930fee8bb4 100644 (file)
@@ -1,13 +1,11 @@
 /*
- * ipc_c_tcp.c
+ * $Id$
  * 
- * Citadel/UX client/server IPC - client module using TCP/IP
- *
- * version 1.3 $Id$
+ * Client-side IPC functions
  *
  */
 
-#define        UDS                     "citadel unix domain socket type of thing"
+#define        UDS                     "_UDS_"
 
 #define DEFAULT_HOST           UDS
 #define DEFAULT_PORT           "citadel"
@@ -128,12 +126,13 @@ int connectsock(char *host, char *service, char *protocol)
 
 int uds_connectsock(char *sockpath)
 {
-       struct sockaddr_un sun;
+       struct sockaddr_un addr;
        int s;
 
-       memset(&sun, 0, sizeof(sun));
-       sun.sun_family = AF_UNIX;
-       strncpy(sun.sun_path, sockpath, sizeof sun.sun_path);
+
+       memset(&addr, 0, sizeof(addr));
+       addr.sun_family = AF_UNIX;
+       strncpy(addr.sun_path, sockpath, sizeof addr.sun_path);
 
        s = socket(AF_UNIX, SOCK_STREAM, 0);
        if (s < 0) {
@@ -142,7 +141,7 @@ int uds_connectsock(char *sockpath)
                logoff(3);
        }
 
-       if (connect(s, (struct sockaddr *) &sun, sizeof(sun)) < 0) {
+       if (connect(s, (struct sockaddr *) &addr, sizeof(addr)) < 0) {
                fprintf(stderr, "can't connect: %s\n",
                        strerror(errno));
                logoff(3);
@@ -270,22 +269,23 @@ void serv_puts(char *buf)
 /*
  * attach to server
  */
-void attach_to_server(int argc, char **argv)
+void attach_to_server(int argc, char **argv, char *hostbuf, char *portbuf)
 {
        int a;
-       char cithost[256];
+       char cithost[SIZ];
        int host_copied = 0;
-       char citport[256];
+       char citport[SIZ];
        int port_copied = 0;
-       char socks4[256];
-       char buf[256];
+       char socks4[SIZ];
+       char buf[SIZ];
        struct passwd *p;
-       char sockpath[256];
+       char sockpath[SIZ];
 
        strcpy(cithost, DEFAULT_HOST);  /* default host */
        strcpy(citport, DEFAULT_PORT);  /* default port */
        strcpy(socks4, "");     /* SOCKS v4 server */
 
+
        for (a = 0; a < argc; ++a) {
                if (a == 0) {
                        /* do nothing */
@@ -314,14 +314,18 @@ void attach_to_server(int argc, char **argv)
 
        /* If we're using a unix domain socket we can do a bunch of stuff */
        if (!strcmp(cithost, UDS)) {
-               sprintf(sockpath, "%s/citadel.socket", BBSDIR);
+               sprintf(sockpath, "citadel.socket");
                serv_sock = uds_connectsock(sockpath);
+               if (hostbuf != NULL) strcpy(hostbuf, cithost);
+               if (portbuf != NULL) strcpy(portbuf, sockpath);
                return;
        }
 
        /* if not using a SOCKS proxy server, make the connection directly */
        if (strlen(socks4) == 0) {
                serv_sock = connectsock(cithost, citport, "tcp");
+               if (hostbuf != NULL) strcpy(hostbuf, cithost);
+               if (portbuf != NULL) strcpy(portbuf, citport);
                return;
        }
        /* if using SOCKS, connect first to the proxy... */