Rev 4505 | Rev 4589 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
| Rev 4505 | Rev 4558 | ||
|---|---|---|---|
| Line 43... | Line 43... | ||
| 43 | #include "../../structures/packet/packet.h" |
43 | #include "../../structures/packet/packet.h" |
| 44 | #include "../../structures/packet/packet_client.h" |
44 | #include "../../structures/packet/packet_client.h" |
| 45 | 45 | ||
| 46 | #include "ip_header.h" |
46 | #include "ip_header.h" |
| 47 | 47 | ||
| 48 | int ip_client_prepare_packet( packet_t packet, int protocol, int ttl, int tos, int dont_fragment, int ipopt_length ){ |
48 | int ip_client_prepare_packet( packet_t packet, ip_protocol_t protocol, ip_ttl_t ttl, ip_tos_t tos, int dont_fragment, size_t ipopt_length ){ |
| 49 | ip_header_ref header; |
49 | ip_header_ref header; |
| 50 | uint8_t * data; |
50 | uint8_t * data; |
| 51 | int padding; |
51 | size_t padding; |
| 52 | 52 | ||
| 53 | padding = ipopt_length % 4; |
53 | padding = ipopt_length % 4; |
| 54 | if( padding ){ |
54 | if( padding ){ |
| 55 | padding = 4 - padding; |
55 | padding = 4 - padding; |
| 56 | ipopt_length += padding; |
56 | ipopt_length += padding; |
| 57 | } |
57 | } |
| 58 | data = ( uint8_t * ) packet_prefix( packet, sizeof( ip_header_t ) + padding ); |
58 | data = ( uint8_t * ) packet_prefix( packet, sizeof( ip_header_t ) + padding ); |
| 59 | if( ! data ) return ENOMEM; |
59 | if( ! data ) return ENOMEM; |
| 60 | while( padding -- ) data[ sizeof( ip_header_t ) + padding ] = IPOPT_NOOP; |
60 | while( padding -- ) data[ sizeof( ip_header_t ) + padding ] = IPOPT_NOOP; |
| 61 | header = ( ip_header_ref ) data; |
61 | header = ( ip_header_ref ) data; |
| 62 | header->ihl = ( sizeof( ip_header_t ) + ipopt_length ) / 4; |
62 | header->ihl = ( uint8_t ) ( sizeof( ip_header_t ) + ipopt_length ) / 4; |
| 63 | header->ttl = ( ttl > 0 ) ? (( ttl <= MAXTTL ) ? ttl : MAXTTL ) : IPDEFTTL; |
63 | header->ttl = ttl ? (( ttl <= MAXTTL ) ? ttl : MAXTTL ) : IPDEFTTL; |
| 64 | header->tos = tos; |
64 | header->tos = tos; |
| 65 | header->protocol = protocol; |
65 | header->protocol = protocol; |
| 66 | if( dont_fragment ) header->flags = IPFLAG_DONT_FRAGMENT; |
66 | if( dont_fragment ) header->flags = IPFLAG_DONT_FRAGMENT; |
| 67 | return EOK; |
67 | return EOK; |
| 68 | } |
68 | } |