add winpcap 4.0.2 from url http://www.winpcap.org/
[natblaster.git] / src / share / netio.h
blob48bbb478025cdb51c8e119fa0282b4c99b88ec6f
1 /*****************************************************************************
2 * Copyright 2005 Daniel Ferullo *
3 * *
4 * Licensed under the Apache License, Version 2.0 (the "License"); *
5 * you may not use this file except in compliance with the License. *
6 * You may obtain a copy of the License at *
7 * *
8 * http://www.apache.org/licenses/LICENSE-2.0 *
9 * *
10 * Unless required by applicable law or agreed to in writing, software *
11 * distributed under the License is distributed on an "AS IS" BASIS, *
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. *
13 * See the License for the specific language governing permissions and *
14 * limitations under the License. *
15 * *
16 *****************************************************************************/
18 /**
19 * @file netio.h
20 * @author Daniel Ferullo (ferullo@.cmu.edu)
22 * @brief provides functions to do read/write from/to a socket
25 #ifndef __NETIO_H__
26 #define __NETIO_H__
28 #include <stdio.h>
30 #include "errorcodes.h"
31 #include "comm.h"
32 #include "def.h"
34 /**
35 * @brief reads up to buf_len bytes into buf
37 * This function checks that as it read messages the length field of the header
38 * is correct
40 * THIS FUNCTION CONTAINS A COMPLICATED WHILE LOOP THAT IS WORTH A SECOND LOOK!
42 * @param sd the socket to read from
43 * @param type the message type to read
44 * @param buf the buffer to store the message in (the payload only)
45 * @param buf_len the length of the buffer
47 * @return SUCCESS, errorcode on failure
49 errorcode readMsg(sock_t sd, comm_type_t type, void* buf, int buf_len);
51 /**
52 * @brief creates a message from the type and payload and sents it
54 * @param sd the socket to send on
55 * @param type the message type
56 * @param payload a pointer to the payload (can be NULL if payload == 0)
57 * @param payload_len the length of the payload in bytes
59 * @return SUCCESS, neg on failure
61 errorcode sendMsg(sock_t sd, long type, void* payload, long payload_len);
63 #endif /* __NETIO_H__ */