1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556 |
- #define _GNU_SOURCE 1 // Needed for getline to avoid implicit function declaration, see `man 3 getline`
- #include <stdlib.h>
- #include <string.h>
- #include <errno.h>
- #include "io.h"
- #include "parse.h"
- void getline_wrapper(struct arguments *args) {
- size_t bufsize = 0;
- char *line = NULL;
- errno = 0;
- int getline_retval = getline(&line, &bufsize, args->ist);
- if(line == NULL || line == 0 || feof(args->ist) || errno != 0 || getline_retval < 0) {
- if(errno != 0) {
- printf("Error %d (%s) getting line for reading.\n", errno, strerror(errno));
- }
- free(line);
- return;
- }
- char start[256]; // Make it big enough for ipv6
- strncpy(start, line, 256);
- char *end = NULL;
- int ret;
- if((ret = split_range(start, &end)) != 0) {
- fprintf(stderr, "Error when attempting to split range %s into start and end parts.\n", line);
- exit(1);
- }
- in_addr_t lower;
- if((lower = inet_network(start)) == -1) {
- fprintf(stderr, "Lower address invalid\n");
- exit(1);
- }
- in_addr_t upper;
- if((upper = inet_network(end)) == -1) {
- fprintf(stderr, "Upper address invalid\n");
- exit(1);
- }
- if(upper < lower) {
- fprintf(stderr, "Incorrect order in range specification? (%s > %s)\n", start, end);
- exit(1);
- }
- deaggregate(lower, upper);
- free(line);
- }
- void no_read(struct arguments *args) {
- printf("Unknown mode. Not reading any lines.\n");
- }
- void sigint_handler(int sig) {
- break_print_loop = true;
- }
|