Last active
August 29, 2015 14:15
-
-
Save geofft/a9c033bbcb8b2a365a1e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <sys/socket.h> | |
#include <sys/types.h> | |
#include <netinet/ip.h> | |
#include <signal.h> | |
#include <stdio.h> | |
#include <stdlib.h> | |
#include <string.h> | |
void | |
handler(int signal) | |
{ | |
const char message[] = "Signal handler!\n"; | |
write(2, message, sizeof(message)); | |
} | |
int | |
main(void) | |
{ | |
struct sigaction action = { | |
.sa_handler = handler, | |
.sa_mask = 0, | |
.sa_flags = 0, | |
}; | |
sigaction(SIGUSR1, &action, NULL); | |
int fd = socket(AF_INET, SOCK_STREAM, 0); | |
union {struct sockaddr sa; struct sockaddr_in sin;} addr = { | |
.sin = { | |
.sin_family = AF_INET, | |
.sin_port = htons(54321), | |
.sin_addr.s_addr = htonl(0x7F000001), | |
} | |
}; | |
char *buffer = malloc(104857600); | |
connect(fd, &addr.sa, sizeof(addr.sa)); | |
printf("Connection established -- please drop packets\n"); | |
getchar(); | |
memset(buffer, 'a', sizeof(buffer)); | |
int ret = write(fd, buffer, 104857600); | |
printf("write returned %d\n", ret); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment