Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/lib/c/generic/inet.c

    r5a324d99 r77ad86c  
    108108{
    109109        async_exch_t *exch = async_exchange_begin(inet_sess);
    110        
     110
    111111        ipc_call_t answer;
    112         aid_t req = async_send_4(exch, INET_SEND, dgram->iplink, dgram->tos,
    113             ttl, df, &answer);
    114        
    115         int rc = async_data_write_start(exch, &dgram->src, sizeof(inet_addr_t));
    116         if (rc != EOK) {
    117                 async_exchange_end(exch);
    118                 async_forget(req);
    119                 return rc;
    120         }
    121        
    122         rc = async_data_write_start(exch, &dgram->dest, sizeof(inet_addr_t));
    123         if (rc != EOK) {
    124                 async_exchange_end(exch);
    125                 async_forget(req);
    126                 return rc;
    127         }
    128        
    129         rc = async_data_write_start(exch, dgram->data, dgram->size);
    130        
     112        aid_t req = async_send_5(exch, INET_SEND, dgram->src.ipv4,
     113            dgram->dest.ipv4, dgram->tos, ttl, df, &answer);
     114        int rc = async_data_write_start(exch, dgram->data, dgram->size);
    131115        async_exchange_end(exch);
    132        
     116
    133117        if (rc != EOK) {
    134118                async_forget(req);
    135119                return rc;
    136120        }
    137        
     121
    138122        sysarg_t retval;
    139123        async_wait_for(req, &retval);
    140        
    141         return (int) retval;
     124        if (retval != EOK)
     125                return retval;
     126
     127        return EOK;
    142128}
    143129
    144130int inet_get_srcaddr(inet_addr_t *remote, uint8_t tos, inet_addr_t *local)
    145131{
     132        sysarg_t local_addr;
    146133        async_exch_t *exch = async_exchange_begin(inet_sess);
    147        
    148         ipc_call_t answer;
    149         aid_t req = async_send_1(exch, INET_GET_SRCADDR, tos, &answer);
    150        
    151         int rc = async_data_write_start(exch, remote, sizeof(inet_addr_t));
    152         if (rc != EOK) {
    153                 async_exchange_end(exch);
    154                 async_forget(req);
     134
     135        int rc = async_req_2_1(exch, INET_GET_SRCADDR, remote->ipv4,
     136            tos, &local_addr);
     137        async_exchange_end(exch);
     138
     139        if (rc != EOK)
    155140                return rc;
    156         }
    157        
    158         rc = async_data_read_start(exch, local, sizeof(inet_addr_t));
    159        
    160         async_exchange_end(exch);
    161        
    162         if (rc != EOK) {
    163                 async_forget(req);
    164                 return rc;
    165         }
    166        
    167         sysarg_t retval;
    168         async_wait_for(req, &retval);
    169        
    170         return (int) retval;
     141
     142        local->ipv4 = local_addr;
     143        return EOK;
    171144}
    172145
    173 static void inet_ev_recv(ipc_callid_t iid, ipc_call_t *icall)
     146static void inet_ev_recv(ipc_callid_t callid, ipc_call_t *call)
    174147{
     148        int rc;
    175149        inet_dgram_t dgram;
    176        
    177         dgram.tos = IPC_GET_ARG1(*icall);
    178        
    179         ipc_callid_t callid;
    180         size_t size;
    181         if (!async_data_write_receive(&callid, &size)) {
    182                 async_answer_0(callid, EINVAL);
    183                 async_answer_0(iid, EINVAL);
     150
     151        dgram.src.ipv4 = IPC_GET_ARG1(*call);
     152        dgram.dest.ipv4 = IPC_GET_ARG2(*call);
     153        dgram.tos = IPC_GET_ARG3(*call);
     154
     155        rc = async_data_write_accept(&dgram.data, false, 0, 0, 0, &dgram.size);
     156        if (rc != EOK) {
     157                async_answer_0(callid, rc);
    184158                return;
    185159        }
    186        
    187         if (size != sizeof(inet_addr_t)) {
    188                 async_answer_0(callid, EINVAL);
    189                 async_answer_0(iid, EINVAL);
    190                 return;
    191         }
    192        
    193         int rc = async_data_write_finalize(callid, &dgram.src, size);
    194         if (rc != EOK) {
    195                 async_answer_0(callid, rc);
    196                 async_answer_0(iid, rc);
    197                 return;
    198         }
    199        
    200         if (!async_data_write_receive(&callid, &size)) {
    201                 async_answer_0(callid, EINVAL);
    202                 async_answer_0(iid, EINVAL);
    203                 return;
    204         }
    205        
    206         if (size != sizeof(inet_addr_t)) {
    207                 async_answer_0(callid, EINVAL);
    208                 async_answer_0(iid, EINVAL);
    209                 return;
    210         }
    211        
    212         rc = async_data_write_finalize(callid, &dgram.dest, size);
    213         if (rc != EOK) {
    214                 async_answer_0(callid, rc);
    215                 async_answer_0(iid, rc);
    216                 return;
    217         }
    218        
    219         rc = async_data_write_accept(&dgram.data, false, 0, 0, 0, &dgram.size);
    220         if (rc != EOK) {
    221                 async_answer_0(iid, rc);
    222                 return;
    223         }
    224        
     160
    225161        rc = inet_ev_ops->recv(&dgram);
    226         async_answer_0(iid, rc);
     162        async_answer_0(callid, rc);
    227163}
    228164
     
    232168                ipc_call_t call;
    233169                ipc_callid_t callid = async_get_call(&call);
    234                
     170
    235171                if (!IPC_GET_IMETHOD(call)) {
    236172                        /* TODO: Handle hangup */
    237173                        return;
    238174                }
    239                
     175
    240176                switch (IPC_GET_IMETHOD(call)) {
    241177                case INET_EV_RECV:
Note: See TracChangeset for help on using the changeset viewer.