Annotation of embedaddon/hping2/sendip_handler.c, revision 1.1.1.1

1.1       misho       1: /* 
                      2:  * $smu-mark$ 
                      3:  * $name: sendip_handler.c$ 
                      4:  * $author: Salvatore Sanfilippo <antirez@invece.org>$ 
                      5:  * $copyright: Copyright (C) 1999 by Salvatore Sanfilippo$ 
                      6:  * $license: This software is under GPL version 2 of license$ 
                      7:  * $date: Fri Nov  5 11:55:49 MET 1999$ 
                      8:  * $rev: 3$ 
                      9:  */ 
                     10: 
                     11: #include <stdio.h>
                     12: 
                     13: #include "hping2.h"
                     14: #include "globals.h"
                     15: 
                     16: void send_ip_handler(char *packet, unsigned int size)
                     17: {
                     18:        ip_optlen = ip_opt_build(ip_opt);
                     19: 
                     20:        if (!opt_fragment && (size+ip_optlen+20 >= h_if_mtu))
                     21:        {
                     22:                /* auto-activate fragmentation */
                     23:                virtual_mtu = h_if_mtu-20;
                     24:                virtual_mtu = virtual_mtu - (virtual_mtu % 8);
                     25:                opt_fragment = TRUE;
                     26:                opt_mf = opt_df = FALSE; /* deactivate incompatible options */
                     27:                if (opt_verbose || opt_debug)
                     28:                        printf("auto-activate fragmentation, fragments size: %d\n", virtual_mtu);
                     29:        }
                     30: 
                     31:        if (!opt_fragment)
                     32:        {
                     33:                unsigned short fragment_flag = 0;
                     34: 
                     35:                if (opt_mf) fragment_flag |= MF; /* more fragments */
                     36:                if (opt_df) fragment_flag |= DF; /* dont fragment */
                     37:                send_ip((char*)&local.sin_addr,
                     38:                        (char*)&remote.sin_addr,
                     39:                        packet, size, fragment_flag, ip_frag_offset,
                     40:                        ip_opt, ip_optlen);
                     41:        }
                     42:        else
                     43:        {
                     44:                unsigned int remainder = size;
                     45:                int frag_offset = 0;
                     46: 
                     47:                while(1) {
                     48:                        if (remainder <= virtual_mtu)
                     49:                                break;
                     50: 
                     51:                        send_ip((char*)&local.sin_addr,
                     52:                                (char*)&remote.sin_addr,
                     53:                                packet+frag_offset,
                     54:                                virtual_mtu, MF, frag_offset,
                     55:                                ip_opt, ip_optlen);
                     56: 
                     57:                        remainder-=virtual_mtu;
                     58:                        frag_offset+=virtual_mtu;
                     59:                }
                     60: 
                     61:                send_ip((char*)&local.sin_addr,
                     62:                        (char*)&remote.sin_addr,
                     63:                        packet+frag_offset,
                     64:                        remainder, NF, frag_offset,
                     65:                        ip_opt, ip_optlen);
                     66:        }
                     67: }

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>