feat(v3): parameter sanitization
This commit is contained in:
parent
7169fd369d
commit
fe9cd55727
1 changed files with 11 additions and 5 deletions
16
tsock_v3.c
16
tsock_v3.c
|
@ -65,11 +65,13 @@ int main (int argc, char **argv)
|
|||
nb_message = atoi(optarg);
|
||||
// Packets are numerotated with 5 figures, which means the number of
|
||||
// packets send can't be bigger than (or equal) 10 ** 6
|
||||
if(nb_message >= 100000) {
|
||||
if (nb_message >= 100000) {
|
||||
printf("Too many packets");
|
||||
exit(1);
|
||||
} else if (nb_message <= 0) {
|
||||
printf("Lets try to send all at least one message (:");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
case 'u':
|
||||
|
@ -81,9 +83,14 @@ int main (int argc, char **argv)
|
|||
// A TCP packet is roughly 1500 bytes. We allow for some overhead.
|
||||
// We provide an MTU of 1400 bytes.
|
||||
if(lg >= 1400) {
|
||||
printf("Messages too long");
|
||||
printf("Messages too long (max 1400)");
|
||||
exit(1);
|
||||
} else if (lg < 5) {
|
||||
// The message size includes the message number, whos size is 5.
|
||||
printf("Messages too long (min 5)");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
default:
|
||||
|
@ -117,7 +124,6 @@ int main (int argc, char **argv)
|
|||
nb_message = 10 ;
|
||||
}
|
||||
|
||||
|
||||
//Affichage des informations de communication initiée
|
||||
if (source == 1) {
|
||||
//Recuperation du nom logique
|
||||
|
@ -125,7 +131,7 @@ int main (int argc, char **argv)
|
|||
printf("SOURCE:lg_mesg_emis=%d,port=%d,nb_envois=%d,TP=%s,dest=%s\n",
|
||||
lg,port,nb_message,(udp)?"UDP":"TCP",nom_machine_distante);
|
||||
} else {
|
||||
printf("PUITS:lg_mesg-lu=%d,port=%d,nb_receptions=",lg,port);
|
||||
printf("PUITS:lg_mesg_lu=%d,port=%d,nb_receptions=",lg,port);
|
||||
if (nb_message!=-1 && !source) {
|
||||
printf("infini");
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue