summaryrefslogtreecommitdiff
path: root/cleopatre/application
diff options
context:
space:
mode:
authorYacine Belkadi2011-04-27 11:03:49 +0200
committerYacine Belkadi2011-05-05 18:19:42 +0200
commit41e3fa77b410198b128473252563f059fcb8dade (patch)
tree056c48e8415d6eec8018bf802bbaffd61fbf86ae /cleopatre/application
parent53393d4de608e9ec80ee20777c7501f123b34b1e (diff)
cleo/app/igmp_snoopd: refactor: init(), igmp_snooping(), refs #2371
- move some initialization code to init(). - rename igmp_snooping() to start_snooping().
Diffstat (limited to 'cleopatre/application')
-rw-r--r--cleopatre/application/igmp_snoopd/src/main.c68
1 files changed, 37 insertions, 31 deletions
diff --git a/cleopatre/application/igmp_snoopd/src/main.c b/cleopatre/application/igmp_snoopd/src/main.c
index 3bca4e20c7..f9c52dd0b2 100644
--- a/cleopatre/application/igmp_snoopd/src/main.c
+++ b/cleopatre/application/igmp_snoopd/src/main.c
@@ -158,12 +158,17 @@ send_general_query (int sockfd)
}
}
-/*
+/**
* Initialize.
- * \param ctx The context.
+ * \param[out] sockfd_rx The socket file descriptor for receiving packets.
+ * \param[out] sockfd_tx The socket file descriptor for sending packets.
+ * \param[out] ctx The context.
+ * \param ifname The name of the interface to use
+ * \param dominant_traffic_type The type of the dominant traffic.
*/
static void
-init (struct context *ctx)
+init (int *sockfd_rx, int *sockfd_tx, struct context *ctx,
+ const char *ifname, traffic_type_t dominant_traffic_type)
{
LIST_INIT (&ctx->groups_head);
@@ -180,6 +185,20 @@ init (struct context *ctx)
evp.sigev_notify_attributes = NULL;
timer_create (CLOCK_MONOTONIC, &evp, &ctx->timer_query_tx);
+
+ *sockfd_rx = open_rx_socket_and_attach_filter (ifname, dominant_traffic_type);
+ if (*sockfd_rx == -1)
+ {
+ exit (EXIT_FAILURE);
+ }
+
+ *sockfd_tx = open_tx_socket (ifname);
+ if (*sockfd_tx == -1)
+ {
+ exit (EXIT_FAILURE);
+ }
+
+ seed_random_number_generator (ifname, *sockfd_tx);
}
/**
@@ -214,7 +233,6 @@ log_libspid_error(const char *fct_name, libspid_error_t status)
}
}
-
/**
* Receive a packet and process it.
* \param sockfd The socket file descriptor.
@@ -272,35 +290,16 @@ receive_and_process (int sockfd,
/**
* Start IGMP Snooping.
- * \param ifname The name of the network interface.
+ * \param sockfd_rx The socket file descriptor for receiving packets.
+ * \param sockfd_tx The socket file descriptor for sending packets.
+ * \param ctx The context.
* \param mcast_info_file The path to the file where to write the multicast
* info.
- * \param dominant_traffic_type The type of the dominant traffic.
- * \param ctx The context.
*/
static void
-igmp_snooping (const char *ifname,
- const char *mcast_info_file,
- traffic_type_t dominant_traffic_type,
- struct context *ctx)
+start_snooping (int sockfd_rx, int sockfd_tx, struct context *ctx,
+ const char *mcast_info_file)
{
- /* Socket for listening to traffic */
- int sockfd_rx = open_rx_socket_and_attach_filter (ifname,
- dominant_traffic_type);
- if (sockfd_rx == -1)
- {
- exit (EXIT_FAILURE);
- }
-
- /* Socket for sending queries */
- int sockfd_tx = open_tx_socket (ifname);
- if (sockfd_tx == -1)
- {
- exit (EXIT_FAILURE);
- }
-
- seed_random_number_generator (ifname, sockfd_tx);
-
sigset_t sigmask;
/* Block the signal used for the timer */
@@ -404,12 +403,19 @@ main (int argc, char *argv[])
return -1;
}
+ /* Socket for listening to traffic */
+ int sockfd_rx;
+
+ /* Socket for sending queries */
+ int sockfd_tx;
+
+ /* The context */
struct context ctx;
- init (&ctx);
+ init (&sockfd_rx, &sockfd_tx, &ctx, INTERFACE_NAME, dominant_traffic_type);
- igmp_snooping (INTERFACE_NAME, LIBSPID_MULTICAST_INFO_PATH,
- dominant_traffic_type, &ctx); /* never returns */
+ start_snooping (sockfd_rx, sockfd_tx, &ctx,
+ LIBSPID_MULTICAST_INFO_PATH); /* never returns */
return 0;
}