예제 #1
0
static void
dump_range (AddrRange * range, GstRTSPAddressPool * pool)
{
    gchar *addr1, *addr2;

    addr1 = get_address_string (&range->min);
    addr2 = get_address_string (&range->max);
    g_print ("  address %s-%s, port %u-%u, ttl %u\n", addr1, addr2,
             range->min.port, range->max.port, range->ttl);
    g_free (addr1);
    g_free (addr2);
}
예제 #2
0
void NetInfoIPv6::print_address_info()
{
  PRINTF("   IP Address: %s\n", get_address_string());
  PRINTF("     Net Mask: %s\n", get_netmask_string());
  PRINTF("     Gate Way: %s\n", get_gateway_string());
  if (AM_LIKELY(dns)) {
    uint32_t count = 1;
    for (DnsIPv6 *d = dns; d; d = d->dns_next) {
      PRINTF("         DNS%u: %s\n", count ++, d->get_dns_string());
    }
  }
}
예제 #3
0
int main()
{
	// Init Events...
	sei();

	// set portD bit 5 (flow control) as output
	DDRD |= _BV(PD5);

	// Initial setup
	init_state_machine();
	btle_usart_init();
	wan_usart_init();
	// Open flow control
	PORTD &= ~_BV(PD5);

	// BGAPI commands
	// Can be found in bluetooth smart software reference PDF on pg. 101, 102, and 111. respectively
	uint8_t discoverCmd[] = {0x00, 0x01, 0x06, 0x02, 0x01};
	uint8_t endDiscoverCmd[] = {0x00, 0x00, 0x06, 0x04};
	uint8_t discoverParams[] = {0x00, 0x05, 0x06, 0x07, 0x40, 0x00, 0x32, 0x00, 0x00};

	// BGAPI initialization commands
	btle_usart_clear_buffer();
	btle_usart_transmit_bytes(endDiscoverCmd, 4);
	_delay_ms(100);
	btle_usart_transmit_bytes(discoverParams, 9);
	_delay_ms(100);
	btle_usart_transmit_bytes(discoverCmd, 5);

	char c[PRINT_BUFFER_SIZE];
	while(true)
	{
		if (state == 5) {
			// Close flow control
			PORTD |= _BV(PD5);

			PACKAGE *pkg = parse(msg);

			get_address_string(pkg, c);
			wan_usart_transmit_string("Address: ");
			wan_usart_transmit_string(c);
			wan_usart_transmit_string("\r\n");

			get_data_length_string(pkg, c);
			wan_usart_transmit_string("Data Length: ");
			wan_usart_transmit_string(c);
			wan_usart_transmit_string("\r\n");

			get_data_string(pkg, c);
			wan_usart_transmit_string("Data: ");
			wan_usart_transmit_string(c);
			wan_usart_transmit_string("\r\n\n");

			//To transmit raw hex data of entire message... uncomment
			//wan_usart_transmit_bytes(msg, msgIndex);

			msgIndex = 0;
			state = 0;
			free(pkg);

			//Open flow control
			PORTD &= ~_BV(PD5);
		}
	}
	return 0;
}
예제 #4
0
/**
 * gst_rtsp_address_pool_reserve_address:
 * @pool: a #GstRTSPAddressPool
 * @ip_address: The IP address to reserve
 * @port: The first port to reserve
 * @n_ports: The number of ports
 * @ttl: The requested ttl
 * @address: (out): storage for a #GstRTSPAddress
 *
 * Take a specific address and ports from @pool. @n_ports consecutive
 * ports will be allocated of which the first one can be found in
 * @port.
 *
 * If @ttl is 0, @address should be a unicast address. If @ttl > 0, @address
 * should be a valid multicast address.
 *
 * Returns: #GST_RTSP_ADDRESS_POOL_OK if an address was reserved. The address
 * is returned in @address and should be freed with gst_rtsp_address_free
 * after use.
 */
