/* Copyright (C) 1995 NetWin World, New Zealand, All rights reserved. */
#ifdef MULTINET
#include "multinet_root:[multinet.include]errno.h"
#include "multinet_root:[multinet.include.sys]types.h"
#include "multinet_root:[multinet.include.sys]socket.h"
#include "multinet_root:[multinet.include.sys]time.h"
#include "multinet_root:[multinet.include.netinet]in.h"
#include "multinet_root:[multinet.include]netdb.h"
#endif

#ifdef unix
#include <errno.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netdb.h>
#include <sys/time.h>
#include <unistd.h>
#ifdef LINUX
#include <linux/in.h>
#else
#include <netinet/in.h>
#endif

#define socket_perror perror
#define socket_close close
#define socket_open open
#define socket_read read
#define socket_write write
#define bcopy(src,dst,len) memmove(dst,src,len)

#endif

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
static	struct hostent *hp;
static	struct servent *sp;

static short chan;
int nntp_open(char *dst_name)
{
	int dst_port=119;
	struct hostent *hp;
	struct sockaddr_in sin;
	int st;

	hp = gethostbyname(dst_name);
	if (hp==NULL) {
		printf("nntp: Hostname not found {%s} \n",dst_name);
		return -1;
	}

	chan = socket(hp->h_addrtype,SOCK_STREAM, 0);
	if (chan<0) { socket_perror("Socket"); return -1;}
	sin.sin_family = hp->h_addrtype;
	bcopy(hp->h_addr, &sin.sin_addr, hp->h_length);
	sin.sin_port = htons(dst_port);
#ifdef VMS
	st = connect(chan, &sin, sizeof(sin), 0);
#else
	st = connect(chan, &sin, sizeof(sin));
#endif
        if (st<0) { socket_perror("connect"); return -1;}
	return chan;
}
int nntp_write(int c, char *bf, int sz)
{
	short chan=c;
	return socket_write(chan,bf,sz);
}
int nntp_read(int c, char *bf, int sz)
{
	short chan=c;
	return socket_read(chan,bf,sz);
}
char *nntp_hostname(void)
{
	static char bf[200];
	if (gethostname(bf,190)!=0) emsg("nntp: Can't get host name\n");
	return bf;
}
