nova verzija tcp+udp->serial com

Committer:
bosko001
Date:
Sun Apr 05 12:56:41 2020 +0000
Revision:
2:45b351b4fc2a
Child:
3:1196befeace0
n0

Who changed what in which revision?

UserRevisionLine numberNew 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 2:45b351b4fc2a 11 int test_num( char *s )
bosko001 2:45b351b4fc2a 12 {
bosko001 2:45b351b4fc2a 13 int m=strlen(s), n=0, i;
bosko001 2:45b351b4fc2a 14 for( i=0; i<m; i++)
bosko001 2:45b351b4fc2a 15 if( isdigit(s[i]) ) n++;
bosko001 2:45b351b4fc2a 16 if(i==n) return 1;
bosko001 2:45b351b4fc2a 17 return 0;
bosko001 2:45b351b4fc2a 18 }
bosko001 2:45b351b4fc2a 19
bosko001 2:45b351b4fc2a 20 int test_ip( char *s )
bosko001 2:45b351b4fc2a 21 {
bosko001 2:45b351b4fc2a 22 char str[16];
bosko001 2:45b351b4fc2a 23 strncpy( str, s, 16);
bosko001 2:45b351b4fc2a 24
bosko001 2:45b351b4fc2a 25
bosko001 2:45b351b4fc2a 26 int d = strlen(str);
bosko001 2:45b351b4fc2a 27
bosko001 2:45b351b4fc2a 28 if( d < 7) return 0;
bosko001 2:45b351b4fc2a 29 else
bosko001 2:45b351b4fc2a 30 {
bosko001 2:45b351b4fc2a 31 int k=0;
bosko001 2:45b351b4fc2a 32 for( int i=0; i<d; i++)
bosko001 2:45b351b4fc2a 33 if( str[i] == '.' ) k++;
bosko001 2:45b351b4fc2a 34 if(k != 3 ) { return 0; }
bosko001 2:45b351b4fc2a 35 k=0;
bosko001 2:45b351b4fc2a 36 char *token;
bosko001 2:45b351b4fc2a 37 token = strtok(str, ".");
bosko001 2:45b351b4fc2a 38 while( token != NULL )
bosko001 2:45b351b4fc2a 39 {
bosko001 2:45b351b4fc2a 40 if( test_num(token) ) k++;
bosko001 2:45b351b4fc2a 41 token = strtok(NULL, ".");
bosko001 2:45b351b4fc2a 42 }
bosko001 2:45b351b4fc2a 43 if(k==4) return 1;
bosko001 2:45b351b4fc2a 44 else return 0;
bosko001 2:45b351b4fc2a 45
bosko001 2:45b351b4fc2a 46 }
bosko001 2:45b351b4fc2a 47
bosko001 2:45b351b4fc2a 48 }
bosko001 2:45b351b4fc2a 49