*
* DHCP Server library with GLib integration
*
- * Copyright (C) 2009-2010 Intel Corporation. All rights reserved.
+ * Copyright (C) 2009-2012 Intel Corporation. All rights reserved.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
#define OFFER_TIME (5*60)
struct _GDHCPServer {
- gint ref_count;
+ int ref_count;
GDHCPType type;
gboolean started;
int ifindex;
struct sockaddr_in *server_ip;
uint32_t ret = 0;
- sk = socket(PF_INET, SOCK_DGRAM, 0);
+ sk = socket(PF_INET, SOCK_DGRAM | SOCK_CLOEXEC, 0);
if (sk < 0) {
perror("Open socket error");
return 0;
return 0;
listener_sockfd = dhcp_l3_socket(SERVER_PORT,
- dhcp_server->interface);
+ dhcp_server->interface, AF_INET);
if (listener_sockfd < 0)
return -EIO;
g_io_channel_set_close_on_unref(listener_channel, TRUE);
dhcp_server->listener_watch =
- g_io_add_watch_full(listener_channel,
- G_PRIORITY_HIGH, G_IO_IN,
+ g_io_add_watch_full(listener_channel, G_PRIORITY_HIGH,
+ G_IO_IN | G_IO_NVAL | G_IO_ERR | G_IO_HUP,
listener_event, dhcp_server,
NULL);
g_io_channel_unref(dhcp_server->listener_channel);
if (dhcp_server == NULL)
return NULL;
- g_atomic_int_inc(&dhcp_server->ref_count);
+ __sync_fetch_and_add(&dhcp_server->ref_count, 1);
return dhcp_server;
}
if (dhcp_server == NULL)
return;
- if (g_atomic_int_dec_and_test(&dhcp_server->ref_count) == FALSE)
+ if (__sync_fetch_and_sub(&dhcp_server->ref_count, 1) != 1)
return;
g_dhcp_server_stop(dhcp_server);