$Log$
+Revision 211.4 2000/03/19 19:49:31 ajc
+* Added support for unix domain sockets
+
Revision 211.3 2000/02/11 23:45:04 nbryant
* Makefile.in, configure.in: add, like, some *more* code for FreeBSD
* tcp_sockets.c: include <arpa/inet.h>
1998-12-03 Nathan Bryant <bryant@cs.usm.maine.edu>
* webserver.c: warning fix
-
WEBCIT for the Citadel/UX System
- version 2.11
+ version 2.12
- Copyright (C) 1996-1999 by Art Cancro, Nathan Bryant, and Nick Grossman
+ Copyright (C) 1996-2000 by Art Cancro, Nathan Bryant, and Nick Grossman
This program is free software released under the terms of the GNU General
Public License. Please read COPYING.txt for more licensing information.
webserver [-p localport] [-t tracefile] [remotehost [remoteport]]
+ *or*
+
+ webserver [-p localport] [-t tracefile] uds /your/citadel/directory
+
Explained:
-> localport: the TCP port on which you wish your WebCit server to run.
-> remoteport: the port number on which your Citadel/UX server is running.
The default is port 504, the IANA-designated standard port for Citadel.
+ -> "uds" is a keyword which tells WebCit that you wish to connect to a
+ Citadel server running on the same computer, rather than using a TCP/IP
+ socket. /your/citadel/directory should be set to the actual name of the
+ directory in which you have Citadel installed
+ (such as /usr/local/citadel). If you run Citadel and WebCit on the same
+ computer, you should set it up this way; it runs a bit faster.
+
GRAPHICS
--------
#include <limits.h>
#include <netinet/in.h>
#include <arpa/inet.h>
+#include <sys/un.h>
#include <netdb.h>
#include <string.h>
#include <pwd.h>
exit(3);
}
-int connectsock(char *host, char *service, char *protocol)
+
+
+/*
+ * Connect a unix domain socket
+ */
+int uds_connectsock(char *sockpath)
+{
+ struct sockaddr_un sun;
+ int s;
+
+ memset(&sun, 0, sizeof(sun));
+ sun.sun_family = AF_UNIX;
+ strncpy(sun.sun_path, sockpath, sizeof sun.sun_path);
+
+ s = socket(AF_UNIX, SOCK_STREAM, 0);
+ if (s < 0) {
+ fprintf(stderr, "Can't create socket: %s\n",
+ strerror(errno));
+ return(-1);
+ }
+
+ if (connect(s, (struct sockaddr *) &sun, sizeof(sun)) < 0) {
+ fprintf(stderr, "can't connect: %s\n",
+ strerror(errno));
+ return(-1);
+ }
+
+ return s;
+}
+
+
+/*
+ * Connect a TCP/IP socket
+ */
+int tcp_connectsock(char *host, char *service)
{
struct hostent *phe;
struct servent *pse;
struct protoent *ppe;
struct sockaddr_in sin;
- int s, type;
+ int s;
bzero((char *) &sin, sizeof(sin));
sin.sin_family = AF_INET;
- pse = getservbyname(service, protocol);
+ pse = getservbyname(service, "tcp");
if (pse) {
sin.sin_port = pse->s_port;
} else if ((sin.sin_port = htons((u_short) atoi(service))) == 0) {
host, strerror(errno));
return (-1);
}
- if ((ppe = getprotobyname(protocol)) == 0) {
- fprintf(stderr, "Can't get %s protocol entry: %s\n",
- protocol, strerror(errno));
+ if ((ppe = getprotobyname("tcp")) == 0) {
+ fprintf(stderr, "Can't get TCP protocol entry: %s\n",
+ strerror(errno));
return (-1);
}
- if (!strcmp(protocol, "udp"))
- type = SOCK_DGRAM;
- else
- type = SOCK_STREAM;
- s = socket(PF_INET, type, ppe->p_proto);
+ s = socket(PF_INET, SOCK_STREAM, ppe->p_proto);
if (s < 0) {
fprintf(stderr, "Can't create socket: %s\n", strerror(errno));
return (-1);
strcpy(c_host, bstr("host"));
if (strlen(bstr("port")) > 0)
strcpy(c_port, bstr("port"));
- WC->serv_sock = connectsock(c_host, c_port, "tcp");
+
+ if (!strcasecmp(c_host, "uds")) {
+ /* unix domain socket */
+ sprintf(buf, "%s/citadel.socket", c_port);
+ WC->serv_sock = uds_connectsock(buf);
+ }
+ else {
+ /* tcp socket */
+ WC->serv_sock = tcp_connectsock(c_host, c_port);
+ }
+
if (WC->serv_sock < 0) {
do_logout();
}
#define SLEEPING 180 /* TCP connection timeout */
#define WEBCIT_TIMEOUT 900 /* WebCit session timeout */
#define PORT_NUM 2000 /* port number to listen on */
-#define SERVER "WebCit v2.11" /* who's in da house */
+#define SERVER "WebCit v2.12" /* who's in da house */
#define DEVELOPER_ID 0
#define CLIENT_ID 4
-#define CLIENT_VERSION 211
+#define CLIENT_VERSION 212
#define DEFAULT_HOST "localhost" /* Default Citadel server */
#define DEFAULT_PORT "504"
#define LB (1) /* Internal escape chars */
void gotonext(void);
void ungoto(void);
void get_serv_info(char *, char *);
-int connectsock(char *host, char *service, char *protocol);
+int uds_connectsock(char *);
+int tcp_connectsock(char *, char *);
void serv_gets(char *strbuf);
void serv_puts(char *string);
void whobbs(void);