Rev 4721 | Rev 4728 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 4721 | Rev 4722 | ||
---|---|---|---|
Line 38... | Line 38... | ||
38 | #include <errno.h> |
38 | #include <errno.h> |
39 | 39 | ||
40 | #include <sys/types.h> |
40 | #include <sys/types.h> |
41 | 41 | ||
42 | #include "../../include/ip_client.h" |
42 | #include "../../include/ip_client.h" |
- | 43 | #include "../../include/socket_errno.h" |
|
43 | 44 | ||
44 | #include "../../structures/packet/packet.h" |
45 | #include "../../structures/packet/packet.h" |
45 | #include "../../structures/packet/packet_client.h" |
46 | #include "../../structures/packet/packet_client.h" |
46 | 47 | ||
47 | #include "ip_header.h" |
48 | #include "ip_header.h" |
Line 97... | Line 98... | ||
97 | return 0; |
98 | return 0; |
98 | } |
99 | } |
99 | return header->ihl * 4u; |
100 | return header->ihl * 4u; |
100 | } |
101 | } |
101 | 102 | ||
- | 103 | int ip_client_set_pseudo_header_data_length( ip_pseudo_header_ref header, size_t headerlen, size_t data_length ){ |
|
- | 104 | ipv4_pseudo_header_ref header_in; |
|
- | 105 | ||
- | 106 | if( headerlen == sizeof( ipv4_pseudo_header_t )){ |
|
- | 107 | header_in = ( ipv4_pseudo_header_ref ) header; |
|
- | 108 | header_in->data_length = htons( data_length ); |
|
- | 109 | return EOK; |
|
- | 110 | }else{ |
|
- | 111 | return EINVAL; |
|
- | 112 | } |
|
- | 113 | } |
|
- | 114 | ||
- | 115 | int ip_client_get_pseudo_header( ip_protocol_t protocol, struct sockaddr * src, socklen_t srclen, struct sockaddr * dest, socklen_t destlen, size_t data_length, ip_pseudo_header_ref * header, size_t * headerlen ){ |
|
- | 116 | ipv4_pseudo_header_ref header_in; |
|
- | 117 | struct sockaddr_in * address_in; |
|
- | 118 | ||
- | 119 | if( !( header && headerlen )) return EBADMEM; |
|
- | 120 | if( !( src && dest && ( srclen >= sizeof( struct sockaddr )) && ( srclen == destlen ) && ( src->sa_family == dest->sa_family ))) return EINVAL; |
|
- | 121 | switch( src->sa_family ){ |
|
- | 122 | case AF_INET: |
|
- | 123 | if( srclen != sizeof( struct sockaddr_in )) return EINVAL; |
|
- | 124 | * headerlen = sizeof( * header_in ); |
|
- | 125 | header_in = ( ipv4_pseudo_header_ref ) malloc( * headerlen ); |
|
- | 126 | if( ! header_in ) return ENOMEM; |
|
- | 127 | bzero( header_in, * headerlen ); |
|
- | 128 | address_in = ( struct sockaddr_in * ) dest; |
|
- | 129 | header_in->destination_address = address_in->sin_addr.s_addr; |
|
- | 130 | address_in = ( struct sockaddr_in * ) src; |
|
- | 131 | header_in->source_address = address_in->sin_addr.s_addr; |
|
- | 132 | header_in->protocol = protocol; |
|
- | 133 | header_in->data_length = htons( data_length ); |
|
- | 134 | * header = ( ip_pseudo_header_ref ) header_in; |
|
- | 135 | return EOK; |
|
- | 136 | // TODO IPv6 |
|
- | 137 | /* case AF_INET6: |
|
- | 138 | if( addrlen != sizeof( struct sockaddr_in6 )) return EINVAL; |
|
- | 139 | address_in6 = ( struct sockaddr_in6 * ) addr; |
|
- | 140 | return EOK; |
|
- | 141 | */ default: |
|
- | 142 | return EAFNOSUPPORT; |
|
- | 143 | } |
|
- | 144 | } |
|
- | 145 | ||
102 | /** @} |
146 | /** @} |
103 | */ |
147 | */ |