예제 #1
0
int main(void) {
	coconut::IOServiceContainer ioServiceContainer;

	boost::shared_ptr<MyUdpClientController> udpclient(new MyUdpClientController);
	coconut::NetworkHelper::bindUdp(&ioServiceContainer, 0/*for client*/, udpclient);
	udpclient->udpSocket()->writeTo("HELLO", 5, "localhost", UDP_PORT);

	ioServiceContainer.run();
}
예제 #2
0
double estimateCapacity_pairs(int tcpsock)
{
	pcapeststart pcap;
	pcapestack pcapack;
	int udpsock = 0;
	char buf[2000];
	int ret;
	struct timeval tv;
	double ct = 0;

	pcap.header.ptype = P_CAPEST_START;
	pcap.header.length = 0;
	writewrapper(tcpsock, (char *)&pcap, sizeof(struct _capeststart));
	ret = readwrapper(tcpsock, (char *)&pcapack, sizeof(struct _capestack));
	if(ret == -1 || pcapack.header.ptype != P_CAP_ACK)
	{
		fprintf(stderr, "cannot read OR wrong cap ack\n");
		return -1;
	}

	udpsock = udpclient();
	while(1)
	{
		gettimeofday(&tv, NULL);
		ct = tv.tv_sec + tv.tv_usec/1.0e6;
		memcpy(buf, (const char *)&ct, sizeof(ct));
		ret = send(udpsock, buf, 500, 0);
		if(ret == -1)
		{
			fprintf(stderr, "cannot send\n");
			return -1;
		}
		ret = send(udpsock, buf, 500, 0);
		if(ret == -1)
		{
			fprintf(stderr, "cannot send\n");
			return -1;
		}

		ret = readwrapper(tcpsock, (char *)&pcapack, 
				sizeof(struct _capestack));
		if(ret == -1 || pcapack.header.ptype != P_CAP_ACK)
		{
			fprintf(stderr, "cannot read OR wrong cap ack\n");
			return -1;
		}
		//printf("Capacity: %.2f\n", pcapack.capacity);
		printf("."); fflush(stdout);
		if(pcapack.finalflag == 1) break;
		usleep(30000);
	}

	close(udpsock);

	printf("Capacity: %.2f\n", pcapack.capacity);
	return pcapack.capacity;
}
예제 #3
0
void Udpclienthandler(void *param)
{
	/*here gives the udp demo code*/
	vTaskDelay(1000);
	printf("\n\rUdp client test");
	
	udpclient();	
#if defined(INCLUDE_uxTaskGetStackHighWaterMark) && (INCLUDE_uxTaskGetStackHighWaterMark == 1)
	printf("\n\rMin available stack size of %s = %d * %d bytes", __FUNCTION__, uxTaskGetStackHighWaterMark(NULL), sizeof(portBASE_TYPE));
#endif
	printf("\n\rUDP: udp client stopped!");
	udpcllient_task = NULL;
	vTaskDelete(NULL);	
}
예제 #4
0
파일: pwnat.c 프로젝트: PKRoma/pwnat
int main(int argc, char* argv[])
{
	int ret;
	int isserv = 0;
#ifdef _WIN32
	WSADATA wsa_data;
	ret = WSAStartup(MAKEWORD(2,0), &wsa_data);
	ERROR_GOTO(ret != 0, "WSAStartup() failed", error);
#endif
	while((ret = getopt(argc, argv, "hscv6")) != EOF) {
		switch(ret) {
		case '6':
			ipver = SOCK_IPV6;
			break;
		case 's':
			isserv = 1;
			break;
		case 'c':
			isserv = 0;
			break;
		case 'v':
			if(debug_level < 3)
				debug_level++;
			break;
		case 'h':
			/* fall through */
		default:
			goto error;
		}
	}
	ret = 0;
	if(isserv) {
		if(argc - optind < 0)
			goto error;
		ret = udpserver(argc - optind, argv + optind);
	} else {
		if(argc - optind != 5 && argc - optind != 6 && argc - optind != 4)
			goto error;
		ret = udpclient(argc - optind, argv + optind);
	}
#ifdef _WIN32
	WSACleanup();
#endif
	return ret;
error:
	usage(argv[0]);
	exit(1);
}
예제 #5
0
int main ( int argc, char **argv)
{
	struct sockaddr_in peer;
	SOCKET s;

	INIT();

	set_address(argv[1], argv[2], &peer, "upd");
	s = socket(AF_INET, SOCK_DGRAM, 0);
	if (!isvalidsock(s))
		error(1, errno, "error in call socket()");

	if (connect(s, (struct sockaddr *)&peer, sizeof(peer)))
		error (1, errno, "error in call connect");

	udpclient(s, &peer);

	EXIT(0);
}
예제 #6
0
int main(int argc, char *argv[])
{
  int tcpsock = 0;
  int udpsock = 0;
  struct sockaddr_in from;
  double capacityup = 0, capacitydown = 0;
  double measupcap = 0, measdowncap = 0;
  unsigned int tbresult = 0, tbmindepth = 0, tbmaxdepth = 0, tbabortflag = 0;
  double tbrate = 0, truecapup = 0, truecapdown = 0;
  double sleepRes = 1;
  char filename[256], tracefile[256];
  int fileid = -1;
  struct in_addr sin_addr;
  struct timeval tv;
  FILE *fp;
  extern double TB_RATE_AVG_INTERVAL;

  TB_RATE_AVG_INTERVAL = 0.3;

  memset(tracefile, 0, 256);
  CHKRET(prober_config_load(argc, argv, tracefile, &fileid));

  sleepRes = prober_sleep_resolution();

  if (serverip) {
    tcpsock = connect2server(serverip, fileid);
  } else {
    tcpsock = selectServer(fileid);
    if(tcpsock <= 0) printf("Server busy. Please try again later.\n");
  }
  CHKRET(tcpsock);

  memset(&from, 0, sizeof(from));
  from.sin_family      = PF_INET;
  //from.sin_port        = htons(SERV_PORT_UDP);
  from.sin_port        = htons(serv_port);
  from.sin_addr.s_addr = serverip;

  gettimeofday(&tv, NULL);
  sin_addr.s_addr = serverip;
  memset(filename, 0, 256);
  sprintf(filename, "/tmp/udp_%s.log", inet_ntoa(sin_addr));
  fp = fopen(filename, "a+w");
  fprintf(fp, "sleep time resolution: %.2f ms.\n", sleepRes*1000);

  //udpsock = udpclient(serverip, SERV_PORT_UDP);
  udpsock = udpclient(serverip, serv_port);
  CHKRET(udpsock);
  sin_addr.s_addr = serverip;
  fprintf(fp, "Connected to server %s.\n", inet_ntoa(sin_addr));

  fprintf(fp, "\nEstimating capacity:\n");
  capacityup = estimateCapacity(tcpsock, udpsock, &from);
  CHKRET(capacityup);
  CHKRET(sendCapEst(tcpsock));
  fprintf(fp, "Upstream: %d Kbps.\n", (int)capacityup);
  capacitydown = capacityEstimation(tcpsock, udpsock, &from, fp);
  CHKRET(capacitydown);
  //printf("Downstream: %d Kbps.\n", (int)capacitydown);

  // send to test log
  printf("%s, %d, %.2f, %.2f\n",inet_ntoa(sin_addr), (int)tv.tv_sec, capacityup, capacitydown);
  fprintf(fp, "LOG: %s, %s, %d, %.2f, %.2f\n", filename, inet_ntoa(sin_addr), (int)tv.tv_sec, capacityup, capacitydown);
  // finished logging

  close(udpsock);
  close(tcpsock);

  //printf("\nFor more information, visit: http://www.cc.gatech.edu/~partha/diffprobe\n");
  fprintf(fp, "\nDONE\n");
  fclose(fp);

  unlink(filename);
  return(0);
}
예제 #7
0
int main(int argc, char *argv[])
{
    int tcpsock = 0;
    int udpsock = 0;
    struct sockaddr_in from;
    double capacityup = 0, capacitydown = 0;
    double measupcap = 0, measdowncap = 0;
    unsigned int tbresult = 0, tbmindepth = 0, tbmaxdepth = 0, tbabortflag = 0;
    double tbrate = 0, truecapup = 0, truecapdown = 0;
    double sleepRes = 1;
    char filename[256], tracefile[256];
    int fileid = -1;
    struct in_addr sin_addr;
    struct timeval tv;
    FILE *fp;
    extern double TB_RATE_AVG_INTERVAL;

    TB_RATE_AVG_INTERVAL = 0.3;

    printf("DiffProbe beta release. October 2009.\n");
    printf("Shaper Detection Module.\n\n");

    memset(tracefile, 0, 256);
    CHKRET(prober_config_load(argc, argv, tracefile, &fileid));

    sleepRes = prober_sleep_resolution();

    tcpsock = connect2server(serverip, fileid);
    //tcpsock = selectServer(fileid);
    if(tcpsock <= 0) printf("Server busy. Please try again later.\n");
    CHKRET(tcpsock);

    memset(&from, 0, sizeof(from));
    from.sin_family      = PF_INET;
    //from.sin_port        = htons(SERV_PORT_UDP);
    from.sin_port        = htons(serv_port);
    from.sin_addr.s_addr = serverip;

    gettimeofday(&tv, NULL);
    sin_addr.s_addr = serverip;
    memset(filename, 0, 256);
    sprintf(filename, "%s_%d.txt", inet_ntoa(sin_addr), (int)tv.tv_sec);
    //fp = fopen(filename, "w");
    //fprintf(fp, "sleep time resolution: %.2f ms.\n", sleepRes*1000);

    //udpsock = udpclient(serverip, SERV_PORT_UDP);
    udpsock = udpclient(serverip, serv_port);
    CHKRET(udpsock);
    sin_addr.s_addr = serverip;
    printf("Connected to server %s.\n", inet_ntoa(sin_addr));

    printf("\nEstimating capacity:\n");
    capacityup = estimateCapacity(tcpsock, udpsock, &from);
    CHKRET(capacityup);
    CHKRET(sendCapEst(tcpsock));
    capacitydown = capacityEstimation(tcpsock, udpsock, &from, fp);
    CHKRET(capacitydown);

    mflowSender(tcpsock, udpsock, &from,
                (capacityup > 100000) ? 95000 : capacityup, sleepRes, &measupcap);
    mflowReceiver(tcpsock, udpsock, &measdowncap, fp);
    //XXX: the meas code needs trains and lower cpu
    if(capacityup < 80000) capacityup = measupcap;
    if(capacitydown < 80000) capacitydown = measdowncap;
    if(capacityup > 100000)
    {
        //printf("Upstream: greater than 100 Mbps.\n");
        printf("Upstream: %d Kbps.\n", (int)capacityup);
        capacityup = 95000;
    }
    else
    {
        printf("Upstream: %d Kbps.\n", (int)capacityup);
//	  capacityup *= 0.95; //reduce loss-based aborts
    }
    truecapup = capacityup;
    if(capacitydown > 100000)
    {
        //printf("Downstream: greater than 100 Mbps.\n");
        printf("Downstream: %d Kbps.\n", (int)capacitydown);
        capacitydown = 95000;
    }
    else
    {
        printf("Downstream: %d Kbps.\n", (int)capacitydown);
//	  capacitydown *= 0.95; //reduce loss-based aborts
    }
    truecapdown = capacitydown;

    printf("\nThe measurement will last for about %.1f minutes. Please wait.\n",
           0.5*ceil(2*(
                        (2 * (60)  // probing + low-rate
                         + (40560 + 3.5 * capacitydown * (60) ) * 8 / (1000*capacityup))/60)));  // to upload file

    printf("\nChecking for traffic shapers:\n\n");
    CHKRET(tbdetectSender(tcpsock, udpsock, &from, capacityup, sleepRes,
                          &tbresult, &tbmindepth, &tbmaxdepth, &tbrate, &tbabortflag, fp));
    if(tbresult == 1) truecapup = tbrate;
//  mflowSender(tcpsock, udpsock, &from, (tbresult == 1) ? tbrate : capacityup/2.0, sleepRes);
    printShaperResult(tbresult, tbmindepth, tbmaxdepth, tbrate, tbabortflag, 0, stdout);

    CHKRET(tbdetectReceiver(tcpsock, udpsock, capacitydown, sleepRes,
                            &tbresult, &tbmindepth, &tbmaxdepth, &tbrate, &tbabortflag, fp));
    if(tbresult == 1) truecapdown = tbrate;
//  mflowReceiver(tcpsock, udpsock, fp);
    //fclose(fp);
    //sendData(tcpsock, filename);
    printShaperResult(tbresult, tbmindepth, tbmaxdepth, tbrate, tbabortflag, 1, stdout);

    close(udpsock);
    close(tcpsock);

    printf("\nFor more information, visit: http://www.cc.gatech.edu/~partha/diffprobe\n");

    return(0);
}