Ejemplo n.º 1
0
/*
 * NAME: ip_bindery
 * USAGE: Establish a local passive (listening) socket at the given port.
 * ARGS: family - AF_INET is the only supported argument.
 *       port - The port to establish the connection upon.  May be 0, 
 *		which requests any open port.
 *	 storage - Pointer to a sockaddr structure big enough for the
 *		   specified family.  Upon success, it will be filled with
 *		   the local sockaddr of the new connection.
 * NOTES: In most cases, the local address for 'storage' will be INADDR_ANY
 *        which doesn't really give you any useful information.  It is not
 *        possible to authoritatively figure out the local IP address
 *        without using ioctl().  However, we guess the best we may.
 *
 * NOTES: This function lacks IPv6 support.
 *        This function lacks Unix Domain Socket support.
 */
int	ip_bindery (int family, unsigned short port, SS *storage)
{
	socklen_t len;
	int	fd;

	if (inet_vhostsockaddr(family, port, NULL, storage, &len))
	{
		syserr(-1, "ip_bindery: inet_vhostsockaddr(%d,%d) failed.", 
							family, port);
		return -1;
	}

	if (!len)
	{
		syserr(-1, "ip_bindery: inet_vhostsockaddr(%d,%d) didn't "
			"return an address I could bind", family, port);
		return -1;
	}

	if ((fd = client_bind((SA *)storage, len)) < 0)
	{
		syserr(-1, "ip_bindery: client_bind(%d,%d) failed.", family, port);
		return -1;
	}

	return fd;
}
Ejemplo n.º 2
0
void dsme_dbus_bind_signals(bool*                             bound_already,
                            const dsme_dbus_signal_binding_t* bindings)
{
  if (bound_already && !*bound_already) {
      const dsme_dbus_signal_binding_t* binding = bindings;

      while (binding && binding->handler) {
          Client* client;

          if (!(client = client_instance())) {
              dsme_log(LOG_ERR,
                       "Could not create D-Bus client for '%s'",
                       binding->name);
              // TODO: roll back the ones that succeeded and break?
          } else if (!client_bind(client,
                                  binding->handler,
                                  binding->interface,
                                  binding->name))
          {
              dsme_log(LOG_ERR, "D-Bus binding for '%s' failed", binding->name);
              // TODO: roll back the ones that succeeded and break?
          }
          ++binding;
      }
  }
}
Ejemplo n.º 3
0
/*
 * NAME: ip_bindery
 * USAGE: Establish a local passive (listening) socket at the given port.
 * ARGS: family - AF_INET is the only supported argument.
 *       port - The port to establish the connection upon.  May be 0, 
 *		which requests any open port.
 *	 storage - Pointer to a sockaddr structure big enough for the
 *		   specified family.  Upon success, it will be filled with
 *		   the local sockaddr of the new connection.
 * NOTES: In most cases, the local address for 'storage' will be INADDR_ANY
 *        which doesn't really give you any useful information.  It is not
 *        possible to authoritatively figure out the local IP address
 *        without using ioctl().  However, we guess the best we may.
 *
 * NOTES: This function lacks IPv6 support.
 *        This function lacks Unix Domain Socket support.
 */
int	ip_bindery (int family, unsigned short port, SS *storage)
{
	int	err;
	socklen_t len;

	if ((err = inet_vhostsockaddr(family, port, storage, &len)))
		return err;

	if (!len)
		return -6;

	return client_bind((SA *)storage, len);
}