<commit_before>#include <arpa/inet.h>
#include <getopt.h>
#include <inttypes.h>
#include <net/if.h>
#include <netdb.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/ioctl.h>
#include <unistd.h>
#include "udplogger.h"
#include "socket.h"


/*
 * Please note that this file cannot link successfully by itself (or even with just socket.o).
 * This library implements a framework for sending beacons and receiving log information from
 * udploggerd logging hosts, but it is not complete in and of itself.  To implement a full client, this
 * library should be linked with another source file that gives an implementation of the function
 * log_packet_hook.
 *
 * Preferrably the log_packet_hook function should be kept simple enough to be inlined.
 *
 * See 'udploggercat.c' for a simple example.
 */


/*
 * Give a strndup prototype to stop compiler warnings.  GNU libraries give it to us,
 * but ISO C90 doesn't allow us to use _GNU_SOURCE before including <string.h>.
 */
char *strndup(const char *, size_t);


/*
 * Structure that is used to store information about the logging hosts that
 * the running instance of this udplogger client is currently sending beacons to.  One host
 * per structure, arranged as a singly-linked list.
 */
struct log_host_t {
	struct sockaddr_in address;
	struct log_host_t *next;
};


/*
 * Structure that contains configuration information for the running instance
 * of this udplogger library.
 */
struct udploggerclientlib_configuration_t {
	uintmax_t beacon_interval;
	struct log_host_t log_host;
} udploggerclientlib_conf;


/*
 * Default configuration values.  Used if not over-ridden by a command-line parameter.
 *
 * DEFAULT_BEACON_INTERVAL               The default interval at which beacons should be dispatched.
 */
#define DEFAULT_BEACON_INTERVAL          30UL


int add_log_host(struct sockaddr_in *);
int arguments_parse(int, char **);
void broadcast_scan();


/**
 * log_packet_hook(<source host>, <log line>)
 *
 * There is no implementation of this function in this file.  This function should be implemented in each
 * udploggerd client program, and should take the arguments sockaddr_in *sender (the source host of the log line)
 * and char *line (the log line data itself).  The hook function should not modify the data in either of those
 * arguments.
 **/
extern void inline log_packet_hook(const struct sockaddr_in *, const char *);


/**
 * main()
 *
 * Initializes the program configuration and state, then starts the beacon thread before
 * finally entering the main loop that reads log entries and dumps them to stdout.
 **/
int main (int argc, char **argv)
{
	fd_set all_set;
	char beacon[BEACON_PACKET_SIZE];
	char buffer[PACKET_MAXIMUM_SIZE];
	struct log_host_t *log_host_ptr;
	int fd;
	fd_set read_set;<commit_msg> * Drop the 'const' requirement for log_packet_hook.  There isn't a strong reason to    keep it and it is more efficient to let the clients munge with the data if they want.<commit_after>#include <arpa/inet.h>
#include <getopt.h>
#include <inttypes.h>
#include <net/if.h>
#include <netdb.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/ioctl.h>
#include <unistd.h>
#include "udplogger.h"
#include "socket.h"


/*
 * Please note that this file cannot link successfully by itself (or even with just socket.o).
 * This library implements a framework for sending beacons and receiving log information from
 * udploggerd logging hosts, but it is not complete in and of itself.  To implement a full client, this
 * library should be linked with another source file that gives an implementation of the function
 * log_packet_hook.
 *
 * Preferrably the log_packet_hook function should be kept simple enough to be inlined.
 *
 * See 'udploggercat.c' for a simple example.
 */


/*
 * Give a strndup prototype to stop compiler warnings.  GNU libraries give it to us,
 * but ISO C90 doesn't allow us to use _GNU_SOURCE before including <string.h>.
 */
char *strndup(const char *, size_t);


/*
 * Structure that is used to store information about the logging hosts that
 * the running instance of this udplogger client is currently sending beacons to.  One host
 * per structure, arranged as a singly-linked list.
 */
struct log_host_t {
	struct sockaddr_in address;
	struct log_host_t *next;
};


/*
 * Structure that contains configuration information for the running instance
 * of this udplogger library.
 */
struct udploggerclientlib_configuration_t {
	uintmax_t beacon_interval;
	struct log_host_t log_host;
} udploggerclientlib_conf;


/*
 * Default configuration values.  Used if not over-ridden by a command-line parameter.
 *
 * DEFAULT_BEACON_INTERVAL               The default interval at which beacons should be dispatched.
 */
#define DEFAULT_BEACON_INTERVAL          30UL


int add_log_host(struct sockaddr_in *);
int arguments_parse(int, char **);
void broadcast_scan();


/**
 * log_packet_hook(<source host>, <log line>)
 *
 * There is no implementation of this function in this file.  This function should be implemented in each
 * udploggerd client program, and should take the arguments sockaddr_in *sender (the source host of the log line)
 * and char *line (the log line data itself).
 **/
extern void inline log_packet_hook(struct sockaddr_in *, char *);


/**
 * main()
 *
 * Initializes the program configuration and state, then starts the beacon thread before
 * finally entering the main loop that reads log entries and dumps them to stdout.
 **/
int main (int argc, char **argv)
{
	fd_set all_set;
	char beacon[BEACON_PACKET_SIZE];
	char buffer[PACKET_MAXIMUM_SIZE];
	struct log_host_t *log_host_ptr;
	int fd;
	fd_set read_set;
{'fraction_non_alphanumeric': 0.07818277865821448, 'fraction_numerical': 0.001408698714562423, 'mean_word_length': 4.206232813932172, 'pattern_counts': {'":': 0, '<': 29, '<?xml version=': 0, '>': 29, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '393613', 'n_tokens_mistral': 1726, 'n_tokens_neox': 1673, 'n_words': 698}