mirror of
https://github.com/solemnwarning/ipxwrapper
synced 2024-12-30 16:45:37 +01:00
Implemented function for formatting complete IPX addresses as strings.
Bugfix: mkstubs.pl used wrong DLL number for calls to log_call.
This commit is contained in:
parent
0f6c458bcc
commit
c836c55ee4
@ -71,7 +71,7 @@ foreach my $func(@stubs) {
|
||||
|
||||
if($do_logging) {
|
||||
print CODE "\tpush\t$f_name\_sym\n";
|
||||
print CODE "\tpush\tdword $dllnum\n";
|
||||
print CODE "\tpush\tdword ".$func->{"dllnum"}."\n";
|
||||
print CODE "\tcall\t_log_call\n";
|
||||
}
|
||||
|
||||
|
@ -22,8 +22,7 @@
|
||||
#include <winsock2.h>
|
||||
#include <stdint.h>
|
||||
|
||||
typedef unsigned char netnum_t[4];
|
||||
typedef unsigned char nodenum_t[6];
|
||||
#include "common.h"
|
||||
|
||||
extern unsigned int addr_cache_ttl;
|
||||
|
||||
|
30
src/common.c
30
src/common.c
@ -45,6 +45,36 @@ const char *w32_error(DWORD errnum) {
|
||||
return buf;
|
||||
}
|
||||
|
||||
/* Format an IPX address as a string.
|
||||
*
|
||||
* The socket number should be in network byte order and the supplied buffer
|
||||
* must be at least IPX_SADDR_SIZE bytes long.
|
||||
*/
|
||||
void ipx_to_string(char *buf, const netnum_t net, const nodenum_t node, uint16_t sock)
|
||||
{
|
||||
/* World's ugliest use of sprintf? */
|
||||
|
||||
sprintf(
|
||||
buf,
|
||||
|
||||
"%02X:%02X:%02X:%02X/%02X:%02X:%02X:%02X:%02X:%02X/%hu",
|
||||
|
||||
(unsigned int)(unsigned char)(net[0]),
|
||||
(unsigned int)(unsigned char)(net[1]),
|
||||
(unsigned int)(unsigned char)(net[2]),
|
||||
(unsigned int)(unsigned char)(net[3]),
|
||||
|
||||
(unsigned int)(unsigned char)(node[0]),
|
||||
(unsigned int)(unsigned char)(node[1]),
|
||||
(unsigned int)(unsigned char)(node[2]),
|
||||
(unsigned int)(unsigned char)(node[3]),
|
||||
(unsigned int)(unsigned char)(node[4]),
|
||||
(unsigned int)(unsigned char)(node[5]),
|
||||
|
||||
ntohs(sock)
|
||||
);
|
||||
}
|
||||
|
||||
BOOL reg_open(REGSAM access) {
|
||||
int err = RegOpenKeyEx(HKEY_CURRENT_USER, "Software\\IPXWrapper", 0, access, ®key);
|
||||
|
||||
|
27
src/common.h
27
src/common.h
@ -22,25 +22,10 @@
|
||||
#include <stdio.h>
|
||||
#include <stdint.h>
|
||||
|
||||
#define NET_TO_STRING(s, net) \
|
||||
sprintf( \
|
||||
s, "%02X:%02X:%02X:%02X", \
|
||||
(unsigned int)(unsigned char)(net[0]), \
|
||||
(unsigned int)(unsigned char)(net[1]), \
|
||||
(unsigned int)(unsigned char)(net[2]), \
|
||||
(unsigned int)(unsigned char)(net[3]) \
|
||||
)
|
||||
#define IPX_SADDR_SIZE 36
|
||||
|
||||
#define NODE_TO_STRING(s, node) \
|
||||
sprintf( \
|
||||
s, "%02X:%02X:%02X:%02X:%02X:%02X", \
|
||||
(unsigned int)(unsigned char)(node[0]), \
|
||||
(unsigned int)(unsigned char)(node[1]), \
|
||||
(unsigned int)(unsigned char)(node[2]), \
|
||||
(unsigned int)(unsigned char)(node[3]), \
|
||||
(unsigned int)(unsigned char)(node[4]), \
|
||||
(unsigned int)(unsigned char)(node[5]) \
|
||||
)
|
||||
typedef unsigned char netnum_t[4];
|
||||
typedef unsigned char nodenum_t[6];
|
||||
|
||||
enum ipx_log_level {
|
||||
LOG_CALL = 1,
|
||||
@ -56,6 +41,12 @@ extern enum ipx_log_level min_log_level;
|
||||
|
||||
const char *w32_error(DWORD errnum);
|
||||
|
||||
#define IPX_STRING_ADDR(var, net, node, sock) \
|
||||
char var[IPX_SADDR_SIZE]; \
|
||||
ipx_to_string(var, net, node, sock);
|
||||
|
||||
void ipx_to_string(char *buf, const netnum_t net, const nodenum_t node, uint16_t sock);
|
||||
|
||||
BOOL reg_open(REGSAM access);
|
||||
void reg_close(void);
|
||||
|
||||
|
@ -59,8 +59,24 @@ struct ipx_interface *get_interfaces(int ifnum) {
|
||||
struct reg_value rv;
|
||||
int got_rv = 0;
|
||||
|
||||
/* Format the hardware address as a hex string for fetching
|
||||
* settings from the registry.
|
||||
*/
|
||||
|
||||
char vname[18];
|
||||
NODE_TO_STRING(vname, ifptr->Address);
|
||||
|
||||
sprintf(
|
||||
vname,
|
||||
|
||||
"%02X:%02X:%02X:%02X:%02X:%02X",
|
||||
|
||||
(unsigned int)(unsigned char)(ifptr->Address[0]),
|
||||
(unsigned int)(unsigned char)(ifptr->Address[1]),
|
||||
(unsigned int)(unsigned char)(ifptr->Address[2]),
|
||||
(unsigned int)(unsigned char)(ifptr->Address[3]),
|
||||
(unsigned int)(unsigned char)(ifptr->Address[4]),
|
||||
(unsigned int)(unsigned char)(ifptr->Address[5])
|
||||
);
|
||||
|
||||
if(reg_get_bin(vname, &rv, sizeof(rv)) == sizeof(rv)) {
|
||||
got_rv = 1;
|
||||
|
@ -32,3 +32,4 @@ s_perror
|
||||
sethostname
|
||||
inet_addr
|
||||
WSHEnumProtocols:0
|
||||
ntohs:1
|
||||
|
11
src/router.c
11
src/router.c
@ -278,15 +278,10 @@ DWORD router_main(void *arg) {
|
||||
}
|
||||
|
||||
if(min_log_level <= LOG_DEBUG) {
|
||||
char src_net[12], src_node[18];
|
||||
NET_TO_STRING(src_net, packet->src_net);
|
||||
NODE_TO_STRING(src_node, packet->src_node);
|
||||
IPX_STRING_ADDR(src_addr, packet->src_net, packet->src_node, packet->src_socket);
|
||||
IPX_STRING_ADDR(dest_addr, packet->dest_net, packet->dest_node, packet->dest_socket);
|
||||
|
||||
char dest_net[12], dest_node[18];
|
||||
NET_TO_STRING(dest_net, packet->dest_net);
|
||||
NODE_TO_STRING(dest_node, packet->dest_node);
|
||||
|
||||
log_printf(LOG_DEBUG, "Recieved packet from %s/%s (%s) for %s/%s", src_net, src_node, inet_ntoa(addr.sin_addr), dest_net, dest_node);
|
||||
log_printf(LOG_DEBUG, "Recieved packet from %s (%s) for %s", src_addr, inet_ntoa(addr.sin_addr), dest_addr);
|
||||
}
|
||||
|
||||
memset(rp_header, 0, sizeof(*rp_header));
|
||||
|
@ -233,7 +233,6 @@ int WSAAPI bind(SOCKET fd, const struct sockaddr *addr, int addrlen) {
|
||||
|
||||
if(ptr) {
|
||||
struct sockaddr_ipx ipxaddr;
|
||||
char net_s[12], node_s[18];
|
||||
|
||||
if(addrlen < sizeof(ipxaddr)) {
|
||||
RETURN_WSA(WSAEFAULT, -1);
|
||||
@ -241,10 +240,9 @@ int WSAAPI bind(SOCKET fd, const struct sockaddr *addr, int addrlen) {
|
||||
|
||||
memcpy(&ipxaddr, addr, sizeof(ipxaddr));
|
||||
|
||||
NET_TO_STRING(net_s, ipxaddr.sa_netnum);
|
||||
NODE_TO_STRING(node_s, ipxaddr.sa_nodenum);
|
||||
IPX_STRING_ADDR(req_addr_s, ipxaddr.sa_netnum, ipxaddr.sa_nodenum, ipxaddr.sa_socket);
|
||||
|
||||
log_printf(LOG_INFO, "bind(%d, net=%s node=%s socket=%hu)", fd, net_s, node_s, ntohs(ipxaddr.sa_socket));
|
||||
log_printf(LOG_INFO, "bind(%d, %s)", fd, req_addr_s);
|
||||
|
||||
if(ptr->flags & IPX_BOUND) {
|
||||
log_printf(LOG_ERROR, "bind failed: socket already bound");
|
||||
@ -255,10 +253,9 @@ int WSAAPI bind(SOCKET fd, const struct sockaddr *addr, int addrlen) {
|
||||
RETURN(-1);
|
||||
}
|
||||
|
||||
NET_TO_STRING(net_s, ipxaddr.sa_netnum);
|
||||
NODE_TO_STRING(node_s, ipxaddr.sa_nodenum);
|
||||
IPX_STRING_ADDR(got_addr_s, ipxaddr.sa_netnum, ipxaddr.sa_nodenum, ipxaddr.sa_socket);
|
||||
|
||||
log_printf(LOG_INFO, "bind address: net=%s node=%s socket=%hu", net_s, node_s, ntohs(ipxaddr.sa_socket));
|
||||
log_printf(LOG_INFO, "bind address: %s", got_addr_s);
|
||||
|
||||
struct sockaddr_in bind_addr;
|
||||
bind_addr.sin_family = AF_INET;
|
||||
@ -363,12 +360,11 @@ static int recv_packet(ipx_socket *sockptr, char *buf, int bufsize, int flags, s
|
||||
return -1;
|
||||
}
|
||||
|
||||
if(min_log_level <= LOG_DEBUG) {
|
||||
char net_s[12], node_s[18];
|
||||
NET_TO_STRING(net_s, packet->src_net);
|
||||
NODE_TO_STRING(node_s, packet->src_node);
|
||||
if(min_log_level <= LOG_DEBUG)
|
||||
{
|
||||
IPX_STRING_ADDR(addr_s, packet->src_net, packet->src_node, packet->src_socket);
|
||||
|
||||
log_printf(LOG_DEBUG, "Received packet from %s/%s", net_s, node_s);
|
||||
log_printf(LOG_DEBUG, "Received packet from %s", addr_s);
|
||||
}
|
||||
|
||||
/* TODO: Move full sockaddr into rp_header? */
|
||||
@ -799,11 +795,9 @@ int WSAAPI sendto(SOCKET fd, const char *buf, int len, int flags, const struct s
|
||||
|
||||
struct sockaddr_in *v4 = (struct sockaddr_in*)&send_addr;
|
||||
|
||||
char net_s[12], node_s[18];
|
||||
NET_TO_STRING(net_s, packet->dest_net);
|
||||
NODE_TO_STRING(node_s, packet->dest_node);
|
||||
IPX_STRING_ADDR(addr_s, packet->dest_net, packet->dest_node, packet->dest_socket);
|
||||
|
||||
log_printf(LOG_DEBUG, "Sending packet to %s/%s (%s)", net_s, node_s, inet_ntoa(v4->sin_addr));
|
||||
log_printf(LOG_DEBUG, "Sending packet to %s (%s)", addr_s, inet_ntoa(v4->sin_addr));
|
||||
}
|
||||
|
||||
int sval = r_sendto(send_fd, (char*)packet, psize, 0, (struct sockaddr*)&send_addr, addrlen);
|
||||
|
Loading…
x
Reference in New Issue
Block a user