1
0
Fork 0

Depreciate NetworkOLK. A big thanks goes to Oliver Delise for implementing it in the first place.

This commit is contained in:
ehofman 2003-11-13 14:42:47 +00:00
parent a37515d7fe
commit e322c70f52
34 changed files with 7 additions and 4242 deletions

2
Thanks
View file

@ -111,7 +111,7 @@ Dave Cornish <dmc@halcyon.com>
Oliver Delise <delise@mail.isis.de>
FAQ Maintainer, Documentation, Public Relations.
Working on adding some networking / multi-user support.
Author of (the now depreciated) networking / multi-user support.
Founder of the FlightGear MultiPilot Project :
http://www.isis.de/members/~odelise/progs/flightgear

View file

@ -59,24 +59,14 @@ fi
# Specify if we want to build with Multiplayer support
# default to with_network=yes
AC_ARG_WITH(multiplayer, [ --with-multiplayer Include default multiplayer support])
AC_ARG_WITH(network_olk, [ --with-network-olk Include Oliver's multi-pilot networking support [default=no]])
AC_ARG_WITH(multiplayer, [ --with-multiplayer Include multiplayer support [default=yes]])
if test "x$with_multiplayer" = "xno" -a "x$with_network_olk" = "xno"; then
if test "x$with_multiplayer" = "xno"; then
echo "Building without any kind of multiplayer support"
elif test "x$with_multiplayer" = "xno"; then
# echo "Building without default multiplayer support"
echo "Building with Oliver's multi-pilot network support"
AC_DEFINE([FG_NETWORK_OLK], 1, [Define to build with Oliver's networking])
else
echo "Building with default multiplayer support"
# echo "Building without Oliver's multi-pilot network support"
AC_DEFINE([FG_MPLAYER_AS], 1, [Define to build with default multiplayer support])
echo "Building with multiplayer support"
AC_DEFINE([FG_MPLAYER_AS], 1, [Define to build with multiplayer support])
fi
AM_CONDITIONAL(ENABLE_NETWORK_OLK, test "x$with_network_olk" != "xno" -a "x$with_multiplayer" = "xno")
AM_CONDITIONAL(ENABLE_MPLAYER_AS, test "x$with_multiplayer" != "xno")
@ -541,7 +531,6 @@ AC_CONFIG_FILES([ \
src/MultiPlayer/Makefile \
src/Navaids/Makefile \
src/Network/Makefile \
src/NetworkOLK/Makefile \
src/Objects/Makefile \
src/Replay/Makefile \
src/Scenery/Makefile \
@ -592,9 +581,7 @@ else
fi
if test "x$with_multiplayer" != "xno"; then
echo "Using default multiplayer support"
elif test "x$with_network_olk" != "xno"; then
echo "Using Oliver's multi-pilot network support"
echo "Building with multiplayer support"
fi
if test "x$with_threads" = "xyes"; then

View file

@ -54,9 +54,6 @@
#include <GUI/gui.h>
#include <Main/globals.hxx>
#include <Main/fg_props.hxx>
#ifdef FG_NETWORK_OLK
#include <NetworkOLK/network.h>
#endif
#include <Scenery/scenery.hxx>
#if defined ( __sun__ ) || defined ( __sgi )
@ -1165,12 +1162,6 @@ void drawHUD()
HUD_TextList.add( fgText(40, 10, get_formated_gmt_time(), 0) );
#ifdef FG_NETWORK_OLK
if ( net_hud_display ) {
net_hud_update();
}
#endif
int apY = 480 - 80;
// char scratch[128];

View file

@ -1,13 +1,5 @@
noinst_LIBRARIES = libGUI.a
EXTRA_DIST = net_dlg.cxx net_dlg.hxx
if ENABLE_NETWORK_OLK
NETWORK_SRCS = net_dlg.cxx net_dlg.hxx
else
NETWORK_SRCS =
endif
libGUI_a_SOURCES = \
new_gui.cxx new_gui.hxx \
dialog.cxx dialog.hxx \
@ -15,7 +7,6 @@ libGUI_a_SOURCES = \
gui.cxx gui.h gui_funcs.cxx \
gui_local.cxx gui_local.hxx \
mouse.cxx \
$(NETWORK_SRCS) \
preset_dlg.cxx preset_dlg.hxx \
prop_picker.cxx prop_picker.hxx \
sgVec3Slider.cxx sgVec3Slider.hxx \

View file

@ -12,7 +12,6 @@ gui_funcs.cxx Implementation of internal GUI functions (deprecated).
gui_local.[ch]xx More internal GUI functions (deprecated).
menubar.[ch]xx XML-configurable menu bar.
mouse.cxx Old GUI mouse support (deprecated).
net_dlg.[ch]xx Hard-coded network dialog (deprecated).
new_gui.[ch]xx Top-level for the GUI subsystem.
preset_dlg.[ch]xx Internal functions for presets (deprecated).
prop_picker.[ch]xx Built-in property-tree dialog.
@ -21,4 +20,4 @@ trackball.[ch] Old mouse view support (deprecated).
David Megginson
2003-09-26
2003-09-26

View file

@ -48,7 +48,6 @@
#include "gui.h"
#include "gui_local.hxx"
#include "net_dlg.hxx"
#include "preset_dlg.hxx"
@ -126,10 +125,5 @@ void guiInit()
ConfirmExitDialogInit();
fgPresetInit();
#ifdef FG_NETWORK_OLK
NewNetIdInit();
NewNetFGDInit();
#endif
mkDialogInit();
}

View file

@ -80,10 +80,6 @@
#include <Main/fg_props.hxx>
#include <Main/viewmgr.hxx>
#ifdef FG_NETWORK_OLK
#include <NetworkOLK/network.h>
#endif
#if defined( WIN32 ) && !defined( __CYGWIN__ ) && !defined(__MINGW32__)
# include <simgear/screen/win32-printer.h>
# include <simgear/screen/GlBitmaps.h>
@ -91,7 +87,6 @@
#include "gui.h"
#include "gui_local.hxx"
#include "net_dlg.hxx"
#include "preset_dlg.hxx"
#include "prop_picker.hxx"
#include "sgVec3Slider.hxx"
@ -104,10 +99,6 @@ extern void fgHUDalphaAdjust( puObject * );
// from cockpit.cxx
extern void fgLatLonFormatToggle( puObject *);
#ifdef FG_NETWORK_OLK
extern void net_fgd_scan(puObject *cb);
#endif // #ifdef FG_NETWORK_OLK
#if defined( TR_HIRES_SNAP)
#include <simgear/screen/tr.h>
extern void trRenderFrame( void );
@ -170,15 +161,6 @@ const __fg_gui_fn_t __fg_gui_fn[] = {
{"fgPresetAirspeed", fgPresetAirspeed},
{"fgPresetCommit", fgPresetCommit},
// Network
#ifdef FG_NETWORK_OLK
{"net_display_toggle", net_display_toggle},
{"NewCallSign", NewCallSign},
{"net_fgd_scan", net_fgd_scan},
{"net_register", net_register},
{"net_unregister", net_unregister},
#endif
// Autopilot
{"NewAltitude", NewAltitude},
{"NewHeading", NewHeading},
@ -404,12 +386,6 @@ void goodBye(puObject *)
// "Program exiting normally at user request." );
cout << "Program exiting normally at user request." << endl;
#ifdef FG_NETWORK_OLK
if ( fgGetBool("/sim/networking/network-olk") ) {
if ( net_is_registered == 0 ) fgd_send_com( "8", FGFS_host);
}
#endif
// close all external I/O connections
globals->get_io()->shutdown_all();
@ -861,25 +837,3 @@ void fgDumpSnapShot () {
}
}
#ifdef FG_NETWORK_OLK
void net_display_toggle( puObject *cb)
{
net_hud_display = (net_hud_display) ? 0 : 1;
printf("Toggle net_hud_display : %d\n", net_hud_display);
}
void net_register( puObject *cb)
{
fgd_send_com( "1", FGFS_host );
net_is_registered = 0;
printf("Registering to deamon\n");
}
void net_unregister( puObject *cb)
{
fgd_send_com( "8", FGFS_host );
net_is_registered = -1;
printf("Unregistering from deamon\n");
}
#endif // #ifdef FG_NETWORK_OLK

View file

@ -1,308 +0,0 @@
// net_dlg.cxx -- data structures for initializing & managing network.
//
// Written by Oliver Delise, started May 1999.
//
// Copyleft (C) 1999 Oliver Delise - delise@rp-plus.de
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License as
// published by the Free Software Foundation; either version 2 of the
// License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful, but
// WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
// General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
//
#ifdef HAVE_CONFIG_H
# include <config.h>
#endif
#include <simgear/compiler.h>
#ifdef HAVE_WINDOWS_H
# include <windows.h>
#endif
#include <stdlib.h>
#include <simgear/constants.h>
#include <simgear/debug/logstream.hxx>
#include <simgear/misc/sg_path.hxx>
#include <Include/general.hxx>
#include <GL/gl.h>
#include <Main/globals.hxx>
#include <Main/fg_props.hxx>
#include <NetworkOLK/network.h>
#include "gui.h"
#include "net_dlg.hxx"
/// The beginnings of networking :-)
// Needs cleaning up but works
// These statics should disapear when this is a class
static puDialogBox *NetIdDialog = 0;
static puFrame *NetIdDialogFrame = 0;
static puText *NetIdDialogMessage = 0;
static puInput *NetIdDialogInput = 0;
static char NewNetId[16];
static char NewNetIdLabel[] = "Enter New Callsign";
extern char *fgd_callsign;
static puOneShot *NetIdDialogOkButton = 0;
static puOneShot *NetIdDialogCancelButton = 0;
void NetIdDialog_Cancel(puObject *)
{
FG_POP_PUI_DIALOG( NetIdDialog );
}
void NetIdDialog_OK (puObject *)
{
string NetId;
static const SGPropertyNode *master_freeze
= fgGetNode("/sim/freeze/master");
bool freeze = master_freeze->getBoolValue();
if ( !freeze ) {
fgSetBool("/sim/freeze/master", true);
}
/*
The following needs some cleanup because
"string options.NetId" and "char *net_callsign"
*/
NetIdDialogInput->getValue(&net_callsign);
NetId = net_callsign;
NetIdDialog_Cancel( NULL );
fgSetString("/networking/call-sign", NetId.c_str() );
strcpy( fgd_callsign, net_callsign);
// strcpy( fgd_callsign, fgGetString("/sim/networking/call-sign").c_str());
/* Entering a callsign indicates : user wants Net HUD Info */
net_hud_display = 1;
if ( !freeze ) {
fgSetBool("/sim/freeze/master", false);
}
}
void NewCallSign(puObject *cb)
{
sprintf( NewNetId, "%s", fgGetString("/sim/networking/call-sign") );
// sprintf( NewNetId, "%s", fgd_callsign );
NetIdDialogInput->setValue( NewNetId );
FG_PUSH_PUI_DIALOG( NetIdDialog );
}
void NewNetIdInit(void)
{
sprintf( NewNetId, "%s", fgGetString("/sim/networking/call-sign") );
// sprintf( NewNetId, "%s", fgd_callsign );
int len = 150 - puGetDefaultLabelFont().getStringWidth( NewNetIdLabel ) / 2;
NetIdDialog = new puDialogBox (150, 50);
{
NetIdDialogFrame = new puFrame (0,0,350, 150);
NetIdDialogMessage = new puText (len, 110);
NetIdDialogMessage -> setLabel (NewNetIdLabel);
NetIdDialogInput = new puInput (50, 70, 300, 100);
NetIdDialogInput -> setValue (NewNetId);
NetIdDialogInput -> acceptInput();
NetIdDialogOkButton = new puOneShot (50, 10, 110, 50);
NetIdDialogOkButton -> setLegend (gui_msg_OK);
NetIdDialogOkButton -> setCallback (NetIdDialog_OK);
NetIdDialogOkButton -> makeReturnDefault(TRUE);
NetIdDialogCancelButton = new puOneShot (240, 10, 300, 50);
NetIdDialogCancelButton -> setLegend (gui_msg_CANCEL);
NetIdDialogCancelButton -> setCallback (NetIdDialog_Cancel);
}
FG_FINALIZE_PUI_DIALOG( NetIdDialog );
}
/*************** Deamon communication **********/
// These statics should disapear when this is a class
static puDialogBox *NetFGDDialog = 0;
static puFrame *NetFGDDialogFrame = 0;
static puText *NetFGDDialogMessage = 0;
//static puInput *NetFGDDialogInput = 0;
//static char NewNetId[16];
static char NewNetFGDLabel[] = "Scan for deamon ";
static char NewFGDHost[64] = "olk.mcp.de";
static int NewFGDPortLo = 10000;
static int NewFGDPortHi = 10001;
//extern char *fgd_callsign;
extern u_short base_port, end_port;
extern int fgd_ip, verbose, current_port;
extern char *fgd_host;
static puOneShot *NetFGDDialogOkButton = 0;
static puOneShot *NetFGDDialogCancelButton = 0;
static puOneShot *NetFGDDialogScanButton = 0;
static puInput *NetFGDHostDialogInput = 0;
static puInput *NetFGDPortLoDialogInput = 0;
static puInput *NetFGDPortHiDialogInput = 0;
void NetFGDDialog_Cancel(puObject *)
{
FG_POP_PUI_DIALOG( NetFGDDialog );
}
void NetFGDDialog_OK (puObject *)
{
char *NetFGD;
static const SGPropertyNode *master_freeze
= fgGetNode("/sim/freeze/master");
bool freeze = master_freeze->getBoolValue();
if ( !freeze ) {
fgSetBool("/sim/freeze/master", true);
}
NetFGDHostDialogInput->getValue( &NetFGD );
strcpy( fgd_host, NetFGD);
NetFGDPortLoDialogInput->getValue( (int *) &base_port );
NetFGDPortHiDialogInput->getValue( (int *) &end_port );
NetFGDDialog_Cancel( NULL );
if ( !freeze ) {
fgSetBool("/sim/freeze/master", false);
}
}
void NetFGDDialog_SCAN (puObject *)
{
char *NetFGD;
int fgd_port;
static const SGPropertyNode *master_freeze
= fgGetNode("/sim/freeze/master");
bool freeze = master_freeze->getBoolValue();
if ( !freeze ) {
fgSetBool("/sim/freeze/master", true);
}
// printf("Vor getvalue %s\n");
NetFGDHostDialogInput->getValue( &NetFGD );
// printf("Vor strcpy %s\n", (char *) NetFGD);
strcpy( fgd_host, NetFGD);
NetFGDPortLoDialogInput->getValue( (int *) &base_port );
NetFGDPortHiDialogInput->getValue( (int *) &end_port );
printf("FGD: %s Port-Start: %d Port-End: %d\n", fgd_host,
base_port, end_port);
net_resolv_fgd(fgd_host);
printf("Resolve : %d\n", net_r);
if ( !freeze ) {
fgSetBool("/sim/freeze/master", false);
}
if ( net_r == 0 ) {
fgd_port = 10000;
strcpy( fgd_name, "");
for( current_port = base_port; ( current_port <= end_port); current_port++) {
fgd_send_com("0" , FGFS_host);
sprintf( NewNetFGDLabel , "Scanning for deamon Port: %d", current_port);
printf("FGD: searching %s\n", fgd_name);
if ( strcmp( fgd_name, "") != 0 ) {
sprintf( NewNetFGDLabel , "Found %s at Port: %d",
fgd_name, current_port);
fgd_port = current_port;
current_port = end_port+1;
}
}
current_port = end_port = base_port = fgd_port;
}
NetFGDDialog_Cancel( NULL );
}
void net_fgd_scan(puObject *cb)
{
NewFGDPortLo = base_port;
NewFGDPortHi = end_port;
strcpy( NewFGDHost, fgd_host);
NetFGDPortLoDialogInput->setValue( NewFGDPortLo );
NetFGDPortHiDialogInput->setValue( NewFGDPortHi );
NetFGDHostDialogInput->setValue( NewFGDHost );
FG_PUSH_PUI_DIALOG( NetFGDDialog );
}
void NewNetFGDInit(void)
{
// sprintf( NewNetId, "%s", fgGetString("/sim/networking/call-sign").c_str() );
// sprintf( NewNetId, "%s", fgd_callsign );
int len = 170
- puGetDefaultLabelFont().getStringWidth( NewNetFGDLabel ) / 2;
NetFGDDialog = new puDialogBox (310, 30);
{
NetFGDDialogFrame = new puFrame (0,0,320, 170);
NetFGDDialogMessage = new puText (len, 140);
NetFGDDialogMessage -> setLabel (NewNetFGDLabel);
NetFGDPortLoDialogInput = new puInput (50, 70, 127, 100);
NetFGDPortLoDialogInput -> setValue (NewFGDPortLo);
NetFGDPortLoDialogInput -> acceptInput();
NetFGDPortHiDialogInput = new puInput (199, 70, 275, 100);
NetFGDPortHiDialogInput -> setValue (NewFGDPortHi);
NetFGDPortHiDialogInput -> acceptInput();
NetFGDHostDialogInput = new puInput (50, 100, 275, 130);
NetFGDHostDialogInput -> setValue (NewFGDHost);
NetFGDHostDialogInput -> acceptInput();
NetFGDDialogScanButton = new puOneShot (130, 10, 200, 50);
NetFGDDialogScanButton -> setLegend ("Scan");
NetFGDDialogScanButton -> setCallback (NetFGDDialog_SCAN);
NetFGDDialogScanButton -> makeReturnDefault(FALSE);
NetFGDDialogOkButton = new puOneShot (50, 10, 120, 50);
NetFGDDialogOkButton -> setLegend (gui_msg_OK);
NetFGDDialogOkButton -> setCallback (NetFGDDialog_OK);
NetFGDDialogOkButton -> makeReturnDefault(TRUE);
NetFGDDialogCancelButton = new puOneShot (210, 10, 280, 50);
NetFGDDialogCancelButton -> setLegend (gui_msg_CANCEL);
NetFGDDialogCancelButton -> setCallback (NetFGDDialog_Cancel);
}
FG_FINALIZE_PUI_DIALOG( NetFGDDialog );
}
/*
static void net_display_toggle( puObject *cb)
{
net_hud_display = (net_hud_display) ? 0 : 1;
printf("Toggle net_hud_display : %d\n", net_hud_display);
}
*/
/*************** End Networking **************/

View file

@ -1,37 +0,0 @@
// net_dlg.hxx -- data structures for initializing & managing network.
//
// Written by Oliver Delise, started May 1999.
//
// Copyleft (C) 1999 Oliver Delise - delise@rp-plus.de
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License as
// published by the Free Software Foundation; either version 2 of the
// License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful, but
// WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
// General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
//
//#ifdef FG_NETWORK_OLK
#include <plib/pu.h>
extern void NetIdDialog_Cancel(puObject *);
extern void NewCallSign(puObject *cb);
extern void NetIdDialog_OK (puObject *);
extern void NewNetIdInit(void);
extern void NetFGDDialog_Cancel(puObject *);
extern void NetFGDDialog_OK (puObject *);
extern void NetFGDDialog_SCAN (puObject *);
extern void net_fgd_scan(puObject *cb);
extern void NewNetFGDInit(void);
//#endif // FG_NETWORK_OLK

View file

@ -10,12 +10,6 @@ else
MPLAYER_LIBS =
endif
if ENABLE_NETWORK_OLK
NETWORK_LIBS = $(top_builddir)/src/NetworkOLK/libNetworkOLK.a
else
NETWORK_LIBS =
endif
if WITH_THREADS
THREAD_LIBS = -lsgthreads $(thread_LIBS)
else
@ -92,7 +86,6 @@ fgfs_LDADD = \
$(top_builddir)/src/Sound/libSound.a \
$(top_builddir)/src/Airports/libAirports.a \
$(MPLAYER_LIBS) \
$(NETWORK_LIBS) \
$(top_builddir)/src/Objects/libObjects.a \
$(top_builddir)/src/Replay/libReplay.a \
$(top_builddir)/src/Systems/libSystems.a \

View file

@ -88,10 +88,6 @@
#include <Time/fg_timer.hxx>
#include <Environment/environment_mgr.hxx>
#ifdef FG_NETWORK_OLK
#include <NetworkOLK/network.h>
#endif
#ifdef FG_MPLAYER_AS
#include <MultiPlayer/multiplaytxmgr.hxx>
#include <MultiPlayer/multiplayrxmgr.hxx>
@ -151,11 +147,6 @@ static GLfloat rwy_exp2_punch_through;
static GLfloat taxi_exp2_punch_through;
static GLfloat ground_exp2_punch_through;
#ifdef FG_NETWORK_OLK
ssgSelector *fgd_sel = NULL;
ssgTransform *fgd_pos = NULL;
#endif
// Sky structures
SGSky *thesky;
@ -637,27 +628,6 @@ void fgRenderFrame() {
fgUpdateDCS();
// $$$ end - added VS Renganthan 17 Oct 2K
# ifdef FG_NETWORK_OLK
if ( fgGetBool("/sim/networking/network-olk") ) {
sgCoord fgdpos;
other = head->next; /* put listpointer to start */
while ( other != tail) { /* display all except myself */
if ( strcmp( other->ipadr, fgd_mcp_ip) != 0) {
other->fgd_sel->select(1);
sgSetCoord( &fgdpos, other->sgFGD_COORD );
other->fgd_pos->setTransform( &fgdpos );
}
other = other->next;
}
// fgd_sel->select(1);
// sgCopyMat4( sgTUX, current_view.sgVIEW);
// sgCoord fgdpos;
// sgSetCoord( &fgdpos, sgFGD_VIEW );
// fgd_pos->setTransform( &fgdpos);
}
# endif
#ifdef FG_MPLAYER_AS
// Update any multiplayer models
globals->get_multiplayer_rx_mgr()->Update();
@ -1023,16 +993,6 @@ static void fgMainLoop( void ) {
SG_LOG( SG_ALL, SG_DEBUG, "Running Main Loop");
SG_LOG( SG_ALL, SG_DEBUG, "======= ==== ====");
#ifdef FG_NETWORK_OLK
if ( fgGetBool("/sim/networking/network-olk") ) {
if ( net_is_registered == 0 ) { // We first have to reg. to fgd
// printf("FGD: Netupdate\n");
fgd_send_com( "A", FGFS_host); // Send Mat4 data
fgd_send_com( "B", FGFS_host); // Recv Mat4 data
}
}
#endif
#if defined( ENABLE_PLIB_JOYSTICK )
// Read joystick and update control settings
// if ( fgGetString("/sim/control-mode") == "joystick" )
@ -1747,14 +1707,6 @@ bool fgMainInit( int argc, char **argv ) {
fgLoadDCS();
// ADA
#ifdef FG_NETWORK_OLK
// Do the network intialization
if ( fgGetBool("/sim/networking/network-olk") ) {
printf("Multipilot mode %s\n",
fg_net_init( globals->get_scenery()->get_scene_graph() ) );
}
#endif
// build our custom render states
fgBuildRenderStates();

View file

@ -50,9 +50,6 @@
// #include <Cockpit/cockpit.hxx>
// #include <FDM/flight.hxx>
// #include <FDM/UIUCModel/uiuc_aircraftdir.h>
#ifdef FG_NETWORK_OLK
# include <NetworkOLK/network.h>
#endif
#include <GUI/gui.h>
@ -223,9 +220,6 @@ fgSetDefaults ()
fgSetString("/sim/startup/time-offset-type", "system-offset");
fgSetLong("/sim/time/cur-time-override", 0);
fgSetBool("/sim/networking/network-olk", false);
fgSetString("/sim/networking/call-sign", "Johnny");
// Freeze options
fgSetBool("/sim/freeze/master", false);
fgSetBool("/sim/freeze/position", false);
@ -936,16 +930,6 @@ fgOptStartDateGmt( const char *arg )
return FG_OPTIONS_OK;
}
#ifdef FG_NETWORK_OLK
static int
fgOptNetHud( const char *arg )
{
fgSetBool("/sim/hud/net-display", true);
net_hud_display = 1; // FIXME
return FG_OPTIONS_OK;
}
#endif
static int
fgOptTraceRead( const char *arg )
{
@ -1368,12 +1352,6 @@ struct OptionDesc {
{"rul", true, OPTION_CHANNEL, "", false, "", 0 },
{"joyclient", true, OPTION_CHANNEL, "", false, "", 0 },
{"jsclient", true, OPTION_CHANNEL, "", false, "", 0 },
#ifdef FG_NETWORK_OLK
{"disable-network-olk", false, OPTION_BOOL, "/sim/networking/olk", false, "", 0 },
{"enable-network-olk", false, OPTION_BOOL, "/sim/networking/olk", true, "", 0 },
{"net-hud", false, OPTION_FUNC, "", false, "", fgOptNetHud },
{"net-id", true, OPTION_STRING, "sim/networking/call-sign", false, "", 0 },
#endif
#ifdef FG_MPLAYER_AS
{"callsign", true, OPTION_STRING, "sim/multiplay/callsign", false, "", 0 },
{"multiplay", true, OPTION_CHANNEL, "", false, "", 0 },

View file

@ -32,10 +32,6 @@ SG_USING_STD(vector);
#include "globals.hxx"
#include "util.hxx"
#if defined(FG_NETWORK_OLK)
#include <NetworkOLK/network.h>
#endif
void
fgDefaultWeatherValue (const char * propname, double value)
@ -61,11 +57,6 @@ fgExit (int status)
{
SG_LOG(SG_GENERAL, SG_INFO, "Exiting FlightGear with status " << status);
#if defined(FG_NETWORK_OLK)
if (fgGetBool("/sim/networking/network-olk"))
fgd_send_com("8", FGFS_host);
#endif
globals->get_io()->shutdown_all();
exit(status);
}

View file

@ -16,12 +16,6 @@ else
MPLAYER_DIRS =
endif
if ENABLE_NETWORK_OLK
NETWORK_DIRS = NetworkOLK
else
NETWORK_DIRS =
endif
SUBDIRS = \
Include \
Aircraft \
@ -38,7 +32,6 @@ SUBDIRS = \
Navaids \
Network \
$(MPLAYER_DIRS) \
$(NETWORK_DIRS) \
Objects \
Replay \
Scenery \

View file

@ -23,7 +23,6 @@ SG_USING_STD(vector);
// Don't pull in the headers, since we don't need them here.
class ssgBranch;
class ssgCutout;
class ssgEntity;
class ssgRangeSelector;
class ssgSelector;

View file

@ -1,11 +0,0 @@
FILES - This file, describing the other files
README - containing Network info
Makefile.am -
net_hud.cxx - display found player's info in bottom/left part of HUD
network.cxx - initialization of netcode and vars
fgd.h -
network.h - declaration of used vars and functions for libNetworkOLK.a
should be included from other files using libNetworkOLK
net_send.cxx - communication with deamon
Tools - directory containing the deamon, tools and toys necessairy
for testing the network with and without FGFS.

View file

@ -1,6 +0,0 @@
noinst_LIBRARIES = libNetworkOLK.a
libNetworkOLK_a_SOURCES = \
net_send.cxx net_hud.cxx network.cxx network.h fgd.h
INCLUDES = -I$(top_srcdir) -I$(top_srcdir)/src

View file

@ -1,34 +0,0 @@
Network README
--------------
Here in .../Simulator/Network will be the new home for multi pilot
related code.
For the moment all you get is a new menu entry "Network" with the
folowing entries:
- Hyper Blast : Toggles between LaRCsim and a tuned Flight-Model
you can change between both "on the fly "
- Toggle Display : enable/disable info (Lat/Lon/Alt) about found player
well, by now it will be you. ;-))
- Display Netinfos : n.i. will display more detailed information
- Enter Callsign : to enter your name
- Scan for Deamons : n.i. will scan the network for FGFS_D's
- Register to FGD : n.i. will allow pilot to connect to found Deamons
- Show Pilots : n.i. ? not yet sure what to show, maybe their planes
- Send Message : n.i. will send a message to a specific Pilot
- Send Message to all : n.i. obvious, isn't it ?
- Unregister from Deamon : n.i.
In the Tools directory you will find some progs (one first try of deamon)
to play with. There is also a README file, check it out.
You don't need a net-access to test this new stuff since it is just an idea
of how to incorporate a Multi-Pilot Mode in FGFS.
There are two security options:
a) Compiletime - commenting the "#define FG_NETWORK_OLK" in "network.h"
disables ALL network related stuff in case of problems, shouldn't occur ;-)
b) Runtime - setting the "int net_hud_display" variable to 0 disables any
network display (default)
Have Phun
Oliver <delise@mail.isis.de>

View file

@ -1,11 +0,0 @@
FILES - This file, describing the other files
HEADERS - Necessairy headers to compile the programs
INSTALL -
README - Detailed explanation about the programs and how to use
Makefile -
fgd.h - Headerfile included by all programs
fgd.c - Flightgear deamon, talkative, strongly recommended for start
fgd_silent.c - Flightgear deamon with no debug output, for advanced users
fgd_com.c - Sends commandos to fgd
fgd_scan.c - Scanner to detect Flightgear deamons via TCP
fgd_mcp.c - Master Control Program for fgd

View file

@ -1,18 +0,0 @@
These includes must be available on any Un*x, Windoze and Mac Donald's
#include <stdio.h>
#include <sys/socket.h>
#include <sys/types.h>
#include <netinet/in.h>
#include <unistd.h>
#include <netdb.h>
#include <sys/time.h>
#include <fcntl.h>
#include <sys/utsname.h>
Please look also into *all* your systemwide "socket.h" and the header
files (mainly in /usr/include/sys or krnl-src) included by them for
declarations like "MSG_PEEK" etc.
In case of missing MSG_foo declarations please contact me:
Oliver Delise <delise@mail.isis.de>

View file

@ -1,32 +0,0 @@
CPPFLAGS =
CFLAGS =
CC = gcc
RM = rm
PROGS = fgd fgd_scan fgd_com fgd_mcp fgd_silent
BINDIR = /usr/local/bin
all: $(PROGS)
fgd: fgd.c
$(CC) -o $@ $^
fgd_silent: fgd_silent.c
$(CC) -o $@ $^
fgd_scan: fgd_scan.c
$(CC) -o $@ $^
fgd_com: fgd_com.c
$(CC) -o $@ $^
fgd_mcp: fgd_mcp.c
$(CC) -o $@ $^
clean:
-$(RM) -f *.o $(PROGS) *~ core
install: all
install $(PROGS) $(BINDIR)
dist: clean
tar czf ../`basename \`pwd\``.tar.gz -C .. `basename \`pwd\``

View file

@ -1,289 +0,0 @@
Welcome to FlightGear Deamon fgd
--------------------------------
Here the first Tools to play with FlightGear Deamon.
This is yet alpha moving to beta and the sources remain to be tidied up,
and to get documented.
Why this software?
------------------
The goal of the author is to keep unnecessairy jobs out of FGFS. This keeps
FGFS doing what it should do: simulate!
Adding more fancy stuff into FGFS would maybe spoil it's framerates and lead
to larger compiletimes. For that reason an external solution comes in quite
handy. Firing up the deamon on another machine than FGFS is running does not
affect the cpu-time of FGFS. Let the deamon do all the other jobs for your
FGFS, also let *him* communicate with the outer world and present the
results in a "precooked" way.
Theory of operation:
--------------------
The FlightGear Deamon, called fgd, is a standalone program which registers
FGFS players willing to have a multiplayer FGFS environment via TCP/IP.
Information like player's IP/lon/lat/alt etc and also messages can be send
to fgd.
The deamon fgd in turn sends back the gathered information upon request.
The purpose of the scan prog "fgd_scan" is to locate free ports on the
network, which can be used for exchanging data between FGFS and fgd.
The commando program "fgd_com" serves as an example of how the communication
to fgd can be done. For the moment, the functionality of fgd_com is not yet
integrated into FGFS. Parts of fgd_com will be later incorporated into FGFS.
The master control program "fgd_mcp" is some sort virtual fgfs. It simulates
up to x FlightGear simulators. It's main purpose is being a development
platform for network related stuff. The coolest advantage here is the
possibilty of having multiple fgfs's in one little program. That saves *much*
memory and also time because recompiling fgd_mcp is way faster then FGFS.
How to play with the tools:
---------------------------
Just fire up fgd on whatever machine reachable from the one on which FGFS
will be running. Even the same machine is ok.
Then use fgd_scan to locate the fgd-deamon.
Also use fgd_com to pass some commandos to fgd.
Try setting up various scenarios with fgd_mcp and see if everything works.
How to compile:
---------------
Have a look at the HEADERS file and check the presence of the required headers
on your machine and adjust them in the fgd.h file just in case of being located
elsewhere. This software is libc5 proof, so maybe on glibc (>=2), the header
files will be located elsewhere.
Use the Makefile with make or just gcc -o prog prog.c
Default location for "make" is current directory, so be sure to have r/w-access
to it. For "make install" you have to be root, binaries go by default into
/usr/local/bin.
Usage:
------
- fgd [start port] [end port] [name] <-v -vv>
where
- start port and end port is the (numeric) range where it should
listen and talk to. (Later the range will be used to check for a
free port within this range, which can be used for communicating
with FGFS.
for the moment make sure you use the _SAME_ port value for start
and stop. A good starting point should be above or equal 10000.
- name (string) of the deamon.
- -v or -vv is the verbose level. This param can be ommitted.
Be careful, trying fgd on a used port doesn't work. Also it doesn't
make any sense and luckyly doesn't goof the service of the used port.
Just in case you did fgd will complain and advise you to look for an
unused port first.
- fgd_scan [host] [start port] [end port] <-v -vv>
comment: params are the same as for fgd except that the start/stop values
should be different to detect fgd. In case of knowning the port,
which fgd uses, one should of course set equal port-values.
Also host means the host running fgd, not where the scanner is
fired up.
Just for fun you can take also the dangerous (priviledged ports)
But the fgd-scanner could maybe get stuck at some used ports.
It doesn't hurt to experiment in the used regions, a ctrl-c
will abort the scanning so that new params can be used.
ACHTUNG! A well configured system, in this case the target-ip the
scanner inquires, will log the replies of various services
trying to react to the scanner. It depends on the vigilance
and mood of the respective sysadmin what will happen to the
*evil* person sending requests to the target system.
Scanning unused ports doesn't hurt at all.
Have a look at the "/etc/services" file which describes all
the "official" services & deamons lurking on various ports.
- fgd_com [FGD-host] [start port] [end port] [-v -vv] [commando] <FGFS-host>
comment: like fgd_scan, but you must enter either an ip (numeric) or alias
(string) or a fqdn (like foo.bar.com) or dummystring as last parameter
here: <FGFS-host>.
Some commandos use it to pass it as real information to fgd. Maybe the
start/end port options will go away later because it's the job of the
scanner to find fgd within a range.
It's a waste to spoil the net with commands (tcp-packets).
- fgd_mcp
comment: works like fgd_com except that it is *not* a single shot program as
the other programs, yes it works interactively so you have to enter
all relevant values yourself at runtime. You can stresstest any
FlightGear deamon to see if it responds a) accurate b) fast enough.
You can enter a Flight route just by entering the start/stop coords
and the speed. This master control program will then automagically
send information about current aircraft to the deamon, like a real
FGFS would do.
You can even define multiple scenarios. That means that all defined
aircrafts fly simultaneous at the same time.
Relevant params here are alt, lon, lat, speed, roll, pitch, yaw,
pilot, model, start/stop-coords and update frequency.
Watch out for broken pipes, never had any in a xterm but often on
text consoles. They will go away when the "recv"-loops will be
replaced by "select"-calls.
The default values suit my personal needs. So don't be paniked if
you get some errormessages. You just have to adjust some values
like IP's and HOST-names in either sourcecode or to enter them at
runtime.
The commandos for fgd_com:
--------------------------
0 : fgd identifies itself and answeres back to scanner
1 : registering to fgd
2 : show who's registered
3 : send message to one specific user (not implemented yet)
4 : send message to all users (not implemented yet)
5 : scan for other fgd's (not implemented yet)
6 : push (fgd_com sends FGFS-data to fgd) (not implemented yet)
7 : pop (fgd_com receives data from fgd) (not implemented yet)
8 : unregister from fgd
9 : shutdown fgd
Comments:
---------
Commandos 1/2/8 use the last parameter (see above, dummy-string) for the
ip or hostname or fqdn of the fgfs-machine which will be added/listed/removed
from fgd.
Commandos 3+4 are some sort of "talk" to registered users on fgd.
The messages are keyed in, then send and stored into fgd until the
recepient user requests fgd data via command 7 (pop).
Command 5 scans the net (within a range given) for other fgd-deamons.
Commandos 6+7 are seperated send/receive requests to/from fgd.
Later it will be FGFS who queries fgd in given intervalls. By now it's
the user who sends/receives at will via menu or keyboard while flying.
Command 9 is a remote shutdown for fgd. This at least avoids telnetting
to the remote machine, where fgd is fired up. Caveat Emptor: be careful,
everybody connected to fgd can send the "fgd-shutdown"-command. And hey,
also everybody can unregister another user...
Since all FGFS pilots are friendly and Multipilot-mode is considered
cooperative rather then deathmatch, I don't expect any malicious mis-use
of Multipilot-mode, err...yes? Also this keeps me from adding foolproof
if/then/else-stuff because FGFS is a serious Simulation Software used by
serious people who *know* what they are doing, even if they store FGFS in
directories like:
/usr/games/fgfs or D:\SPEL\FlightGear or /home/olk/spiele/fgfs
Try registering and unregistering various hosts to see if the add/remove
mechanism works well. It should work correctly as it can be veryfied
with the "2" command.
Examples:
---------
- fgd 10003 10003 Johnney -vv
fgd runs locally on port "10003" called "Johnney" using max. verbose level
- fgd_scan olk 1 1024 -vv
scans for flightgear deamons on host "olk" using ports "1" thru "1024"
beeing very verbose. Using ports below 10000 is, err...you know.
- fgd_com olk 10003 10003 -vv 1 johnny
send "register host"-command to fgd running on host "olk" using port"10003"
and register machine "johnny", here "johnny" is a fqdn.
- fgd_mcp (without any commandline params)
To do:
------
- modify FGFS to talk to fgd and display the data on HUD and draw any found
pilot's aircraft within visible area
- porting to Mac and Windows(95/98/2K/NT)
- clean-up code
- replace "recv"-loops by "select" (blocking vs nonblocking discussion)
- concatenate the elements of one command into one single net-call instead
of sending each element seperately !!!
- reducing of data to be transfered - here: wiping out redundancy,
computers can be upgraded easily but upgrading the bandwith of the net is
almost impossible ;-((
- document the code
- convert code from c to c++ ?
- find a place within FGFS, where to reside
- make fgd a *REAL* deamon which is forked in background
- make fgd concurrent instead of iterative, hmmm...
- make the code more autodetectable, to reduce commandline params
- implement missing commands
- find other useful commands
- find and resolve bugs ;-)
History:
--------
v0.1pre-alpha: May 25 1999 -> First release
v0.1-alpha : Nov 08 1999 -> Introducing fgd-Master-Control-Program
Some cleanups, implementing missing commands
of fgd_com into fgd_mcp
Nov 29 1999 -> Implementing scenario functions like virtual
Pilots
Nov 30 1999 -> ???
v0.1-beta : Jan 16 2000 -> Several libc5, glibc-2.0 and glibc-2.1
issues cleaned up
Future Plans:
-------------
Adding support for downloading files from Webserververs or FTP sites,
eg. weather data (METAR) and passing the infos to FGFS.
Adding some sort of "Tower Control" to the deamon. It could for instance
calculate the nearest airport for each pilot.
Modifying FGFS in a way to accept foreign-data. A so called remote-used
FGFS could display another view of the same flight. Well this requires
at least two or more machines, err...hummm.
On the other hand a remote used FGFS could serve as a teaching facility,
watching somebody else's fly could be very instructive ;-)
Another idea is to implement "black box" features into fgd. The deamon
would serve here as a flightrecorder. By this one could review a past
flight or any flight recorded by somebody else. The recorded "scenario files"
could be read by any deamon and serve as input data for any FGFS switched
into remote mode, see above paragraph.
Thanks:
-------
- W.Richard Stevens+, for his fantastic Unix Network Programming books
- Tennessee Carmel-Veilleux, e-mail: veilleux@ameth.org, for his portscan
program which inspired me writing the FlightGear metwork support.
REMEMBER:
---------
Those 4 toys are alpha and dirty and need also to be documented.
The programs are fairly well tested under Linux only, but the code should
conform to Unix98.
This software is OPEN SOURCE SOFTWARE, this helps to avoid this package to
be involved into _EVIL_ discussions about copyrights etc...
You can do whatever you want with this software, even enhance it.
Send comments/flames/BEER/whatever to delise@mail.isis.de
Oliver Delise Jan/16/00

View file

@ -1,11 +0,0 @@
These includes must be available on any Un*x, Windoze and Mac Donald's
#include <stdio.h>
#include <sys/socket.h>
#include <sys/types.h>
#include <netinet/in.h>
#include <unistd.h>
#include <netdb.h>
#include <sys/time.h>
#include <fcntl.h>
#include <sys/utsname.h>

View file

@ -1,659 +0,0 @@
/*************************************************************/
/* FGD.C by Oliver Delise */
/* Contact info: */
/* e-mail: delise@mail.isis.de */
/* www: http://www.isis.de/members/~odelise/progs/flightgear */
/* */
/* 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 */
/* any physical or moral damage caused by the use of this */
/* software. */
/* */
/* This is a standalone Tool to communicate with any */
/* FlightGear System and FGFS-Deamon. */
/* This is Open Source Software with some parts */
/* shamelessly stolen from others... */
/* */
/* -> This program will use a TCP port listening on a */
/* remote or local host inside the range you give to it. */
/* I offer no warranty over the accuracy though :) */
/* There are 3 verbose modes: No info, service info, and */
/* full info. No info is good of you only want the list */
/* of the ports, no more info. The best mode is Full */
/* info, as you get error information,etc. The main */
/* output is STDOUT, and ALL the errors go to STDERR. */
/* */
/* History: v0.1pre-alpha: May 25 1999 -> First release */
/* v0.1-alpha : Nov 08 1999 */
/* v0.1-beta : Jan 16 2000 */
/* libc5, glibc-2.0, 2.1 cleanups */
/* June 8 2000 socket cleanup */
/*************************************************************/
#include <stdio.h>
#include <sys/socket.h>
#include <sys/types.h>
#include <netinet/in.h>
#include <unistd.h>
#include <netdb.h>
#include <sys/time.h>
#include <fcntl.h>
#include <sys/utsname.h>
//#define printf //
/* Net-stuff */
fd_set rset, allset;
int maxfd, nready, retval;
struct timeval tv;
struct utsname myname;
char *fgd_host, *src_host;
/* Program-stuff */
int verbose, fgd_len_msg;
/* List-stuff (doubly-Linked-list) */
#include <string.h>
#include <stdlib.h>
int i, j, fgd_cnt, fgd_curpos;
char *vb, *fgd_txt;
const int True = 0;
const int False= -1;
float sgFGD_COORD[4][4];
struct list_ele {
unsigned char ipadr[16], callsign[16];
unsigned char lat[8], lon[8], alt[8], speed[8], roll[8], pitch[8], yaw[8];
float latf, lonf, altf, speedf, rollf, pitchf, yawf;
float sgFGD_COORD[4][4];
struct list_ele *next, *prev;
};
struct list_ele *head, *tail, *act, *test, *incoming; /* fgd_msg; */
struct fgd_sock_list {
char adr[16];
int prev_sock;
};
struct fgd_sock_list fgd_cli_list[255];
int fgd_known_cli = -1; /* False */
int fgd_cli = 0;
/*...Create head and tail of list */
void list_init( void) {
incoming = (struct list_ele*) malloc(sizeof(struct list_ele));
head = (struct list_ele*) malloc(sizeof(struct list_ele));
tail = (struct list_ele*) malloc(sizeof(struct list_ele));
if (head == NULL || tail == NULL) { printf("Out of memory\n"); exit(1); }
/* fixme :Where is the "with foobar do command "
head->ipadr = "127.0.0.0";
strcpy(head->callsign, "None");
head->lon = 0;
head->lat = 0;
head->alt = 0;
head->pitch = 0;
head->roll = 0;
head->yaw = 0;
*/
/* yaw!. Who the f$%& invented this ;-) */
head->ipadr[0] = 0;
tail->ipadr[0] = 255;
tail->ipadr[1] = 0;
head->prev = tail->prev = head;
head->next = tail->next = tail;
act = head; /* put listpointer to beginning of list */
}
void list_output( void) {
}
void list_search( char name[16]) {
if (strcmp(name, head->next->ipadr) <= 0) act = head;
else if (strcmp(name, tail->prev->ipadr) > 0) act = tail->prev;
else {
int vergleich = strcmp(name, act->ipadr);
if (vergleich > 0)
while (strcmp(name, act->next->ipadr) > 0) {
act = act->next;
}
else if (vergleich < 0)
while (strcmp(name, act->ipadr) < 0) {
act = act->prev;
}
else
while (strcmp(name, act->ipadr) == 0) {
act = act->prev;
}
}
}
void list_insert( char newip[16]) {
struct list_ele *new_ele;
new_ele = (struct list_ele*) malloc(sizeof(struct list_ele));
if (new_ele == NULL) { printf("Out of memory\n"); exit(1); }
strcpy(new_ele->ipadr, newip);
/* setting default */
strcpy(new_ele->callsign, "not assigned");
list_search( newip);
new_ele->prev = act;
new_ele->next = act->next;
act->next->prev = act->next = new_ele;
}
void list_setval( char newip[16]) {
list_search( newip);
strcpy( act->next->callsign, incoming->callsign);
act->next->latf = incoming->latf;
act->next->lonf = incoming->lonf;
act->next->altf = incoming->altf;
act->next->speedf = incoming->speedf;
act->next->rollf = incoming->rollf;
act->next->pitchf = incoming->pitchf;
act->next->yawf = incoming->yawf;
printf("Callsign %s ", act->next->callsign);
printf(" lat: %7.3f lon: %7.3f alt: %7.3f speed: %7.3f roll: %7.3f pitch: %7.3f yaw: %7.3f",
act->next->latf, act->next->lonf, act->next->altf, act->next->speedf,
act->next->rollf, act->next->pitchf, act->next->yawf);
}
void list_setval_Mat4( char newip[16]) {
list_search( newip);
strcpy( act->next->callsign, incoming->callsign);
for (i=0;i<4;i++)
for (j=0;j<4;j++)
act->next->sgFGD_COORD[i][j] = incoming->sgFGD_COORD[i][j];
printf("Callsign %s ", act->next->callsign);
}
void list_clear( char clrip[16]) {
struct list_ele *clr_ele;
list_search( clrip);
if ( strcmp( clrip, act->next->ipadr))
printf("....Name %s nicht vorhanden", clrip);
else {
clr_ele = act->next;
act->next = act->next->next;
act->next->prev = act;
free( clr_ele);
}
}
int list_not_in( char name[16]) {
i = True;
test = head->next;
while ((test != tail) && (i==True)) {
i = (strcmp(test->ipadr, name) ? True : False);
test = test->next;
if (verbose != 0) printf("list_not_in : %d\n",i);
}
return(i);
}
int sock = -1;
int my_sock;
int fgd_com;
int *ip;
size_t anz;
char buff[1024];
char *fgd_name;
struct { char *adr, *lon, *lat, *alt;} fgd_client;
int fgd_ele_len;
struct sockaddr_in address;
struct sockaddr_in my_address;
int result;
socklen_t size = sizeof(address);
extern int errno;
int current_port = 0;
u_short base_port = 0;
u_short end_port = 1024;
struct hostent *host_info;
struct servent *service_info;
void fgd_init(void);
int main(int argc, char **argv)
{
if (argc < 4) {
fprintf(stderr,"Usage: fgd [start port] [end port] [name] <-v or -vv>\n");
exit(1);
}
switch (argc) {
case 5: if (!strcmp(argv[4],"-v"))
verbose = 1;
else if (!strcmp(argv[4],"-vv"))
verbose = 2;
else { fprintf(stderr,"Usage: fgd [start port] [end port] [name] <-v or -vv>\n");
exit(1); }
case 4: base_port = (u_short)atoi(argv[1]);
end_port = (u_short)atoi(argv[2]);
fgd_name = argv[3];
break;
default: fprintf(stderr,"Usage: fgd [start port] [end port] [name] <-v or -vv>\n");
exit(1);
break;
}
bzero((char *)&address, sizeof(address));
address.sin_family = AF_INET;
if (uname(&myname) == 0) fgd_host = myname.nodename;
printf(" I am running as %s on HOST %s\n", fgd_name, fgd_host);
if (verbose == 2) printf(" Resolving: %s ->",fgd_host);
if (host_info = gethostbyname(fgd_host)) {
bcopy(host_info->h_addr, (char *)&address.sin_addr,host_info->h_length);
printf(" fgd : ip = %s\n", inet_ntoa( address.sin_addr));
if (verbose == 2) printf(" resolved\n");
} else if ((address.sin_addr.s_addr = inet_addr(fgd_host)) == INADDR_NONE) {
fprintf(stderr,"Could not get %s host entry !\n",argv[1]);
printf(" NOT resolved !!!\n");
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);
} else if (verbose == 2) {
printf(" Port range: %d to %d\n",base_port,end_port);
}
printf(" verbose: %d\n",verbose);
/* some init stuff */
fgd_txt = (char *) malloc(1024);
list_init();
fgd_init();
exit(0);
}
void fgd_init(void) {
struct { char *ip, *lon, *lat, *alt;} fg_id;
current_port = base_port;
while (current_port <= end_port) {
sock = socket(PF_INET, SOCK_STREAM, 0);
if (sock == -1)
{
fprintf(stderr, "Error assigning master socket: %s\n",sys_errlist[errno]);
exit(-1);
}
address.sin_port = htons(current_port);
if (verbose == 2) printf(" address.sin_port : %d\n",htons(address.sin_port));
if (1 == 1) {
if ( bind(sock, (struct sockaddr *)&address, sizeof(address)) == -1) {
printf(" Aiiiieeehh...ADRESS ALSO IN USE...\7hmmm...please check another port\n");
printf(" Just wait a few seconds or do a netstat to see the port status.\n");
exit(-1);
}
listen(sock, 5);
/* Hier neu */
maxfd = sock;
FD_ZERO( &allset);
FD_SET( sock, &allset);
for (;;){
rset = allset;
tv.tv_sec = 1;
tv.tv_usec = 0;
nready = select( sock + 1, &rset, NULL, NULL, &tv);
if (FD_ISSET( sock, &rset)) {
my_sock = accept( sock, (struct sockaddr *)&address, &size);
anz = 2;
/* reading length of senders' ip */
fgd_ele_len = 0;
read( my_sock, buff, 1);
fgd_ele_len = buff[0];
if (verbose == 2) printf("ele_len %d\n", fgd_ele_len);
/* reading senders' ip */
read( my_sock, &buff, fgd_ele_len);
ip = (int *) buff;
// printf("%d %d %d %d %x %x %x\n", buff[0], buff[1], buff[2], buff[3], &ip, ip, *ip);
fgd_client.adr = (char*) inet_ntoa( *ip);
src_host = fgd_client.adr;
/* reading commando */
read( my_sock, &buff, 1);
/* closing previous file descriptor of same client, at least we know now
that the previous command is finished since it's the same client who
again requests something. Maybe I'm to quick and diiirty ;-) */
printf("FGD : Using socket #%d\n", my_sock);
fgd_known_cli = False;
for ( fgd_cnt = 1; fgd_cnt < fgd_cli+1; fgd_cnt++) {
printf("FGD : fgd_cnt:%d fgd_cli:%d fgd_client.adr: %s prev.sock:%d fgd_cli_list[fgd_cnt].adr: %s\n",
fgd_cnt, fgd_cli, fgd_client.adr,
fgd_cli_list[fgd_cnt].prev_sock, fgd_cli_list[fgd_cnt].adr);
if ( strcmp( fgd_cli_list[fgd_cnt].adr, fgd_client.adr) == 0) {
printf("FGD : In Vergleichsloop. Closing socket: %d\n",
fgd_cli_list[fgd_cnt].prev_sock);
close( fgd_cli_list[fgd_cnt].prev_sock);
fgd_cli_list[fgd_cnt].prev_sock = my_sock;
fgd_known_cli = True;
}
}
if ( fgd_known_cli == False) {
fgd_cli++;
fgd_cli_list[fgd_cli].prev_sock = my_sock;
strcpy(fgd_cli_list[fgd_cli].adr, fgd_client.adr);
}
printf(" Commando received : %s from Host : %s\n", &buff, src_host);
fgd_com = ( (char) buff[0]) - 0x30;
printf("%d \n", fgd_com);
switch (fgd_com) {
case 0: printf(" fgd : Identify\n");
sprintf( (char*) buff, "FGDLH%s", fgd_name);
buff[3] = strlen(fgd_name) + 1; /* Lo, incl.zero */
buff[4] = 0; /* Hi, names < 0xff ! */
buff[buff[3] + 4] = 0; /* Term.zero */
printf(" I am : %s\n", fgd_name);
write( my_sock, &buff, buff[3]+5); /* fgd housekeeping ;-) */
// close(my_sock);
break;
case 1: printf(" fgd : Register\n");
/* reading length of FGFS_host ip */
fgd_ele_len = 0;
read( my_sock, &buff, 1);
fgd_ele_len = (int) &buff;
/* reading FGFS_host ip */
read( my_sock, &buff, fgd_ele_len);
ip = (int *) buff;
fgd_client.adr = (char*) inet_ntoa( *ip);
if (list_not_in(fgd_client.adr) == True) {
list_insert(fgd_client.adr);
list_search(fgd_client.adr);
// strcpy(act->callsign, "None");
printf(" Setting default values\n");
printf(" IP : %s\n", act->next->ipadr);
printf(" PILOT : %s\n", act->next->callsign);
}
/* writing answer back to client */
sprintf( (char*) buff, "FGDLH%s", fgd_client.adr);
buff[3] = strlen(fgd_client.adr) + 1; /* Lo, incl.zero */
buff[4] = 0; /* Hi, names < 0xff ! */
buff[buff[3] + 4] = 0; /* Term.zero */
write( my_sock, &buff, buff[3]+5); /* fgd housekeeping ;-) */
// close(my_sock);
break;
case 2: printf(" fgd : Show Registered\n");
sprintf( (char*) buff, "FGD");
// buff[3] = buff[4] = 0;
fgd_cnt = 0;
fgd_curpos = 6;
test = head->next;
while (test != tail) {
printf(" IP : %s\n", test->ipadr);
fgd_cnt++;
fgd_ele_len = strlen(test->ipadr) + 1;
// printf(" ele_len %d curpos %d\n", fgd_ele_len, fgd_curpos);
buff[fgd_curpos] = fgd_ele_len;
fgd_curpos++;
bcopy(test->ipadr, &buff[fgd_curpos], fgd_ele_len);
fgd_curpos += fgd_ele_len;
//buff[fgd_curpos] = 0;
test = test->next;
}
if (fgd_cnt == 0) fgd_curpos--;
buff[3] = fgd_curpos & 0xff;
buff[4] = fgd_curpos >> 8;
buff[5] = fgd_cnt;
write( my_sock, &buff, fgd_curpos);
// close(my_sock);
break;
case 3: printf(" fgd : Send MSG\n");
// close(my_sock);
break;
case 4: printf(" fgd : Send MSG to all\n");
// close(my_sock);
break;
case 5: printf(" fgd : Get DATA from client\n");
read( my_sock, &buff, 1);
fgd_ele_len = buff[0];
read( my_sock, &buff, fgd_ele_len);
ip = (int *) buff;
fgd_client.adr = (char*) inet_ntoa( *ip);
printf(" IP : %s\n", fgd_client.adr);
if (verbose != 0) printf("not_in (CASE) : %d\n", list_not_in(fgd_client.adr));
if (list_not_in(fgd_client.adr) == False) {
printf(" Checkpoint\n");
read( my_sock, &buff, 1);
printf(" Checkpoint 1\n");
fgd_ele_len = buff[0];
read( my_sock, &buff, fgd_ele_len);
incoming->callsign[fgd_ele_len] = 0;
bcopy( &buff, incoming->callsign, fgd_ele_len);
/* lat, lon */
read( my_sock, &buff, 56);
sscanf( buff," %7f %7f %7f %7f %7f %7f %7f", &incoming->latf, &incoming->lonf,
&incoming->altf, &incoming->speedf, &incoming->rollf,
&incoming->pitchf, &incoming->yawf);
printf(" lat :%7.3f\n lon :%7.3f\n alt :%7.3f\n speed :%7.3f\n roll :%7.3f\n pitch :%7.3f\n yaw :%7.3f\n",
incoming->latf, incoming->lonf, incoming->altf, incoming->speedf,
incoming->rollf, incoming->pitchf, incoming->yawf);
list_setval(fgd_client.adr);
}
else strcpy( fgd_client.adr, "UNKNOWN");
/* writing answer back to client */
sprintf( (char*) buff, "%sLH%s ", "FGD", fgd_client.adr);
buff[3] = strlen(fgd_client.adr) + 1;
buff[4] = 0;
buff[ buff[3] + 4] = 0;
printf(" IP : %s\n", fgd_client.adr);
write( my_sock, &buff, buff[3]+5);
// close(my_sock);
break;
case 17: printf(" fgd : Get Mat4 DATA from client\n");
read( my_sock, &buff, 1);
fgd_ele_len = buff[0];
read( my_sock, &buff, fgd_ele_len);
ip = (int *) buff;
fgd_client.adr = (char*) inet_ntoa( *ip);
printf(" IP : %s\n", fgd_client.adr);
if (verbose != 0) printf("not_in (CASE) : %d\n", list_not_in(fgd_client.adr));
if (list_not_in(fgd_client.adr) == False) {
printf(" Checkpoint\n");
read( my_sock, &buff, 1);
printf(" Checkpoint 1\n");
fgd_ele_len = buff[0];
read( my_sock, &buff, fgd_ele_len);
incoming->callsign[fgd_ele_len] = 0;
bcopy( &buff, incoming->callsign, fgd_ele_len);
/* lat, lon */
read( my_sock, &buff, 158);
i = sscanf( buff," %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f",
&incoming->sgFGD_COORD[0][0], &incoming->sgFGD_COORD[0][1], &incoming->sgFGD_COORD[0][2], &incoming->sgFGD_COORD[0][3],
&incoming->sgFGD_COORD[1][0], &incoming->sgFGD_COORD[1][1], &incoming->sgFGD_COORD[1][2], &incoming->sgFGD_COORD[1][3],
&incoming->sgFGD_COORD[2][0], &incoming->sgFGD_COORD[2][1], &incoming->sgFGD_COORD[2][2], &incoming->sgFGD_COORD[2][3],
&incoming->sgFGD_COORD[3][0], &incoming->sgFGD_COORD[3][1], &incoming->sgFGD_COORD[3][2], &incoming->sgFGD_COORD[3][3]);
// printf(" sscanf input: %d\n",i);
printf(" sgMat4: \n%f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f\n",
incoming->sgFGD_COORD[0][0], incoming->sgFGD_COORD[0][1], incoming->sgFGD_COORD[0][2], incoming->sgFGD_COORD[0][3],
incoming->sgFGD_COORD[1][0], incoming->sgFGD_COORD[1][1], incoming->sgFGD_COORD[1][2], incoming->sgFGD_COORD[1][3],
incoming->sgFGD_COORD[2][0], incoming->sgFGD_COORD[2][1], incoming->sgFGD_COORD[2][2], incoming->sgFGD_COORD[2][3],
incoming->sgFGD_COORD[3][0], incoming->sgFGD_COORD[3][1], incoming->sgFGD_COORD[3][2], incoming->sgFGD_COORD[3][3]);
list_setval_Mat4(fgd_client.adr);
}
else strcpy( fgd_client.adr, "UNKNOWN");
/* writing answer back to client */
sprintf( (char*) buff, "FGDLH%s", fgd_client.adr);
buff[3] = strlen(fgd_client.adr) + 1;
buff[4] = buff[buff[3]+5] = 0;
printf(" IP : %s\n", fgd_client.adr);
write( my_sock, &buff, buff[3]+5);
// close(my_sock);
break;
case 6: printf(" fgd : Send all DATA to client\n");
sprintf( (char*) buff, "%s %s", "FGD", fgd_client.adr);
buff[3] = 0;
fgd_cnt = 0;
fgd_curpos = 6;
test = head->next;
while (test != tail) {
printf(" IP : %-16s Callsign : %-16s\n", test->ipadr, test->callsign);
fgd_cnt++;
/* IP */
fgd_ele_len = strlen(test->ipadr);
printf(" ele_len %d curpos %d\n", fgd_ele_len, fgd_curpos);
buff[fgd_curpos] = fgd_ele_len;
fgd_curpos++;
bcopy(test->ipadr, &buff[fgd_curpos], fgd_ele_len);
fgd_curpos = fgd_curpos + fgd_ele_len;
/* Callsign */
fgd_ele_len = strlen(test->callsign);
printf(" ele_len %d curpos %d\n", fgd_ele_len, fgd_curpos);
buff[fgd_curpos] = fgd_ele_len;
fgd_curpos++;
bcopy(test->callsign, &buff[fgd_curpos], fgd_ele_len);
fgd_curpos = fgd_curpos + fgd_ele_len;
/* Lat, Lon, Alt, Speed, Roll, Pitch, Yaw
hope this sprintf call is not too expensive */
sprintf( fgd_txt, " %7.3f %7.3f %7.3f %7.3f %7.3f %7.3f %7.3f",
test->latf, test->lonf, test->altf, test->speedf,
test->rollf, test->pitchf, test->yawf);
printf(" ele_len %d curpos %d\n", fgd_ele_len, fgd_curpos);
printf(" Data : %s\n", fgd_txt);
bcopy((char *) fgd_txt, &buff[fgd_curpos], 56);
fgd_curpos += 56;
test = test->next;
}
if (fgd_cnt == 0) fgd_curpos --;
printf(" ele_len %d curpos %d\n", fgd_ele_len, fgd_curpos);
buff[3] = fgd_curpos;
buff[4] = fgd_curpos / 256;
buff[5] = fgd_cnt;
write( my_sock, &buff, fgd_curpos);
// close(my_sock);
break;
case 18: printf(" fgd : Send all Mat4 DATA to client\n");
sprintf( (char*) buff, "FGDLH");
buff[3] = buff[4] = 0;
fgd_cnt = 0;
fgd_curpos = 6;
test = head->next;
while (test != tail) {
printf(" IP : %-16s Callsign : %-16s\n", test->ipadr, test->callsign);
fgd_cnt++;
/* IP */
fgd_ele_len = strlen(test->ipadr);
printf(" ele_len %d curpos %d\n", fgd_ele_len, fgd_curpos);
buff[fgd_curpos] = fgd_ele_len;
fgd_curpos++;
bcopy(test->ipadr, &buff[fgd_curpos], fgd_ele_len);
fgd_curpos = fgd_curpos + fgd_ele_len;
/* Callsign */
fgd_ele_len = strlen(test->callsign);
printf(" ele_len %d curpos %d\n", fgd_ele_len, fgd_curpos);
buff[fgd_curpos] = fgd_ele_len;
fgd_curpos++;
bcopy(test->callsign, &buff[fgd_curpos], fgd_ele_len);
fgd_curpos = fgd_curpos + fgd_ele_len;
/* Lat, Lon, Alt, Speed, Roll, Pitch, Yaw
hope this sprintf call is not too expensive */
fgd_len_msg = sprintf( fgd_txt, " %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f",
test->sgFGD_COORD[0][0], test->sgFGD_COORD[0][1], test->sgFGD_COORD[0][2], test->sgFGD_COORD[0][3],
test->sgFGD_COORD[1][0], test->sgFGD_COORD[1][1], test->sgFGD_COORD[1][2], test->sgFGD_COORD[1][3],
test->sgFGD_COORD[2][0], test->sgFGD_COORD[2][1], test->sgFGD_COORD[2][2], test->sgFGD_COORD[2][3],
test->sgFGD_COORD[3][0], test->sgFGD_COORD[3][1], test->sgFGD_COORD[3][2], test->sgFGD_COORD[3][3]);
fgd_txt[fgd_len_msg] = 0;
printf(" ele_len %d curpos %d\n", fgd_ele_len, fgd_curpos);
printf(" Data : %s\n", fgd_txt);
bcopy((char *) fgd_txt, &buff[fgd_curpos], fgd_len_msg+1);
fgd_curpos += fgd_len_msg+1;
test = test->next;
}
if (fgd_cnt == 0) fgd_curpos -= 1;
printf(" ele_len %d curpos %d\n", fgd_ele_len, fgd_curpos);
buff[3] = fgd_curpos & 0xff;
buff[4] = fgd_curpos / 256;
buff[5] = fgd_cnt;
printf("ANZ: %d CURPOS: %d\n", (unsigned char) buff[3] + (unsigned char) buff[4] * 256, fgd_curpos);
write( my_sock, &buff, fgd_curpos);
// close(my_sock);
break;
case 8: printf(" fgd : Unregister\n");
read( my_sock, &buff, 1);
fgd_ele_len = (int) &buff;
read( my_sock, &buff, fgd_ele_len);
ip = (int *) buff;
fgd_client.adr = (char*) inet_ntoa( *ip);
printf(" IP : %s\n", fgd_client.adr);
if (verbose != 0) printf("not_in (CASE) : %d\n", list_not_in(fgd_client.adr));
if (list_not_in(fgd_client.adr) == -1) {
list_clear(fgd_client.adr);
}
else strcpy( fgd_client.adr, "UNKNOWN");
/* writing answer back to client */
sprintf( (char*) buff, "FGDLH%s", fgd_client.adr);
buff[3] = strlen(fgd_client.adr) + 1;
buff[4] = buff[buff[3]+5] = 0;
printf(" IP : %s\n", fgd_client.adr);
write( my_sock, &buff, buff[3]+5);
// Just leaving the old stuff in, to correct it for FGFS later...
// I'm sick of this f$%&ing libc5/glibc2.0/2.1 quirks
// Oliver...very angry...
// /* writing answer back to client */
// sprintf( (char*) buff, "%s %s", "FGD", fgd_client.adr);
// buff[3] = strlen(fgd_client.adr);
// printf(" IP : %s\n", fgd_client.adr);
// write( my_sock, &buff, buff[3]+4);
// close(my_sock);
break;
case 9: printf(" fgd : Shutdown\n");
close(my_sock);
close(sock);
exit(0);
default: printf(" fgd : Huh?...Unknown Command\n");
break;
}
}
}
/*
switch (verbose) {
case 0: printf("%d\n",base_port+current_port);
break;
case 1: service_info = getservbyport(htons(base_port+current_port),"tcp");
if (!service_info) {
printf("%d -> service name unknown\n",base_port+current_port);
} else {
printf("%d -> %s\n",base_port+current_port,service_info->s_name);
}
break;
case 2: service_info = getservbyport(htons(base_port+current_port),"tcp");
if (!service_info) {
printf("Port %d found. Service name unknown\n",base_port+current_port);
} else {
printf("Port %d found. Service name: %s\n",base_port+current_port,service_info->s_name);
}
break;
}
*/
} else if (errno == 113) {
fprintf(stderr,"No route to host !\n");
exit(1);
}
/* current_port++; */
}
if (verbose == 2) printf("Port scan finished !\n");
}

View file

@ -1,25 +0,0 @@
#ifndef _MSC_VER
#include <sys/socket.h>
#include <sys/types.h>
#include <netinet/in.h>
#include <unistd.h>
#include <netdb.h>
#include <sys/time.h>
#include <fcntl.h>
#include <sys/utsname.h>
/* this seems to be missing for glibc-2.0.x */
/* libc5 & glibc-2.1 do have them */
#ifndef MSG_PEEK
int MSG_PEEK = 0x02; /* Peek at incoming messages. */
#define MSG_PEEK MSG_PEEK
#endif
#ifndef MSG_WAITALL
int MSG_WAITALL = 0x100; /* Wait for a full request. */
#define MSG_WAITALL MSG_WAITALL
#endif
#endif /* !_MSC_VER */

View file

@ -1,200 +0,0 @@
/*************************************************************/
/* FGD_COM.C by Oliver Delise */
/* Contact info: */
/* e-mail: delise@mail-isis.de */
/* www: http://www.isis.de/members/odelise/progs/flightgear */
/* */
/* 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 */
/* any physical or moral damage caused by the use of this */
/* software. */
/* */
/* This is a standalone Tool to communicate with any */
/* FlightGear-Deamon. */
/* This is Open Source Software with many parts */
/* shamelessly stolen from others... */
/* */
/* -> This program will use a TCP port listening on a */
/* remote or local host inside the range you give to it. */
/* I offer no warranty over the accuracy though :) */
/* There are 3 verbose modes: No info, service info, and */
/* full info. No info is good of you only want the list */
/* of the ports, no more info. The best mode is Full */
/* info, as you get error information,etc. The main */
/* output is STDOUT, and ALL the errors go to STDERR. */
/* */
/* History: v0.1pre-alpha: May 25 1999 -> First release */
/* v0.1-alpha Nov 08 1999 */
/* v0.1-beta Jan 16 2000 -> libc5/glibc-2.0 */
/* glibc2.1 cleanups */
/*************************************************************/
#include <stdio.h>
#include <sys/socket.h>
#include <sys/types.h>
#include <netinet/in.h>
#include <unistd.h>
#include <netdb.h>
#include <sys/time.h>
#include <fcntl.h>
#include <sys/utsname.h>
/* Netstuff */
int sock = -1;
int my_sock;
struct sockaddr_in address;
struct sockaddr_in my_address;
int result;
extern int errno;
int current_port = 0;
u_short base_port = 0;
u_short end_port = 1024;
int verbose = 0;
struct hostent *host_info, *f_host_info;
struct servent *service_info;
struct utsname myname;
/* Program-stuff */
int i;
int fgd_len_msg = 1;
size_t anz;
char *buff;
char *src_host, *fgd_host, fgfs_host;
char *usage = "Usage:\n fgd_com [FGD host] [start port] [end port] [-v or -vv] [Commando] [FGFS host]\n";
void fgd_init(void){
bzero((char *)&address, sizeof(address));
address.sin_family = AF_INET;
/* determinating the source/sending host */
if (uname(&myname) == 0) src_host = myname.nodename;
printf("I'm running on HOST : %s\n", src_host);
/* resolving the destination host, here fgd's host */
if (verbose == 2) printf("Resolving: %s ->", fgd_host);
if (host_info = gethostbyname( fgd_host)) {
bcopy(host_info->h_addr, (char *)&address.sin_addr,host_info->h_length);
if (verbose == 2) printf(" resolved\n");
} 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);
} 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);
} else if (verbose == 2) {
printf("Port range: %d to %d\n",base_port,end_port);
}
}
void fgd_send_com( char *FGD_com, char *FGFS_host) {
current_port = base_port;
printf("Sending : %s\n", FGD_com);
while (current_port <= end_port) {
/* fprintf(stderr,"Trying port: %d\n",current_port); */
sock = socket(PF_INET, SOCK_STREAM, 0);
if (sock == -1)
{
fprintf(stderr, "Error assigning master socket: %s\n",sys_errlist[errno]);
exit(-1);
}
address.sin_port = htons(current_port);
printf("address.sin_port : %d\n",htons(address.sin_port));
f_host_info = gethostbyname(src_host);
//printf ("src_host : %s", ntohs(f_host_info->h_addr));
if (connect(sock, (struct sockaddr *)&address, sizeof(address)) == 0) {
// write( sock, FGD_com, 1);
fgd_len_msg = (int) sizeof(f_host_info->h_addr);
/* send length of sender-ip */
write( sock, &fgd_len_msg,1);
/* send sender-ip */
write( sock, f_host_info->h_addr, fgd_len_msg);
/* send commando */
write( sock, FGD_com, 1);
/* send length of dummy-string, for the moment with _WHO_ to execute commando
here: his length of ip */
f_host_info = gethostbyname(FGFS_host);
fgd_len_msg = (int) sizeof(f_host_info->h_addr);
write( sock, &fgd_len_msg,1);
/* send dummy-string, for the moment with _WHO_ to execute commando
here: his ip */
write( sock, f_host_info->h_addr, fgd_len_msg);
printf(" Message : %s\n", FGD_com);
switch (verbose) {
case 0: printf("%d\n",current_port);
break;
case 1: service_info = getservbyport(htons(current_port),"tcp");
if (!service_info) {
printf("%d -> service name unknown\n",current_port);
} else {
printf("%d -> %s\n",current_port,service_info->s_name);
}
break;
case 2: service_info = getservbyport(htons(current_port),"tcp");
if (!service_info) {
printf("Port %d found. Service name unknown\n",current_port);
} else {
printf("Port %d found. Service name: %s\n",current_port,service_info->s_name);
}
break;
}
} else if (errno == 113) {
fprintf(stderr,"No route to host !\n");
exit(1);
}
/* fprintf(stderr,"Error %d connecting socket %d to port %d: %s\n",
errno,sock,current_port,sys_errlist[errno]); */
close(sock);
current_port++;
}
if (verbose == 2) printf("fgd_com terminated.\n");
}
int main(int argc, char **argv) {
if (argc < 6) {
fprintf(stderr, usage);
exit(1);
}
printf("argc %d argv[5] %s\n",argc,argv[5]);
switch (argc) {
case 7: printf("fgd commando : %s\n",argv[5]);
base_port = (u_short)atoi(argv[2]);
end_port = (u_short)atoi(argv[3]);
fgd_host = argv[1];
verbose = 2;
break;
case 5: if (!strcmp(argv[4],"-v"))
verbose = 1;
else if (!strcmp(argv[4],"-vv"))
verbose = 2;
else { fprintf(stderr, usage);
exit(1); }
case 4: base_port = (u_short)atoi(argv[2]);
end_port = (u_short)atoi(argv[3]);
break;
default: fprintf(stderr, usage);
exit(1);
break;
}
fgd_init();
fgd_send_com( argv[5], argv[6]);
exit(0);
}

