- Timestamp:
- Mar 29, 2014, 7:59:38 AM (11 years ago)
- Location:
- trunk/src
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/cutest_sh_tools.c
r295 r448 114 114 CuAssertTrue(tc, !sh_ipvx_is_numeric(input)); 115 115 input = strdup("127"); 116 CuAssertTrue(tc, sh_ipvx_is_numeric(input));116 CuAssertTrue(tc, !sh_ipvx_is_numeric(input)); 117 117 } 118 118 -
trunk/src/sh_ipvx.c
r422 r448 41 41 { 42 42 int j; 43 int count = 0; 43 44 int len = sl_strlen(addr); 45 unsigned int a, b, c, d; 44 46 45 for (j = 0; j < len; ++j) 47 if (len > 15) /* 3*4 + 3 dots */ 48 return (1 == 0); 49 50 for (j = 0; j < len; ++j) { 46 51 if ( (addr[j] < '0' || addr[j] > '9') && addr[j] != '.') 47 52 return (1 == 0); 53 if (addr[j] == '.') ++count; 54 } 55 56 if (count != 3) 57 return (1 == 0); 58 59 if (sscanf(addr, "%3u.%3u.%3u.%3u", &a, &b, &c, &d) != 4) 60 return( 1 == 0 ); 61 62 if ((a|b|c|d) > 255) 63 return( 1 == 0 ); 64 48 65 return (1 == 1); 49 66 } … … 538 555 return 0; 539 556 } 557 558 #ifdef SH_CUTEST 559 #include <stdlib.h> 560 #include "CuTest.h" 561 562 void Test_ipvx (CuTest *tc) { 563 564 int result; 565 566 result = sh_ipvx_is_ipv4("123456789"); 567 CuAssertTrue(tc, result == FALSE); 568 569 result = sh_ipvx_is_ipv4("123456789123..."); 570 CuAssertTrue(tc, result == FALSE); 571 572 result = sh_ipvx_is_ipv4("123.456.789.123"); 573 CuAssertTrue(tc, result == FALSE); 574 575 result = sh_ipvx_is_ipv4("123.156.189.254"); 576 CuAssertTrue(tc, result == TRUE); 577 578 result = sh_ipvx_is_ipv4("255.255.255.255"); 579 CuAssertTrue(tc, result == TRUE); 580 581 result = sh_ipvx_is_ipv4("0.0.0.0"); 582 CuAssertTrue(tc, result == TRUE); 583 584 result = sh_ipvx_is_ipv4("0022.156.189.254"); 585 CuAssertTrue(tc, result == FALSE); 586 587 result = sh_ipvx_is_ipv4("999999999.1.1.2"); 588 CuAssertTrue(tc, result == FALSE); 589 590 } 591 #endif 592
Note:
See TracChangeset
for help on using the changeset viewer.