aboutsummaryrefslogtreecommitdiffstats
path: root/sualibrary/sua/sua_dataname.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'sualibrary/sua/sua_dataname.cpp')
-rw-r--r--sualibrary/sua/sua_dataname.cpp178
1 files changed, 157 insertions, 21 deletions
diff --git a/sualibrary/sua/sua_dataname.cpp b/sualibrary/sua/sua_dataname.cpp
index f71a1ee..2b9d401 100644
--- a/sualibrary/sua/sua_dataname.cpp
+++ b/sualibrary/sua/sua_dataname.cpp
@@ -15,7 +15,7 @@
* *
***************************************************************************/
/*
- * $Id: sua_dataname.cpp,v 1.2 2002/03/01 12:57:38 p82609 Exp $
+ * $Id: sua_dataname.cpp,v 1.6 2002/11/12 11:04:12 p82609 Exp $
*
* SUA implementation according to SUA draft issue 6.
*
@@ -53,7 +53,10 @@
* - initialise Name
* SUA Name List:
* - initialise Name List
- * - read hostname
+ * - read hostname
+ * - read global title
+ * - resolve hostname
+ * - perform Global Title Translation
*/
#include "sctp.h"
@@ -62,6 +65,7 @@
#include "sua_database.h"
#include "sua_asp_mgnt.h"
#include "sua_logging.h"
+#include "sua_adapt.h"
#include <cstdio>
#include <iostream>
@@ -84,7 +88,15 @@ using namespace std;
void db_Sua_NameObject::initialize(){
// initialise to point to a invalid SUA association
- SUA_assoc_id = 0;
+ SUA_assoc_id = 0;
+ sctp_assoc_id = 0;
+ GT.Translation_Type = 0;
+ GT.Numbering_Plan = 0;
+ GT.Nature_of_Address = 0;
+ /* initialise to empty string */
+ GT.digits="";
+ hostname = "";
+
}
@@ -107,7 +119,9 @@ void db_Sua_NameList::initialize(){
/***********************************************************************/
/* Sua_NameList::read_host_name */
/***********************************************************************/
-string db_Sua_NameList::read_host_name(string name){
+string db_Sua_NameList::read_host_name( unsigned int sua_assoc_id,
+ string name
+ ){
char *hostname;
const char *ip_addr_ptr;
@@ -129,7 +143,7 @@ string db_Sua_NameList::read_host_name(string name){
#ifdef DEBUG
cout << "Hostname " << hptr->h_name << " has the following IP address(es)\n";
#endif
-
+
pptr = hptr->h_addr_list;
for ( ; *pptr != NULL;pptr++)
{
@@ -143,30 +157,152 @@ string db_Sua_NameList::read_host_name(string name){
cout << ip_addr_ptr << "\n";
#endif
}
-
+
#ifdef DEBUG
cout << "output IP list = " << addr_str << "\n";
#endif
-
- string name_str;
- int last= name.size();
- unsigned int current = name.rfind('.');
- while(current != string::npos){
- name_str = name_str + name.substr(current+1,(last-current)) + ".";
- last= current - 1;
- current = name.rfind('.', last);
- }
- name_str = name_str + name.substr(0,last+1);
+
+ instance[num_of_instance].SUA_assoc_id = sua_assoc_id;
+
+ instance[num_of_instance].hostname = name;
+
+ return(addr_str);
+
+}
+/***********************************************************************/
+/* Sua_NameList::read_Global_Title */
+/***********************************************************************/
+void db_Sua_NameList::read_Global_Title( unsigned int sua_assoc_id,
+ string gt
+ )
+{
+ string GT_TT_str, GT_NP_str, GT_NA_str, GT_Digits_str;
+ unsigned int first = 0, last = 0;
+ unsigned int current = gt.find('-', first);
+
+ first = 1;
+ last = current - 1;
+ GT_TT_str = gt.substr( first, last);
+
+ first = current + 1;
+ current = gt.find('-', first);
+ last = current - 1;
+ GT_NP_str = gt.substr( first , last);
+
+ first = current + 1;
+ current = gt.find('-', first);
+ last = current - 1;
+ GT_NA_str = gt.substr( first , last);
+
+ first = current + 1;
+ last = gt.size();
+ GT_Digits_str = gt.substr( first , last);
+
+ instance[num_of_instance].SUA_assoc_id = sua_assoc_id;
+
+ instance[num_of_instance].GT.Translation_Type = atoi(GT_TT_str.c_str());
+ instance[num_of_instance].GT.Numbering_Plan = atoi(GT_NP_str.c_str());
+ instance[num_of_instance].GT.Nature_of_Address = atoi(GT_NA_str.c_str());
+ instance[num_of_instance].GT.digits = GT_Digits_str;
+
+}
+
+/***********************************************************************/
+/* db_Sua_NameList::resolve_host_name */
+/***********************************************************************/
+signed int db_Sua_NameList::resolve_host_name ( hostname_str& dest_name,
+ pointcode_str& dest_pc
+ )
+{
+ struct hostent *hptr;
+ char **pptr;
+ char str[INET6_ADDRSTRLEN];
+ char *dest_carr;
+
+ /* resolving can be done via: */
+ /* - local global Titel database */
+ /* - resolve hostname via DNS(simplest for single hop translations) */
+ dest_carr = dest_name;
+
+ if ((hptr = gethostbyname( dest_carr )) == NULL)
+ {
+ cout << "Hostname " << dest_name << " not known in DNS.\n";
+ return(-1);
+ }
+
#ifdef DEBUG
- cout << "Ready for storing SUA dest hostname = " << name_str << " in NameDB\n";
+ cout << "Hostname " << dest_name << " resolved to dest IP address(es)\n";
+ cout << "IP address length = "<< hptr->h_length << "\n";
#endif
-
-
- return(addr_str);
+
+ /* initialise the length field of the structure: */
+ /* length field is NOT always present in every Unix like operating system */
+ dest_pc.ipvx.ch[0] = 0;
+
+ pptr = hptr->h_addr_list;
+ for ( ; (*pptr != NULL) ;pptr++)
+ {
+ inet_ntop(hptr->h_addrtype, *pptr, str,sizeof(str));
+#ifdef DEBUG
+ cout << str << "\n";
+#endif
+ /* got a IP address */
+ dest_pc.ipvx.sa.sa_family = hptr->h_addrtype;
+ if (dest_pc.ipvx.sa.sa_family == AF_INET)
+ inet_pton( AF_INET,
+ str,
+ &dest_pc.ipvx.sin.sin_addr
+ );
+ else if (dest_pc.ipvx.sa.sa_family == AF_INET6)
+ inet_pton( AF_INET6,
+ str,
+ &dest_pc.ipvx.sin6.sin6_addr
+ );
+ else
+ {
+ cout << "ERROR resolve_host_name: Unknown IP addresstype\n";
+ return(-2);
+ }
+ }
+ return(0);
+};
-}
+/***********************************************************************/
+/* db_Sua_NameList::resolve_GT */
+/***********************************************************************/
+signed int db_Sua_NameList::perform_GTT ( global_title_str& cld_in,
+ global_title_str& clg_in,
+ global_title_str& cld_out,
+ global_title_str& clg_out,
+ pointcode_str& dest_pc
+ )
+{
+ boolean search_gt = true, gt_entry_found = false;
+ int i, found_gt_entry;
+
+ /* resolving can be done via: */
+ /* - local global Titel database */
+ i= 0;
+ while (search_gt){
+ gt_entry_found = ((instance[i].GT.Translation_Type == cld_in.Translation_Type) &&
+ (instance[i].GT.Numbering_Plan == cld_in.Numbering_Plan) &&
+ (instance[i].GT.Nature_of_Address == cld_in.Nature_of_Address) &&
+ (instance[i].GT.digits == cld_in.digits));
+
+ found_gt_entry = i;
+ /* next entry of name table */
+ i++;
+ }
+ if (gt_entry_found) {
+ /* get the association number from gt database */
+ dest_pc = get_destpc_addr(instance[found_gt_entry].SUA_assoc_id);
+ return(0);
+ }
+ else
+ return(-1);
+};
// end of module sua_dataname.c