mirror of
https://github.com/solemnwarning/ipxwrapper
synced 2024-12-30 16:45:37 +01:00
More code cleanup and a couple of files I forgot to add last commit.
This commit is contained in:
parent
8b1c53e0bd
commit
2674e3356f
17
src/common.h
17
src/common.h
@ -42,19 +42,6 @@
|
|||||||
(unsigned int)(unsigned char)(node[5]) \
|
(unsigned int)(unsigned char)(node[5]) \
|
||||||
)
|
)
|
||||||
|
|
||||||
struct ipx_interface {
|
|
||||||
uint32_t ipaddr;
|
|
||||||
uint32_t netmask;
|
|
||||||
uint32_t bcast;
|
|
||||||
|
|
||||||
unsigned char hwaddr[6];
|
|
||||||
|
|
||||||
unsigned char ipx_net[4];
|
|
||||||
unsigned char ipx_node[6];
|
|
||||||
|
|
||||||
struct ipx_interface *next;
|
|
||||||
};
|
|
||||||
|
|
||||||
extern HKEY regkey;
|
extern HKEY regkey;
|
||||||
|
|
||||||
void log_printf(const char *fmt, ...);
|
void log_printf(const char *fmt, ...);
|
||||||
@ -69,8 +56,4 @@ DWORD reg_get_bin(const char *val_name, void *buf, DWORD size);
|
|||||||
|
|
||||||
HMODULE load_sysdll(const char *name);
|
HMODULE load_sysdll(const char *name);
|
||||||
|
|
||||||
/* interface.c functions */
|
|
||||||
struct ipx_interface *get_interfaces(int ifnum);
|
|
||||||
void free_interfaces(struct ipx_interface *iface);
|
|
||||||
|
|
||||||
#endif /* !IPXWRAPPER_COMMON_H */
|
#endif /* !IPXWRAPPER_COMMON_H */
|
||||||
|
137
src/interface.c
Normal file
137
src/interface.c
Normal file
@ -0,0 +1,137 @@
|
|||||||
|
/* IPXWrapper - Interface functions
|
||||||
|
* Copyright (C) 2011 Daniel Collins <solemnwarning@solemnwarning.net>
|
||||||
|
*
|
||||||
|
* This program is free software; you can redistribute it and/or modify it
|
||||||
|
* under the terms of the GNU General Public License version 2 as published by
|
||||||
|
* the Free Software Foundation.
|
||||||
|
*
|
||||||
|
* 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., 51
|
||||||
|
* Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <windows.h>
|
||||||
|
#include <iphlpapi.h>
|
||||||
|
|
||||||
|
#include "interface.h"
|
||||||
|
#include "common.h"
|
||||||
|
#include "config.h"
|
||||||
|
|
||||||
|
/* Get virtual IPX interfaces
|
||||||
|
* Select a single interface by setting ifnum >= 0
|
||||||
|
*/
|
||||||
|
struct ipx_interface *get_interfaces(int ifnum) {
|
||||||
|
IP_ADAPTER_INFO *ifroot, tbuf;
|
||||||
|
ULONG bufsize = sizeof(IP_ADAPTER_INFO);
|
||||||
|
|
||||||
|
int err = GetAdaptersInfo(&tbuf, &bufsize);
|
||||||
|
if(err == ERROR_NO_DATA) {
|
||||||
|
log_printf("No network interfaces detected!");
|
||||||
|
return NULL;
|
||||||
|
}else if(err != ERROR_SUCCESS && err != ERROR_BUFFER_OVERFLOW) {
|
||||||
|
log_printf("Error fetching network interfaces: %s", w32_error(err));
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(!(ifroot = malloc(bufsize))) {
|
||||||
|
log_printf("Out of memory! (Tried to allocate %u bytes)", (unsigned int)bufsize);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
err = GetAdaptersInfo(ifroot, &bufsize);
|
||||||
|
if(err != ERROR_SUCCESS) {
|
||||||
|
log_printf("Error fetching network interfaces: %s", w32_error(err));
|
||||||
|
|
||||||
|
free(ifroot);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
struct ipx_interface *nics = NULL, *enic = NULL;
|
||||||
|
|
||||||
|
IP_ADAPTER_INFO *ifptr = ifroot;
|
||||||
|
int this_ifnum = 0;
|
||||||
|
|
||||||
|
while(ifptr) {
|
||||||
|
if(ifnum >= 0 && this_ifnum++ != ifnum) {
|
||||||
|
ifptr = ifptr->Next;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
struct reg_value rv;
|
||||||
|
int got_rv = 0;
|
||||||
|
|
||||||
|
char vname[18];
|
||||||
|
NODE_TO_STRING(vname, ifptr->Address);
|
||||||
|
|
||||||
|
if(reg_get_bin(vname, &rv, sizeof(rv)) == sizeof(rv)) {
|
||||||
|
got_rv = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(got_rv && !rv.enabled) {
|
||||||
|
/* Interface has been disabled, don't add it */
|
||||||
|
ifptr = ifptr->Next;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
struct ipx_interface *nnic = malloc(sizeof(struct ipx_interface));
|
||||||
|
if(!nnic) {
|
||||||
|
log_printf("Out of memory! (Tried to allocate %u bytes)", (unsigned int)sizeof(struct ipx_interface));
|
||||||
|
|
||||||
|
free_interfaces(nics);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
nnic->ipaddr = inet_addr(ifptr->IpAddressList.IpAddress.String);
|
||||||
|
nnic->netmask = inet_addr(ifptr->IpAddressList.IpMask.String);
|
||||||
|
nnic->bcast = nnic->ipaddr | ~nnic->netmask;
|
||||||
|
|
||||||
|
memcpy(nnic->hwaddr, ifptr->Address, 6);
|
||||||
|
|
||||||
|
if(got_rv) {
|
||||||
|
memcpy(nnic->ipx_net, rv.ipx_net, 4);
|
||||||
|
memcpy(nnic->ipx_node, rv.ipx_node, 6);
|
||||||
|
}else{
|
||||||
|
unsigned char net[] = {0,0,0,1};
|
||||||
|
|
||||||
|
memcpy(nnic->ipx_net, net, 4);
|
||||||
|
memcpy(nnic->ipx_node, nnic->hwaddr, 6);
|
||||||
|
}
|
||||||
|
|
||||||
|
nnic->next = NULL;
|
||||||
|
|
||||||
|
if(got_rv && rv.primary) {
|
||||||
|
/* Force primary flag set, insert at start of NIC list */
|
||||||
|
nnic->next = nics;
|
||||||
|
nics = nnic;
|
||||||
|
|
||||||
|
if(!enic) {
|
||||||
|
enic = nnic;
|
||||||
|
}
|
||||||
|
}else if(enic) {
|
||||||
|
enic->next = nnic;
|
||||||
|
enic = nnic;
|
||||||
|
}else{
|
||||||
|
enic = nics = nnic;
|
||||||
|
}
|
||||||
|
|
||||||
|
ifptr = ifptr->Next;
|
||||||
|
}
|
||||||
|
|
||||||
|
free(ifroot);
|
||||||
|
|
||||||
|
return nics;
|
||||||
|
}
|
||||||
|
|
||||||
|
void free_interfaces(struct ipx_interface *iface) {
|
||||||
|
while(iface) {
|
||||||
|
struct ipx_interface *del = iface;
|
||||||
|
iface = iface->next;
|
||||||
|
|
||||||
|
free(del);
|
||||||
|
}
|
||||||
|
}
|
39
src/interface.h
Normal file
39
src/interface.h
Normal file
@ -0,0 +1,39 @@
|
|||||||
|
/* IPXWrapper - Interface header
|
||||||
|
* Copyright (C) 2011 Daniel Collins <solemnwarning@solemnwarning.net>
|
||||||
|
*
|
||||||
|
* This program is free software; you can redistribute it and/or modify it
|
||||||
|
* under the terms of the GNU General Public License version 2 as published by
|
||||||
|
* the Free Software Foundation.
|
||||||
|
*
|
||||||
|
* 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., 51
|
||||||
|
* Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef IPXWRAPPER_INTERFACE_H
|
||||||
|
#define IPXWRAPPER_INTERFACE_H
|
||||||
|
|
||||||
|
#include <stdint.h>
|
||||||
|
|
||||||
|
struct ipx_interface {
|
||||||
|
uint32_t ipaddr;
|
||||||
|
uint32_t netmask;
|
||||||
|
uint32_t bcast;
|
||||||
|
|
||||||
|
unsigned char hwaddr[6];
|
||||||
|
|
||||||
|
unsigned char ipx_net[4];
|
||||||
|
unsigned char ipx_node[6];
|
||||||
|
|
||||||
|
struct ipx_interface *next;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct ipx_interface *get_interfaces(int ifnum);
|
||||||
|
void free_interfaces(struct ipx_interface *iface);
|
||||||
|
|
||||||
|
#endif /* !IPXWRAPPER_INTERFACE_H */
|
@ -28,6 +28,7 @@
|
|||||||
|
|
||||||
#include "ipxwrapper.h"
|
#include "ipxwrapper.h"
|
||||||
#include "common.h"
|
#include "common.h"
|
||||||
|
#include "interface.h"
|
||||||
|
|
||||||
#define DLL_UNLOAD(dll) \
|
#define DLL_UNLOAD(dll) \
|
||||||
if(dll) {\
|
if(dll) {\
|
||||||
|
@ -55,7 +55,6 @@
|
|||||||
|
|
||||||
typedef struct ipx_socket ipx_socket;
|
typedef struct ipx_socket ipx_socket;
|
||||||
typedef struct ipx_packet ipx_packet;
|
typedef struct ipx_packet ipx_packet;
|
||||||
typedef struct ipx_nic ipx_nic;
|
|
||||||
typedef struct ipx_host ipx_host;
|
typedef struct ipx_host ipx_host;
|
||||||
|
|
||||||
struct ipx_socket {
|
struct ipx_socket {
|
||||||
|
@ -25,6 +25,7 @@
|
|||||||
|
|
||||||
#include "ipxwrapper.h"
|
#include "ipxwrapper.h"
|
||||||
#include "common.h"
|
#include "common.h"
|
||||||
|
#include "interface.h"
|
||||||
|
|
||||||
INT APIENTRY EnumProtocolsA(LPINT protocols, LPVOID buf, LPDWORD bsptr) {
|
INT APIENTRY EnumProtocolsA(LPINT protocols, LPVOID buf, LPDWORD bsptr) {
|
||||||
int bufsize = *bsptr, rval, i, want_ipx = 0;
|
int bufsize = *bsptr, rval, i, want_ipx = 0;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user