Annotation of embedaddon/libnet/src/libnet_internal.c, revision 1.1.1.3

1.1       misho       1: /*
                      2:  *  $Id: libnet_internal.c,v 1.14 2004/03/16 18:40:59 mike Exp $
                      3:  *
                      4:  *  libnet
                      5:  *  libnet_internal.c - secret routines!
                      6:  *
                      7:  *  Copyright (c) 1998 - 2004 Mike D. Schiffman <mike@infonexus.com>
                      8:  *  All rights reserved.
                      9:  *
                     10:  * Redistribution and use in source and binary forms, with or without
                     11:  * modification, are permitted provided that the following conditions
                     12:  * are met:
                     13:  * 1. Redistributions of source code must retain the above copyright
                     14:  *    notice, this list of conditions and the following disclaimer.
                     15:  * 2. Redistributions in binary form must reproduce the above copyright
                     16:  *    notice, this list of conditions and the following disclaimer in the
                     17:  *    documentation and/or other materials provided with the distribution.
                     18:  *
                     19:  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
                     20:  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
                     21:  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
                     22:  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
                     23:  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
                     24:  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
                     25:  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
                     26:  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
                     27:  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
                     28:  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
                     29:  * SUCH DAMAGE.
                     30:  *
                     31:  */
                     32: 
1.1.1.3 ! misho      33: #include "common.h"
1.1       misho      34: 
                     35: void
1.1.1.2   misho      36: libnet_diag_dump_hex(const uint8_t *packet, uint32_t len, int swap, FILE *stream)
1.1       misho      37: {
                     38:     int i, s_cnt;
1.1.1.2   misho      39:     uint16_t *p;
1.1       misho      40: 
1.1.1.2   misho      41:     p     = (uint16_t *)packet;
                     42:     s_cnt = len / sizeof(uint16_t);
1.1       misho      43: 
                     44:     fprintf(stream, "\t");
                     45:     for (i = 0; --s_cnt >= 0; i++)
                     46:     {
                     47:         if ((!(i % 8)))
                     48:         {
                     49:             fprintf(stream, "\n%02x\t", (i * 2));
                     50:         }
                     51:         fprintf(stream, "%04x ", swap ? ntohs(*(p++)) : *(p++));
                     52:     }
                     53: 
                     54:     /*
                     55:      *  Mop up an odd byte.
                     56:      */
                     57:     if (len & 1)
                     58:     {
                     59:         if ((!(i % 8)))
                     60:         {
                     61:             fprintf(stream, "\n%02x\t", (i * 2));
                     62:         }
1.1.1.2   misho      63:         fprintf(stream, "%02x ", *(uint8_t *)p);
1.1       misho      64:     }
                     65:     fprintf(stream, "\n");
                     66: }
                     67: 
                     68: 
                     69: void
                     70: libnet_diag_dump_context(libnet_t *l)
                     71: {
                     72:     if (l == NULL)
                     73:     { 
                     74:         return;
                     75:     } 
                     76: 
                     77:     fprintf(stderr, "fd:\t\t%d\n", l->fd);
                     78:  
                     79:     switch (l->injection_type)
                     80:     {
                     81:         case LIBNET_LINK:
                     82:             fprintf(stderr, "injection type:\tLIBNET_LINK\n");
                     83:             break;
                     84:         case LIBNET_RAW4:
                     85:             fprintf(stderr, "injection type:\tLIBNET_RAW4\n");
                     86:             break;
                     87:         case LIBNET_RAW6:
                     88:             fprintf(stderr, "injection type:\tLIBNET_RAW6\n");
                     89:             break;
                     90:         case LIBNET_LINK_ADV:
                     91:             fprintf(stderr, "injection type:\tLIBNET_LINK_ADV\n");
                     92:             break;
                     93:         case LIBNET_RAW4_ADV:
                     94:             fprintf(stderr, "injection type:\tLIBNET_RAW4_ADV\n");
                     95:             break;
                     96:         case LIBNET_RAW6_ADV:
                     97:             fprintf(stderr, "injection type:\tLIBNET_RAW6_ADV\n");
                     98:             break;
                     99:         default:
                    100:             fprintf(stderr, "injection type:\tinvalid injection type %d\n", 
                    101:                     l->injection_type);
                    102:             break;
                    103:     }
                    104:     
                    105:     fprintf(stderr, "pblock start:\t%p\n", l->protocol_blocks);
                    106:     fprintf(stderr, "pblock end:\t%p\n", l->pblock_end);
                    107:     fprintf(stderr, "link type:\t%d\n", l->link_type);
                    108:     fprintf(stderr, "link offset:\t%d\n", l->link_offset);
                    109:     fprintf(stderr, "aligner:\t%d\n", l->aligner);
                    110:     fprintf(stderr, "device:\t\t%s\n", l->device);
1.1.1.2   misho     111:     fprintf(stderr, "packets sent:\t%lld\n", (long long int)l->stats.packets_sent);
                    112:     fprintf(stderr, "packet errors:\t%lld\n", (long long int)l->stats.packet_errors);
                    113:     fprintf(stderr, "bytes written:\t%lld\n", (long long int)l->stats.bytes_written);
1.1       misho     114:     fprintf(stderr, "ptag state:\t%d\n", l->ptag_state);
                    115:     fprintf(stderr, "context label:\t%s\n", l->label);
                    116:     fprintf(stderr, "last errbuf:\t%s\n", l->err_buf);
                    117:     fprintf(stderr, "total size:\t%d\n", l->total_size);
                    118: }
                    119: 
                    120: void
                    121: libnet_diag_dump_pblock(libnet_t *l)
                    122: {
1.1.1.2   misho     123:     uint32_t n;
1.1       misho     124:     libnet_pblock_t *p;
                    125: 
                    126:     for (p = l->protocol_blocks; p; p = p->next)
                    127:     {
                    128:         fprintf(stderr, "pblock type:\t%s\n", 
                    129:                 libnet_diag_dump_pblock_type(p->type));
                    130:         fprintf(stderr, "ptag number:\t%d\n", p->ptag);
                    131:         fprintf(stderr, "pblock address:\t%p\n", p);
                    132:         fprintf(stderr, "next pblock\t%p ", p->next);
                    133:         if (p->next)
                    134:         {
                    135:             fprintf(stderr, "(%s)",
                    136:                     libnet_diag_dump_pblock_type(p->next->type));
                    137:         }
                    138:         fprintf(stderr, "\n");
                    139:         fprintf(stderr, "prev pblock\t%p ", p->prev);
                    140:         if (p->prev)
                    141:         {
                    142:             fprintf(stderr, "(%s)",
                    143:                     libnet_diag_dump_pblock_type(p->prev->type));
                    144:         }
                    145:         fprintf(stderr, "\n");
                    146:         fprintf(stderr, "buf:\t\t");
                    147:         for (n = 0; n < p->b_len; n++)
                    148:         {
                    149:             fprintf(stderr, "%02x", p->buf[n]);
                    150:         }
                    151:         fprintf(stderr, "\nbuffer length:\t%d\n", p->b_len);
                    152:         if ((p->flags) & LIBNET_PBLOCK_DO_CHECKSUM)
                    153:         {
                    154:             fprintf(stderr, "checksum flag:\tYes\n");
                    155:             fprintf(stderr, "chksum length:\t%d\n", p->h_len);
                    156:         }
                    157:         else
                    158:         {
                    159:             fprintf(stderr, "checksum flag:\tNo\n");
                    160:         }
                    161:         fprintf(stderr, "bytes copied:\t%d\n\n", p->copied);
                    162:     }
                    163: }
                    164: 
                    165: char *
