trunk/src/osd/sdl/netdev_pcap.c
| r243241 | r243242 | |
| 3 | 3 | #else |
| 4 | 4 | |
| 5 | 5 | #include <pcap.h> |
| 6 | |
| 7 | static int (*pcap_compile_dl)(pcap_t *, struct bpf_program *, char *, int, bpf_u_int32) = NULL; |
| 8 | static int (*pcap_findalldevs_dl)(pcap_if_t **, char *) = NULL; |
| 9 | static pcap_t *(*pcap_open_live_dl)(const char *name, int, int, int, char *) = NULL; |
| 10 | static int (*pcap_next_ex_dl)(pcap_t *, struct pcap_pkthdr **, const u_char **) = NULL; |
| 11 | static void (*pcap_close_dl)(pcap_t *) = NULL; |
| 12 | static int (*pcap_setfilter_dl)(pcap_t *, struct bpf_program *) = NULL; |
| 13 | static int (*pcap_sendpacket_dl)(pcap_t *, u_char *, int) = NULL; |
| 14 | static int (*pcap_set_datalink_dl)(pcap_t *, int) = NULL; |
| 15 | |
| 16 | #include <dlfcn.h> |
| 17 | |
| 6 | 18 | #include "emu.h" |
| 7 | 19 | #include "osdnet.h" |
| 8 | 20 | |
| 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 |
| 21 | static void *handle = NULL; |
| 17 | 22 | |
| 18 | | |
| 19 | 23 | class netdev_pcap : public netdev |
| 20 | 24 | { |
| 21 | 25 | public: |
| r243241 | r243242 | |
| 92 | 96 | { |
| 93 | 97 | pcap_if_t *devs; |
| 94 | 98 | 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 | } |
| 95 | 127 | if(pcap_findalldevs_dl(&devs, errbuf) == -1) |
| 96 | 128 | { |
| 129 | dlclose(handle); |
| 97 | 130 | osd_printf_verbose("Unable to get network devices: %s\n", errbuf); |
| 98 | 131 | return; |
| 99 | 132 | } |
| r243241 | r243242 | |
| 108 | 141 | void deinit_pcap() |
| 109 | 142 | { |
| 110 | 143 | clear_netdev(); |
| 144 | dlclose(handle); |
| 145 | handle = NULL; |
| 111 | 146 | } |
| 112 | 147 | |
| 113 | 148 | #endif // SDLMAME_WIN32 |