[asterisk-commits] blanchet: branch blanchet/v6 r58477 - /team/blanchet/v6/include/asterisk/

asterisk-commits at lists.digium.com asterisk-commits at lists.digium.com
Thu Mar 8 14:07:33 MST 2007


Author: blanchet
Date: Thu Mar  8 15:07:32 2007
New Revision: 58477

URL: http://svn.digium.com/view/asterisk?view=rev&rev=58477
Log:
First cut of IP version independent netsock routines
Supports both IPv4 and IPv6.
no changes to the current ast_netsock routines were done.
new routines names start with ast_vinetsock. (vi stands for version independent)

Modified:
    team/blanchet/v6/include/asterisk/netsock.h

Modified: team/blanchet/v6/include/asterisk/netsock.h
URL: http://svn.digium.com/view/asterisk/team/blanchet/v6/include/asterisk/netsock.h?view=diff&rev=58477&r1=58476&r2=58477
==============================================================================
--- team/blanchet/v6/include/asterisk/netsock.h (original)
+++ team/blanchet/v6/include/asterisk/netsock.h Thu Mar  8 15:07:32 2007
@@ -18,7 +18,14 @@
  */
 
 /*! \file
- * \brief Network socket handling
+ * \brief Network socket handling. 
+ * The ast_vinetwork* functions, vi stands for 'version independant', support 
+ * both IPv4 and IPv6. Storage of sockaddr_* is in sockaddr_storage but, 
+ * as per RFC3493 routines, pointers to sockaddr struct are use for public API.
+ *
+ * IPv6/version independent version:
+ * \author Marc Blanchet <marc.blanchet at viagenie.ca>
+ * \author Frederick Lefebvre <frederick.lefebvre at viagenie.ca>
  */
 
 #ifndef _ASTERISK_NETSOCK_H
@@ -31,7 +38,113 @@
 #include <netinet/in.h>
 #include "asterisk/io.h"
 #include "asterisk/astobj.h"
+#include "asterisk/utils.h"
 
