Changeset fb4d788 in mainline for uspace/srv/net/udp/pdu.c


Ignore:
Timestamp:
2015-07-28T11:28:14Z (9 years ago)
Author:
Maurizio Lombardi <m.lombardi85@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
6accc5cf
Parents:
df2bce3 (diff), 47726b5e (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:

Merge from the mainline

File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/srv/net/udp/pdu.c

    rdf2bce3 rfb4d788  
    11/*
    2  * Copyright (c) 2012 Jiri Svoboda
     2 * Copyright (c) 2015 Jiri Svoboda
    33 * All rights reserved.
    44 *
     
    4141#include <stdlib.h>
    4242#include <inet/addr.h>
    43 #include <net/socket_codes.h>
    4443#include "msg.h"
    4544#include "pdu.h"
     
    163162
    164163/** Decode incoming PDU */
    165 int udp_pdu_decode(udp_pdu_t *pdu, udp_sockpair_t *sp, udp_msg_t **msg)
     164int udp_pdu_decode(udp_pdu_t *pdu, inet_ep2_t *epp, udp_msg_t **msg)
    166165{
    167166        udp_msg_t *nmsg;
     
    180179        hdr = (udp_header_t *)pdu->data;
    181180
    182         sp->foreign.port = uint16_t_be2host(hdr->src_port);
    183         sp->foreign.addr = pdu->src;
    184         sp->local.port = uint16_t_be2host(hdr->dest_port);
    185         sp->local.addr = pdu->dest;
     181        epp->local_link = pdu->iplink;
     182        epp->remote.port = uint16_t_be2host(hdr->src_port);
     183        epp->remote.addr = pdu->src;
     184        epp->local.port = uint16_t_be2host(hdr->dest_port);
     185        epp->local.addr = pdu->dest;
    186186
    187187        length = uint16_t_be2host(hdr->length);
     
    197197                return ENOMEM;
    198198
    199         nmsg->data = text;
    200199        nmsg->data_size = length - sizeof(udp_header_t);
     200        nmsg->data = malloc(nmsg->data_size);
     201        if (nmsg->data == NULL)
     202                return ENOMEM;
     203
     204        memcpy(nmsg->data, text, nmsg->data_size);
    201205
    202206        *msg = nmsg;
     
    205209
    206210/** Encode outgoing PDU */
    207 int udp_pdu_encode(udp_sockpair_t *sp, udp_msg_t *msg, udp_pdu_t **pdu)
     211int udp_pdu_encode(inet_ep2_t *epp, udp_msg_t *msg, udp_pdu_t **pdu)
    208212{
    209213        udp_pdu_t *npdu;
     
    215219                return ENOMEM;
    216220
    217         npdu->iplink = sp->iplink;
    218         npdu->src = sp->local.addr;
    219         npdu->dest = sp->foreign.addr;
     221        npdu->iplink = epp->local_link;
     222        npdu->src = epp->local.addr;
     223        npdu->dest = epp->remote.addr;
    220224
    221225        npdu->data_size = sizeof(udp_header_t) + msg->data_size;
     
    227231
    228232        hdr = (udp_header_t *)npdu->data;
    229         hdr->src_port = host2uint16_t_be(sp->local.port);
    230         hdr->dest_port = host2uint16_t_be(sp->foreign.port);
     233        hdr->src_port = host2uint16_t_be(epp->local.port);
     234        hdr->dest_port = host2uint16_t_be(epp->remote.port);
    231235        hdr->length = host2uint16_t_be(npdu->data_size);
    232236        hdr->checksum = 0;
Note: See TracChangeset for help on using the changeset viewer.