A function that checks if a string subnet mask is valid
Missing includes

#include &lt;stdbool.h&gt;
#include &lt;string.h&gt;


Other test may be needed

@Wingblade

Non-standard function

is_numeric() is not standard C library nor did I find it in Linux.

Questionable signature

I'd expect a function that checks a string's validity to cope with a const char * subNetMask.  So using strtok() on the supplied subNetMask is not possible.  Code needs to make a copy or otherwise assess the string.

// isValidSubnetMask(IN char *subNetMask)
isValidSubnetMask(IN const char *subNetMask)


Weak functionality

Below are 7 test cases that failed OP's code.  Sample working code provided.  sscanf() is a bit ponderous, yet useful as a test competitor.

bool is_numeric() {  // Added undefined Op's missing function.
  return true;
}

static bool isValidSubnetMask2(const char *subNetMask) {
  int n = 0;
  sscanf(subNetMask, "%*3[0-9].%*3[0-9].%*3[0-9].%*3[0-9]%n", &amp;n);
  if (n == 0 || subNetMask[n]) {
    return false;
  }
  int i[4];
  sscanf(subNetMask, "%d.%d.%d.%d", &amp;i[0], &amp;i[1], &amp;i[2], &amp;i[3]);
  return i[0] &lt;= 255 &amp;&amp; i[1] &lt;= 255 &amp;&amp; i[2] &lt;= 255 &amp;&amp; i[3] &lt;= 255;
}

void test(bool expect, const char *s) {
  char buff[99];
  strcpy(buff, s);
  bool y = isValidSubnetMask(buff);
  if (y != expect) {
    printf("Failed %d &lt;%s&gt;\n", expect, s);
  }
  y = isValidSubnetMask2(s);
  if (y != expect) {
    printf("Oops %d &lt;%s&gt;\n", expect, s);
  }
}

int main() {
  test(1, "255.255.255.0");
  test(1, "255.255.255.123");
  test(1, "0.0.0.0");
  test(0, "455.255.255.0");
  test(0, "255.255.255.-0");
  test(0, "255.255.255. 0");
  test(0, "2.2.5.2.3");
  test(0, "2.2.3");
  test(0, "+2.5.2.3");
  test(0, "A.5.2.3");
  test(0, "2.2.5.2.");
  test(0, "2..2.5.2");
  return 0;
}


Output

Failed 0 &lt;255.255.255.-0&gt;
Failed 0 &lt;255.255.255. 0&gt;
Failed 0 &lt;2.2.5.2.3&gt;
Failed 0 &lt;2.2.3&gt;
Failed 0 &lt;+2.5.2.3&gt;
Failed 0 &lt;2.2.5.2.&gt;
Failed 0 &lt;2..2.5.2&gt;