[asterisk-commits] may: branch may/ooh323_ipv6 r292409 - in /team/may/ooh323_ipv6/addons: ./ ooh...

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Wed Oct 20 16:24:32 CDT 2010


Author: may
Date: Wed Oct 20 16:24:29 2010
New Revision: 292409

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=292409
Log:
initial changes in stack, socket operations and some other adopted

Modified:
    team/may/ooh323_ipv6/addons/Makefile
    team/may/ooh323_ipv6/addons/chan_ooh323.c
    team/may/ooh323_ipv6/addons/ooh323c/src/ooCalls.h
    team/may/ooh323_ipv6/addons/ooh323c/src/ooGkClient.h
    team/may/ooh323_ipv6/addons/ooh323c/src/ooLogChan.h
    team/may/ooh323_ipv6/addons/ooh323c/src/ooSocket.c
    team/may/ooh323_ipv6/addons/ooh323c/src/ooSocket.h
    team/may/ooh323_ipv6/addons/ooh323c/src/oochannels.c
    team/may/ooh323_ipv6/addons/ooh323c/src/ooh323ep.c
    team/may/ooh323_ipv6/addons/ooh323c/src/ooh323ep.h
    team/may/ooh323_ipv6/addons/ooh323c/src/ooports.c
    team/may/ooh323_ipv6/addons/ooh323c/src/ootypes.h

Modified: team/may/ooh323_ipv6/addons/Makefile
URL: http://svnview.digium.com/svn/asterisk/team/may/ooh323_ipv6/addons/Makefile?view=diff&rev=292409&r1=292408&r2=292409
==============================================================================
--- team/may/ooh323_ipv6/addons/Makefile (original)
+++ team/may/ooh323_ipv6/addons/Makefile Wed Oct 20 16:24:29 2010
@@ -14,10 +14,10 @@
 MENUSELECT_CATEGORY=ADDONS
 MENUSELECT_DESCRIPTION=Add-ons (See README-addons.txt)
 
-H323OBJS:=ooCmdChannel.o ooLogChan.o ooUtils.o ooGkClient.o context.o \
+H323OBJS:=ooSocket.o ooCmdChannel.o ooLogChan.o ooUtils.o context.o \
 	ooDateTime.o decode.o dlist.o encode.o errmgmt.o \
-	memheap.o ootrace.o oochannels.o ooh245.o ooports.o \
-	ooq931.o ooCapability.o ooSocket.o perutil.o eventHandler.o \
+	memheap.o ootrace.o oochannels.o ooports.o ooh245.o \
+	ooq931.o ooGkClient.o ooCapability.o perutil.o eventHandler.o \
 	ooCalls.o ooStackCmds.o ooh323.o ooh323ep.o printHandler.o \
 	rtctype.o ooTimer.o h323/H235-SECURITY-MESSAGESDec.o \
 	h323/H235-SECURITY-MESSAGESEnc.o h323/H323-MESSAGES.o h323/H323-MESSAGESDec.o \

