debugging linux port
This commit is contained in:
@@ -44,7 +44,7 @@
|
|||||||
#define MAX_MPDU (MAX_HEADER+MAX_PDU)
|
#define MAX_MPDU (MAX_HEADER+MAX_PDU)
|
||||||
|
|
||||||
bool ethernet_valid(void);
|
bool ethernet_valid(void);
|
||||||
bool ethernet_cleanup(void);
|
void ethernet_cleanup(void);
|
||||||
bool ethernet_init(char *interface_name);
|
bool ethernet_init(char *interface_name);
|
||||||
|
|
||||||
/* function to send a packet out the 802.2 socket */
|
/* function to send a packet out the 802.2 socket */
|
||||||
|
|||||||
@@ -45,7 +45,6 @@
|
|||||||
#include <sys/socket.h>
|
#include <sys/socket.h>
|
||||||
#include <net/route.h>
|
#include <net/route.h>
|
||||||
#include <net/if.h>
|
#include <net/if.h>
|
||||||
|
|
||||||
#include <features.h> /* for the glibc version number */
|
#include <features.h> /* for the glibc version number */
|
||||||
#if __GLIBC__ >= 2 && __GLIBC_MINOR >= 1
|
#if __GLIBC__ >= 2 && __GLIBC_MINOR >= 1
|
||||||
#include <netpacket/packet.h>
|
#include <netpacket/packet.h>
|
||||||
@@ -56,13 +55,16 @@
|
|||||||
#include <linux/if_ether.h> /* The L2 protocols */
|
#include <linux/if_ether.h> /* The L2 protocols */
|
||||||
#endif
|
#endif
|
||||||
#include <netinet/in.h>
|
#include <netinet/in.h>
|
||||||
|
#include <arpa/inet.h>
|
||||||
|
#include <sys/un.h>
|
||||||
#include <sys/ioctl.h>
|
#include <sys/ioctl.h>
|
||||||
|
#include <netdb.h>
|
||||||
|
|
||||||
#include "bacdef.h"
|
#include "bacdef.h"
|
||||||
#include "ethernet.h"
|
#include "ethernet.h"
|
||||||
#include "bacdcode.h"
|
#include "bacdcode.h"
|
||||||
|
|
||||||
// commonly used comparison address for ethernet
|
// commonly used comparison address for ethernet
|
||||||
uint8_t Ethernet_Broadcast[MAX_MAC_LEN] =
|
uint8_t Ethernet_Broadcast[MAX_MAC_LEN] =
|
||||||
{ 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF };
|
{ 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF };
|
||||||
// commonly used empty address for ethernet quick compare
|
// commonly used empty address for ethernet quick compare
|
||||||
@@ -78,13 +80,13 @@ bool ethernet_valid(void)
|
|||||||
return (eth802_sockfd >= 0);
|
return (eth802_sockfd >= 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ethernet_cleanup(void)
|
void ethernet_cleanup(void)
|
||||||
{
|
{
|
||||||
if (ethernet_valid())
|
if (ethernet_valid())
|
||||||
close(eth802_sockfd);
|
close(eth802_sockfd);
|
||||||
eth802_sockfd = -1;
|
eth802_sockfd = -1;
|
||||||
|
|
||||||
return true;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* opens an 802.2 socket to receive and send packets */
|
/* opens an 802.2 socket to receive and send packets */
|
||||||
@@ -93,6 +95,7 @@ static int ethernet_bind(struct sockaddr *eth_addr, char *interface_name)
|
|||||||
int sock_fd = -1; // return value
|
int sock_fd = -1; // return value
|
||||||
int uid = 0;
|
int uid = 0;
|
||||||
|
|
||||||
|
fprintf(stderr,"ethernet: opening \"%s\"\n",interface_name);
|
||||||
/* check to see if we are being run as root */
|
/* check to see if we are being run as root */
|
||||||
uid = getuid();
|
uid = getuid();
|
||||||
if (uid != 0) {
|
if (uid != 0) {
|
||||||
@@ -101,21 +104,27 @@ static int ethernet_bind(struct sockaddr *eth_addr, char *interface_name)
|
|||||||
"Try running with root priveleges.\n");
|
"Try running with root priveleges.\n");
|
||||||
return sock_fd;
|
return sock_fd;
|
||||||
}
|
}
|
||||||
|
// note: on some systems you may have to add or enable in
|
||||||
|
// modules.conf (or in modutils/alias on Debian with update-modules)
|
||||||
|
// alias net-pf-17 af_packet
|
||||||
|
// Then follow it by: # modprobe af_packet
|
||||||
|
|
||||||
/* Attempt to open the socket for 802.2 ethernet frames */
|
/* Attempt to open the socket for 802.2 ethernet frames */
|
||||||
if ((sock_fd = socket(AF_INET, SOCK_PACKET, htons(ETH_P_802_2))) < 0)
|
if ((sock_fd = socket(PF_INET, SOCK_PACKET, htons(ETH_P_802_2))) < 0)
|
||||||
{
|
{
|
||||||
/* Error occured */
|
/* Error occured */
|
||||||
fprintf(stderr,
|
fprintf(stderr,
|
||||||
"ethernet: Error opening socket : %s\n",
|
"ethernet: Error opening socket: %s\n",
|
||||||
strerror(errno));
|
strerror(errno));
|
||||||
exit(-1);
|
exit(-1);
|
||||||
}
|
}
|
||||||
/* Bind the socket to an address */
|
/* Bind the socket to an address */
|
||||||
eth_addr->sa_family = AF_UNIX;
|
eth_addr->sa_family = AF_INET;
|
||||||
/* Clear the memory before copying */
|
/* Clear the memory before copying */
|
||||||
memset(eth_addr->sa_data, '\0', sizeof(struct sockaddr_in));
|
memset(eth_addr->sa_data, '\0', sizeof(struct sockaddr_in));
|
||||||
/* Strcpy the interface name into the address */
|
/* Strcpy the interface name into the address */
|
||||||
strncpy(eth_addr->sa_data, interface_name, IFNAMSIZ);
|
strncpy(eth_addr->sa_data, interface_name, IFNAMSIZ);
|
||||||
|
fprintf(stderr,"ethernet: binding \"%s\"\n",eth_addr->sa_data);
|
||||||
/* Attempt to bind the socket to the interface */
|
/* Attempt to bind the socket to the interface */
|
||||||
if (bind(sock_fd, eth_addr, sizeof(struct sockaddr)) != 0)
|
if (bind(sock_fd, eth_addr, sizeof(struct sockaddr)) != 0)
|
||||||
{
|
{
|
||||||
@@ -123,11 +132,19 @@ static int ethernet_bind(struct sockaddr *eth_addr, char *interface_name)
|
|||||||
fprintf(stderr,
|
fprintf(stderr,
|
||||||
"ethernet: Unable to bind 802.2 socket : %s\n",
|
"ethernet: Unable to bind 802.2 socket : %s\n",
|
||||||
strerror(errno));
|
strerror(errno));
|
||||||
|
fprintf(stderr,
|
||||||
|
"You might need to add the following to modules.conf\n"
|
||||||
|
"(or in modutils/alias on Debian with update-modules):\n"
|
||||||
|
"alias net-pf-17 af_packet\n"
|
||||||
|
"Then follow it by:\n"
|
||||||
|
"# modprobe af_packet\n");
|
||||||
/* Close the socket */
|
/* Close the socket */
|
||||||
close(sock_fd);
|
close(sock_fd);
|
||||||
exit(-1);
|
exit(-1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
atexit(ethernet_cleanup);
|
||||||
|
|
||||||
return sock_fd;
|
return sock_fd;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -70,6 +70,7 @@ void WhoIsHandler(
|
|||||||
int32_t low_limit = 0;
|
int32_t low_limit = 0;
|
||||||
int32_t high_limit = 0;
|
int32_t high_limit = 0;
|
||||||
|
|
||||||
|
fprintf(stderr,"Received Who-Is Request!\r");
|
||||||
len = whois_decode_service_request(
|
len = whois_decode_service_request(
|
||||||
service_request,
|
service_request,
|
||||||
service_len,
|
service_len,
|
||||||
|
|||||||
Reference in New Issue
Block a user