1 /* $Id: localopen.c 6155 2003-01-19 19:58:25Z rra $
8 #include <sys/socket.h>
10 #include "inn/innconf.h"
15 #if HAVE_UNIX_DOMAIN_SOCKETS
21 ** Open a connection to the local InterNetNews NNTP server and optionally
22 ** create stdio FILE's for talking to it. Return -1 on error.
25 NNTPlocalopen(FILE **FromServerp, FILE **ToServerp, char *errbuff)
27 #if defined(HAVE_UNIX_DOMAIN_SOCKETS)
31 struct sockaddr_un server;
33 char mybuff[NNTP_STRLEN + 2];
36 buff = errbuff ? errbuff : mybuff;
39 /* Create a socket. */
40 if ((i = socket(AF_UNIX, SOCK_STREAM, 0)) < 0)
43 /* Connect to the server. */
44 memset(&server, 0, sizeof server);
45 server.sun_family = AF_UNIX;
46 strlcpy(server.sun_path, innconf->pathrun, sizeof(server.sun_path));
47 strlcat(server.sun_path, "/", sizeof(server.sun_path));
48 strlcat(server.sun_path, _PATH_NNTPCONNECT, sizeof(server.sun_path));
49 if (connect(i, (struct sockaddr *)&server, SUN_LEN(&server)) < 0) {
56 /* Connected -- now make sure we can post. */
57 if ((F = fdopen(i, "r")) == NULL) {
63 if (fgets(buff, sizeof mybuff, F) == NULL) {
70 if (j != NNTP_POSTOK_VAL && j != NNTP_NOPOSTOK_VAL) {
72 /* This seems like a reasonable error code to use... */
78 if ((*ToServerp = fdopen(dup(i), "w")) == NULL) {
86 return NNTPconnect("127.0.0.1", innconf->port, FromServerp, ToServerp,
88 #endif /* defined(HAVE_UNIX_DOMAIN_SOCKETS) */