Modified: team/may/ooh323_ipv6/addons/chan_ooh323.c
URL: http://svnview.digium.com/svn/asterisk/team/may/ooh323_ipv6/addons/chan_ooh323.c?view=diff&rev=292409&r1=292408&r2=292409
==============================================================================
--- team/may/ooh323_ipv6/addons/chan_ooh323.c (original)
+++ team/may/ooh323_ipv6/addons/chan_ooh323.c Wed Oct 20 16:24:29 2010
@@ -2533,6 +2533,7 @@
 			ast_copy_string(gIP, v->value, sizeof(gIP));
 			if (ast_parse_arg(v->value, PARSE_ADDR, &bindaddr)) {
 				ast_log(LOG_WARNING, "Invalid address: %s\n", v->value);
+				return 1;
 			}
 		} else if (!strcasecmp(v->name, "h225portrange")) {
 			char* endlimit = 0;
@@ -2751,7 +2752,7 @@
 	/* Determine ip address if neccessary */
 	if (ast_strlen_zero(gIP)) {
 		ooGetLocalIPAddress(gIP);
-		if (!strcmp(gIP, "127.0.0.1")) {
+		if (!strcmp(gIP, "127.0.0.1") || !strcmp(gIP, "::1")) {
 			ast_log(LOG_NOTICE, "Failed to determine local ip address. Please "
 									 "specify it in ooh323.conf. OOH323 Disabled\n");
 			return 1;

Modified: team/may/ooh323_ipv6/addons/ooh323c/src/ooCalls.h
URL: http://svnview.digium.com/svn/asterisk/team/may/ooh323_ipv6/addons/ooh323c/src/ooCalls.h?view=diff&rev=292409&r1=292408&r2=292409
==============================================================================
--- team/may/ooh323_ipv6/addons/ooh323c/src/ooCalls.h (original)
+++ team/may/ooh323_ipv6/addons/ooh323c/src/ooCalls.h Wed Oct 20 16:24:29 2010
@@ -178,12 +178,12 @@
    int			dtmfcodec;
    OOMediaInfo          *mediaInfo;
    OOCallFwdData        *pCallFwdData;
-   char                 localIP[20];/* Local IP address */
+   char                 localIP[2+8*4+7];/* Local IP address */
    OOH323Channel*       pH225Channel;
    OOH323Channel*       pH245Channel;
    OOSOCKET             *h245listener;
    int                  *h245listenport;
-   char                 remoteIP[20];/* Remote IP address */
+   char                 remoteIP[2+8*4+7];/* Remote IP address */
    int                  remotePort;
    int                  remoteH245Port;
    char                 *remoteDisplayName;

Modified: team/may/ooh323_ipv6/addons/ooh323c/src/ooGkClient.h
URL: http://svnview.digium.com/svn/asterisk/team/may/ooh323_ipv6/addons/ooh323c/src/ooGkClient.h?view=diff&rev=292409&r1=292408&r2=292409
==============================================================================
--- team/may/ooh323_ipv6/addons/ooh323c/src/ooGkClient.h (original)
+++ team/may/ooh323_ipv6/addons/ooh323c/src/ooGkClient.h Wed Oct 20 16:24:29 2010
@@ -47,7 +47,7 @@
 
 
 
-#define MAX_IP_LEN 18
+#define MAX_IP_LEN 2+8*4+7
 #define DEFAULT_GKPORT 1719
 #define MULTICAST_GKADDRESS "224.0.1.41"
 #define MULTICAST_GKPORT 1718
@@ -181,9 +181,9 @@
    OOCTXT msgCtxt;
    OOSOCKET rasSocket;
    int localRASPort;
-   char localRASIP[20];
-   char gkRasIP[20];
-   char gkCallSignallingIP[20];
+   char localRASIP[2+8*4+7];
+   char gkRasIP[2+8*4+7];
+   char gkCallSignallingIP[2+8*4+7];
    RasGatekeeperInfo gkInfo;
    int gkRasPort;
    int gkCallSignallingPort;

Modified: team/may/ooh323_ipv6/addons/ooh323c/src/ooLogChan.h
URL: http://svnview.digium.com/svn/asterisk/team/may/ooh323_ipv6/addons/ooh323c/src/ooLogChan.h?view=diff&rev=292409&r1=292408&r2=292409
==============================================================================
--- team/may/ooh323_ipv6/addons/ooh323c/src/ooLogChan.h (original)
+++ team/may/ooh323_ipv6/addons/ooh323c/src/ooLogChan.h Wed Oct 20 16:24:29 2010
@@ -53,12 +53,12 @@
    int  sessionID;
    enum OOCapType type;
    char dir[10];  /* receive/transmit */
-   char remoteIP[20];
+   char remoteIP[2+8*4+7];
    int  remoteMediaPort;
    int  remoteMediaControlPort;
    int  localRtpPort;
    int  localRtcpPort;
-   char localIP[20];
+   char localIP[2+8*4+7];
    OOLogicalChannelState state;         
    struct ooH323EpCapability *chanCap;
    struct OOLogicalChannel *next;

Modified: team/may/ooh323_ipv6/addons/ooh323c/src/ooSocket.c
URL: http://svnview.digium.com/svn/asterisk/team/may/ooh323_ipv6/addons/ooh323c/src/ooSocket.c?view=diff&rev=292409&r1=292408&r2=292409
==============================================================================
--- team/may/ooh323_ipv6/addons/ooh323c/src/ooSocket.c (original)
+++ team/may/ooh323_ipv6/addons/ooh323c/src/ooSocket.c Wed Oct 20 16:24:29 2010
@@ -21,9 +21,16 @@
 #include "asterisk/lock.h"
 #include "asterisk/utils.h"
 #include "asterisk/network.h"
+#include "asterisk/netsock2.h"
+#include "asterisk/config.h"
 
 #include "ooSocket.h"
 #include "ootrace.h"
+#include "ooh323ep.h"
+
+/** Global endpoint structure */
+extern OOH323EndPoint gH323ep;
+
 #if defined(_WIN32_WCE)
 static int inited = 0;
 #define SEND_FLAGS     0
@@ -191,11 +198,18 @@
 int ooSocketCreate (OOSOCKET* psocket) 
 {
    int on;
+   OOSOCKET sock;
 
    struct linger linger;
-   OOSOCKET sock = socket (AF_INET,
-                             SOCK_STREAM,
-                             0);
+   if (gH323ep.v6Mode) {
+   	sock = socket (AF_INET6,
+                             	SOCK_STREAM,
+                             	0);
+   } else {
+   	sock = socket (AF_INET,
+                            	SOCK_STREAM,
+                             	0);
+   }
   
    if (sock == OOSOCKET_INVALID){
       OOTRACEERR1("Error:Failed to create TCP socket\n");
@@ -225,8 +239,14 @@
 {
    int on;
    struct linger linger;
-
-   OOSOCKET sock = socket (AF_INET,
+   OOSOCKET sock;
+
+   if (gH323ep.v6Mode)
+   	sock = socket (AF_INET6,
+                             SOCK_DGRAM,
+                             0);
+   else
+   	sock = socket (AF_INET,
                              SOCK_DGRAM,
                              0);
 
@@ -262,7 +282,10 @@
 
 int ooSocketBind (OOSOCKET socket, OOIPADDR addr, int port) 
 {
-   struct sockaddr_in m_addr;
+   struct ast_sockaddr m_addr;
+
+   memset(&m_addr, 0, sizeof(m_addr));
+
 
    if (socket == OOSOCKET_INVALID)
    { 
@@ -270,14 +293,10 @@
       return ASN_E_INVSOCKET;
    }
 
-   memset (&m_addr, 0, sizeof (m_addr));
-   m_addr.sin_family = AF_INET;
-   m_addr.sin_addr.s_addr = (addr == 0) ? INADDR_ANY : htonl (addr);
-   m_addr.sin_port = htons ((unsigned short)port);
-
-   if (bind (socket, (struct sockaddr *) (void*) &m_addr,
-                     sizeof (m_addr)) == -1)
-   {
+   ast_sockaddr_copy(&m_addr, &addr);
+   ast_sockaddr_set_port(&m_addr, port);
+
+   if (ast_bind(socket, &m_addr) < 0) {
       if (errno != EADDRINUSE) {
       	perror ("bind");
       	OOTRACEERR2("Error:Bind failed, error: %d\n", errno);
@@ -304,17 +323,14 @@
 int ooSocketGetIpAndPort(OOSOCKET socket, char *ip, int len, int *port)
 {
    int ret=ASN_OK;
-   socklen_t size;
-   struct sockaddr_in addr;
+   struct ast_sockaddr addr;
    const char *host=NULL;
 
-   size = sizeof(addr);
-
-   ret = ooSocketGetSockName(socket, &addr, &size);
+   ret = ast_getsockname(socket, &addr);
    if(ret != 0)
       return ASN_E_INVSOCKET;
 
-   host = ast_inet_ntoa(addr.sin_addr);
+   host = ast_sockaddr_stringify_host(&addr);
 
    if(host && strlen(host) < (unsigned)len)
       strcpy(ip, host);   
@@ -323,8 +339,7 @@
                  "ooSocketGetIpAndPort\n");
       return -1;
    }
-   
-   *port = addr.sin_port;
+   *port = ast_sockaddr_port(&addr);
 
    return ASN_OK;
 }
@@ -342,27 +357,25 @@
 int ooSocketAccept (OOSOCKET socket, OOSOCKET *pNewSocket, 
                     OOIPADDR* destAddr, int* destPort) 
 {
-   struct sockaddr_in m_addr;
-   OOSOCKLEN addr_length = sizeof (m_addr);
+   struct ast_sockaddr addr;
 
    if (socket == OOSOCKET_INVALID) return ASN_E_INVSOCKET;
    if (pNewSocket == 0) return ASN_E_INVPARAM;
 
-   *pNewSocket = accept (socket, (struct sockaddr *) (void*) &m_addr, 
-                         &addr_length);
+   *pNewSocket = ast_accept (socket, &addr);
    if (*pNewSocket <= 0) return ASN_E_INVSOCKET;
 
    if (destAddr != 0) 
-      *destAddr = ntohl (m_addr.sin_addr.s_addr);
+      *destAddr = addr;
    if (destPort != 0)
-      *destPort = ntohs (m_addr.sin_port);
+      *destPort =  ast_sockaddr_port(&addr);
 
    return ASN_OK;
 }
 
 int ooSocketConnect (OOSOCKET socket, const char* host, int port) 
 {
-   struct sockaddr_in m_addr;
+   struct ast_sockaddr m_addr;
 
    if (socket == OOSOCKET_INVALID)
    { 
@@ -370,13 +383,12 @@
    }
    
    memset (&m_addr, 0, sizeof (m_addr));
-
-   m_addr.sin_family = AF_INET;
-   m_addr.sin_port = htons ((unsigned short)port);
-   m_addr.sin_addr.s_addr = inet_addr (host);
+   ast_parse_arg(host, PARSE_ADDR, &m_addr);
+   ast_sockaddr_set_port(&m_addr, port);
 
    if (connect (socket, (struct sockaddr *) (void*) &m_addr, 
                 sizeof (struct sockaddr_in)) == -1)
+   if (ast_connect(socket, &m_addr))
    {
       return ASN_E_INVSOCKET;
    }
@@ -512,10 +524,18 @@
    ret = gethostname(hostname, 100);
    if(ret == 0)
    {
-      if (!(hp = ast_gethostbyname(hostname, &phost))) {
-	  		struct in_addr i;
-			memcpy(&i, hp->h_addr, sizeof(i));
-			  strcpy(pIPAddrs, (ast_inet_ntoa(i) == NULL) ? "127.0.0.1" : ast_inet_ntoa(i));
+      if ((hp = ast_gethostbyname(hostname, &phost))) {
+			if (hp->h_addrtype == AF_INET6) {
+				struct in6_addr i;
+				memcpy(&i, hp->h_addr, sizeof(i));
+				strcpy(pIPAddrs, (inet_ntop(AF_INET6, &i, 
+				hostname, sizeof(hostname))) == NULL ? "::1" : 
+				inet_ntop(AF_INET6, &i, hostname, sizeof(hostname)));
+			} else {
+	  			struct in_addr i;
+				memcpy(&i, hp->h_addr, sizeof(i));
+			  	strcpy(pIPAddrs, (ast_inet_ntoa(i) == NULL) ? "127.0.0.1" : ast_inet_ntoa(i));
+			}
       } else {
          return -1;
       }
@@ -526,7 +546,7 @@
    return ASN_OK;
 }
 
-int ooSocketStrToAddr (const char* pIPAddrStr, OOIPADDR* pIPAddr) 
+/* int ooSocketStrToAddr (const char* pIPAddrStr, OOIPADDR* pIPAddr) 
 {
    int b1, b2, b3, b4;
    int rv = sscanf (pIPAddrStr, "%d.%d.%d.%d", &b1, &b2, &b3, &b4);
@@ -579,7 +599,7 @@
       return ASN_E_BUFOVFLW;
    sprintf (pbuf, "%s.%s.%s.%s", buf1, buf2, buf3, buf4);
    return ASN_OK;
-}
+} */
 
 int ooSocketsCleanup (void)
 {

Modified: team/may/ooh323_ipv6/addons/ooh323c/src/ooSocket.h
URL: http://svnview.digium.com/svn/asterisk/team/may/ooh323_ipv6/addons/ooh323c/src/ooSocket.h?view=diff&rev=292409&r1=292408&r2=292409
==============================================================================
--- team/may/ooh323_ipv6/addons/ooh323c/src/ooSocket.h (original)
+++ team/may/ooh323_ipv6/addons/ooh323c/src/ooSocket.h Wed Oct 20 16:24:29 2010
@@ -81,7 +81,8 @@
  * address. The least significant 8 bits represent the last number of the IP
  * address.
  */
-typedef unsigned long OOIPADDR;
+/* typedef unsigned long OOIPADDR; */
+typedef struct ast_sockaddr OOIPADDR;
 
 #define OOIPADDR_ANY   ((OOIPADDR)0)
 #define OOIPADDR_LOCAL ((OOIPADDR)0x7f000001UL) /* 127.0.0.1 */
@@ -351,7 +352,7 @@
  * @return             Completion status of operation: 0 (ASN_OK) = success,
  *                     negative return value is error.
  */
-EXTERN int ooSocketStrToAddr (const char* pIPAddrStr, OOIPADDR* pIPAddr);
+/* EXTERN int ooSocketStrToAddr (const char* pIPAddrStr, OOIPADDR* pIPAddr); */
 
 /**
  * This function converts an internet dotted ip address to network address
@@ -364,7 +365,7 @@
  * @return             Completion status of operation: 0 (ASN_OK) = success,
  *                     negative return value is error.
  */
-EXTERN int ooSocketConvertIpToNwAddr(char *inetIp, unsigned char *netIp);
+/* EXTERN int ooSocketConvertIpToNwAddr(char *inetIp, unsigned char *netIp); */
 
 /**
  * This function retrives the IP address of the local host.

Modified: team/may/ooh323_ipv6/addons/ooh323c/src/oochannels.c
URL: http://svnview.digium.com/svn/asterisk/team/may/ooh323_ipv6/addons/ooh323c/src/oochannels.c?view=diff&rev=292409&r1=292408&r2=292409
==============================================================================
--- team/may/ooh323_ipv6/addons/ooh323c/src/oochannels.c (original)
+++ team/may/ooh323_ipv6/addons/ooh323c/src/oochannels.c Wed Oct 20 16:24:29 2010
@@ -16,6 +16,8 @@
 #include "asterisk.h"
 #include "asterisk/lock.h"
 #include "asterisk/poll-compat.h"
+#include "asterisk/config.h"
+#include "asterisk/netsock2.h"
 
 #include "ooports.h" 
 #include "oochannels.h"
@@ -31,6 +33,7 @@
 #include "ooh323ep.h"
 #include "ooStackCmds.h"
 #include "ooCmdChannel.h"
+#include "ooSocket.h"
 #include "ootypes.h"
 
 
@@ -379,7 +382,7 @@
       OOTRACEERR1("Failed to create socket for H323 Listener\n");
       return OO_FAILED;
    }
-   ret= ooSocketStrToAddr (gH323ep.signallingIP, &ipaddrs);
+   ret = ast_parse_arg(gH323ep.signallingIP, PARSE_ADDR, &ipaddrs);
    if((ret=ooSocketBind (channelSocket, ipaddrs, 
                          gH323ep.listenPort))==ASN_OK) 
    {

Modified: team/may/ooh323_ipv6/addons/ooh323c/src/ooh323ep.c
URL: http://svnview.digium.com/svn/asterisk/team/may/ooh323_ipv6/addons/ooh323c/src/ooh323ep.c?view=diff&rev=292409&r1=292408&r2=292409
==============================================================================
--- team/may/ooh323_ipv6/addons/ooh323c/src/ooh323ep.c (original)
+++ team/may/ooh323_ipv6/addons/ooh323c/src/ooh323ep.c Wed Oct 20 16:24:29 2010
@@ -157,7 +157,7 @@
 
 
 
-int ooH323EpSetLocalAddress(const char* localip, int listenport)
+int ooH323EpSetLocalAddress(const char* localip, int listenport, int mode)
 {
    if(localip)
    {
@@ -169,6 +169,9 @@
    {
       gH323ep.listenPort = listenport;
       OOTRACEINFO2("Listen port number is set to %d\n", listenport);
+   }
+   if (mode == 1) {
+	gH323ep.v6Mode = OO_TRUE;
    }
    return OO_OK;
 }

Modified: team/may/ooh323_ipv6/addons/ooh323c/src/ooh323ep.h
URL: http://svnview.digium.com/svn/asterisk/team/may/ooh323_ipv6/addons/ooh323c/src/ooh323ep.h?view=diff&rev=292409&r1=292408&r2=292409
==============================================================================
--- team/may/ooh323_ipv6/addons/ooh323c/src/ooh323ep.h (original)
+++ team/may/ooh323_ipv6/addons/ooh323c/src/ooh323ep.h Wed Oct 20 16:24:29 2010
@@ -130,7 +130,7 @@
    int noOfCaps;
    OOH225MsgCallbacks h225Callbacks;
    OOH323CALLBACKS h323Callbacks;
-   char signallingIP[20];
+   char signallingIP[2+8*4+7];
    int listenPort;
    OOSOCKET *listener;
    OOH323CallData *callList;
@@ -148,6 +148,7 @@
    OOInterface *ifList; /* interface list for the host we are running on*/
    OOBOOL isGateway;
    OOSOCKET cmdSock;
+   OOBOOL v6Mode;
 } OOH323EndPoint;
 
 #define ooEndPoint OOH323EndPoint

Modified: team/may/ooh323_ipv6/addons/ooh323c/src/ooports.c
URL: http://svnview.digium.com/svn/asterisk/team/may/ooh323_ipv6/addons/ooh323c/src/ooports.c?view=diff&rev=292409&r1=292408&r2=292409
==============================================================================
--- team/may/ooh323_ipv6/addons/ooh323c/src/ooports.c (original)
+++ team/may/ooh323_ipv6/addons/ooh323c/src/ooports.c Wed Oct 20 16:24:29 2010
@@ -16,6 +16,8 @@
 
 #include "asterisk.h"
 #include "asterisk/lock.h"
+#include "asterisk/netsock2.h"
+#include "asterisk/config.h"
 
 #include "ooports.h"
 #include "ooh323ep.h"
@@ -71,7 +73,7 @@
    initialPort = ooGetNextPort (type);
    bindPort = initialPort;
 
-   ret= ooSocketStrToAddr (ip, &ipAddrs);
+   ret=ast_parse_arg(ip, PARSE_ADDR, &ipAddrs);
 
    while(1)
    {

Modified: team/may/ooh323_ipv6/addons/ooh323c/src/ootypes.h
URL: http://svnview.digium.com/svn/asterisk/team/may/ooh323_ipv6/addons/ooh323c/src/ootypes.h?view=diff&rev=292409&r1=292408&r2=292409
==============================================================================
--- team/may/ooh323_ipv6/addons/ooh323c/src/ootypes.h (original)
+++ team/may/ooh323_ipv6/addons/ooh323c/src/ootypes.h Wed Oct 20 16:24:29 2010
@@ -143,7 +143,7 @@
 #define OOTERMTYPE 60
 
 /** Maximum length of an IP address (xxx.xxx.xxx.xxx). */
-#define MAX_IP_LENGTH 15
+#define MAX_IP_LENGTH 2+8*4+7
 
 /** Maximum length of a log file message */
 #define MAXLOGMSGLEN 2048




More information about the asterisk-commits mailing list