Example #1
0
int rpc_join(const char * sockname)
{
  if(!load_symbols_rpc())
    return -1;

	struct sockaddr_un addr;
	int conn_err = -1, attempts = 0;
	memset(&addr, 0, sizeof(addr));
	addr.sun_family = AF_UNIX;
	strncpy(addr.sun_path, sockname, sizeof(addr.sun_path)-1);

	int sock;
	if((sock = realsocket(AF_UNIX, SOCK_STREAM, 0)) < 0){
		fprintf(stderr, "Error while creating RPC socket\n");
		return -1;
	}
	while((conn_err != 0) && (attempts < SERVICE_CONNECT_ATTEMPTS)){
		if((conn_err = realconnect(sock, (struct sockaddr*)&addr, sizeof(addr))) != 0) {
			fprintf(stderr, "Error while connecting to RPC socket. Re-attempting...\n");
			sleep(1);
		}
		else
			return sock;
		attempts++;
	}
	return -1;
}
int socket(int domain,
           int type,
           int protocol)
{
    init_syms();

    if (getenv("LIBVIRT_TEST_IPV4ONLY") && domain == AF_INET6) {
        errno = EAFNOSUPPORT;
        return -1;
    }

    return realsocket(domain, type, protocol);
}
Example #3
0
/**
 * @brief socket - create an endpoint for communication
 *
 * This function intercepts the real libc() socket() function and
 * checks if for the current executable a firewall mark needs to be
 * set on the socket.
 *
 */
int socket(int domain, int type, int protocol)
{
    int s;
    if (!realsocket) {
        errno = ENFILE;
        return -1;
    }

    s= realsocket(domain, type, protocol);
    if (s != -1 && (domain == AF_INET || domain == AF_INET6) && hook)
        if (setsockopt(s, SOL_SOCKET, SO_MARK, val, sizeof(*val)) < 0)
            perror("setsockopt");

    return s;
}
static void init_syms(void)
{
    int fd;

    if (realsocket)
        return;

    realsocket = dlsym(RTLD_NEXT, "socket");

    if (!realsocket) {
        VIR_TEST_DEBUG("Unable to find 'socket' symbol\n");
        abort();
    }

    fd = realsocket(AF_INET6, SOCK_STREAM, 0);
    if (fd < 0)
        return;

    host_has_ipv6 = true;
    VIR_FORCE_CLOSE(fd);
}