View file

@ -1,605 +0,0 @@
/*************************************************************/
/* FGD_MCP.C by Oliver Delise */
/* Contact info: */
/* e-mail: delise@mail.isis.de */
/* www: http://www.isis.de/members/odelise/progs/flightgear */
/* */
/* 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 */
/* any physical or moral damage caused by the use of this */
/* software. */
/* */
/* This is an interactive standalone Tool to communicate */
/* with any FlightGear-Deamon. */
/* This is Open Source Software with many parts */
/* shamelessly stolen from others... */
/* */
/* -> This program will use a TCP port listening on a */
/* remote or local host inside the range you give to it. */
/* I offer no warranty over the accuracy though :) */
/* There are 3 verbose modes: No info, service info, and */
/* full info. No info is good of you only want the list */
/* of the ports, no more info. The best mode is Full */
/* info, as you get error information,etc. The main */
/* output is STDOUT, and ALL the errors go to STDERR. */
/* */
/* History: v0.1pre-alpha: May 25 1999 -> First release */
/* v0.1-alpha Nov 11 1999 */
/* v0.1-beta Jan 16 2000 libc5/glibc-2.0 */
/* glibc-2.1 cleanups */
/*************************************************************/
#include <stdio.h>
#include "fgd.h"
#include <math.h>
//#define printf //
/* Netstuff */
int sock = -1;
int my_sock;
struct sockaddr_in address;
struct sockaddr_in my_address;
int result;
extern int errno;
int current_port = 10000;
u_short base_port = 10000;
u_short end_port = 10000;
int verbose = 2;
struct hostent *host_info, *f_host_info;
struct servent *service_info;
struct utsname myname;
/* Program-stuff */
int i, j;
int fgd_len_msg = 1, fgd_status, fgd_ele_len, fgd_curpos, fgd_cnt, fgd_ppl,
fgd_ppl_old, fgd_loss;
size_t anz;
char *fgd_job, *fgd_callsign, *fgd_name, *fgd_ip, *fgd_mcp_ip;
char *buffp, *src_host, *fgd_host, *fgfs_host, *fgfs_pilot, *fgd_txt;
/* List-stuff */
const int True = 0;
const int False= -1;
struct list_ele {
unsigned char ipadr[16], callsign[16];
unsigned char lon[8], lat[8], alt[8], roll[8], pitch[8], yaw[8];
float lonf, latf, altf, speedf, rollf, pitchf, yawf;
struct list_ele *next, *prev;
};
struct list_ele *head, *tail, *act, *test, *incoming, *boss, *other; /* fgd_msg; */
/*...Create head and tail of list */
void list_init( void) {
incoming = (struct list_ele*) malloc(sizeof(struct list_ele));
boss = (struct list_ele*) malloc(sizeof(struct list_ele));
other = (struct list_ele*) malloc(sizeof(struct list_ele));
head = (struct list_ele*) malloc(sizeof(struct list_ele));
tail = (struct list_ele*) malloc(sizeof(struct list_ele));
if (head == NULL || tail == NULL) { printf("Out of memory\n"); exit(1); }
head->ipadr[0] = 0;
tail->ipadr[0] = 255;
tail->ipadr[1] = 0;
head->prev = tail->prev = head;
head->next = tail->next = tail;
act = head; /* put listpointer to beginning of list */
}
void list_output( void) {
}
void list_search( char name[16]) {
if (strcmp(name, head->next->ipadr) <= 0) act = head;
else if (strcmp(name, tail->prev->ipadr) > 0) act = tail->prev;
else {
int vergleich = strcmp(name, act->ipadr);
if (vergleich > 0)
while (strcmp(name, act->next->ipadr) > 0) {
act = act->next;
}
else if (vergleich < 0)
while (strcmp(name, act->ipadr) < 0) {
act = act->prev;
}
else
while (strcmp(name, act->ipadr) == 0) {
act = act->prev;
}
}
}
void list_insert( char newip[16]) {
struct list_ele *new_ele;
new_ele = (struct list_ele*) malloc(sizeof(struct list_ele));
if (new_ele == NULL) { printf("Out of memory\n"); exit(1); }
strcpy(new_ele->ipadr, newip);
/* setting default */
strcpy(new_ele->callsign, "not assigned");
list_search( newip);
new_ele->prev = act;
new_ele->next = act->next;
act->next->prev = act->next = new_ele;
}
void list_setval( char newip[16]) {
list_search( newip);
strcpy( act->next->callsign, incoming->callsign);
printf("Callsign %s\n", act->next->callsign);
}
void list_clear( char clrip[16]) {
struct list_ele *clr_ele;
list_search( clrip);
if ( strcmp( clrip, act->next->ipadr))
printf("....Name %s nicht vorhanden", clrip);
else {
clr_ele = act->next;
act->next = act->next->next;
act->next->prev = act;
free( clr_ele);
}
}
int list_not_in( char name[16]) {
i = True;
test = head->next;
while ((test != tail) && (i==True)) {
i = (strcmp(test->ipadr, name) ? True : False);
test = test->next;
if (verbose != 0) printf("list_not_in : %d\n",i);
}
return(i);
}
void fgd_init(void){
/* Let's init a few things */
printf("MCP: Allocating memory...");
buffp = (char *) malloc(1024); /* No I don't check if there are another KB */
fgd_job = (char *) malloc(8);
fgd_host = (char *) malloc(64);
fgd_callsign = (char *) malloc(64);
fgd_name = (char*) malloc(64);
fgd_ip = (char *) malloc(16);
fgd_mcp_ip = (char *) malloc(16);
fgfs_host = (char *) malloc(64);
fgfs_pilot = (char *) malloc(64);
src_host = (char *) malloc(64);
fgd_txt = (char *) malloc(1024);
printf("ok\nMCP: Initializing values...");
strcpy( fgd_job, "xxx");
strcpy( fgd_host, "Johnny");
strcpy( fgd_callsign, "Unknown");
strcpy( fgd_name, "Unknown");
strcpy( fgd_ip, (char *) inet_ntoa(address.sin_addr));
strcpy( fgd_txt, "");
printf("ok\n");
boss->latf = 112.3;
boss->lonf = 4.5;
boss->altf = 0.67;
boss->speedf = 100.95;
boss->rollf = 89.0;
boss->pitchf = 1.23;
boss->yawf = 456.789;
fgd_ppl = 0;
bzero((char *)&address, sizeof(address));
address.sin_family = AF_INET;
/* 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)) {
bcopy(host_info->h_addr, (char *)&address.sin_addr,host_info->h_length);
strcpy((char *) fgd_mcp_ip, (char *) inet_ntoa(address.sin_addr));
}
printf("IP : %s\n", fgd_mcp_ip);
/* resolving the destination host, here fgd's host */
if (verbose == 2) printf(" Resolving default DEAMON: %s ->", fgd_host);
if (host_info = gethostbyname( fgd_host)) {
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) {
printf(" resolved\n FGD running on HOST : %s", fgd_host);
printf(" IP : %s\n", fgd_ip);
}
} else if ((address.sin_addr.s_addr = inet_addr( fgd_host)) == INADDR_NONE) {
printf(" NOT resolved !!!\n");
printf("MCP: Could not get %s host entry !\n", fgd_host);
printf("MCP: Enter '10' for deamon IP or fqdn or alias. (your choice)\n");
// exit(1);
} else if (verbose == 2) printf(" address valid\n");
if ((base_port > end_port) || ((short)base_port < 0)) {
printf("MCP: Bad port range : start=%d end=%d !\n");
printf("MCP: Enter '10' for deamon IP/fqdn\n");
exit(1);
} else if (verbose == 2) {
printf(" Port range: %d to %d\n",base_port,end_port);
}
}
void fgd_send_com( char *FGD_com, char *FGFS_host) {
strcpy( buffp, " ");
current_port = base_port;
printf(" Sending : %s\n", FGD_com);
while (current_port <= end_port) {
/* fprintf(stderr,"Trying port: %d\n",current_port); */
sock = socket(PF_INET, SOCK_STREAM, 0);
if (sock == -1)
{
fprintf(stderr, "Error assigning master socket: %s\n",sys_errlist[errno]);
exit(-1);
}
address.sin_port = htons(current_port);
printf(" address.sin_port : %d\n",htons(address.sin_port));
f_host_info = gethostbyname(src_host);
//printf ("src_host : %s", ntohs(f_host_info->h_addr));
if (connect(sock, (struct sockaddr *)&address, sizeof(address)) == 0) {
/* FIXME: make a single string instead of sending elements */
fgd_len_msg = (int) sizeof(f_host_info->h_addr);
/* send length of sender-ip */
write( sock, &fgd_len_msg,1);
/* send sender-ip */
write( sock, f_host_info->h_addr, fgd_len_msg);
/* send commando */
write( sock, FGD_com, 1);
/* send length of dummy-string, for the moment with _WHO_ to execute commando
here: his length of ip */
f_host_info = gethostbyname(FGFS_host);
fgd_len_msg = (int) sizeof(f_host_info->h_addr);
write( sock, &fgd_len_msg,1);
/* send dummy-string, for the moment with _WHO_ to execute commando
here: his ip */
write( sock, f_host_info->h_addr, fgd_len_msg);
/* END FIXME */
/* Here we send subsequent data... */
switch (atoi((char *) FGD_com)) {
case 5: fgd_len_msg = strlen( fgd_callsign);
write( sock, &fgd_len_msg,1);
/* send string, for the moment, here: callsign */
write( sock, fgd_callsign, fgd_len_msg);
/* Lon, Lat, Alt, Speed, Roll, Pitch, Yaw
hope this sprintf call is not too expensive */
sprintf( fgd_txt, " %7.3f %7.3f %7.3f %7.3f %7.3f %7.3f %7.3f",
boss->latf, boss->lonf, boss->altf, boss->speedf,
boss->rollf, boss->pitchf, boss->yawf);
write( sock, fgd_txt, 56);
break;
default: break;
}
/* be verbose, this goes later into own (*void) */
printf(" Message : %s\n", FGD_com);
switch (verbose) {
case 0: printf("%d\n",current_port);
break;
case 1: service_info = getservbyport(htons(current_port),"tcp");
if (!service_info) {
printf("%d -> service name unknown\n",current_port);
} else {
printf("%d -> %s\n",current_port,service_info->s_name);
}
break;
case 2: service_info = getservbyport(htons(current_port),"tcp");
if (!service_info) {
printf(" Port %d found. Service name unknown\n",current_port);
} else {
printf(" Port %d found. Service name: %s\n",current_port,service_info->s_name);
}
break;
}
} else if (errno == 113) {
fprintf(stderr,"No route to host !\n");
exit(1);
}
/* fprintf(stderr,"Error %d connecting socket %d to port %d: %s\n",
errno,sock,current_port,sys_errlist[errno]); */
// service_info = getservbyport(htons(current_port),"tcp");
// if (!service_info) {
/* The Receiving Part, fgd returns errormessages, succes, etc... */
do {
fgd_status = recv( sock, (char *) buffp, 5, MSG_WAITALL);
printf(" status %d\n", fgd_status);
}
// while ( (fgd_status != 5) && (fgd_status != 0) );
while ( (fgd_status == -1) || (fgd_status == -1) );
if (verbose == 2) {
printf(" Got reply : %x %x %x\n", buffp[0], buffp[1], buffp[2]);
printf(" Got reply : %x\n", &buffp);
}
if (strncmp( buffp, "FGD", 3) == 0) {
switch (atoi((char *) FGD_com)) {
case 0: read( sock, fgd_name, buffp[3]);
fgd_name[buffp[3]] = 0;
printf("FGD: FlightGear-Deamon %s detected\n", fgd_name);
break;
case 1: printf("FGD: Registering Host %s\n", FGFS_host);
break;
case 2: printf("FGD: Showing registered Hosts at %s\n", fgd_host);
printf(" %d %d\n", buffp[3], buffp[4]);
if ( (buffp[3] + 256 * buffp[4]) != 5 ) {
/* FIXME: replace with SELECT to avoid broken pipes, known bug (-; */
/* but the transfer is calculated very accurately, null problemo */
do {
fgd_status = recv( sock, fgd_txt, buffp[3]-5, MSG_WAITALL);
// printf(" status %d\n", fgd_status);
}
// while ( (fgd_status != 4) && (fgd_status != 0) );
while ( (fgd_status == -1) || (fgd_status == -1) );
// read( sock, fgd_txt, buffp[3]-5);
fgd_curpos = 2;
for (fgd_cnt = 1; fgd_cnt < (fgd_txt[0]+1); fgd_cnt++) {
fgd_ele_len = fgd_txt[fgd_curpos-1];
bcopy( &fgd_txt[fgd_curpos], fgfs_host, fgd_ele_len);
fgfs_host[fgd_ele_len] = 0;
fgd_curpos = fgd_curpos + fgd_ele_len + 1;
printf(" #%d %s\n", fgd_cnt, fgfs_host);
}
}
break;
case 5: printf("FGD: Receiving data from Host %s\n", FGFS_host);
read( sock, fgd_txt, (unsigned char) buffp[3] + 256 * (unsigned char) buffp[4]);
fgd_txt[buffp[3]] = 0;
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);
break;
case 6: printf("FGD: Sending data to Host %s\n", FGFS_host);
if (buffp[3] != 5) {
/* FIXME: replace with SELECT */
if (verbose == 2) printf("Noch %d bytes\n", (unsigned char) buffp[3] + 256 * (unsigned char) buffp[4]);
do {
fgd_status = recv( sock, fgd_txt, (unsigned char) buffp[3]-5, MSG_PEEK);
if (verbose == 2) printf("Status %d\n", fgd_status);
}
while ( (fgd_status == 5) || (fgd_status == -1) );
// while ( (fgd_status == -1) || (fgd_status == -1) );
read( sock, fgd_txt, buffp[3]-5);
fgd_curpos = 2;
fgd_ppl_old = fgd_ppl;
fgd_ppl = fgd_txt[0];
/* Check if list has changed (pilot joined/left) */
if (fgd_ppl != fgd_ppl_old) {
printf(" List changed!!!\n");
for (fgd_cnt = 1; fgd_cnt <= abs(fgd_ppl - fgd_ppl_old); fgd_cnt++) {
printf(" Checkpoint\n");
incoming = head->next;
if ((fgd_ppl - fgd_ppl_old) > 0) list_insert("test\0");
else {
printf(" Clearing entry.\n");
list_clear(incoming->ipadr);
}
}
}
// else {
incoming = head->next;
for (fgd_cnt = 1; fgd_cnt < (fgd_ppl+1); fgd_cnt++) {
/* IP */
fgd_ele_len = fgd_txt[fgd_curpos-1];
bcopy( &fgd_txt[fgd_curpos], incoming->ipadr, fgd_ele_len);
incoming->ipadr[fgd_ele_len] = 0;
fgd_curpos = fgd_curpos + fgd_ele_len + 1;
/* Pilot */
fgd_ele_len = fgd_txt[fgd_curpos-1];
bcopy( &fgd_txt[fgd_curpos], incoming->callsign, fgd_ele_len);
incoming->callsign[fgd_ele_len] = 0;
fgd_curpos = fgd_curpos + fgd_ele_len + 1;
/* Lon, Lat...etc */
printf(" #%d %-16s %s\n", fgd_cnt, incoming->ipadr, incoming->callsign);
printf(" curpos:%d\n", fgd_curpos);
sscanf( &fgd_txt[fgd_curpos]," %7f %7f %7f %7f %7f %7f %7f",
&incoming->latf, &incoming->lonf,
&incoming->altf, &incoming->speedf, &incoming->rollf,
&incoming->pitchf, &incoming->yawf);
printf(" lat :%7.3f\n lon :%7.3f\n alt :%7.3f\n speed :%7.3f\n roll :%7.3f\n pitch :%7.3f\n yaw :%7.3f\n",
incoming->latf, incoming->lonf, incoming->altf, incoming->speedf,
incoming->rollf, incoming->pitchf, incoming->yawf);
fgd_curpos += 56;
incoming = incoming->next;
} /* end for */
// } /* end else */
} /* end if "data available" */
/* Here reading the answer of completed command by fgd */
/* read( sock, fgd_txt, buffp[3]);
fgd_txt[buffp[3]] = 0;
if (strcmp(fgd_txt, "UNKNOWN") == -1) {
printf("FGD: Data to Host sent\n");
}
else printf("FGD: Host not in list, sorry...\n");
*/
break;
case 8: printf("FGD: Unregistering Host %s\n", FGFS_host);
read( sock, fgd_txt, buffp[3]);
fgd_txt[buffp[3]] = 0;
if (strcmp(fgd_txt, "UNKNOWN") == 0) {
printf("FGD: Host not in list, sorry...\n");
}
else printf("FGD: Host %s unregistered\n", fgd_txt);
break;
case 9: printf(" Shutdown FlightGear-Deamon %s .\n", fgd_name);
break;
default: break;
}
} else printf(" Huh?: no deamon present, yuk!!!\n");
// }
close(sock);
current_port++;
}
if (verbose == 2) printf("fgd_com completed.\n");
}
int main(int argc, char **argv) {
list_init();
fgd_init();
for ( ; (atoi( (char*) fgd_job)) != 99;){
printf("MCP: ready...enter commando (42 help) ");
fgets((char *) fgd_job, 5, stdin);
// if (verbose == 2) printf("MCP: got %s %d\n", (char *) fgd_job, strlen((char *) fgd_job));
if ( strcmp( fgd_job, "\n") > 0 ) switch( atoi((char*) fgd_job)) {
case 0 : if ( strncmp( (char *) fgd_job, "0", 1) == 0 ){
printf("MCP: Scan for fgd\n");
fgd_send_com( "0", src_host);
}
break;
case 1 : printf("MCP: Register to fgd\n");
fgd_send_com( "1", src_host);
break;
case 2 : printf("MCP: Show registered\n");
fgd_send_com( "2", src_host);
break;
case 3 : printf("MCP: Send MSG\n");
break;
case 4 : printf("MCP: Send MSG to ALL\n");
break;
case 5 : printf("MCP: Push Data to fgd\n");
fgd_send_com( "5", src_host);
break;
case 6 : printf("MCP: Pop Data from fgd\n");
fgd_send_com( "6", src_host);
break;
case 8 : printf("MCP: Unregister from fgd\n");
fgd_send_com( "8", src_host);
break;
case 9 : printf("MCP: Shutdown fgd-deamon\n");
fgd_send_com( "9", src_host);
break;
case 10 : printf("MCP: Choose default deamon HOST:\n");
printf(" Deamon Host IP Port\n");
printf(" %-16s%-16s%-16s%-16d\n", fgd_name, fgd_host, fgd_ip, base_port);
printf("\n Enter new Host:[%s] ", fgd_host);
fgets((char *) fgd_txt, 32, stdin);
if ( strlen(fgd_txt) != 1 ) {
strcpy(fgd_host, fgd_txt);
fgd_host[ strlen( fgd_txt) - 1] = 0;
if (host_info = gethostbyname( fgd_host)) {
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) {
printf("MCP: Resolved...FGD running on HOST : %s", fgd_host);
printf(" IP : %s\n", fgd_ip);
}
} else if ((address.sin_addr.s_addr = inet_addr( fgd_host)) == INADDR_NONE) {
fprintf(stderr,"MCP: Could not get %s host entry !\n", fgd_host);
printf(" NOT resolved !!!\n");
// exit(1);
} else if (verbose == 2) printf(" address valid\n");
}
break;
case 11 : printf("MCP: Choose default deamon Port:\n");
printf(" Deamon Host IP Port\n");
printf(" %-16s%-16s%-16s%-16d\n", fgd_name, fgd_host, fgd_ip, base_port);
printf(" Enter new Port:[%d] ", base_port);
fgets((char *) buffp, 16, stdin);
current_port = atoi((char*) buffp);
if (current_port < 1025) {
printf("MCP: Be fair please...Ports below 1024 are not a good choice\n");
current_port = base_port;
break;
}
if (current_port != 0) {
base_port = atoi((char*) buffp);
end_port = base_port;
}
break;
case 20 : printf("MCP: Current values:\n");
printf(" Deamon Host IP Port\n");
printf(" %-16s%-16s%-16s%-16d\n", fgd_name, fgd_host, fgd_ip, base_port);
printf(" -----------------------------------------------------\n");
printf(" Callsign Host IP Port\n");
printf(" %-16s%-16s%-16s%-16d\n", fgd_callsign, src_host, fgd_mcp_ip, base_port);
printf(" Lat Lon Alt Speed Roll Pitch Yaw\n");
printf(" %-8s % 7.3f % 7.3f % 7.3f % 7.3f % 7.3f % 7.3f % 7.3f\n", fgd_callsign, boss->latf,
boss->lonf, boss->altf, boss->speedf, boss->rollf, boss->pitchf, boss->yawf);
printf(" -----------------------------------------------------\n");
printf(" Pilot list:\n");
test = head->next;
while (test != tail) {
printf(" Callsign Host\n");
printf(" %-16s%-16s\n", test->callsign, test->ipadr);
printf(" Lat Lon Alt Speed Roll Pitch Yaw\n");
printf(" %-8s % 7.3f % 7.3f % 7.3f % 7.3f % 7.3f % 7.3f % 7.3f\n", test->callsign, test->latf,
test->lonf, test->altf, test->speedf, test->rollf, test->pitchf, test->yawf);
test = test->next;
}
printf(" -----------------------------------------------------\n");
break;
case 21 : printf("MCP: Enter your callsign, Pilot ");
fgets((char *) fgd_callsign, 32, stdin);
fgd_callsign[ strlen(fgd_callsign) - 1 ] = 0;
break;
case 42 : printf("MCP: Commands available:\n 0 Scan for fgd\n 1 Register\n");
printf(" 2 Show registered\n 3 Send MSG\n 4 Send MSG to ALL\n");
printf(" 5 Push Data to fgd\n 6 Pop Data from fgd\n");
printf(" 8 Unregister from fgd\n 9 Shutdown fgd\n");
printf("10 Set deamon HOST\n11 Set deamon PORT\n");
printf("20 Show values\n21 Set own callsign\n");
// printf("31 Set deamon PORT\n");
printf("98 Stress test\n");
printf("99 Quit Master Control Program (not recommended)\n");
break;
case 98 : printf("MCP: Stress test ");
fgd_loss = 0;
list_search(fgd_mcp_ip);
other = act->next;
printf("other-ip %s\n", other->ipadr);
sleep(3);
for ( j=1; j<10000; j++) {
boss->latf += 0.001;
fgd_send_com( "5", src_host);
fgd_send_com( "6", src_host);
printf("other lat:%7.3f boss lat:%7.3f\n", other->latf, boss->latf);
if (fabs( (double) boss->latf - (double) other->latf ) > 0.001) {
printf("other lat:%7.3f boss lat:%7.3f\n", other->latf, boss->latf);
fgd_loss++;
}
}
printf(" Packets lost: %d\n", fgd_loss);
break;
case 99 : printf("MCP: Good bye...\n");
break;
default: printf("MCP: ???\n");
}
}
// fgd_send_com( argv[5], argv[6]);
free(buffp);
free(fgd_job);
free(fgd_host);
free(fgd_callsign);
free(fgd_name);
free(fgd_ip);
free(fgd_mcp_ip);
free(fgfs_host);
free(fgfs_pilot);
free(src_host);
free(fgd_txt);
exit(0);
}

