Exemple #1
0
int setup_inetd_connection(gchar **argv)
{
	int sv[2], status;
	pid_t child;

	if (socketpair(AF_UNIX, SOCK_STREAM, 0, sv) == -1) {
		strncpy(errstr, strerror(errno), errstr_len);
		return -1;
	}

	child = vfork();
	if (child == 0) {
		dup2(sv[0], 0);
		close(sv[0]);
		close(sv[1]);
		execvp(argv[0], argv);
		perror("execvp");
		_exit(-1);
	} else if (child == -1) {
		close(sv[0]);
		close(sv[1]);
		strncpy(errstr, strerror(errno), errstr_len);
		return -1;
	}

	close(sv[0]);
	if (waitpid(child, &status, WNOHANG)) {
		close(sv[1]);
		return -1;
	}

	setmysockopt(sv[1]);
	return sv[1];
}
Exemple #2
0
int setup_unix_connection(gchar * unixsock)
{
	struct sockaddr_un addr;
	int sock;

	sock = 0;
	if ((sock = socket(AF_UNIX, SOCK_STREAM, 0)) < 0) {
		strncpy(errstr, strerror(errno), errstr_len);
		goto err;
	}

	setmysockopt(sock);
	memset(&addr, 0, sizeof(struct sockaddr_un));
	addr.sun_family = AF_UNIX;
	strncpy(addr.sun_path, unixsock, sizeof addr.sun_path);
	addr.sun_path[sizeof(addr.sun_path)-1] = '\0';
	if (connect(sock, (struct sockaddr *)&addr, sizeof(addr)) < 0) {
		strncpy(errstr, strerror(errno), errstr_len);
		goto err_open;
	}
	goto end;
err_open:
	close(sock);
err:
	sock = -1;
end:
	return sock;
}
Exemple #3
0
int setup_inet_connection(gchar * hostname, int port)
{
	int sock;
	struct hostent *host;
	struct sockaddr_in addr;

	sock = 0;
	if ((sock = socket(PF_INET, SOCK_STREAM, IPPROTO_TCP)) < 0) {
		strncpy(errstr, strerror(errno), errstr_len);
		goto err;
	}
	setmysockopt(sock);
	if (!(host = gethostbyname(hostname))) {
		strncpy(errstr, hstrerror(h_errno), errstr_len);
		goto err_open;
	}
	addr.sin_family = AF_INET;
	addr.sin_port = htons(port);
	addr.sin_addr.s_addr = *((int *)host->h_addr);
	if ((connect(sock, (struct sockaddr *)&addr, sizeof(addr)) < 0)) {
		strncpy(errstr, strerror(errno), errstr_len);
		goto err_open;
	}
	goto end;
err_open:
	close(sock);
err:
	sock = -1;
end:
	return sock;
}
Exemple #4
0
int setup_unix_connection(gchar* unixsock, gchar* name, CONNECTION_TYPE ctype, int* serverflags) {
	struct sockaddr_un addr;
	int sock;

	sock = 0;
	if(ctype<CONNECTION_TYPE_CONNECT) {
		goto end;
	}
	if((sock=socket(AF_UNIX, SOCK_STREAM, 0))<0) {
		strncpy(errstr, strerror(errno), errstr_len);
		goto err;
	}

	setmysockopt(sock);
	memset(&addr, 0, sizeof(struct sockaddr_un));
	addr.sun_family = AF_UNIX;
	strncpy(addr.sun_path, unixsock, 107);
	if(connect(sock, (struct sockaddr*)&addr, sizeof(addr))<0) {
		strncpy(errstr, strerror(errno), errstr_len);
		goto err_open;
	}
	sock = setup_connection_common(sock, name, ctype, serverflags);
	goto end;
err_open:
	close(sock);
err:
	sock=-1;
end:
	return sock;
}