if (sd->timer_id)
g_source_remove(sd->timer_id);
sd->timer_id = g_timeout_add(sd->timeout, send_arp, sd);
-
}
}
return TRUE;
}
+static void __close_channel_and_sock(struct sock_data* sd)
+{
+ INFO("+");
+ GError* error = NULL;
+
+ if (sd == NULL)
+ return;
+
+ if (G_IO_STATUS_NORMAL !=
+ g_io_channel_shutdown(sd->chk_conflict_sock_io, FALSE,
+ &error)) {
+ INFO("Failure received while shutdown io channel[%d]:[%s]", error->code, error->message);
+ g_error_free(error);
+ }
+
+ g_io_channel_unref(sd->chk_conflict_sock_io);
+ g_source_remove(sd->chk_conflict_data_id);
+ sd->chk_conflict_data_id = -1;
+
+ close(sd->chk_conflict_sd);
+ sd->chk_conflict_sd = -1;
+}
+
+static int __open_channel_and_sock(struct sock_data* sd)
+{
+ INFO("+");
+ if (sd == NULL)
+ return -1;
+
+ if ((sd->chk_conflict_sd = socket(AF_PACKET, SOCK_RAW, htons(ETH_P_ARP))) == -1) {
+ INFO("socket Failed.\n");
+ return -1;
+ }
+
+ sd->chk_conflict_sock_io = g_io_channel_unix_new(sd->chk_conflict_sd);
+ if (sd->chk_conflict_sock_io == NULL) {
+ INFO("Failed to create channel");
+ g_free(sd);
+ return -1;
+ }
+ g_io_channel_set_close_on_unref(sd->chk_conflict_sock_io, TRUE);
+ if (G_IO_STATUS_NORMAL != g_io_channel_set_encoding(sd->chk_conflict_sock_io,
+ NULL, NULL))
+ INFO("Failed to set encoding NULL on io channel");
+ if (G_IO_STATUS_NORMAL != g_io_channel_set_flags(sd->chk_conflict_sock_io,
+ G_IO_FLAG_NONBLOCK, NULL))
+ INFO("Failed to set flags on io channel");
+ sd->chk_conflict_data_id = g_io_add_watch(sd->chk_conflict_sock_io, G_IO_IN,
+ __netconfig_check_arp_receive, sd);
+ DBG("socket %d", sd->chk_conflict_sd);
+ return 0;
+}
+
static gboolean send_arp(gpointer data)
{
struct sock_data *sd = data;
addr.sll_protocol = htons(ETH_P_ARP);
memcpy(addr.sll_addr, broadcast_addr, ETHER_ADDR_LEN);
- if (sendto(sd->chk_conflict_sd, &arp, sizeof(arp), 0, (struct sockaddr*)&addr, sizeof(addr)) < 0) {
+ if (sendto(sd->chk_conflict_sd, &arp, sizeof(arp), 0,
+ (struct sockaddr*)&addr, sizeof(addr)) < 0) {
INFO("Sending ARP Packet Failed. Error. = %s\n",
strerror_r(errno, error_buf, MAX_SIZE_ERROR_BUFFER));
- /* close socket */
- close(sd->chk_conflict_sd);
- sd->chk_conflict_sd = -1;
-
- /* reopen socket */
- if ((sd->chk_conflict_sd = socket(AF_PACKET, SOCK_RAW, htons(ETH_P_ARP))) == -1) {
- INFO("socket %d", sd->chk_conflict_sd);
- INFO("socket Failed. Error = %s\n",
- strerror_r(errno, error_buf, MAX_SIZE_ERROR_BUFFER));
- }
+ __close_channel_and_sock(sd);
+ if (__open_channel_and_sock(sd) == -1)
+ INFO("__open_channel_and_sock failed");
goto err;
} else {
DBG("Sent ARP Packet \n");
return NULL;
}
- char error_buf[MAX_SIZE_ERROR_BUFFER] = {0, };
initial_bursts = true;
sd = g_try_malloc0(sizeof(struct sock_data));
sd->timer_id = 0;
sd->iteration = 0;
- if ((sd->chk_conflict_sd = socket(AF_PACKET, SOCK_RAW, htons(ETH_P_ARP))) == -1) {
- INFO("socket Failed. Error = %s\n",
- strerror_r(errno, error_buf, MAX_SIZE_ERROR_BUFFER));
+ if (__open_channel_and_sock(sd) == -1) {
+ INFO("__open_channel_and_sock failed");
g_free(sd);
return NULL;
- } else {
- sd->chk_conflict_sock_io = g_io_channel_unix_new(sd->chk_conflict_sd);
- if (sd->chk_conflict_sock_io == NULL) {
- INFO("Failed to create channel");
- INFO("Exit");
- g_free(sd);
- return NULL;
- }
-
- g_io_channel_set_close_on_unref(sd->chk_conflict_sock_io, TRUE);
+ }
- if (G_IO_STATUS_NORMAL != g_io_channel_set_encoding(sd->chk_conflict_sock_io,
- NULL, NULL))
- INFO("Failed to set encoding NULL on io channel");
- if (G_IO_STATUS_NORMAL != g_io_channel_set_flags(sd->chk_conflict_sock_io,
- G_IO_FLAG_NONBLOCK, NULL))
- INFO("Failed to set flags on io channel");
- sd->chk_conflict_data_id = g_io_add_watch(sd->chk_conflict_sock_io, G_IO_IN,
- __netconfig_check_arp_receive, sd);
- DBG("socket %d", sd->chk_conflict_sd);
+ sd->timeout = td.initial_time;
+ send_arp(sd);
+ is_ip_conflict_detect_enabled = true;
+ conflict_state = NETCONFIG_IP_CONFLICT_STATE_CONFLICT_NOT_DETECTED;
- sd->timeout = td.initial_time;
- send_arp(sd);
- is_ip_conflict_detect_enabled = true;
- conflict_state = NETCONFIG_IP_CONFLICT_STATE_CONFLICT_NOT_DETECTED;
- return sd;
- }
+ return sd;
}
void stop_ip_conflict_mon()
{
INFO("+");
- GError* error = NULL;
if (sd == NULL) {
INFO("sd is NULL");
return;
}
- if (-1 < sd->chk_conflict_sd) {
- if (G_IO_STATUS_NORMAL !=
- g_io_channel_shutdown(sd->chk_conflict_sock_io, FALSE,
- &error)) {
- INFO("Failure received while shutdown io channel[%d]:[%s]", error->code, error->message);
- g_error_free(error);
- }
- g_io_channel_unref(sd->chk_conflict_sock_io);
- g_source_remove(sd->chk_conflict_data_id);
- sd->chk_conflict_data_id = -1;
- close(sd->chk_conflict_sd);
- sd->chk_conflict_sd = -1;
- }
+
+ if (-1 < sd->chk_conflict_sd)
+ __close_channel_and_sock(sd);
+
if (sd->timer_id > 0) {
g_source_remove(sd->timer_id);
sd->timer_id = 0;
{
g_return_val_if_fail(wifi != NULL, TRUE);
-
if (detect == false) {
if (sd != NULL)
stop_ip_conflict_mon();