GstRTSPAddressPoolResult
gst_rtsp_address_pool_reserve_address (GstRTSPAddressPool * pool,
                                       const gchar * ip_address, guint port, guint n_ports, guint ttl,
                                       GstRTSPAddress ** address)
{
    GstRTSPAddressPoolPrivate *priv;
    Addr input_addr;
    GList *list;
    AddrRange *addr_range;
    GstRTSPAddress *addr;
    gboolean is_multicast;
    GstRTSPAddressPoolResult result;

    g_return_val_if_fail (GST_IS_RTSP_ADDRESS_POOL (pool),
                          GST_RTSP_ADDRESS_POOL_EINVAL);
    g_return_val_if_fail (ip_address != NULL, GST_RTSP_ADDRESS_POOL_EINVAL);
    g_return_val_if_fail (port > 0, GST_RTSP_ADDRESS_POOL_EINVAL);
    g_return_val_if_fail (n_ports > 0, GST_RTSP_ADDRESS_POOL_EINVAL);
    g_return_val_if_fail (address != NULL, GST_RTSP_ADDRESS_POOL_EINVAL);

    priv = pool->priv;
    addr_range = NULL;
    addr = NULL;
    is_multicast = ttl != 0;

    if (!fill_address (ip_address, port, &input_addr, is_multicast))
        goto invalid;

    g_mutex_lock (&priv->lock);
    list = find_address_in_ranges (priv->addresses, &input_addr, port, n_ports,
                                   ttl);
    if (list != NULL) {
        AddrRange *range = list->data;
        guint skip_port, skip_addr;

        skip_addr = diff_address (&input_addr, &range->min);
        skip_port = port - range->min.port;

        GST_DEBUG_OBJECT (pool, "diff 0x%08x/%u", skip_addr, skip_port);

        /* we found a range, remove from the list */
        priv->addresses = g_list_delete_link (priv->addresses, list);
        /* now split and exit our loop */
        addr_range = split_range (pool, range, skip_addr, skip_port, n_ports);
        priv->allocated = g_list_prepend (priv->allocated, addr_range);
    }

    if (addr_range) {
        addr = g_slice_new0 (GstRTSPAddress);
        addr->pool = g_object_ref (pool);
        addr->address = get_address_string (&addr_range->min);
        addr->n_ports = n_ports;
        addr->port = addr_range->min.port;
        addr->ttl = addr_range->ttl;
        addr->priv = addr_range;

        result = GST_RTSP_ADDRESS_POOL_OK;
        GST_DEBUG_OBJECT (pool, "reserved address %s:%u ttl %u", addr->address,
                          addr->port, addr->ttl);
    } else {
        /* We failed to reserve the address. Check if it was because the address
         * was already in use or if it wasn't in the pool to begin with */
        list = find_address_in_ranges (priv->allocated, &input_addr, port, n_ports,
                                       ttl);
        if (list != NULL) {
            result = GST_RTSP_ADDRESS_POOL_ERESERVED;
        } else {
            result = GST_RTSP_ADDRESS_POOL_ERANGE;
        }
    }
    g_mutex_unlock (&priv->lock);

    *address = addr;
    return result;

    /* ERRORS */
invalid:
    {
        GST_ERROR_OBJECT (pool, "invalid address %s:%u/%u/%u", ip_address,
                          port, n_ports, ttl);
        *address = NULL;
        return GST_RTSP_ADDRESS_POOL_EINVAL;
    }
}
예제 #5
0
/**
 * gst_rtsp_address_pool_acquire_address:
 * @pool: a #GstRTSPAddressPool
 * @flags: flags
 * @n_ports: the amount of ports
 *
 * Take an address and ports from @pool. @flags can be used to control the
 * allocation. @n_ports consecutive ports will be allocated of which the first
 * one can be found in @port.
 *
 * Returns: (nullable): a #GstRTSPAddress that should be freed with
 * gst_rtsp_address_free after use or %NULL when no address could be
 * acquired.
 */
GstRTSPAddress *
gst_rtsp_address_pool_acquire_address (GstRTSPAddressPool * pool,
                                       GstRTSPAddressFlags flags, gint n_ports)
{
    GstRTSPAddressPoolPrivate *priv;
    GList *walk, *next;
    AddrRange *result;
    GstRTSPAddress *addr;

    g_return_val_if_fail (GST_IS_RTSP_ADDRESS_POOL (pool), NULL);
    g_return_val_if_fail (n_ports > 0, NULL);

    priv = pool->priv;
    result = NULL;
    addr = NULL;

    g_mutex_lock (&priv->lock);
    /* go over available ranges */
    for (walk = priv->addresses; walk; walk = next) {
        AddrRange *range;
        gint ports, skip;

        range = walk->data;
        next = walk->next;

        /* check address type when given */
        if (flags & GST_RTSP_ADDRESS_FLAG_IPV4 && !ADDR_IS_IPV4 (&range->min))
            continue;
        if (flags & GST_RTSP_ADDRESS_FLAG_IPV6 && !ADDR_IS_IPV6 (&range->min))
            continue;
        if (flags & GST_RTSP_ADDRESS_FLAG_MULTICAST && range->ttl == 0)
            continue;
        if (flags & GST_RTSP_ADDRESS_FLAG_UNICAST && range->ttl != 0)
            continue;

        /* check for enough ports */
        ports = range->max.port - range->min.port + 1;
        if (flags & GST_RTSP_ADDRESS_FLAG_EVEN_PORT
                && !ADDR_IS_EVEN_PORT (&range->min))
            skip = 1;
        else
            skip = 0;
        if (ports - skip < n_ports)
            continue;

        /* we found a range, remove from the list */
        priv->addresses = g_list_delete_link (priv->addresses, walk);
        /* now split and exit our loop */
        result = split_range (pool, range, 0, skip, n_ports);
        priv->allocated = g_list_prepend (priv->allocated, result);
        break;
    }
    g_mutex_unlock (&priv->lock);

    if (result) {
        addr = g_slice_new0 (GstRTSPAddress);
        addr->pool = g_object_ref (pool);
        addr->address = get_address_string (&result->min);
        addr->n_ports = n_ports;
        addr->port = result->min.port;
        addr->ttl = result->ttl;
        addr->priv = result;

        GST_DEBUG_OBJECT (pool, "got address %s:%u ttl %u", addr->address,
                          addr->port, addr->ttl);
    }

    return addr;
}