*
* Citadel/UX client/server IPC - client module using TCP/IP
*
- * version 1.3
+ * version 1.3 $Id$
*
*/
#include <string.h>
#include <pwd.h>
#include <errno.h>
+#include <stdarg.h>
+#include "citadel.h"
#include "citadel_decls.h"
#include "ipc.h"
+#ifndef HAVE_SNPRINTF
+#include "snprintf.h"
+#endif
/*
* If server_is_local is set to nonzero, the client assumes that it is running
struct sockaddr_in sin;
int s,type;
- bzero((char *)&sin,sizeof(sin));
+ memset(&sin,0,sizeof(sin));
sin.sin_family = AF_INET;
pse=getservbyname(service,protocol);
struct servent *pse;
struct sockaddr_in sin;
- bzero((char *)&sin,sizeof(sin));
+ memset(&sin,0,sizeof(sin));
sin.sin_family = AF_INET;
pse=getservbyname(service,protocol);
while(len<bytes) {
rlen = read(serv_sock,&buf[len],bytes-len);
if (rlen<1) {
- printf("\rNetwork error - connection terminated.\n");
- printf("%s\n", strerror(errno));
+ /* printf("\rNetwork error - connection terminated.\n");
+ printf("%s\n", strerror(errno)); */
logoff(3);
}
len = len + rlen;
retval = write(serv_sock, &buf[bytes_written],
nbytes - bytes_written);
if (retval < 1) {
+ /*
printf("\rNetwork error - connection terminated.\n");
- printf("%s\n", strerror(errno));
+ printf("%s\n", strerror(errno)); */
logoff(3);
}
bytes_written = bytes_written + retval;
*/
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;
}
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);