embox

Форк
0
/
af_unix.c 
81 строка · 1.5 Кб
1
/**
2
 * @file
3
 *
4
 * @brief PF_UNIX protocol family socket handler
5
 *
6
 * @date 31.01.2012
7
 * @author Anton Bondarev
8
 */
9
#include <errno.h>
10
#include <sys/socket.h>
11

12
#include <net/sock.h>
13

14
#include "family.h"
15

16
EMBOX_NET_FAMILY(AF_UNIX, unix_create);
17

18
/* Prototypes */
19
static const struct family_ops unix_dgram_ops;
20
static const struct family_ops unix_stream_ops;
21
static const struct family_ops unix_seqpacket_ops;
22
static const struct proto unix_proto;
23

24
struct unix_sock {
25
	/* sk has to be the first member */
26
	struct sock sk;
27
};
28

29
static int supported_sock_type(struct socket *sock) {
30
	switch (sock->type) {
31
	default:
32
		return -ESOCKTNOSUPPORT;
33
	case SOCK_STREAM:
34
		sock->ops = &unix_stream_ops;
35
		break;
36
	case SOCK_RAW:
37
		sock->type = SOCK_DGRAM;
38
	case SOCK_DGRAM:
39
		sock->ops = &unix_dgram_ops;
40
		break;
41
	case SOCK_SEQPACKET:
42
		sock->ops = &unix_seqpacket_ops;
43
		break;
44
	}
45

46
	return ENOERR;
47
}
48

49
static int unix_create(struct socket *sock, int type, int protocol) {
50
	int res;
51
	struct sock *sk;
52

53
	res = supported_sock_type(sock);
54
	if (res < 0) {
55
		return res;
56
	}
57

58
	sk = sk_alloc(/*net,*/PF_UNIX, (struct proto *)&unix_proto);
59
	if (sk == NULL) {
60
		return -ENOMEM;
61
	}
62

63
	return ENOERR;
64
}
65

66
static const struct family_ops unix_dgram_ops = {
67
		.family =	PF_UNIX,
68
};
69

70
static const struct family_ops unix_stream_ops = {
71
		.family =	PF_UNIX,
72
};
73

74
static const struct family_ops unix_seqpacket_ops = {
75
		.family =	PF_UNIX,
76
};
77

78
static const struct proto unix_proto = {
79
		.name = "UNIX",
80
		.obj_size = sizeof(struct unix_sock),
81
};
82

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.