Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/srv/net/inetsrv/icmp.c

    r9749e47 r695b6ff  
    4040#include <mem.h>
    4141#include <stdlib.h>
    42 #include <types/inetping.h>
     42#include <net/socket_codes.h>
    4343#include "icmp.h"
    4444#include "icmp_std.h"
     
    122122{
    123123        log_msg(LOG_DEFAULT, LVL_DEBUG, "icmp_recv_echo_reply()");
    124 
     124       
    125125        if (dgram->size < sizeof(icmp_echo_t))
    126126                return EINVAL;
    127 
     127       
    128128        icmp_echo_t *reply = (icmp_echo_t *) dgram->data;
    129 
     129       
    130130        inetping_sdu_t sdu;
    131 
    132         sdu.src = dgram->src;
    133         sdu.dest = dgram->dest;
     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       
    134140        sdu.seq_no = uint16_t_be2host(reply->seq_no);
    135141        sdu.data = reply + sizeof(icmp_echo_t);
    136142        sdu.size = dgram->size - sizeof(icmp_echo_t);
    137 
     143       
    138144        uint16_t ident = uint16_t_be2host(reply->ident);
    139145
     
    147153        if (rdata == NULL)
    148154                return ENOMEM;
    149 
     155       
    150156        icmp_echo_t *request = (icmp_echo_t *) rdata;
    151 
     157       
    152158        request->type = ICMP_ECHO_REQUEST;
    153159        request->code = 0;
     
    155161        request->ident = host2uint16_t_be(ident);
    156162        request->seq_no = host2uint16_t_be(sdu->seq_no);
    157 
     163       
    158164        memcpy(rdata + sizeof(icmp_echo_t), sdu->data, sdu->size);
    159 
     165       
    160166        uint16_t checksum = inet_checksum_calc(INET_CHECKSUM_INIT, rdata, rsize);
    161167        request->checksum = host2uint16_t_be(checksum);
    162 
     168       
    163169        inet_dgram_t dgram;
    164 
    165         dgram.src = sdu->src;
    166         dgram.dest = sdu->dest;
     170       
     171        inet_addr_set(sdu->src, &dgram.src);
     172        inet_addr_set(sdu->dest, &dgram.dest);
     173       
    167174        dgram.iplink = 0;
    168175        dgram.tos = ICMP_TOS;
    169176        dgram.data = rdata;
    170177        dgram.size = rsize;
    171 
     178       
    172179        int rc = inet_route_packet(&dgram, IP_PROTO_ICMP, INET_TTL_MAX, 0);
    173 
     180       
    174181        free(rdata);
    175182        return rc;
Note: See TracChangeset for help on using the changeset viewer.