mirror of
https://github.com/ep00ch/lwip-contrib-mac.git
synced 2024-09-13 12:55:26 +00:00
Changed pktif.c/pktdrv.c implementation to remove global variables -> more than one adapter can be used (needed to test DHCP on multiple adapters); added DHCP support; initialize loopif before ethernetif (little bit faster since netif_list starts with ethernetif)
This commit is contained in:
parent
cc72279627
commit
d0fee92fe2
@ -218,6 +218,18 @@
|
|||||||
</FileConfiguration>
|
</FileConfiguration>
|
||||||
</File>
|
</File>
|
||||||
</Filter>
|
</Filter>
|
||||||
|
<Filter
|
||||||
|
Name="Header Files"
|
||||||
|
>
|
||||||
|
<File
|
||||||
|
RelativePath="..\pktdrv.h"
|
||||||
|
>
|
||||||
|
</File>
|
||||||
|
<File
|
||||||
|
RelativePath="..\pktif.h"
|
||||||
|
>
|
||||||
|
</File>
|
||||||
|
</Filter>
|
||||||
</Files>
|
</Files>
|
||||||
<Globals>
|
<Globals>
|
||||||
</Globals>
|
</Globals>
|
||||||
|
@ -62,6 +62,8 @@
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#include "pktdrv.h"
|
||||||
|
|
||||||
#define WIN32_LEAN_AND_MEAN
|
#define WIN32_LEAN_AND_MEAN
|
||||||
/* get the windows definitions of the following 4 functions out of the way */
|
/* get the windows definitions of the following 4 functions out of the way */
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
@ -78,24 +80,26 @@
|
|||||||
#define PACKET_ADAPTER_BUFSIZE 512000
|
#define PACKET_ADAPTER_BUFSIZE 512000
|
||||||
#define PACKET_INPUT_BUFSIZE 256000
|
#define PACKET_INPUT_BUFSIZE 256000
|
||||||
|
|
||||||
extern void process_input(void);
|
struct packet_adapter {
|
||||||
|
input_fn input;
|
||||||
/* global variables for only one adapter */
|
void *input_fn_arg;
|
||||||
LPADAPTER lpAdapter;
|
LPADAPTER lpAdapter;
|
||||||
LPPACKET lpPacket;
|
LPPACKET lpPacket;
|
||||||
char buffer[PACKET_INPUT_BUFSIZE]; /* buffer to hold the data coming from the driver */
|
/* buffer to hold the data coming from the driver */
|
||||||
unsigned char *cur_packet;
|
char buffer[PACKET_INPUT_BUFSIZE];
|
||||||
int cur_length;
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Open a network adapter and set it up for packet input
|
* Open a network adapter and set it up for packet input
|
||||||
*
|
*
|
||||||
* @param adapter_num the index of the adapter to use
|
* @param adapter_num the index of the adapter to use
|
||||||
* @param mac_addr the MAC address of the adapter is stored here (if != NULL)
|
* @param mac_addr the MAC address of the adapter is stored here (if != NULL)
|
||||||
* @return 0 on success, -1 on failure
|
* @param input a function to call to receive a packet
|
||||||
|
* @param arg argument to pass to input
|
||||||
|
* @return an adapter handle on success, NULL on failure
|
||||||
*/
|
*/
|
||||||
int
|
void*
|
||||||
init_adapter(int adapter_num, char* mac_addr)
|
init_adapter(int adapter_num, char *mac_addr, input_fn input, void *arg)
|
||||||
{
|
{
|
||||||
void *AdapterList[MAX_NUM_ADAPTERS];
|
void *AdapterList[MAX_NUM_ADAPTERS];
|
||||||
int i;
|
int i;
|
||||||
@ -104,8 +108,13 @@ init_adapter(int adapter_num, char* mac_addr)
|
|||||||
int AdapterNum =0;
|
int AdapterNum =0;
|
||||||
ULONG AdapterLength;
|
ULONG AdapterLength;
|
||||||
PPACKET_OID_DATA ppacket_oid_data;
|
PPACKET_OID_DATA ppacket_oid_data;
|
||||||
|
struct packet_adapter *pa = malloc(sizeof(struct packet_adapter));
|
||||||
unsigned char ethaddr[ETHARP_HWADDR_LEN];
|
unsigned char ethaddr[ETHARP_HWADDR_LEN];
|
||||||
|
|
||||||
|
memset(pa, 0, sizeof(struct packet_adapter));
|
||||||
|
pa->input = input;
|
||||||
|
pa->input_fn_arg = arg;
|
||||||
|
|
||||||
memset(AdapterList, 0, sizeof(AdapterList));
|
memset(AdapterList, 0, sizeof(AdapterList));
|
||||||
memset(AdapterName, 0, sizeof(AdapterName));
|
memset(AdapterName, 0, sizeof(AdapterName));
|
||||||
|
|
||||||
@ -114,7 +123,8 @@ init_adapter(int adapter_num, char* mac_addr)
|
|||||||
AdapterLength = ADAPTER_NAME_LEN;
|
AdapterLength = ADAPTER_NAME_LEN;
|
||||||
if (PacketGetAdapterNames((char*)AdapterName, &AdapterLength)==FALSE){
|
if (PacketGetAdapterNames((char*)AdapterName, &AdapterLength)==FALSE){
|
||||||
printf("Unable to retrieve the list of the adapters!\n");
|
printf("Unable to retrieve the list of the adapters!\n");
|
||||||
return -1;
|
free(pa);
|
||||||
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* get the start of each adapter name in the list and put it into
|
/* get the start of each adapter name in the list and put it into
|
||||||
@ -137,86 +147,96 @@ init_adapter(int adapter_num, char* mac_addr)
|
|||||||
/* print all adapter names */
|
/* print all adapter names */
|
||||||
AdapterNum = i;
|
AdapterNum = i;
|
||||||
if (AdapterNum <= 0) {
|
if (AdapterNum <= 0) {
|
||||||
return -1; /* no adapters found */
|
free(pa);
|
||||||
|
return NULL; /* no adapters found */
|
||||||
}
|
}
|
||||||
for (i = 0; i < AdapterNum; i++) {
|
for (i = 0; i < AdapterNum; i++) {
|
||||||
printf("%2i: %s\n", i, AdapterList[i]);
|
printf("%2i: %s\n", i, AdapterList[i]);
|
||||||
}
|
}
|
||||||
/* invalid adapter index -> check this after printing the adapters */
|
/* invalid adapter index -> check this after printing the adapters */
|
||||||
if (adapter_num < 0) {
|
if (adapter_num < 0) {
|
||||||
return -1;
|
free(pa);
|
||||||
|
return NULL;
|
||||||
}
|
}
|
||||||
/* adapter index out of range */
|
/* adapter index out of range */
|
||||||
if (adapter_num >= AdapterNum) {
|
if (adapter_num >= AdapterNum) {
|
||||||
return -1;
|
free(pa);
|
||||||
|
return NULL;
|
||||||
}
|
}
|
||||||
/* set up the selected adapter */
|
/* set up the selected adapter */
|
||||||
ppacket_oid_data = malloc(sizeof(PACKET_OID_DATA) + ETHARP_HWADDR_LEN);
|
ppacket_oid_data = malloc(sizeof(PACKET_OID_DATA) + ETHARP_HWADDR_LEN);
|
||||||
lpAdapter = PacketOpenAdapter(AdapterList[adapter_num]);
|
pa->lpAdapter = PacketOpenAdapter(AdapterList[adapter_num]);
|
||||||
if (!lpAdapter || (lpAdapter->hFile == INVALID_HANDLE_VALUE)) {
|
if (!pa->lpAdapter || (pa->lpAdapter->hFile == INVALID_HANDLE_VALUE)) {
|
||||||
lpAdapter = NULL;
|
free(pa);
|
||||||
return -1;
|
return NULL;
|
||||||
}
|
}
|
||||||
/* get the MAC address of the selected adapter */
|
/* get the MAC address of the selected adapter */
|
||||||
ppacket_oid_data->Oid = OID_802_3_PERMANENT_ADDRESS;
|
ppacket_oid_data->Oid = OID_802_3_PERMANENT_ADDRESS;
|
||||||
ppacket_oid_data->Length = ETHARP_HWADDR_LEN;
|
ppacket_oid_data->Length = ETHARP_HWADDR_LEN;
|
||||||
if (!PacketRequest(lpAdapter, FALSE, ppacket_oid_data)) {
|
if (!PacketRequest(pa->lpAdapter, FALSE, ppacket_oid_data)) {
|
||||||
lpAdapter = NULL;
|
free(pa);
|
||||||
return -1;
|
return NULL;
|
||||||
}
|
}
|
||||||
/* copy the MAC address */
|
/* copy the MAC address */
|
||||||
memcpy(ðaddr, ppacket_oid_data->Data, ETHARP_HWADDR_LEN);
|
memcpy(ðaddr, ppacket_oid_data->Data, ETHARP_HWADDR_LEN);
|
||||||
free(ppacket_oid_data);
|
free(ppacket_oid_data);
|
||||||
if (mac_addr != NULL) {
|
if (mac_addr != NULL) {
|
||||||
/* copy the MAC address to the user supplied buffer, also */
|
/* copy the MAC address to the user supplied buffer, also */
|
||||||
memcpy(mac_addr, ethaddr, ETHARP_HWADDR_LEN);
|
memcpy(mac_addr, ðaddr, ETHARP_HWADDR_LEN);
|
||||||
}
|
}
|
||||||
printf("MAC: %02X:%02X:%02X:%02X:%02X:%02X\n", ethaddr[0], ethaddr[1], ethaddr[2], ethaddr[3], ethaddr[4], ethaddr[5]);
|
printf("MAC: %02X:%02X:%02X:%02X:%02X:%02X\n", ethaddr[0], ethaddr[1], ethaddr[2],
|
||||||
|
ethaddr[3], ethaddr[4], ethaddr[5]);
|
||||||
/* some more adapter settings */
|
/* some more adapter settings */
|
||||||
PacketSetBuff(lpAdapter, PACKET_ADAPTER_BUFSIZE);
|
PacketSetBuff(pa->lpAdapter, PACKET_ADAPTER_BUFSIZE);
|
||||||
PacketSetReadTimeout(lpAdapter, 1);
|
PacketSetReadTimeout(pa->lpAdapter, 1);
|
||||||
PacketSetHwFilter(lpAdapter, NDIS_PACKET_TYPE_ALL_LOCAL | NDIS_PACKET_TYPE_PROMISCUOUS);
|
PacketSetHwFilter(pa->lpAdapter, NDIS_PACKET_TYPE_ALL_LOCAL | NDIS_PACKET_TYPE_PROMISCUOUS);
|
||||||
/* set up packet descriptor (the application input buffer) */
|
/* set up packet descriptor (the application input buffer) */
|
||||||
if ((lpPacket = PacketAllocatePacket()) == NULL) {
|
if ((pa->lpPacket = PacketAllocatePacket()) == NULL) {
|
||||||
lpAdapter = NULL;
|
free(pa);
|
||||||
return -1;
|
return NULL;
|
||||||
}
|
}
|
||||||
PacketInitPacket(lpPacket,(char*)buffer, sizeof(buffer));
|
PacketInitPacket(pa->lpPacket,(char*)pa->buffer, sizeof(pa->buffer));
|
||||||
|
|
||||||
return 0;
|
return pa;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Close the adapter (no more packets can be sent or received
|
* Close the adapter (no more packets can be sent or received)
|
||||||
|
*
|
||||||
|
* @param adapter adapter handle received by a call to init_adapter, invalid on return
|
||||||
*/
|
*/
|
||||||
void
|
void
|
||||||
shutdown_adapter(void)
|
shutdown_adapter(void *adapter)
|
||||||
{
|
{
|
||||||
if (lpAdapter != NULL) {
|
struct packet_adapter *pa = (struct packet_adapter*)adapter;
|
||||||
PacketFreePacket(lpPacket);
|
if (pa != NULL) {
|
||||||
PacketCloseAdapter(lpAdapter);
|
PacketFreePacket(pa->lpPacket);
|
||||||
|
PacketCloseAdapter(pa->lpAdapter);
|
||||||
|
free(pa);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Send a packet
|
* Send a packet
|
||||||
*
|
*
|
||||||
|
* @param adapter adapter handle received by a call to init_adapter
|
||||||
* @param buffer complete packet to send (including ETH header; without CRC)
|
* @param buffer complete packet to send (including ETH header; without CRC)
|
||||||
* @param len length of the packet (including ETH header; without CRC)
|
* @param len length of the packet (including ETH header; without CRC)
|
||||||
*/
|
*/
|
||||||
int
|
int
|
||||||
packet_send(void *buffer, int len)
|
packet_send(void *adapter, void *buffer, int len)
|
||||||
{
|
{
|
||||||
|
struct packet_adapter *pa = (struct packet_adapter*)adapter;
|
||||||
LPPACKET lpPacket;
|
LPPACKET lpPacket;
|
||||||
|
|
||||||
if (lpAdapter == NULL) {
|
if (pa == NULL) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
if ((lpPacket = PacketAllocatePacket()) == NULL) {
|
if ((lpPacket = PacketAllocatePacket()) == NULL) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
PacketInitPacket(lpPacket, buffer, len);
|
PacketInitPacket(lpPacket, buffer, len);
|
||||||
if (!PacketSendPacket(lpAdapter, lpPacket, TRUE)) {
|
if (!PacketSendPacket(pa->lpAdapter, lpPacket, TRUE)) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
PacketFreePacket(lpPacket);
|
PacketFreePacket(lpPacket);
|
||||||
@ -228,16 +248,25 @@ packet_send(void *buffer, int len)
|
|||||||
* Process a packet buffer (which can hold multiple packets) and feed
|
* Process a packet buffer (which can hold multiple packets) and feed
|
||||||
* every packet to process_input().
|
* every packet to process_input().
|
||||||
*
|
*
|
||||||
* @param lpPacket the packet buffer to process */
|
* @param adapter adapter handle received by a call to init_adapter
|
||||||
|
* @param lpPacket the packet buffer to process
|
||||||
|
*/
|
||||||
static void
|
static void
|
||||||
ProcessPackets(LPPACKET lpPacket)
|
ProcessPackets(void *adapter, LPPACKET lpPacket)
|
||||||
{
|
{
|
||||||
|
struct packet_adapter *pa = (struct packet_adapter*)adapter;
|
||||||
ULONG ulLines, ulBytesReceived;
|
ULONG ulLines, ulBytesReceived;
|
||||||
char *base;
|
char *base;
|
||||||
char *buf;
|
char *buf;
|
||||||
u_int off = 0;
|
u_int off = 0;
|
||||||
u_int tlen, tlen1;
|
u_int tlen, tlen1;
|
||||||
struct bpf_hdr *hdr;
|
struct bpf_hdr *hdr;
|
||||||
|
void *cur_packet;
|
||||||
|
int cur_length;
|
||||||
|
|
||||||
|
if (pa == NULL) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
ulBytesReceived = lpPacket->ulBytesReceived;
|
ulBytesReceived = lpPacket->ulBytesReceived;
|
||||||
|
|
||||||
@ -261,18 +290,22 @@ ProcessPackets(LPPACKET lpPacket)
|
|||||||
cur_packet = base;
|
cur_packet = base;
|
||||||
off = Packet_WORDALIGN(off + tlen);
|
off = Packet_WORDALIGN(off + tlen);
|
||||||
|
|
||||||
process_input();
|
pa->input(pa->input_fn_arg, cur_packet, cur_length);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Check for newly received packets. Called in the main loop: 'interrupt' mode is not
|
* Check for newly received packets. Called in the main loop: 'interrupt' mode is not
|
||||||
* really supported :(
|
* really supported :(
|
||||||
|
*
|
||||||
|
* @param adapter adapter handle received by a call to init_adapter
|
||||||
*/
|
*/
|
||||||
void
|
void
|
||||||
update_adapter(void)
|
update_adapter(void *adapter)
|
||||||
{
|
{
|
||||||
if ((lpAdapter != NULL) && (PacketReceivePacket(lpAdapter, lpPacket, TRUE))) {
|
struct packet_adapter *pa = (struct packet_adapter*)adapter;
|
||||||
ProcessPackets(lpPacket);
|
|
||||||
|
if ((pa != NULL) && (PacketReceivePacket(pa->lpAdapter, pa->lpPacket, TRUE))) {
|
||||||
|
ProcessPackets(adapter, pa->lpPacket);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
19
ports/win32/pktdrv.h
Normal file
19
ports/win32/pktdrv.h
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
#ifndef __PKTDRV_H__
|
||||||
|
#define __PKTDRV_H__
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
|
typedef void (*input_fn)(void *arg, void *packet, int len);
|
||||||
|
|
||||||
|
void *init_adapter(int adapter_num, char *mac_addr, input_fn input, void *arg);
|
||||||
|
void shutdown_adapter(void *adapter);
|
||||||
|
int packet_send(void *adapter, void *buffer, int len);
|
||||||
|
void update_adapter(void *adapter);
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif
|
@ -62,6 +62,8 @@
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#include "pktif.h"
|
||||||
|
|
||||||
/* get the windows definitions of the following 4 functions out of the way */
|
/* get the windows definitions of the following 4 functions out of the way */
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
@ -78,6 +80,7 @@
|
|||||||
#include "lwip/snmp.h"
|
#include "lwip/snmp.h"
|
||||||
|
|
||||||
#include "netif/etharp.h"
|
#include "netif/etharp.h"
|
||||||
|
#include "pktdrv.h"
|
||||||
|
|
||||||
/* include the port-dependent configuration */
|
/* include the port-dependent configuration */
|
||||||
#include "lwipcfg_msvc.h"
|
#include "lwipcfg_msvc.h"
|
||||||
@ -94,19 +97,13 @@
|
|||||||
#define PACKET_LIB_ADAPTER_NR 0
|
#define PACKET_LIB_ADAPTER_NR 0
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
static struct eth_addr broadcastaddr = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
|
const static struct eth_addr broadcastaddr = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
|
||||||
|
|
||||||
/* Forward declarations. */
|
/* Forward declarations. */
|
||||||
static void ethernetif_input(struct netif *netif);
|
void ethernetif_process_input(void *arg, void *packet, int len);
|
||||||
|
|
||||||
static struct netif *pktif_netif;
|
static struct netif *pktif_netif;
|
||||||
|
|
||||||
extern unsigned char ethaddr[ETHARP_HWADDR_LEN];
|
|
||||||
extern unsigned char *cur_packet;
|
|
||||||
extern int cur_length;
|
|
||||||
extern int init_adapter(int adapter_num, char* mac_addr);
|
|
||||||
extern int packet_send(void *buffer, int len);
|
|
||||||
|
|
||||||
/*-----------------------------------------------------------------------------------*/
|
/*-----------------------------------------------------------------------------------*/
|
||||||
static void
|
static void
|
||||||
low_level_init(struct netif *netif)
|
low_level_init(struct netif *netif)
|
||||||
@ -116,7 +113,8 @@ low_level_init(struct netif *netif)
|
|||||||
LWIP_DEBUGF(NETIF_DEBUG, ("pktif: eth_addr %02X%02X%02X%02X%02X%02X\n",netif->hwaddr[0],netif->hwaddr[1],netif->hwaddr[2],netif->hwaddr[3],netif->hwaddr[4],netif->hwaddr[5]));
|
LWIP_DEBUGF(NETIF_DEBUG, ("pktif: eth_addr %02X%02X%02X%02X%02X%02X\n",netif->hwaddr[0],netif->hwaddr[1],netif->hwaddr[2],netif->hwaddr[3],netif->hwaddr[4],netif->hwaddr[5]));
|
||||||
|
|
||||||
/* Do whatever else is needed to initialize interface. */
|
/* Do whatever else is needed to initialize interface. */
|
||||||
if (init_adapter(PACKET_LIB_ADAPTER_NR, mac_addr) != 0) {
|
if ((netif->state = init_adapter(PACKET_LIB_ADAPTER_NR, mac_addr,
|
||||||
|
ethernetif_process_input, netif)) == NULL) {
|
||||||
printf("ERROR initializing network adapter %d!\n", PACKET_LIB_ADAPTER_NR);
|
printf("ERROR initializing network adapter %d!\n", PACKET_LIB_ADAPTER_NR);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -139,7 +137,7 @@ low_level_init(struct netif *netif)
|
|||||||
/*-----------------------------------------------------------------------------------*/
|
/*-----------------------------------------------------------------------------------*/
|
||||||
|
|
||||||
static err_t
|
static err_t
|
||||||
low_level_output(struct netif *ethernetif, struct pbuf *p)
|
low_level_output(struct netif *netif, struct pbuf *p)
|
||||||
{
|
{
|
||||||
struct pbuf *q;
|
struct pbuf *q;
|
||||||
unsigned char buffer[1600];
|
unsigned char buffer[1600];
|
||||||
@ -161,7 +159,7 @@ low_level_output(struct netif *ethernetif, struct pbuf *p)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* signal that packet should be sent(); */
|
/* signal that packet should be sent(); */
|
||||||
if (packet_send(buffer, p->tot_len) < 0) {
|
if (packet_send(netif->state, buffer, p->tot_len) < 0) {
|
||||||
return ERR_BUF;
|
return ERR_BUF;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -178,26 +176,24 @@ low_level_output(struct netif *ethernetif, struct pbuf *p)
|
|||||||
*/
|
*/
|
||||||
/*-----------------------------------------------------------------------------------*/
|
/*-----------------------------------------------------------------------------------*/
|
||||||
static struct pbuf *
|
static struct pbuf *
|
||||||
low_level_input(struct netif *netif)
|
low_level_input(struct netif *netif, void *packet, int packet_len)
|
||||||
{
|
{
|
||||||
struct pbuf *p, *q;
|
struct pbuf *p, *q;
|
||||||
int start, length;
|
int start, length;
|
||||||
struct eth_hdr *ethhdr;
|
struct eth_hdr *ethhdr;
|
||||||
|
|
||||||
/* Obtain the size of the packet and put it into the "len" variable. */
|
/* Obtain the size of the packet and put it into the "len" variable. */
|
||||||
length = cur_length;
|
length = packet_len;
|
||||||
if (length<=0) {
|
if (length <= 0) {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
ethhdr = (struct eth_hdr*)cur_packet;
|
ethhdr = (struct eth_hdr*)packet;
|
||||||
/* MAC filter: only let my MAC or non-unicast through */
|
/* MAC filter: only let my MAC or non-unicast through */
|
||||||
if (((memcmp(ðhdr->dest, &netif->hwaddr, ETHARP_HWADDR_LEN)) &&
|
if (((memcmp(ðhdr->dest, &netif->hwaddr, ETHARP_HWADDR_LEN)) &&
|
||||||
((ethhdr->dest.addr[0] & 0x01) == 0)) ||
|
((ethhdr->dest.addr[0] & 0x01) == 0)) ||
|
||||||
/* and don't let feedback packets through (limitation in winpcap?) */
|
/* and don't let feedback packets through (limitation in winpcap?) */
|
||||||
!memcmp(ðhdr->src, netif->hwaddr, ETHARP_HWADDR_LEN)) {
|
!memcmp(ðhdr->src, netif->hwaddr, ETHARP_HWADDR_LEN)) {
|
||||||
/* acknowledge that packet has been read(); */
|
|
||||||
cur_length=0;
|
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -215,19 +211,16 @@ low_level_input(struct netif *netif)
|
|||||||
variable. */
|
variable. */
|
||||||
/* read data into(q->payload, q->len); */
|
/* read data into(q->payload, q->len); */
|
||||||
LWIP_DEBUGF(NETIF_DEBUG, ("netif: recv start %i length %i q->payload %p q->len %i q->next %p\n", start, length, q->payload, (int)q->len, q->next));
|
LWIP_DEBUGF(NETIF_DEBUG, ("netif: recv start %i length %i q->payload %p q->len %i q->next %p\n", start, length, q->payload, (int)q->len, q->next));
|
||||||
memcpy(q->payload, &cur_packet[start], q->len);
|
memcpy(q->payload, &((char*)packet)[start], q->len);
|
||||||
start += q->len;
|
start += q->len;
|
||||||
length -= q->len;
|
length -= q->len;
|
||||||
if (length<=0) {
|
if (length<=0) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
/* acknowledge that packet has been read(); */
|
|
||||||
cur_length = 0;
|
|
||||||
LINK_STATS_INC(link.recv);
|
LINK_STATS_INC(link.recv);
|
||||||
} else {
|
} else {
|
||||||
/* drop packet(); */
|
/* drop packet(); */
|
||||||
cur_length = 0;
|
|
||||||
LINK_STATS_INC(link.memerr);
|
LINK_STATS_INC(link.memerr);
|
||||||
LINK_STATS_INC(link.drop);
|
LINK_STATS_INC(link.drop);
|
||||||
}
|
}
|
||||||
@ -247,16 +240,13 @@ low_level_input(struct netif *netif)
|
|||||||
*/
|
*/
|
||||||
/*-----------------------------------------------------------------------------------*/
|
/*-----------------------------------------------------------------------------------*/
|
||||||
static void
|
static void
|
||||||
ethernetif_input(struct netif *netif)
|
ethernetif_input(struct netif *netif, void *packet, int packet_len)
|
||||||
{
|
{
|
||||||
struct ethernetif *ethernetif;
|
|
||||||
struct eth_hdr *ethhdr;
|
struct eth_hdr *ethhdr;
|
||||||
struct pbuf *p;
|
struct pbuf *p;
|
||||||
|
|
||||||
ethernetif = netif->state;
|
|
||||||
|
|
||||||
/* move received packet into a new pbuf */
|
/* move received packet into a new pbuf */
|
||||||
p = low_level_input(netif);
|
p = low_level_input(netif, packet, packet_len);
|
||||||
/* no packet could be read, silently ignore this */
|
/* no packet could be read, silently ignore this */
|
||||||
if (p == NULL) {
|
if (p == NULL) {
|
||||||
return;
|
return;
|
||||||
@ -315,6 +305,19 @@ ethernetif_init(struct netif *netif)
|
|||||||
|
|
||||||
return ERR_OK;
|
return ERR_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
ethernetif_shutdown(struct netif *netif)
|
||||||
|
{
|
||||||
|
shutdown_adapter(netif->state);
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
ethernetif_poll(struct netif *netif)
|
||||||
|
{
|
||||||
|
update_adapter(netif->state);
|
||||||
|
}
|
||||||
|
|
||||||
/*-----------------------------------------------------------------------------------*/
|
/*-----------------------------------------------------------------------------------*/
|
||||||
/*
|
/*
|
||||||
* pktif_update():
|
* pktif_update():
|
||||||
@ -323,7 +326,9 @@ ethernetif_init(struct netif *netif)
|
|||||||
* be done inside a thread.
|
* be done inside a thread.
|
||||||
*/
|
*/
|
||||||
/*-----------------------------------------------------------------------------------*/
|
/*-----------------------------------------------------------------------------------*/
|
||||||
void process_input(void)
|
void
|
||||||
|
ethernetif_process_input(void *arg, void *packet, int packet_len)
|
||||||
{
|
{
|
||||||
ethernetif_input(pktif_netif);
|
struct netif *netif = (struct netif*)arg;
|
||||||
|
ethernetif_input(netif, packet, packet_len);
|
||||||
}
|
}
|
||||||
|
10
ports/win32/pktif.h
Normal file
10
ports/win32/pktif.h
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
#ifndef __PKTIF_H__
|
||||||
|
#define __PKTIF_H__
|
||||||
|
|
||||||
|
#include "lwip/err.h"
|
||||||
|
|
||||||
|
err_t ethernetif_init(struct netif *netif);
|
||||||
|
void ethernetif_shutdown(struct netif *netif);
|
||||||
|
void ethernetif_poll(struct netif *netif);
|
||||||
|
|
||||||
|
#endif
|
@ -49,6 +49,7 @@
|
|||||||
#include "lwip/tcp.h"
|
#include "lwip/tcp.h"
|
||||||
#include "lwip/udp.h"
|
#include "lwip/udp.h"
|
||||||
#include "lwip/dns.h"
|
#include "lwip/dns.h"
|
||||||
|
#include "lwip/dhcp.h"
|
||||||
|
|
||||||
/* lwIP netif includes */
|
/* lwIP netif includes */
|
||||||
#include "netif/loopif.h"
|
#include "netif/loopif.h"
|
||||||
@ -69,13 +70,11 @@
|
|||||||
#include "lwip/autoip.h"
|
#include "lwip/autoip.h"
|
||||||
#endif /* NO_SYS */
|
#endif /* NO_SYS */
|
||||||
|
|
||||||
|
#include "pktif.h"
|
||||||
|
|
||||||
/* include the port-dependent configuration */
|
/* include the port-dependent configuration */
|
||||||
#include "lwipcfg_msvc.h"
|
#include "lwipcfg_msvc.h"
|
||||||
|
|
||||||
/* some forward function definitions... */
|
|
||||||
err_t ethernetif_init(struct netif *netif);
|
|
||||||
void shutdown_adapter(void);
|
|
||||||
void update_adapter(void);
|
|
||||||
|
|
||||||
#if NO_SYS
|
#if NO_SYS
|
||||||
/* port-defined functions used for timer execution */
|
/* port-defined functions used for timer execution */
|
||||||
@ -169,25 +168,7 @@ msvc_netif_init()
|
|||||||
struct ip_addr ipaddr, netmask, gw;
|
struct ip_addr ipaddr, netmask, gw;
|
||||||
#if LWIP_HAVE_LOOPIF
|
#if LWIP_HAVE_LOOPIF
|
||||||
struct ip_addr loop_ipaddr, loop_netmask, loop_gw;
|
struct ip_addr loop_ipaddr, loop_netmask, loop_gw;
|
||||||
#endif /* LWIP_HAVE_LOOPIF */
|
|
||||||
|
|
||||||
LWIP_PORT_INIT_GW(&gw);
|
|
||||||
LWIP_PORT_INIT_IPADDR(&ipaddr);
|
|
||||||
LWIP_PORT_INIT_NETMASK(&netmask);
|
|
||||||
printf("Starting lwIP, local interface IP is %s\n", inet_ntoa(*(struct in_addr*)&ipaddr));
|
|
||||||
|
|
||||||
#if NO_SYS
|
|
||||||
#if LWIP_ARP
|
|
||||||
netif_set_default(netif_add(&netif, &ipaddr, &netmask, &gw, NULL, ethernetif_init, ethernet_input));
|
|
||||||
#else /* LWIP_ARP */
|
|
||||||
netif_set_default(netif_add(&netif, &ipaddr, &netmask, &gw, NULL, ethernetif_init, ip_input));
|
|
||||||
#endif /* LWIP_ARP */
|
|
||||||
#else /* NO_SYS */
|
|
||||||
netif_set_default(netif_add(&netif, &ipaddr, &netmask, &gw, NULL, ethernetif_init, tcpip_input));
|
|
||||||
#endif /* NO_SYS */
|
|
||||||
netif_set_up(&netif);
|
|
||||||
|
|
||||||
#if LWIP_HAVE_LOOPIF
|
|
||||||
IP4_ADDR(&loop_gw, 127,0,0,1);
|
IP4_ADDR(&loop_gw, 127,0,0,1);
|
||||||
IP4_ADDR(&loop_ipaddr, 127,0,0,1);
|
IP4_ADDR(&loop_ipaddr, 127,0,0,1);
|
||||||
IP4_ADDR(&loop_netmask, 255,0,0,0);
|
IP4_ADDR(&loop_netmask, 255,0,0,0);
|
||||||
@ -200,10 +181,38 @@ msvc_netif_init()
|
|||||||
#endif /* NO_SYS */
|
#endif /* NO_SYS */
|
||||||
netif_set_up(&loop_netif);
|
netif_set_up(&loop_netif);
|
||||||
#endif /* LWIP_HAVE_LOOPIF */
|
#endif /* LWIP_HAVE_LOOPIF */
|
||||||
|
|
||||||
|
#if LWIP_DHCP
|
||||||
|
gw.addr = 0;
|
||||||
|
ipaddr.addr = 0;
|
||||||
|
netmask.addr = 0;
|
||||||
|
printf("Starting lwIP, local interface IP is dhcp-enabled\n");
|
||||||
|
#else /* LWIP_DHCP */
|
||||||
|
LWIP_PORT_INIT_GW(&gw);
|
||||||
|
LWIP_PORT_INIT_IPADDR(&ipaddr);
|
||||||
|
LWIP_PORT_INIT_NETMASK(&netmask);
|
||||||
|
printf("Starting lwIP, local interface IP is %s\n", inet_ntoa(*(struct in_addr*)&ipaddr));
|
||||||
|
#endif /* LWIP_DHCP */
|
||||||
|
|
||||||
|
#if NO_SYS
|
||||||
|
#if LWIP_ARP
|
||||||
|
netif_set_default(netif_add(&netif, &ipaddr, &netmask, &gw, NULL, ethernetif_init, ethernet_input));
|
||||||
|
#else /* LWIP_ARP */
|
||||||
|
netif_set_default(netif_add(&netif, &ipaddr, &netmask, &gw, NULL, ethernetif_init, ip_input));
|
||||||
|
#endif /* LWIP_ARP */
|
||||||
|
#else /* NO_SYS */
|
||||||
|
netif_set_default(netif_add(&netif, &ipaddr, &netmask, &gw, NULL, ethernetif_init, tcpip_input));
|
||||||
|
#endif /* NO_SYS */
|
||||||
|
#if LWIP_DHCP
|
||||||
|
dhcp_start(&netif);
|
||||||
|
#else /* LWIP_DHCP */
|
||||||
|
netif_set_up(&netif);
|
||||||
|
#endif /* LWIP_DHCP */
|
||||||
}
|
}
|
||||||
|
|
||||||
void dns_found(const char *name, struct ip_addr *addr, void *arg)
|
void dns_found(const char *name, struct ip_addr *addr, void *arg)
|
||||||
{ printf("%s: %s\n", name, addr?inet_ntoa(*(struct in_addr*)addr):"<not found>");
|
{
|
||||||
|
printf("%s: %s\n", name, addr?inet_ntoa(*(struct in_addr*)addr):"<not found>");
|
||||||
}
|
}
|
||||||
|
|
||||||
/* This function initializes applications */
|
/* This function initializes applications */
|
||||||
@ -218,7 +227,7 @@ apps_init()
|
|||||||
}
|
}
|
||||||
#endif /* LWIP_DNS */
|
#endif /* LWIP_DNS */
|
||||||
|
|
||||||
#if LWIP_RAW
|
#if LWIP_RAW && LWIP_ICMP
|
||||||
ping_init();
|
ping_init();
|
||||||
#endif /* LWIP_RAW */
|
#endif /* LWIP_RAW */
|
||||||
|
|
||||||
@ -292,11 +301,11 @@ void main_loop()
|
|||||||
#endif /* NO_SYS */
|
#endif /* NO_SYS */
|
||||||
|
|
||||||
/* check for packets */
|
/* check for packets */
|
||||||
update_adapter();
|
ethernetif_poll(&netif);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* release the pcap library... */
|
/* release the pcap library... */
|
||||||
shutdown_adapter();
|
ethernetif_shutdown(&netif);
|
||||||
}
|
}
|
||||||
|
|
||||||
int main(void)
|
int main(void)
|
||||||
|
Loading…
Reference in New Issue
Block a user