1: /*
2: * net_functions.h
3: *
4: * Created on: 30.07.2009
5: * Author: Chebotarev Roman
6: */
7:
8: #ifndef NET_FUNCTIONS_H_
9: #define NET_FUNCTIONS_H_
10:
11: #include "net.h"
12:
13: enum packet_types
14: {
15: dhcp_packet,
16: arp_packet
17: };
18:
19: /* Return pcap network device if success. Otherwise - exit from programm. */
20: pcap_t * get_device(const struct config_params * params);
21:
22: /* Calculate CRC for data in 'buffer'. Return checksumm. */
23: uint16_t rs_crc(const unsigned short *buffer, int length);
24:
25: /* Create ARP header */
26: void assemble_net_header_arp(struct arp_packet_net_header * net_header,
27: const uint8_t * ether_src,
28: uint16_t op_code);
29:
30: /* Create network header - ethernet + IP + UDP. Store in 'header'. */
31: void assemble_net_header_dhcp
32: (
33: struct dhcp_packet_net_header * header, /* Can't be NULL */
34: const int data_len, /* Length of UDP data */
35: const struct config_params * params, /* Can't be NULL */
36: const uint8_t * ether_src, /* Source ethernet address. Binary format. Can't be NULL */
37: const uint32_t dst_ip, /* If zero - using broadcast. */
38: const uint32_t src_ip
39: );
40:
41: /* Send packet to network. 'data_len' - only UDP data, exclude network headers */
42: int send_packet(pcap_t* descr, /* Can't be NULL */
43: enum packet_types packet_type, /* Type of sended packet. Se 'enum packet_types' in dhcdrop_types.h */
44: const uint8_t *snd_data, /* UDP payload. Can't be NULL */
45: const int data_len, /* Payload data length */
46: const struct config_params * params, /* May be NULL */
47: const uint8_t * ether_src, /* Source ethernet address. Can't be NULL */
48: const uint32_t dst_ip);
49:
50: #ifdef _WIN32
51: void CALLBACK timeout(UINT uTimerID, UINT uMsg, DWORD_PTR dwUser, DWORD_PTR dw1, DWORD_PTR dw2);
52: #else
53: void timeout(int signal);
54: #endif
55:
56: #endif /* NET_FUNCTIONS_H_ */
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>