mirror of
https://github.com/yoboujon/tsock.git
synced 2025-06-08 14:00:50 +02:00
Merge pull request #5 from yoboujon/yohan
Ajout de l'adresse ip et du port dans les paramètres.
This commit is contained in:
commit
ce8b44f3b4
7 changed files with 36 additions and 22 deletions
|
@ -2,7 +2,7 @@
|
||||||
#define HEADER_PUIT
|
#define HEADER_PUIT
|
||||||
|
|
||||||
#include "tsock.h"
|
#include "tsock.h"
|
||||||
int launchPuit(int nombreMessage,int TailleMessage);
|
int launchPuit(int nombreMessage,int TailleMessage,int isTCP);
|
||||||
int receiveMultipleData(int nombreMessages, int tailleMessage, int sock, struct sockaddr_in socketStruct);
|
int receiveMultipleData(int nombreMessages, int tailleMessage, int sock, struct sockaddr_in socketStruct);
|
||||||
int exitMax(int var,int tailleMax);
|
int exitMax(int var,int tailleMax);
|
||||||
#endif
|
#endif
|
|
@ -2,7 +2,7 @@
|
||||||
#define HEADER_SOURCE
|
#define HEADER_SOURCE
|
||||||
#include "tsock.h"
|
#include "tsock.h"
|
||||||
|
|
||||||
int launchSource(int nombreMessage);
|
int launchSource(int nombreMessage, int isTCP);
|
||||||
int sendMultipleData(int nombreMessages, int tailleMessage, int sock, struct sockaddr_in socketStruct);
|
int sendMultipleData(int nombreMessages, int tailleMessage, int sock, struct sockaddr_in socketStruct);
|
||||||
|
|
||||||
#endif
|
#endif
|
|
@ -10,10 +10,12 @@
|
||||||
#include <netdb.h>
|
#include <netdb.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
void setNbMessage(int * nb, int source);
|
void setNbMessage(int * nb, int source);
|
||||||
void printInfo(int nb, int source);
|
void printInfo(int nb, int source, int portNumber, char ipAddress[]);
|
||||||
void initStructSocket(struct sockaddr_in *socketServerTemp, int source);
|
void initStructSocket(struct sockaddr_in *socketServerTemp, int source);
|
||||||
|
void getNonOtpArgs(char ** argv, int argc, int portNumber, char * ipAddress[]);
|
||||||
|
|
||||||
#define PORT_NUM 9000
|
#define PORT_NUM 9000
|
||||||
|
|
||||||
|
|
33
src/main.c
33
src/main.c
|
@ -4,24 +4,23 @@
|
||||||
|
|
||||||
int main (int argc, char **argv)
|
int main (int argc, char **argv)
|
||||||
{
|
{
|
||||||
int c;
|
char usageChar[30]="usage: cmd [-p|-s][-n ##]\n";
|
||||||
|
char *ipAddress;
|
||||||
extern char *optarg;
|
extern char *optarg;
|
||||||
extern int optind;
|
extern int optind;
|
||||||
int nb_message = -1; /* Nb de messages à envoyer ou à recevoir, par défaut : 10 en émission, infini en réception */
|
int source = -1, nb_message = -1, c, tcp=1, port=9000, tailleMessage; /* Nb de messages à envoyer ou à recevoir, par défaut : 10 en émission, infini en réception */
|
||||||
int source = -1 ; /* 0=puits, 1=source */
|
while ((c = getopt(argc, argv, "pn:su")) != -1) {
|
||||||
int tailleMessage; // -l
|
|
||||||
while ((c = getopt(argc, argv, "pn:sl:")) != -1) {
|
|
||||||
switch (c) {
|
switch (c) {
|
||||||
case 'p':
|
case 'p':
|
||||||
if (source != -1) {
|
if (source != -1) {
|
||||||
printf("usage: cmd [-p|-s][-n ##]\n");
|
printf(usageChar);
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
source = 0;
|
source = 0;
|
||||||
break;
|
break;
|
||||||
case 's':
|
case 's':
|
||||||
if (source != -1) {
|
if (source != -1) {
|
||||||
printf("usage: cmd [-p|-s][-n ##]\n");
|
printf(usageChar);
|
||||||
exit(1) ;
|
exit(1) ;
|
||||||
}
|
}
|
||||||
source = 1;
|
source = 1;
|
||||||
|
@ -33,28 +32,32 @@ int main (int argc, char **argv)
|
||||||
case 'n':
|
case 'n':
|
||||||
nb_message = atoi(optarg);
|
nb_message = atoi(optarg);
|
||||||
break;
|
break;
|
||||||
|
case 'u':
|
||||||
|
tcp=0;
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
printf("usage: cmd [-p|-s][-n ##]\n");
|
printf(usageChar);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (source == -1) {
|
if (source == -1) {
|
||||||
printf("usage: cmd [-p|-s][-n ##]\n");
|
printf("-p|-s non present !\n");
|
||||||
|
printf(usageChar);
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
getNonOtpArgs(argv, argc, port, &ipAddress);
|
||||||
setNbMessage(&nb_message,source);
|
setNbMessage(&nb_message,source);
|
||||||
printInfo(nb_message,source);
|
printInfo(nb_message,source,port,ipAddress);
|
||||||
|
|
||||||
if(source)
|
if(source)
|
||||||
{
|
{
|
||||||
printf("Source : %d\n",nb_message);
|
//printf("Source : %d\n",nb_message);
|
||||||
launchSource(nb_message);
|
launchSource(nb_message,tcp);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
printf("Puit : %d\n",nb_message);
|
//printf("Puit : %d\n",nb_message);
|
||||||
launchPuit(nb_message,tailleMessage);
|
launchPuit(nb_message,tailleMessage,tcp);
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -1,6 +1,6 @@
|
||||||
#include "../header/puit.h"
|
#include "../header/puit.h"
|
||||||
|
|
||||||
int launchPuit(int nombreMessage,int tailleMessage)
|
int launchPuit(int nombreMessage,int tailleMessage,int isTCP)
|
||||||
{
|
{
|
||||||
int sock;
|
int sock;
|
||||||
struct sockaddr_in socketPuit;
|
struct sockaddr_in socketPuit;
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
#include "../header/source.h"
|
#include "../header/source.h"
|
||||||
|
|
||||||
int launchSource(int nombreMessage)
|
int launchSource(int nombreMessage, int isTCP)
|
||||||
{
|
{
|
||||||
int sock;
|
int sock;
|
||||||
struct sockaddr_in socketSource;
|
struct sockaddr_in socketSource;
|
||||||
|
|
13
src/tsock.c
13
src/tsock.c
|
@ -8,16 +8,17 @@ void setNbMessage(int * nb, int source)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void printInfo(int nb, int source)
|
void printInfo(int nb, int source, int portNumber, char ipAddress[])
|
||||||
{
|
{
|
||||||
if(source)
|
if(source)
|
||||||
{
|
{
|
||||||
printf("tsock lance en mode source, nombre de tampons à envoyer : %d\n", nb);
|
printf("tsock lance en mode source, nombre de tampons à envoyer : %d\nPort : %d\t Adresse IP : %s\n", nb, portNumber, ipAddress);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
printf("tsock lance en mode puit, nombre de tampons à recevoir :");
|
printf("tsock lance en mode puit, nombre de tampons à recevoir :");
|
||||||
nb != -1 ? printf("%d\n", nb) : printf("infini\n");
|
nb != -1 ? printf("%d\n", nb) : printf("infini\n");
|
||||||
|
printf("Port : %d\n",portNumber);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -41,4 +42,12 @@ void initStructSocket(struct sockaddr_in *socketTempStruct, int source)
|
||||||
socketTempStruct->sin_addr.s_addr=INADDR_ANY;
|
socketTempStruct->sin_addr.s_addr=INADDR_ANY;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void getNonOtpArgs(char ** argv, int argc, int portNumber, char ** ipAddress)
|
||||||
|
{
|
||||||
|
portNumber = atoi(argv[argc-2]);
|
||||||
|
*ipAddress = NULL;
|
||||||
|
*ipAddress = (char *)malloc(sizeof(argv[argc-1]));
|
||||||
|
strcpy(*ipAddress,argv[argc-1]);
|
||||||
}
|
}
|
Loading…
Add table
Reference in a new issue