🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: news.software.nntp
Article #3399

Suck/Poll News

#3399
From: Mail Account for root
Date: Sun, 26 Feb 1995 01:11
1012 lines
34252 bytes
After so many request for it I decided to post my package "nntppoll". It is
a tool that allows you to poll news from a nntp server and post it locally.
The package is based on the package "suck" - in fact it reuses quite a bit
of it's code - but is faster and more monolithic.

I provide the package as-is without any written or implicit warranty. I use
it myself of a linux system and have tested it only there - but porting
shouldn't be too difficult.

---- Cut Here and unpack ----
#!/bin/sh
# shar:	Shell Archiver  (v1.22)
#	Packed Sat Feb 25 16:18:35 EST 1995 by btoy1!root
#	from directory /tmp
#
#	Run the following text with /bin/sh to create:
#	  nntppoll/.nntppoll.rc
#	  nntppoll/Makefile
#	  nntppoll/nntppoll.c
#	  nntppoll/nntppoll.h
#	  nntppoll/nntppoll.man
#
echo "x - extracting nntppoll/.nntppoll.rc (Text)"
sed 's/^X//' << 'SHAR_EOF' > nntppoll/.nntppoll.rc &&
X# /usr/lib/news/.nntppoll.rc, created by nntppoll, Version 1.1, 25-Jan-1995
X# Sat Feb 25 08:16:03 1995
Xalt.answers 7601
Xalt.bbs.internet 25973
Xalt.bbs 41489
Xalt.os.linux 1416
Xalt.sex.stories 55660
Xalt.sources 12289
Xalt.uu.comp.os.linux.questions 3202
Xbiz.comp.services 5851
Xcomp.archives 17132
Xcomp.mail.elm 17963
Xcomp.mail.headers 2394
Xcomp.mail.sendmail 18834
Xcomp.mail.uucp 14899
Xcomp.os.linux.admin 27321
Xcomp.os.linux.advocacy 3294
Xcomp.os.linux.announce 3590
Xcomp.os.linux.answers 57
Xcomp.os.linux.development.apps 1254
Xcomp.os.linux.development.system 2541
Xcomp.os.linux.development 27111
Xcomp.os.linux.hardware 3840
Xcomp.os.linux.help 93326
Xcomp.os.linux.misc 41165
Xcomp.os.linux.networking 2738
Xcomp.os.linux.setup 3865
Xcomp.os.linux.x 3462
Xcomp.unix.admin 31508
Xcomp.unix.pc-clone.32bit 9414
Xcomp.unix.shell 24378
Xde.comp.os.linux 31774
Xfido.ger.linux 8052
Xmaus.os.linux 6506
Xnews.admin.misc 33287
Xnews.answers 38611
Xnews.groups 135712
Xnews.newusers.questions 52002
Xservtech.announce 114
Xservtech.general 273
Xservtech.ppp 202
Xsoc.culture.german 58596
Xwny.events 643
Xwny.general 616
Xwny.news 18
Xwny.rochester.freenet 0
Xwny.rocslug 0
Xwny.seminar 259
Xwny.test 0
Xwny.unix-wizards 0
Xwny.wanted 411
Xwny.wbfo 1325
Xwny.yumyum 0
SHAR_EOF
chmod 0644 nntppoll/.nntppoll.rc || echo "restore of nntppoll/.nntppoll.rc fails"
echo "x - extracting nntppoll/Makefile (Text)"
sed 's/^X//' << 'SHAR_EOF' > nntppoll/Makefile &&
X#
X# Makefile generated with genmake - version 1.1  08/22/92
X#
X# genmake is Copyright 1991 by Edwin R. Carp
X#
X# GENMAKE [files]
X#
X
XCC = gcc -O6 -Wall -pipe -m386
XCFLAGS =  $(INCLUDE)
XLDFLAGS = -s
X
XSOURCES = nntppoll.c 
XOBJECTS = nntppoll.o 
XPROGRAMS = nntppoll 
X
XBINDIR = /usr/local/bin
XMANDIR = /usr/local/man/man1
X
Xall: $(PROGRAMS) 
X
Xnntppoll: nntppoll.o 
X	$(CC) $(CFLAGS) -o nntppoll nntppoll.o $(LDFLAGS)  -O
X
Xinstall: $(PROGRAMS)
X	install -m 755 -o bin -g bin $(PROGRAMS) $(BINDIR)
X
Xclean:
X	/bin/rm -f $(OBJECTS) MAKELOG eddep makedep *~
X
Xclobber:
X	/bin/rm -f $(OBJECTS) $(PROGRAMS) MAKELOG eddep makedep *~ *.bak *.BAK
Xhidden:
X	echo "make all > MAKELOG 2>&1 &"|/bin/sh
X
Xmakefile:
X	genmake $(SOURCES) &
X
Xmakeall:
X	genmake *.c &
X
SHAR_EOF
chmod 0644 nntppoll/Makefile || echo "restore of nntppoll/Makefile fails"
echo "x - extracting nntppoll/nntppoll.c (Text)"
sed 's/^X//' << 'SHAR_EOF' > nntppoll/nntppoll.c &&
X/********************************************************************
X * nntppoll.c - poll news from a NNTP server and
X *              write them to the local news spool
X *
X * 1.0  24-Jan-1995 TB  First version
X * 1.1  25-Jan-1995 TB  Unit-tested
X * 1.2  25-Feb-1995 TB  Make sure that all return values are reported
X *                       correctly
X ********************************************************************/
X
X/* Includes */
X#include <stdio.h>
X#include <stdlib.h>
X#include <sys/types.h>
X#include <sys/socket.h>
X#include <netinet/in.h>
X#include <arpa/inet.h>
X#include <netdb.h>
X#include <sys/time.h>
X#include <string.h>
X#include <unistd.h>
X#include <ctype.h>
X#include "nntppoll.h"
X
X/* Prototypes */
Xint                 nntp_transfer (int SockFD);
Xint                 get_message_id_list (int SockFD);
Xint                 get_articles (int SockFD);
X
Xchar                *basename (char *name);
Xint                 nntp_open (char *hostname);
Xvoid                nntp_close (int SockFD);
Xint                 sgets (int SockFD, char *sTempBuf, int maxlen);
Xint                 sputs (int SockFD, char *outTempBuf);
Xchar                *number (char *sp, int *intPtr);
X
Xint main (int argc, char **argv)
X{
X    /* Local variables */
X    int             OptRet;
X    char            DebugFName[TEMPBUF_LEN / 4] = {0},
X                    NNTPServer[TEMPBUF_LEN / 4] = {0},
X                    PIDFName[] = "/tmp/nntppoll.pid",
X                    SysCmd[TEMPBUF_LEN / 4];
X    time_t          Time;
X    FILE            *PIDFile;
X
X    /* Preset the result code */
X    ResultCode = ALL_OK;
X
X    /* Get the current time */
X    Time = time(NULL);
X    strcpy (DateString, ctime(&Time));
X
X    /* Get the program name */
X    strcpy (ProgName, basename (argv[0]));
X    fprintf (stderr, "%s Version %s\nStarted: %s",
X                     ProgName, VERSION, DateString);
X
X    /* Is the program already running ? */
X    PIDFile = fopen (PIDFName, "r");
X    if (PIDFile != NULL)
X    {
X        /* No -> Spit out some error message */
X        fprintf (stderr, "%s: ERROR %d: %s already running\n",
X                         ProgName, PROG_ALREADY_RUNNING, ProgName);
X
X        /* Show the contents of the file */
X        while ((fgets (SysCmd, sizeof (SysCmd), PIDFile)) != NULL)
X        {
X            printf ("\t%s", SysCmd);
X        }   /* end while fgets */
X        fclose (PIDFile);
X
X        /* Terminate this program */
X        exit (PROG_ALREADY_RUNNING);
X    }   /* end if PIDFile */
X
X    /* Get the pid of the program */
X    PID = getpid();
X
X    /* Can we write it out ? */
X    PIDFile = fopen (PIDFName, "w");
X    if (PIDFile != NULL)
X    {
X        /* Yes -> Do it */
X        fprintf (PIDFile, "PID: %d\nUser: %s\nProgram: %s\nVersion: %s\nStarted: %s",
X                          PID, getenv("LOGNAME"), ProgName, VERSION, DateString);
X        fclose (PIDFile);
X    }
X    else
X    {
X        /* No -> Spit out some error message */
X        fprintf (stderr, "%s: ERROR %d: %s can not be created\n",
X                         ProgName, NO_PID_FILE, PIDFName);
X
X        /* Terminate this program */
X        exit (NO_PID_FILE);
X    }   /* end if PIDFile */
X    
X    /* Check the options */
X    while ((OptRet = getopt(argc, argv, "hdvD:r:t")) != -1)
X    {
X        switch (OptRet)
X        {
X            case 'd':   /* Send debug info to syslog */
X                SyslogFlag = 1;
X                break;
X
X            case 'D':   /* Send debug info to named file */
X                strcpy (DebugFName, optarg);
X                break;
X
X            case 'r':   /* Use different rcfile */
X                strcpy (RCName, optarg);
X                break;
X
X            case 't':   /* Testmode only */
X                TestFlag = 1;
X                break;
X
X            case 'v':   /* Set the verbose flag */
X                VerboseFlag = 1;
X                break;
X
X            case 'h':
X            case '?':
X              printf ("%s: [Options] news-server\n", argv[0]);
X              printf ("  -h             Show this help\n");
X              printf ("  -d             Log debug info via syslogd\n");
X              printf ("  -D filename    Log debug info to filename\n");
X              printf ("  -r filename    Use filename as rc file\n");
X              printf ("  -v             Show nntp actions\n");
X              ResultCode = HELP_REQ;
X              break;
X
X            default:
X              printf ("Unknown option %c\n", OptRet);
X              break;
X        }   /* end switch OptRet */
X    }   /* end while OptRet */
X
X    /* Was everyting okay so far ? */
X    if (ResultCode == ALL_OK)
X    {
X        /* Yes -> Should we open a debug file ? */
X        if (DebugFName[0] != '\0')
X        {
X            /* Yes -> Try to open it */
X            DebugFile = fopen (DebugFName, "w");
X            if (VerboseFlag)
X                printf ("%s: Debug info will be written to %s\n",
X                        ProgName, DebugFName);
X        }   /* end if DebugFName */
X
X        /* Is a news-server specified ? */
X        if (optind < argc)
X        {
X            /* Yes -> Get it's name */
X            strcpy (NNTPServer, argv[optind]);
X        }
X        else
X        {
X            /* No -> Try to get the environment variable */
X            if (getenv ("NNTPSERVER") != NULL)
X                strcpy (NNTPServer, getenv ("NNTPSERVER"));
X        }   /* end if optind */
X
X        /* Do we have a valid news-server ? */
X        if (NNTPServer[0] != '\0')
X        {
X            /* Yes -> Can we to open it ? */
X            if (DebugFile != NULL)
X                fprintf (DebugFile, "DEBUG Newsserver is %s\n", NNTPServer);
X            nntp_socket = nntp_open (NNTPServer);
X            if (nntp_socket >= 0)
X            {
X                /* Yes -> Can we transfer ? */
X                if (nntp_transfer (nntp_socket) == 0)
X                {
X                    /* Yes -> Close the connection */
X                    nntp_close (nntp_socket);
X
X                    /* Update the rc file */
X                    sprintf (SysCmd, "mv /tmp/nntppoll.rc.tmp.%d %s",
X                                     PID, RCName);
X                    if (VerboseFlag)
X                        printf ("%s: Updating rc file %s\n",
X                                ProgName, RCName);
X                    system (SysCmd);
X                }
X            }   /* end if nntp_socket */
X        }
X        else
X        {
X            /* No -> Spit out some error message */
X            fprintf (stderr, "%s: ERROR %d: No news server found\n",
X                             ProgName, NO_NNTPSERVER);
X            ResultCode = NO_NNTPSERVER;
X        }   /* end if NNTPServer */
X
X        /* Close the debug file (if necessary) */
X        if (DebugFile != NULL)
X            fclose (DebugFile);
X    }   /* end if ResultCode */
X
X    /* Remove the PID file */
X    unlink (PIDFName);
X
X    /* Get the current time */
X    Time = time(NULL);
X    strcpy (DateString, ctime(&Time));
X
X    /* Show some good-bye message */    
X    fprintf (stderr, "%s Version %s\nEnded : %s",
X                     ProgName, VERSION, DateString);
X
X    /* Report back the result code */
X    return (ResultCode);
X}   /* end main */
X
X/* Maintain the actual NNTP transfer */
Xint nntp_transfer (int SockFD)
X{
X    /* Local variables */
X    char            TempBuffer[TEMPBUF_LEN],
X                    FileName[TEMPBUF_LEN / 4],
X                    SysCmd[TEMPBUF_LEN / 2];
X    int             NoArticles,
X            ResultCode = 0;
X
X    /* Get the announcement line */
X    if (sgets (SockFD, TempBuffer, TEMPBUF_LEN) < 1)
X        return (-1);
X
X    if (VerboseFlag)
X        printf ("%s: %s\n", ProgName, TempBuffer);
X
X    /* Tell the server we are a reader */
X    sputs (SockFD, "mode reader\r\n");
X    if (sgets (SockFD, TempBuffer, TEMPBUF_LEN) < 1)
X        return(-1);
X
X    if (VerboseFlag)
X        printf ("%s: %s\n", ProgName, TempBuffer);
X
X    /* The the article message IDs */
X    NoArticles = get_message_id_list (SockFD);
X    if ((NoArticles >= 0) && (VerboseFlag))
X        printf ("%s: %d articles found\n",ProgName, NoArticles);
X
X    /* Did we get any articles ? */
X    if (NoArticles > 0)
X    {
X        /* Yes -> Sort the message IDs and remove duplicates */
X        sprintf (SysCmd, "sort -u /tmp/nntppoll.index.%d > /tmp/nntppoll.sorted.%d",
X                         PID, PID);
X        if (VerboseFlag)
X            printf ("%s: Removing duplicates of message IDs\n", ProgName);
X        system (SysCmd);
X
X        /* Get rid of the orginal index file */
X        sprintf (FileName, "/tmp/nntppoll.index.%d", PID);
X        unlink (FileName);
X
X        /* Get the articles themselves */
X        ResultCode = get_articles (SockFD);
X    }
X    else
X    {
X        /* No -> Get rid of the orginal index file */
X        sprintf (FileName, "/tmp/nntppoll.index.%d", PID);
X        unlink (FileName);
X
X        ResultCode = NoArticles;
X    }   /* end if NoArticles */
X
X    return (ResultCode);
X}   /* end nntp_transfer */
X
Xint get_message_id_list (int SockFD)
X{
X    /* Local variables */
X    int             NoArticles = 0,
X                    NoArgs,
X                    Count,
X                    High,
X                    Low,
X                    Response,
X                    LastRead;
X    char            *sp,
X                    TempBuf[TEMPBUF_LEN],
X                    RCLine[TEMPBUF_LEN / 2],
X                    GroupName[TEMPBUF_LEN / 2];
X
X    FILE            *IndexFile,
X                    *RCFile,
X                    *TempFile;
X
X    /* Can we open the rc file ? */
X    RCFile = fopen (RCName, "r");
X    if (RCFile == NULL)
X    {
X        /* No -> Spit out some error message */
X        fprintf (stderr, "%s: ERROR %d: %s does not exist\n",
X                         ProgName, NO_RC_FILE, RCName);
X        ResultCode = NO_RC_FILE;
X
X        /* Terminate this function */
X        return (-1);
X    }   /* end if RCFile */
X    if (VerboseFlag)
X        printf ("%s: Reading rcfile %s\n", ProgName, RCName);
X
X    /* Can we open the temp file ? */
X    sprintf (TempBuf, "/tmp/nntppoll.rc.tmp.%d", PID);
X    TempFile = fopen (TempBuf, "w");
X    if (TempFile == NULL)
X    {
X        /* No -> Spit out some error message */
X        fprintf (stderr, "%s: ERROR %d: %s can not be created\n",
X                         ProgName, NO_TMP_FILE, TempBuf);
X        ResultCode = NO_TMP_FILE;
X
X        /* Terminate this function */
X        return (-1);
X    }
X    else
X    {
X        /* Yes -> Write out a title line */
X        fprintf (TempFile, "# %s, created by %s, Version %s\n# %s",
X                           RCName, ProgName, VERSION, DateString);
X    }   /* end if TempFile */
X
X    /* Can we open the index file ? */
X    sprintf (TempBuf, "/tmp/nntppoll.index.%d", PID);
X    IndexFile = fopen (TempBuf, "w");
X    if (IndexFile == NULL)
X    {
X        /* No -> Spit out some error message */
X        fprintf (stderr, "%s: ERROR %d: %s can not be created\n",
X                         ProgName, NO_INDEX_FILE, TempBuf);
X        ResultCode = NO_INDEX_FILE;
X
X        /* Terminate this function */
X        return (-1);
X    }   /* end if IndexFile */
X
X    /* Now read line by line from the rc file */
X    while ((fgets (RCLine, sizeof (GroupName), RCFile)) != NULL)
X    {
X        /* Is it an empty of comment line ? */
X        if ((RCLine[0] != '\n') && (RCLine[0] != '#'))
X        {
X            /* No -> Get the groupname and the last read number */
X            NoArgs = sscanf (RCLine, "%s %d\n", GroupName, &LastRead);
X
X            /* Did we get any arguments ? */
X            if (NoArgs > 0)
X            {
X                /* Yes -> Did we get a last read number ? */
X                if (NoArgs == 1)
X                {
X                    /* No -> Start with 0 */
X                    LastRead = 0;
X                }   /* end if NoArgs */
X
X                /* Form the correct command */
X                sprintf (TempBuf, "group %s\r\n", GroupName);
X
X                /* Issue the command and read the response */
X                sputs (SockFD, TempBuf);
X                if (sgets (SockFD, TempBuf, TEMPBUF_LEN) < 1)
X                {
X                    NoArticles = 0;
X                    goto EXIT_get_message_id_list;
X                }
X                sp = number (TempBuf, &Response);
X                if (sp == NULL)
X                {
X                    /* No -> Spit out some error message */
X                    fprintf (stderr, "%s: ERROR %d: Protocol error!\n",
X                                     ProgName, PROTOCOL_ERROR);
X                    ResultCode = PROTOCOL_ERROR;
X
X                    /* Terminate this function */
X                    return (-1);
X                }
X                if (Response != 211)
X                {
X                    if (VerboseFlag)
X                        printf ("%s: GROUP <%s>, unexpected Response %d\n",
X                                     ProgName, GroupName, Response);
X                    continue;       /* next newsgroup */
X                }
X                sp = number (sp, &Count);
X                sp = number (sp, &Low);
X                sp = number (sp, &High);
X
X                fprintf (TempFile, "%s %d\n", GroupName, High);
X
X                if (LastRead && LastRead < High)
X                {
X                    if (LastRead < Low)
X                    LastRead = Low;
X                    sprintf (TempBuf, "xhdr Message-ID %d-\r\n", LastRead + 1);
X                    if (VerboseFlag)
X                        printf ("%s: %s...articles %d-%d\n", ProgName, GroupName, LastRead + 1, High);
X
X                    sputs (SockFD, TempBuf);
X                    if (sgets (SockFD, TempBuf, TEMPBUF_LEN) < 1)
X                    {
X                        NoArticles = 0;
X                        goto EXIT_get_message_id_list;
X                    }
X                    number (TempBuf, &Response);
X                    if (Response == 221)
X                    {
X                        do
X                        {
X                            if (sgets (SockFD, TempBuf, TEMPBUF_LEN) < 1)
X                            {
X                                NoArticles = 0;
X                                goto EXIT_get_message_id_list;
X                            }
X                            if (TempBuf[0] != '.')
X                            {
X                                for (sp = TempBuf; *sp != '<'; sp++);
X                                fprintf (IndexFile, "%s\n", sp);
X                                NoArticles++;
X                            }   /* end if TempBuf[0] */
X                        } while (TempBuf[0] != '.' || TempBuf[1] != '\0');
X                    }
X                    else
X                    {
X                        /* No -> Spit out some error message */
X                        fprintf (stderr, "%s: ERROR %d:  Unexpected Response %d getting IDs\n",
X                                         ProgName, UNEXPECTED_RESPONSE, Response);
X                        ResultCode = UNEXPECTED_RESPONSE;
X
X                        /* Terminate this function */
X                        return (-1);
X                    }   /* end if Response */
X                }   /* end if LastRead */
X            }   /* end if NoArgs */
X        }   /* end if GroupName[0] */
X    }   /* end while */
X
XEXIT_get_message_id_list:
X    fclose (IndexFile);
X    fclose (TempFile);
X    fclose (RCFile);
X
X    return (NoArticles);
X}   /* end get_message_id_list */
X
X/* Get article by article */
Xint get_articles (int SockFD)
X{
X    /* Local variables */
X    char            TempBuffer1[TEMPBUF_LEN],
X                    TempBuffer2[TEMPBUF_LEN],
X                    FileName[TEMPBUF_LEN / 4],
X                    MsgIDLine[TEMPBUF_LEN / 2];
X    int             Response, Len;
X    FILE            *SortedFile,
X                    *Rnews;
X
X    /* Can we open the sorted message ID file ? */
X    sprintf (FileName, "/tmp/nntppoll.sorted.%d", PID);
X    SortedFile = fopen (FileName, "r");
X    if (SortedFile != NULL)
X    {
X        /* Yes -> Read line by line */ 
X        while ((fgets (MsgIDLine, sizeof(MsgIDLine), SortedFile)) != NULL)
X        {
X            /* Open a pipe to rnews */
X            if (TestFlag)
X                Rnews = popen ("less", "w");
X            else
X                Rnews = popen (RNEWS, "w");
X
X            /* Could we open the pipe ? */
X            if (Rnews == NULL)
X            {
X                /* No -> Spit out some error message */
X                fprintf (stderr, "%s: ERROR %d: %s does not exist\n",
X                                 ProgName, NO_SORTED_FILE, RCName);
X                ResultCode = NO_RNEWS;
X
X                /* Terminate this function */
X                return (-1);
X            }   /* end if Rnews */
X
X            /* Format the command and send it */
X            sprintf (TempBuffer1, "article %s\r\n", MsgIDLine);
X            sputs (SockFD, TempBuffer1);
X
X            /* Get the response code */
X            if (sgets (SockFD, TempBuffer2, TEMPBUF_LEN) < 1)
X                return(0);
X            number (TempBuffer2, &Response);
X
X            /* Was it successful ? */
X            if (Response == 220)
X            {
X                /* Yes -> Pipe the input to rnews */
X                do
X                {
X                    Len = sgets (SockFD, TempBuffer2, TEMPBUF_LEN);
X                    if ((TempBuffer2[0] != '.') || (Len == 1))
X                        fprintf (Rnews, "%s\n", TempBuffer2);
X                } while ((Len != 1) || (TempBuffer2[0] != '.'));
X            }
X            else
X            {
X                /* No -> Show a message */
X                if (VerboseFlag)
X                    printf ("%s: Unexpected Response %d\n",
X                            ProgName, Response);
X            }   /* end if Response */
X
X            /* Close the pipe */
X            pclose (Rnews);
X        }   /* end while fgets */
X
X        /* Remove the sorted file */
X        fclose (SortedFile);
X        unlink (FileName);
X    }
X    else
X    {
X        /* No -> Spit out some error message */
X        fprintf (stderr, "%s: ERROR %d: %s does not exist\n",
X                         ProgName, NO_SORTED_FILE, RCName);
X        ResultCode = NO_SORTED_FILE;
X
X        /* Terminate this function */
X        return (-1);
X    }   /* end if SortedFile */
X
X    return (0);
X}   /* end get_articles */
X
X/* Get the basename of a file */
Xchar *basename (char *name)
X{
X    /* Local variables */
X    static char *RetCPtr;
X
X    /* Get the last occurence of '/' */
X    RetCPtr = strrchr (name, '/');
X
X    if (RetCPtr == NULL)
X        RetCPtr = name;
X    else
X        RetCPtr++;
X
X    return (RetCPtr);
X}   /* end basename */
X
X/* Open a socket to NNTP host "hostname */
Xint nntp_open (char *hostname)
X{
X    /* Local variables */
X    int             SockFD = -1;
X    char            *ptr;
X    struct hostent  *hi;
X    struct in_addr  *aptr;
X    struct in_addr  saddr;
X    struct sockaddr_in address;
X
X    if (VerboseFlag)
X        printf ("Try to get internet address of %s\n", hostname);
X    /* Can we find the internet address of the NNTP server */
X    hi = gethostbyname (hostname);
X    if (hi != NULL)
X    {
X        /* Yes -> Get all aliases */
X        while ((ptr = *(hi->h_aliases)) != NULL)
X        {
X            if (VerboseFlag)
X                printf ("%s: Alias: %s\n", ProgName, ptr);
X             hi->h_aliases++;
X        }
X
X        /* Can we use it ? */
X        if (hi->h_addrtype == AF_INET)
X        {
X            /* Yes -> Get it's address */
X            while ((aptr = (struct in_addr *) *(hi->h_addr_list)++) != NULL)
X            {
X                saddr = *aptr;
X                if (VerboseFlag)
X#ifdef OLD_GCC
X                    printf ("%s: Address: %s\n", ProgName, inet_ntoa (aptr));
X#else
X                    printf ("%s: Address: %s\n", ProgName, inet_ntoa (*aptr));
X#endif
X                if (DebugFile != NULL)
X#ifdef OLD_GCC
X                    fprintf (DebugFile, "DEBUG IP address is %s\n", inet_ntoa (aptr));
X#else
X                    fprintf (DebugFile, "DEBUG IP address is %s\n", inet_ntoa (*aptr));
X#endif
X            }
X
X            /* Can we create a socket ? */
X            SockFD = socket (AF_INET, SOCK_STREAM, 0);
X            if (SockFD >= 0)
X            {
X                /* Yes -> Set up the connection parameters */
X                if (DebugFile != NULL)
X                    fprintf (DebugFile, "DEBUG Socket %d opened\n", SockFD);
X                address.sin_family = AF_INET;
X                address.sin_port = htons (119); /* NNTP port */
X                address.sin_addr = saddr;
X
X                /* Can we connect ? */
X                if (connect (SockFD, (struct sockaddr *) &address, sizeof address) >= 0)
X                {
X                    /* Yes -> Show some message (if verbose) */
X                    if (VerboseFlag)
X                        printf ("%s: Connected to %s\n", ProgName, hi->h_name);
X                    if (DebugFile != NULL)
X                        fprintf (DebugFile, "DEBUG Connected to %s\n", hi->h_name);
X                }
X                else
X                {
X                    /* No -> Spit out some error message */
X                    fprintf (stderr, "%s: ERROR %d: No connection\n",
X                                     ProgName, NO_CONNECTION);
X                    ResultCode = NO_CONNECTION;
X                    close (SockFD);
X                }   /* end if connect */
X            }
X            else
X            {
X                /* No -> Spit out some error message */
X                fprintf (stderr, "%s: ERROR %d: No free socket\n",
X                                 ProgName, NO_FREE_SOCKET);
X                ResultCode = NO_FREE_SOCKET;
X            }   /* end if SockFD */
X
X        }
X        else
X        {
X            /* No -> Spit out some error message */
X            printf ("Unsupported address type.\n");
X            ResultCode = WRONG_ADDR_TYPE;
X        }   /* end if hi->h_addrtype */
X
X    }
X    else
X    {
X        /* No -> Spit out some error message */
X        fprintf (stderr, "%s: ERROR %d: No IP address found for %s\n",
X                         ProgName, NO_NNTPSERVER, hostname);
X        ResultCode = NO_NNTPSERVER;
X    }   /* end if hi */
X
X    /* Return the socket file descriptor */
X    if (DebugFile != NULL)
X        fprintf (DebugFile, "DEBUG Result of connection is %d\n", ResultCode);
X
X    return (SockFD);
X}   /* end nntp_open */
X
X/* Close the connection to the NNTP server */
Xvoid nntp_close (int SockFD)
X{
X    /* Send the quit command */
X    sputs (SockFD, "quit\r\n");
X    close (SockFD);
X    
X    if (VerboseFlag)
X        printf ("%s: Connection closed\n", ProgName);
X}   /* end nntp_close */
X
X/* Write one line to the socket */
Xint sputs (int SockFD, char *outTempBuf)
X{
X    if (DebugFile != NULL)
X        fprintf (DebugFile, "DEBUG sputs: %s\n", outTempBuf);
X
X    return (send (SockFD, outTempBuf, strlen (outTempBuf), 0));
X}   /* end sputs */
X
X/* Get a CR\NL terminated line from newsserver.
X   sgets doesn't really care for maxlen yet :-)
X*/
Xint sgets (int SockFD, char *sTempBuf, int maxlen)
X    
X{
X    /* Local variables */
X    int             ret;
X    char            *ptr;
X    static int      Count = 0;
X    static char     TempBuffer[TEMPBUF_LEN * 16];
X
X    /* Is there something left from last time ? */
X    if (Count > 0)
X    {
X        /* Yes -> Search for EOL */
X        ptr = strstr (TempBuffer, "\r\n");
X        if (DebugFile != NULL)
X            fprintf (DebugFile, "DEBUG Character count %d\n", Count);
X
X        /* No EOL found ? */
X        if (ptr != NULL)
X            goto returnline;
X    }   /* end if Count */
X
X    do
X    {
X        /* Get some data ... */
X        ret = recv (SockFD, &TempBuffer[Count], sizeof (TempBuffer) - Count, 0);
X
X        /* Did we get anything ? */
X        if (ret >= 1)
X        {
X            /* Yes -> Save the input */
X            Count += ret;
X            TempBuffer[Count] = '\0';    /* for strstr to work */
X
X            /* Check for EOL */
X            ptr = strstr (TempBuffer, "\r\n");
X        }
X        else
X        {
X            /* No -> Spit out some error message */
X            printf ("Socket receive error\n");
X            ResultCode = RECEIVE_ERROR;
X            close (SockFD);
X            return (0);
X        }   /* end if ret */
X    }  while (ptr == NULL);
X
Xreturnline:
X    ret = ptr - TempBuffer;      /* somehow it's the strlen */
X    bcopy (TempBuffer, sTempBuf, ret);   /* copy the whole line */
X    ptr = sTempBuf + ret;     /* point to \r\n in sTempBuf */
X    *ptr = '\0';          /* terminate sTempBuf, forget \r\n */
X    Count = Count - ret - 2;  /* Count=remaining bytes in TempBuffer */
X    if (Count > 0)
X    {
X        bcopy (TempBuffer + ret + 2, TempBuffer, Count);    /* bcopy cares for overlap */
X        TempBuffer[Count] = '\0';    /* terminate TempBuffer */
X    }
X    else
X    {
X        Count = 0;
X        *TempBuffer = '\0';
X    }   /* end if Count */
X
X    if (DebugFile != NULL)
X        fprintf (DebugFile, "DEBUG sgets: %d %s\n", Count, sTempBuf);
X
X    return (ret);         /* return strlen of sTempBuf */
X}   /* end sgets */
X
X/* get next number in string */
Xchar * number (char *sp, int *intPtr)
X{
X    /* Local variables */
X    int             i, c;
X
X    if (sp == NULL)
X    {
X        *intPtr = 0;
X        return (sp);
X    }
X
X    for (i = 0; sp[i] != ' '; i++)
X    if (sp[i] == '\0')
X        break;
X    c = sp[i];
X    sp[i] = '\0';
X    sscanf (sp, "%d", intPtr);
X    sp[i++] = c;
X    return (sp + i);
X}   /* end number */
SHAR_EOF
chmod 0644 nntppoll/nntppoll.c || echo "restore of nntppoll/nntppoll.c fails"
echo "x - extracting nntppoll/nntppoll.h (Text)"
sed 's/^X//' << 'SHAR_EOF' > nntppoll/nntppoll.h &&
X/* External variables */
Xextern int getopt(int argc, char * const argv[], const char *optstring);
Xextern char *optarg;
Xextern int optind, opterr;
Xstruct hostent *hi;
X
X/* Global defines */
X#define VERSION     "1.2, 25-Feb-1995"
X#define TEMPBUF_LEN 1024
X#define RNEWS       "/usr/lib/news/rnews"
X
X/* Global variables */
Xchar                ProgName[TEMPBUF_LEN / 4] = {0},
X                    RCName[TEMPBUF_LEN / 4] = ".nntppoll.rc",
X                    DateString[TEMPBUF_LEN / 4];
Xint                 VerboseFlag = 0,
X                    SyslogFlag = 0,
X#ifdef TEST_MODE
X                    TestFlag = 1,
X#else
X                    TestFlag = 0,
X#endif
X                    nntp_socket = -1,
X                    PID = -1;
XFILE                *DebugFile = NULL;
Xenum {  ALL_OK = 0,
X        HELP_REQ, 
X        PROG_ALREADY_RUNNING,
X        NO_PID_FILE,
X        NO_NNTPSERVER,
X        NO_IP_ADDRESS,
X        WRONG_ADDR_TYPE,
X        NO_FREE_SOCKET,
X        NO_CONNECTION,
X        RECEIVE_ERROR,
X        NO_RC_FILE,
X        NO_TMP_FILE,
X        NO_INDEX_FILE,
X        PROTOCOL_ERROR,
X        UNEXPECTED_RESPONSE,
X        NO_SORTED_FILE,
X        NO_RNEWS } ResultCode;
SHAR_EOF
chmod 0644 nntppoll/nntppoll.h || echo "restore of nntppoll/nntppoll.h fails"
echo "x - extracting nntppoll/nntppoll.man (Text)"
sed 's/^X//' << 'SHAR_EOF' > nntppoll/nntppoll.man &&
X.TH nntppoll 1 "Last changed: 02/25/95"
X.SH NAME
Xnntppoll - poll news articles from a nntp host
X.SH SYNOPSIS
X\fBnntppoll\fP [-h] [-d] [-d \fIfilename\fP] [-r \fIrc-file\fP] [-v] [nntp-host]
X.SH DESCRIPTION
X\fInntppoll\fP polls news articles from a nntp host
X.SS Options
X.TP
X\fB-h\fP
XShow a help screen and exit
X.TP
X\fB-d\fP
XLog debug info via syslogd
X.TP
X\fB-D \fifilename\fP\fP
XLog debug info to \fIfilename\fP
X.TP
X\fB-r \fifilename\fP\fP
XUse \fIfilename\fP as rc file
X.TP
X\fB-v\fP
XShow nntp actions verbosely
X.SS rcfile
XThe structure of the \fIrc file\fP is as following:
X
XAny empty line or starting with a \fI#\fP is a comment - any other line will
Xbe taken as a newsgroup and an optional count.
X
XExample:
X
X# This is a comment line
X
Xalt.sources 3765
X.SS nntp-host
XIf a nntp-host is not specified in the invocation the value of the
Xenvironment variable \fINNTPSERVER\fP is taken.
X.SH FILES
X\fI/usr/local/bin/nntppoll\fP
X.SH "SEE ALSO"
X\fIinnd\fP(8), \fInntpd\fP(8)
X.SH BUGS
Xunknown
X.SH AUTHOR
Xroot@btoy1.btoy1.rochester.ny.us
SHAR_EOF
chmod 0644 nntppoll/nntppoll.man || echo "restore of nntppoll/nntppoll.man fails"
exit 0

