Changes in uspace/srv/net/inetsrv/icmp.c [695b6ff:9749e47] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/srv/net/inetsrv/icmp.c
r695b6ff r9749e47 40 40 #include <mem.h> 41 41 #include <stdlib.h> 42 #include < net/socket_codes.h>42 #include <types/inetping.h> 43 43 #include "icmp.h" 44 44 #include "icmp_std.h" … … 122 122 { 123 123 log_msg(LOG_DEFAULT, LVL_DEBUG, "icmp_recv_echo_reply()"); 124 124 125 125 if (dgram->size < sizeof(icmp_echo_t)) 126 126 return EINVAL; 127 127 128 128 icmp_echo_t *reply = (icmp_echo_t *) dgram->data; 129 129 130 130 inetping_sdu_t sdu; 131 132 uint16_t family = inet_addr_get(&dgram->src, &sdu.src, NULL); 133 if (family != AF_INET) 134 return EINVAL; 135 136 family = inet_addr_get(&dgram->dest, &sdu.dest, NULL); 137 if (family != AF_INET) 138 return EINVAL; 139 131 132 sdu.src = dgram->src; 133 sdu.dest = dgram->dest; 140 134 sdu.seq_no = uint16_t_be2host(reply->seq_no); 141 135 sdu.data = reply + sizeof(icmp_echo_t); 142 136 sdu.size = dgram->size - sizeof(icmp_echo_t); 143 137 144 138 uint16_t ident = uint16_t_be2host(reply->ident); 145 139 … … 153 147 if (rdata == NULL) 154 148 return ENOMEM; 155 149 156 150 icmp_echo_t *request = (icmp_echo_t *) rdata; 157 151 158 152 request->type = ICMP_ECHO_REQUEST; 159 153 request->code = 0; … … 161 155 request->ident = host2uint16_t_be(ident); 162 156 request->seq_no = host2uint16_t_be(sdu->seq_no); 163 157 164 158 memcpy(rdata + sizeof(icmp_echo_t), sdu->data, sdu->size); 165 159 166 160 uint16_t checksum = inet_checksum_calc(INET_CHECKSUM_INIT, rdata, rsize); 167 161 request->checksum = host2uint16_t_be(checksum); 168 162 169 163 inet_dgram_t dgram; 170 171 inet_addr_set(sdu->src, &dgram.src); 172 inet_addr_set(sdu->dest, &dgram.dest); 173 164 165 dgram.src = sdu->src; 166 dgram.dest = sdu->dest; 174 167 dgram.iplink = 0; 175 168 dgram.tos = ICMP_TOS; 176 169 dgram.data = rdata; 177 170 dgram.size = rsize; 178 171 179 172 int rc = inet_route_packet(&dgram, IP_PROTO_ICMP, INET_TTL_MAX, 0); 180 173 181 174 free(rdata); 182 175 return rc;
Note:
See TracChangeset
for help on using the changeset viewer.