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