View file

@ -1,195 +0,0 @@
/*************************************************************/
/* FGD_SCAN.C by Oliver Delise */
/* Contact info: */
/* e-mail: delise@mail-isis.de */
/* www: http://www.isis.de/members/odelise/progs/flightgear */
/* */
/* 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 */
/* any physical or moral damage caused by the use of this */
/* software. */
/* */
/* This is a standalone Tool to scan for any FlightGear */
/* Deamon. */
/* This is Open Source Software with many parts */
/* shamelessly stolen from others... */
/* */
/* -> This program will scan for TCP port listening on a */
/* remote or local host inside the range you give to it. */
/* I offer no warranty over the accuracy though :) */
/* There are 3 verbose modes: No info, service info, and */
/* full info. No info is good of you only want the list */
/* of the ports, no more info. The best mode is Full */
/* info, as you get error information,etc. The main */
/* output is STDOUT, and ALL the errors go to STDERR. */
/* */
/* History: v0.1pre-alpha: May 25 1999 -> First release */
/* v0.1-alpha Nov 08 1999 */
/* v0.1-beta Jan 16 2000 libc5/glibc-2.0 */
/* glibc-2.1 cleanups */
/*************************************************************/
#include <stdio.h>
#include <sys/socket.h>
#include <sys/types.h>
#include <netinet/in.h>
#include <unistd.h>
#include <netdb.h>
#include <sys/time.h>
#include <fcntl.h>
#include <sys/utsname.h>
int i;
int sock = -1;
int my_sock;
struct sockaddr_in address;
struct sockaddr_in my_address;
int result;
extern int errno;
int current_port = 20000;
u_short base_port = 20000;
u_short end_port = 20100;
int verbose = 0;
struct hostent *host_info, *f_host_info;
struct servent *service_info;
struct utsname myname;
size_t anz;
char *buff;
char *src_host;
void port_scan( char FGD_com);
void fgd_scan();
int main(int argc, char **argv)
{
if (argc < 4) {
fprintf(stderr,"Usage: fgd_scan [host] [start port] [end port] <-v or -vv>\n");
exit(1);
}
printf("argc %d argv[5] %s\n",argc,argv[5]);
verbose = 0;
switch (argc) {
/* case 5: base_port = (u_short)atoi(argv[2]);
end_port = (u_short)atoi(argv[3]);
verbose = 2;
src_host = argv[6];
break; */
case 5: if (!strcmp(argv[4],"-v"))
verbose = 1;
else if (!strcmp(argv[4],"-vv"))
verbose = 2;
else { fprintf(stderr,"Usage: fgd_scan [host] [start port] [end port] <-v or -vv>\n");
exit(1); }
case 4: base_port = (u_short)atoi(argv[2]);
end_port = (u_short)atoi(argv[3]);
break;
default: fprintf(stderr,"Usage: fgd_scan [host] [start port] [end port] <-v or -vv>\n");
exit(1);
break;
}
bzero((char *)&address, sizeof(address));
address.sin_family = AF_INET;
/* determinating the source/sending host */
if (uname(&myname) == 0) src_host = myname.nodename;
printf("I'm running on HOST : %s\n", src_host);
/* resolving the destination host, here: fgd's host */
if (verbose == 2) printf("Resolving: %s ->",argv[1]);
if (host_info = gethostbyname(argv[1])) {
bcopy(host_info->h_addr, (char *)&address.sin_addr,host_info->h_length);
if (verbose == 2) printf(" resolved\n");
} else if ((address.sin_addr.s_addr = inet_addr(argv[1])) == INADDR_NONE) {
fprintf(stderr,"Could not get %s host entry !\n",argv[1]);
printf(" NOT resolved !!!\n");
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);
} else if (verbose == 2) {
printf("Port range: %d to %d\n",base_port,end_port);
}
fgd_scan();
exit(0);
}
int fgd_len_msg = 1;
/******* HERE SCAN ROUTINE *******/
void fgd_scan() {
current_port = base_port;
printf("Scanning for fgd...\n");
while (current_port <= end_port) {
fprintf(stderr,"Trying port: %d\n",current_port);
sock = socket(PF_INET, SOCK_STREAM, 0);
if (sock == -1) {
fprintf(stderr, "Error assigning master socket: %s\n",sys_errlist[errno]);
exit(-1);
}
address.sin_port = htons(current_port);
printf("address.sin_port : %d\n",htons(address.sin_port));
f_host_info = gethostbyname(src_host);
/* printf ("src_host : %s", ntohs(f_host_info->h_addr)); */
if (connect(sock, (struct sockaddr *)&address, sizeof(address)) == 0) {
/* we determine length of our ip */
fgd_len_msg = (int) sizeof(f_host_info->h_addr);
/* first we send length of ip */
write( sock, &fgd_len_msg,1);
/* then we send our ip */
write( sock, f_host_info->h_addr, fgd_len_msg);
/* we send the command, here 0 : we ask fgd to identify itself */
write( sock, "0", 1);
printf("verbose: %d", verbose);
printf(" Inquiring FGD to identify itself\n");
switch (verbose) {
case 0: printf("%d\n",current_port);
break;
case 1: service_info = getservbyport(htons(current_port),"tcp");
if (!service_info) {
printf("%d -> service name unknown\n",current_port);
} else {
printf("%d -> %s\n",current_port,service_info->s_name);
}
break;
case 2: service_info = getservbyport(htons(current_port),"tcp");
if (!service_info) {
read( sock, &buff, 4);
printf(" Got reply : %s\n", &buff);
if (strncmp(&buff, "FGD", 3) == 0) {
read( sock, &buff, (int) &buff[3]);
printf(" FlightGear-Deamon %s detected.\n", &buff);
break;
}
printf("Port %d found. Service name unknown\n",current_port);
} else {
printf("Port %d found. Service name: %s\n",current_port,service_info->s_name);
}
break;
}
} else if (errno == 113) {
fprintf(stderr,"No route to host !\n");
exit(1);
}
/* fprintf(stderr,"Error %d connecting socket %d to port %d: %s\n",
errno,sock,current_port,sys_errlist[errno]); */
close(sock);
current_port++;
}
if (verbose == 2) printf("FGD scan finished !\n");
}

