tsocket: for unix domain sockets we need to use sizeof(struct sockaddr_un)
[ira/wip.git] / lib / tsocket / tsocket.h
1 /*
2    Unix SMB/CIFS implementation.
3
4    Copyright (C) Stefan Metzmacher 2009
5
6      ** NOTE! The following LGPL license applies to the tevent
7      ** library. This does NOT imply that all of Samba is released
8      ** under the LGPL
9
10    This library is free software; you can redistribute it and/or
11    modify it under the terms of the GNU Lesser General Public
12    License as published by the Free Software Foundation; either
13    version 3 of the License, or (at your option) any later version.
14
15    This library is distributed in the hope that it will be useful,
16    but WITHOUT ANY WARRANTY; without even the implied warranty of
17    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
18    Lesser General Public License for more details.
19
20    You should have received a copy of the GNU Lesser General Public
21    License along with this library; if not, see <http://www.gnu.org/licenses/>.
22 */
23
24 #ifndef _TSOCKET_H
25 #define _TSOCKET_H
26
27 #include <talloc.h>
28 #include <tevent.h>
29
30 struct tsocket_address;
31 struct tdgram_context;
32 struct iovec;
33
34 /*
35  * tsocket_address related functions
36  */
37 char *tsocket_address_string(const struct tsocket_address *addr,
38                              TALLOC_CTX *mem_ctx);
39
40 struct tsocket_address *_tsocket_address_copy(const struct tsocket_address *addr,
41                                               TALLOC_CTX *mem_ctx,
42                                               const char *location);
43
44 #define tsocket_address_copy(addr, mem_ctx) \
45         _tsocket_address_copy(addr, mem_ctx, __location__)
46
47 /*
48  * tdgram_context related functions
49  */
50 struct tevent_req *tdgram_recvfrom_send(TALLOC_CTX *mem_ctx,
51                                         struct tevent_context *ev,
52                                         struct tdgram_context *dgram);
53 ssize_t tdgram_recvfrom_recv(struct tevent_req *req,
54                              int *perrno,
55                              TALLOC_CTX *mem_ctx,
56                              uint8_t **buf,
57                              struct tsocket_address **src);
58
59 struct tevent_req *tdgram_sendto_send(TALLOC_CTX *mem_ctx,
60                                       struct tevent_context *ev,
61                                       struct tdgram_context *dgram,
62                                       const uint8_t *buf, size_t len,
63                                       const struct tsocket_address *dst);
64 ssize_t tdgram_sendto_recv(struct tevent_req *req,
65                            int *perrno);
66
67 struct tevent_req *tdgram_disconnect_send(TALLOC_CTX *mem_ctx,
68                                           struct tevent_context *ev,
69                                           struct tdgram_context *dgram);
70 int tdgram_disconnect_recv(struct tevent_req *req,
71                            int *perrno);
72
73 /*
74  * BSD sockets: inet, inet6 and unix
75  */
76
77 int _tsocket_address_inet_from_strings(TALLOC_CTX *mem_ctx,
78                                        const char *fam,
79                                        const char *addr,
80                                        uint16_t port,
81                                        struct tsocket_address **_addr,
82                                        const char *location);
83 #define tsocket_address_inet_from_strings(mem_ctx, fam, addr, port, _addr) \
84         _tsocket_address_inet_from_strings(mem_ctx, fam, addr, port, _addr, \
85                                            __location__)
86
87 char *tsocket_address_inet_addr_string(const struct tsocket_address *addr,
88                                        TALLOC_CTX *mem_ctx);
89 uint16_t tsocket_address_inet_port(const struct tsocket_address *addr);
90 int tsocket_address_inet_set_port(struct tsocket_address *addr,
91                                   uint16_t port);
92 void tsocket_address_inet_set_broadcast(struct tsocket_address *addr,
93                                         bool broadcast);
94
95 int _tsocket_address_unix_from_path(TALLOC_CTX *mem_ctx,
96                                     const char *path,
97                                     struct tsocket_address **_addr,
98                                     const char *location);
99 #define tsocket_address_unix_from_path(mem_ctx, path, _addr) \
100         _tsocket_address_unix_from_path(mem_ctx, path, _addr, \
101                                         __location__)
102 char *tsocket_address_unix_path(const struct tsocket_address *addr,
103                                 TALLOC_CTX *mem_ctx);
104
105 int _tdgram_inet_udp_socket(const struct tsocket_address *local,
106                             const struct tsocket_address *remote,
107                             TALLOC_CTX *mem_ctx,
108                             struct tdgram_context **dgram,
109                             const char *location);
110 #define tdgram_inet_udp_socket(local, remote, mem_ctx, dgram) \
111         _tdgram_inet_udp_socket(local, remote, mem_ctx, dgram, __location__)
112
113 int _tdgram_unix_dgram_socket(const struct tsocket_address *local,
114                               const struct tsocket_address *remote,
115                               TALLOC_CTX *mem_ctx,
116                               struct tdgram_context **dgram,
117                               const char *location);
118 #define tdgram_unix_dgram_socket(local, remote, mem_ctx, dgram) \
119         _tdgram_unix_dgram_socket(local, remote, mem_ctx, dgram, __location__)
120
121 /*
122  * Queue helpers
123  */
124
125 struct tevent_req *tdgram_sendto_queue_send(TALLOC_CTX *mem_ctx,
126                                             struct tevent_context *ev,
127                                             struct tdgram_context *dgram,
128                                             struct tevent_queue *queue,
129                                             const uint8_t *buf,
130                                             size_t len,
131                                             struct tsocket_address *dst);
132 ssize_t tdgram_sendto_queue_recv(struct tevent_req *req, int *perrno);
133
134 #endif /* _TSOCKET_H */
135