KallistiOS  2.0.0
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups
Data Structures | Macros | Typedefs | Functions
fs_socket.h File Reference

Definitions for a sockets "filesystem". More...

#include <sys/cdefs.h>
#include <arch/types.h>
#include <kos/limits.h>
#include <kos/fs.h>
#include <kos/net.h>
#include <sys/queue.h>
#include <sys/socket.h>
#include <stdint.h>

Go to the source code of this file.

Data Structures

struct  net_socket
 Internal representation of a socket for fs_socket. More...
struct  fs_socket_proto
 Internal sockets protocol handler. More...

Macros

#define FS_SOCKET_PROTO_ENTRY   { NULL, NULL }
 Initializer for the entry field in the fs_socket_proto_t struct.
#define FS_SOCKET_NONBLOCK   0x00000001 /** \brief Non-blocking operations */
#define FS_SOCKET_V6ONLY   0x00000002 /** \brief IPv6 Only */
#define FS_SOCKET_GEN_MAX   0x00008000 /** \brief Maximum generic flag */
#define FS_SOCKET_FAM_MAX   0x00800000 /** \brief Maximum family flag */

Typedefs

typedef struct net_socket net_socket_t
 Internal representation of a socket for fs_socket.
typedef struct fs_socket_proto fs_socket_proto_t
 Internal sockets protocol handler.

Functions

net_socket_tfs_socket_open_sock (fs_socket_proto_t *proto)
 Open a socket without calling the protocol initializer.
int fs_socket_input (netif_t *src, int domain, int protocol, const void *hdr, const uint8 *data, int size)
 Input a packet into some socket family handler.
int fs_socket_proto_add (fs_socket_proto_t *proto)
 Add a new protocol for use with fs_socket.
int fs_socket_proto_remove (fs_socket_proto_t *proto)
 Unregister a protocol from fs_socket.

Detailed Description

Definitions for a sockets "filesystem".

This file provides definitions to support the BSD-sockets-like filesystem in KallistiOS. Technically, this filesystem mounts itself on /sock, but it doesn't export any files there, so that point is largely irrelevant. The filesystem is designed to be extensible, making it possible to add additional socket family handlers at runtime. Currently, the kernel only implements UDP sockets over IPv4 and IPv6, but as mentioned, this can be extended in a fairly straightforward manner. In general, as a user of KallistiOS (someone not interested in adding additional socket family drivers), there's very little in this file that will be of interest.

Author:
Lawrence Sebald

Macro Definition Documentation

#define FS_SOCKET_PROTO_ENTRY   { NULL, NULL }

Initializer for the entry field in the fs_socket_proto_t struct.


Typedef Documentation

Internal sockets protocol handler.

This structure is a protocol handler used within fs_socket. Each protocol that is supported has one of these registered for it within the kernel. Generally, users will not come in contact with this structure (unless you're planning on writing a protocol handler), and it can generally be ignored.

For a complete list of appropriate errno values to return from any functions that are in here, take a look at the Single Unix Specification (aka, the POSIX spec), specifically the page about sys/socket.h (and all the functions that it defines, which is available at http://www.opengroup.org/onlinepubs/9699919799/basedefs/sys_socket.h.html .

typedef struct net_socket net_socket_t

Internal representation of a socket for fs_socket.

This structure is the internal representation of a socket "file" that is used within fs_socket. A normal user will never deal with this structure directly (only protocol handlers and fs_socket itself ever sees this structure directly).


Function Documentation

int fs_socket_input ( netif_t src,
int  domain,
int  protocol,
const void *  hdr,
const uint8 data,
int  size 
)

Input a packet into some socket family handler.

This function is used by the lower-level network protocol handlers to input packets for further processing by upper-level protocols. This will call the input function on the family handler, if one is found.

Parameters:
srcThe network interface the packet came in on
domainThe low-level protocol used (AF_INET or AF_INET6)
protocolThe upper-level protocol that we're looking for
hdrThe low-level protocol header
dataThe upper-level packet, without any lower-level protocol headers, but with the upper-level ones intact
sizeThe size of the packet (the data parameter)
Return values:
-2The protocol is not known
-1Protocol-level error processing packet
0On success
net_socket_t* fs_socket_open_sock ( fs_socket_proto_t proto)

Open a socket without calling the protocol initializer.

This function creates a new socket, but does not call the protocol's socket() function. This is meant to be used for things like accepting an incoming connection, where calling the regular socket initializer could cause issues. You shouldn't really have any need to call this function unless you are implementing a new protocol handler.

Parameters:
protoThe protocol to use for the socket.
Returns:
The newly created socket on success, NULL on failure.
Error Conditions:
EWOULDBLOCK - if the function would block in an IRQ
ENOMEM - out of memory
EMFILE - too many files open
int fs_socket_proto_add ( fs_socket_proto_t proto)

Add a new protocol for use with fs_socket.

This function registers a protocol handler with fs_socket for use when creating and using sockets. This protocol handler must implement all of the functions in the fs_socket_proto_t structure. See the code in kos/kernel/net/net_udp.c for an example of how to do this.

This function is NOT safe to call inside an interrupt.

Parameters:
protoThe new protocol handler to register
Return values:
0On success (no error conditions are currently defined)
int fs_socket_proto_remove ( fs_socket_proto_t proto)

Unregister a protocol from fs_socket.

This function does the exact opposite of fs_socket_proto_add, and removes a protocol from use with fs_socket. It is the programmer's responsibility to make sure that no sockets are still around that are registered with the protocol to be removed (as they will not work properly once the handler has been removed).

Parameters:
protoThe protocol handler to remove
Return values:
-1On error (This function does not directly change errno)
0On success