File: getlhs.c

package info (click to toggle)
hping2 2.rc3-3
  • links: PTS
  • area: main
  • in suites: sarge
  • size: 756 kB
  • ctags: 951
  • sloc: ansic: 6,706; makefile: 110; sh: 83
file content (127 lines) | stat: -rw-r--r-- 2,450 bytes parent folder | download | duplicates (3)
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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
/* 
 * $smu-mark$ 
 * $name: getlhs.c$ 
 * $author: Salvatore Sanfilippo <antirez@invece.org>$ 
 * $copyright: Copyright (C) 1999 by Salvatore Sanfilippo$ 
 * $license: This software is under GPL version 2 of license$ 
 * $date: Fri Nov  5 11:55:47 MET 1999$ 
 * $rev: 8$ 
 */ 

/* $Id: getlhs.c,v 1.10 2003/07/25 12:11:24 njombart Exp $ */

#include <string.h>

#include "hping2.h"
#include "globals.h"


#if (!defined OSTYPE_LINUX) || (defined FORCE_LIBPCAP)
int get_linkhdr_size(char *ifname)
{
	int dltype = pcap_datalink(pcapfp);

	if (opt_debug)
		printf("DEBUG: dltype is %d\n", dltype);

	switch(dltype) {
	case DLT_EN10MB:
	case DLT_IEEE802:
		linkhdr_size = 14;
		break;
	case DLT_SLIP:
	case DLT_SLIP_BSDOS:
		linkhdr_size = 16;
		break;
	case DLT_PPP:
	case DLT_NULL:
#ifdef DLT_PPP_SERIAL
	case DLT_PPP_SERIAL:
#endif
#ifdef DLT_LOOP
	case DLT_LOOP:
#endif
		linkhdr_size = 4;
		break;
	case DLT_PPP_BSDOS:
		linkhdr_size = 24;
		break;
	case DLT_FDDI:
		linkhdr_size = 13;
		break;
	case DLT_RAW:
		linkhdr_size = 0;
		break;
	case DLT_IEEE802_11:
		linkhdr_size = 14;
		break;
	case DLT_IEEE802_11:
		linkhdr_size = 14;
		break;
	case DLT_TOKEN_RING:
		linkhdr_size = 20;
		break;
	case DLT_ATM_RFC1483:
#ifdef DLT_CIP
	case DLT_CIP:
#endif
#ifdef DLT_ATM_CLIP
	case DLT_ATM_CLIP:
#endif
		linkhdr_size = 8;
		break;
#ifdef DLT_C_HDLC
	case DLT_C_HDLC:
		linkhdr_size = 4;
		break;
#endif
#ifdef DLT_LINUX_SLL
	case DLT_LINUX_SLL:
#endif
#ifdef DLT_LANE8023
	case DLT_LANE8023:
#endif
		linkhdr_size = 16;
		break;
	default:
		return -1;
		break;
	}
	return 0;
}
#else /* Linux... */
int get_linkhdr_size(char *ifname)
{

	if ( strstr(ifname, "ppp") ) { /* also works for ippp (ISDN) */
		linkhdr_size = PPPHDR_SIZE_LINUX;
		return 0;
	} else if ( strstr(ifname, "eth") ) {
		linkhdr_size = ETHHDR_SIZE;
		return 0;
	} else if (strstr(ifname, "ets")) {
		linkhdr_size = 0;
		return 0;
	} else if ( strstr(ifname, "lo") ) {
		linkhdr_size = LOHDR_SIZE;
		return 0;
	} else if (strstr(ifname, "atm")) {
		linkhdr_size = 0;
		return 0;
	} else if ( strstr(ifname, "wlan") ) {
		linkhdr_size = WLANHDR_SIZE;
		return 0;
	} else if (strstr(ifname, "atm")) {
		linkhdr_size = 0;
		return 0;
	} else if ( strstr(ifname, "wlan") ) {
		linkhdr_size = WLANHDR_SIZE;
		return 0;
	} else if ( strstr(ifname, "tr") ) {
		linkhdr_size = TRHDR_SIZE;
		return 0;
	}
	else
		return -1;
}
#endif /* (!defined OSTYPE_LINUX) || (defined FORCE_LIBPCAP) */