dropper.c
来自「rtpfiletransfer 使用udp封装rtp的实现文件传输协议」· C语言 代码 · 共 73 行
C
73 行
/* * 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(¤t_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 + =
减小字号Ctrl + -
显示快捷键?