bosko lekovic
/
ETHtoCOM_10
nova verzija tcp+udp->serial com
clubbing.cpp
- Committer:
- bosko001
- Date:
- 2020-07-10
- Revision:
- 26:c14d034d7459
- Parent:
- 8:c0f54b381346
File content as of revision 26:c14d034d7459:
#include "clubbing.h" #include <stdio.h> #include <stdlib.h> #include <string.h> #include <ctype.h> #define IN_RANGE( MIN, a, MAX ) ((a >= MIN) ? (( a<=MAX) ? 1:0) : 0) /********************** PRINT-ovi *********************************/ void P_niz( const char *s, const char *niz, int val ) { printf("%s",s); for( int i=0; i < val; i++) printf("%c", niz[i]); printf("\n\r"); fflush(stdout); } void P_int(const char *s, int i ) { printf("%s = %d\n\r", s, i); fflush(stdout); } void P_str(const char *s, const char *p ) { printf("%s = %s\n\r", s, p); fflush(stdout); } /************************ IP testovi ****************************/ int _test_num( const char *s ) { int m=strlen(s), n=0, i; for( i=0; i<m; i++) if( isdigit(s[i]) ) n++; if(i==n) return 1; return 0; } int test_num( const char *s ) { if ( _test_num( s ) ) if( IN_RANGE( 1000, atoi(s), 65535-1) ) return 1; return 0; } int test_ip( const char *s ) { char str[16]; strncpy( str, s, 16); int d = strlen(str); if( d < 7) return 0; else { int k=0; for( int i=0; i<d; i++) if( str[i] == '.' ) k++; if(k != 3 ) { return 0; } k=0; char *token; token = strtok(str, "."); while( token != NULL ) { if( _test_num(token) ) k++; token = strtok(NULL, "."); } if(k==4) return 1; else return 0; } }