/*
 *	Set up a socket
 *			
 *	Alan Cox 1990
 *
 *	This software is placed in the public domain
 */

#include <stdio.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <errno.h>
#include <netinet/in.h>
#include <netdb.h>
#include <sys/ioctl.h>
#include <pragmas/socket_pragmas.h>

extern long SocketBase;

/*
 *	Create the client socket
 */
 
int Make_Connection(int port,const char *buf)
{
	struct sockaddr_in myaddress;
	struct hostent *host;
	int v;
	int one=1;
	host=gethostbyname(buf);
	if(host==NULL)
	{
		fprintf(stderr,"Unknown host '%s'.\n",host);
		exit(1);
	}
	myaddress.sin_family=host->h_addrtype;
	myaddress.sin_addr.s_addr=*((long *)host->h_addr);
	myaddress.sin_port=htons(port);
	v=socket(AF_INET,SOCK_STREAM,0);
	if(v==-1)
	{
		fprintf(stderr,"Unable to create a socket.\n");
		exit(1);
	}
	if(connect(v,(struct sockaddr *)&myaddress,sizeof(myaddress))<0)
	{
		fprintf(stderr,"Connection attempt failed.\n");
		exit(1);
	}
	ioctl(v,FIONBIO,&one);
	return(v);
}

