- 01
- 02
- 03
- 04
- 05
- 06
- 07
- 08
- 09
- 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
...
// TODO: remove this godless "switch()"!
switch(tuntype) { // TODO: Important: do as in documentation instead of reverse-ingeniering!
#define PACKET_TRY {\
if(packet->ip_v == 4) {\
hl=packet->ip_hl<<2;\
if(hl>=sizeof(*packet))\
break;\
/* TODO: Check in RFC something about of ICMP send-back in this case */\
fprintf(stderr, "Got too short IP-header (%i)...\n",hl);\
}\
if((packet->ip_v&IPV6_VERSION_MASK) == IPV6_VERSION) {\
break;\
}\
}
#define NEXT(a) tuntype=a;\
if(tuntry>=2)\
goto tun_process_switch_end;\
tuntry++;
#define CASE(a) NEXT(a);\
case a
tun_process_switch:
// switch(tuntype) {
case TUNTYPE_NORM: // NetBSD-like?
packet=(typeof(packet))ptr;
PACKET_TRY;
CASE(TUNTYPE_EXT): // FreeBSD-like?
packet=(typeof(packet))((char *)ptr + 4);
if(s>4)
if(*ptr==0x02)
PACKET_TRY;
CASE(TUNTYPE_ETH): // Ethernet? TODO: Implement VLAN-tagging
packet=(typeof(packet))((char *)ptr + sizeof(*eth));
eth=(typeof(eth))ptr;
if(!teth) {
teth=alloca(sizeof(*teth));
memcpy(&teth->ether_shost, ð->ether_dhost, sizeof(teth->ether_shost));
memcpy(&teth->ether_dhost, ð->ether_shost, sizeof(teth->ether_dhost));
teth->ether_type=ETHERTYPE_IP;
}
if(s>sizeof(*eth))
// if((*(char *)ð->ether_type==0x08/* not IPv4? */)||(*(char *)ð->ether_type==0x86/* not IPv6? */)) // TODO: Implement compatibility with all protocols over ethernet
PACKET_TRY;
NEXT(TUNTYPE_NORM);
goto tun_process_switch;
default:
tuntype=TUNTYPE_NORM;
goto tun_process_switch;
// }
tun_process_switch_end:
#undef CASE
#undef NEXT
#undef PACKET_TRY
if(tuntry<~0)
tuntry=0;
tuntype=oldtuntype;
fprintf(stderr, "Got unknown packet. Flushing...\n");
FLUSH; // Flush all. We don't know the length of packet with unknown type.. So, we have to flush the buffer, to probably get new packets from the start.
goto tun_process_while;
}
...
"Ляпотааааа"... Очень "структурный" switch...
guest 12.11.2009 20:37 # 0
guest 16.11.2009 18:15 # 0
guest 16.11.2009 18:30 # 0
guest 16.11.2009 18:31 # 0
xaionaro 17.11.2009 11:40 # +3
guest 20.11.2009 14:53 # +1
И перебранок меньше будет из-за всяких школънегов, тк с ником будет хоть немного стыдно, некоторому проценту населения.
А то все, как захотят сказать что-то гадкое и зловонное, так сразу разлогиниваються, переходя в гостя. И без угрызений совести матерьатца.
guest 20.11.2009 14:55 # 0
xaionaro 25.11.2009 18:47 # 0
guest 01.12.2009 14:23 # 0
xaionaro 01.12.2009 18:05 # 0
fasol8 07.02.2010 05:36 # 0