]> code.citadel.org Git - citadel.git/blobdiff - citadel/ipc_c_tcp.c
* commands.c, control.c, cux2ascii.c, file_ops.c, import.c,
[citadel.git] / citadel / ipc_c_tcp.c
index c3d5aa4c5281e0d6c8b9bef5c31d493609c5b749..9e5b4805721e80b49da4cc105d601697fb79765d 100644 (file)
@@ -3,7 +3,7 @@
  * 
  * Citadel/UX client/server IPC - client module using TCP/IP
  *
- * version 1.3
+ * version 1.3 $Id$
  *
  */
 
@@ -121,7 +121,7 @@ int connectsock(char *host, char *service, char *protocol)
  * convert service and host entries into a six-byte numeric in the format
  * expected by a SOCKS v4 server
  */
-void numericize(unsigned char *buf, char *host, char *service, char *protocol)
+void numericize(char *buf, char *host, char *service, char *protocol)
 {
        struct hostent *phe;
        struct servent *pse;
@@ -204,13 +204,25 @@ void serv_write(char *buf, int nbytes)
  */
 void serv_gets(char *buf)
 {
-       buf[0] = 0;
-       do {
-               buf[strlen(buf) + 1] = 0;
-               if (strlen(buf) < 255) serv_read(&buf[strlen(buf)], 1);
-               } while (buf[strlen(buf)-1] != 10);
-       if (strlen(buf) > 0) buf[strlen(buf)-1] = 0;
-       /* printf("> %s\n", buf); */
+       int i;
+
+       /* Read one character at a time.
+        */
+       for (i = 0;;i++) {
+               serv_read(&buf[i], 1);
+               if (buf[i] == '\n' || i == 255)
+                       break;
+               }
+
+       /* If we got a long line, discard characters until the newline.
+        */
+       if (i == 255)
+               while (buf[i] != '\n')
+                       serv_read(&buf[i], 1);
+
+       /* Strip the trailing newline.
+        */
+       buf[i] = 0;
        }
 
 
@@ -234,7 +246,7 @@ void attach_to_server(int argc, char **argv)
        char cithost[256];      int host_copied = 0;
        char citport[256];      int port_copied = 0;
        char socks4[256];
-       unsigned char buf[256];
+       char buf[256];
        struct passwd *p;
 
        strcpy(cithost,DEFAULT_HOST);   /* default host */
@@ -283,7 +295,7 @@ void attach_to_server(int argc, char **argv)
        printf("Attaching to server...\r");
        fflush(stdout);
 
-       sprintf(buf,"%c%c",
+       snprintf(buf,sizeof buf,"%c%c",
                4,                      /* version 4 */
                1);                     /* method = connect */
        serv_write(buf,2);