| 1 | /* arping/src/unix.c |
| 2 | * |
| 3 | * Copyright (C) 2000-2011 Thomas Habets <[email protected]> |
| 4 | * |
| 5 | * This program is free software; you can redistribute it and/or modify |
| 6 | * it under the terms of the GNU General Public License as published by |
| 7 | * the Free Software Foundation; either version 2 of the License, or |
| 8 | * (at your option) any later version. |
| 9 | * |
| 10 | * This program is distributed in the hope that it will be useful, |
| 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 13 | * GNU General Public License for more details. |
| 14 | * |
| 15 | * You should have received a copy of the GNU General Public License along |
| 16 | * with this program; if not, write to the Free Software Foundation, Inc., |
| 17 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. |
| 18 | */ |
| 19 | #define _GNU_SOURCEcxx . . $ `src/unix.c:19:9`! |
| 20 | #if HAVE_CONFIG_Hcxx . . $ `<built-in>:411:9`! |
| 21 | #include "config.h"cxx . . $ `<file>/config.h`/ |
| 22 | #endif |
| 23 | |
| 24 | #include <errno.h> |
| 25 | #include <signal.h> |
| 26 | #include <string.h> |
| 27 | |
| 28 | #if HAVE_SYS_SOCKET_Hcxx . . $ `config.h:167:9`! |
| 29 | #include <sys/socket.h> |
| 30 | #endif |
| 31 | |
| 32 | #if HAVE_NETINET_IN_Hcxx . . $ `config.h:89:9`! |
| 33 | #include <netinet/in.h> |
| 34 | #endif |
| 35 | |
| 36 | #include <pcap.h> |
| 37 | |
| 38 | #include "arping.h"cxx . . $ `<file>/src/arping.h`/ |
| 39 | |
| 40 | #define UNUSEDcxx . . $ `src/unix.c:40:9`!(x) (void)(x) |
| 41 | |
| 42 | /** |
| 43 | * Fall back on getting device name from pcap. |
| 44 | */ |
| 45 | const char * |
| 46 | arping_lookupdev_defaultcxx . . $ arping_lookupdev_default(ace80522166ec2ef).(uint32_tcxx . . $ uint32_t# srcip, uint32_tcxx . . $ uint32_t# dstip, char *ebuf) |
| 47 | { |
| 48 | #ifdef HAVE_PCAP_FINDALLDEVScxx . . $ `config.h:98:9`! |
| 49 | UNUSEDcxx . . $ `src/unix.c:40:9`!(srcip); |
| 50 | pcap_if_tcxx . . $ pcap_if_t# *ifs = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!; |
| 51 | int rc = pcap_findalldevscxx . . $ pcap_findalldevs(6a11ba43065e6cb8).(&ifs, ebuf); |
| 52 | if (rc) { |
| 53 | return NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!; |
| 54 | } |
| 55 | |
| 56 | pcap_if_tcxx . . $ pcap_if_t# *t; |
| 57 | char* ifname = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!; |
| 58 | for (t = ifs; !ifname && t; t = t->nextcxx . . $ pcap_if#next.) { |
| 59 | #ifdef PCAP_IF_LOOPBACKcxx . . $ `<external>/6591679532602058896/pcap.h:357:9`! |
| 60 | if (t->flagscxx . . $ pcap_if#flags. & PCAP_IF_LOOPBACKcxx . . $ `<external>/6591679532602058896/pcap.h:357:9`!) { |
| 61 | continue; |
| 62 | } |
| 63 | #endif |
| 64 | #ifdef PCAP_IF_UPcxx . . $ `<external>/6591679532602058896/pcap.h:358:9`! |
| 65 | if (!(t->flagscxx . . $ pcap_if#flags. & PCAP_IF_UPcxx . . $ `<external>/6591679532602058896/pcap.h:358:9`!)) { |
| 66 | continue; |
| 67 | } |
| 68 | #endif |
| 69 | |
| 70 | // This code is only called when using -F, which is "don't try |
| 71 | // to be smart". If we wanted to be smart we would have used |
| 72 | // findif_*.c. |
| 73 | if (1) { |
| 74 | // Intentional memory leak. Caller may edit the string, |
| 75 | // so do not fix this memory leak. |
| 76 | ifname = strdupcxx . . $ strdup(a8b8e32347182212).(t->namecxx . . $ pcap_if#name.); |
| 77 | break; |
| 78 | } |
| 79 | |
| 80 | // UNREACHABLE |
| 81 | pcap_addr_tcxx . . $ pcap_addr_t# *a; |
| 82 | for (a = t->addressescxx . . $ pcap_if#addresses.; !ifname && a; a = a->nextcxx . . $ pcap_addr#next.) { |
| 83 | if (a->addrcxx . . $ pcap_addr#addr.->sa_familycxx . . $ sockaddr#sa_family. != AF_INETcxx . . $ `<external>/8962547315054503424/socket.h:97:9`!) { |
| 84 | continue; |
| 85 | } |
| 86 | const struct sockaddr_incxx . . $ sockaddr_in#* sa = (struct sockaddr_incxx . . $ sockaddr_in#*)a->addrcxx . . $ pcap_addr#addr.; |
| 87 | const struct sockaddr_incxx . . $ sockaddr_in#* smask = (struct sockaddr_incxx . . $ sockaddr_in#*)a->netmaskcxx . . $ pcap_addr#netmask.; |
| 88 | const uint32_tcxx . . $ uint32_t# addr = sa->sin_addrcxx . . $ sockaddr_in#sin_addr..s_addrcxx . . $ in_addr#s_addr.; |
| 89 | const uint32_tcxx . . $ uint32_t# mask = smask->sin_addrcxx . . $ sockaddr_in#sin_addr..s_addrcxx . . $ in_addr#s_addr.; |
| 90 | if ((addr & mask) != (dstip & mask)) { |
| 91 | // Not optimal: memory leak. |
| 92 | ifname = strdupcxx . . $ strdup(a8b8e32347182212).(t->namecxx . . $ pcap_if#name.); |
| 93 | } |
| 94 | } |
| 95 | } |
| 96 | pcap_freealldevscxx . . $ pcap_freealldevs(6416428333318598).(ifs); |
| 97 | return ifname; |
| 98 | #else |
| 99 | UNUSED(srcip); |
| 100 | UNUSED(dstip); |
| 101 | return pcap_lookupdev(ebuf); |
| 102 | #endif |
| 103 | } |
| 104 | |
| 105 | /** |
| 106 | * |
| 107 | */ |
| 108 | void |
| 109 | do_signal_initcxx . . $ do_signal_init(49f6e7a06ebc5aa8).() |
| 110 | { |
| 111 | if (SIG_ERRcxx . . $ `<external>/11773118241360591791/signum-generic.h:28:9`! == signalcxx . . $ signal(c2d516773f91faf8).(SIGINTcxx . . $ `<external>/11773118241360591791/signum-generic.h:48:9`!, sigintcxx . . $ sigint(d4f767463ce0a6b3).)) { |
| 112 | fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).(stderrcxx . . $ `<external>/232824719582829767/stdio.h:159:9`!, "arping: failed to set SIGINT handler: %s\n", |
| 113 | strerrorcxx . . $ strerror(ff224f080444ee45).(errnocxx . . $ `<external>/17633486526465735210/errno.h:38:10`!)); |
| 114 | } |
| 115 | } |
| 116 | /* ---- Emacs Variables ---- |
| 117 | * Local Variables: |
| 118 | * c-basic-offset: 8 |
| 119 | * indent-tabs-mode: nil |
| 120 | * End: |
| 121 | */ |