View file

@ -1,642 +0,0 @@
/*************************************************************/
/* FGD.C 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 */
/* */
/* Version 0.1-alpha */
/* 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 */
/* any physical or moral damage caused by the use of this */
/* software. */
/* */
/* This is a standalone Tool to communicate with any */
/* FlightGear System and FGFS-Deamon. */
/* This is Open Source Software with some parts */
/* shamelessly stolen from others... */
/* */
/* -> This program will use a TCP port listening on a */
/* remote or local host inside the range you give to it. */
/* I offer no warranty over the accuracy though :) */
/* There are 3 verbose modes: No info, service info, and */
/* full info. No info is good of you only want the list */
/* of the ports, no more info. The best mode is Full */
/* info, as you get error information,etc. The main */
/* output is STDOUT, and ALL the errors go to STDERR. */
/* */
/* History: v0.1pre-alpha: May 25 1999 -> First release */
/* v0.1-alpha : Nov 08 1999 */
/*************************************************************/
#include <stdio.h>
#include <sys/socket.h>
#include <sys/types.h>
#include <netinet/in.h>
#include <unistd.h>
#include <netdb.h>
#include <sys/time.h>
#include <fcntl.h>
#include <sys/utsname.h>
// #define printf //
/* Net-stuff */
fd_set rset, allset;
int maxfd, nready, retval;
struct timeval tv;
struct utsname myname;
char *fgd_host, *src_host;
/* Program-stuff */
int verbose, fgd_len_msg;
/* List-stuff (doubly-Linked-list) */
#include <string.h>
#include <stdlib.h>
int i, j, fgd_cnt, fgd_curpos;
char *vb, *fgd_txt;
const int True = 0;
const int False= -1;
float sgFGD_COORD[4][4];
struct list_ele {
unsigned char ipadr[16], callsign[16];
unsigned char lat[8], lon[8], alt[8], speed[8], roll[8], pitch[8], yaw[8];
float latf, lonf, altf, speedf, rollf, pitchf, yawf;
float sgFGD_COORD[4][4];
struct list_ele *next, *prev;
};
struct list_ele *head, *tail, *act, *test, *incoming; /* fgd_msg; */
struct fgd_sock_list {
char adr[16];
int prev_sock;
};
struct fgd_sock_list fgd_cli_list[255];
int fgd_known_cli = -1; /* False */
int fgd_cli = 0;
/*...Create head and tail of list */
void list_init( void) {
incoming = (struct list_ele*) malloc(sizeof(struct list_ele));
head = (struct list_ele*) malloc(sizeof(struct list_ele));
tail = (struct list_ele*) malloc(sizeof(struct list_ele));
if (head == NULL || tail == NULL) { printf("Out of memory\n"); exit(1); }
/* fixme :Where is the "with foobar do command "
head->ipadr = "127.0.0.0";
strcpy(head->callsign, "None");
head->lon = 0;
head->lat = 0;
head->alt = 0;
head->pitch = 0;
head->roll = 0;
head->yaw = 0;
*/
/* yaw!. Who the f$%& invented this ;-) */
head->ipadr[0] = 0;
tail->ipadr[0] = 255;
tail->ipadr[1] = 0;
head->prev = tail->prev = head;
head->next = tail->next = tail;
act = head; /* put listpointer to beginning of list */
}
void list_output( void) {
}
void list_search( char name[16]) {
if (strcmp(name, head->next->ipadr) <= 0) act = head;
else if (strcmp(name, tail->prev->ipadr) > 0) act = tail->prev;
else {
int vergleich = strcmp(name, act->ipadr);
if (vergleich > 0)
while (strcmp(name, act->next->ipadr) > 0) {
act = act->next;
}
else if (vergleich < 0)
while (strcmp(name, act->ipadr) < 0) {
act = act->prev;
}
else
while (strcmp(name, act->ipadr) == 0) {
act = act->prev;
}
}
}
void list_insert( char newip[16]) {
struct list_ele *new_ele;
new_ele = (struct list_ele*) malloc(sizeof(struct list_ele));
if (new_ele == NULL) { printf("Out of memory\n"); exit(1); }
strcpy(new_ele->ipadr, newip);
/* setting default */
strcpy(new_ele->callsign, "not assigned");
list_search( newip);
new_ele->prev = act;
new_ele->next = act->next;
act->next->prev = act->next = new_ele;
}
void list_setval( char newip[16]) {
list_search( newip);
strcpy( act->next->callsign, incoming->callsign);
act->next->latf = incoming->latf;
act->next->lonf = incoming->lonf;
act->next->altf = incoming->altf;
act->next->speedf = incoming->speedf;
act->next->rollf = incoming->rollf;
act->next->pitchf = incoming->pitchf;
act->next->yawf = incoming->yawf;
printf("Callsign %s ", act->next->callsign);
printf(" lat: %7.3f lon: %7.3f alt: %7.3f speed: %7.3f roll: %7.3f pitch: %7.3f yaw: %7.3f",
act->next->latf, act->next->lonf, act->next->altf, act->next->speedf,
act->next->rollf, act->next->pitchf, act->next->yawf);
}
void list_setval_Mat4( char newip[16]) {
list_search( newip);
strcpy( act->next->callsign, incoming->callsign);
for (i=0;i<4;i++)
for (j=0;j<4;j++)
act->next->sgFGD_COORD[i][j] = incoming->sgFGD_COORD[i][j];
printf("Callsign %s ", act->next->callsign);
}
void list_clear( char clrip[16]) {
struct list_ele *clr_ele;
list_search( clrip);
if ( strcmp( clrip, act->next->ipadr))
printf("....Name %s nicht vorhanden", clrip);
else {
clr_ele = act->next;
act->next = act->next->next;
act->next->prev = act;
free( clr_ele);
}
}
int list_not_in( char name[16]) {
i = True;
test = head->next;
while ((test != tail) && (i==True)) {
i = (strcmp(test->ipadr, name) ? True : False);
test = test->next;
if (verbose != 0) printf("list_not_in : %d\n",i);
}
return(i);
}
int sock = -1;
int my_sock;
int fgd_com;
int *ip;
size_t anz;
char buff[1024];
char *fgd_name;
struct { char *adr, *lon, *lat, *alt;} fgd_client;
int fgd_ele_len;
struct sockaddr_in address;
struct sockaddr_in my_address;
int result;
extern char *sys_errlist[];
extern int errno;
int current_port = 0;
u_short base_port = 0;
u_short end_port = 1024;
struct hostent *host_info;
struct servent *service_info;
void fgd_init(void);
int main(int argc, char **argv)
{
if (argc < 4) {
fprintf(stderr,"Usage: fgd [start port] [end port] [name] <-v or -vv>\n");
exit(1);
}
switch (argc) {
case 5: if (!strcmp(argv[4],"-v"))
verbose = 1;
else if (!strcmp(argv[4],"-vv"))
verbose = 2;
else { fprintf(stderr,"Usage: fgd [start port] [end port] [name] <-v or -vv>\n");
exit(1); }
case 4: base_port = (u_short)atoi(argv[1]);
end_port = (u_short)atoi(argv[2]);
fgd_name = argv[3];
break;
default: fprintf(stderr,"Usage: fgd [start port] [end port] [name] <-v or -vv>\n");
exit(1);
break;
}
bzero((char *)&address, sizeof(address));
address.sin_family = AF_INET;
if (uname(&myname) == 0) fgd_host = myname.nodename;
printf(" I am running as %s on HOST %s\n", fgd_name, fgd_host);
if (verbose == 2) printf(" Resolving: %s ->",fgd_host);
if (host_info = gethostbyname(fgd_host)) {
bcopy(host_info->h_addr, (char *)&address.sin_addr,host_info->h_length);
printf(" fgd : ip = %s\n", inet_ntoa( address.sin_addr));
if (verbose == 2) printf(" resolved\n");
} else if ((address.sin_addr.s_addr = inet_addr(fgd_host)) == INADDR_NONE) {
fprintf(stderr,"Could not get %s host entry !\n",argv[1]);
printf(" NOT resolved !!!\n");
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);
} else if (verbose == 2) {
printf(" Port range: %d to %d\n",base_port,end_port);
}
printf(" verbose: %d\n",verbose);
/* some init stuff */
fgd_txt = (char *) malloc(1024);
list_init();
fgd_init();
exit(0);
}
void fgd_init(void) {
struct { char *ip, *lon, *lat, *alt;} fg_id;
current_port = base_port;
while (current_port <= end_port) {
sock = socket(PF_INET, SOCK_STREAM, 0);
if (sock == -1)
{
fprintf(stderr, "Error assigning master socket: %s\n",sys_errlist[errno]);
exit(-1);
}
address.sin_port = htons(current_port);
if (verbose == 2) printf(" address.sin_port : %d\n",htons(address.sin_port));
if (1 == 1) {
if ( bind(sock, (struct sockaddr *)&address, sizeof(address)) == -1) {
printf(" Aiiiieeehh...ADRESS ALSO IN USE...\7hmmm...please check another port\n");
exit(-1);
}
listen(sock, 5);
/* Hier neu */
maxfd = sock;
FD_ZERO( &allset);
FD_SET( sock, &allset);
for (;;){
rset = allset;
tv.tv_sec = 1;
tv.tv_usec = 0;
nready = select( sock + 1, &rset, NULL, NULL, &tv);
if (FD_ISSET( sock, &rset)) {
my_sock = accept( sock, (struct sockaddr *)&address, (int*) sizeof(address));
anz = 2;
/* reading length of senders' ip */
fgd_ele_len = 0;
read( my_sock, buff, 1);
fgd_ele_len = buff[0];
if (verbose == 2) printf("ele_len %d\n", fgd_ele_len);
/* reading senders' ip */
read( my_sock, &buff, fgd_ele_len);
ip = (int *) buff;
// printf("%d %d %d %d %x %x %x\n", buff[0], buff[1], buff[2], buff[3], &ip, ip, *ip);
fgd_client.adr = (char*) inet_ntoa( *ip);
src_host = fgd_client.adr;
/* reading commando */
read( my_sock, &buff, 1);
/* closing previous file descriptor of same client, at least we know now
that the previous command is finished since it's the same client who
again requests something. Maybe I'm to quick and diiirty ;-) */
printf("FGD : Using socket #%d\n", my_sock);
fgd_known_cli = False;
for ( fgd_cnt = 1; fgd_cnt < fgd_cli+1; fgd_cnt++) {
printf("FGD : fgd_cnt:%d fgd_cli:%d fgd_client.adr: %s prev.sock:%d fgd_cli_list[fgd_cnt].adr: %s\n",
fgd_cnt, fgd_cli, fgd_client.adr,
fgd_cli_list[fgd_cnt].prev_sock, fgd_cli_list[fgd_cnt].adr);
if ( strcmp( fgd_cli_list[fgd_cnt].adr, fgd_client.adr) == 0) {
printf("FGD : In Vergleichsloop. Closing socket: %d\n",
fgd_cli_list[fgd_cnt].prev_sock);
close( fgd_cli_list[fgd_cnt].prev_sock);
fgd_cli_list[fgd_cnt].prev_sock = my_sock;
fgd_known_cli = True;
}
}
if ( fgd_known_cli == False) {
fgd_cli++;
fgd_cli_list[fgd_cli].prev_sock = my_sock;
strcpy(fgd_cli_list[fgd_cli].adr, fgd_client.adr);
}
printf(" Commando received : %s from Host : %s\n", &buff, src_host);
fgd_com = ( (char) buff[0]) - 0x30;
printf("%d \n", fgd_com);
switch (fgd_com) {
case 0: printf(" fgd : Identify\n");
sprintf( (char*) buff, "FGDLH%s", fgd_name);
buff[3] = strlen(fgd_name) + 1; /* Lo, incl.zero */
buff[4] = 0; /* Hi, names < 0xff ! */
buff[buff[3] + 4] = 0; /* Term.zero */
printf(" I am : %s\n", fgd_name);
write( my_sock, &buff, buff[3]+5); /* fgd housekeeping ;-) */
// close(my_sock);
break;
case 1: printf(" fgd : Register\n");
/* reading length of FGFS_host ip */
fgd_ele_len = 0;
read( my_sock, &buff, 1);
fgd_ele_len = (int) &buff;
/* reading FGFS_host ip */
read( my_sock, &buff, fgd_ele_len);
ip = (int *) buff;
fgd_client.adr = (char*) inet_ntoa( *ip);
if (list_not_in(fgd_client.adr) == True) {
list_insert(fgd_client.adr);
list_search(fgd_client.adr);
// strcpy(act->callsign, "None");
printf(" Setting default values\n");
printf(" IP : %s\n", act->next->ipadr);
printf(" PILOT : %s\n", act->next->callsign);
}
/* writing answer back to client */
sprintf( (char*) buff, "FGDLH%s", fgd_client.adr);
buff[3] = strlen(fgd_client.adr) + 1; /* Lo, incl.zero */
buff[4] = 0; /* Hi, names < 0xff ! */
buff[buff[3] + 4] = 0; /* Term.zero */
write( my_sock, &buff, buff[3]+5); /* fgd housekeeping ;-) */
// close(my_sock);
break;
case 2: printf(" fgd : Show Registered\n");
sprintf( (char*) buff, "FGD");
// buff[3] = buff[4] = 0;
fgd_cnt = 0;
fgd_curpos = 6;
test = head->next;
while (test != tail) {
printf(" IP : %s\n", test->ipadr);
fgd_cnt++;
fgd_ele_len = strlen(test->ipadr) + 1;
// printf(" ele_len %d curpos %d\n", fgd_ele_len, fgd_curpos);
buff[fgd_curpos] = fgd_ele_len;
fgd_curpos++;
bcopy(test->ipadr, &buff[fgd_curpos], fgd_ele_len);
fgd_curpos += fgd_ele_len;
//buff[fgd_curpos] = 0;
test = test->next;
}
if (fgd_cnt == 0) fgd_curpos--;
buff[3] = fgd_curpos & 0xff;
buff[4] = fgd_curpos >> 8;
buff[5] = fgd_cnt;
write( my_sock, &buff, fgd_curpos);
// close(my_sock);
break;
case 3: printf(" fgd : Send MSG\n");
// close(my_sock);
break;
case 4: printf(" fgd : Send MSG to all\n");
// close(my_sock);
break;
case 5: printf(" fgd : Get DATA from client\n");
read( my_sock, &buff, 1);
fgd_ele_len = buff[0];
read( my_sock, &buff, fgd_ele_len);
ip = (int *) buff;
fgd_client.adr = (char*) inet_ntoa( *ip);
printf(" IP : %s\n", fgd_client.adr);
if (verbose != 0) printf("not_in (CASE) : %d\n", list_not_in(fgd_client.adr));
if (list_not_in(fgd_client.adr) == False) {
printf(" Checkpoint\n");
read( my_sock, &buff, 1);
printf(" Checkpoint 1\n");
fgd_ele_len = buff[0];
read( my_sock, &buff, fgd_ele_len);
incoming->callsign[fgd_ele_len] = 0;
bcopy( &buff, incoming->callsign, fgd_ele_len);
/* lat, lon */
read( my_sock, &buff, 56);
sscanf( buff," %7f %7f %7f %7f %7f %7f %7f", &incoming->latf, &incoming->lonf,
&incoming->altf, &incoming->speedf, &incoming->rollf,
&incoming->pitchf, &incoming->yawf);
printf(" lat :%7.3f\n lon :%7.3f\n alt :%7.3f\n speed :%7.3f\n roll :%7.3f\n pitch :%7.3f\n yaw :%7.3f\n",
incoming->latf, incoming->lonf, incoming->altf, incoming->speedf,
incoming->rollf, incoming->pitchf, incoming->yawf);
list_setval(fgd_client.adr);
}
else strcpy( fgd_client.adr, "UNKNOWN");
/* writing answer back to client */
sprintf( (char*) buff, "%s %s", "FGD", fgd_client.adr);
buff[3] = strlen(fgd_client.adr);
printf(" IP : %s\n", fgd_client.adr);
write( my_sock, &buff, buff[3]+4);
// close(my_sock);
break;
case 17: printf(" fgd : Get Mat4 DATA from client\n");
read( my_sock, &buff, 1);
fgd_ele_len = buff[0];
read( my_sock, &buff, fgd_ele_len);
ip = (int *) buff;
fgd_client.adr = (char*) inet_ntoa( *ip);
printf(" IP : %s\n", fgd_client.adr);
if (verbose != 0) printf("not_in (CASE) : %d\n", list_not_in(fgd_client.adr));
if (list_not_in(fgd_client.adr) == False) {
printf(" Checkpoint\n");
read( my_sock, &buff, 1);
printf(" Checkpoint 1\n");
fgd_ele_len = buff[0];
read( my_sock, &buff, fgd_ele_len);
incoming->callsign[fgd_ele_len] = 0;
bcopy( &buff, incoming->callsign, fgd_ele_len);
/* lat, lon */
read( my_sock, &buff, 158);
i = sscanf( buff," %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f",
&incoming->sgFGD_COORD[0][0], &incoming->sgFGD_COORD[0][1], &incoming->sgFGD_COORD[0][2], &incoming->sgFGD_COORD[0][3],
&incoming->sgFGD_COORD[1][0], &incoming->sgFGD_COORD[1][1], &incoming->sgFGD_COORD[1][2], &incoming->sgFGD_COORD[1][3],
&incoming->sgFGD_COORD[2][0], &incoming->sgFGD_COORD[2][1], &incoming->sgFGD_COORD[2][2], &incoming->sgFGD_COORD[2][3],
&incoming->sgFGD_COORD[3][0], &incoming->sgFGD_COORD[3][1], &incoming->sgFGD_COORD[3][2], &incoming->sgFGD_COORD[3][3]);
// printf(" sscanf input: %d\n",i);
printf(" sgMat4: \n%f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f\n",
incoming->sgFGD_COORD[0][0], incoming->sgFGD_COORD[0][1], incoming->sgFGD_COORD[0][2], incoming->sgFGD_COORD[0][3],
incoming->sgFGD_COORD[1][0], incoming->sgFGD_COORD[1][1], incoming->sgFGD_COORD[1][2], incoming->sgFGD_COORD[1][3],
incoming->sgFGD_COORD[2][0], incoming->sgFGD_COORD[2][1], incoming->sgFGD_COORD[2][2], incoming->sgFGD_COORD[2][3],
incoming->sgFGD_COORD[3][0], incoming->sgFGD_COORD[3][1], incoming->sgFGD_COORD[3][2], incoming->sgFGD_COORD[3][3]);
list_setval_Mat4(fgd_client.adr);
}
else strcpy( fgd_client.adr, "UNKNOWN");
/* writing answer back to client */
sprintf( (char*) buff, "FGDLH%s", fgd_client.adr);
buff[3] = strlen(fgd_client.adr) + 1;
buff[4] = buff[buff[3]+5] = 0;
printf(" IP : %s\n", fgd_client.adr);
write( my_sock, &buff, buff[3]+5);
// close(my_sock);
break;
case 6: printf(" fgd : Send all DATA to client\n");
sprintf( (char*) buff, "%s %s", "FGD", fgd_client.adr);
buff[3] = 0;
fgd_cnt = 0;
fgd_curpos = 5;
test = head->next;
while (test != tail) {
printf(" IP : %-16s Callsign : %-16s\n", test->ipadr, test->callsign);
fgd_cnt++;
/* IP */
fgd_ele_len = strlen(test->ipadr);
printf(" ele_len %d curpos %d\n", fgd_ele_len, fgd_curpos);
buff[fgd_curpos] = fgd_ele_len;
fgd_curpos++;
bcopy(test->ipadr, &buff[fgd_curpos], fgd_ele_len);
fgd_curpos = fgd_curpos + fgd_ele_len;
/* Callsign */
fgd_ele_len = strlen(test->callsign);
printf(" ele_len %d curpos %d\n", fgd_ele_len, fgd_curpos);
buff[fgd_curpos] = fgd_ele_len;
fgd_curpos++;
bcopy(test->callsign, &buff[fgd_curpos], fgd_ele_len);
fgd_curpos = fgd_curpos + fgd_ele_len;
/* Lat, Lon, Alt, Speed, Roll, Pitch, Yaw
hope this sprintf call is not too expensive */
sprintf( fgd_txt, " %7.3f %7.3f %7.3f %7.3f %7.3f %7.3f %7.3f",
test->latf, test->lonf, test->altf, test->speedf,
test->rollf, test->pitchf, test->yawf);
printf(" ele_len %d curpos %d\n", fgd_ele_len, fgd_curpos);
printf(" Data : %s\n", fgd_txt);
bcopy((char *) fgd_txt, &buff[fgd_curpos], 56);
fgd_curpos += 56;
test = test->next;
}
if (fgd_cnt == 0) fgd_curpos --;
printf(" ele_len %d curpos %d\n", fgd_ele_len, fgd_curpos);
buff[3] = fgd_curpos;
buff[4] = fgd_cnt;
write( my_sock, &buff, fgd_curpos);
// close(my_sock);
break;
case 18: printf(" fgd : Send all Mat4 DATA to client\n");
sprintf( (char*) buff, "FGDLH");
buff[3] = buff[4] = 0;
fgd_cnt = 0;
fgd_curpos = 6;
test = head->next;
while (test != tail) {
printf(" IP : %-16s Callsign : %-16s\n", test->ipadr, test->callsign);
fgd_cnt++;
/* IP */
fgd_ele_len = strlen(test->ipadr);
printf(" ele_len %d curpos %d\n", fgd_ele_len, fgd_curpos);
buff[fgd_curpos] = fgd_ele_len;
fgd_curpos++;
bcopy(test->ipadr, &buff[fgd_curpos], fgd_ele_len);
fgd_curpos = fgd_curpos + fgd_ele_len;
/* Callsign */
fgd_ele_len = strlen(test->callsign);
printf(" ele_len %d curpos %d\n", fgd_ele_len, fgd_curpos);
buff[fgd_curpos] = fgd_ele_len;
fgd_curpos++;
bcopy(test->callsign, &buff[fgd_curpos], fgd_ele_len);
fgd_curpos = fgd_curpos + fgd_ele_len;
/* Lat, Lon, Alt, Speed, Roll, Pitch, Yaw
hope this sprintf call is not too expensive */
fgd_len_msg = sprintf( fgd_txt, " %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f",
test->sgFGD_COORD[0][0], test->sgFGD_COORD[0][1], test->sgFGD_COORD[0][2], test->sgFGD_COORD[0][3],
test->sgFGD_COORD[1][0], test->sgFGD_COORD[1][1], test->sgFGD_COORD[1][2], test->sgFGD_COORD[1][3],
test->sgFGD_COORD[2][0], test->sgFGD_COORD[2][1], test->sgFGD_COORD[2][2], test->sgFGD_COORD[2][3],
test->sgFGD_COORD[3][0], test->sgFGD_COORD[3][1], test->sgFGD_COORD[3][2], test->sgFGD_COORD[3][3]);
fgd_txt[fgd_len_msg] = 0;
printf(" ele_len %d curpos %d\n", fgd_ele_len, fgd_curpos);
printf(" Data : %s\n", fgd_txt);
bcopy((char *) fgd_txt, &buff[fgd_curpos], fgd_len_msg+1);
fgd_curpos += fgd_len_msg+1;
test = test->next;
}
if (fgd_cnt == 0) fgd_curpos -= 1;
printf(" ele_len %d curpos %d\n", fgd_ele_len, fgd_curpos);
buff[3] = fgd_curpos & 0xff;
buff[4] = fgd_curpos / 256;
buff[5] = fgd_cnt;
printf("ANZ: %d CURPOS: %d\n", (unsigned char) buff[3] + (unsigned char) buff[4] * 256, fgd_curpos);
write( my_sock, &buff, fgd_curpos);
// close(my_sock);
break;
case 8: printf(" fgd : Unregister\n");
read( my_sock, &buff, 1);
fgd_ele_len = (int) &buff;
read( my_sock, &buff, fgd_ele_len);
ip = (int *) buff;
fgd_client.adr = (char*) inet_ntoa( *ip);
printf(" IP : %s\n", fgd_client.adr);
if (verbose != 0) printf("not_in (CASE) : %d\n", list_not_in(fgd_client.adr));
if (list_not_in(fgd_client.adr) == -1) {
list_clear(fgd_client.adr);
}
else strcpy( fgd_client.adr, "UNKNOWN");
/* writing answer back to client */
sprintf( (char*) buff, "%s %s", "FGD", fgd_client.adr);
buff[3] = strlen(fgd_client.adr);
printf(" IP : %s\n", fgd_client.adr);
write( my_sock, &buff, buff[3]+4);
// close(my_sock);
break;
case 9: printf(" fgd : Shutdown\n");
close(my_sock);
close(sock);
exit(0);
default: printf(" fgd : Huh?...Unknown Command\n");
break;
}
}
}
/*
switch (verbose) {
case 0: printf("%d\n",base_port+current_port);
break;
case 1: service_info = getservbyport(htons(base_port+current_port),"tcp");
if (!service_info) {
printf("%d -> service name unknown\n",base_port+current_port);
} else {
printf("%d -> %s\n",base_port+current_port,service_info->s_name);
}
break;
case 2: service_info = getservbyport(htons(base_port+current_port),"tcp");
if (!service_info) {
printf("Port %d found. Service name unknown\n",base_port+current_port);
} else {
printf("Port %d found. Service name: %s\n",base_port+current_port,service_info->s_name);
}
break;
}
*/
} else if (errno == 113) {
fprintf(stderr,"No route to host !\n");
exit(1);
}
/* current_port++; */
}
if (verbose == 2) printf("Port scan finished !\n");
}

