Update of /usr/cvsroot/asterisk-addons/asterisk-ooh323c/ooh323c/src
In directory mongoose.digium.com:/tmp/cvs-serv30162/src
Modified Files:
ooGkClient.c ooSocket.c ooSocket.h oochannels.c ooh323ep.c
ooh323ep.h ooports.c ooports.h ooq931.c
Log Message:
Updated stack source
Index: ooGkClient.c
===================================================================
RCS file:
/usr/cvsroot/asterisk-addons/asterisk-ooh323c/ooh323c/src/ooGkClient.c,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -d -r1.2 -r1.3
--- ooGkClient.c 16 Jun 2005 19:41:23 -0000 1.2
+++ ooGkClient.c 24 Jun 2005 21:01:49 -0000 1.3
@@ -46,6 +46,7 @@
char *szGkAddr, int iGkPort )
{
ooGkClient *pGkClient=NULL;
+ OOInterface *cur=NULL;
pGkClient = (ooGkClient*)
memAlloc(&gH323ep.ctxt, sizeof(ooGkClient));
if(!pGkClient)
@@ -62,7 +63,34 @@
pGkClient->grqRetries = 0;
strcpy(pGkClient->localRASIP, gH323ep.signallingIP);
-
+#ifndef _WIN32
+ if(!strcmp(pGkClient->localRASIP, "0.0.0.0") ||
+ !strcmp(pGkClient->localRASIP, "127.0.0.1"))
+ {
+ if(!gH323ep.ifList)
+ {
+ if(ooSocketGetInterfaceList(&gH323ep.ctxt, &gH323ep.ifList)!= ASN_OK)
+ {
+ OOTRACEERR1("Error:Failed to retrieve interface addresses\n");
+ return OO_FAILED;
+ }
+ }
+ for(cur = gH323ep.ifList; cur; cur = cur->next)
+ {
+ if(!strcmp(cur->name, "lo") || !strcmp(cur->addr, "127.0.0.1"))
+ continue;
+ break;
+ }
+ if(cur)
+ {
+ OOTRACEINFO2("Using local RAS Ip address %s\n", cur->addr);
+ strcpy(pGkClient->localRASIP, cur->addr);
+ }else{
+ OOTRACEERR1("Error:Failed to assign a local RAS IP address\n");
+ return OO_FAILED;
+ }
+ }
+#endif
if(OO_OK != ooGkClientSetGkMode(pGkClient, eGkMode, szGkAddr, iGkPort))
{
OOTRACEERR1("Error:Failed to set Gk mode\n");
@@ -236,7 +264,7 @@
}
}
else {
- ret = ooBindPort (OOUDP, pGkClient->rasSocket);
+ ret = ooBindPort (OOUDP, pGkClient->rasSocket, pGkClient->localRASIP);
if(ret == OO_FAILED)
{
OOTRACEERR1("ERROR: Failed to bind port to RAS socket\n");
Index: ooSocket.c
===================================================================
RCS file: /usr/cvsroot/asterisk-addons/asterisk-ooh323c/ooh323c/src/ooSocket.c,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -d -r1.3 -r1.4
--- ooSocket.c 16 Jun 2005 19:41:23 -0000 1.3
+++ ooSocket.c 24 Jun 2005 21:01:49 -0000 1.4
@@ -37,6 +37,7 @@
static LPFN_SHUTDOWN shutdown;
+static LPFN_IOCTLSOCKET ioctlsocket;
static LPFN_SENDTO sendto;
static LPFN_INET_NTOA inet_ntoa;
static LPFN_RECVFROM recvfrom;
@@ -56,6 +57,8 @@
#define closesocket close
#endif
+
+
int ooSocketsInit ()
{
#if defined(_WIN32_WCE)
@@ -136,6 +139,9 @@
getsockname = (LPFN_GETSOCKNAME) GetProcAddress (ws32, "getsockname");
if (getsockname == NULL) return ASN_E_NOTINIT;
+ ioctlsocket = (LPFN_IOCTLSOCKET) GetProcAddress(ws32, "ioctlsocket");
+ if(ioctlsocket == NULL) return ASN_E_NOTINIT;
+
sendto = (LPFN_SENDTO) GetProcAddress (ws32, "sendto");
if (sendto == NULL) return ASN_E_NOTINIT;
@@ -561,3 +567,153 @@
{
return htons(val);
}
+
+#ifndef _WIN32
+int ooSocketGetInterfaceList(OOCTXT *pctxt, OOInterface **ifList)
+{
+ OOSOCKET sock;
+ struct ifconf ifc;
+ int ifNum;
+ OOInterface *pIf=NULL;
+
+ OOTRACEDBGA1("Retrieving local interfaces\n");
+ if(ooSocketCreateUDP(&sock)!= ASN_OK)
+ {
+ OOTRACEERR1("Error:Failed to create udp socket - "
+ "ooSocketGetInterfaceList\n");
+ return -1;
+ }
+#ifdef SIOCGIFNUM
+ if(ioctl(sock, SIOCGIFNUM, &ifNum) >= 0)
+ {
+ OOTRACEERR1("Error: ioctl for ifNum failed\n");
+ return -1;
+ }
+#else
+ ifNum = 50;
+#endif
+
+ ifc.ifc_len = ifNum * sizeof(struct ifreq);
+ ifc.ifc_req = (struct ifreq *)memAlloc(pctxt, ifNum *sizeof(struct ifreq));
+ if(!ifc.ifc_req)
+ {
+ OOTRACEERR1("Error:Memory - ooSocketGetInterfaceList - ifc.ifc_req\n");
+ return -1;
+ }
+
+ if (ioctl(sock, SIOCGIFCONF, &ifc) >= 0) {
+ void * ifEndList = (char *)ifc.ifc_req + ifc.ifc_len;
+ struct ifreq *ifName;
+ struct ifreq ifReq;
+ int flags;
+ for (ifName = ifc.ifc_req; (void*)ifName < ifEndList; ifName++) {
+ char *pName=NULL;
+ char addr[50], mask[50];
+
+ pIf = (struct OOInterface*)memAlloc(pctxt, sizeof(struct
OOInterface));
+ pName = (char*)memAlloc(pctxt, strlen(ifName->ifr_name)+1);
+ if(!pIf)
+ {
+ OOTRACEERR1("Error:Memory - ooSocketGetInterfaceList - "
+ "pIf/pName\n");
+ return -1;
+ }
+ OOTRACEDBGA2("\tInterface name: %s\n", ifName->ifr_name);
+
+
+ strcpy(ifReq.ifr_name, ifName->ifr_name);
+ strcpy(pName, ifName->ifr_name);
+ pIf->name = pName;
+
+ /* Check whether the interface is up*/
+ if (ioctl(sock, SIOCGIFFLAGS, &ifReq) < 0) {
+ OOTRACEERR2("Error:Unable to determine status of interface %s\n",
+ pName);
+ memFreePtr(pctxt, pIf->name);
+ memFreePtr(pctxt, pIf);
+ continue;
+ }
+ flags = ifReq.ifr_flags;
+ if (!(flags & IFF_UP)) {
+ OOTRACEWARN2("Warn:Interface %s is not up\n", pName);
+ memFreePtr(pctxt, pIf->name);
+ memFreePtr(pctxt, pIf);
+ continue;
+ }
+
+ /* Retrieve interface address */
+ if (ioctl(sock, SIOCGIFADDR, &ifReq) < 0)
+ {
+ OOTRACEWARN2("Warn:Unable to determine address of interface %s\n",
+ pName);
+ memFreePtr(pctxt, pIf->name);
+ memFreePtr(pctxt, pIf);
+ continue;
+ }
+ strcpy(addr, inet_ntoa(((struct
sockaddr_in*)&ifReq.ifr_addr)->sin_addr));
+ OOTRACEDBGA2("\tIP address is %s\n", addr);
+ pIf->addr = (char*)memAlloc(pctxt, strlen(addr)+1);
+ if(!pIf->addr)
+ {
+ OOTRACEERR1("Error:Memory - ooSocketGetInterfaceList - "
+ "pIf->addr\n");
+ memFreePtr(pctxt, pIf->name);
+ memFreePtr(pctxt, pIf);
+ return -1;
+ }
+ strcpy(pIf->addr, addr);
+
+
+ if (ioctl(sock, SIOCGIFNETMASK, &ifReq) < 0)
+ {
+ OOTRACEWARN2("Warn:Unable to determine mask for interface %s\n",
+ pName);
+ memFreePtr(pctxt, pIf->name);
+ memFreePtr(pctxt, pIf->addr);
+ memFreePtr(pctxt, pIf);
+ continue;
+ }
+ strcpy(mask, inet_ntoa(((struct sockaddr_in
*)&ifReq.ifr_netmask)->sin_addr));
+ OOTRACEDBGA2("\tMask is %s\n", mask);
+ pIf->mask = (char*)memAlloc(pctxt, strlen(mask)+1);
+ if(!pIf->mask)
+ {
+ OOTRACEERR1("Error:Memory - ooSocketGetInterfaceList - "
+ "pIf->mask\n");
+ memFreePtr(pctxt, pIf->name);
+ memFreePtr(pctxt, pIf->addr);
+ memFreePtr(pctxt, pIf);
+ return -1;
+ }
+ strcpy(pIf->mask, mask);
+
+ pIf->next = NULL;
+
+ /* Add to the list */
+ if(!*ifList)
+ {
+ *ifList = pIf;
+ pIf = NULL;
+ }else{
+ pIf->next = *ifList;
+ *ifList = pIf;
+ pIf=NULL;
+ }
+/*
+#if defined(OO_FREEBSD) || defined(OO_OPENBSD) || defined(OO_NETBSD) ||
defined(OO_MACOSX) || defined(OO_VXWORKS) || defined(OO_RTEMS) ||
defined(OO_QNX)
+#ifndef _SIZEOF_ADDR_IFREQ
+#define _SIZEOF_ADDR_IFREQ(ifr) \
+ ((ifr).ifr_addr.sa_len > sizeof(struct sockaddr) ? \
+ (sizeof(struct ifreq) - sizeof(struct sockaddr) + \
+ (ifr).ifr_addr.sa_len) : sizeof(struct ifreq))
+#endif
+ ifName = (struct ifreq *)((char *)ifName + _SIZEOF_ADDR_IFREQ(*ifName));
+#else
+ ifName++;
+*/
+ }
+
+ }
+ return ASN_OK;
+}
+#endif
Index: ooSocket.h
===================================================================
RCS file: /usr/cvsroot/asterisk-addons/asterisk-ooh323c/ooh323c/src/ooSocket.h,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -d -r1.3 -r1.4
--- ooSocket.h 16 Jun 2005 19:41:23 -0000 1.3
+++ ooSocket.h 24 Jun 2005 21:01:49 -0000 1.4
@@ -33,10 +33,12 @@
#include <sys/types.h>
#include "sys/time.h"
#include <sys/socket.h>
+#include <sys/ioctl.h>
#include <netinet/in.h>
#include <netdb.h>
#include <unistd.h>
#include <arpa/inet.h>
+#include <net/if.h>
#endif
#include "ooasn1.h"
@@ -81,6 +83,14 @@
#define OOIPADDR_ANY ((OOIPADDR)0)
#define OOIPADDR_LOCAL ((OOIPADDR)0x7f000001UL) /* 127.0.0.1 */
+typedef struct OOInterface{
+ char *name;
+ char *addr;
+ char *mask;
+ struct OOInterface *next;
+}OOInterface;
+
+
/**
* This function permits an incoming connection attempt on a socket. It
@@ -379,6 +389,9 @@
* @return ASN_OK, on success; -ve on failed.
*/
EXTERN int ooSocketGetIpAndPort(OOSOCKET socket, char *ip, int len, int *port);
+
+
+EXTERN int ooSocketGetInterfaceList(OOCTXT *pctxt, OOInterface **ifList);
/**
* @}
*/
Index: oochannels.c
===================================================================
RCS file:
/usr/cvsroot/asterisk-addons/asterisk-ooh323c/ooh323c/src/oochannels.c,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -d -r1.5 -r1.6
--- oochannels.c 16 Jun 2005 19:41:23 -0000 1.5
+++ oochannels.c 24 Jun 2005 21:01:49 -0000 1.6
@@ -48,7 +48,7 @@
"(%s, %s)\n", call->callType, call->callToken);
return OO_FAILED;
}
- ret = ooBindPort (OOTCP, channelSocket);
+ ret = ooBindPort (OOTCP, channelSocket, call->localIP);
if(ret == OO_FAILED)
{
OOTRACEERR3("Error:Unable to bind to a TCP port - H245 listener creation"
@@ -96,7 +96,7 @@
bind socket to a port before connecting. Thus avoiding
implicit bind done by a connect call.
*/
- ret = ooBindPort(OOTCP, channelSocket);
+ ret = ooBindPort(OOTCP, channelSocket, call->localIP);
if(ret == OO_FAILED)
{
OOTRACEERR3("Error:Unable to bind to a TCP port - h245 connection "
@@ -250,9 +250,9 @@
to any random port.
*/
#ifndef _WIN32
- ret = ooBindPort(OOTCP,channelSocket);
+ ret = ooBindPort(OOTCP,channelSocket, call->localIP);
#else
- ret = ooBindOSAllocatedPort(channelSocket);
+ ret = ooBindOSAllocatedPort(channelSocket, call->localIP);
#endif
if(ret == OO_FAILED)
Index: ooh323ep.c
===================================================================
RCS file: /usr/cvsroot/asterisk-addons/asterisk-ooh323c/ooh323c/src/ooh323ep.c,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -d -r1.3 -r1.4
--- ooh323ep.c 3 Jun 2005 14:54:06 -0000 1.3
+++ ooh323ep.c 24 Jun 2005 21:01:49 -0000 1.4
@@ -143,6 +143,7 @@
gH323ep.logicalChannelTimeout = DEFAULT_LOGICALCHAN_TIMEOUT;
gH323ep.sessionTimeout = DEFAULT_ENDSESSION_TIMEOUT;
+ gH323ep.ifList = NULL;
#ifdef HAVE_PIPE
if(pipe(gH323ep.cmdPipe)<0){
OOTRACEERR1("Error:Failed to create command pipe\n");
Index: ooh323ep.h
===================================================================
RCS file: /usr/cvsroot/asterisk-addons/asterisk-ooh323c/ooh323c/src/ooh323ep.h,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -d -r1.4 -r1.5
--- ooh323ep.h 16 Jun 2005 19:41:23 -0000 1.4
+++ ooh323ep.h 24 Jun 2005 21:01:49 -0000 1.5
@@ -141,6 +141,7 @@
int cmdPipe[2];
struct ooGkClient *gkClient;
DList stkCmdList; /* stack command list */
+ OOInterface *ifList; /* interface list for the host we are running on*/
} OOH323EndPoint;
#define ooEndPoint OOH323EndPoint
Index: ooports.c
===================================================================
RCS file: /usr/cvsroot/asterisk-addons/asterisk-ooh323c/ooh323c/src/ooports.c,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -d -r1.3 -r1.4
--- ooports.c 16 Jun 2005 19:41:23 -0000 1.3
+++ ooports.c 24 Jun 2005 21:01:49 -0000 1.4
@@ -58,7 +58,7 @@
return OO_FAILED;
}
-int ooBindPort (OOH323PortType type, OOSOCKET socket)
+int ooBindPort (OOH323PortType type, OOSOCKET socket, char *ip)
{
int initialPort, bindPort, ret;
OOIPADDR ipAddrs;
@@ -66,7 +66,7 @@
initialPort = ooGetNextPort (type);
bindPort = initialPort;
- ret= ooSocketStrToAddr (gH323ep.signallingIP, &ipAddrs);
+ ret= ooSocketStrToAddr (ip, &ipAddrs);
while(1)
{
@@ -83,13 +83,13 @@
}
#ifdef _WIN32
-int ooBindOSAllocatedPort(OOSOCKET socket)
+int ooBindOSAllocatedPort(OOSOCKET socket, char *ip)
{
OOIPADDR ipAddrs;
int size, ret;
struct sockaddr_in name;
size = sizeof(struct sockaddr_in);
- ret= ooSocketStrToAddr (gH323ep.signallingIP, &ipAddrs);
+ ret= ooSocketStrToAddr (ip, &ipAddrs);
if((ret=ooSocketBind(socket, ipAddrs,
0))==ASN_OK)
{
Index: ooports.h
===================================================================
RCS file: /usr/cvsroot/asterisk-addons/asterisk-ooh323c/ooh323c/src/ooports.h,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -d -r1.3 -r1.4
--- ooports.h 16 Jun 2005 19:41:23 -0000 1.3
+++ ooports.h 24 Jun 2005 21:01:49 -0000 1.4
@@ -60,22 +60,28 @@
* @param ep Reference to H323 Endpoint structure.
* @param type Type of the port required for the socket.
* @param socket The socket to be bound.
+ * @param ip Dotted Ip address to bind to.
*
* @return In case of success returns the port number to which
* socket is bound and in case of failure just returns
* a negative value.
*/
-EXTERN int ooBindPort (OOH323PortType type, OOSOCKET socket);
+EXTERN int ooBindPort (OOH323PortType type, OOSOCKET socket, char *ip);
/**
* This function is supported for windows version only.
* Windows sockets have problem in reusing the addresses even after
* setting SO_REUSEADDR, hence in windows we just allow os to bind
* to any random port.
-*/
-
+ * @param socket Socket to be bound.
+ * @param ip Dotted ip address to bind to.
+ *
+ * @return In case of success returns the port number to which
+ * socket is bound and in case of failure just returns
+ * a negative value.
+ */
#ifdef _WIN32
-EXTERN int ooBindOSAllocatedPort(OOSOCKET socket);
+EXTERN int ooBindOSAllocatedPort(OOSOCKET socket, char *ip);
#endif
#ifdef __cplusplus
Index: ooq931.c
===================================================================
RCS file: /usr/cvsroot/asterisk-addons/asterisk-ooh323c/ooh323c/src/ooq931.c,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -d -r1.5 -r1.6
--- ooq931.c 23 Jun 2005 14:50:15 -0000 1.5
+++ ooq931.c 24 Jun 2005 21:01:49 -0000 1.6
@@ -1590,14 +1590,13 @@
ret=ooSendH225Msg(call, q931msg);
if(ret != OO_OK)
{
- OOTRACEERR3("Error:Failed to enqueue Connect message to outbound queue."
- "(%s, %s)\n", call->callType, call->callToken);
+ OOTRACEERR3("Error:Failed to enqueue Connect message to outbound
queue.(%s, %s)\n", call->callType, call->callToken);
memReset(&gH323ep.msgctxt);
return OO_FAILED;
}
memReset(&gH323ep.msgctxt);
-
+#if 0
if (OO_TESTFLAG (call->flags, OO_M_TUNNELING))
{
/* Start terminal capability exchange and master slave determination */
@@ -1616,7 +1615,7 @@
return ret;
}
}
-
+#endif
return OO_OK;
}
_______________________________________________
Asterisk-Cvs mailing list
[email protected]
http://lists.digium.com/mailman/listinfo/asterisk-cvs