bosko lekovic
/
EthToCom_11
nova proba
clubbing.cpp@8:c0f54b381346, 2020-04-19 (annotated)
- Committer:
- bosko001
- Date:
- Sun Apr 19 22:13:45 2020 +0000
- Revision:
- 8:c0f54b381346
- Parent:
- 5:c9a908749d4c
zavrseno sa dataFlashom i sa HTML-om
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
bosko001 | 2:45b351b4fc2a | 1 | #include "clubbing.h" |
bosko001 | 2:45b351b4fc2a | 2 | |
bosko001 | 2:45b351b4fc2a | 3 | |
bosko001 | 2:45b351b4fc2a | 4 | |
bosko001 | 2:45b351b4fc2a | 5 | #include <stdio.h> |
bosko001 | 2:45b351b4fc2a | 6 | #include <stdlib.h> |
bosko001 | 2:45b351b4fc2a | 7 | #include <string.h> |
bosko001 | 2:45b351b4fc2a | 8 | #include <ctype.h> |
bosko001 | 2:45b351b4fc2a | 9 | |
bosko001 | 2:45b351b4fc2a | 10 | |
bosko001 | 8:c0f54b381346 | 11 | |
bosko001 | 8:c0f54b381346 | 12 | #define IN_RANGE( MIN, a, MAX ) ((a >= MIN) ? (( a<=MAX) ? 1:0) : 0) |
bosko001 | 8:c0f54b381346 | 13 | |
bosko001 | 8:c0f54b381346 | 14 | |
bosko001 | 3:1196befeace0 | 15 | /********************** PRINT-ovi *********************************/ |
bosko001 | 3:1196befeace0 | 16 | |
bosko001 | 5:c9a908749d4c | 17 | void P_niz( const char *s, const char *niz, int val ) |
bosko001 | 3:1196befeace0 | 18 | { |
bosko001 | 3:1196befeace0 | 19 | printf("%s",s); |
bosko001 | 3:1196befeace0 | 20 | for( int i=0; i < val; i++) printf("%c", niz[i]); |
bosko001 | 3:1196befeace0 | 21 | printf("\n\r"); |
bosko001 | 3:1196befeace0 | 22 | fflush(stdout); |
bosko001 | 3:1196befeace0 | 23 | } |
bosko001 | 3:1196befeace0 | 24 | |
bosko001 | 5:c9a908749d4c | 25 | void P_int(const char *s, int i ) |
bosko001 | 3:1196befeace0 | 26 | { |
bosko001 | 3:1196befeace0 | 27 | printf("%s = %d\n\r", s, i); fflush(stdout); |
bosko001 | 3:1196befeace0 | 28 | } |
bosko001 | 3:1196befeace0 | 29 | |
bosko001 | 3:1196befeace0 | 30 | void P_str(const char *s, const char *p ) |
bosko001 | 3:1196befeace0 | 31 | { |
bosko001 | 3:1196befeace0 | 32 | printf("%s = %s\n\r", s, p); fflush(stdout); |
bosko001 | 3:1196befeace0 | 33 | } |
bosko001 | 3:1196befeace0 | 34 | |
bosko001 | 3:1196befeace0 | 35 | |
bosko001 | 3:1196befeace0 | 36 | |
bosko001 | 3:1196befeace0 | 37 | /************************ IP testovi ****************************/ |
bosko001 | 8:c0f54b381346 | 38 | int _test_num( const char *s ) |
bosko001 | 2:45b351b4fc2a | 39 | { |
bosko001 | 2:45b351b4fc2a | 40 | int m=strlen(s), n=0, i; |
bosko001 | 2:45b351b4fc2a | 41 | for( i=0; i<m; i++) |
bosko001 | 2:45b351b4fc2a | 42 | if( isdigit(s[i]) ) n++; |
bosko001 | 2:45b351b4fc2a | 43 | if(i==n) return 1; |
bosko001 | 2:45b351b4fc2a | 44 | return 0; |
bosko001 | 2:45b351b4fc2a | 45 | } |
bosko001 | 2:45b351b4fc2a | 46 | |
bosko001 | 8:c0f54b381346 | 47 | int test_num( const char *s ) |
bosko001 | 8:c0f54b381346 | 48 | { |
bosko001 | 8:c0f54b381346 | 49 | if ( _test_num( s ) ) |
bosko001 | 8:c0f54b381346 | 50 | if( IN_RANGE( 1000, atoi(s), 65535-1) ) return 1; |
bosko001 | 8:c0f54b381346 | 51 | return 0; |
bosko001 | 8:c0f54b381346 | 52 | } |
bosko001 | 8:c0f54b381346 | 53 | |
bosko001 | 5:c9a908749d4c | 54 | int test_ip( const char *s ) |
bosko001 | 2:45b351b4fc2a | 55 | { |
bosko001 | 2:45b351b4fc2a | 56 | char str[16]; |
bosko001 | 2:45b351b4fc2a | 57 | strncpy( str, s, 16); |
bosko001 | 2:45b351b4fc2a | 58 | |
bosko001 | 2:45b351b4fc2a | 59 | |
bosko001 | 2:45b351b4fc2a | 60 | int d = strlen(str); |
bosko001 | 2:45b351b4fc2a | 61 | |
bosko001 | 2:45b351b4fc2a | 62 | if( d < 7) return 0; |
bosko001 | 2:45b351b4fc2a | 63 | else |
bosko001 | 2:45b351b4fc2a | 64 | { |
bosko001 | 2:45b351b4fc2a | 65 | int k=0; |
bosko001 | 2:45b351b4fc2a | 66 | for( int i=0; i<d; i++) |
bosko001 | 2:45b351b4fc2a | 67 | if( str[i] == '.' ) k++; |
bosko001 | 2:45b351b4fc2a | 68 | if(k != 3 ) { return 0; } |
bosko001 | 2:45b351b4fc2a | 69 | k=0; |
bosko001 | 2:45b351b4fc2a | 70 | char *token; |
bosko001 | 2:45b351b4fc2a | 71 | token = strtok(str, "."); |
bosko001 | 2:45b351b4fc2a | 72 | while( token != NULL ) |
bosko001 | 2:45b351b4fc2a | 73 | { |
bosko001 | 8:c0f54b381346 | 74 | if( _test_num(token) ) k++; |
bosko001 | 2:45b351b4fc2a | 75 | token = strtok(NULL, "."); |
bosko001 | 2:45b351b4fc2a | 76 | } |
bosko001 | 2:45b351b4fc2a | 77 | if(k==4) return 1; |
bosko001 | 2:45b351b4fc2a | 78 | else return 0; |
bosko001 | 2:45b351b4fc2a | 79 | |
bosko001 | 2:45b351b4fc2a | 80 | } |
bosko001 | 2:45b351b4fc2a | 81 | |
bosko001 | 2:45b351b4fc2a | 82 | } |
bosko001 | 2:45b351b4fc2a | 83 | |
bosko001 | 3:1196befeace0 | 84 | |
bosko001 | 3:1196befeace0 | 85 |