?? dropper.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(¤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 */
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -