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