1 /* 2 * Copyright 2006-2008, Haiku, Inc. All Rights Reserved. 3 * Distributed under the terms of the MIT License. 4 */ 5 #ifndef NET_PROTOCOL_H 6 #define NET_PROTOCOL_H 7 8 9 #include <net_buffer.h> 10 #include <net_socket.h> 11 12 13 // level flags to pass to control() 14 #define LEVEL_SET_OPTION 0x10000000 15 #define LEVEL_GET_OPTION 0x20000000 16 #define LEVEL_DRIVER_IOCTL 0x0f000000 17 #define LEVEL_MASK 0x0fffffff 18 19 typedef struct net_protocol { 20 struct net_protocol *next; 21 struct net_protocol_module_info *module; 22 net_socket *socket; 23 } net_protocol; 24 25 // net_protocol_module_info::flags field 26 #define NET_PROTOCOL_ATOMIC_MESSAGES 0x01 27 28 struct net_protocol_module_info { 29 module_info info; 30 uint32 flags; 31 32 net_protocol *(*init_protocol)(net_socket *socket); 33 status_t (*uninit_protocol)(net_protocol *self); 34 35 status_t (*open)(net_protocol *self); 36 status_t (*close)(net_protocol *self); 37 status_t (*free)(net_protocol *self); 38 39 status_t (*connect)(net_protocol *self, const struct sockaddr *address); 40 status_t (*accept)(net_protocol *self, struct net_socket **_acceptedSocket); 41 status_t (*control)(net_protocol *self, int level, int option, void *value, 42 size_t *_length); 43 status_t (*getsockopt)(net_protocol *self, int level, int option, 44 void *value, int *_length); 45 status_t (*setsockopt)(net_protocol *self, int level, int option, 46 const void *value, int length); 47 48 status_t (*bind)(net_protocol *self, const struct sockaddr *address); 49 status_t (*unbind)(net_protocol *self, struct sockaddr *address); 50 status_t (*listen)(net_protocol *self, int count); 51 status_t (*shutdown)(net_protocol *self, int direction); 52 53 status_t (*send_data)(net_protocol *self, net_buffer *buffer); 54 status_t (*send_routed_data)(net_protocol *self, 55 struct net_route *route, net_buffer *buffer); 56 ssize_t (*send_avail)(net_protocol *self); 57 58 status_t (*read_data)(net_protocol *self, size_t numBytes, uint32 flags, 59 net_buffer **_buffer); 60 ssize_t (*read_avail)(net_protocol *self); 61 62 struct net_domain *(*get_domain)(net_protocol *self); 63 size_t (*get_mtu)(net_protocol *self, const struct sockaddr *address); 64 65 status_t (*receive_data)(net_buffer *data); 66 status_t (*deliver_data)(net_protocol *protocol, net_buffer *data); 67 68 status_t (*error)(uint32 code, net_buffer *data); 69 status_t (*error_reply)(net_protocol *self, net_buffer *causedError, 70 uint32 code, void *errorData); 71 72 status_t (*attach_ancillary_data)(net_protocol *self, net_buffer *buffer, 73 const cmsghdr *header); 74 ssize_t (*process_ancillary_data)(net_protocol *self, 75 const ancillary_data_header *header, const void *data, 76 void *buffer, size_t bufferSize); 77 }; 78 79 #endif // NET_PROTOCOL_H 80