🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: fj.sources
Article #1

Usenet article download program

#1
From: 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);
}
Technical Details
Message-ID: <87cyda5wrn.fsf@atos.oosiro.biz>
Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!illumos!news.pugleaf.net!.TX!i2pn2.pugleaf.net!nnrp.usenet.blueworldhosting.com!!spool1.usenet.blueworldhosting.com!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!eternal-september.org!.POSTED!not-for-mail

Show Full Headers
Complete Article Headers
Message-ID: <87cyda5wrn.fsf@atos.oosiro.biz>
Subject: Usenet article download program
Date: Fri, 18 Apr 2025 06:00:12 +0900
From: Takanori Oshiro <takanori@oosiro.biz>
Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!illumos!news.pugleaf.net!.TX!i2pn2.pugleaf.net!nnrp.usenet.blueworldhosting.com!!spool1.usenet.blueworldhosting.com!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!eternal-september.org!.POSTED!not-for-mail
Newsgroups: fj.sources
Organization: Takanori Oshiro father & son company
Lines: 121
MIME-Version: 1.0
Content-Type: text/plain
Injection-Date: Thu, 17 Apr 2025 23:02:13 +0200 (CEST)
Injection-Info: dont-email.me; posting-host="6a813f84a0d20b771595c1bf9aa3148f";
	logging-data="1503424"; mail-complaints-to="abuse@eternal-september.org";	posting-account="U2FsdGVkX18S4csuFJwvLGN2/PyX8X9S8Vs93lSfTrg="
User-Agent: Gnus/5.13 (Gnus v5.13)
Cancel-Lock: sha1:1GVjw9qS588xu1lO6xoPGmLrdcQ=
	sha1:w8kS1oqESHSo78XJIhZgxI/+Hgs=