feat(v3): parameter sanitization

This commit is contained in:
Paul Alnet 2024-03-07 10:23:56 +01:00
parent 7169fd369d
commit fe9cd55727

View file

@ -65,11 +65,13 @@ int main (int argc, char **argv)
nb_message = atoi(optarg); nb_message = atoi(optarg);
// Packets are numerotated with 5 figures, which means the number of // Packets are numerotated with 5 figures, which means the number of
// packets send can't be bigger than (or equal) 10 ** 6 // packets send can't be bigger than (or equal) 10 ** 6
if(nb_message >= 100000) { if (nb_message >= 100000) {
printf("Too many packets"); printf("Too many packets");
exit(1); exit(1);
} else if (nb_message <= 0) {
printf("Lets try to send all at least one message (:");
exit(1);
} }
break; break;
case 'u': case 'u':
@ -81,9 +83,14 @@ int main (int argc, char **argv)
// A TCP packet is roughly 1500 bytes. We allow for some overhead. // A TCP packet is roughly 1500 bytes. We allow for some overhead.
// We provide an MTU of 1400 bytes. // We provide an MTU of 1400 bytes.
if(lg >= 1400) { 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); exit(1);
} }
break; break;
default: default:
@ -117,7 +124,6 @@ int main (int argc, char **argv)
nb_message = 10 ; nb_message = 10 ;
} }
//Affichage des informations de communication initiée //Affichage des informations de communication initiée
if (source == 1) { if (source == 1) {
//Recuperation du nom logique //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", 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); lg,port,nb_message,(udp)?"UDP":"TCP",nom_machine_distante);
} else { } 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) { if (nb_message!=-1 && !source) {
printf("infini"); printf("infini");
} }