Wed Jan 8 2020 09:49:48

Asterisk developer's documentation


netsock2.h
Go to the documentation of this file.
1 /*
2  * Asterisk -- An open source telephony toolkit.
3  *
4  * Copyright (C) 2010, Digium, Inc.
5  *
6  * ViagĂ©nie <asteriskv6@viagenie.ca>
7  *
8  * See http://www.asterisk.org for more information about
9  * the Asterisk project. Please do not directly contact
10  * any of the maintainers of this project for assistance;
11  * the project provides a web site, mailing lists and IRC
12  * channels for your use.
13  *
14  * This program is free software, distributed under the terms of
15  * the GNU General Public License Version 2. See the LICENSE file
16  * at the top of the source tree.
17  */
18 
19 /*! \file
20  * \brief Network socket handling
21  */
22 
23 #ifndef _ASTERISK_NETSOCK2_H
24 #define _ASTERISK_NETSOCK2_H
25 
26 #if defined(__cplusplus) || defined(c_plusplus)
27 extern "C" {
28 #endif
29 
30 #include <sys/socket.h>
31 
32 #include <netinet/in.h>
33 
34 /*!
35  * Values for address families that we support. This is reproduced from socket.h
36  * because we do not want users to include that file. Only netsock2.c should
37  * ever include socket.h.
38  */
39 enum {
43 };
44 
45 /*!
46  * \brief Socket address structure.
47  *
48  * \details
49  * The first member is big enough to contain addresses of any
50  * family. The second member contains the length (in bytes) used
51  * in the first member.
52  *
53  * \note
54  * Some BSDs have the length embedded in sockaddr structs. We
55  * ignore them. (This is the right thing to do.)
56  *
57  * \note
58  * It is important to always initialize ast_sockaddr before use
59  * -- even if they are passed to ast_sockaddr_copy() as the
60  * underlying storage could be bigger than what ends up being
61  * copied -- leaving part of the data unitialized.
62  */
63 struct ast_sockaddr {
64  struct sockaddr_storage ss;
65  socklen_t len;
66 };
67 
68 /*!
69  * \brief
70  * Convert an IPv4-mapped IPv6 address into an IPv4 address.
71  *
72  * \warning You should rarely need this function. Only call this
73  * if you know what you're doing.
74  *
75  * \param addr The IPv4-mapped address to convert
76  * \param mapped_addr The resulting IPv4 address
77  * \retval 0 Unable to make the conversion
78  * \retval 1 Successful conversion
79  */
80 int ast_sockaddr_ipv4_mapped(const struct ast_sockaddr *addr, struct ast_sockaddr *ast_mapped);
81 
82 /*!
83  * \since 1.8
84  *
85  * \brief
86  * Checks if the ast_sockaddr is null. "null" in this sense essentially
87  * means uninitialized, or having a 0 length.
88  *
89  * \param addr Pointer to the ast_sockaddr we wish to check
90  * \retval 1 \a addr is null
91  * \retval 0 \a addr is non-null.
92  */
93 static inline int ast_sockaddr_isnull(const struct ast_sockaddr *addr)
94 {
95  return !addr || addr->len == 0;
96 }
97 
98 /*!
99  * \since 1.8
100  *
101  * \brief
102  * Sets address \a addr to null.
103  *
104  * \retval void
105  */
106 static inline void ast_sockaddr_setnull(struct ast_sockaddr *addr)
107 {
108  addr->len = 0;
109 }
110 
111 /*!
112  * \since 1.8
113  *
114  * \brief
115  * Copies the data from one ast_sockaddr to another
116  *
117  * \param dst The destination ast_sockaddr
118  * \param src The source ast_sockaddr
119  * \retval void
120  */
121 static inline void ast_sockaddr_copy(struct ast_sockaddr *dst,
122  const struct ast_sockaddr *src)
123 {
124  memcpy(dst, src, src->len);
125  dst->len = src->len;
126 };
127 
128 /*!
129  * \since 1.8
130  *
131  * \brief
132  * Compares two ast_sockaddr structures
133  *
134  * \retval -1 \a a is lexicographically smaller than \a b
135  * \retval 0 \a a is equal to \a b
136  * \retval 1 \a b is lexicographically smaller than \a a
137  */
138 int ast_sockaddr_cmp(const struct ast_sockaddr *a, const struct ast_sockaddr *b);
139 
140 /*!
141  * \since 1.8
142  *
143  * \brief
144  * Compares the addresses of two ast_sockaddr structures.
145  *
146  * \retval -1 \a a is lexicographically smaller than \a b
147  * \retval 0 \a a is equal to \a b
148  * \retval 1 \a b is lexicographically smaller than \a a
149  */
150 int ast_sockaddr_cmp_addr(const struct ast_sockaddr *a, const struct ast_sockaddr *b);
151 
152 #define AST_SOCKADDR_STR_ADDR (1 << 0)
153 #define AST_SOCKADDR_STR_PORT (1 << 1)
154 #define AST_SOCKADDR_STR_BRACKETS (1 << 2)
155 #define AST_SOCKADDR_STR_REMOTE (1 << 3)
156 #define AST_SOCKADDR_STR_HOST (AST_SOCKADDR_STR_ADDR | AST_SOCKADDR_STR_BRACKETS)
157 #define AST_SOCKADDR_STR_DEFAULT (AST_SOCKADDR_STR_ADDR | AST_SOCKADDR_STR_PORT)
158 #define AST_SOCKADDR_STR_ADDR_REMOTE (AST_SOCKADDR_STR_ADDR | AST_SOCKADDR_STR_REMOTE)
159 #define AST_SOCKADDR_STR_HOST_REMOTE (AST_SOCKADDR_STR_HOST | AST_SOCKADDR_STR_REMOTE)
160 #define AST_SOCKADDR_STR_DEFAULT_REMOTE (AST_SOCKADDR_STR_DEFAULT | AST_SOCKADDR_STR_REMOTE)
161 #define AST_SOCKADDR_STR_FORMAT_MASK (AST_SOCKADDR_STR_ADDR | AST_SOCKADDR_STR_PORT | AST_SOCKADDR_STR_BRACKETS)
162 
163 /*!
164  * \since 1.8
165  *
166  * \brief
167  * Convert a socket address to a string.
168  *
169  * \details
170  * This will be of the form a.b.c.d:xyz
171  * for IPv4 and [a:b:c:...:d]:xyz for IPv6.
172  *
173  * This function is thread-safe. The returned string is on static
174  * thread-specific storage.
175  *
176  * \param addr The input to be stringified
177  * \param format one of the following:
178  * AST_SOCKADDR_STR_DEFAULT:
179  * a.b.c.d:xyz for IPv4
180  * [a:b:c:...:d]:xyz for IPv6.
181  * AST_SOCKADDR_STR_ADDR: address only
182  * a.b.c.d for IPv4
183  * a:b:c:...:d for IPv6.
184  * AST_SOCKADDR_STR_HOST: address only, suitable for a URL
185  * a.b.c.d for IPv4
186  * [a:b:c:...:d] for IPv6.
187  * AST_SOCKADDR_STR_PORT: port only
188  *
189  * \note The string pointer returned by this function will point to a string that
190  * will be changed whenever any form of ast_sockaddr_stringify_fmt is called on that
191  * thread. Because of this, it is important that if you use this function, you use the
192  * string before another use of this function is made elsewhere in the same thread.
193  * The easiest way to accomplish this is by immediately copying the string to a buffer
194  * with something like ast_strdupa.
195  *
196  * \retval "(null)" \a addr is null
197  * \retval "" An error occurred during processing
198  * \retval string The stringified form of the address
199  */
200 char *ast_sockaddr_stringify_fmt(const struct ast_sockaddr *addr, int format);
201 
202 /*!
203  * \since 1.8
204  *
205  * \brief
206  * Wrapper around ast_sockaddr_stringify_fmt() with default format
207  *
208  * \return same as ast_sockaddr_stringify_fmt()
209  */
210 static inline char *ast_sockaddr_stringify(const struct ast_sockaddr *addr)
211 {
213 }
214 
215 /*!
216  * \since 1.8
217  *
218  * \brief
219  * Wrapper around ast_sockaddr_stringify_fmt() with default format
220  *
221  * \note This address will be suitable for passing to a remote machine via the
222  * application layer. For example, the scope-id on a link-local IPv6 address
223  * will be stripped.
224  *
225  * \return same as ast_sockaddr_stringify_fmt()
226  */
227 static inline char *ast_sockaddr_stringify_remote(const struct ast_sockaddr *addr)
228 {
230 }
231 
232 /*!
233  * \since 1.8
234  *
235  * \brief
236  * Wrapper around ast_sockaddr_stringify_fmt() to return an address only
237  *
238  * \return same as ast_sockaddr_stringify_fmt()
239  */
240 static inline char *ast_sockaddr_stringify_addr(const struct ast_sockaddr *addr)
241 {
243 }
244 
245 /*!
246  * \since 1.8
247  *
248  * \brief
249  * Wrapper around ast_sockaddr_stringify_fmt() to return an address only
250  *
251  * \note This address will be suitable for passing to a remote machine via the
252  * application layer. For example, the scope-id on a link-local IPv6 address
253  * will be stripped.
254  *
255  * \return same as ast_sockaddr_stringify_fmt()
256  */
257 static inline char *ast_sockaddr_stringify_addr_remote(const struct ast_sockaddr *addr)
258 {
260 }
261 
262 /*!
263  * \since 1.8
264  *
265  * \brief
266  * Wrapper around ast_sockaddr_stringify_fmt() to return an address only,
267  * suitable for a URL (with brackets for IPv6).
268  *
269  * \return same as ast_sockaddr_stringify_fmt()
270  */
271 static inline char *ast_sockaddr_stringify_host(const struct ast_sockaddr *addr)
272 {
274 }
275 
276 /*!
277  * \since 1.8
278  *
279  * \brief
280  * Wrapper around ast_sockaddr_stringify_fmt() to return an address only,
281  * suitable for a URL (with brackets for IPv6).
282  *
283  * \note This address will be suitable for passing to a remote machine via the
284  * application layer. For example, the scope-id on a link-local IPv6 address
285  * will be stripped.
286  *
287  * \return same as ast_sockaddr_stringify_fmt()
288  */
289 static inline char *ast_sockaddr_stringify_host_remote(const struct ast_sockaddr *addr)
290 {
292 }
293 
294 /*!
295  * \since 1.8
296  *
297  * \brief
298  * Wrapper around ast_sockaddr_stringify_fmt() to return a port only
299  *
300  * \return same as ast_sockaddr_stringify_fmt()
301  */
302 static inline char *ast_sockaddr_stringify_port(const struct ast_sockaddr *addr)
303 {
305 }
306 
307 /*!
308  * \since 1.8
309  *
310  * \brief
311  * Splits a string into its host and port components
312  *
313  * \param str[in] The string to parse. May be modified by writing a NUL at the end of
314  * the host part.
315  * \param host[out] Pointer to the host component within \a str.
316  * \param port[out] Pointer to the port component within \a str.
317  * \param flags If set to zero, a port MAY be present. If set to PARSE_PORT_IGNORE, a
318  * port MAY be present but will be ignored. If set to PARSE_PORT_REQUIRE,
319  * a port MUST be present. If set to PARSE_PORT_FORBID, a port MUST NOT
320  * be present.
321  *
322  * \retval 1 Success
323  * \retval 0 Failure
324  */
325 int ast_sockaddr_split_hostport(char *str, char **host, char **port, int flags);
326 
327 /*!
328  * \since 1.8
329  *
330  * \brief
331  * Parse an IPv4 or IPv6 address string.
332  *
333  * \details
334  * Parses a string containing an IPv4 or IPv6 address followed by an optional
335  * port (separated by a colon) into a struct ast_sockaddr. The allowed formats
336  * are the following:
337  *
338  * a.b.c.d
339  * a.b.c.d:port
340  * a:b:c:...:d
341  * [a:b:c:...:d]
342  * [a:b:c:...:d]:port
343  *
344  * Host names are NOT allowed.
345  *
346  * \param[out] addr The resulting ast_sockaddr. This MAY be NULL from
347  * functions that are performing validity checks only, e.g. ast_parse_arg().
348  * \param str The string to parse
349  * \param flags If set to zero, a port MAY be present. If set to
350  * PARSE_PORT_IGNORE, a port MAY be present but will be ignored. If set to
351  * PARSE_PORT_REQUIRE, a port MUST be present. If set to PARSE_PORT_FORBID, a
352  * port MUST NOT be present.
353  *
354  * \retval 1 Success
355  * \retval 0 Failure
356  */
357 int ast_sockaddr_parse(struct ast_sockaddr *addr, const char *str, int flags);
358 
359 /*!
360  * \since 1.8
361  *
362  * \brief
363  * Parses a string with an IPv4 or IPv6 address and place results into an array
364  *
365  * \details
366  * Parses a string containing a host name or an IPv4 or IPv6 address followed
367  * by an optional port (separated by a colon). The result is returned into a
368  * array of struct ast_sockaddr. Allowed formats for str are the following:
369  *
370  * hostname:port
371  * host.example.com:port
372  * a.b.c.d
373  * a.b.c.d:port
374  * a:b:c:...:d
375  * [a:b:c:...:d]
376  * [a:b:c:...:d]:port
377  *
378  * \param[out] addrs The resulting array of ast_sockaddrs
379  * \param str The string to parse
380  * \param flags If set to zero, a port MAY be present. If set to
381  * PARSE_PORT_IGNORE, a port MAY be present but will be ignored. If set to
382  * PARSE_PORT_REQUIRE, a port MUST be present. If set to PARSE_PORT_FORBID, a
383  * port MUST NOT be present.
384  *
385  * \param family Only addresses of the given family will be returned. Use 0 or
386  * AST_SOCKADDR_UNSPEC to get addresses of all families.
387  *
388  * \retval 0 Failure
389  * \retval non-zero The number of elements in addrs array.
390  */
391 int ast_sockaddr_resolve(struct ast_sockaddr **addrs, const char *str,
392  int flags, int family);
393 
394 /*!
395  * \since 1.8
396  *
397  * \brief
398  * Get the port number of a socket address.
399  *
400  * \warning Do not use this function unless you really know what you are doing.
401  * And "I want the port number" is not knowing what you are doing.
402  *
403  * \retval 0 Address is null
404  * \retval non-zero The port number of the ast_sockaddr
405  */
406 #define ast_sockaddr_port(addr) _ast_sockaddr_port(addr, __FILE__, __LINE__, __PRETTY_FUNCTION__)
407 uint16_t _ast_sockaddr_port(const struct ast_sockaddr *addr, const char *file, int line, const char *func);
408 
409 /*!
410  * \since 1.8
411  *
412  * \brief
413  * Sets the port number of a socket address.
414  *
415  * \warning Do not use this function unless you really know what you are doing.
416  * And "I want the port number" is not knowing what you are doing.
417  *
418  * \param addr Address on which to set the port
419  * \param port The port you wish to set the address to use
420  * \retval void
421  */
422 #define ast_sockaddr_set_port(addr,port) _ast_sockaddr_set_port(addr,port,__FILE__,__LINE__,__PRETTY_FUNCTION__)
423 void _ast_sockaddr_set_port(struct ast_sockaddr *addr, uint16_t port, const char *file, int line, const char *func);
424 
425 /*!
426  * \since 1.8
427  *
428  * \brief
429  * Get an IPv4 address of an ast_sockaddr
430  *
431  * \warning You should rarely need this function. Only use if you know what
432  * you're doing.
433  * \return IPv4 address in network byte order
434  */
435 uint32_t ast_sockaddr_ipv4(const struct ast_sockaddr *addr);
436 
437 /*!
438  * \since 1.8
439  *
440  * \brief
441  * Determine if the address is an IPv4 address
442  *
443  * \warning You should rarely need this function. Only use if you know what
444  * you're doing.
445  * \retval 1 This is an IPv4 address
446  * \retval 0 This is an IPv6 or IPv4-mapped IPv6 address
447  */
448 int ast_sockaddr_is_ipv4(const struct ast_sockaddr *addr);
449 
450 /*!
451  * \since 1.8
452  *
453  * \brief
454  * Determine if this is an IPv4-mapped IPv6 address
455  *
456  * \warning You should rarely need this function. Only use if you know what
457  * you're doing.
458  *
459  * \retval 1 This is an IPv4-mapped IPv6 address.
460  * \retval 0 This is not an IPv4-mapped IPv6 address.
461  */
462 int ast_sockaddr_is_ipv4_mapped(const struct ast_sockaddr *addr);
463 
464 /*!
465  * \since 1.8
466  *
467  * \brief
468  * Determine if this is a link-local IPv6 address
469  *
470  * \warning You should rarely need this function. Only use if you know what
471  * you're doing.
472  *
473  * \retval 1 This is a link-local IPv6 address.
474  * \retval 0 This is link-local IPv6 address.
475  */
476 int ast_sockaddr_is_ipv6_link_local(const struct ast_sockaddr *addr);
477 
478 /*!
479  * \since 1.8
480  *
481  * \brief
482  * Determine if this is an IPv6 address
483  *
484  * \warning You should rarely need this function. Only use if you know what
485  * you're doing.
486  *
487  * \retval 1 This is an IPv6 or IPv4-mapped IPv6 address.
488  * \retval 0 This is an IPv4 address.
489  */
490 int ast_sockaddr_is_ipv6(const struct ast_sockaddr *addr);
491 
492 /*!
493  * \since 1.8
494  *
495  * \brief
496  * Determine if the address type is unspecified, or "any" address.
497  *
498  * \details
499  * For IPv4, this would be the address 0.0.0.0, and for IPv6,
500  * this would be the address ::. The port number is ignored.
501  *
502  * \retval 1 This is an "any" address
503  * \retval 0 This is not an "any" address
504  */
505 int ast_sockaddr_is_any(const struct ast_sockaddr *addr);
506 
507 /*!
508  * \since 1.8
509  *
510  * \brief
511  * Computes a hash value from the address. The port is ignored.
512  *
513  * \retval 0 Unknown address family
514  * \retval other A 32-bit hash derived from the address
515  */
516 int ast_sockaddr_hash(const struct ast_sockaddr *addr);
517 
518 /*!
519  * \since 1.8
520  *
521  * \brief
522  * Wrapper around accept(2) that uses struct ast_sockaddr.
523  *
524  * \details
525  * For parameter and return information, see the man page for
526  * accept(2).
527  */
528 int ast_accept(int sockfd, struct ast_sockaddr *addr);
529 
530 /*!
531  * \since 1.8
532  *
533  * \brief
534  * Wrapper around bind(2) that uses struct ast_sockaddr.
535  *
536  * \details
537  * For parameter and return information, see the man page for
538  * bind(2).
539  */
540 int ast_bind(int sockfd, const struct ast_sockaddr *addr);
541 
542 /*!
543  * \since 1.8
544  *
545  * \brief
546  * Wrapper around connect(2) that uses struct ast_sockaddr.
547  *
548  * \details
549  * For parameter and return information, see the man page for
550  * connect(2).
551  */
552 int ast_connect(int sockfd, const struct ast_sockaddr *addr);
553 
554 /*!
555  * \since 1.8
556  *
557  * \brief
558  * Wrapper around getsockname(2) that uses struct ast_sockaddr.
559  *
560  * \details
561  * For parameter and return information, see the man page for
562  * getsockname(2).
563  */
564 int ast_getsockname(int sockfd, struct ast_sockaddr *addr);
565 
566 /*!
567  * \since 1.8
568  *
569  * \brief
570  * Wrapper around recvfrom(2) that uses struct ast_sockaddr.
571  *
572  * \details
573  * For parameter and return information, see the man page for
574  * recvfrom(2).
575  */
576 ssize_t ast_recvfrom(int sockfd, void *buf, size_t len, int flags,
577  struct ast_sockaddr *src_addr);
578 
579 /*!
580  * \since 1.8
581  *
582  * \brief
583  * Wrapper around sendto(2) that uses ast_sockaddr.
584  *
585  * \details
586  * For parameter and
587  * return information, see the man page for sendto(2)
588  */
589 ssize_t ast_sendto(int sockfd, const void *buf, size_t len, int flags,
590  const struct ast_sockaddr *dest_addr);
591 
592 /*!
593  * \since 1.8
594  *
595  * \brief
596  * Set type of service
597  *
598  * \details
599  * Set ToS ("Type of Service for IPv4 and "Traffic Class for IPv6) and
600  * CoS (Linux's SO_PRIORITY)
601  *
602  * \param sockfd File descriptor for socket on which to set the parameters
603  * \param tos The type of service for the socket
604  * \param cos The cost of service for the socket
605  * \param desc A text description of the socket in question.
606  * \retval 0 Success
607  * \retval -1 Error, with errno set to an appropriate value
608  */
609 int ast_set_qos(int sockfd, int tos, int cos, const char *desc);
610 
611 /*!
612  * These are backward compatibility functions that may be used by subsystems
613  * that have not yet been converted to IPv6. They will be removed when all
614  * subsystems are IPv6-ready.
615  */
616 /*@{*/
617 
618 /*!
619  * \since 1.8
620  *
621  * \brief
622  * Converts a struct ast_sockaddr to a struct sockaddr_in.
623  *
624  * \param addr The ast_sockaddr to convert
625  * \param[out] sin The resulting sockaddr_in struct
626  * \retval nonzero Success
627  * \retval zero Failure
628  */
629 #define ast_sockaddr_to_sin(addr,sin) _ast_sockaddr_to_sin(addr,sin, __FILE__, __LINE__, __PRETTY_FUNCTION__)
630 int _ast_sockaddr_to_sin(const struct ast_sockaddr *addr,
631  struct sockaddr_in *sin, const char *file, int line, const char *func);
632 
633 /*!
634  * \since 1.8
635  *
636  * \brief
637  * Converts a struct sockaddr_in to a struct ast_sockaddr.
638  *
639  * \param sin The sockaddr_in to convert
640  * \return an ast_sockaddr structure
641  */
642 #define ast_sockaddr_from_sin(addr,sin) _ast_sockaddr_from_sin(addr,sin, __FILE__, __LINE__, __PRETTY_FUNCTION__)
643 void _ast_sockaddr_from_sin(struct ast_sockaddr *addr, const struct sockaddr_in *sin,
644  const char *file, int line, const char *func);
645 
646 /*@}*/
647 
648 #if defined(__cplusplus) || defined(c_plusplus)
649 }
650 #endif
651 
652 #endif /* _ASTERISK_NETSOCK2_H */
static char * ast_sockaddr_stringify_addr(const struct ast_sockaddr *addr)
Wrapper around ast_sockaddr_stringify_fmt() to return an address only.
Definition: netsock2.h:240
struct sockaddr_storage ss
Definition: netsock2.h:64
ssize_t ast_sendto(int sockfd, const void *buf, size_t len, int flags, const struct ast_sockaddr *dest_addr)
Wrapper around sendto(2) that uses ast_sockaddr.
Definition: netsock2.c:486
static char * ast_sockaddr_stringify_addr_remote(const struct ast_sockaddr *addr)
Wrapper around ast_sockaddr_stringify_fmt() to return an address only.
Definition: netsock2.h:257
static unsigned int tos
Definition: chan_h323.c:146
int ast_sockaddr_parse(struct ast_sockaddr *addr, const char *str, int flags)
Parse an IPv4 or IPv6 address string.
Definition: netsock2.c:198
static void ast_sockaddr_copy(struct ast_sockaddr *dst, const struct ast_sockaddr *src)
Copies the data from one ast_sockaddr to another.
Definition: netsock2.h:121
int ast_sockaddr_ipv4_mapped(const struct ast_sockaddr *addr, struct ast_sockaddr *ast_mapped)
Convert an IPv4-mapped IPv6 address into an IPv4 address.
Definition: netsock2.c:39
socklen_t len
Definition: netsock2.h:65
static char * ast_sockaddr_stringify_remote(const struct ast_sockaddr *addr)
Wrapper around ast_sockaddr_stringify_fmt() with default format.
Definition: netsock2.h:227
uint32_t ast_sockaddr_ipv4(const struct ast_sockaddr *addr)
Get an IPv4 address of an ast_sockaddr.
Definition: netsock2.c:394
const char * str
Definition: app_jack.c:144
int ast_sockaddr_cmp(const struct ast_sockaddr *a, const struct ast_sockaddr *b)
Compares two ast_sockaddr structures.
Definition: netsock2.c:300
Socket address structure.
Definition: netsock2.h:63
int ast_bind(int sockfd, const struct ast_sockaddr *addr)
Wrapper around bind(2) that uses struct ast_sockaddr.
Definition: netsock2.c:462
#define AST_SOCKADDR_STR_DEFAULT_REMOTE
Definition: netsock2.h:160
int ast_sockaddr_cmp_addr(const struct ast_sockaddr *a, const struct ast_sockaddr *b)
Compares the addresses of two ast_sockaddr structures.
Definition: netsock2.c:325
#define AST_SOCKADDR_STR_DEFAULT
Definition: netsock2.h:157
static void ast_sockaddr_setnull(struct ast_sockaddr *addr)
Sets address addr to null.
Definition: netsock2.h:106
static int ast_sockaddr_isnull(const struct ast_sockaddr *addr)
Checks if the ast_sockaddr is null. &quot;null&quot; in this sense essentially means uninitialized, or having a 0 length.
Definition: netsock2.h:93
static char * ast_sockaddr_stringify_port(const struct ast_sockaddr *addr)
Wrapper around ast_sockaddr_stringify_fmt() to return a port only.
Definition: netsock2.h:302
int _ast_sockaddr_to_sin(const struct ast_sockaddr *addr, struct sockaddr_in *sin, const char *file, int line, const char *func)
Definition: netsock2.c:540
int ast_sockaddr_is_any(const struct ast_sockaddr *addr)
Determine if the address type is unspecified, or &quot;any&quot; address.
Definition: netsock2.c:424
int ast_sockaddr_split_hostport(char *str, char **host, char **port, int flags)
Splits a string into its host and port components.
Definition: netsock2.c:132
int ast_accept(int sockfd, struct ast_sockaddr *addr)
Wrapper around accept(2) that uses struct ast_sockaddr.
Definition: netsock2.c:456
#define AST_SOCKADDR_STR_HOST_REMOTE
Definition: netsock2.h:159
int ast_sockaddr_hash(const struct ast_sockaddr *addr)
Computes a hash value from the address. The port is ignored.
Definition: netsock2.c:438
static const char desc[]
Definition: cdr_radius.c:85
#define AST_SOCKADDR_STR_PORT
Definition: netsock2.h:153
int ast_sockaddr_is_ipv6_link_local(const struct ast_sockaddr *addr)
Determine if this is a link-local IPv6 address.
Definition: netsock2.c:412
uint16_t _ast_sockaddr_port(const struct ast_sockaddr *addr, const char *file, int line, const char *func)
Definition: netsock2.c:365
#define AST_SOCKADDR_STR_HOST
Definition: netsock2.h:156
int ast_set_qos(int sockfd, int tos, int cos, const char *desc)
Set type of service.
Definition: netsock2.c:493
static int len(struct ast_channel *chan, const char *cmd, char *data, char *buf, size_t buflen)
static char * ast_sockaddr_stringify(const struct ast_sockaddr *addr)
Wrapper around ast_sockaddr_stringify_fmt() with default format.
Definition: netsock2.h:210
ssize_t ast_recvfrom(int sockfd, void *buf, size_t len, int flags, struct ast_sockaddr *src_addr)
Wrapper around recvfrom(2) that uses struct ast_sockaddr.
Definition: netsock2.c:478
char * ast_sockaddr_stringify_fmt(const struct ast_sockaddr *addr, int format)
Convert a socket address to a string.
Definition: netsock2.c:67
void _ast_sockaddr_set_port(struct ast_sockaddr *addr, uint16_t port, const char *file, int line, const char *func)
Definition: netsock2.c:380
static char * ast_sockaddr_stringify_host_remote(const struct ast_sockaddr *addr)
Wrapper around ast_sockaddr_stringify_fmt() to return an address only, suitable for a URL (with brack...
Definition: netsock2.h:289
#define AST_SOCKADDR_STR_ADDR_REMOTE
Definition: netsock2.h:158
int ast_sockaddr_is_ipv4_mapped(const struct ast_sockaddr *addr)
Determine if this is an IPv4-mapped IPv6 address.
Definition: netsock2.c:406
void _ast_sockaddr_from_sin(struct ast_sockaddr *addr, const struct sockaddr_in *sin, const char *file, int line, const char *func)
Definition: netsock2.c:561
#define AST_SOCKADDR_STR_ADDR
Definition: netsock2.h:152
int ast_sockaddr_is_ipv4(const struct ast_sockaddr *addr)
Determine if the address is an IPv4 address.
Definition: netsock2.c:400
int ast_getsockname(int sockfd, struct ast_sockaddr *addr)
Wrapper around getsockname(2) that uses struct ast_sockaddr.
Definition: netsock2.c:472
static unsigned int cos
Definition: chan_h323.c:147
static snd_pcm_format_t format
Definition: chan_alsa.c:93
int ast_sockaddr_is_ipv6(const struct ast_sockaddr *addr)
Determine if this is an IPv6 address.
Definition: netsock2.c:418
int ast_connect(int sockfd, const struct ast_sockaddr *addr)
Wrapper around connect(2) that uses struct ast_sockaddr.
Definition: netsock2.c:467
static char * ast_sockaddr_stringify_host(const struct ast_sockaddr *addr)
Wrapper around ast_sockaddr_stringify_fmt() to return an address only, suitable for a URL (with brack...
Definition: netsock2.h:271
int ast_sockaddr_resolve(struct ast_sockaddr **addrs, const char *str, int flags, int family)
Parses a string with an IPv4 or IPv6 address and place results into an array.
Definition: netsock2.c:248