View file

@ -1,23 +0,0 @@
#ifndef _MSC_VER
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <unistd.h>
#include <netdb.h>
#include <sys/time.h>
#include <fcntl.h>
#include <sys/utsname.h>
/* this seems to be missing for glibc-2.0.x */
/* libc5 & glibc-2.1 do have them */
#ifndef MSG_PEEK
#define MSG_PEEK 0x02 /* Peek at incoming messages. */
#endif
#ifndef MSG_WAITALL
#define MSG_WAITALL 0x100 /* Wait for a full request. */
#endif
#endif /* !_MSC_VER */

View file

@ -1,95 +0,0 @@
// network.cxx -- data structures for managing network.
//
// Written by Oliver Delise, started May 1999.
//
// Copyleft (C) 1999 Oliver Delise - delise@mail.isis.de
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License as
// published by the Free Software Foundation; either version 2 of the
// License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful, but
// WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
// General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
//
// $Id$
#ifdef HAVE_CONFIG_H
# include <config.h>
#endif
/*
#ifdef HAVE_WINDOWS_H
# include <windows.h>
#endif
#ifdef __BORLANDC__
# define exception c_exception
#endif
#include <math.h>
#include FG_GLUT_H
#include <stdlib.h>
#include <string.h>
#ifdef HAVE_VALUES_H
# include <values.h> // for MAXINT
#endif
#include <simgear/logstream.hxx>
#include <simgear/constants.h>
#include <simgear/fg_random.h>
#include <simgear/polar3d.hxx>
#include <Aircraft/aircraft.hxx>
#include <GUI/gui.h>
#include <Scenery/scenery.hxx>
#include <Time/fg_timer.hxx>
#if defined ( __sun__ ) || defined ( __sgi )
extern "C" {
extern void *memmove(void *, const void *, size_t);
}
#endif
*/
#include <Cockpit/hud.hxx>
#include <NetworkOLK/network.h>
extern char *fgd_callsign;
void net_hud_update(){
static char fgd_str[80];
static float fgd_lon, fgd_lat, fgd_alt;
int LinePos;
fgd_lon = get_longitude();
fgd_lat = get_latitude();
fgd_alt = get_altitude();
// sprintf(fgd_str,"Found %s %3.3f %3.3f", net_callsign, fgd_lat, fgd_lon);
// HUD_TextList.add( fgText( 40, 18, fgd_str) );
other = head->next;
LinePos = 38;
while ( other != tail) {
if ( strcmp( other->ipadr, fgd_mcp_ip) != 0 ) {
sprintf( fgd_str, "%-16s%-16s", other->callsign, other->ipadr);
HUD_TextList.add( fgText( 40, LinePos, fgd_str) );
LinePos += 13;
}
other = other->next;
}
sprintf(fgd_str,"%-16s%-16s", fgd_callsign, fgd_mcp_ip);
HUD_TextList.add( fgText( 40, LinePos ,fgd_str) );
sprintf(fgd_str,"Callsign IP");
HUD_TextList.add( fgText( 40, LinePos + 13 ,fgd_str) );
}