1.1.1.2   misho     166: libnet_diag_dump_pblock_type(uint8_t type)
1.1       misho     167: {
                    168:     switch (type)
                    169:     {
1.1.1.2   misho     170:         /* below text can be regenerated using ./map-pblock-types */
1.1       misho     171:         case LIBNET_PBLOCK_ARP_H:
1.1.1.2   misho     172:             return ("arp");
1.1       misho     173:         case LIBNET_PBLOCK_DHCPV4_H:
1.1.1.2   misho     174:             return ("dhcpv4");
1.1       misho     175:         case LIBNET_PBLOCK_DNSV4_H:
1.1.1.2   misho     176:             return ("dnsv4");
1.1       misho     177:         case LIBNET_PBLOCK_ETH_H:
1.1.1.2   misho     178:             return ("eth");
1.1       misho     179:         case LIBNET_PBLOCK_ICMPV4_H:
1.1.1.2   misho     180:             return ("icmpv4");
1.1       misho     181:         case LIBNET_PBLOCK_ICMPV4_ECHO_H:
1.1.1.2   misho     182:             return ("icmpv4_echo");
1.1       misho     183:         case LIBNET_PBLOCK_ICMPV4_MASK_H:
1.1.1.2   misho     184:             return ("icmpv4_mask");
1.1       misho     185:         case LIBNET_PBLOCK_ICMPV4_UNREACH_H:
1.1.1.2   misho     186:             return ("icmpv4_unreach");
1.1       misho     187:         case LIBNET_PBLOCK_ICMPV4_TIMXCEED_H:
1.1.1.2   misho     188:             return ("icmpv4_timxceed");
1.1       misho     189:         case LIBNET_PBLOCK_ICMPV4_REDIRECT_H:
1.1.1.2   misho     190:             return ("icmpv4_redirect");
1.1       misho     191:         case LIBNET_PBLOCK_ICMPV4_TS_H:
1.1.1.2   misho     192:             return ("icmpv4_ts");
1.1       misho     193:         case LIBNET_PBLOCK_IGMP_H:
1.1.1.2   misho     194:             return ("igmp");
1.1       misho     195:         case LIBNET_PBLOCK_IPV4_H:
1.1.1.2   misho     196:             return ("ipv4");
1.1       misho     197:         case LIBNET_PBLOCK_IPO_H:
1.1.1.2   misho     198:             return ("ipo");
1.1       misho     199:         case LIBNET_PBLOCK_IPDATA:
1.1.1.2   misho     200:             return ("ipdata");
1.1       misho     201:         case LIBNET_PBLOCK_OSPF_H:
1.1.1.2   misho     202:             return ("ospf");
1.1       misho     203:         case LIBNET_PBLOCK_OSPF_HELLO_H:
1.1.1.2   misho     204:             return ("ospf_hello");
1.1       misho     205:         case LIBNET_PBLOCK_OSPF_DBD_H:
1.1.1.2   misho     206:             return ("ospf_dbd");
1.1       misho     207:         case LIBNET_PBLOCK_OSPF_LSR_H:
1.1.1.2   misho     208:             return ("ospf_lsr");
1.1       misho     209:         case LIBNET_PBLOCK_OSPF_LSU_H:
1.1.1.2   misho     210:             return ("ospf_lsu");
1.1       misho     211:         case LIBNET_PBLOCK_OSPF_LSA_H:
1.1.1.2   misho     212:             return ("ospf_lsa");
1.1       misho     213:         case LIBNET_PBLOCK_OSPF_AUTH_H:
1.1.1.2   misho     214:             return ("ospf_auth");
1.1       misho     215:         case LIBNET_PBLOCK_OSPF_CKSUM:
1.1.1.2   misho     216:             return ("ospf_cksum");
1.1       misho     217:         case LIBNET_PBLOCK_LS_RTR_H:
1.1.1.2   misho     218:             return ("ls_rtr");
1.1       misho     219:         case LIBNET_PBLOCK_LS_NET_H:
1.1.1.2   misho     220:             return ("ls_net");
1.1       misho     221:         case LIBNET_PBLOCK_LS_SUM_H:
1.1.1.2   misho     222:             return ("ls_sum");
1.1       misho     223:         case LIBNET_PBLOCK_LS_AS_EXT_H:
1.1.1.2   misho     224:             return ("ls_as_ext");
1.1       misho     225:         case LIBNET_PBLOCK_NTP_H:
1.1.1.2   misho     226:             return ("ntp");
1.1       misho     227:         case LIBNET_PBLOCK_RIP_H:
1.1.1.2   misho     228:             return ("rip");
1.1       misho     229:         case LIBNET_PBLOCK_TCP_H:
1.1.1.2   misho     230:             return ("tcp");
1.1       misho     231:         case LIBNET_PBLOCK_TCPO_H:
1.1.1.2   misho     232:             return ("tcpo");
1.1       misho     233:         case LIBNET_PBLOCK_TCPDATA:
1.1.1.2   misho     234:             return ("tcpdata");
1.1       misho     235:         case LIBNET_PBLOCK_UDP_H:
1.1.1.2   misho     236:             return ("udp");
1.1       misho     237:         case LIBNET_PBLOCK_VRRP_H:
1.1.1.2   misho     238:             return ("vrrp");
1.1       misho     239:         case LIBNET_PBLOCK_DATA_H:
                    240:             return ("data");
                    241:         case LIBNET_PBLOCK_CDP_H:
1.1.1.2   misho     242:             return ("cdp");
1.1       misho     243:         case LIBNET_PBLOCK_IPSEC_ESP_HDR_H:
1.1.1.2   misho     244:             return ("ipsec_esp_hdr");
1.1       misho     245:         case LIBNET_PBLOCK_IPSEC_ESP_FTR_H:
1.1.1.2   misho     246:             return ("ipsec_esp_ftr");
1.1       misho     247:         case LIBNET_PBLOCK_IPSEC_AH_H:
1.1.1.2   misho     248:             return ("ipsec_ah");
1.1       misho     249:         case LIBNET_PBLOCK_802_1Q_H:
1.1.1.2   misho     250:             return ("802_1q");
1.1       misho     251:         case LIBNET_PBLOCK_802_2_H:
1.1.1.2   misho     252:             return ("802_2");
1.1       misho     253:         case LIBNET_PBLOCK_802_2SNAP_H:
1.1.1.2   misho     254:             return ("802_2snap");
1.1       misho     255:         case LIBNET_PBLOCK_802_3_H:
1.1.1.2   misho     256:             return ("802_3");
1.1       misho     257:         case LIBNET_PBLOCK_STP_CONF_H:
1.1.1.2   misho     258:             return ("stp_conf");
1.1       misho     259:         case LIBNET_PBLOCK_STP_TCN_H:
1.1.1.2   misho     260:             return ("stp_tcn");
1.1       misho     261:         case LIBNET_PBLOCK_ISL_H:
1.1.1.2   misho     262:             return ("isl");
1.1       misho     263:         case LIBNET_PBLOCK_IPV6_H:
1.1.1.2   misho     264:             return ("ipv6");
1.1       misho     265:         case LIBNET_PBLOCK_802_1X_H:
1.1.1.2   misho     266:             return ("802_1x");
1.1       misho     267:         case LIBNET_PBLOCK_RPC_CALL_H:
1.1.1.2   misho     268:             return ("rpc_call");
1.1       misho     269:         case LIBNET_PBLOCK_MPLS_H:
1.1.1.2   misho     270:             return ("mpls");
1.1       misho     271:         case LIBNET_PBLOCK_FDDI_H:
1.1.1.2   misho     272:             return ("fddi");
1.1       misho     273:         case LIBNET_PBLOCK_TOKEN_RING_H:
1.1.1.2   misho     274:             return ("token_ring");
1.1       misho     275:         case LIBNET_PBLOCK_BGP4_HEADER_H:
1.1.1.2   misho     276:             return ("bgp4_header");
1.1       misho     277:         case LIBNET_PBLOCK_BGP4_OPEN_H:
1.1.1.2   misho     278:             return ("bgp4_open");
1.1       misho     279:         case LIBNET_PBLOCK_BGP4_UPDATE_H:
1.1.1.2   misho     280:             return ("bgp4_update");
1.1       misho     281:         case LIBNET_PBLOCK_BGP4_NOTIFICATION_H:
1.1.1.2   misho     282:             return ("bgp4_notification");
1.1       misho     283:         case LIBNET_PBLOCK_GRE_H:
1.1.1.2   misho     284:             return ("gre");
1.1       misho     285:         case LIBNET_PBLOCK_GRE_SRE_H:
1.1.1.2   misho     286:             return ("gre_sre");
1.1       misho     287:         case LIBNET_PBLOCK_IPV6_FRAG_H:
1.1.1.2   misho     288:             return ("ipv6_frag");
1.1       misho     289:         case LIBNET_PBLOCK_IPV6_ROUTING_H:
1.1.1.2   misho     290:             return ("ipv6_routing");
1.1       misho     291:         case LIBNET_PBLOCK_IPV6_DESTOPTS_H:
1.1.1.2   misho     292:             return ("ipv6_destopts");
1.1       misho     293:         case LIBNET_PBLOCK_IPV6_HBHOPTS_H:
1.1.1.2   misho     294:             return ("ipv6_hbhopts");
                    295:         case LIBNET_PBLOCK_SEBEK_H:
                    296:             return ("sebek");
                    297:         case LIBNET_PBLOCK_HSRP_H:
                    298:             return ("hsrp");
                    299:         case LIBNET_PBLOCK_ICMPV6_H:
                    300:             return ("icmpv6");
1.1.1.3 ! misho     301:         case LIBNET_PBLOCK_ICMPV6_ECHO_H:
        !           302:             return ("icmpv6_echo");
1.1.1.2   misho     303:         case LIBNET_PBLOCK_ICMPV6_UNREACH_H:
                    304:             return ("icmpv6_unreach");
                    305:         case LIBNET_PBLOCK_ICMPV6_NDP_NSOL_H:
                    306:             return ("icmpv6_ndp_nsol");
                    307:         case LIBNET_PBLOCK_ICMPV6_NDP_NADV_H:
                    308:             return ("icmpv6_ndp_nadv");
                    309:         case LIBNET_PBLOCK_ICMPV6_NDP_OPT_H:
                    310:             return ("icmpv6_ndp_opt");
1.1       misho     311:     }
1.1.1.2   misho     312:     return ("unrecognized pblock");
1.1       misho     313: }
1.1.1.2   misho     314: 
1.1.1.3 ! misho     315: /**
        !           316:  * Local Variables:
        !           317:  *  indent-tabs-mode: nil
        !           318:  *  c-file-style: "stroustrup"
        !           319:  * End:
        !           320:  */

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