• 大小: 137KB
    文件类型: .gz
    金币: 1
    下载: 0 次
    发布日期: 2021-06-05
  • 语言: C/C++
  • 标签:

资源简介

libnet是一个小型的接口函数库,主要用C语言写成,提供了低层网络数据包的构造、处理和发送功能。libnet的开发目的是:建立一个简单统一的网络编程接口以屏蔽不同操作系统底层网络编程的差别,使得程序员将精力集中在解决关键问题上。 该源码包已经经过测试,可正常使用!

资源截图

代码片段和文件信息

/*
 *  $Id: libnet-example-1.cv 1.1.1.1 2000/05/25 00:28:49 route Exp $
 *
 *  libnet example code
 *  example 1:  raw socket api / TCP packet
 *
 *  Copyright (c) 1998 - 2001 Mike D. Schiffman 
 *  All rights reserved.
 *
 * Redistribution and use in source and binary forms with or without
 * modification are permitted provided that the following conditions
 * are met:
 * 1. Redistributions of source code must retain the above copyright
 *    notice this list of conditions and the following disclaimer.
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice this list of conditions and the following disclaimer in the
 *    documentation and/or other materials provided with the distribution.
 *
 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ‘‘AS IS‘‘ AND
 * ANY EXPRESS OR IMPLIED WARRANTIES INCLUDING BUT NOT LIMITED TO THE
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
 * FOR ANY DIRECT INDIRECT INCIDENTAL SPECIAL EXEMPLARY OR CONSEQUENTIAL
 * DAMAGES (INCLUDING BUT NOT LIMITED TO PROCUREMENT OF SUBSTITUTE GOODS
 * OR SERVICES; LOSS OF USE DATA OR PROFITS; OR BUSINESS INTERRUPTION)
 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY WHETHER IN CONTRACT STRICT
 * LIABILITY OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
 * OUT OF THE USE OF THIS SOFTWARE EVEN IF ADVISED OF THE POSSIBILITY OF
 * SUCH DAMAGE.
 *
 */

#include 

void usage(char *);

int
main(int argc char **argv)
{
    int network packet_size c;
    u_long src_ip dst_ip;
    u_short src_prt dst_prt;
    u_char *cp *packet;

    printf(“libnet example code:\tmodule 1\n\n“);
    printf(“packet injection interface:\traw socket\n“);
    printf(“packet type:\t\t\tTCP [no payload]\n“);

    src_ip  = 0;
    dst_ip  = 0;
    src_prt = 0;
    dst_prt = 0;

    while((c = getopt(argc argv “d:s:“)) != EOF)
    {      
        switch (c)
        {
            /*
             *  We expect the input to be of the form ‘ip.ip.ip.ip.port‘.  We
             *  point cp to the last dot of the IP address/port string and
             *  then seperate them with a NULL byte.  The optarg now points to
             *  just the IP address and cp points to the port.
             */
            case ‘d‘:
                if (!(cp = strrchr(optarg ‘.‘)))
                {
                    usage(argv[0]);
                }
                *cp++ = 0;
                dst_prt = (u_short)atoi(cp);
                if (!(dst_ip = libnet_name_resolve(optarg LIBNET_RESOLVE)))
                {
                    libnet_error(LIBNET_ERR_FATAL “Bad destination IP address: %s\n“ optarg);
                }
                break;
            case ‘s‘:
                if (!(cp = strrchr(optarg ‘.‘)))
                {
                    usage(argv[0]);
                }
                *cp++ = 0;
     

评论

共有 条评论

相关资源