mirror of git://vps1.g8bpq.net/linbpq
parent
48f7c6192c
commit
3143e32c1a
@ -0,0 +1,216 @@
|
||||
// Includes code from MiniUPnPc, used subject to the following conditions:
|
||||
|
||||
/*
|
||||
|
||||
MiniUPnPc
|
||||
Copyright (c) 2005-2020, Thomas BERNARD
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions are met:
|
||||
|
||||
* Redistributions of source code must retain the above copyright notice,
|
||||
this list of conditions and the following disclaimer.
|
||||
* Redistributions in binary form must reproduce the above copyright notice,
|
||||
this list of conditions and the following disclaimer in the documentation
|
||||
and/or other materials provided with the distribution.
|
||||
* The name of the author may not be used to endorse or promote products
|
||||
derived from this software without specific prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
|
||||
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
*/
|
||||
|
||||
#define MINIUPNP_STATICLIB
|
||||
|
||||
#include <stdio.h>
|
||||
#ifdef _WIN32
|
||||
#include "upnpcommands.h"
|
||||
#include "miniupnpc.h"
|
||||
#include "upnperrors.h"
|
||||
#include <winsock2.h>
|
||||
#endif
|
||||
#ifdef LINBPQ
|
||||
#ifndef MACBPQ
|
||||
#ifndef WIN32
|
||||
#include <miniupnpc/upnpcommands.h>
|
||||
#include <miniupnpc/miniupnpc.h>
|
||||
#include <miniupnpc/upnperrors.h>
|
||||
#include <stdio.h>
|
||||
#endif
|
||||
#endif
|
||||
#endif
|
||||
#ifdef MACBPQ
|
||||
#include </usr/local/Cellar/miniupnpc/2.2.5/include/miniupnpc/upnpcommands.h>
|
||||
#include </usr/local/Cellar/miniupnpc/2.2.5/include/miniupnpc/miniupnpc.h>
|
||||
#include </usr/local/Cellar/miniupnpc/2.2.5/include/miniupnpc/upnperrors.h>
|
||||
#include <stdio.h>
|
||||
#endif
|
||||
int AddMap(char * controlURL, char * eport, char * iport, char * proto);
|
||||
int DeleteMap(char * controlURL, char * eport, char * iport, char * proto);
|
||||
|
||||
void Consoleprintf(const char * format, ...);
|
||||
|
||||
struct UPNP
|
||||
{
|
||||
struct UPNP * Next;
|
||||
char * Protocol;
|
||||
char * LANport;
|
||||
char * WANPort;
|
||||
};
|
||||
|
||||
extern struct UPNP * UPNPConfig;
|
||||
|
||||
char * controlURL = 0;
|
||||
char * servicetype = 0;
|
||||
char iaddr[] = "IP";
|
||||
char * inClient = NULL;
|
||||
#ifdef LINBPQ
|
||||
char desc[] = "LinBPQ ";
|
||||
#else
|
||||
char desc[] = "BPQ32 ";
|
||||
#endif
|
||||
char * remoteHost = NULL;
|
||||
char * leaseDuration = NULL;
|
||||
|
||||
struct UPNPDev * devlist = 0;
|
||||
char lanaddr[64] = "unset"; /* my ip address on the LAN */
|
||||
char wanaddr[64] = "unset"; /* my ip address on the LAN */
|
||||
struct UPNPUrls urls;
|
||||
struct IGDdatas data;
|
||||
|
||||
int i;
|
||||
const char * rootdescurl = 0;
|
||||
const char * multicastif = 0;
|
||||
const char * minissdpdpath = 0;
|
||||
#ifdef UPNP_LOCAL_PORT_ANY
|
||||
int localport = UPNP_LOCAL_PORT_ANY;
|
||||
#else
|
||||
int localport = 0;
|
||||
#endif
|
||||
int retcode = 0;
|
||||
int error = 0;
|
||||
int ipv6 = 0;
|
||||
int ignore = 0;
|
||||
unsigned char ttl = 2;
|
||||
|
||||
|
||||
int upnpInit()
|
||||
{
|
||||
struct UPNP * Config = UPNPConfig;
|
||||
int i;
|
||||
#ifdef WIN32
|
||||
WSADATA wsaData;
|
||||
int nResult = WSAStartup(MAKEWORD(2,2), &wsaData);
|
||||
if(nResult != NO_ERROR)
|
||||
{
|
||||
fprintf(stderr, "WSAStartup() failed.\n");
|
||||
return -1;
|
||||
}
|
||||
#endif
|
||||
|
||||
while (Config)
|
||||
{
|
||||
if (devlist == NULL)
|
||||
{
|
||||
#if MINIUPNPC_API_VERSION == 10
|
||||
devlist = upnpDiscover(2000, multicastif, minissdpdpath, localport, ipv6, &error);
|
||||
#else
|
||||
devlist = upnpDiscover(2000, multicastif, minissdpdpath, localport, ipv6, ttl, &error);
|
||||
#endif
|
||||
if (devlist == NULL)
|
||||
{
|
||||
Consoleprintf("Failed to find a UPNP device");
|
||||
return 0;
|
||||
}
|
||||
|
||||
#if MINIUPNPC_API_VERSION >= 18
|
||||
i = UPNP_GetValidIGD(devlist, &urls, &data, lanaddr, sizeof(lanaddr), wanaddr, sizeof(wanaddr));
|
||||
#else
|
||||
i = UPNP_GetValidIGD(devlist, &urls, &data, lanaddr, sizeof(lanaddr));
|
||||
#endif
|
||||
}
|
||||
|
||||
AddMap(devlist->descURL, Config->LANport, Config->WANPort, Config->Protocol);
|
||||
Config = Config->Next;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int upnpClose()
|
||||
{
|
||||
struct UPNP * Config = UPNPConfig;
|
||||
int i;
|
||||
|
||||
while (Config)
|
||||
{
|
||||
if (devlist == NULL)
|
||||
{
|
||||
#if MINIUPNPC_API_VERSION == 10
|
||||
devlist = upnpDiscover(2000, multicastif, minissdpdpath, localport, ipv6, &error);
|
||||
#else
|
||||
devlist = upnpDiscover(2000, multicastif, minissdpdpath, localport, ipv6, ttl, &error);
|
||||
#endif
|
||||
if (devlist == NULL)
|
||||
{
|
||||
Consoleprintf("Failed to find a UPNP device");
|
||||
return 0;
|
||||
}
|
||||
|
||||
#if MINIUPNPC_API_VERSION >= 18
|
||||
i = UPNP_GetValidIGD(devlist, &urls, &data, lanaddr, sizeof(lanaddr), wanaddr, sizeof(wanaddr));
|
||||
#else
|
||||
i = UPNP_GetValidIGD(devlist, &urls, &data, lanaddr, sizeof(lanaddr));
|
||||
#endif
|
||||
}
|
||||
|
||||
DeleteMap(devlist->descURL, Config->LANport, Config->WANPort, Config->Protocol);
|
||||
Config = Config->Next;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int AddMap(char * controlURL, char * eport, char * iport, char * proto)
|
||||
{
|
||||
int r = UPNP_AddPortMapping(urls.controlURL, data.first.servicetype,
|
||||
eport, iport, lanaddr, desc,
|
||||
proto, remoteHost, leaseDuration);
|
||||
|
||||
if (r != UPNPCOMMAND_SUCCESS)
|
||||
{
|
||||
Consoleprintf("UPNP AddPortMapping(%s, %s, %s) failed with code %d (%s)", eport, iport, lanaddr, r, strupnperror(r));
|
||||
return -2;
|
||||
}
|
||||
Consoleprintf("UPNP AddPortMapping(%s, %s, %s) Succeeded", eport, iport, lanaddr, r);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int DeleteMap(char * controlURL, char * eport, char * iport, char * proto)
|
||||
{
|
||||
int r = UPNP_DeletePortMapping(urls.controlURL, data.first.servicetype, eport, proto, remoteHost);
|
||||
|
||||
if(r != UPNPCOMMAND_SUCCESS)
|
||||
{
|
||||
Consoleprintf("UPNP DeletePortMapping(%s, %s, %s) failed with code %d (%s)", eport, iport, lanaddr, r, strupnperror(r));
|
||||
return -2;
|
||||
}
|
||||
Consoleprintf("UPNP DeletePortMapping(%s, %s, %s) Succeeded", eport, iport, lanaddr, r);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
@ -0,0 +1,126 @@
|
||||
|
||||
#ifdef Kernel
|
||||
|
||||
#define Vers 5,2,9,2
|
||||
#define Verstring "5.2.9.2\0"
|
||||
#define Datestring "September 2012"
|
||||
#define VerComments "G8BPQ Packet Switch V5.2.9.2\0"
|
||||
#define VerCopyright "Copyright © 2001-2012 John Wiseman G8BPQ\0"
|
||||
#define VerDesc "BPQ32 Switch\0"
|
||||
|
||||
#endif
|
||||
|
||||
#define KVers 6,0,24,76
|
||||
#define KVerstring "6.0.24.76\0"
|
||||
|
||||
|
||||
#ifdef CKernel
|
||||
|
||||
#define Vers KVers
|
||||
#define Verstring KVerstring
|
||||
#define Datestring "July 2025"
|
||||
#define VerComments "G8BPQ Packet Switch (C Version)" KVerstring
|
||||
#define VerCopyright "Copyright © 2001-2025 John Wiseman G8BPQ\0"
|
||||
#define VerDesc "BPQ32 Switch\0"
|
||||
#define VerProduct "BPQ32"
|
||||
|
||||
#endif
|
||||
|
||||
#ifdef TermTCP
|
||||
|
||||
#define Vers 1,0,16,2
|
||||
#define Verstring "1.0.16.2\0"
|
||||
#define VerComments "Internet Terminal for G8BPQ Packet Switch\0"
|
||||
#define VerCopyright "Copyright © 2011-2025 John Wiseman G8BPQ\0"
|
||||
#define VerDesc "Simple TCP Terminal Program for G8BPQ Switch\0"
|
||||
#define VerProduct "BPQTermTCP"
|
||||
|
||||
#endif
|
||||
|
||||
#ifdef BPQTerm
|
||||
|
||||
#define Vers 2,2,5,2
|
||||
#define Verstring "2.2.5.2\0"
|
||||
#define VerComments "Simple Terminal for G8BPQ Packet Switch\0"
|
||||
#define VerCopyright "Copyright © 1999-2025 John Wiseman G8BPQ\0"
|
||||
#define VerDesc "Simple Terminal Program for G8BPQ Switch\0"
|
||||
#define VerProduct "BPQTerminal"
|
||||
|
||||
#endif
|
||||
|
||||
#ifdef BPQTermMDI
|
||||
|
||||
#define Vers 2,2,0,3
|
||||
#define Verstring "2.2.0.3\0"
|
||||
#define VerComments "MDI Terminal for G8BPQ Packet Switch\0"
|
||||
#define VerCopyright "Copyright © 1999-2025 John Wiseman G8BPQ\0"
|
||||
#define VerDesc "MDI Terminal Program for G8BPQ Switch\0"
|
||||
|
||||
#endif
|
||||
|
||||
#ifdef MAIL
|
||||
|
||||
#define Vers KVers
|
||||
#define Verstring KVerstring
|
||||
#define VerComments "Mail server for G8BPQ Packet Switch\0"
|
||||
#define VerCopyright "Copyright © 2009-2025 John Wiseman G8BPQ\0"
|
||||
#define VerDesc "Mail server for G8BPQ's 32 Bit Switch\0"
|
||||
#define VerProduct "BPQMail"
|
||||
|
||||
#endif
|
||||
|
||||
#ifdef HOSTMODES
|
||||
|
||||
#define Vers 1,1,8,1
|
||||
#define Verstring "1.1.8.1\0"
|
||||
//#define SPECIALVERSION "Test 3"
|
||||
#define VerComments "Host Modes Emulator for G8BPQ Packet Switch\0"
|
||||
#define VerCopyright "Copyright © 2009-2019 John Wiseman G8BPQ\0"
|
||||
#define VerDesc "Host Modes Emulator for G8BPQ's 32 Bit Switch\0"
|
||||
#define VerProduct "BPQHostModes"
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
#ifdef UIUTIL
|
||||
|
||||
#define Vers 0,1,3,1
|
||||
#define Verstring "0.1.3.1\0"
|
||||
#define VerComments "Beacon Utility for G8BPQ Packet Switch\0"
|
||||
#define VerCopyright "Copyright © 2011-2019 John Wiseman G8BPQ\0"
|
||||
#define VerDesc "Beacon Utility for G8BPQ Switch\0"
|
||||
#define VerProduct "BPQUIUtil"
|
||||
|
||||
#endif
|
||||
|
||||
#ifdef AUTH
|
||||
|
||||
#define Vers 0,1,0,0
|
||||
#define Verstring "0.1.0.0\0"
|
||||
#define VerComments "Password Generation Utility for G8BPQ Packet Switch\0"
|
||||
#define VerCopyright "Copyright © 2011-2025 John Wiseman G8BPQ\0"
|
||||
#define VerDesc "Password Generation Utility for G8BPQ Switch\0"
|
||||
|
||||
#endif
|
||||
|
||||
#ifdef APRS
|
||||
|
||||
#define Vers KVers
|
||||
#define Verstring KVerstring
|
||||
#define VerComments "APRS Client for G8BPQ Switch\0"
|
||||
#define VerCopyright "Copyright © 2012-2025 John Wiseman G8BPQ\0"
|
||||
#define VerDesc "APRS Client for G8BPQ Switch\0"
|
||||
#define VerProduct "BPQAPRS"
|
||||
|
||||
#endif
|
||||
|
||||
#ifdef CHAT
|
||||
|
||||
#define Vers KVers
|
||||
#define Verstring KVerstring
|
||||
#define VerComments "Chat server for G8BPQ Packet Switch\0"
|
||||
#define VerCopyright "Copyright © 2009-2025 John Wiseman G8BPQ\0"
|
||||
#define VerDesc "Chat server for G8BPQ's 32 Bit Switch\0"
|
||||
#define VerProduct "BPQChat"
|
||||
|
||||
#endif
|
||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,499 @@
|
||||
/*
|
||||
Copyright 2001-2015 John Wiseman G8BPQ
|
||||
|
||||
This file is part of LinBPQ/BPQ32.
|
||||
|
||||
LinBPQ/BPQ32 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 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
LinBPQ/BPQ32 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 LinBPQ/BPQ32. If not, see http://www.gnu.org/licenses
|
||||
*/
|
||||
|
||||
//
|
||||
// DLL to provide BPQEther support for G8BPQ switch in a Linux environment,
|
||||
|
||||
// Normally uses a Raw socket, but that can't send to other apps on same machine.
|
||||
// so can use a TAP device instead (or maybe as well??)
|
||||
|
||||
#if !(defined(MACBPQ) || defined(FREEBSD))
|
||||
|
||||
#include <stdio.h>
|
||||
#include "cheaders.h"
|
||||
#include <sys/socket.h>
|
||||
|
||||
#if !(defined(FREEBSD))
|
||||
|
||||
#include <linux/if_packet.h>
|
||||
#include <linux/if_ether.h>
|
||||
#include <linux/if_arp.h>
|
||||
|
||||
#endif
|
||||
#endif
|
||||
|
||||
|
||||
extern int tap_fd;
|
||||
|
||||
typedef struct PCAPStruct
|
||||
{
|
||||
UCHAR EthSource[6];
|
||||
UCHAR EthDest[6];
|
||||
short EtherType;
|
||||
BOOL RLITX;
|
||||
BOOL RLIRX;
|
||||
BOOL Promiscuous;
|
||||
|
||||
int s; /*socketdescriptor*/
|
||||
struct sockaddr_ll socket_address; /*target address*/
|
||||
|
||||
} PCAPINFO, *PPCAPINFO ;
|
||||
|
||||
PCAPINFO PCAPInfo[32];
|
||||
|
||||
// on linux default to broadcast
|
||||
|
||||
short udpport=0;
|
||||
|
||||
unsigned int OurInst = 0;
|
||||
|
||||
BOOL GotMsg;
|
||||
|
||||
DWORD n;
|
||||
|
||||
char Adapter[256];
|
||||
|
||||
static BOOL ReadConfigFile(int Port);
|
||||
static int ProcessLine(char * buf,int Port, BOOL CheckPort);
|
||||
int WritetoConsoleLocal(char * buff);
|
||||
|
||||
static size_t ExtProc(int fn, int port, PMESSAGE buff)
|
||||
{
|
||||
int len,txlen=0,res;
|
||||
char txbuff[500];
|
||||
unsigned char rxbuff[1600];
|
||||
PCAPINFO * IF = &PCAPInfo[port];
|
||||
|
||||
if (IF->s == 0)
|
||||
return 0;
|
||||
|
||||
switch (fn)
|
||||
{
|
||||
case 1: // poll
|
||||
|
||||
res = recvfrom(IF->s, rxbuff, ETH_FRAME_LEN, 0, NULL, NULL);
|
||||
|
||||
if (res == -1)
|
||||
{
|
||||
if (errno == 11)
|
||||
return 0; //Resource temporarily unavailable
|
||||
|
||||
perror("Eth RX");
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (res == 0)
|
||||
/* Timeout elapsed */
|
||||
return 0;
|
||||
|
||||
if (rxbuff[13] != 0xff)
|
||||
return 0;
|
||||
|
||||
if (IF->RLIRX)
|
||||
|
||||
// RLI MODE - An extra 3 bytes before len, seem to be 00 00 41
|
||||
|
||||
{
|
||||
len=rxbuff[18]*256 + rxbuff[17];
|
||||
|
||||
if ((len < 16) || (len > 320)) return 0; // Probably BPQ Mode Frame
|
||||
|
||||
len-=3;
|
||||
|
||||
memcpy(&buff->DEST, &rxbuff[19], len);
|
||||
len += (1 + sizeof(void *));
|
||||
}
|
||||
else
|
||||
{
|
||||
len=rxbuff[15]*256 + rxbuff[14];
|
||||
|
||||
if ((len < 16) || (len > 320)) return 0; // Probably RLI Mode Frame
|
||||
|
||||
len-=3;
|
||||
memcpy(&buff->DEST, &rxbuff[16], len);
|
||||
len += (1 + sizeof(void *));
|
||||
}
|
||||
|
||||
PutLengthinBuffer((PDATAMESSAGE)buff, len);
|
||||
|
||||
return 1;
|
||||
|
||||
|
||||
case 2: // send
|
||||
|
||||
if (IF->RLITX)
|
||||
|
||||
// RLI MODE - An extra 3 bytes before len, seem to be 00 00 41
|
||||
|
||||
{
|
||||
txlen = GetLengthfromBuffer((PDATAMESSAGE)buff); // 2 for CRC
|
||||
txlen -= (sizeof(void *) - 2);
|
||||
txbuff[16]=0x41;
|
||||
txbuff[17]=(txlen & 0xff);
|
||||
txbuff[18]=(txlen >> 8);
|
||||
|
||||
if (txlen < 1 || txlen > 400)
|
||||
return 0;
|
||||
|
||||
memcpy(&txbuff[19], &buff->DEST[0], txlen);
|
||||
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
txlen = GetLengthfromBuffer((PDATAMESSAGE)buff); // 2 for CRC
|
||||
txlen -= (sizeof(void *) - 2);
|
||||
|
||||
txbuff[14]=(txlen & 0xff);
|
||||
txbuff[15]=(txlen >> 8);
|
||||
|
||||
if (txlen < 1 || txlen > 400)
|
||||
return 0;
|
||||
|
||||
|
||||
memcpy(&txbuff[16], &buff->DEST[0], txlen);
|
||||
}
|
||||
|
||||
memcpy(&txbuff[0], &IF->EthDest[0],6);
|
||||
memcpy(&txbuff[6], &IF->EthSource[0],6);
|
||||
memcpy(&txbuff[12], &IF->EtherType,2);
|
||||
|
||||
txlen+=14;
|
||||
|
||||
if (txlen < 60) txlen = 60;
|
||||
|
||||
// Send down the packet
|
||||
|
||||
res = sendto(IF->s, txbuff, txlen, 0,
|
||||
(const struct sockaddr *)&IF->socket_address, sizeof(struct sockaddr_ll));
|
||||
|
||||
if (res < 0)
|
||||
{
|
||||
perror("Eth Send");
|
||||
return 3;
|
||||
}
|
||||
|
||||
// if (tap_fd)
|
||||
// write(tap_fd, txbuff, txlen);
|
||||
|
||||
return (0);
|
||||
|
||||
case 3: // CHECK IF OK TO SEND
|
||||
|
||||
return (0); // OK
|
||||
|
||||
case 4: // reinit
|
||||
|
||||
return 0;
|
||||
|
||||
case 5: // reinit
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
return (0);
|
||||
}
|
||||
|
||||
|
||||
void * ETHERExtInit(struct PORTCONTROL * PortEntry)
|
||||
{
|
||||
// Can have multiple ports, each mapping to a different Ethernet Adapter
|
||||
|
||||
// The Adapter number is in IOADDR
|
||||
//
|
||||
|
||||
int i=0;
|
||||
u_int netmask;
|
||||
char buf[256];
|
||||
int n;
|
||||
struct ifreq ifr;
|
||||
size_t if_name_len;
|
||||
PCAPINFO * IF;
|
||||
int port = PortEntry->PORTNUMBER;
|
||||
u_long param=1;
|
||||
struct ifreq buffer;
|
||||
|
||||
WritetoConsoleLocal("LinEther ");
|
||||
|
||||
//
|
||||
// Read config
|
||||
//
|
||||
|
||||
if (!ReadConfigFile(port))
|
||||
return (FALSE);
|
||||
|
||||
if_name_len = strlen(Adapter);
|
||||
|
||||
IF = &PCAPInfo[port];
|
||||
|
||||
IF->s = socket(AF_PACKET, SOCK_RAW, htons(ETH_P_BPQ));
|
||||
|
||||
if (IF->s == -1)
|
||||
{
|
||||
perror("Open Ether Socket");
|
||||
IF->s = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
ioctl(IF->s, FIONBIO, ¶m);
|
||||
memcpy(ifr.ifr_name, Adapter, if_name_len);
|
||||
ifr.ifr_name[if_name_len] = 0;
|
||||
|
||||
if (ioctl(IF->s, SIOCGIFINDEX,&ifr) == -1)
|
||||
perror("Get IF Number");
|
||||
|
||||
// Get MAC Address
|
||||
|
||||
memset(&buffer, 0x00, sizeof(buffer));
|
||||
|
||||
strcpy(buffer.ifr_name, Adapter);
|
||||
ioctl(IF->s, SIOCGIFHWADDR, &buffer);
|
||||
memcpy(IF->EthSource, buffer.ifr_hwaddr.sa_data, 6);
|
||||
}
|
||||
|
||||
n=sprintf(buf,"Using %s = Interface %d\n", Adapter, ifr.ifr_ifindex);
|
||||
WritetoConsoleLocal(buf);
|
||||
|
||||
/*prepare sockaddr_ll*/
|
||||
|
||||
/*RAW communication*/
|
||||
IF->socket_address.sll_family = PF_PACKET;
|
||||
|
||||
/*we don't use a protocoll above ethernet layer ->just use anything here*/
|
||||
IF->socket_address.sll_protocol = htons(ETH_P_IP);
|
||||
|
||||
//index of the network device
|
||||
|
||||
IF->socket_address.sll_ifindex = ifr.ifr_ifindex;
|
||||
|
||||
/*ARP hardware identifier is ethernet*/
|
||||
IF->socket_address.sll_hatype = ARPHRD_ETHER;
|
||||
|
||||
/*target is another host*/
|
||||
IF->socket_address.sll_pkttype = PACKET_BROADCAST;
|
||||
|
||||
/*address length*/
|
||||
IF->socket_address.sll_halen = ETH_ALEN;
|
||||
/*MAC - begin*/
|
||||
|
||||
memcpy(IF->socket_address.sll_addr, IF->EthDest, 6);
|
||||
IF->socket_address.sll_addr[6] = 0x00;/*not used*/
|
||||
IF->socket_address.sll_addr[7] = 0x00;/*not used*/
|
||||
|
||||
|
||||
// n=sprintf(buf,"Using %s Adapter = Interface %d\r", ifr.ifr_ifindex);
|
||||
// WritetoConsole(buf);
|
||||
|
||||
return (ExtProc);
|
||||
}
|
||||
|
||||
|
||||
|
||||
static BOOL ReadConfigFile(int Port)
|
||||
{
|
||||
//TYPE 1 08FF # Ethernet Type
|
||||
//ETH 1 FF:FF:FF:FF:FF:FF # Target Ethernet AddrMAP G8BPQ-7 10.2.77.1 # IP 93 for compatibility
|
||||
//ADAPTER 1 \Device\NPF_{21B601E8-8088-4F7D-96 29-EDE2A9243CF4} # Adapter Name
|
||||
|
||||
char buf[256],errbuf[256];
|
||||
char * Config;
|
||||
|
||||
Config = PortConfig[Port];
|
||||
|
||||
PCAPInfo[Port].Promiscuous = 1; // Default
|
||||
PCAPInfo[Port].EtherType=htons(0x08FF); // Default
|
||||
memset(PCAPInfo[Port].EthDest, 0xff, 6);
|
||||
|
||||
|
||||
if (Config)
|
||||
{
|
||||
// Using config from bpq32.cfg
|
||||
|
||||
char * ptr1 = Config, * ptr2;
|
||||
|
||||
ptr2 = strchr(ptr1, 13);
|
||||
while(ptr2)
|
||||
{
|
||||
memcpy(buf, ptr1, ptr2 - ptr1);
|
||||
buf[ptr2 - ptr1] = 0;
|
||||
ptr1 = ptr2 + 2;
|
||||
ptr2 = strchr(ptr1, 13);
|
||||
|
||||
strcpy(errbuf,buf); // save in case of error
|
||||
|
||||
if (!ProcessLine(buf, Port, FALSE))
|
||||
{
|
||||
WritetoConsoleLocal("BPQEther - Bad config record ");
|
||||
WritetoConsoleLocal(errbuf);
|
||||
WritetoConsoleLocal("\n");
|
||||
}
|
||||
}
|
||||
return (TRUE);
|
||||
}
|
||||
|
||||
n=sprintf(buf,"No config info found in bpq32.cfg\n");
|
||||
WritetoConsoleLocal(buf);
|
||||
|
||||
return (FALSE);
|
||||
}
|
||||
|
||||
|
||||
static int ProcessLine(char * buf, int Port, BOOL CheckPort)
|
||||
{
|
||||
char * ptr;
|
||||
char * p_port;
|
||||
char * p_mac;
|
||||
char * p_Adapter;
|
||||
char * p_type;
|
||||
|
||||
int port;
|
||||
int a,b,c,d,e,f,num;
|
||||
|
||||
ptr = strtok(buf, " \t\n\r");
|
||||
|
||||
if(ptr == NULL) return (TRUE);
|
||||
|
||||
if(*ptr =='#') return (TRUE); // comment
|
||||
|
||||
if(*ptr ==';') return (TRUE); // comment
|
||||
|
||||
if (CheckPort)
|
||||
{
|
||||
p_port = strtok(NULL, " \t\n\r");
|
||||
|
||||
if (p_port == NULL) return (FALSE);
|
||||
|
||||
port = atoi(p_port);
|
||||
|
||||
if (Port != port) return TRUE; // Not for us
|
||||
}
|
||||
|
||||
if(_stricmp(ptr,"ADAPTER") == 0)
|
||||
{
|
||||
p_Adapter = strtok(NULL, " \t\n\r");
|
||||
|
||||
strcpy(Adapter,p_Adapter);
|
||||
return (TRUE);
|
||||
}
|
||||
|
||||
if(_stricmp(ptr,"TYPE") == 0)
|
||||
{
|
||||
p_type = strtok(NULL, " \t\n\r");
|
||||
|
||||
if (p_type == NULL) return (FALSE);
|
||||
|
||||
num=sscanf(p_type,"%x",&a);
|
||||
|
||||
if (num != 1) return FALSE;
|
||||
|
||||
PCAPInfo[Port].EtherType=htons(a);
|
||||
return (TRUE);
|
||||
|
||||
}
|
||||
|
||||
if(_stricmp(ptr,"promiscuous") == 0)
|
||||
{
|
||||
ptr = strtok(NULL, " \t\n\r");
|
||||
|
||||
if (ptr == NULL) return (FALSE);
|
||||
|
||||
PCAPInfo[Port].Promiscuous = atoi(ptr);
|
||||
|
||||
return (TRUE);
|
||||
|
||||
}
|
||||
|
||||
if(_stricmp(ptr,"RXMODE") == 0)
|
||||
{
|
||||
p_port = strtok(NULL, " \t\n\r");
|
||||
|
||||
if (p_port == NULL) return (FALSE);
|
||||
|
||||
if(_stricmp(p_port,"RLI") == 0)
|
||||
{
|
||||
PCAPInfo[Port].RLIRX=TRUE;
|
||||
return (TRUE);
|
||||
}
|
||||
|
||||
if(_stricmp(p_port,"BPQ") == 0)
|
||||
{
|
||||
PCAPInfo[Port].RLIRX=FALSE;
|
||||
return (TRUE);
|
||||
}
|
||||
|
||||
return FALSE;
|
||||
|
||||
}
|
||||
|
||||
if(_stricmp(ptr,"TXMODE") == 0)
|
||||
{
|
||||
p_port = strtok(NULL, " \t\n\r");
|
||||
|
||||
if (p_port == NULL) return (FALSE);
|
||||
|
||||
if(_stricmp(p_port,"RLI") == 0)
|
||||
{
|
||||
PCAPInfo[Port].RLITX=TRUE;
|
||||
return (TRUE);
|
||||
}
|
||||
|
||||
if(_stricmp(p_port,"BPQ") == 0)
|
||||
{
|
||||
PCAPInfo[Port].RLITX=FALSE;
|
||||
return (TRUE);
|
||||
}
|
||||
|
||||
return FALSE;
|
||||
|
||||
}
|
||||
|
||||
if(_stricmp(ptr,"DEST") == 0)
|
||||
{
|
||||
p_mac = strtok(NULL, " \t\n\r");
|
||||
|
||||
if (p_mac == NULL) return (FALSE);
|
||||
|
||||
num=sscanf(p_mac,"%x-%x-%x-%x-%x-%x",&a,&b,&c,&d,&e,&f);
|
||||
|
||||
if (num != 6) return FALSE;
|
||||
|
||||
PCAPInfo[Port].EthDest[0]=a;
|
||||
PCAPInfo[Port].EthDest[1]=b;
|
||||
PCAPInfo[Port].EthDest[2]=c;
|
||||
PCAPInfo[Port].EthDest[3]=d;
|
||||
PCAPInfo[Port].EthDest[4]=e;
|
||||
PCAPInfo[Port].EthDest[5]=f;
|
||||
|
||||
|
||||
// strcpy(Adapter,p_Adapter);
|
||||
|
||||
return (TRUE);
|
||||
}
|
||||
|
||||
if(_stricmp(ptr,"SOURCE") == 0) // not used, but ignore
|
||||
return (TRUE);
|
||||
|
||||
//
|
||||
// Bad line
|
||||
//
|
||||
return (FALSE);
|
||||
|
||||
}
|
||||
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
Binary file not shown.
Loading…
Reference in new issue