File:  [CSRG BSD Unix] / 43BSD / ingres / source / support / initsocket.c
Revision 1.1.1.1 (vendor branch): download - view: text, annotated - select for diffs
Tue Apr 24 16:12:55 2018 UTC (8 years, 1 month ago) by root
Branches: MAIN, BSD
CVS tags: HEAD, BSD43
BSD 4.3

# include	<stdio.h>
# include	<sys/types.h>
# include	<sys/socket.h>
# include	<sys/ioctl.h>
# include	<netinet/in.h>
# include	<netdb.h>
# include	<signal.h>
# include	<sccs.h>

SCCSID(@(#)initsocket.c	8.1	12/31/84)

/*
** init_socket
** initilize the socket to the socket server
*/
init_socket()
{
	register	int	from_socket;	/* file descriptor to attach to socket server */
	int	to_ioctl = 1;			/* used in ioctl call */
	struct	sockaddr_in	addr;		/* address where socket server is */
	char	hostname[BUFSIZ];		/* hostname */
	struct	servent		*server;
	struct	hostent		*myhost;
	auto	int		len;
	extern	int		errno;

	if ( (len = fork()) != 0 )
	{
# ifdef	DEBUG
		printf("lock driver becomes %d\n",len);
# endif	DEBUG
		if ( len == -1 )
		{
			perror("ingres lock driver, fork");
			exit(errno);
		}
		exit(0);
	}
	if ( (from_socket = socket(AF_INET,SOCK_STREAM,0)) == -1 )
	{
# ifdef	DEBUG
		perror("INIT_S socket");
# endif	DEBUG
		exit(errno);
	}
	len = BUFSIZ;
	gethostname(hostname,&len);

	if ( (server = getservbyname("ingreslock",(char *)0)) == 0 )
		exit(errno);

	if ( (myhost = gethostbyname(hostname)) == 0 )
		exit(errno);
	bzero((char *) &addr,sizeof (addr));
	bcopy(myhost->h_addr,(char *)&addr.sin_addr,myhost->h_length);
	addr.sin_family = AF_INET;
	addr.sin_port = server->s_port;
	len = sizeof (addr);
	if ( bind(from_socket,&addr,len) == -1 )
	{
# ifdef	DEBUG
		perror("INIT_S bind, assuming driver already running");
# endif	DEBUG
		exit(0);
	}

	if ( listen(from_socket,10) == -1 )
	{
		perror("Ingres lock, can't listen on port");
		exit(errno);
	}
	ioctl(from_socket,FIONBIO,&to_ioctl);
	return ( from_socket );
}/* init_socket */

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.