View file

@ -1,696 +0,0 @@
/*************************************************************/
/* NET_SEND.CXX by Oliver Delise */
/* Contact info: */
/* e-mail: delise@mail.isis.de */
/* www: http://www.isis.de/members/odelise/progs/flightgear */
/* */
/* 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 */
/* any physical or moral damage caused by the use of this */
/* software. */
/* */
/* This is an interactive standalone Tool to communicate */
/* with any FlightGear-Deamon. */
/* This is Open Source Software with many parts */
/* shamelessly stolen from others... */
/* */
/* -> This program will use a TCP port listening on a */
/* remote or local host inside the range you give to it. */
/* I offer no warranty over the accuracy though :) */
/* There are 3 verbose modes: No info, service info, and */
/* full info. No info is good of you only want the list */
/* of the ports, no more info. The best mode is Full */
/* info, as you get error information,etc. The main */
/* output is STDOUT, and ALL the errors go to STDERR. */
/* */
/* 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 <plib/ssg.h>
#include <Main/globals.hxx>
#include <Main/viewmgr.hxx>
#include <Model/loader.hxx>
//#define printf //
/* Netstuff */
#include <arpa/inet.h>
int sock = -1;
int my_sock;
struct sockaddr_in address;
struct sockaddr_in my_address;
int result;
//#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;
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;
int fgd_len_msg = 1, fgd_reply_len, fgd_status, fgd_ele_len, fgd_curpos, fgd_cnt, fgd_ppl,
fgd_ppl_old, fgd_loss, net_r;
size_t anz;
char *fgd_job, *fgd_callsign, *fgd_name, *fgd_ip, *fgd_mcp_ip;
char *buffp, *src_host, *fgd_host, *fgfs_host, *fgfs_pilot, *fgd_txt;
sgMat4 sgFGD_COORD;
extern sgMat4 sgFGD_VIEW;
extern ssgRoot *fgd_scene;
extern char *FGFS_host, *net_callsign;
/* List-stuff */
const int listTrue = 0;
const int listFalse= -1;
struct list_ele {
/* unsigned */ char ipadr[16], callsign[16];
/* unsigned */ char lon[8], lat[8], alt[8], roll[8], pitch[8], yaw[8];
float lonf, latf, altf, speedf, rollf, pitchf, yawf;
sgMat4 sgFGD_COORD;
ssgSelector *fgd_sel;
ssgTransform *fgd_pos;
struct list_ele *next, *prev;
};
struct list_ele *head, *tail, *act, *test, *incoming, *boss, *other; /* fgd_msg; */
/*...Create head and tail of list */
void list_init( void) {
incoming = (struct list_ele*) malloc(sizeof(struct list_ele));
boss = (struct list_ele*) malloc(sizeof(struct list_ele));
other = (struct list_ele*) malloc(sizeof(struct list_ele));
head = (struct list_ele*) malloc(sizeof(struct list_ele));
tail = (struct list_ele*) malloc(sizeof(struct list_ele));
if (head == NULL || tail == NULL) { printf("Out of memory\n"); exit(1); }
head->ipadr[0] = 0;
tail->ipadr[0] = 255;
tail->ipadr[1] = 0;
head->prev = tail->prev = head;
head->next = tail->next = tail;
act = head; /* put listpointer to beginning of list */
}
void list_output( void) {
}
void list_search( char name[16]) {
if (strcmp(name, head->next->ipadr) <= 0) act = head;
else if (strcmp(name, tail->prev->ipadr) > 0) act = tail->prev;
else {
int vergleich = strcmp(name, act->ipadr);
if (vergleich > 0)
while (strcmp(name, act->next->ipadr) > 0) {
act = act->next;
}
else if (vergleich < 0)
while (strcmp(name, act->ipadr) < 0) {
act = act->prev;
}
else
while (strcmp(name, act->ipadr) == 0) {
act = act->prev;
}
}
}
void list_insert( char newip[16]) {
struct list_ele *new_ele;
new_ele = (struct list_ele*) malloc(sizeof(struct list_ele));
if (new_ele == NULL) { printf("Out of memory\n"); exit(1); }
strcpy(new_ele->ipadr, newip);
/* setting default */
strcpy(new_ele->callsign, "not assigned");
/* generating ssg stuff */
new_ele->fgd_sel = new ssgSelector;
new_ele->fgd_pos = new ssgTransform;
ssgEntity *fgd_obj = globals->get_model_loader()->load_model( "tuxcopter.ac" );
fgd_obj->clrTraversalMaskBits( SSGTRAV_HOT );
new_ele->fgd_pos->addKid( fgd_obj );
new_ele->fgd_sel->addKid( new_ele->fgd_pos );
ssgFlatten( fgd_obj );
ssgStripify( new_ele->fgd_sel );
fgd_scene->addKid( new_ele->fgd_sel );
fgd_scene->addKid( fgd_obj );
/* ssgKid "born" and inserted into scene */
list_search( newip);
new_ele->prev = act;
new_ele->next = act->next;
act->next->prev = act->next = new_ele;
}
void list_setval( char newip[16]) {
list_search( newip);
strcpy( act->next->callsign, incoming->callsign);
printf("Callsign %s\n", act->next->callsign);
}
void list_clear( char clrip[16]) {
struct list_ele *clr_ele;
list_search( clrip);
if ( strcmp( clrip, act->next->ipadr))
printf("....Name %s nicht vorhanden", clrip);
else {
clr_ele = act->next;
act->next = act->next->next;
act->next->prev = act;
free( clr_ele);
}
}
int list_not_in( char name[16]) {
i = listTrue;
test = head->next;
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;
}
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",
m[1][0], m[1][1], m[1][2], m[1][3] );
printf("2.0 %f 2.1 %f 2.2 %f 2.3 %f\n",
m[2][0], m[2][1], m[2][2], m[2][3] );
printf("3.0 %f 3.1 %f 3.2 %f 3.3 %f\n",
m[3][0], m[3][1], m[3][2], m[3][3] );
}
void fgd_init(void){
/* Let's init a few things */
printf("MCP: Allocating memory...");
buffp = (char *) malloc(1024); /* No I don't check if there are another KB */
fgd_job = (char *) malloc(8);
fgd_host = (char *) malloc(64);
fgd_callsign = (char *) malloc(64);
fgd_name = (char*) malloc(64);
fgd_ip = (char *) malloc(16);
fgd_mcp_ip = (char *) malloc(16);
fgfs_host = (char *) malloc(64);
fgfs_pilot = (char *) malloc(64);
src_host = (char *) malloc(64);
fgd_txt = (char *) malloc(1024);
printf("ok\nMCP: Initializing values...");
strcpy( fgd_job, "xxx");
strcpy( fgd_host, "Olk");
strcpy( fgd_callsign, "Unknown");
strcpy( fgd_name, "Unknown");
strcpy( fgd_ip, (char *) inet_ntoa(address.sin_addr));
strcpy( fgd_txt, "");
printf("ok\n");
boss->latf = 112.3;
boss->lonf = 4.5;
boss->altf = 0.67;
boss->speedf = 100.95;
boss->rollf = 89.0;
boss->pitchf = 1.23;
boss->yawf = 456.789;
fgd_ppl = 0;
bzero((char *)&address, sizeof(address));
address.sin_family = AF_INET;
/* 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)) != 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));
}
printf("IP : %s\n", fgd_mcp_ip);
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)) != 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) {
printf(" resolved\n FGD running on HOST : %s", fgd_host);
printf(" IP : %s\n", fgd_ip);
}
} 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);
} 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",base_port,end_port);
// exit(1);
} else if (verbose == 2) {
printf(" Port range: %d to %d\n",base_port,end_port);
}
}
int net_resolv_fgd( char *fgd_host_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)) != 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;
if (verbose == 0) {
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;
}
} 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;
// 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",base_port,end_port);
// exit(1);
net_r = -2;
return -2;
} else if (verbose == 2) {
printf(" Port range: %d to %d\n",base_port,end_port);
}
return 0;
}
void fgd_send_com( char *FGD_com, char *FGFS_host) {
strcpy( buffp, " ");
// current_port = base_port;
if (verbose == 2) printf(" Sending : %s\n", FGD_com);
// while (current_port <= end_port) {
/* fprintf(stderr,"Trying port: %d\n",current_port); */
sock = socket(PF_INET, SOCK_STREAM, 0);
if (sock == -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);
if (verbose == 2) printf(" address.sin_port : %d\n",htons(address.sin_port));
f_host_info = gethostbyname(src_host);
//printf ("src_host : %s", ntohs(f_host_info->h_addr));
if (connect(sock, (struct sockaddr *)&address, sizeof(address)) == 0) {
/* FIXME: make a single string instead of sending elements */
fgd_len_msg = (int) sizeof(f_host_info->h_addr);
/* send length of sender-ip */
write( sock, &fgd_len_msg,1);
/* send sender-ip */
write( sock, f_host_info->h_addr, fgd_len_msg);
/* send commando */
write( sock, FGD_com, 1);
/* send length of dummy-string, for the moment with _WHO_ to execute commando
here: his length of ip */
f_host_info = gethostbyname(FGFS_host);
fgd_len_msg = (int) sizeof(f_host_info->h_addr);
write( sock, &fgd_len_msg,1);
/* send dummy-string, for the moment with _WHO_ to execute commando
here: his ip */
write( sock, f_host_info->h_addr, fgd_len_msg);
/* END FIXME */
/* Here we send subsequent data... */
switch ( (char) FGD_com[0] - 0x30) {
case 5: fgd_len_msg = strlen( net_callsign);
write( sock, &fgd_len_msg,1);
/* send string, for the moment, here: callsign */
write( sock, net_callsign, fgd_len_msg);
/* Lon, Lat, Alt, Speed, Roll, Pitch, Yaw
hope this sprintf call is not too expensive */
sprintf( fgd_txt, " %7.3f %7.3f %7.3f %7.3f %7.3f %7.3f %7.3f",
// boss->latf, boss->lonf, boss->altf, boss->speedf,
// boss->rollf, boss->pitchf, boss->yawf);
/*
Must decide if it's better to send values "as are" or convert them for
deamon, better is to let deamon make the job. Anyway this will depend on
speed loss/gain in network-area...
*/
get_latitude(), get_longitude(), get_altitude(),
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, globals->get_current_view()->get_VIEW());
if (verbose == 2) {
printf("current_view\n");
fgd_print_Mat4( globals->get_current_view()->get_VIEW());
printf("FGD_COORD\n");
fgd_print_Mat4( sgFGD_COORD);
}
fgd_len_msg = strlen( net_callsign);
write( sock, &fgd_len_msg,1);
/* send string, for the moment, here: callsign */
write( sock, net_callsign, fgd_len_msg);
/* MATRIX-variant of Lon, Lat etc...
hope this sprintf call is not too expensive */
fgd_len_msg = sprintf( fgd_txt, " %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f",
sgFGD_COORD[0][0], sgFGD_COORD[0][1], sgFGD_COORD[0][2], sgFGD_COORD[0][3],
sgFGD_COORD[1][0], sgFGD_COORD[1][1], sgFGD_COORD[1][2], sgFGD_COORD[1][3],
sgFGD_COORD[2][0], sgFGD_COORD[2][1], sgFGD_COORD[2][2], sgFGD_COORD[2][3],
sgFGD_COORD[3][0], sgFGD_COORD[3][1], sgFGD_COORD[3][2], sgFGD_COORD[3][3]);
fgd_txt[fgd_len_msg] = 0;
write( sock, fgd_txt, fgd_len_msg+1);
break;
default: break;
}
/* be verbose, this goes later into own (*void) */
if (verbose == 2) printf(" Message : %s\n", FGD_com);
switch (verbose) {
case 0: // printf("%d\n",current_port);
break;
case 1: service_info = getservbyport(htons(current_port),"tcp");
if (!service_info) {
printf("%d -> service name unknown\n",current_port);
} else {
printf("%d -> %s\n",current_port,service_info->s_name);
}
break;
case 2: service_info = getservbyport(htons(current_port),"tcp");
if (!service_info) {
printf(" Port %d found. Service name unknown\n",current_port);
} else {
printf(" Port %d found. Service name: %s\n",current_port,service_info->s_name);
}
break;
}
} else if (errno == 113) {
fprintf(stderr,"No route to host !\n");
/* must check this */
// exit(1);
}
/* fprintf(stderr,"Error %d connecting socket %d to port %d: %s\n",
errno,sock,current_port,sys_errlist[errno]); */
// service_info = getservbyport(htons(current_port),"tcp");
// if (!service_info) {
/* The Receiving Part, fgd returns errormessages, succes, etc... */
do {
fgd_status = recv( sock, (char *) buffp, 5, MSG_WAITALL);
if (verbose == 2) printf(" status %d\n", fgd_status);
}
// while ( (fgd_status != 5) && (fgd_status != 0) );
while ( (fgd_status == -1) || (fgd_status == -1) );
fgd_reply_len = (unsigned char) buffp[3] + (unsigned char) buffp[4] * 256;
if (verbose == 2) {
printf(" Got reply : %x %x %x MSG length %d Bytes\n",
buffp[0], buffp[1], buffp[2], fgd_reply_len);
}
if (strncmp( buffp, "FGD", 3) == 0) {
switch ( (char) FGD_com[0] - 0x30) {
case 0: int abc;
abc = read( sock, fgd_name, fgd_reply_len);
if (verbose == 2) printf("readwert: %d", abc);
// fgd_name[buffp[3]] = 0;
printf("FGD: FlightGear-Deamon %s detected\n", fgd_name);
break;
case 1: read( sock, fgd_txt, fgd_reply_len);
printf("FGD: Registering Host %s\n", fgd_txt);
break;
case 2: printf("FGD: Showing registered Hosts at %s\n", fgd_host);
if ( fgd_reply_len != 5) {
/* FIXME: replace with SELECT to avoid broken pipes, known bug (-; */
do {
fgd_status = recv( sock, fgd_txt, fgd_reply_len - 5,
MSG_WAITALL);
// printf(" status %d\n", fgd_status);
}
// while ( (fgd_status != 5) && (fgd_status != 0) );
while ( (fgd_status == -1) || (fgd_status == -1) );
// read( sock, fgd_txt, fgd_reply_len - 5);
fgd_curpos = 1;
for (fgd_cnt = 1; fgd_cnt < (fgd_txt[0]+1); fgd_cnt++) {
fgd_ele_len = fgd_txt[fgd_curpos];
bcopy( &fgd_txt[fgd_curpos], fgfs_host, fgd_ele_len);
// fgfs_host[fgd_ele_len] = 0;
fgd_curpos += fgd_ele_len + 1;
if (verbose == 2) printf(" #%d %s\n", fgd_cnt, fgfs_host);
}
}
break;
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);
// fgd_txt[buffp[3]] = 0;
if (strcmp(fgd_txt, "UNKNOWN") == -1) {
if (verbose == 2) printf("FGD: Mat4 Data from Host %s received\n", fgd_txt);
}
else printf("FGD: Host not in list, sorry...\n");
break;
case 6: printf("FGD: Sending data to Host %s\n", FGFS_host);
if (buffp[3] != 4) {
/* FIXME: replace with SELECT */
if (verbose == 2) printf("Noch %d bytes\n", (unsigned char) buffp[3]);
do {
fgd_status = recv( sock, fgd_txt, (unsigned char) buffp[3]-4, MSG_PEEK);
if (verbose == 2) printf("Status %d\n", fgd_status);
}
while ( (fgd_status == 4) || (fgd_status == -1) );
// while ( (fgd_status == -1) || (fgd_status == -1) );
read( sock, fgd_txt, buffp[3]-4);
fgd_curpos = 2;
fgd_ppl_old = fgd_ppl;
fgd_ppl = fgd_txt[0];
/* Check if list has changed (pilot joined/left) */
if (fgd_ppl != fgd_ppl_old) {
printf(" List changed!!!\n");
for (fgd_cnt = 1; fgd_cnt <= abs(fgd_ppl - fgd_ppl_old); fgd_cnt++) {
if (verbose == 2) printf(" Checkpoint\n");
incoming = head->next;
if ((fgd_ppl - fgd_ppl_old) > 0) list_insert("test\0");
else {
printf(" Clearing entry.\n");
list_clear(incoming->ipadr);
}
}
}
// else {
incoming = head->next;
for (fgd_cnt = 1; fgd_cnt < (fgd_ppl+1); fgd_cnt++) {
/* IP */
fgd_ele_len = fgd_txt[fgd_curpos-1];
bcopy( &fgd_txt[fgd_curpos], incoming->ipadr, fgd_ele_len);
incoming->ipadr[fgd_ele_len] = 0;
fgd_curpos = fgd_curpos + fgd_ele_len + 1;
/* Pilot */
fgd_ele_len = fgd_txt[fgd_curpos-1];
bcopy( &fgd_txt[fgd_curpos], incoming->callsign, fgd_ele_len);
incoming->callsign[fgd_ele_len] = 0;
fgd_curpos = fgd_curpos + fgd_ele_len + 1;
/* Lon, Lat...etc */
if (verbose == 2) {
printf(" #%d %-16s %s\n", fgd_cnt, incoming->ipadr, incoming->callsign);
printf(" curpos:%d\n", fgd_curpos);
sscanf( &fgd_txt[fgd_curpos]," %7f %7f %7f %7f %7f %7f %7f",
&incoming->latf, &incoming->lonf,
&incoming->altf, &incoming->speedf, &incoming->rollf,
&incoming->pitchf, &incoming->yawf);
printf(" lat :%7.3f\n lon :%7.3f\n alt :%7.3f\n speed :%7.3f\n roll :%7.3f\n pitch :%7.3f\n yaw :%7.3f\n",
incoming->latf, incoming->lonf, incoming->altf, incoming->speedf,
incoming->rollf, incoming->pitchf, incoming->yawf);
}
fgd_curpos += 56;
incoming = incoming->next;
} /* end for */
// } /* end else */
} /* end if "data available" */
/* Here reading the answer of completed command by fgd */
/* read( sock, fgd_txt, buffp[3]);
fgd_txt[buffp[3]] = 0;
if (strcmp(fgd_txt, "UNKNOWN") == -1) {
if (verbose == 2) printf("FGD: Data to Host sent\n");
}
else printf("FGD: Host not in list, sorry...\n");
*/
break;
case 18: if (verbose == 2) printf("FGD: Sending Mat4 data to Host %s\n", FGFS_host);
if (fgd_reply_len != 5) {
/* FIXME: replace with SELECT */
if (verbose == 2) printf("Noch %d bytes\n", fgd_reply_len);
do {
fgd_status = recv( sock, fgd_txt, fgd_reply_len - 5, MSG_WAITALL);
if (verbose == 2) printf("Status %d\n", fgd_status);
}
// while ( (fgd_status == 4) || (fgd_status == -1) );
while ( (fgd_status == -1) || (fgd_status == -1) );
// read( sock, fgd_txt, fgd_reply_len - 5);
fgd_curpos = 2;
fgd_ppl_old = fgd_ppl;
fgd_ppl = fgd_txt[0];
/* Check if list has changed (pilot joined/left) */
if (fgd_ppl != fgd_ppl_old) {
printf(" List changed!!!\n");
for (fgd_cnt = 1; fgd_cnt <= abs(fgd_ppl - fgd_ppl_old); fgd_cnt++) {
if (verbose == 2) printf(" Checkpoint\n");
incoming = head->next;
if ((fgd_ppl - fgd_ppl_old) > 0) list_insert("test\0");
else {
printf(" Clearing entry.\n");
list_clear(incoming->ipadr);
}
}
}
// else {
incoming = head->next;
for (fgd_cnt = 1; fgd_cnt < (fgd_ppl+1); fgd_cnt++) {
/* IP */
fgd_ele_len = fgd_txt[fgd_curpos-1];
bcopy( &fgd_txt[fgd_curpos], incoming->ipadr, fgd_ele_len);
incoming->ipadr[fgd_ele_len] = 0;
fgd_curpos = fgd_curpos + fgd_ele_len + 1;
/* Pilot */
fgd_ele_len = fgd_txt[fgd_curpos-1];
bcopy( &fgd_txt[fgd_curpos], incoming->callsign, fgd_ele_len);
incoming->callsign[fgd_ele_len] = 0;
fgd_curpos = fgd_curpos + fgd_ele_len + 1;
/* Lon, Lat...etc */
if (verbose == 2) {
printf(" #%d %-16s %s\n", fgd_cnt, incoming->ipadr, incoming->callsign);
printf(" curpos:%d\n", fgd_curpos);
}
fgd_len_msg = strlen ( &fgd_txt[fgd_curpos]);
sscanf( &fgd_txt[fgd_curpos]," %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f",
&incoming->sgFGD_COORD[0][0], &incoming->sgFGD_COORD[0][1], &incoming->sgFGD_COORD[0][2], &incoming->sgFGD_COORD[0][3],
&incoming->sgFGD_COORD[1][0], &incoming->sgFGD_COORD[1][1], &incoming->sgFGD_COORD[1][2], &incoming->sgFGD_COORD[1][3],
&incoming->sgFGD_COORD[2][0], &incoming->sgFGD_COORD[2][1], &incoming->sgFGD_COORD[2][2], &incoming->sgFGD_COORD[2][3],
&incoming->sgFGD_COORD[3][0], &incoming->sgFGD_COORD[3][1], &incoming->sgFGD_COORD[3][2], &incoming->sgFGD_COORD[3][3]);
if (verbose == 2) {
printf("Incoming Mat4\n");
fgd_print_Mat4( incoming->sgFGD_COORD );
}
fgd_curpos += fgd_len_msg + 2;
incoming = incoming->next;
} /* end for */
// } /* end else */
} /* end if "data available" */
/* The first view-Mat4 is somebody else */
sgCopyMat4(sgFGD_VIEW, head->next->sgFGD_COORD);
/* Here reading the answer of completed command by fgd */
/* read( sock, fgd_txt, buffp[3]);
// fgd_txt[buffp[3]] = 0;
if (strcmp(fgd_txt, "UNKNOWN") == -1) {
if (verbose == 2) printf("FGD: Mat4 Data to Host sent\n");
}
else printf("FGD: Host not in list, sorry...\n");
*/
break;
case 8: printf("FGD: Unregistering Host %s\n", FGFS_host);
read( sock, fgd_txt, buffp[3]);
fgd_txt[buffp[3]] = 0;
test = head->next;
while (test != tail) {
list_clear( test->ipadr );
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");
*/
break;
case 9: printf(" Shutdown FlightGear-Deamon %s .\n", fgd_name);
break;
default: break;
}
} else printf(" Huh?: no deamon present, yuk!!!\n");
// }
close(sock);
// current_port++;
// }
if (verbose == 2) printf("fgd_com completed.\n");
}

