Main Page | Class List | File List | Class Members | File Members

socketIO.c File Reference

#include <linux/if_packet.h>
#include <linux/if_ether.h>
#include <sys/ioctl.h>
#include <net/if.h>
#include <unistd.h>
#include <string.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include "socketIO.h"

Functions

int rst_open (char *i, int mode)
 Open a raw socket.

int rst_send (int fd, unsigned char *buf, int len)
 Send a raw ethernet frame.

int rst_receive (int fd, unsigned char *buf, int t)
 Receive next frame.

void rst_close (int fd)
 Close a raw socket.


Function Documentation

void rst_close int  fd  ) 
 

Close a raw socket.

Parameters:
fd file descriptor
Precondition:
fd is an open file descriptor returned by rst_open
Postcondition:
the socket is closed; fd is no longer valid

int rst_open char *  i,
int  mode
 

Open a raw socket.

Parameters:
i Ethernet interface of the form ethN
mode if non-zero, open the socket in promiscuous mode
Postcondition:
open a raw socket with protocol ETH_P_ALL
Returns:
the file descriptor or 0 on failure

int rst_receive int  fd,
unsigned char *  buf,
int  t
 

Receive next frame.

Parameters:
fd file descriptor
buf frame buffer
t read timeout in seconds. If t = -1, rst_receive blocks until the next frame arrives.
Precondition:
fd is a open file descriptor returned by rst_open

buf points to at least 1514 bytes

Postcondition:
buf[0..r-1] contains the frame, where r is the return value
Returns:
number of bytes read or -1 on error

int rst_send int  fd,
unsigned char *  buf,
int  len
 

Send a raw ethernet frame.

Parameters:
fd file descriptor
buf frame buffer
len buffer length in bytes
Precondition:
fd is a open file descriptor returned by rst_open.

buf points to at least len bytes.

len in [64..1514]

Postcondition:
fd[0..len-1] is sent to the interface associated with fd
Returns:
0 on success and -1 on error


Generated on Sun Jul 18 17:30:56 2004 by doxygen 1.3.6