📄 testsend.c
字号:
#include <stdio.h>#include <stdlib.h>#include <unistd.h>#include <time.h>#include <sys/socket.h>#include <netinet/in.h>#include <netinet/in.h>#include <arpa/inet.h>#include <string.h>#include "../pmtp.h"int main () { int s, dummy = 1; struct sockaddr_in s_in; unsigned char packet[1500] = "Hallo!"; int count = 0; int l, r; int packets, bytes; struct packet_buffer buffer; srandom(time(NULL)); if ((s = socket (AF_INET, SOCK_DGRAM, 0)) < 0) { perror ("socket"); exit (1); } if (setsockopt (s, SOL_IP, IP_MULTICAST_LOOP, &dummy, sizeof(dummy))) { perror ("setsockopt"); exit (1); } s_in.sin_family = AF_INET; inet_aton ("232.5.5.5", &(s_in.sin_addr)); s_in.sin_port = htons(PMTP_PORT); init_packet_buffer (&buffer); while (count < 1400) { r = random() % 500; printf ("Buffering %u packets\n", r); for (l = 0; l < r && count < 1400; l++) { count++; memset (packet, count & 0XFF, count); while (buffer_packet (&buffer, packet, count) == -1) { send_buffer (s, &s_in, &buffer, 16384, &packets, &bytes); printf ("Sent %u packets with in total %u bytes\n", packets, bytes); sleep (1); } } } while (send_buffer (s, &s_in, &buffer, 16384, &packets, &bytes) != 0) { printf ("Sent %u packets with in total %u bytes\n", packets, bytes); sleep (1); } free_packet_buffer (&buffer); return 1;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -