Exemplo n.º 1
0
void child_process(int sock)
{
    int fd;
    int fds[2], nfds;
    char b[] = "This is on the received fd!\n";

    if(ancil_recv_fd(sock, &fd)) {
  perror("ancil_recv_fd");
  exit(1);
    } else {
	printf("Received fd: %d\n", fd);
    }
    write(fd, b, sizeof(b));
    close(fd);
    sleep(2);

    nfds = ancil_recv_fds(sock, fds, 2);
    if(nfds < 0) {
	perror("ancil_recv_fds");
	exit(1);
    } else {
	printf("Received %d/2 fds : %d %d.\n", nfds,
	    fds[0], fds[1]);
    }
}
Exemplo n.º 2
0
void child_process1(int sock)
{
    int fd;
	char str[SIZE];
	int i;
	int size;

printf("The following is printed in child 1*************************\n");
    if(ancil_recv_fd(sock, &fd)) {
	  printf("Received fd: %d!!!\n", fd);
    }

    size = read(fd, &str[0], SIZE);
	for(i = 0; i < size; i++)
		printf("%c", str[i]);
	printf("\n");
    close(fd); //So child 2 can't inherit this file from its parent (child1).

	// Try to create a child (child 2)
	// Create process 2 
	switch(fork()) {
	case 0:
	    child_process2(sock);
	    exit(1);
	    break;
	case -1:
	    perror("fork");
	    exit(1);
	default:
		break;
	}
}
Exemplo n.º 3
0
void child_process(int sock)
{
    int fd;
	int i;

	char str[256];
	int size;
    char buf[] = "WWWWWWWWW";
	int offset;

    if(ancil_recv_fd(sock, &fd)) {
	  printf("Received fd: %d!!!\n", fd);
	 // perror("ancil_recv_fd");
	 // exit(1);
    } else {
	  printf("Received fd: %d!!!\n", fd);
    }
 //   write(fd, b, sizeof(b));
    size = read(fd, &str[0], 256);
	for(i = 0; i < size; i++)
		printf("%c", str[i]);
	printf("\n");
	write(fd, buf, sizeof(buf));
	offset = lseek(fd, -sizeof(buf), SEEK_CUR);
    close(fd);
    sleep(2);
}
Exemplo n.º 4
0
/** receive TUN fd from Android GUI; this is the only way to open TUN device on non-rooted Android */
int fastd_android_receive_tunfd(void) {
	init_ctrl_sock();

	int handle;
	if (ancil_recv_fd(ctx.android_ctrl_sock_fd, &handle)) {
		pr_error("could not receive TUN handle from Android");
		return -1;
	}

	pr_debug("received fd: %u", handle);

	return handle;
}
Exemplo n.º 5
0
void sfera_webserver::worker::_acceptorThreadRoutine()
{
    while (_working) {
        int newClientFd = 0;
        ancil_recv_fd(_masterCommunicationSocket, &newClientFd);

        b_ip::tcp::socket* acceptedSocket = new b_ip::tcp::socket(_server->ioService());
        acceptedSocket->assign(b_ip::tcp::v4(), newClientFd);

        _server->ioService().post([this, acceptedSocket]() {
            _server->handleClientConnection(acceptedSocket);
        });

        _acceptingCondition.notify_one();
    }
}
Exemplo n.º 6
0
void child_process2(int sock)
{
    int fd;
	int i;

	char str[SIZE];
	int size;

printf("The following is printed in child 2****************************\n");
    if(ancil_recv_fd(sock, &fd)) {
	  printf("Received fd: %d!!!\n", fd);
    }

    size = read(fd, &str[0], SIZE);
	for(i = 0; i < size; i++)
		printf("%c", str[i]);
	printf("\n");
    close(fd);
}
Exemplo n.º 7
0
/* 0: connected Unix socket */
    static ERL_NIF_TERM
nif_fdrecv(ErlNifEnv *env, int argc, const ERL_NIF_TERM argv[])
{
    int fd = -1;    /* connected socket */
    int s = -1;     /* socket received from pipe */


    if (!enif_get_int(env, argv[0], &fd))
        return enif_make_badarg(env);

    if (ancil_recv_fd(fd, &s) < 0) {
        int err = errno;
        (void)close(fd);
        return error_tuple(env, err);
    }

    if (close(fd) < 0)
        return error_tuple(env, errno);

    return enif_make_tuple2(env,
            atom_ok,
            enif_make_int(env, s));
}