Skip to content

Commit

Permalink
Fix initialization and deinitialization of mrouter socket
Browse files Browse the repository at this point in the history
Ensure that uninitialized socket is invalid (-1) and not stdin (0).
  • Loading branch information
pali committed Sep 5, 2020
1 parent 7d4598a commit a7791d5
Showing 1 changed file with 7 additions and 8 deletions.
15 changes: 7 additions & 8 deletions src/mroute-api.c
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@

// need an IGMP socket as interface for the mrouted API
// - receives the IGMP messages
int MRouterFD; /* socket for all network I/O */
int MRouterFD = -1; /* socket for all network I/O */
char *recv_buf; /* input packet buffer */
char *send_buf; /* output packet buffer */

Expand Down Expand Up @@ -78,14 +78,13 @@ int enableMRouter(void)
*/
void disableMRouter(void)
{
if ( setsockopt( MRouterFD, IPPROTO_IP, MRT_DONE, NULL, 0 )
|| close( MRouterFD )
) {
MRouterFD = 0;
my_log( LOG_ERR, errno, "MRT_DONE/close" );
}
if ( setsockopt( MRouterFD, IPPROTO_IP, MRT_DONE, NULL, 0 ) < 0 )
my_log( LOG_WARNING, errno, "MRT_DONE" );

if ( close( MRouterFD ) < 0 )
my_log( LOG_WARNING, errno, "IGMP socket close" );

MRouterFD = 0;
MRouterFD = -1;
}

/*
Expand Down

0 comments on commit a7791d5

Please sign in to comment.