]> git.mxchange.org Git - flightgear.git/blobdiff - src/NetworkOLK/net_send.cxx
Updates to the scenery loading infrastructure to make it more flexible,
[flightgear.git] / src / NetworkOLK / net_send.cxx
index d6e2ca296748311bbe92c59a7e75791ef993d906..2465d843ccdd069a40e205bae2cc898ca7fc1d02 100644 (file)
@@ -1,11 +1,10 @@
 /*************************************************************/
-/* FGD_MCP.C by Oliver Delise                                */
+/* NET_SEND.CXX by Oliver Delise                             */
 /* Contact info:                                             */
 /* e-mail: delise@mail.isis.de                               */
-/* www: http://www.isis.de/members/~odelise/progs/mmx-emu/   */
-/* ftp: http://www.isis.de/members/~odelise/progs/flightgear */
+/* www: http://www.isis.de/members/odelise/progs/flightgear  */
 /*                                                           */
-/* Version 0.1-alpha                                         */
+/* Version 0.1-beta                                          */
 /* The author of this program offers no waranty at all       */
 /* about the correct execution of this software material.    */
 /* Furthermore, the author can NOT be held responsible for   */
 /*                                                           */
 /*    History: v0.1pre-alpha: May 25 1999 -> First release   */
 /*             v0.1-alpha     Nov 11 1999                    */
+/*             v0.1-beta      Jan 16 2000 -> libc5, glibc2.0 */
+/*                            glibc-2.1 issues fixed         */
 /*************************************************************/
 
 #include <stdio.h>
+#include <strings.h>
 #include "fgd.h"
 
 /* I prefer NHV's decl. */
+#include <simgear/constants.h>
+
 #include <Cockpit/hud.hxx>
-#include <Include/fg_constants.h>
-#include <ssg.h>
-#include <Main/views.hxx>
+#include <plib/ssg.h>
+#include <Main/globals.hxx>
+#include <Main/viewmgr.hxx>
 
 //#define printf //
 
-
 /* Netstuff */
 #include <arpa/inet.h>
 int sock = -1;
@@ -49,15 +52,33 @@ int my_sock;
 struct sockaddr_in address;
 struct sockaddr_in my_address;
 int result;
-extern const char *const sys_errlist[];
-extern int errno;
+
+//#if defined( __CYGWIN__ )
+#include <errno.h>
+//const char *const *sys_errlist = _sys_errlist;
+//#else
+//extern int errno;
+//extern const char *const sys_errlist[];
+//#endif
+
+//#if defined( __CYGWIN__ )
+//#include <errno.h>
+//#else
+//extern int errno;
+//#endif
+
+//extern const char *const sys_errlist[];
+
+/* -dlw- I fixed a few of the cases, but please make non externally used */
+/*  symbols static to avoid possible linker conflicts */
 int current_port  = 10000; 
 u_short base_port = 10000;
 u_short end_port  = 10010;
-int verbose = 0;
-struct hostent *host_info, *f_host_info;
-struct servent *service_info;
-struct utsname myname;
+
+static int verbose = 0;
+static struct hostent *host_info, *f_host_info;
+static struct servent *service_info;
+static struct utsname myname;
 
 /* Program-stuff */
 int i, j;
@@ -73,8 +94,8 @@ extern char *FGFS_host, *net_callsign;
 
 /* List-stuff */
 
