<commit_before>#include <miknet/miknet.h>

/**
 *  Construct a server object, bound to an address and ready for config.
 *
 *  @s: pointer to the server object
 *  @port: port between 0 - 65535
 *  @ip: IPv4/IPv6
 *
 *  @return: 0 on success; negative error code on failure
 */
int mik_serv_make (mikserv_t *s, uint16_t port, mikip_t ip)
{
	if (!s)
		return ERR_MISSING_PTR;

	struct addrinfo hint, *serv, *p;
	char portstr[MIK_PORT_MAX] = {0};
	int yes = 1;
	int err;

	memset(s, 0, sizeof(mikserv_t));
	memset(&hint, 0, sizeof(hint));
	sprintf(portstr, "%d", port);

	s->ip = ip;

	if (ip == MIK_IPV4)
		hint.ai_family = AF_INET;
	else if (ip == MIK_IPV6)
		hint.ai_family = AF_INET6;
	else
		return ERR_INVALID_IP;

	s->tcp = socket(hint.ai_family, SOCK_STREAM, 0);
	s->udp = socket(hint.ai_family, SOCK_DGRAM, 0);
	if (s->udp < 0)
		return mik_debug(ERR_SOCKET);


	hint.ai_flags = AI_PASSIVE;

	hint.ai_socktype = SOCK_STREAM;
	err = getaddrinfo(NULL, portstr, &hint, &serv);
	if (err)
		return mik_debug(ERR_ADDRESS);

	for (p = serv; p; p = p->ai_next) {
		err = bind(s->tcp, p->ai_addr, p->ai_addrlen);
		if (!err) {
			if (MIK_DEBUG)
				mik_print_addr(p->ai_addr, p->ai_addrlen);
			break;
		}
	}

	freeaddrinfo(serv);

	hint.ai_socktype = SOCK_DGRAM;
	err = getaddrinfo(NULL, portstr, &hint, &serv);
	if (err)
		return mik_debug(ERR_ADDRESS);

	for (p = serv; p; p = p->ai_next) {
		err = bind(s->udp, p->ai_addr, p->ai_addrlen);
		if (!err) {
			if (MIK_DEBUG)
				mik_print_addr(p->ai_addr, p->ai_addrlen);
			break;
		}
	}

	freeaddrinfo(serv);

	if (err < 0)
		return mik_debug(ERR_BIND);

	err = setsockopt(s->tcp, SOL_SOCKET, SO_REUSEADDR, &yes, sizeof(int));
	err = setsockopt(s->udp, SOL_SOCKET, SO_REUSEADDR, &yes, sizeof(int));
	if (err < 0)
		return mik_debug(ERR_SOCK_OPT);

	err = listen(s->tcp, MIK_WAIT_MAX);
	if (err < 0)
		return mik_debug(ERR_LISTEN);<commit_msg>Don't set socket options for the DGRAM port.<commit_after>#include <miknet/miknet.h>

/**
 *  Construct a server object, bound to an address and ready for config.
 *
 *  @s: pointer to the server object
 *  @port: port between 0 - 65535
 *  @ip: IPv4/IPv6
 *
 *  @return: 0 on success; negative error code on failure
 */
int mik_serv_make (mikserv_t *s, uint16_t port, mikip_t ip)
{
	if (!s)
		return ERR_MISSING_PTR;

	struct addrinfo hint, *serv, *p;
	char portstr[MIK_PORT_MAX] = {0};
	int yes = 1;
	int err;

	memset(s, 0, sizeof(mikserv_t));
	memset(&hint, 0, sizeof(hint));
	sprintf(portstr, "%d", port);

	s->ip = ip;

	if (ip == MIK_IPV4)
		hint.ai_family = AF_INET;
	else if (ip == MIK_IPV6)
		hint.ai_family = AF_INET6;
	else
		return ERR_INVALID_IP;

	s->tcp = socket(hint.ai_family, SOCK_STREAM, 0);
	s->udp = socket(hint.ai_family, SOCK_DGRAM, 0);
	if (s->udp < 0)
		return mik_debug(ERR_SOCKET);


	hint.ai_flags = AI_PASSIVE;

	hint.ai_socktype = SOCK_STREAM;
	err = getaddrinfo(NULL, portstr, &hint, &serv);
	if (err)
		return mik_debug(ERR_ADDRESS);

	for (p = serv; p; p = p->ai_next) {
		err = bind(s->tcp, p->ai_addr, p->ai_addrlen);
		if (!err) {
			if (MIK_DEBUG)
				mik_print_addr(p->ai_addr, p->ai_addrlen);
			break;
		}
	}

	freeaddrinfo(serv);

	hint.ai_socktype = SOCK_DGRAM;
	err = getaddrinfo(NULL, portstr, &hint, &serv);
	if (err)
		return mik_debug(ERR_ADDRESS);

	for (p = serv; p; p = p->ai_next) {
		err = bind(s->udp, p->ai_addr, p->ai_addrlen);
		if (!err) {
			if (MIK_DEBUG)
				mik_print_addr(p->ai_addr, p->ai_addrlen);
			break;
		}
	}

	freeaddrinfo(serv);

	if (err < 0)
		return mik_debug(ERR_BIND);

	err = setsockopt(s->tcp, SOL_SOCKET, SO_REUSEADDR, &yes, sizeof(int));
	if (err < 0)
		return mik_debug(ERR_SOCK_OPT);

	err = listen(s->tcp, MIK_WAIT_MAX);
	if (err < 0)
		return mik_debug(ERR_LISTEN);
{'fraction_non_alphanumeric': 0.15468875233769702, 'fraction_numerical': 0.012823938017632914, 'mean_word_length': 3.887728459530026, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 42, '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': '6133094', 'n_tokens_mistral': 1766, 'n_tokens_neox': 1626, 'n_words': 378}