embox
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
16EMBOX_NET_FAMILY(AF_UNIX, unix_create);17
18/* Prototypes */
19static const struct family_ops unix_dgram_ops;20static const struct family_ops unix_stream_ops;21static const struct family_ops unix_seqpacket_ops;22static const struct proto unix_proto;23
24struct unix_sock {25/* sk has to be the first member */26struct sock sk;27};28
29static int supported_sock_type(struct socket *sock) {30switch (sock->type) {31default:32return -ESOCKTNOSUPPORT;33case SOCK_STREAM:34sock->ops = &unix_stream_ops;35break;36case SOCK_RAW:37sock->type = SOCK_DGRAM;38case SOCK_DGRAM:39sock->ops = &unix_dgram_ops;40break;41case SOCK_SEQPACKET:42sock->ops = &unix_seqpacket_ops;43break;44}45
46return ENOERR;47}
48
49static int unix_create(struct socket *sock, int type, int protocol) {50int res;51struct sock *sk;52
53res = supported_sock_type(sock);54if (res < 0) {55return res;56}57
58sk = sk_alloc(/*net,*/PF_UNIX, (struct proto *)&unix_proto);59if (sk == NULL) {60return -ENOMEM;61}62
63return ENOERR;64}
65
66static const struct family_ops unix_dgram_ops = {67.family = PF_UNIX,68};69
70static const struct family_ops unix_stream_ops = {71.family = PF_UNIX,72};73
74static const struct family_ops unix_seqpacket_ops = {75.family = PF_UNIX,76};77
78static const struct proto unix_proto = {79.name = "UNIX",80.obj_size = sizeof(struct unix_sock),81};82