+
+struct ast_vinetsock {
+	ASTOBJ_COMPONENTS(struct ast_vinetsock);
+	struct sockaddr_storage bindaddr;
+        socklen_t bindaddrlen;
+	int sock_family;
+	int sock_protocol;
+	int sock_type;
+	int sockfd;
+	int *ioref;
+	struct io_context *ioc;
+	void *data;
+};
+
+struct ast_vinetsock_list {
+	ASTOBJ_CONTAINER_COMPONENTS(struct ast_vinetsock);
+	struct io_context *ioc;
+};
+
+/* vinetsock utilitary functions */
+struct ast_vinetsock_list *ast_vinetsock_list_alloc(void);
+void ast_vinetsock_free(struct ast_vinetsock* ns);
+void ast_vinetsock_init(struct ast_vinetsock_list *list);
+void ast_vinetsock_release(struct ast_vinetsock_list *list);
+struct ast_vinetsock* ast_vinetsock_find_best(struct ast_vinetsock_list *list, 
+					      struct sockaddr* dst, socklen_t dstlen,
+					      int af);
+int ast_vinetsock_list_isempty(struct ast_vinetsock_list *list);
+struct ast_vinetsock *ast_vinetsock_find(struct ast_vinetsock_list *list,
+					 struct sockaddr *sa, socklen_t salen,
+					 int sockfd);
+void ast_vinetsock_list_add(struct ast_vinetsock_list *list, struct ast_vinetsock *ns);
+void ast_vinetsock_unref(struct ast_vinetsock *ns);
+
+/* vinetsock socket functions */
+void ast_vinetsock_list_bind(struct ast_vinetsock_list *list,
+			    struct io_context *ioc, 
+			    int tos, ast_io_cb callback, void *data,
+			    int reuseaddr, char *module_name);
+struct ast_vinetsock *ast_vinetsock_bindaddr(struct ast_vinetsock_list *list, 
+					     struct io_context *ioc, 
+					     struct addrinfo *bindaddr, int tos, 
+					     ast_io_cb callback, void *data);
+struct ast_vinetsock *ast_vinetsock_bind_portn(struct ast_vinetsock_list *list, 
+					  struct io_context *ioc, const char *bindinfo, 
+					  int port, int tos, ast_io_cb callback, void *data);
+struct ast_vinetsock *ast_vinetsock_bind_portstr(struct ast_vinetsock_list *list, struct io_context *ioc,
+					 const char *bindinfo, char *port, int tos,
+					 ast_io_cb callback, void *data);
+struct ast_vinetsock *ast_vinetsock_new(const char* iabuf, const char *sbuf);
+int ast_vinetsock_bind(struct ast_vinetsock *ns, struct io_context *ioc, 
+			int tos, ast_io_cb callback, void *data, int reuseaddr,
+		       const char* module_name);
+int ast_vinetsock_list_getsockfd(struct ast_vinetsock_list *list, int af);
+int ast_vinetsock_sockfd_settos(int sockfd, int af, int tos);
+
+/* vinetsock sockaddr functions */
+void ast_vinetsock_list_set_defport(struct ast_vinetsock_list *list,
+				    int portno);
+int ast_vinetsock_getport(const struct ast_vinetsock *ns);
+int ast_vinetsock_isvalid_port(long int portno);
+int ast_vinetsock_safromhost(char* host, char* port, int stype,
+			     struct sockaddr* sa, socklen_t *salen);
+int ast_vinetsock_sa_fromstr(const char* addr, const char* port, struct sockaddr* sa, 
+			     socklen_t *salen, int af, int numerichost);
+int ast_vinetsock_sa_setport(const struct sockaddr *sa, const int portno);
+int ast_vinetsock_sa_getport(const struct sockaddr *sa, socklen_t salen);
+int ast_vinetsock_sa_getsrc(struct sockaddr* dst, socklen_t dstlen,
+			    struct sockaddr* src, socklen_t *srclen,
+			    int socktype);
+int ast_vinetsock_getaddr(const struct ast_vinetsock* ns,
+			  char* iabuf, size_t iabuflen);
+int ast_vinetsock_sa_getaddr(const struct sockaddr* sa, socklen_t salen,
+			     char* iabuf, size_t iabuflen);
+int ast_vinetsock_sa_getsrc_default(struct sockaddr* dst, socklen_t dstlen,
+				    struct sockaddr* src, socklen_t *srclen,
+				    int portno);
+int ast_vinetsock_sa_is_ipv4(const struct sockaddr* sa);
+int ast_vinetsock_is_ipv4(const struct ast_vinetsock* ns);
+int ast_vinetsock_is_ipv6(const struct ast_vinetsock* ns);
+int ast_vinetsock_sa_is_ipv6(const struct sockaddr* sa);
+int ast_vinetsock_is_wildcard(const struct ast_vinetsock* ns);
+int ast_vinetsock_sa_is_wildcard(const struct sockaddr* sa);
+
+/* vinetsock string functions */
+int ast_vinetsock_str2port(const char *port);
+int ast_vinetsock_str2hp(char *hbuf, size_t hostsize, char *sbuf,
+			 size_t portsize, const char *hostport,
+			 int numeric, const char **end);
+int ast_vinetsock_hp2str(char *hbuf, char *sbuf, char *hp, size_t hplen);
+int ast_vinetsock_sa_get_host(const struct sockaddr* sa, socklen_t salen,
+			      char* host, size_t hostlen);
+int ast_vinetsock_get_hostport(const struct ast_vinetsock *ns, char *hostport, 
+			       size_t hplen);
+int ast_vinetsock_sa_get_hostport(const struct sockaddr *sa, socklen_t salen, 
+				  char *hostport, size_t hplen);
+
+int ast_vinetsock_sacmp(const struct sockaddr *sa1,
+		    socklen_t sa1len, const struct sockaddr *sa2,
+		    socklen_t sa2len, int ignore_port);
+int ast_vinetsock_sacmp_port(const struct sockaddr *sa1,
+		    socklen_t sa1len, const struct sockaddr *sa2,
+		    socklen_t sa2len);
+
+/* below is the original netsock IPv4-only code. kept for compatibility */
 struct ast_netsock;
 
 struct ast_netsock_list;



More information about the asterisk-commits mailing list