Esempio n. 1
0
static void dhcp_server_stop(GDHCPServer *server)
{
	if (server == NULL)
		return;

	g_dhcp_server_unref(server);
}
Esempio n. 2
0
static void stop_dhcp_server(struct connman_peer *peer)
{
	DBG("");

	if (peer->dhcp_server)
		g_dhcp_server_unref(peer->dhcp_server);

	peer->dhcp_server = NULL;

	if (peer->ip_pool)
		__connman_ippool_unref(peer->ip_pool);
	peer->ip_pool = NULL;
}
Esempio n. 3
0
int main(int argc, char *argv[])
{
    struct sigaction sa;
    GDHCPServerError error;
    GDHCPServer *dhcp_server;
    int index;

    if (argc < 2) {
        printf("Usage: dhcp-server-test <interface index>\n");
        exit(0);
    }

    index = atoi(argv[1]);

    printf("Create DHCP server for interface %d\n", index);

    dhcp_server = g_dhcp_server_new(G_DHCP_IPV4, index, &error);
    if (dhcp_server == NULL) {
        handle_error(error);
        exit(0);
    }

    g_dhcp_server_set_debug(dhcp_server, dhcp_debug, "DHCP");

    g_dhcp_server_set_lease_time(dhcp_server, 3600);
    g_dhcp_server_set_option(dhcp_server, G_DHCP_SUBNET, "255.255.0.0");
    g_dhcp_server_set_option(dhcp_server, G_DHCP_ROUTER, "192.168.0.2");
    g_dhcp_server_set_option(dhcp_server, G_DHCP_DNS_SERVER, "192.168.0.3");
    g_dhcp_server_set_ip_range(dhcp_server, "192.168.0.101",
                               "192.168.0.102");
    main_loop = g_main_loop_new(NULL, FALSE);

    printf("Start DHCP Server operation\n");

    g_dhcp_server_start(dhcp_server);

    memset(&sa, 0, sizeof(sa));
    sa.sa_handler = sig_term;
    sigaction(SIGINT, &sa, NULL);
    sigaction(SIGTERM, &sa, NULL);

    g_main_loop_run(main_loop);

    g_dhcp_server_unref(dhcp_server);

    g_main_loop_unref(main_loop);

    return 0;
}