🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

1 total messages Started by Takanori Oshiro Thu, 17 Apr 2025 21:00
Usenet article download program
#1
Author: Takanori Oshiro
Date: Thu, 17 Apr 2025 21:00
120 lines
4516 bytes
A usenet article download program was written
This program was built on FreeBSD, so some modification will be needed
on other platforms

First, invoke this program, then welcome message from newsserver will be
shown
Enter AUTHINFO USER loginname
Second password will be required
Enter AUTHINFO PASS password
Third interesting newsgroup name will be needed
Enter newsgroup name
Then reply code, number of preserved articles, starting article number,
ending article number, name of newsgroup are displayed
Enter starting unread article number
Then articles will be downloaded in a file named newsgroup name
Absolutely no error check, so if typo, terminate the program
Because article can be handled by UNIX standard programs, I thik that this
program is suited in UNIX way
Takanori Oshiro
Uniform resource locator oosiro.biz

#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <sys/socket.h>
#include <sys/types.h>
#include <stdlib.h>
int main(void)
{
	struct sockadd_in {
		uint8_t	sin_len;
		sa_family_t	sin_family;
		in_port_t	sin_port;
		struct	in_addr	sin_addr;
		char	sin_zero[8];
	} sa;
	int fd_skt;
	char buf[65535];
	ssize_t nread;
	FILE *fp;
	sa.sin_len = sizeof(sa);
	sa.sin_family = AF_INET;
	sa.sin_port = htons(119);
	sa.sin_addr.s_addr = inet_addr("135.181.20.170");
	int i=0,j;
	int article_number;
	int lwm,hwm;
	char c;
	char newsgroup[255];
	char request[255];

	fd_skt = socket(AF_INET, SOCK_STREAM,0);
	connect(fd_skt, (struct sockaddr *)&sa, sizeof(sa));
	nread = read(fd_skt, buf, sizeof(buf));
	write(STDOUT_FILENO, buf, nread);
	nread = read(STDIN_FILENO, buf, sizeof(buf));
	write(fd_skt, buf, nread);
	nread = read(fd_skt, buf, nread);
	write(STDOUT_FILENO, buf, nread);
	nread = read(STDIN_FILENO, buf, sizeof(buf));
	write(fd_skt, buf, nread);
	nread = read(fd_skt, buf,sizeof(buf));
	write(STDOUT_FILENO, buf, nread);
	printf("Please input newsgroup name:");
	scanf("%s",newsgroup);
	sprintf(request,"GROUP %s\r\n",newsgroup);
	write(fd_skt,request,strlen(request));
	nread = read(fd_skt, buf, sizeof(buf));
	write(STDOUT_FILENO,buf,nread);
	if(buf[0] == '4' && buf[1] == '1' && buf[2] == '1'){
		close(fd_skt);
		exit(1);
	}
	sscanf(buf,"%d %d %d %d %s",&i,&j,&lwm,&hwm,newsgroup);
	printf("Please secify starting article number:");
	scanf("%d",&article_number);
	if(article_number < lwm)
		article_number = lwm;
	else if(article_number >= hwm){
		close(fd_skt);
		exit(1);
	}
	fp=fopen(newsgroup,"a");
	i=article_number;
loop:	sprintf(request,"ARTICLE %d\r\n",i);
	write(fd_skt,request,strlen(request));
	nread = read(fd_skt, buf, sizeof(buf));
	if(buf[0]=='4' && buf[1]=='2' && buf[2]=='3'){
		++i;
		goto loop;
	}
	sprintf(request,"HEAD %d\r\n",i);
	write(fd_skt,request,strlen(request));
	nread =read(fd_skt, buf, sizeof(buf));
	for(j=0;j<nread;j++)
		putc(buf[j],fp);
	sprintf(request,"BODY %d\r\n",i);
	write(fd_skt,request,strlen(request));
	j=0;
	while((nread = read(fd_skt, buf, sizeof(buf))) != 0){
		if(buf[nread-3]=='.' && buf[nread-2]=='\r'){
			j=0;
			printf("Now reading %d\n",i);
			while(j<nread)
				putc(buf[j++],fp);
			if(i == hwm)
				goto exit1;
			++i;	
			goto loop;
		}
			while(j<nread)
				putc(buf[j++],fp);
			j=0;
	}
exit1:	fclose(fp);
	close(fd_skt);
	exit(0);
}
Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads