Load nodes from file
This commit is contained in:
parent
5453e62e17
commit
8d0df5f5f8
1 changed files with 31 additions and 0 deletions
31
main.c
31
main.c
|
@ -1,8 +1,20 @@
|
||||||
#include <tox/tox.h>
|
#include <tox/tox.h>
|
||||||
|
|
||||||
|
#include <stdlib.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
|
#define IP_LENGTH_MAX 15
|
||||||
|
|
||||||
|
struct Node {
|
||||||
|
char ip[IP_LENGTH_MAX + 1];
|
||||||
|
int port;
|
||||||
|
char key[(TOX_PUBLIC_KEY_SIZE * 2) + 1];
|
||||||
|
};
|
||||||
|
|
||||||
|
#define NODES_COUNT 26
|
||||||
|
#define NODES_FILE_NAME "nodes"
|
||||||
|
|
||||||
int main()
|
int main()
|
||||||
{
|
{
|
||||||
struct Tox_Options tox_options;
|
struct Tox_Options tox_options;
|
||||||
|
@ -29,5 +41,24 @@ int main()
|
||||||
|
|
||||||
printf("\n");
|
printf("\n");
|
||||||
|
|
||||||
|
struct Node nodes[NODES_COUNT];
|
||||||
|
|
||||||
|
FILE *nodes_file = fopen(NODES_FILE_NAME, "r");
|
||||||
|
|
||||||
|
if (!nodes_file)
|
||||||
|
exit(EXIT_FAILURE);
|
||||||
|
|
||||||
|
for (int node_index = 0; node_index < NODES_COUNT; ++node_index) {
|
||||||
|
struct Node *const node = &nodes[node_index];
|
||||||
|
|
||||||
|
fscanf(nodes_file, "%s %d %s",
|
||||||
|
node->ip,
|
||||||
|
&node->port,
|
||||||
|
node->key
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
fclose(nodes_file);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
Reference in a new issue