View file

@ -1,99 +0,0 @@
// network.cxx -- data structures for initializing & managing network.
//
// Written by Oliver Delise, started May 1999.
//
// Copyleft (C) 1999 Oliver Delise - delise@mail.isis.de
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License as
// published by the Free Software Foundation; either version 2 of the
// License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful, but
// WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
// General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
//
// $Id$
#ifdef HAVE_CONFIG_H
# include <config.h>
#endif
/*
#ifdef HAVE_WINDOWS_H
# include <windows.h>
#endif
#ifdef __BORLANDC__
# define exception c_exception
#endif
#include <math.h>
#include FG_GLUT_H
#include <stdlib.h>
#include <string.h>
#ifdef HAVE_VALUES_H
# include <values.h> // for MAXINT
#endif
#include <simgear/logstream.hxx>
#include <simgear/constants.h>
#include <simgear/fg_random.h>
#include <simgear/polar3d.hxx>
#include <Aircraft/aircraft.hxx>
#include <GUI/gui.h>
#include <Scenery/scenery.hxx>
#include <Time/fg_timer.hxx>
#if defined ( __sun__ ) || defined ( __sgi )
extern "C" {
extern void *memmove(void *, const void *, size_t);
}
#endif
*/
#include <plib/sg.h>
#include <plib/ssg.h>
#include <simgear/compiler.h>
#include <Main/globals.hxx>
#include <Main/fg_props.hxx>
int net_blast_toggle, net_hud_display, net_is_registered;
char *net_callsign, *FGFS_host;
sgMat4 sgFGD_VIEW;
ssgRoot *fgd_scene;
extern void list_init();
extern void fgd_init();
extern void fgd_send_com( char *FGD_com, char *FGFS_host);
char *fg_net_init( ssgRoot *orig_scene ){
// We enable display of netinfos only if user wishes it via cmd-line param
net_hud_display = (net_hud_display == 0) ? 0 : 1;
// Get pilot's name from options, can be modified at runtime via menu
net_callsign = (char *)(fgGetString("/sim/networking/call-sign"));
// Disable Blast Mode -1 = Disable, 0 = Enable
net_blast_toggle = -1;
// We start unregistered, we reg. later via menu to fgd
net_is_registered = -1;
fgd_scene = orig_scene;
// Init list of Pilots
list_init();
// Init Sockets et al...
fgd_init();
// Register to deamon
// fgd_send_com( "0", FGFS_host);
// fgd_send_com( "1", FGFS_host);
return("activated");
}

