/*
- * 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"
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) {
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);
/*
* 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 */
/* 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... */