2006-08-08 17:07:07 +04:00
|
|
|
/*
|
2008-02-07 18:09:19 +03:00
|
|
|
* Copyright 2006-2008, Haiku, Inc. All Rights Reserved.
|
2006-08-08 17:07:07 +04:00
|
|
|
* Distributed under the terms of the MIT License.
|
|
|
|
*/
|
|
|
|
#ifndef NET_PROTOCOL_H
|
|
|
|
#define NET_PROTOCOL_H
|
|
|
|
|
|
|
|
|
|
|
|
#include <net_buffer.h>
|
|
|
|
#include <net_socket.h>
|
|
|
|
|
|
|
|
|
|
|
|
// level flags to pass to control()
|
2006-12-19 05:06:07 +03:00
|
|
|
#define LEVEL_SET_OPTION 0x10000000
|
|
|
|
#define LEVEL_GET_OPTION 0x20000000
|
|
|
|
#define LEVEL_DRIVER_IOCTL 0x0f000000
|
|
|
|
#define LEVEL_MASK 0x0fffffff
|
2006-08-08 17:07:07 +04:00
|
|
|
|
|
|
|
typedef struct net_protocol {
|
|
|
|
struct net_protocol *next;
|
|
|
|
struct net_protocol_module_info *module;
|
|
|
|
net_socket *socket;
|
|
|
|
} net_protocol;
|
|
|
|
|
2008-02-07 18:09:19 +03:00
|
|
|
// net_protocol_module_info::flags field
|
|
|
|
#define NET_PROTOCOL_ATOMIC_MESSAGES 0x01
|
|
|
|
|
2006-08-08 17:07:07 +04:00
|
|
|
struct net_protocol_module_info {
|
|
|
|
module_info info;
|
2008-02-07 18:09:19 +03:00
|
|
|
uint32 flags;
|
2006-08-08 17:07:07 +04:00
|
|
|
|
|
|
|
net_protocol *(*init_protocol)(net_socket *socket);
|
|
|
|
status_t (*uninit_protocol)(net_protocol *self);
|
|
|
|
|
|
|
|
status_t (*open)(net_protocol *self);
|
|
|
|
status_t (*close)(net_protocol *self);
|
|
|
|
status_t (*free)(net_protocol *self);
|
|
|
|
|
|
|
|
status_t (*connect)(net_protocol *self, const struct sockaddr *address);
|
|
|
|
status_t (*accept)(net_protocol *self, struct net_socket **_acceptedSocket);
|
|
|
|
status_t (*control)(net_protocol *self, int level, int option, void *value,
|
|
|
|
size_t *_length);
|
2007-04-20 05:58:14 +04:00
|
|
|
status_t (*getsockopt)(net_protocol *self, int level, int option,
|
|
|
|
void *value, int *_length);
|
|
|
|
status_t (*setsockopt)(net_protocol *self, int level, int option,
|
|
|
|
const void *value, int length);
|
2006-08-08 17:07:07 +04:00
|
|
|
|
2007-04-25 20:14:14 +04:00
|
|
|
status_t (*bind)(net_protocol *self, const struct sockaddr *address);
|
2006-08-08 17:07:07 +04:00
|
|
|
status_t (*unbind)(net_protocol *self, struct sockaddr *address);
|
|
|
|
status_t (*listen)(net_protocol *self, int count);
|
|
|
|
status_t (*shutdown)(net_protocol *self, int direction);
|
|
|
|
|
|
|
|
status_t (*send_data)(net_protocol *self, net_buffer *buffer);
|
|
|
|
status_t (*send_routed_data)(net_protocol *self,
|
|
|
|
struct net_route *route, net_buffer *buffer);
|
|
|
|
ssize_t (*send_avail)(net_protocol *self);
|
|
|
|
|
|
|
|
status_t (*read_data)(net_protocol *self, size_t numBytes, uint32 flags,
|
|
|
|
net_buffer **_buffer);
|
|
|
|
ssize_t (*read_avail)(net_protocol *self);
|
|
|
|
|
|
|
|
struct net_domain *(*get_domain)(net_protocol *self);
|
|
|
|
size_t (*get_mtu)(net_protocol *self, const struct sockaddr *address);
|
|
|
|
|
|
|
|
status_t (*receive_data)(net_buffer *data);
|
2007-04-15 11:31:04 +04:00
|
|
|
status_t (*deliver_data)(net_protocol *protocol, net_buffer *data);
|
2006-08-08 17:07:07 +04:00
|
|
|
|
2007-04-15 11:31:04 +04:00
|
|
|
status_t (*error)(uint32 code, net_buffer *data);
|
2006-08-08 17:07:07 +04:00
|
|
|
status_t (*error_reply)(net_protocol *self, net_buffer *causedError,
|
|
|
|
uint32 code, void *errorData);
|
|
|
|
};
|
|
|
|
|
|
|
|
#endif // NET_PROTOCOL_H
|