Commit d557dbcb authored by Oleg Dzhimiev's avatar Oleg Dzhimiev

formatting

parent ce5a85ee
......@@ -50,96 +50,98 @@ int generate_packet(char * buf, int pnum){
//client
int main(int argc, char **argv) {
struct timeval t0;
int fd;
char buffer[MAXLINE];
int res = 0;
struct sockaddr_in servaddr;
in_addr_t s_addr = INADDR_ANY;
if (argc>1){
if (!inet_aton(argv[1],&s_addr)){
perror("Invalid inet addr in argv[1]");
return -1;
}
struct timeval t0;
int fd;
char buffer[MAXLINE];
int res = 0;
struct sockaddr_in servaddr;
in_addr_t s_addr = INADDR_ANY;
if (argc>1){
if (!inet_aton(argv[1],&s_addr)){
perror("Invalid inet addr in argv[1]");
return -1;
}
}
if ( (fd = socket(AF_INET, SOCK_DGRAM, 0)) < 0 ) {
perror("socket creation failed");
exit(EXIT_FAILURE);
}
if ( (fd = socket(AF_INET, SOCK_DGRAM, 0)) < 0 ) {
perror("socket creation failed");
exit(EXIT_FAILURE);
}
memset(&servaddr, 0, sizeof(servaddr));
memset(&servaddr, 0, sizeof(servaddr));
// Server info
servaddr.sin_family = AF_INET; // IPv4
servaddr.sin_addr.s_addr = s_addr;
servaddr.sin_port = htons(PORT);
// Server info
servaddr.sin_family = AF_INET; // IPv4
servaddr.sin_addr.s_addr = s_addr;
servaddr.sin_port = htons(PORT);
struct sockaddr_in saddr;
memset(&saddr, 0, sizeof(struct sockaddr_in));
saddr.sin_family = AF_INET;
saddr.sin_port = htons(0);
saddr.sin_addr.s_addr = htonl(INADDR_ANY);
struct sockaddr_in saddr;
memset(&saddr, 0, sizeof(struct sockaddr_in));
saddr.sin_family = AF_INET;
saddr.sin_port = htons(0);
saddr.sin_addr.s_addr = htonl(INADDR_ANY);
if (bind(fd, (struct sockaddr *)&saddr, sizeof(struct sockaddr_in))<0){
printf("BIND ERROR!");
}
if (bind(fd, (struct sockaddr *)&saddr, sizeof(struct sockaddr_in))<0){
printf("BIND ERROR!");
}
printf("Sending to %s:%d\n",inet_ntoa(servaddr.sin_addr),PORT);
printf("Sending to %s:%d\n",inet_ntoa(servaddr.sin_addr),PORT);
int frame_cnt = 0;
int pnum = 0;
int frame_cnt = 0;
int pnum = 0;
if (connect(fd,(const struct sockaddr *) &servaddr, sizeof(servaddr))<0){
printf("connect() error: %d",errno);
return -2;
}
if (connect(fd,(const struct sockaddr *) &servaddr, sizeof(servaddr))<0){
printf("connect() error: %d",errno);
return -2;
}
// Send
while(true){
// Send
while(true){
random_string(buffer,MAXLINE);
random_string(buffer,MAXLINE);
for(int i=0;i<NUMBER_OF_PACKETS_IN_FRAME;i++){
for(int i=0;i<NUMBER_OF_PACKETS_IN_FRAME;i++){
gettimeofday(&t0, NULL);
printf("packet: %06d, time: %lu.%06d\n", pnum, t0.tv_sec, t0.tv_usec);
gettimeofday(&t0, NULL);
printf("packet: %06d, time: %lu.%06d\n", pnum, t0.tv_sec, t0.tv_usec);
generate_packet(buffer,pnum);
// tested
//res = sendto(fd, (const char *)buffer, strlen(buffer), 0, (const struct sockaddr *) &servaddr, sizeof(servaddr));
// tested
//res = write(fd,(const char *)buffer,strlen(buffer));
generate_packet(buffer,pnum);
//gettimeofday(&t0, NULL);
//printf("time before2 : %lu.%06d\n", t0.tv_sec,t0.tv_usec);
// tested
//res = sendto(fd, (const char *)buffer, strlen(buffer), 0, (const struct sockaddr *) &servaddr, sizeof(servaddr));
int iovcnt;
struct iovec iov[3];
// tested
//res = write(fd,(const char *)buffer,strlen(buffer));
char *buf1 = "This is a longer string\n";
char *buf2 = "This is the longest string in this example\n";
iov[0].iov_base = buffer;
iov[0].iov_len = strlen(buffer);
iov[1].iov_base = buf1;
iov[1].iov_len = strlen(buf1);
iov[2].iov_base = buf2;
iov[2].iov_len = strlen(buf2);
//gettimeofday(&t0, NULL);
//printf("time before2 : %lu.%06d\n", t0.tv_sec,t0.tv_usec);
iovcnt = 3;
int iovcnt;
struct iovec iov[3];
res = writev(fd,iov,iovcnt);
char *buf1 = "This is a longer string\n";
char *buf2 = "This is the longest string in this example\n";
iov[0].iov_base = buffer;
iov[0].iov_len = strlen(buffer);
iov[1].iov_base = buf1;
iov[1].iov_len = strlen(buf1);
iov[2].iov_base = buf2;
iov[2].iov_len = strlen(buf2);
//gettimeofday(&t0, NULL);
//printf("time after : %lu.%06d\n", t0.tv_sec,t0.tv_usec);
iovcnt = 3;
if (res<0){
printf(" send result= %d, errno= %d\n",res,errno);
}else{
//printf(" sent %d bytes\n",res);
}
res = writev(fd,iov,iovcnt);
//gettimeofday(&t0, NULL);
//printf("time after : %lu.%06d\n", t0.tv_sec,t0.tv_usec);
if (res<0){
printf(" send result= %d, errno= %d\n",res,errno);
}else{
//printf(" sent %d bytes\n",res);
}
pnum++;
}
//printf("%s\n",buffer);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment