/*
* Copyright (c) 2009 Lukas Mejdrech
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* - Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* - Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* - The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/** @addtogroup socket
* @{
*/
/** @file
* Socket application program interface (API).
* This is a part of the network application library.
* Based on the linux src/include/linux/socket.h header file and BSD socket interface.
*/
#ifndef __NET_SOCKET_H__
#define __NET_SOCKET_H__
#include <sys/types.h>
#include "byteorder.h"
#include "in.h"
#include "inet.h"
/* Supported address families. */
/** Unspecified address family.
*/
#define AF_UNSPEC 0
/** Unix domain sockets address family.
*/
#define AF_UNIXL 1
/** POSIX name for AF_UNIX address family.
*/
#define AF_LOCAL 1
/** Internet IP Protocol address family.
*/
#define AF_INET 2
/** Amateur Radio AX.25 address family.
*/
#define AF_AX25 3
/** Novell IPX address family.
*/
#define AF_IPX 4
/** AppleTalk DDP address family.
*/
#define AF_APPLETALK 5
/** Amateur Radio NET/ROM address family.
*/
#define AF_NETROM 6
/** Multiprotocol bridge address family.
*/
#define AF_BRIDGE 7
/** ATM PVCs address family.
*/
#define AF_ATMPVC 8
/** Reserved for X.25 project address family.
*/
#define AF_X25 9
/** IP version 6 address family.
*/
#define AF_INET6 10
/** Amateur Radio X.25 PLP address family.
*/
#define AF_ROSE 11
/** Reserved for DECnet project address family.
*/
#define AF_DECnet 12
/** Reserved for 802.2LLC project address family.
*/
#define AF_NETBEUI 13
/** Security callback pseudo AF address family.
*/
#define AF_SECURITY 14
/** PF_KEY key management API address family.
*/
#define AF_KEY 15
/** Alias to emulate 4.4BSD address family.
*/
#define AF_NETLINK 16
/** Packet family address family.
*/
#define AF_PACKET 17
/** Ash address family.
*/
#define AF_ASH 18
/** Acorn Econet address family.
*/
#define AF_ECONET 19
/** ATM SVCs address family.
*/
#define AF_ATMSVC 20
/** Linux SNA Project (nutters!) address family.
*/
#define AF_SNA 22
/** IRDA sockets address family.
*/
#define AF_IRDA 23
/** PPPoX sockets address family.
*/
#define AF_PPPOX 24
/** Wanpipe API Sockets address family.
*/
#define AF_WANPIPE 25
/** Linux LLC address family.
*/
#define AF_LLC 26
/** Controller Area Network address family.
*/
#define AF_CAN 29
/** TIPC sockets address family.
*/
#define AF_TIPC 30
/** Bluetooth sockets address family.
*/
#define AF_BLUETOOTH 31
/** IUCV sockets address family.
*/
#define AF_IUCV 32
/** RxRPC sockets address family.
*/
#define AF_RXRPC 33
/** Maximum address family.
*/
#define AF_MAX 34
/* Protocol families, same as address families. */
#define PF_UNSPEC AF_UNSPEC
#define PF_UNIX AF_UNIX
#define PF_LOCAL AF_LOCAL
#define PF_INET AF_INET
#define PF_AX25 AF_AX25
#define PF_IPX AF_IPX
#define PF_APPLETALK AF_APPLETALK
#define PF_NETROM AF_NETROM
#define PF_BRIDGE AF_BRIDGE
#define PF_ATMPVC AF_ATMPVC
#define PF_X25 AF_X25
#define PF_INET6 AF_INET6
#define PF_ROSE AF_ROSE
#define PF_DECnet AF_DECnet
#define PF_NETBEUI AF_NETBEUI
#define PF_SECURITY AF_SECURITY
#define PF_KEY AF_KEY
#define PF_NETLINK AF_NETLINK
#define PF_ROUTE AF_ROUTE
#define PF_PACKET AF_PACKET
#define PF_ASH AF_ASH
#define PF_ECONET AF_ECONET
#define PF_ATMSVC AF_ATMSVC
#define PF_SNA AF_SNA
#define PF_IRDA AF_IRDA
#define PF_PPPOX AF_PPPOX
#define PF_WANPIPE AF_WANPIPE
#define PF_LLC AF_LLC
#define PF_CAN AF_CAN
#define PF_TIPC AF_TIPC
#define PF_BLUETOOTH AF_BLUETOOTH
#define PF_IUCV AF_IUCV
#define PF_RXRPC AF_RXRPC
#define PF_MAX AF_MAX
/* Setsockoptions(2) level. Thanks to BSD these must match IPPROTO_xxx */
#define SOL_IP 0
#define SOL_ICMP 1
#define SOL_TCP 6
#define SOL_UDP 17
#define SOL_IPV6 41
#define SOL_ICMPV6 58
#define SOL_SCTP 132
#define SOL_UDPLITE 136 /* UDP-Lite (RFC 3828) */
#define SOL_RAW 255
#define SOL_IPX 256
#define SOL_AX25 257
#define SOL_ATALK 258
#define SOL_NETROM 259
#define SOL_ROSE 260
#define SOL_DECNET 261
#define SOL_X25 262
#define SOL_PACKET 263
#define SOL_ATM 264 /* ATM layer (cell level) */
#define SOL_AAL 265 /* ATM Adaption Layer (packet level) */
#define SOL_IRDA 266
#define SOL_NETBEUI 267
#define SOL_LLC 268
#define SOL_DCCP 269
#define SOL_NETLINK 270
#define SOL_TIPC 271
#define SOL_RXRPC 272
#define SOL_PPPOL2TP 273
#define SOL_BLUETOOTH 274
//
/* * IPX options.
*/
//#define IPX_TYPE 1
/** Socket type type definition.
*/
typedef enum sock_type{
/** Stream (connection oriented) socket.
*/
SOCK_STREAM = 1,
/** Datagram (connectionless oriented) socket.
*/
SOCK_DGRAM = 2,
/** Raw socket.
*/
SOCK_RAW = 3
} sock_type_t;
typedef int32_t socklen_t;
int socket( int domain, int type, int protocol );
int bind( int socket_id, const struct sockaddr * my_addr, socklen_t addrlen );
int listen( int socket_id, int backlog );
int accept( int socket_id, struct sockaddr * cliaddr, socklen_t * addrlen );
int connect( int socket_id, const struct sockaddr * serv_addr, socklen_t addrlen );
int closesocket( int socket_id );
int send( int socket_id, void * data, size_t datalength, int flags );
int sendto( int socket_id, const void * data, size_t datalength, int flags, const struct sockaddr * toaddr, socklen_t addrlen );
int recv( int socket_id, void * data, size_t datalength, int flags );
int recvfrom( int socket_id, void * data, size_t datalength, int flags, struct sockaddr * fromaddr, socklen_t * addrlen );
int getsockopt( int socket_id, int level, int optname, void * value, size_t * optlen );
int setsockopt( int socket_id, int level, int optname, const void * value, size_t optlen );
#endif
/** @}
*/