Page MenuHomeFreeBSD
Authored By
tuexen
Jan 13 2019, 3:32 PM
Size
1 KB
Referenced Files
None
Subscribers
None

test-raw-1.c

#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <netinet/ip.h>
#include <arpa/inet.h>
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
int main(void)
{
char buffer[4096];
struct sockaddr_in addr;
struct ip *ip;
const int on = 1;
int i, fd;
memset(&addr, 0, sizeof(struct sockaddr_in));
addr.sin_family = AF_INET;
addr.sin_len = sizeof(struct sockaddr_in);
addr.sin_port = htons(0);
addr.sin_addr.s_addr = inet_addr("212.201.121.85");
ip = (struct ip *)buffer;
ip->ip_hl = 60 >> 2;
ip->ip_v = IPVERSION;
ip->ip_tos = IPTOS_THROUGHPUT;
ip->ip_len = htons(4096);
ip->ip_id = 0;
ip->ip_off = 0;
ip->ip_ttl = IPDEFTTL;
ip->ip_p = IPPROTO_SCTP;
ip->ip_sum = 0;
ip->ip_src.s_addr = inet_addr("0.0.0.0");
ip->ip_dst.s_addr = inet_addr("212.201.121.85");
arc4random_buf(buffer + 60, sizeof(buffer) - 60);
if ((fd = socket(AF_INET, SOCK_RAW, IPPROTO_SCTP)) < 0) {
perror("socket");
}
if (connect(fd, (const struct sockaddr *)&addr, sizeof(struct sockaddr_in)) < 0) {
perror("connect");
}
if (setsockopt(fd, IPPROTO_IP, IP_HDRINCL, &on, sizeof(int))) {
perror("setsockopt");
}
for (i = 0; i < 1024 * 1024; i++) {
arc4random_buf(buffer + 20, 40);
if (write(fd, buffer, sizeof(buffer)) != sizeof(buffer)) {
perror("write");
}
}
if (close(fd) < 0) {
perror("close");
}
return (0);
}

File Metadata

Mime Type
text/x-c
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
1712046
Default Alt Text
test-raw-1.c (1 KB)

Event Timeline