Annotation of embedaddon/hping2/parseoptions.c, revision 1.1
1.1 ! misho 1: /* parseoptions.c -- options handling
! 2: * Copyright(C) 1999-2001 Salvatore Sanfilippo
! 3: * Under GPL, see the COPYING file for more information about
! 4: * the license. */
! 5:
! 6: /* $Id: parseoptions.c,v 1.25 2003/08/08 14:39:00 antirez Exp $ */
! 7:
! 8: #include <unistd.h>
! 9: #include <stdio.h>
! 10: #include <stdlib.h>
! 11: #include <string.h>
! 12: #include <sys/time.h>
! 13: #include <ctype.h>
! 14: #include <sys/socket.h>
! 15: #include <netinet/in.h>
! 16: #include <arpa/inet.h>
! 17: #include "antigetopt.h"
! 18:
! 19: #include "hping2.h"
! 20: #include "globals.h"
! 21:
! 22: enum { OPT_COUNT, OPT_INTERVAL, OPT_NUMERIC, OPT_QUIET, OPT_INTERFACE,
! 23: OPT_HELP, OPT_VERSION, OPT_DESTPORT, OPT_BASEPORT, OPT_TTL, OPT_ID,
! 24: OPT_WIN, OPT_SPOOF, OPT_FIN, OPT_SYN, OPT_RST, OPT_PUSH, OPT_ACK,
! 25: OPT_URG, OPT_XMAS, OPT_YMAS, OPT_FRAG, OPT_MOREFRAG, OPT_DONTFRAG,
! 26: OPT_FRAGOFF, OPT_TCPOFF, OPT_REL, OPT_DATA, OPT_RAWIP, OPT_ICMP,
! 27: OPT_UDP, OPT_BIND, OPT_UNBIND, OPT_DEBUG, OPT_VERBOSE, OPT_WINID,
! 28: OPT_KEEP, OPT_FILE, OPT_DUMP, OPT_PRINT, OPT_SIGN, OPT_LISTEN,
! 29: OPT_SAFE, OPT_TRACEROUTE, OPT_TOS, OPT_MTU, OPT_SEQNUM, OPT_BADCKSUM,
! 30: OPT_SETSEQ, OPT_SETACK, OPT_ICMPTYPE, OPT_ICMPCODE, OPT_END,
! 31: OPT_RROUTE, OPT_IPPROTO, OPT_ICMP_IPVER, OPT_ICMP_IPHLEN,
! 32: OPT_ICMP_IPLEN, OPT_ICMP_IPID, OPT_ICMP_IPPROTO, OPT_ICMP_CKSUM,
! 33: OPT_ICMP_TS, OPT_ICMP_ADDR, OPT_TCPEXITCODE, OPT_FAST, OPT_TR_KEEP_TTL,
! 34: OPT_TCP_TIMESTAMP, OPT_TR_STOP, OPT_TR_NO_RTT, OPT_ICMP_HELP,
! 35: OPT_RAND_DEST, OPT_RAND_SOURCE, OPT_LSRR, OPT_SSRR, OPT_ROUTE_HELP,
! 36: OPT_ICMP_IPSRC, OPT_ICMP_IPDST, OPT_ICMP_SRCPORT, OPT_ICMP_DSTPORT,
! 37: OPT_ICMP_GW, OPT_FORCE_ICMP, OPT_APD_SEND, OPT_SCAN, OPT_FASTER };
! 38:
! 39: static struct ago_optlist hping_optlist[] = {
! 40: { 'c', "count", OPT_COUNT, AGO_NEEDARG },
! 41: { 'i', "interval", OPT_INTERVAL, AGO_NEEDARG|AGO_EXCEPT0 },
! 42: { 'n', "numeric", OPT_NUMERIC, AGO_NOARG },
! 43: { 'q', "quiet", OPT_QUIET, AGO_NOARG },
! 44: { 'I', "interface", OPT_INTERFACE, AGO_NEEDARG },
! 45: { 'h', "help", OPT_HELP, AGO_NOARG },
! 46: { 'v', "version", OPT_VERSION, AGO_NOARG },
! 47: { 'p', "destport", OPT_DESTPORT, AGO_NEEDARG|AGO_EXCEPT0 },
! 48: { 's', "baseport", OPT_BASEPORT, AGO_NEEDARG|AGO_EXCEPT0 },
! 49: { 't', "ttl", OPT_TTL, AGO_NEEDARG },
! 50: { 'N', "id", OPT_ID, AGO_NEEDARG|AGO_EXCEPT0 },
! 51: { 'w', "win", OPT_WIN, AGO_NEEDARG|AGO_EXCEPT0 },
! 52: { 'a', "spoof", OPT_SPOOF, AGO_NEEDARG|AGO_EXCEPT0 },
! 53: { 'F', "fin", OPT_FIN, AGO_NOARG|AGO_EXCEPT0 },
! 54: { 'S', "syn", OPT_SYN, AGO_NOARG|AGO_EXCEPT0 },
! 55: { 'R', "rst", OPT_RST, AGO_NOARG|AGO_EXCEPT0 },
! 56: { 'P', "push", OPT_PUSH, AGO_NOARG|AGO_EXCEPT0 },
! 57: { 'A', "ack", OPT_ACK, AGO_NOARG|AGO_EXCEPT0 },
! 58: { 'U', "urg", OPT_URG, AGO_NOARG|AGO_EXCEPT0 },
! 59: { 'X', "xmas", OPT_XMAS, AGO_NOARG|AGO_EXCEPT0 },
! 60: { 'Y', "ymas", OPT_YMAS, AGO_NOARG|AGO_EXCEPT0 },
! 61: { 'f', "frag", OPT_FRAG, AGO_NOARG|AGO_EXCEPT0 },
! 62: { 'x', "morefrag", OPT_MOREFRAG, AGO_NOARG|AGO_EXCEPT0 },
! 63: { 'y', "dontfrag", OPT_DONTFRAG, AGO_NOARG },
! 64: { 'g', "fragoff", OPT_FRAGOFF, AGO_NEEDARG|AGO_EXCEPT0 },
! 65: { 'O', "tcpoff", OPT_TCPOFF, AGO_NEEDARG|AGO_EXCEPT0 },
! 66: { 'r', "rel", OPT_REL, AGO_NOARG },
! 67: { 'd', "data", OPT_DATA, AGO_NEEDARG|AGO_EXCEPT0 },
! 68: { '0', "rawip", OPT_RAWIP, AGO_NOARG|AGO_EXCEPT0 },
! 69: { '1', "icmp", OPT_ICMP, AGO_NOARG },
! 70: { '2', "udp", OPT_UDP, AGO_NOARG },
! 71: { '8', "scan", OPT_SCAN, AGO_NEEDARG },
! 72: { 'z', "bind", OPT_BIND, AGO_NOARG },
! 73: { 'Z', "unbind", OPT_UNBIND, AGO_NOARG },
! 74: { 'D', "debug", OPT_DEBUG, AGO_NOARG },
! 75: { 'V', "verbose", OPT_VERBOSE, AGO_NOARG },
! 76: { 'W', "winid", OPT_WINID, AGO_NOARG },
! 77: { 'k', "keep", OPT_KEEP, AGO_NOARG },
! 78: { 'E', "file", OPT_FILE, AGO_NEEDARG|AGO_EXCEPT0 },
! 79: { 'j', "dump", OPT_DUMP, AGO_NOARG|AGO_EXCEPT0 },
! 80: { 'J', "print", OPT_PRINT, AGO_NOARG|AGO_EXCEPT0 },
! 81: { 'e', "sign", OPT_SIGN, AGO_NEEDARG|AGO_EXCEPT0 },
! 82: { '9', "listen", OPT_LISTEN, AGO_NEEDARG|AGO_EXCEPT0 },
! 83: { 'B', "safe", OPT_SAFE, AGO_NOARG|AGO_EXCEPT0 },
! 84: { 'T', "traceroute", OPT_TRACEROUTE, AGO_NOARG },
! 85: { 'o', "tos", OPT_TOS, AGO_NEEDARG },
! 86: { 'm', "mtu", OPT_MTU, AGO_NEEDARG|AGO_EXCEPT0 },
! 87: { 'Q', "seqnum", OPT_SEQNUM, AGO_NOARG|AGO_EXCEPT0 },
! 88: { 'b', "badcksum", OPT_BADCKSUM, AGO_NOARG|AGO_EXCEPT0 },
! 89: { 'M', "setseq", OPT_SETSEQ, AGO_NEEDARG|AGO_EXCEPT0 },
! 90: { 'L', "setack", OPT_SETACK, AGO_NEEDARG|AGO_EXCEPT0 },
! 91: { 'C', "icmptype", OPT_ICMPTYPE, AGO_NEEDARG|AGO_EXCEPT0 },
! 92: { 'K', "icmpcode", OPT_ICMPCODE, AGO_NEEDARG|AGO_EXCEPT0 },
! 93: { 'u', "end", OPT_END, AGO_NOARG|AGO_EXCEPT0 },
! 94: { 'G', "rroute", OPT_RROUTE, AGO_NOARG },
! 95: { 'H', "ipproto", OPT_IPPROTO, AGO_NEEDARG|AGO_EXCEPT0 },
! 96: { '\0', "icmp-help", OPT_ICMP_HELP, AGO_NOARG },
! 97: { '\0', "icmp-ipver", OPT_ICMP_IPVER, AGO_NEEDARG|AGO_EXCEPT0 },
! 98: { '\0', "icmp-iphlen", OPT_ICMP_IPHLEN, AGO_NEEDARG|AGO_EXCEPT0 },
! 99: { '\0', "icmp-iplen", OPT_ICMP_IPLEN, AGO_NEEDARG|AGO_EXCEPT0 },
! 100: { '\0', "icmp-ipid", OPT_ICMP_IPID, AGO_NEEDARG|AGO_EXCEPT0 },
! 101: { '\0', "icmp-ipproto", OPT_ICMP_IPPROTO, AGO_NEEDARG|AGO_EXCEPT0 },
! 102: { '\0', "icmp-cksum", OPT_ICMP_CKSUM, AGO_NEEDARG|AGO_EXCEPT0 },
! 103: { '\0', "icmp-ts", OPT_ICMP_TS, AGO_NOARG },
! 104: { '\0', "icmp-addr", OPT_ICMP_ADDR, AGO_NOARG },
! 105: { '\0', "tcpexitcode", OPT_TCPEXITCODE, AGO_NOARG },
! 106: { '\0', "fast", OPT_FAST, AGO_NOARG|AGO_EXCEPT0 },
! 107: { '\0', "faster", OPT_FASTER, AGO_NOARG|AGO_EXCEPT0 },
! 108: { '\0', "tr-keep-ttl", OPT_TR_KEEP_TTL, AGO_NOARG },
! 109: { '\0', "tcp-timestamp",OPT_TCP_TIMESTAMP, AGO_NOARG },
! 110: { '\0', "tr-stop", OPT_TR_STOP, AGO_NOARG },
! 111: { '\0', "tr-no-rtt", OPT_TR_NO_RTT, AGO_NOARG },
! 112: { '\0', "rand-dest", OPT_RAND_DEST, AGO_NOARG },
! 113: { '\0', "rand-source", OPT_RAND_SOURCE, AGO_NOARG },
! 114: { '\0', "lsrr", OPT_LSRR, AGO_NEEDARG|AGO_EXCEPT0 },
! 115: { '\0', "ssrr", OPT_SSRR, AGO_NEEDARG|AGO_EXCEPT0 },
! 116: { '\0', "route-help", OPT_ROUTE_HELP, AGO_NOARG },
! 117: { '\0', "apd-send", OPT_APD_SEND, AGO_NEEDARG },
! 118: { '\0', "icmp-ipsrc", OPT_ICMP_IPSRC, AGO_NEEDARG|AGO_EXCEPT0 },
! 119: { '\0', "icmp-ipdst", OPT_ICMP_IPDST, AGO_NEEDARG|AGO_EXCEPT0 },
! 120: { '\0', "icmp-gw", OPT_ICMP_GW, AGO_NEEDARG|AGO_EXCEPT0 },
! 121: { '\0', "icmp-srcport", OPT_ICMP_SRCPORT, AGO_NEEDARG|AGO_EXCEPT0 },
! 122: { '\0', "icmp-dstport", OPT_ICMP_DSTPORT, AGO_NEEDARG|AGO_EXCEPT0 },
! 123: { '\0', "force-icmp", OPT_FORCE_ICMP, AGO_NOARG },
! 124: AGO_LIST_TERM
! 125: };
! 126:
! 127: /* The following var is turned to 1 if the -i option is used.
! 128: * This allows to assign a different delay default value if
! 129: * the scanning mode is selected. */
! 130: static int delay_changed = 0;
! 131:
! 132: static int suidtester(void)
! 133: {
! 134: return (getuid() != geteuid());
! 135: }
! 136:
! 137: void fail_parse_route(void)
! 138: {
! 139: fprintf(stderr, "RECTUM\n");
! 140: exit(1);
! 141: }
! 142:
! 143: void parse_route(unsigned char *route, unsigned int *route_len, char *str)
! 144: {
! 145: struct in_addr ip;
! 146: unsigned int i = 0;
! 147: unsigned int j;
! 148: unsigned int n = 0;
! 149: unsigned int route_ptr = 256;
! 150: char c;
! 151:
! 152: route += 3;
! 153: while (str[i] != '\0')
! 154: {
! 155: for (j = i; isalnum(str[j]) || str[j] == '.'; j++);
! 156: switch(c = str[j])
! 157: {
! 158: case '\0':
! 159: case '/':
! 160: if (n >= 62)
! 161: {
! 162: fprintf(stderr, "too long route\n");
! 163: fail_parse_route();
! 164: }
! 165: str[j] = '\0';
! 166: if (inet_aton(str+i, &ip))
! 167: {
! 168: memcpy(route+4*n, &ip.s_addr, 4);
! 169: n++;
! 170: if (c == '/')
! 171: str[j++] = '/';
! 172: break;
! 173: }
! 174: fprintf(stderr, "invalid IP adress in route\n");
! 175: fail_parse_route();
! 176: case ':':
! 177: if ((!i) && j && j < 4)
! 178: {
! 179: sscanf(str, "%u:%n", &route_ptr, &i);
! 180: if (i == ++j)
! 181: {
! 182: if (route_ptr < 256)
! 183: break;
! 184: }
! 185: }
! 186: default:
! 187: fail_parse_route();
! 188: }
! 189: i = j;
! 190: }
! 191: if (route_ptr == 256)
! 192: route[-1] = (unsigned char) ( n ? 8 : 4 );
! 193: else
! 194: route[-1] = (unsigned char) route_ptr;
! 195: *route_len = 4*n + 3;
! 196: route[-2] = (unsigned char) *route_len;
! 197: }
! 198:
! 199: int parse_options(int argc, char **argv)
! 200: {
! 201: int src_ttl_set = 0;
! 202: int targethost_set = 0;
! 203: int o;
! 204:
! 205: if (argc < 2)
! 206: return -1;
! 207:
! 208: ago_set_exception(0, suidtester, "Option disabled when setuid");
! 209:
! 210: while ((o = antigetopt(argc, argv, hping_optlist)) != AGO_EOF) {
! 211: switch(o) {
! 212: case AGO_UNKNOWN:
! 213: case AGO_REQARG:
! 214: case AGO_AMBIG:
! 215: ago_gnu_error("hping", o);
! 216: fprintf(stderr, "Try hping --help\n");
! 217: exit(1);
! 218: case AGO_ALONE:
! 219: if (targethost_set == 1) {
! 220: fprintf(stderr, "hping: you must specify only "
! 221: "one target host at a time\n");
! 222: exit(1);
! 223: } else {
! 224: strlcpy(targetname, ago_optarg, 1024);
! 225: targethost_set = 1;
! 226: }
! 227: break;
! 228: case OPT_COUNT:
! 229: count = strtol(ago_optarg, NULL, 0);
! 230: break;
! 231: case OPT_INTERVAL:
! 232: delay_changed = 1;
! 233: if (*ago_optarg == 'u') {
! 234: opt_waitinusec = TRUE;
! 235: usec_delay.it_value.tv_sec =
! 236: usec_delay.it_interval.tv_sec = 0;
! 237: usec_delay.it_value.tv_usec =
! 238: usec_delay.it_interval.tv_usec =
! 239: atol(ago_optarg+1);
! 240: }
! 241: else
! 242: sending_wait = strtol(ago_optarg, NULL, 0);
! 243: break;
! 244: case OPT_NUMERIC:
! 245: opt_numeric = TRUE;
! 246: break;
! 247: case OPT_QUIET:
! 248: opt_quiet = TRUE;
! 249: break;
! 250: case OPT_INTERFACE:
! 251: strlcpy (ifname, ago_optarg, 1024);
! 252: break;
! 253: case OPT_HELP:
! 254: show_usage();
! 255: break;
! 256: case OPT_VERSION:
! 257: show_version();
! 258: break;
! 259: case OPT_DESTPORT:
! 260: if (*ago_optarg == '+')
! 261: {
! 262: opt_incdport = TRUE;
! 263: ago_optarg++;
! 264: }
! 265: if (*ago_optarg == '+')
! 266: {
! 267: opt_force_incdport = TRUE;
! 268: ago_optarg++;
! 269: }
! 270: base_dst_port = dst_port = strtol(ago_optarg, NULL, 0);
! 271: break;
! 272: case OPT_BASEPORT:
! 273: initsport = strtol(ago_optarg, NULL, 0);
! 274: break;
! 275: case OPT_TTL:
! 276: src_ttl = strtol(ago_optarg, NULL, 0);
! 277: src_ttl_set = 1;
! 278: break;
! 279: case OPT_ID:
! 280: src_id = strtol(ago_optarg, NULL, 0);
! 281: break;
! 282: case OPT_WIN:
! 283: src_winsize = strtol(ago_optarg, NULL, 0);
! 284: break;
! 285: case OPT_SPOOF:
! 286: strlcpy (spoofaddr, ago_optarg, 1024);
! 287: break;
! 288: case OPT_FIN:
! 289: tcp_th_flags |= TH_FIN;
! 290: break;
! 291: case OPT_SYN:
! 292: tcp_th_flags |= TH_SYN;
! 293: break;
! 294: case OPT_RST:
! 295: tcp_th_flags |= TH_RST;
! 296: break;
! 297: case OPT_PUSH:
! 298: tcp_th_flags |= TH_PUSH;
! 299: break;
! 300: case OPT_ACK:
! 301: tcp_th_flags |= TH_ACK;
! 302: break;
! 303: case OPT_URG:
! 304: tcp_th_flags |= TH_URG;
! 305: break;
! 306: case OPT_XMAS:
! 307: tcp_th_flags |= TH_X;
! 308: break;
! 309: case OPT_YMAS:
! 310: tcp_th_flags |= TH_Y;
! 311: break;
! 312: case OPT_FRAG:
! 313: opt_fragment = TRUE;
! 314: break;
! 315: case OPT_MOREFRAG:
! 316: opt_mf = TRUE;
! 317: break;
! 318: case OPT_DONTFRAG:
! 319: opt_df = TRUE;
! 320: break;
! 321: case OPT_FRAGOFF:
! 322: ip_frag_offset = strtol(ago_optarg, NULL, 0);
! 323: break;
! 324: case OPT_TCPOFF:
! 325: src_thoff = strtol(ago_optarg, NULL, 0);
! 326: break;
! 327: case OPT_REL:
! 328: opt_relid = TRUE;
! 329: break;
! 330: case OPT_DATA:
! 331: data_size = strtol(ago_optarg, NULL, 0);
! 332: break;
! 333: case OPT_RAWIP:
! 334: opt_rawipmode = TRUE;
! 335: break;
! 336: case OPT_ICMP:
! 337: opt_icmpmode = TRUE;
! 338: break;
! 339: case OPT_ICMP_TS:
! 340: opt_icmpmode = TRUE;
! 341: opt_icmptype = 13;
! 342: break;
! 343: case OPT_ICMP_ADDR:
! 344: opt_icmpmode = TRUE;
! 345: opt_icmptype = 17;
! 346: break;
! 347: case OPT_UDP:
! 348: opt_udpmode = TRUE;
! 349: break;
! 350: case OPT_SCAN:
! 351: opt_scanmode = TRUE;
! 352: opt_scanports = strdup(ago_optarg);
! 353: break;
! 354: case OPT_LISTEN:
! 355: opt_listenmode = TRUE;
! 356: strlcpy(sign, ago_optarg, 1024);
! 357: signlen = strlen(ago_optarg);
! 358: break;
! 359: case OPT_IPPROTO:
! 360: raw_ip_protocol = strtol(ago_optarg, NULL, 0);
! 361: break;
! 362: case OPT_ICMPTYPE:
! 363: opt_icmpmode= TRUE;
! 364: opt_icmptype = strtol(ago_optarg, NULL, 0);
! 365: break;
! 366: case OPT_ICMPCODE:
! 367: opt_icmpmode= TRUE;
! 368: opt_icmpcode = strtol(ago_optarg, NULL, 0);
! 369: break;
! 370: case OPT_BIND:
! 371: ctrlzbind = BIND_TTL;
! 372: break;
! 373: case OPT_UNBIND:
! 374: ctrlzbind = BIND_NONE;
! 375: break;
! 376: case OPT_DEBUG:
! 377: opt_debug = TRUE;
! 378: break;
! 379: case OPT_VERBOSE:
! 380: opt_verbose = TRUE;
! 381: break;
! 382: case OPT_WINID:
! 383: opt_winid_order = TRUE;
! 384: break;
! 385: case OPT_KEEP:
! 386: opt_keepstill = TRUE;
! 387: break;
! 388: case OPT_FILE:
! 389: opt_datafromfile = TRUE;
! 390: strlcpy(datafilename, ago_optarg, 1024);
! 391: break;
! 392: case OPT_DUMP:
! 393: opt_hexdump = TRUE;
! 394: break;
! 395: case OPT_PRINT:
! 396: opt_contdump = TRUE;
! 397: break;
! 398: case OPT_SIGN:
! 399: opt_sign = TRUE;
! 400: strlcpy(sign, ago_optarg, 1024);
! 401: signlen = strlen(ago_optarg);
! 402: break;
! 403: case OPT_SAFE:
! 404: opt_safe = TRUE;
! 405: break;
! 406: case OPT_END:
! 407: opt_end = TRUE;
! 408: break;
! 409: case OPT_TRACEROUTE:
! 410: opt_traceroute = TRUE;
! 411: break;
! 412: case OPT_TOS:
! 413: if (!strcmp(ago_optarg, "help"))
! 414: tos_help();
! 415: else
! 416: {
! 417: static unsigned int tos_tmp = 0;
! 418:
! 419: sscanf(ago_optarg, "%2x", &tos_tmp);
! 420: ip_tos |= tos_tmp; /* OR tos */
! 421: }
! 422: break;
! 423: case OPT_MTU:
! 424: virtual_mtu = strtol(ago_optarg, NULL, 0);
! 425: opt_fragment = TRUE;
! 426: if(virtual_mtu > 65535) {
! 427: virtual_mtu = 65535;
! 428: printf("Specified MTU too high, "
! 429: "fixed to 65535.\n");
! 430: }
! 431: break;
! 432: case OPT_SEQNUM:
! 433: opt_seqnum = TRUE;
! 434: break;
! 435: case OPT_BADCKSUM:
! 436: opt_badcksum = TRUE;
! 437: break;
! 438: case OPT_SETSEQ:
! 439: set_seqnum = TRUE;
! 440: tcp_seqnum = strtoul(ago_optarg, NULL, 0);
! 441: break;
! 442: case OPT_SETACK:
! 443: set_ack = TRUE;
! 444: tcp_ack = strtoul(ago_optarg, NULL, 0);
! 445: break;
! 446: case OPT_RROUTE:
! 447: opt_rroute = TRUE;
! 448: break;
! 449: case OPT_ICMP_HELP:
! 450: icmp_help(); /* ICMP options help */
! 451: break;
! 452: case OPT_ICMP_IPVER:
! 453: icmp_ip_version = strtol(ago_optarg, NULL, 0);
! 454: break;
! 455: case OPT_ICMP_IPHLEN:
! 456: icmp_ip_ihl = strtol(ago_optarg, NULL, 0);
! 457: break;
! 458: case OPT_ICMP_IPLEN:
! 459: icmp_ip_tot_len = strtol(ago_optarg, NULL, 0);
! 460: break;
! 461: case OPT_ICMP_IPID:
! 462: icmp_ip_id = strtol(ago_optarg, NULL, 0);
! 463: break;
! 464: case OPT_ICMP_IPPROTO:
! 465: icmp_ip_protocol = strtol(ago_optarg, NULL, 0);
! 466: break;
! 467: case OPT_ICMP_IPSRC:
! 468: strlcpy (icmp_ip_srcip, ago_optarg, 1024);
! 469: break;
! 470: case OPT_ICMP_IPDST:
! 471: strlcpy (icmp_ip_dstip, ago_optarg, 1024);
! 472: break;
! 473: case OPT_ICMP_GW:
! 474: strlcpy (icmp_gwip, ago_optarg, 1024);
! 475: break;
! 476: case OPT_ICMP_SRCPORT:
! 477: icmp_ip_srcport = strtol(ago_optarg, NULL, 0);
! 478: break;
! 479: case OPT_ICMP_DSTPORT:
! 480: icmp_ip_dstport = strtol(ago_optarg, NULL, 0);
! 481: break;
! 482: case OPT_FORCE_ICMP:
! 483: opt_force_icmp = TRUE;
! 484: break;
! 485: case OPT_ICMP_CKSUM:
! 486: icmp_cksum = strtol(ago_optarg, NULL, 0);
! 487: break;
! 488: case OPT_TCPEXITCODE:
! 489: opt_tcpexitcode = TRUE;
! 490: break;
! 491: case OPT_FAST:
! 492: delay_changed = 1;
! 493: opt_waitinusec = TRUE;
! 494: usec_delay.it_value.tv_sec =
! 495: usec_delay.it_interval.tv_sec = 0;
! 496: usec_delay.it_value.tv_usec =
! 497: usec_delay.it_interval.tv_usec = 100000;
! 498: break;
! 499: case OPT_FASTER:
! 500: delay_changed = 1;
! 501: opt_waitinusec = TRUE;
! 502: usec_delay.it_value.tv_sec =
! 503: usec_delay.it_interval.tv_sec = 0;
! 504: usec_delay.it_value.tv_usec =
! 505: usec_delay.it_interval.tv_usec = 1;
! 506: case OPT_TR_KEEP_TTL:
! 507: opt_tr_keep_ttl = TRUE;
! 508: break;
! 509: case OPT_TCP_TIMESTAMP:
! 510: opt_tcp_timestamp = TRUE;
! 511: break;
! 512: case OPT_TR_STOP:
! 513: opt_tr_stop = TRUE;
! 514: break;
! 515: case OPT_TR_NO_RTT:
! 516: opt_tr_no_rtt = TRUE;
! 517: break;
! 518: case OPT_RAND_DEST:
! 519: opt_rand_dest = TRUE;
! 520: break;
! 521: case OPT_RAND_SOURCE:
! 522: opt_rand_source = TRUE;
! 523: break;
! 524: case OPT_LSRR:
! 525: opt_lsrr = TRUE;
! 526: parse_route(lsr, &lsr_length, ago_optarg);
! 527: if (lsr[0])
! 528: printf("Warning: erasing previously given "
! 529: "loose source route");
! 530: lsr[0] = 131;
! 531: break;
! 532: case OPT_SSRR:
! 533: opt_ssrr = TRUE;
! 534: parse_route(ssr, &ssr_length, ago_optarg);
! 535: if (ssr[0])
! 536: printf("Warning: erasing previously given "
! 537: "strong source route");
! 538: ssr[0] = 137;
! 539: break;
! 540: case OPT_ROUTE_HELP:
! 541: route_help();
! 542: break;
! 543: case OPT_APD_SEND:
! 544: hping_ars_send(ago_optarg);
! 545: break;
! 546: }
! 547: }
! 548:
! 549: /* missing target host? */
! 550: if (targethost_set == 0 && opt_listenmode && opt_safe)
! 551: {
! 552: printf(
! 553: "you must specify a target host if you require safe protocol\n"
! 554: "because hping needs a target for HCMP packets\n");
! 555: exit(1);
! 556: }
! 557:
! 558: if (targethost_set == 0 && !opt_listenmode) return -1;
! 559:
! 560: if (opt_numeric == TRUE) opt_gethost = FALSE;
! 561:
! 562: /* some error condition */
! 563: if (data_size+IPHDR_SIZE+TCPHDR_SIZE > 65535) {
! 564: printf("Option error: sorry, data size must be <= %lu\n",
! 565: (unsigned long)(65535-IPHDR_SIZE+TCPHDR_SIZE));
! 566: exit(1);
! 567: }
! 568: else if (count <= 0 && count != -1) {
! 569: printf("Option error: count must > 0\n");
! 570: exit(1);
! 571: }
! 572: else if (sending_wait < 0) {
! 573: printf("Option error: bad timing interval\n");
! 574: exit(1);
! 575: }
! 576: else if (opt_waitinusec == TRUE && usec_delay.it_value.tv_usec < 0)
! 577: {
! 578: printf("Option error: bad timing interval\n");
! 579: exit(1);
! 580: }
! 581: else if (opt_datafromfile == TRUE && data_size == 0)
! 582: {
! 583: printf("Option error: -E option useless without -d\n");
! 584: exit(1);
! 585: }
! 586: else if (opt_sign && data_size && signlen > data_size)
! 587: {
! 588: printf(
! 589: "Option error: signature (%d bytes) is larger than data size\n"
! 590: "check -d option, don't specify -d to let hping compute it\n", signlen);
! 591: exit(1);
! 592: }
! 593: else if ((opt_sign || opt_listenmode) && signlen > 1024)
! 594: {
! 595: printf("Option error: signature too big\n");
! 596: exit(1);
! 597: }
! 598: else if (opt_safe == TRUE && src_id != -1)
! 599: {
! 600: printf("Option error: sorry, you can't set id and "
! 601: "use safe protocol at some time\n");
! 602: exit(1);
! 603: }
! 604: else if (opt_safe == TRUE && opt_datafromfile == FALSE &&
! 605: opt_listenmode == FALSE)
! 606: {
! 607: printf("Option error: sorry, safe protocol is useless "
! 608: "without 'data from file' option\n");
! 609: exit(1);
! 610: }
! 611: else if (opt_safe == TRUE && opt_sign == FALSE &&
! 612: opt_listenmode == FALSE)
! 613: {
! 614: printf("Option error: sorry, safe protocol require you "
! 615: "sign your packets, see --sign | -e option\n");
! 616: exit(1);
! 617: } else if (opt_rand_dest == TRUE && ifname[0] == '\0') {
! 618: printf("Option error: you need to specify an interface "
! 619: "when the --rand-dest option is enabled\n");
! 620: exit(1);
! 621: }
! 622:
! 623: /* dependences */
! 624: if (opt_safe == TRUE)
! 625: src_id = 1;
! 626:
! 627: if (opt_traceroute == TRUE && ctrlzbind == BIND_DPORT)
! 628: ctrlzbind = BIND_TTL;
! 629:
! 630: if (opt_traceroute == TRUE && src_ttl_set == 0)
! 631: src_ttl = DEFAULT_TRACEROUTE_TTL;
! 632:
! 633: /* set the data size to the signature len if the no data size
! 634: * was specified */
! 635: if (opt_sign && !data_size)
! 636: data_size = signlen;
! 637:
! 638: /* If scan mode is on, and the -i option was not used,
! 639: * set the default delay to zero, that's send packets
! 640: * as fast as possible. */
! 641: if (opt_scanmode && !delay_changed) {
! 642: opt_waitinusec = TRUE;
! 643: usec_delay.it_value.tv_sec =
! 644: usec_delay.it_interval.tv_sec = 0;
! 645: usec_delay.it_value.tv_usec =
! 646: usec_delay.it_interval.tv_usec = 0;
! 647: }
! 648:
! 649: return 1;
! 650: }
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>