diff options
| author | Root THC | 2026-02-24 12:42:47 +0000 |
|---|---|---|
| committer | Root THC | 2026-02-24 12:42:47 +0000 |
| commit | c9cbeced5b3f2bdd7407e29c0811e65954132540 (patch) | |
| tree | aefc355416b561111819de159ccbd86c3004cf88 /other/b-scan/tmp/modules/mod_ping.c | |
| parent | 073fe4bf9fca6bf40cef2886d75df832ef4b6fca (diff) | |
initial
Diffstat (limited to 'other/b-scan/tmp/modules/mod_ping.c')
| -rw-r--r-- | other/b-scan/tmp/modules/mod_ping.c | 205 |
1 files changed, 205 insertions, 0 deletions
diff --git a/other/b-scan/tmp/modules/mod_ping.c b/other/b-scan/tmp/modules/mod_ping.c new file mode 100644 index 0000000..73a90a4 --- /dev/null +++ b/other/b-scan/tmp/modules/mod_ping.c | |||
| @@ -0,0 +1,205 @@ | |||
| 1 | /* | ||
| 2 | * ping-module for bscan. | ||
| 3 | * IDEA: add record-route and source-route feature | ||
| 4 | * and -p pattern [where can we save our time-struct then ? | ||
| 5 | */ | ||
| 6 | |||
| 7 | #include <bscan/bscan.h> | ||
| 8 | #include <bscan/module.h> | ||
| 9 | #include <bscan/system.h> | ||
| 10 | #include <stdio.h> | ||
| 11 | |||
| 12 | |||
| 13 | #ifndef MOD_NAME | ||
| 14 | #define MOD_NAME "mod_ping" | ||
| 15 | #endif | ||
| 16 | |||
| 17 | static int process_rcv(struct _opt *); | ||
| 18 | |||
| 19 | static int isinit=0; | ||
| 20 | /* | ||
| 21 | * some variables from the binary-process | ||
| 22 | */ | ||
| 23 | extern int dlt_len; | ||
| 24 | extern u_char *align_buf; | ||
| 25 | extern unsigned short ip_options; | ||
| 26 | extern struct ip *ip; | ||
| 27 | extern struct Ether_header *eth; | ||
| 28 | extern u_int plen, pcaplen; | ||
| 29 | extern struct timeval *pts; | ||
| 30 | |||
| 31 | struct _mopt | ||
| 32 | { | ||
| 33 | int type; | ||
| 34 | int size; | ||
| 35 | } static mopt; | ||
| 36 | |||
| 37 | /* | ||
| 38 | * static functions prototypes | ||
| 39 | */ | ||
| 40 | static int mdo_opt(int, char **, struct _opt *); | ||
| 41 | static void init_vars(struct _opt *); | ||
| 42 | |||
| 43 | /* | ||
| 44 | * print out usage informations | ||
| 45 | */ | ||
| 46 | void | ||
| 47 | musage() | ||
| 48 | { | ||
| 49 | printf ("\n"MOD_NAME"\n"); | ||
| 50 | printf (" -t (echo|time) -s <size>, size of ping-data [default 56].\n"); | ||
| 51 | } | ||
| 52 | |||
| 53 | |||
| 54 | /* | ||
| 55 | * return 0 on success, != 0 on failure | ||
| 56 | */ | ||
| 57 | int | ||
| 58 | init(char **modname, int argc, char *argv[], struct _opt *opt) | ||
| 59 | { | ||
| 60 | #ifdef DEBUG | ||
| 61 | printf("MODULE INIT\n"); | ||
| 62 | #endif | ||
| 63 | if (isinit) | ||
| 64 | return(-1); | ||
| 65 | |||
| 66 | *modname = MOD_NAME; | ||
| 67 | isinit = 1; | ||
| 68 | init_vars(opt); | ||
| 69 | |||
| 70 | if (mdo_opt(argc, argv, opt) != 0) | ||
| 71 | return(-1); | ||
| 72 | |||
| 73 | return(0); | ||
| 74 | } | ||
| 75 | |||
| 76 | /* | ||
| 77 | * fini-routine. called on cleanup | ||
| 78 | */ | ||
| 79 | int | ||
| 80 | fini() | ||
| 81 | { | ||
| 82 | #ifdef DEBUG | ||
| 83 | printf("MODULE FINI\n"); | ||
| 84 | #endif | ||
| 85 | return(0); | ||
| 86 | } | ||
| 87 | |||
| 88 | |||
| 89 | /* | ||
| 90 | * Module entry point [entry] | ||
| 91 | * RMOD_OK: everything allright. send the packet out [if first] | ||
| 92 | * or do nothing [MOD_RCV]. | ||
| 93 | * RMOD_SKIP: proceed with next IP without sending out the packet. | ||
| 94 | */ | ||
| 95 | int | ||
| 96 | callmdl(int entry, struct _opt *opt) | ||
| 97 | { | ||
| 98 | #ifdef DEBUG | ||
| 99 | printf("MODULE CALLMDL\n"); | ||
| 100 | #endif | ||
| 101 | if (entry == MOD_FIRSTPKG) | ||
| 102 | { | ||
| 103 | add_icmpping (opt->packet + ETH_SIZE + IP_SIZE, mopt.size, mopt.type); | ||
| 104 | add_iphdr (opt->packet + ETH_SIZE, IPPROTO_ICMP, &opt->nt, ICMP_SIZE + mopt.size); | ||
| 105 | opt->pkg_len = IP_SIZE + ICMP_SIZE + mopt.size; | ||
| 106 | return(RMOD_OK); | ||
| 107 | } | ||
| 108 | |||
| 109 | if (entry == MOD_RCV) | ||
| 110 | process_rcv(opt); | ||
| 111 | |||
| 112 | return(RMOD_OK); | ||
| 113 | } | ||
| 114 | |||
| 115 | |||
| 116 | /* | ||
| 117 | *********************************************************** | ||
| 118 | * Our OWN/static functions for THIS module * | ||
| 119 | *********************************************************** | ||
| 120 | */ | ||
| 121 | |||
| 122 | /* | ||
| 123 | * initialize all local variables. | ||
| 124 | * We use some 'unused' variables of the masterprogramm | ||
| 125 | */ | ||
| 126 | static void | ||
| 127 | init_vars(struct _opt *opt) | ||
| 128 | { | ||
| 129 | mopt.size = ICMP_ECHO; | ||
| 130 | mopt.size = 56; | ||
| 131 | } | ||
| 132 | |||
| 133 | |||
| 134 | /* | ||
| 135 | * LOCAL/STATIC function, only available in the module | ||
| 136 | * return 0 on success, != 0 on failure | ||
| 137 | */ | ||
| 138 | static int | ||
| 139 | mdo_opt(int argc, char *argv[], struct _opt *opt) | ||
| 140 | { | ||
| 141 | extern char *optarg; | ||
| 142 | /*extern int optind, opterr, optopt;*/ | ||
| 143 | int c; | ||
| 144 | |||
| 145 | while ((c = getopt (argc, argv, "t:s:")) != -1) | ||
| 146 | { | ||
| 147 | switch (c) | ||
| 148 | { | ||
| 149 | case 't': | ||
| 150 | if (strcasecmp (optarg, "echo") == 0) | ||
| 151 | mopt.type = ICMP_ECHO; | ||
| 152 | else if (strcasecmp (optarg, "time") == 0) | ||
| 153 | mopt.type = ICMP_TSTAMP; | ||
| 154 | else | ||
| 155 | return (-1); | ||
| 156 | break; | ||
| 157 | case 's': | ||
| 158 | mopt.size = atoi(optarg); | ||
| 159 | break; | ||
| 160 | case ':': | ||
| 161 | fprintf(stderr, "missing parameter\n"); | ||
| 162 | return(-1); | ||
| 163 | default: | ||
| 164 | return(-1); | ||
| 165 | } | ||
| 166 | } | ||
| 167 | return(0); | ||
| 168 | } | ||
| 169 | |||
| 170 | |||
| 171 | /* | ||
| 172 | * handle incoming icmp ECHO_REPLY packages | ||
| 173 | */ | ||
| 174 | static int | ||
| 175 | process_rcv(struct _opt *opt) | ||
| 176 | { | ||
| 177 | struct icmp *icmp; | ||
| 178 | struct timeval now; | ||
| 179 | double rrt; | ||
| 180 | |||
| 181 | if (ip->ip_p != IPPROTO_ICMP) | ||
| 182 | return(0); | ||
| 183 | |||
| 184 | if (plen < dlt_len + IP_SIZE + ip_options + sizeof(*icmp)) | ||
| 185 | return(0); /* invalid size */ | ||
| 186 | |||
| 187 | icmp = (struct icmp *) (align_buf + IP_SIZE + ip_options); | ||
| 188 | |||
| 189 | // if ((icmp->icmp_type != 0) || (icmp->icmp_code != 0)) | ||
| 190 | // return(0); | ||
| 191 | |||
| 192 | memcpy(&now, pts, sizeof(now)); | ||
| 193 | time_diff((struct timeval *)icmp->icmp_dun.id_data, &now); | ||
| 194 | rrt = now.tv_sec * 1000.0 + now.tv_usec / 1000.0; | ||
| 195 | |||
| 196 | printf("%d bytes from %s: icmp_seq=%u ttl=%d time=%.3f ms\n", | ||
| 197 | (int)(plen - dlt_len - IP_SIZE - ip_options), | ||
| 198 | int_ntoa(ip->ip_src.s_addr), icmp->icmp_hun.ih_idseq.icd_seq, | ||
| 199 | ip->ip_ttl, rrt); | ||
| 200 | |||
| 201 | return(0); | ||
| 202 | |||
| 203 | } | ||
| 204 | |||
| 205 | |||
