Previous 199869 Revisions Next

r34730 Thursday 29th January, 2015 at 22:44:06 UTC by Couriersud
Converted osd/sdl/nedev_pcap.c to dynamic library loading. (nw)
[src/osd/sdl]netdev_pcap.c sdl.mak

trunk/src/osd/sdl/netdev_pcap.c
r243241r243242
33#else
44
55#include <pcap.h>
6
7static int (*pcap_compile_dl)(pcap_t *, struct bpf_program *, char *, int, bpf_u_int32) = NULL;
8static int (*pcap_findalldevs_dl)(pcap_if_t **, char *) = NULL;
9static pcap_t *(*pcap_open_live_dl)(const char *name, int, int, int, char *) = NULL;
10static int (*pcap_next_ex_dl)(pcap_t *, struct pcap_pkthdr **, const u_char **) = NULL;
11static void (*pcap_close_dl)(pcap_t *) = NULL;
12static int (*pcap_setfilter_dl)(pcap_t *, struct bpf_program *) = NULL;
13static int (*pcap_sendpacket_dl)(pcap_t *, u_char *, int) = NULL;
14static int (*pcap_set_datalink_dl)(pcap_t *, int) = NULL;
15
16#include <dlfcn.h>
17
618#include "emu.h"
719#include "osdnet.h"
820
9#define pcap_compile_dl pcap_compile
10#define pcap_findalldevs_dl pcap_findalldevs
11#define pcap_open_live_dl pcap_open_live
12#define pcap_next_ex_dl pcap_next_ex
13#define pcap_close_dl pcap_close
14#define pcap_setfilter_dl pcap_setfilter
15#define pcap_sendpacket_dl pcap_sendpacket
16#define pcap_set_datalink_dl pcap_set_datalink
21static void *handle = NULL;
1722
18
1923class netdev_pcap : public netdev
2024{
2125public:
r243241r243242
9296{
9397   pcap_if_t *devs;
9498   char errbuf[PCAP_ERRBUF_SIZE];
99   handle = NULL;
100
101   try
102   {
103      if(!(handle = dlopen("libpcap.so", RTLD_LAZY))) throw dlerror();
104      if(!(pcap_findalldevs_dl = (int (*)(pcap_if_t **, char *))dlsym(handle, "pcap_findalldevs")))
105         throw dlerror();
106      if(!(pcap_open_live_dl = (pcap_t* (*)(const char *, int, int, int, char *))dlsym(handle, "pcap_open_live")))
107         throw dlerror();
108      if(!(pcap_next_ex_dl = (int (*)(pcap_t *, struct pcap_pkthdr **, const u_char **))dlsym(handle, "pcap_next_ex")))
109         throw dlerror();
110      if(!(pcap_compile_dl = (int (*)(pcap_t *, struct bpf_program *, char *, int, bpf_u_int32))dlsym(handle, "pcap_compile")))
111         throw dlerror();
112      if(!(pcap_close_dl = (void (*)(pcap_t *))dlsym(handle, "pcap_close")))
113         throw dlerror();
114      if(!(pcap_setfilter_dl = (int (*)(pcap_t *, struct bpf_program *))dlsym(handle, "pcap_setfilter")))
115         throw dlerror();
116      if(!(pcap_sendpacket_dl = (int (*)(pcap_t *, u_char *, int))dlsym(handle, "pcap_sendpacket")))
117         throw dlerror();
118      if(!(pcap_set_datalink_dl = (int (*)(pcap_t *, int))dlsym(handle, "pcap_set_datalink")))
119         throw dlerror();
120   }
121   catch (const char *e)
122   {
123      dlclose(handle);
124      osd_printf_verbose("Unable to load winpcap: %s\n", e);
125      return;
126   }
95127   if(pcap_findalldevs_dl(&devs, errbuf) == -1)
96128   {
129      dlclose(handle);
97130      osd_printf_verbose("Unable to get network devices: %s\n", errbuf);
98131      return;
99132   }
r243241r243242
108141void deinit_pcap()
109142{
110143   clear_netdev();
144   dlclose(handle);
145   handle = NULL;
111146}
112147
113148#endif  // SDLMAME_WIN32
trunk/src/osd/sdl/sdl.mak
r243241r243242
209209ifeq ($(TARGETOS),linux)
210210BASE_TARGETOS = unix
211211SYNC_IMPLEMENTATION = tc
212SDL_NETWORK = taptun
213#SDL_NETWORK = pcap
212#SDL_NETWORK = taptun
213SDL_NETWORK = pcap
214214
215215ifndef NO_USE_MIDI
216216INCPATH += `pkg-config --cflags alsa`


Previous 199869 Revisions Next


© 1997-2024 The MAME Team