Hi All!
There are two possible argument to this programme (extract below) of the
formats "192.148.14.1-192.148.14.30 "and "192.148.14.1/21". I can successfully
extract the int's in either scenario but my error checking seems not intuitive
enough. I was also wondering if there is a concise way of extracting this
int's. and performing the error checking.
And yeah, it's an HOMEWORK that needs perfection.
Thanks.
Lawal. O
int main(int argc,char *argv[]){
int i,ip_add[4],ip_add2[4];
int maskBit;
if( argc==1){
printf("NO INPUT!!\n");
printf("Use --help for help\t -v for version number\n");
return 0;
}
else {
for(i = 1; i < argc; i++)
{
//if any of this options is input
if(!strcmp(argv[i], "--help") || !strcmp(argv[i], "/?") ||
!strcmp(argv[i], "-h"))
{
help();
return 0;
}
if(!strcmp(argv[i], "--version") || !strcmp(argv[i], "-v"))
{
version();
return 0;
}
}
}
//to improve, incorrect input formating
if (sscanf(argv[1],
"%d.%d.%d.%d-%d.%d.%d.%d",&ip_add[0],&ip_add[1],&ip_add[2],&ip_add[3],&ip_add2[0],&ip_add2[1],&ip_add2[2],&ip_add2[3])!=8){
}
else {
deaggregate(ip_add,ip_add2);
return 0;
}
if(
sscanf(argv[1],"%d.%d.%d.%d/%d",&ip_add[0],&ip_add[1],&ip_add[2],&ip_add[3],&maskBit)
!=5 ){
printf("Ip calculation can't be performed'\n");
printf("Deaggregation can't be performed'\n Check Input for errors\n");
return 0;
}
else ipcalc(ip_add,maskBit);
return 0;
}
[Non-text portions of this message have been removed]