Ignore:
File:
1 edited

Legend:

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

    r77ad86c r5a324d99  
    108108{
    109109        async_exch_t *exch = async_exchange_begin(inet_sess);
    110 
     110       
    111111        ipc_call_t answer;
    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);
    115         async_exchange_end(exch);
    116 
    117         if (rc != EOK) {
    118                 async_forget(req);
    119                 return rc;
    120         }
    121 
     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       
     131        async_exchange_end(exch);
     132       
     133        if (rc != EOK) {
     134                async_forget(req);
     135                return rc;
     136        }
     137       
    122138        sysarg_t retval;
    123139        async_wait_for(req, &retval);
    124         if (retval != EOK)
    125                 return retval;
    126 
    127         return EOK;
     140       
     141        return (int) retval;
    128142}
    129143
    130144int inet_get_srcaddr(inet_addr_t *remote, uint8_t tos, inet_addr_t *local)
    131145{
    132         sysarg_t local_addr;
    133         async_exch_t *exch = async_exchange_begin(inet_sess);
    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)
    140                 return rc;
    141 
    142         local->ipv4 = local_addr;
    143         return EOK;
    144 }
    145 
    146 static void inet_ev_recv(ipc_callid_t callid, ipc_call_t *call)
    147 {
    148         int rc;
     146        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);
     155                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;
     171}
     172
     173static void inet_ev_recv(ipc_callid_t iid, ipc_call_t *icall)
     174{
    149175        inet_dgram_t dgram;
    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 
     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);
     184                return;
     185        }
     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       
    155219        rc = async_data_write_accept(&dgram.data, false, 0, 0, 0, &dgram.size);
    156220        if (rc != EOK) {
    157                 async_answer_0(callid, rc);
    158                 return;
    159         }
    160 
     221                async_answer_0(iid, rc);
     222                return;
     223        }
     224       
    161225        rc = inet_ev_ops->recv(&dgram);
    162         async_answer_0(callid, rc);
     226        async_answer_0(iid, rc);
    163227}
    164228
     
    168232                ipc_call_t call;
    169233                ipc_callid_t callid = async_get_call(&call);
    170 
     234               
    171235                if (!IPC_GET_IMETHOD(call)) {
    172236                        /* TODO: Handle hangup */
    173237                        return;
    174238                }
    175 
     239               
    176240                switch (IPC_GET_IMETHOD(call)) {
    177241                case INET_EV_RECV:
Note: See TracChangeset for help on using the changeset viewer.