⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 dropper.c

📁 rtpfiletransfer 使用udp封装rtp的实现文件传输协议
💻 C
字号:
/* * dropper.c * CS 3251 packet dropper * Russ Clark */ //#include <sys/types.h>#include <winsock.h>//#include <netinet/in.h>//#include <arpa/inet.h>#include <string.h>#include <stdio.h>//#include <unistd.h>#include <stdlib.h>//#include <sys/time.h>#include "libcommon.h"ENABLE_DEBUG()/* GLOBAL DEFINITIONS * All defaults are set to zero */static int DROPPER_loss_percentage = 0;int set_dropper(int L){   struct timeval current_time;   if ((L <0) || (L>100)) {        /* debug print - see libcommon.h */       print("set_dropper: Invalid value of loss percentage\n");       return -1;   }     DROPPER_loss_percentage = L;   /* debug print - see libcommon.h */     aprint("set_dropper: loss percentage set to %d\n",              DROPPER_loss_percentage);   gettimeofday(&current_time,NULL);   srand(current_time.tv_usec);   return 1;} /* set_dropper *//* dropper version of sendto..accepting the same parameters */ssize_t sendto_dropper(      int s,       const void *msg,       size_t len,      int flags,      const struct sockaddr *to,      int tolen    ) {    int randomvalue;    int nbytes;         randomvalue = rand() % 100;        if (randomvalue < DROPPER_loss_percentage) {          /* packet is lost --- do nothing, but make it look like success */	return(len);    }        /* default: nothing wrong, call sendto as is.. */    nbytes = sendto(s,msg,len,flags,to,tolen);    return(nbytes);} /* sendto_dropper */

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -