-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathget_tls_sites.c
More file actions
50 lines (46 loc) · 1.37 KB
/
Copy pathget_tls_sites.c
File metadata and controls
50 lines (46 loc) · 1.37 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#include "get_tls_sites.h"
#include<stdio.h>
#include<netinet/in.h>
#include<stdlib.h>
#include <arpa/inet.h>
#include <string.h>
#define NUM_TLS_SITES 47713654
#define IP_ADDR_LEN 18 //account for \n
#define HTTPS_PORT 443
struct sockaddr_in* get_tls_sites(int num_sites) { //if -1, return all sites
if (num_sites == -1)
num_sites = NUM_TLS_SITES;
//init array of struct sockaddr_in
struct sockaddr_in* arr = calloc(num_sites, sizeof(struct sockaddr_in));
if (!arr) {
printf("could not allocate array for sockaddr sites\n");
return NULL;
}
//process ip addrs
char ip_buf[IP_ADDR_LEN];
FILE *fp = fopen("full_443_scan.csv", "r");
if (!fp) {
printf("could not open csv file\n");
return NULL;
}
char* fgets_ret = NULL;
for (int i = 0; i < num_sites; i++) {
fgets_ret = fgets(ip_buf, IP_ADDR_LEN, fp);
if (!fgets_ret) {
printf("reading csv finished early");
fclose(fp);
return arr;
}
size_t curr_ip_len = strlen(ip_buf);
if (ip_buf[curr_ip_len-1] == '\n')
ip_buf[curr_ip_len-1] = '\0';
printf("curr ip addr: %s\n", ip_buf);
struct sockaddr_in* curr_in = (struct sockaddr_in*)((char*) arr +
(sizeof(struct sockaddr_in)) * i);
curr_in->sin_family = AF_INET;
curr_in->sin_addr.s_addr = inet_addr(ip_buf);
curr_in->sin_port = htons(HTTPS_PORT);
}
fclose(fp);
return arr;
}