Annotation of embedaddon/hping2/display_ipopt.c, revision 1.1
1.1 ! misho 1: /*
! 2: * Copyright (c) 1989 The Regents of the University of California.
! 3: * All rights reserved.
! 4: *
! 5: * This code is derived from software contributed to Berkeley by
! 6: * Mike Muuss.
! 7: *
! 8: * Redistribution and use in source and binary forms, with or without
! 9: * modification, are permitted provided that the following conditions
! 10: * are met:
! 11: * 1. Redistributions of source code must retain the above copyright
! 12: * notice, this list of conditions and the following disclaimer.
! 13: * 2. Redistributions in binary form must reproduce the above copyright
! 14: * notice, this list of conditions and the following disclaimer in the
! 15: * documentation and/or other materials provided with the distribution.
! 16: * 3. All advertising materials mentioning features or use of this software
! 17: * must display the following acknowledgement:
! 18: * This product includes software developed by the University of
! 19: * California, Berkeley and its contributors.
! 20: * 4. Neither the name of the University nor the names of its contributors
! 21: * may be used to endorse or promote products derived from this software
! 22: * without specific prior written permission.
! 23: *
! 24: * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
! 25: * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
! 26: * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
! 27: * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
! 28: * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
! 29: * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
! 30: * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
! 31: * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
! 32: * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
! 33: * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
! 34: * SUCH DAMAGE.
! 35: */
! 36:
! 37: #include <stdio.h>
! 38: #include <string.h>
! 39: #include <sys/types.h>
! 40: #include <sys/socket.h>
! 41: #include <netinet/in.h>
! 42: #include <arpa/inet.h>
! 43:
! 44: #include "hping2.h"
! 45: #include "globals.h"
! 46:
! 47: /* ripped from ping */
! 48:
! 49: void display_ipopt(char* buf)
! 50: {
! 51: int i,j;
! 52: unsigned long l;
! 53: static int old_rrlen;
! 54: static char old_rr[MAX_IPOPTLEN];
! 55: unsigned char* cp;
! 56: int hlen;
! 57: struct myiphdr *ip;
! 58: struct in_addr in;
! 59:
! 60:
! 61: ip = (struct myiphdr *)buf;
! 62: hlen = ip->ihl * 4;
! 63:
! 64: cp = (u_char *)buf + sizeof(struct myiphdr);
! 65:
! 66: for (; hlen > (int)sizeof(struct myiphdr); --hlen, ++cp)
! 67: switch (*cp) {
! 68: case IPOPT_EOL:
! 69: hlen = 0;
! 70: break;
! 71: case IPOPT_LSRR:
! 72: (void)printf("LSRR: ");
! 73: hlen -= 2;
! 74: j = *++cp;
! 75: ++cp;
! 76: if (j > IPOPT_MINOFF)
! 77: for (;;) {
! 78: l = *++cp;
! 79: l = (l<<8) + *++cp;
! 80: l = (l<<8) + *++cp;
! 81: l = (l<<8) + *++cp;
! 82: in.s_addr=htonl(l);
! 83: printf("\t%s",inet_ntoa(in));
! 84: hlen -= 4;
! 85: j -= 4;
! 86: if (j <= IPOPT_MINOFF)
! 87: break;
! 88: (void)putchar('\n');
! 89: }
! 90: break;
! 91: case IPOPT_RR:
! 92: j = *++cp; /* get length */
! 93: i = *++cp; /* and pointer */
! 94: hlen -= 2;
! 95: if (i > j)
! 96: i = j;
! 97: i -= IPOPT_MINOFF;
! 98: if (i <= 0)
! 99: continue;
! 100: if (i == old_rrlen
! 101: && cp == (u_char *)buf + sizeof(struct myiphdr) + 2
! 102: && !memcmp((char *)cp, old_rr, i)) {
! 103: (void)printf("\t(same route)\n");
! 104: i = ((i + 3) / 4) * 4;
! 105: hlen -= i;
! 106: cp += i;
! 107: break;
! 108: }
! 109: old_rrlen = i;
! 110: memcpy(old_rr, cp, i);
! 111: (void)printf("RR: ");
! 112: for (;;) {
! 113: l = *++cp;
! 114: l = (l<<8) + *++cp;
! 115: l = (l<<8) + *++cp;
! 116: l = (l<<8) + *++cp;
! 117: in.s_addr=htonl(l);
! 118: printf("\t%s",inet_ntoa(in));
! 119: hlen -= 4;
! 120: i -= 4;
! 121: if (i <= 0)
! 122: break;
! 123: (void)putchar('\n');
! 124: }
! 125: putchar('\n');
! 126:
! 127: break;
! 128: case IPOPT_NOP:
! 129: (void)printf("NOP\n");
! 130: break;
! 131: default:
! 132: (void)printf("unknown option %x\n", *cp);
! 133: break;
! 134: }
! 135:
! 136: }
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>