-const int True  = 0;
-const int False= -1;
+const int listTrue  = 0;
+const int listFalse= -1;
 
 struct list_ele {
    /* unsigned */ char ipadr[16], callsign[16];
@@ -181,17 +202,17 @@ struct list_ele *clr_ele;
 
 int list_not_in( char name[16]) {
    
-   i = True;
+   i = listTrue;
    test = head->next;
-   while ((test != tail) && (i==True)) {
-     i = (strcmp(test->ipadr, name) ? True : False);
+   while ((test != tail) && (i==listTrue)) {
+     i = (strcmp(test->ipadr, name) ? listTrue : listFalse);
      test = test->next;
      if (verbose != 0) printf("list_not_in : %d\n",i);
    }
-   return(i);
+   return i;
 }
 
-void fgd_print_Mat4( sgMat4 m ) {
+void fgd_print_Mat4( const sgMat4 m ) {
     printf("0.0 %f 0.1 %f 0.2 %f 0.3 %f\n", 
     m[0][0], m[0][1], m[0][2], m[0][3] );
     printf("1.0 %f 1.1 %f 1.2 %f 1.3 %f\n", 
@@ -238,7 +259,7 @@ void fgd_init(void){
 /* determinating the source/sending host */
    if (uname(&myname) == 0) strcpy(src_host , myname.nodename);   
    printf("MCP: I'm running on HOST : %s  ", src_host);
-   if (host_info = gethostbyname( src_host)) {
+   if ( (host_info = gethostbyname( src_host)) != NULL ) {
      bcopy(host_info->h_addr, (char *)&address.sin_addr,host_info->h_length);
      strcpy((char *) fgd_mcp_ip, (char *) inet_ntoa(address.sin_addr));
      }
@@ -246,7 +267,7 @@ void fgd_init(void){
    FGFS_host = src_host;
 /* resolving the destination host, here fgd's host */   
    if (verbose == 2) printf("     Resolving default DEAMON: %s ->", fgd_host);
-   if (host_info = gethostbyname( fgd_host)) {
+   if ( (host_info = gethostbyname( fgd_host)) != NULL ) {
      bcopy(host_info->h_addr, (char *)&address.sin_addr,host_info->h_length);
      strcpy((char *) fgd_ip, (char *) inet_ntoa(address.sin_addr));
      if (verbose == 2) {
@@ -256,12 +277,12 @@ void fgd_init(void){
    } else if ((address.sin_addr.s_addr = inet_addr( fgd_host)) == INADDR_NONE) {
             fprintf(stderr,"   Could not get %s host entry !\n", fgd_host);
             printf(" NOT resolved !!!\n");
-            exit(1);
+            // exit(1);
           } else if (verbose == 2) printf(" address valid\n");
    
    if ((base_port > end_port) || ((short)base_port < 0)) { 
-     fprintf(stderr,"Bad port range : start=%d end=%d !\n");
-     exit(1);
+     fprintf(stderr,"Bad port range : start=%d end=%d !\n",base_port,end_port);
+   // exit(1);
    } else if (verbose == 2) {
             printf("     Port range: %d to %d\n",base_port,end_port);
             }
@@ -269,12 +290,12 @@ void fgd_init(void){
 
 int net_resolv_fgd( char *fgd_host_check ) {
 
-char *fgd_ip_check;
+   char *fgd_ip_check = "";
 
 /* resolving the destination host, here fgd's host */   
    net_r = 0;
    if (verbose == 2) printf("     Resolving default DEAMON: %s ->", fgd_host_check);
-   if (host_info = gethostbyname( fgd_host_check)) {
+   if ( (host_info = gethostbyname( fgd_host_check)) != NULL ) {
      bcopy(host_info->h_addr, (char *)&address.sin_addr,host_info->h_length);
      strcpy((char *) fgd_ip_check, (char *) inet_ntoa(address.sin_addr));
      fgd_ip = fgd_ip_check;
@@ -282,24 +303,25 @@ char *fgd_ip_check;
             printf(" FGD: resolved\nFGD: running on HOST : %s", fgd_host_check);
             printf("   IP : %s\n", fgd_ip_check);
             strcpy( fgd_host, fgd_host_check);
-//            return(0);
+//            return 0;
             }
    } else if ((address.sin_addr.s_addr = inet_addr( fgd_host)) == INADDR_NONE) {
             fprintf(stderr,"FGD:  Could not get %s host entry !\n", fgd_host_check);
             printf(" FGD: NOT resolved !!!\n");
             net_r = -1;
-            return(-1);
+            return -1;
             // exit(1);
           } else if (verbose == 2) printf(" address valid\n");
    
    if ((base_port > end_port) || ((short)base_port < 0)) { 
-     fprintf(stderr,"Bad port range : start=%d end=%d !\n");
+     fprintf(stderr,"Bad port range : start=%d end=%d !\n",base_port,end_port);
      // exit(1);
         net_r = -2;
-        return(-2);
+        return -2;
    } else if (verbose == 2) {
             printf("     Port range: %d to %d\n",base_port,end_port);
             }
+   return 0;
 }
 
 
@@ -313,8 +335,11 @@ void fgd_send_com( char *FGD_com, char *FGFS_host) {
     sock = socket(PF_INET, SOCK_STREAM, 0);
     if (sock == -1)
      {
-       fprintf(stderr, "Error assigning master socket: %s\n",sys_errlist[errno]);
-       exit(-1);
+//     fprintf(stderr, "Error assigning master socket: %s\n",sys_errlist[errno]);
+                fprintf(stderr, "Error assigning master socket: %s\n",
+                                strerror(errno));
+        /* must check how severe this really is */
+       // exit(-1);
      } 
 
     address.sin_port = htons(current_port);
@@ -361,18 +386,18 @@ void fgd_send_com( char *FGD_com, char *FGFS_host) {
    speed loss/gain in network-area...
 */
                           get_latitude(), get_longitude(), get_altitude(),
-                          get_speed(), get_roll()*RAD_TO_DEG,
-                          get_pitch()*RAD_TO_DEG, get_heading());
+                          get_speed(), get_roll()*SGD_RADIANS_TO_DEGREES,
+                          get_pitch()*SGD_RADIANS_TO_DEGREES, get_heading());
                  write( sock, fgd_txt, 56);
                  break;
 
 /* Here sending the previously calculated view.Mat4 by FGFS */
         case 17: if (verbose == 2) printf("Checkpoint\n");
-                 sgCopyMat4(sgFGD_COORD, current_view.VIEW);
+                 sgCopyMat4(sgFGD_COORD, globals->get_current_view()->get_VIEW());
 
                  if (verbose == 2) {
                     printf("current_view\n");
-                    fgd_print_Mat4( current_view.VIEW);
+                    fgd_print_Mat4( globals->get_current_view()->get_VIEW());
                     printf("FGD_COORD\n");
                     fgd_print_Mat4( sgFGD_COORD);
                  }
@@ -416,7 +441,8 @@ void fgd_send_com( char *FGD_com, char *FGFS_host) {
         } 
     }  else if (errno == 113) {
          fprintf(stderr,"No route to host !\n");
-         exit(1);
+         /* must check this */
+         // exit(1);
        } 
 /*     fprintf(stderr,"Error %d connecting socket %d to port %d: %s\n",
                 errno,sock,current_port,sys_errlist[errno]); */ 
@@ -473,10 +499,18 @@ void fgd_send_com( char *FGD_com, char *FGFS_host) {
                       case  5: printf("FGD: Receiving data from Host %s\n", FGFS_host);
                                read( sock, fgd_txt, buffp[3]);
                                fgd_txt[buffp[3]] = 0;
+/* This works...
+                               if (strcmp(fgd_txt, "UNKNOWN") == 0) {
+                                   printf("FGD: Host not in list, sorry...\n");
+                               }
+                               else printf("FGD: Data from Host %s received\n", fgd_txt);
+*/
+/* This has problem with glibc-2.1
                                if (strcmp(fgd_txt, "UNKNOWN") == -1) {
                                    if (verbose == 2) printf("FGD: Data from Host %s received\n", fgd_txt);
                                    }
                                    else if (verbose == 2) printf("FGD: Host not in list, sorry...\n");
+*/
                                break;
                       case 17: if (verbose == 2) printf("FGD: Receiving Mat4 data from Host %s\n", FGFS_host);
                                read( sock, fgd_txt, fgd_reply_len);
@@ -634,11 +668,18 @@ void fgd_send_com( char *FGD_com, char *FGFS_host) {
                                   test = test->next;
                                }
                                fgd_ppl = 0;
-/*
+/*  This does...
+                               if (strcmp(fgd_txt, "UNKNOWN") == 0) {
+                                   printf("FGD: Host not in list, sorry...\n");
+                               }
+                               else printf("FGD: Host %s unregistered\n", fgd_txt);
+*/
+/*  This does not work on glibc-2.1
                                if (strcmp(fgd_txt, "UNKNOWN") == -1) {
                                    printf("FGD: Host %s unregistered\n", fgd_txt);
                                    }
-                                   else printf("FGD: Host not in list, sorry...\n"); */
+                               else printf("FGD: Host not in list, sorry...\n"); 
+*/
                                break;                               
                       case  9: printf(" Shutdown FlightGear-Deamon %s .\n", fgd_name);
                                break;