diff --git a/src/include/socket.h b/src/include/socket.h index 8197a65..68ce235 100644 --- a/src/include/socket.h +++ b/src/include/socket.h @@ -66,6 +66,7 @@ static int findInterfaces(const char* prefixList, char* names, union socketAddre #endif struct netIf userIfs[MAX_IFS]; bool searchNot = prefixList && prefixList[0] == '^'; + bool searchExact = prefixList && prefixList[0] == '='; int nUserIfs = parseStringList(prefixList, userIfs, MAX_IFS); int found = 0; @@ -92,7 +93,7 @@ static int findInterfaces(const char* prefixList, char* names, union socketAddre } // check against user specified interfaces - if (!(matchIfList(interface->ifa_name, -1, userIfs, nUserIfs) ^ searchNot)) { + if (!(matchIfList(interface->ifa_name, -1, userIfs, nUserIfs, searchExact) ^ searchNot)) { continue; } diff --git a/src/include/utils.h b/src/include/utils.h index 29b72ad..93e72c8 100644 --- a/src/include/utils.h +++ b/src/include/utils.h @@ -20,6 +20,6 @@ struct netIf { }; int parseStringList(const char* string, struct netIf* ifList, int maxList); -bool matchIfList(const char* string, int port, struct netIf* ifList, int listSize); +bool matchIfList(const char* string, int port, struct netIf* ifList, int listSize, bool matchExact); #endif diff --git a/src/misc/utils.cc b/src/misc/utils.cc index 5e884ae..5093755 100644 --- a/src/misc/utils.cc +++ b/src/misc/utils.cc @@ -147,8 +147,8 @@ int parseStringList(const char* string, struct netIf* ifList, int maxList) { if (!string) return 0; const char* ptr = string; - // Ignore "^" prefix, will be detected outside of this function - if (ptr[0] == '^') ptr++; + // Ignore "^" or "=" prefix, will be detected outside of this function + if (ptr[0] == '^' || ptr[0] == '=') ptr++; int ifNum = 0; int ifC = 0; @@ -177,8 +177,10 @@ int parseStringList(const char* string, struct netIf* ifList, int maxList) { return ifNum; } -static bool matchPrefix(const char* string, const char* prefix) { - return (strncmp(string, prefix, strlen(prefix)) == 0); +static bool matchIf(const char* string, const char* ref, bool matchExact) { + // Make sure to include '\0' in the exact case + int matchLen = matchExact ? strlen(string) + 1 : strlen(ref); + return strncmp(string, ref, matchLen) == 0; } static bool matchPort(const int port1, const int port2) { @@ -189,12 +191,12 @@ static bool matchPort(const int port1, const int port2) { } -bool matchIfList(const char* string, int port, struct netIf* ifList, int listSize) { +bool matchIfList(const char* string, int port, struct netIf* ifList, int listSize, bool matchExact) { // Make an exception for the case where no user list is defined if (listSize == 0) return true; for (int i=0; i