-- 
--______ __ ---------------------------------------------------------
 '  /  '/  )  This is the mail account for ROOT@BTOY1.ROCHESTER.NY.US
   /   /--<    btoy1 is a system running LINUX on a 386DX/40Mhz
(_/   /___/
Technical Details
Message-ID: <3iokfq$47u@btoy1.btoy1.rochester.NY.US>
Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!illumos!news.pugleaf.net!.TX!i2pn2.pugleaf.net!archive.newsdeef.eu!mbox2nntp-alt.sources.mbox.zip!nntp.gmd.de!news.rwth-aachen.de!news.rhrz.uni-bonn.de!RRZ.Uni-Koeln.DE!uni-duisburg.de!zib-berlin.de!news.mathworks.com!udel!news.sprintlink.net!uhost1.servtech.com!btoy1.rochester.ny.us!not-for-mail

Show Full Headers
Complete Article Headers
Message-ID: <3iokfq$47u@btoy1.btoy1.rochester.NY.US>
Subject: Suck/Poll News
Date: Sun, 26 Feb 1995 01:11:21 +0000
From: rootmail@btoy1.rochester.ny.us (Mail Account for root)
Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!illumos!news.pugleaf.net!.TX!i2pn2.pugleaf.net!archive.newsdeef.eu!mbox2nntp-alt.sources.mbox.zip!nntp.gmd.de!news.rwth-aachen.de!news.rhrz.uni-bonn.de!RRZ.Uni-Koeln.DE!uni-duisburg.de!zib-berlin.de!news.mathworks.com!udel!news.sprintlink.net!uhost1.servtech.com!btoy1.rochester.ny.us!not-for-mail
Newsgroups: alt.sources,comp.os.linux.networking,news.software.nntp
Organization: A private site
Lines: 1012
Distribution: world
Reply-To: rootmail@btoy1.rochester.ny.us
NNTP-Posting-Host: btoy1.btoy1.rochester.ny.us
X-Newsreader: TIN [version 1.2 PL2]