Revision 156, 3.0 KB
(checked in by andreu, 11 years ago)
|
CaNA tool for renetcol
|
Rev | Line | |
---|
[156] | 1 | |
---|
| 2 | |
---|
| 3 | |
---|
| 4 | |
---|
| 5 | |
---|
| 6 | |
---|
| 7 | |
---|
| 8 | |
---|
| 9 | |
---|
| 10 | |
---|
| 11 | |
---|
| 12 | |
---|
| 13 | |
---|
| 14 | |
---|
| 15 | |
---|
| 16 | |
---|
| 17 | |
---|
| 18 | |
---|
| 19 | |
---|
| 20 | |
---|
| 21 | |
---|
| 22 | |
---|
| 23 | |
---|
| 24 | |
---|
| 25 | |
---|
| 26 | |
---|
| 27 | |
---|
| 28 | #define _GNU_SOURCE |
---|
| 29 | |
---|
| 30 | #include <unistd.h> |
---|
| 31 | #include <stdio.h> |
---|
| 32 | #include <string.h> |
---|
| 33 | #include <stdlib.h> |
---|
| 34 | #include <syslog.h> |
---|
| 35 | #include <sys/types.h> |
---|
| 36 | #include <sys/socket.h> |
---|
| 37 | #include <netinet/in.h> |
---|
| 38 | #include <netinet/ip.h> |
---|
| 39 | #include <netinet/udp.h> |
---|
| 40 | #include <net/if.h> |
---|
| 41 | #include <arpa/inet.h> |
---|
| 42 | #include <time.h> |
---|
| 43 | #include <errno.h> |
---|
| 44 | #include <search.h> |
---|
| 45 | #include <sys/ioctl.h> |
---|
| 46 | |
---|
| 47 | #define MAX_ROUTERS_NB 60 |
---|
| 48 | #define NB_ENTRY 600 |
---|
| 49 | #define RECEPTION_ADDRESS "" |
---|
| 50 | #define RECEPTION_PORT 9999 |
---|
| 51 | #define SOCKET_BUFFER_SIZE 1500 |
---|
| 52 | |
---|
| 53 | typedef int s32; |
---|
| 54 | typedef unsigned int u32; |
---|
| 55 | typedef char s8; |
---|
| 56 | typedef unsigned char u8; |
---|
| 57 | typedef unsigned short u16; |
---|
| 58 | typedef signed short s16; |
---|
| 59 | |
---|
| 60 | typedef struct Filter * FilterPtr; |
---|
| 61 | typedef struct Filter { |
---|
| 62 | s8 nb_filters; |
---|
| 63 | u32 new_router_ip; |
---|
| 64 | u32 new_destination_ip; |
---|
| 65 | u16 new_dest_udp_port; |
---|
| 66 | u32 second_router_ip; |
---|
| 67 | u32 second_destination_ip; |
---|
| 68 | u16 second_dest_udp_port; |
---|
| 69 | u32 third_router_ip; |
---|
| 70 | u32 third_destination_ip; |
---|
| 71 | u16 third_dest_udp_port; |
---|
| 72 | u32 fourth_router_ip; |
---|
| 73 | u32 fourth_destination_ip; |
---|
| 74 | u16 fourth_dest_udp_port; |
---|
| 75 | u32 five_router_ip; |
---|
| 76 | u32 five_destination_ip; |
---|
| 77 | u16 five_dest_udp_port; |
---|
| 78 | u32 six_router_ip; |
---|
| 79 | u32 six_destination_ip; |
---|
| 80 | u16 six_dest_udp_port; |
---|
| 81 | } FilterType; |
---|
| 82 | |
---|
| 83 | typedef struct IpHeader * IpHeaderPtr; |
---|
| 84 | typedef struct IpHeader { |
---|
| 85 | unsigned short versionAndLength; |
---|
| 86 | unsigned short tos; |
---|
| 87 | unsigned short length; |
---|
| 88 | unsigned short ident; |
---|
| 89 | unsigned short flagsAndOffset; |
---|
| 90 | unsigned short ttl; |
---|
| 91 | unsigned short protocol; |
---|
| 92 | unsigned short checksum; |
---|
| 93 | unsigned long srcAdd; |
---|
| 94 | unsigned long dstAdd; |
---|
| 95 | } IpHeaderType; |
---|
| 96 | |
---|
| 97 | typedef struct UdpHeader * UdpHeaderPtr; |
---|
| 98 | typedef struct UdpHeader { |
---|
| 99 | unsigned short srcPort; |
---|
| 100 | unsigned short dstPort; |
---|
| 101 | unsigned short length; |
---|
| 102 | unsigned short checksum; |
---|
| 103 | } UdpHeaderType; |
---|
| 104 | |
---|
| 105 | typedef struct Datagram * DatagramPtr; |
---|
| 106 | typedef struct Datagram { |
---|
| 107 | IpHeaderPtr ipH; |
---|
| 108 | UdpHeaderPtr udp_header; |
---|
| 109 | } DatagramType; |
---|
| 110 | |
---|
| 111 | struct toCkSum_UdpHeader { |
---|
| 112 | struct in_addr srcIP; |
---|
| 113 | struct in_addr dstIP; |
---|
| 114 | unsigned char padding; |
---|
| 115 | unsigned char protocol; |
---|
| 116 | unsigned short udp_length; |
---|
| 117 | struct udphdr udp; |
---|
| 118 | }; |
---|