Netexpert FAQ 网络分析专家学习建议入口 @netexpert成员申请指南
网络分析时代 netexpert积分规则的说明 Netis招贤纳士(2007年12月2日更新)
发新话题
打印

毕业设计题目--OSPF协议实现

毕业设计题目--OSPF协议实现

如题,我的题目是OSPF协议的实现,当然我一个人肯定做不完,所以只能达到勉强实现就行了。
用C写,用winpcap发包 和接收。

我不会把各种包的结构组起来,并且赋值,请教各位,请给我指导一下吧。。!!!大家共同讨论,共同进步。
定义了这么多header,却只能望着他们发愁。。

/* 14 bytes MAC header */
typedef struct mac_header{
    u_char byte1;
    u_char byte2;
    u_char byte3;
    u_char byte4;
    u_char byte5;
    u_char byte6;
    u_char byte7;
    u_char byte8;
    u_char byte9;
    u_char byte10;
    u_char byte11;
    u_char byte12;
    u_char byte13;
    u_char byte14;
}mac_header;

/* 4 bytes IP address */
typedef struct ip_address{
    u_char byte1;
    u_char byte2;
    u_char byte3;
    u_char byte4;
}ip_address,*ip_addr;

/* IPv4 header */
typedef struct ip_header{
    u_char                ver_ihl;        // Version (4 bits) + Internet header length (4 bits)
    u_char                tos;            // Type of service
    u_short                tlen;           // Total length
    u_short                identification; // Identification
    u_short                flags_fo;       // Flags (3 bits) + Fragment offset (13 bits)
    u_char                ttl;            // Time to live
    u_char                proto;          // Protocol
    u_short                crc;            // Header checksum
    ip_address  saddr;      // Source address
    ip_address  daddr;      // Destination address
    u_int                op_pad;         // Option + Padding
}ip_header;

/*
*  OSPF authentication header
*  Static header size: 8 bytes
*/
typedef struct crypt
{
    u_short ospf_auth_null; /* NULL */
    u_char ospf_auth_keyid; /* authentication key ID */
    u_char ospf_auth_len;   /* auth data length */
    u_int ospf_auth_seq;    /* cryptographic sequence number */
}crypt;

/*OSPF header
/*Static header size: 16 bytes*/
typedef struct ospf_header {
        u_char                version;
        u_char                type;
        u_short                len;
        ip_address        rtr_id;
        u_int                area_id;
        u_short                chksum;
        u_short                auth_type;
        crypt       authentication;
}ospf_header;

/*  OSPF hello header(type 1)
*  Static header size: 28 bytes*/
typedef struct hello_header {
        u_int                netmask;
        u_short                hello_interval;
        u_char                opts;
        u_char                rtr_priority;
        u_int                rtr_dead_interval;
        ip_address        d_rtr;
        ip_address        bd_rtr;
        ip_address  Neighbor;
}hello_header;


winpcap sendpacket()来通过MAC全1来发送hello包的话,并且给header赋上初值,应该怎么弄啊。。
想了很久,还是不会,请哪位高手指点迷津啊,最好能给个sample.小弟万分感激啊。
小弟水平有限。需要大家的帮助。以便快速进入正轨。谢谢。

[ 本帖最后由 zxy5207 于 2008-4-1 00:52 编辑 ]

TOP

高手们 给我指条路啊

TOP

有勇气啊, 参考一下zebra的实现。
白天图生存,晚上求发展.
----------------------------------------
解决问题,创造价值,凝聚财富。

TOP

发新话题
版块跳转