Ok, so this problem has been bugging me for a while. I'm creating a c++ program with the libpcap and libnet libraries. It will scan a given country for open ports by SYN'ing with libnet and checking for replies with libpcap. I have a main.cpp file that includes network.h which includes the source files necessary for generating the IPv4 ranges (regex.cpp) and for scanning them (libnet.cpp). Now, my network.h file contains the definition for struct range which is just two uint32_t's representing the starting address of the range and the end.
network.h:
#ifndef NETWORK_H
#define NETWORK_H
#include <iostream>
#include <string>
#include <vector>
#include <cstdlib>
#include <regex>
#include <fstream>
#include <libnet.h>
#include <pcap.h>
#include "src/regex.cpp"
#include "src/libnet.cpp"
#include "src/libpcap.cpp"
#define COLOR_GREEN "\x1b[32m"
#define COLOR_RED "\x1b[31m"
#define COLOR_RESET "\x1b[0m"
#define SNAP_LEN 1518
typedef struct range {
uint32_t begin;
uint32_t end;
} range;
#endif
And I use struct range as the return type for getRangeByCountry
#include "../network.h"
std::vector<struct range> getRangeByCountry(const char* country){
std::vector<struct range> ranges;
try {
std::ifstream f("csv/geoip.csv");
std::regex re("\"\\d+.\\d+.\\d+.\\d+\",\"\\d+.\\d+.\\d+.\\d+\",\"(\\d+)\",\"(\\d+)\",\"\\w$
while (1){
std::string line;
std::getline(f, line);
std::smatch m;
if(line == ""){break;}
std::regex_match(line, m, re);
if (m[3] == country){
struct range r;
r.begin = std::stoul(std::string(m[1]), NULL, 0);
r.end = std::stoul(std::string(m[2]), NULL, 0);
ranges.push_back(r);
}
}
} catch (...){return ranges;}
return std::move(ranges);
}
But when I compile I get this error:
src/regex.cpp: In function ‘std::vector<range> getRangeByCountry(const
char*)’:
src/regex.cpp:15:17: error: aggregate ‘range r’ has incomplete type and
cannot be defined
struct range r;
Why doesn't the compiler throw an error when I set declare a vector of struct range locally? Or when I set the same as the return type? When I define the struct in the same file as getRangebyCountry() it compiles without error. Is this a problem with my g++ parameters? Here they are just in case: g++ main.cpp -lpcap -lnet --std=c++11