Changeset 637 for Whitix/branches

Show
Ignore:
Timestamp:
06/24/08 14:01:44 (5 months ago)
Author:
mwhitworth
Message:

Add RawReceive and RawAddPacket functions.

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • Whitix/branches/network/net/inet/raw.c

    r622 r637  
    2020#include <error.h> 
    2121#include <init.h> 
     22#include <malloc.h> 
    2223#include <net/network.h> 
    2324#include <net/tcp.h> 
     
    3839} 
    3940 
     41int RawAddPacket(struct SocketBuffer* sockBuff) 
     42{ 
     43        struct Socket* curr; 
     44 
     45        ListForEachEntry(curr, &rawSocketList, next) 
     46        { 
     47                struct SocketBuffer* copy=(struct SocketBuffer*)malloc(sizeof(struct SocketBuffer)+sockBuff->length); 
     48                memcpy(copy, sockBuff, sizeof(struct SocketBuffer)+sockBuff->length); 
     49                ListAddTail(&copy->next, &curr->recvPackets); 
     50        } 
     51 
     52        return 0; 
     53} 
     54 
    4055int RawClose(struct Socket* socket) 
    4156{ 
     57        ListRemove(&socket->next); 
    4258        return 0; 
    4359} 
     
    5470                return -ENOMEM; 
    5571 
    56         if (!socket->device->ops || !socket->device->ops->send) 
    57                 return -ENOTIMPL; 
     72        return NetDeviceSend(socket->device, sockBuff); 
     73} 
    5874 
    59         return socket->device->ops->send(socket->device, sockBuff); 
     75int RawReceive(struct Socket* socket, void* buffer, int length, int flags) 
     76{ 
     77        struct SocketBuffer* sockBuff; 
     78 
     79        while (ListEmpty(&socket->recvPackets)) 
     80                ThrSchedule(); 
     81 
     82        sockBuff=ListEntry(socket->recvPackets.next,struct SocketBuffer, next); 
     83 
     84        int toCopy=MIN(length, sockBuff->length); 
     85 
     86        memcpy((char*)buffer, sockBuff->data, toCopy); 
     87 
     88        SocketDestroyBuffer(sockBuff); 
     89 
     90        return toCopy; 
    6091} 
    6192 
     
    6596        .close = RawClose, 
    6697        .send = RawSend, 
     98        .receive = RawReceive, 
    6799}; 
    68100 
     
    71103        InetRegisterOps(INET_PROTOCOL_RAW, &rawOps); 
    72104        printf("RAW: Registered protocol.\n"); 
     105        return 0; 
    73106}