View file

@ -1,61 +0,0 @@
// network.h -- public data structures for managing network.
//
// Written by Oliver Delise, started May 1999.
//
// Copyleft (C) 1999 Oliver Delise - delise@mail.isis.de
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License as
// published by the Free Software Foundation; either version 2 of the
// License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful, but
// WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
// General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
//
// $Id$
#ifndef NETWORK_OLK_H
#define NETWORK_OLK_H
#define FGD
#include <plib/ssg.h>
extern char *net_callsign;
extern int net_hud_display;
extern int net_blast_toggle;
extern int net_is_registered;
extern int net_r, current_port;
extern u_short base_port, end_port;
extern char *fg_net_init( ssgRoot *orig_scene );
extern char *FGFS_host, *fgd_mcp_ip, *fgd_name;
extern void net_hud_update( void );
extern int net_resolv_fgd( char *);
#include "fgd.h"
extern sgMat4 sgFGD_VIEW;
struct list_ele {
/* unsigned */ char ipadr[16], callsign[16];
/* unsigned */ char lon[8], lat[8], alt[8], roll[8], pitch[8], yaw[8];
float lonf, latf, altf, speedf, rollf, pitchf, yawf;
sgMat4 sgFGD_COORD;
ssgSelector *fgd_sel;
ssgTransform * fgd_pos;
struct list_ele *next, *prev;
};
extern struct list_ele *head, *tail, *other;
extern void fgd_send_com( char *FGD_com, char *FGFS_host);
extern void list_init( void );
extern void fgd_init( void);
#endif