int
main( int argc, char **argv ) {
    int sendRate;
    rbudpSender_t *rbudpSender;

    if ( argc < 4 ) {
        printf( "Usage: sendfile <receiver> <sending rate (Kbps)> <MTU>\n" );
        exit( 1 );
    }

    sendRate = atoi( argv[2] );
    // QUANTAnet_rbudpSender_c *mysender = new QUANTAnet_rbudpSender_c (38000);
    rbudpSender = malloc( sizeof( rbudpSender_t ) );
    memset( rbudpSender, 0, sizeof( rbudpSender_t ) );

    // the constructor
    QUANTAnet_rbudpSender_c( rbudpSender, SEND_PORT );

    // mysender->init (argv[1]);
    initSender( rbudpSender, argv[1] );

    QUANTAnet_rbudpBase_c( &rbudpSender->rbudpBase );
    // mysender->sendfile (sendRate, atoi (argv[3]));
    rbSendfile( rbudpSender, sendRate, atoi( argv[3] ), ( char * ) 0 );

    // mysender->close ();
    sendClose( rbudpSender );
    return 1;
}
Exemple #2
0
int beginCapture() {
  char* dev, errbuf[PCAP_ERRBUF_SIZE];
  pcap_if_t *alldevsp, *devsp;
  //TODO(willscott): Remove IPv4 Limitation
  bpf_u_int32 mask;
  bpf_u_int32 net;

  struct bpf_program fp;
  char filter_exp[] = "icmp[0:1] == 0x0b or (dst port 8080 and dst host %s)";
  char filterbuf[256];

  // Find Device. Gets the first valid device.
  if (pcap_findalldevs(&alldevsp, errbuf)) {
    printf("Couldn't find Devices: %s \n", errbuf);
    exit(1);
  }
  devsp = alldevsp;
  dev = NULL;
  while (devsp != NULL) {
    // flags = !loopback
    char* addr = NULL;
    if (devsp->addresses != NULL && (devsp->flags & 1) != 1) {
      struct pcap_addr* addrs = devsp->addresses;
      while (addrs != NULL) {
        if (addrs->addr->sa_family == AF_INET) {
          addr = inet_ntoa(((struct sockaddr_in*)addrs->addr)->sin_addr);
          break;
        }
        addrs = addrs->next;
      }
      if (addr != NULL) {
        sprintf(filterbuf, filter_exp,addr);
        printf("%s\n", filterbuf);
        dev = devsp->name;
        break;
      }
    } else {
      devsp = devsp->next;
    }
  }
  if (dev == NULL) {
    printf("No valid device found!\n");
    exit(1);
  }
  printf("Using Dev %s\n", dev);

  // Initialize Log.
  logfile = fopen("log.txt", "a");
  if (logfile == NULL) {
    printf("Couldn't open log file.\n");
    exit(1);
  }

  // Get Local IP.
  if (pcap_lookupnet(dev, &net, &mask, errbuf) == -1) {
    printf("Couldn't get netmask for device %s: %s\n", dev, errbuf);
    exit(1);
  }

  // Open Device.
  handle = pcap_open_live(dev, BUFSIZ, 1, 1000, errbuf);
  if (handle == NULL) {
    printf("Couldn't open device %s: %s\n", dev, errbuf);
    exit(1);
  }

  // free list
  pcap_freealldevs(alldevsp);

  // Set the filter.
  if (pcap_compile(handle, &fp, filterbuf, 0, net) == -1) {
    printf("Invalid Filter: %s\n", filter_exp);
    exit(1);
  }
  if (pcap_setfilter(handle, &fp) == -1) {
    printf("Filter couldn't be installed: %s\n", pcap_geterr(handle));
    exit(1);
  }

  if (pcap_setnonblock(handle, 1, errbuf) == -1) {
    printf("Nonblocking mode failed: %s\n", errbuf);
    exit(1);
  }

  // Initialize Sending.
  initSender();

  return pcap_get_selectable_fd(handle);
};
Exemple #3
0
int main (int argc, char** argv)
{
	int choix;
	int lg_message = LG_MESS_DEFAUT;
	int *n;
	char * msg = malloc(sizeof(char)*lg_message);
	
	pthread_mutex_t displayMutex = PTHREAD_MUTEX_INITIALIZER;
	initBeaconsLocation(beaconsLocation, (int) NUMBER_BEACONS);
	
	n = malloc(sizeof(int));
	//*n = 500000;
	*n = 1;
	
	char * adr = malloc(12*sizeof(char));
	adr = ADR_DIST;
	
	msgSend = malloc(sizeof(char)*lg_message);
	msgRcv = malloc(sizeof(char)*lg_message);
	
	pthread_t tid[2];
	pthread_create(&tid[0], NULL, receiverThread, NULL);
	
	// initialisation socket sender.
	// initialisation ici car on a besoin d'un receiver à l'écoute pour lancer le sender, donc pour le test en localhost on le fait après le receiver
	//printf("before %s\n", adr);
	usleep(30000);
	initSender(adr);
	//printf("%s\n", adr);
	
	pthread_create(&tid[1], NULL, coordinatesThread, n);
	
	pthread_mutex_lock(&displayMutex);
	printf("\n  Drone position : \n");
	printf("  Send : \n\n");
	pthread_mutex_unlock(&displayMutex);
	
	while(1) {

		pthread_mutex_lock(&displayMutex);
		printf("What do you want to do ?\n");
		printf("0 -> Calibration (drone must lay flat on the floor)\n");
		printf("1 -> Magnetic calibration\n");
		printf("2 -> landing\n");
		printf("3 -> take off\n");
		printf("4 -> move roll \n");
		printf("5 -> move pitch\n");
		printf("6 -> move pitch roll\n");
		printf("7 -> emergency\n");
		printf("8 -> anti emergency\n");
		printf("9 -> start mission\n");
		printf("10 -> stop mission\n");
		printf("-1 to close the programm\n");
		
		pthread_mutex_unlock(&displayMutex);
		
		scanf("%d", &choix);
		getchar();	
	
		pthread_mutex_lock(&displayMutex);
		printf("\033[%dA", 2);
		printf("\033[%dM", 1);	
		printf("\033[%dJ", 2);
		pthread_mutex_unlock(&displayMutex);	
		
		if (choix >= 0 && choix < 10) {
			sprintf(msg, " %d ", choix);
		}
		else {
			sprintf(msg, "%d ", choix);
		}
		
			
		if (choix == 9) {
		
			pthread_mutex_lock(&displayMutex);
			printf("\033[%dA", 12);
			printf("\033[%dM", 12);
		
			printf("Choose your beacon (from 0 to 7)\n");
			printf("0 -> %s\n", beaconsLocation[0]);
			printf("1 -> %s\n", beaconsLocation[1]);
			printf("2 -> %s\n", beaconsLocation[2]);
			printf("3 -> %s\n", beaconsLocation[3]);
			printf("4 -> %s\n", beaconsLocation[4]);
			printf("5 -> %s\n", beaconsLocation[5]);
			printf("6 -> %s\n", beaconsLocation[6]);
			printf("7 -> %s\n", beaconsLocation[7]);
			printf("\n\n");
			pthread_mutex_unlock(&displayMutex);
			
			scanf("%d", &choix);
			strcat(msg, beaconsLocation[choix]);
			//printf("######## msg : %s\n", msg);
			
			if (choix >= 0 && choix <=7) {
				pthread_mutex_lock(&messageMutex);
				emettre(lg_message, msgSend, msg);
				pthread_mutex_unlock(&messageMutex);
			
			}
			else {
				pthread_mutex_lock(&displayMutex);
				printf("incorrect choice\n");	
				pthread_mutex_unlock(&displayMutex);
			}
				pthread_mutex_lock(&displayMutex);
				printf("\033[%dA", 12);
				printf("\033[%dM", 12);
				printf("\033[%dJ", 2);
				pthread_mutex_unlock(&displayMutex);
		
		}
		else if (choix >= 0 && choix <= 10) {
			pthread_mutex_lock(&messageMutex);
			emettre(lg_message, msgSend, msg);
			pthread_mutex_unlock(&messageMutex);
		}
		else if (choix == -1) {
			pthread_cancel(tid[0]);
			pthread_cancel(tid[1]);
			closeSender();
			closeReceiver();
			break;
		}
		else {
			pthread_mutex_lock(&displayMutex);
			printf("incorrect choice\n");	
			pthread_mutex_unlock(&displayMutex);
		}
	}
	
	
	// pthread_exit(NULL);
	
	return 0;
}
// --------------------------------------------------------------------------
//! Constructor with a stream and the request ID
// --------------------------------------------------------------------------
XipTreeRequestSender::XipTreeRequestSender(XipStreamBase *Stream, short IDRequest) : XipTreeRequestManager(NULL)
{
	initSender(Stream, IDRequest);
}