<commit_before>/**
 * @file
 * @brief PF_INET protocol family socket handler.
 *
 * @date 01.12.09
 * @author <NAME>
 * @author <NAME>
 */

#include <errno.h>
#include <embox/net/pack.h>
#include <framework/net/sock/api.h>
#include <stddef.h>
#include <linux/aio.h>
#include <net/protocol.h>
#include <net/in.h>
#include <net/sock.h>
#include <net/socket.h>
#include <net/inet_sock.h>
#include <net/port.h>
#include <net/tcp.h>

EMBOX_NET_PACK(ETH_P_IP, ip_rcv, inet_init);

static struct inet_protosw *inet_proto_find(int type, int protocol) {
	struct inet_protosw *p_netsock = NULL;
	const struct net_sock *net_sock_ptr;

	net_sock_foreach(net_sock_ptr) {
		p_netsock = net_sock_ptr->netsock;
		if (p_netsock->type != type) {
			continue;
		}

		return p_netsock;
//		if (IPPROTO_IP == protocol || p_netsock->protocol == protocol) {
//			return p_netsock;
//		}
	}
	return NULL;
}

/* AF_INET socket create */
static int inet_create(struct socket *sock, int protocol) {
	int err;
	struct sock *sk;
	struct inet_sock *inet;
	struct inet_protosw *p_netsock = NULL;

	if (NULL == (p_netsock = inet_proto_find(sock->type, protocol))) {
		return -EPROTONOSUPPORT;
	}

	sk = sk_alloc(PF_INET, 0, (struct proto *) p_netsock->prot);
	if (sk == NULL) {
		return -ENOMEM;
	}

	sock->sk = sk;
	sock->ops = p_netsock->ops;
	sk->sk_type = sock->type;
	sk->sk_protocol = p_netsock->protocol;

	inet = inet_sk(sk);
	inet->id = 0;
	inet->uc_ttl = -1; /* TODO socket setup more options  */
	inet->mc_ttl = 1;

	if (sk->sk_prot->init != NULL) {
		if(0 != (err = sk->sk_prot->init(sk))) {
			sk_common_release(sk);
			return err;
		}
	}

	return ENOERR;
}

int inet_release(struct socket *sock) {
	struct sock *sk;
	struct inet_sock *inet;

	sock_lock(sock->sk);
	sk = sock->sk;
	inet = inet_sk(sk);<commit_msg>net: socket creation<commit_after>/**
 * @file
 * @brief PF_INET protocol family socket handler.
 *
 * @date 01.12.09
 * @author <NAME>
 * @author <NAME>
 */

#include <errno.h>
#include <embox/net/pack.h>
#include <framework/net/sock/api.h>
#include <stddef.h>
#include <linux/aio.h>
#include <net/protocol.h>
#include <net/in.h>
#include <net/sock.h>
#include <net/socket.h>
#include <net/inet_sock.h>
#include <net/port.h>
#include <net/tcp.h>

EMBOX_NET_PACK(ETH_P_IP, ip_rcv, inet_init);

static struct inet_protosw *inet_proto_find(int type, int protocol) {
	struct inet_protosw *p_netsock = NULL;
	const struct net_sock *net_sock_ptr;

	net_sock_foreach(net_sock_ptr) {
		p_netsock = net_sock_ptr->netsock;
		if (p_netsock->type != type) {
			continue;
		}

		return p_netsock;
//		if (IPPROTO_IP == protocol || p_netsock->protocol == protocol) {
//			return p_netsock;
//		}
	}
	return NULL;
}

/* AF_INET socket create */
static int inet_create(struct socket *sock, int protocol) {
	int err;
	struct sock *sk;
	struct inet_sock *inet;
	struct inet_protosw *p_netsock = NULL;

	if (NULL == (p_netsock = inet_proto_find(sock->type, protocol))) {
		return -EPROTONOSUPPORT;
	}

	sk = sk_alloc(PF_INET, 0, (struct proto *) p_netsock->prot);
	if (sk == NULL) {
		return -ENOMEM;
	}

	sock->sk = sk;
	sock->ops = p_netsock->ops;
	sk->sk_type = sock->type;
	sk->sk_protocol = protocol;

	inet = inet_sk(sk);
	inet->id = 0;
	inet->uc_ttl = -1; /* TODO socket setup more options  */
	inet->mc_ttl = 1;

	if (sk->sk_prot->init != NULL) {
		if(0 != (err = sk->sk_prot->init(sk))) {
			sk_common_release(sk);
			return err;
		}
	}

	return ENOERR;
}

int inet_release(struct socket *sock) {
	struct sock *sk;
	struct inet_sock *inet;

	sock_lock(sock->sk);
	sk = sock->sk;
	inet = inet_sk(sk);
{'fraction_non_alphanumeric': 0.16043526785714285, 'fraction_numerical': 0.006138392857142857, 'mean_word_length': 3.9244505494505493, 'pattern_counts': {'":': 0, '<': 31, '<?xml version=': 0, '>': 72, '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': '6850571', 'n_tokens_mistral': 1570, 'n_tokens_neox': 1482, 'n_words': 323}