Main Page   Alphabetical List   Data Structures   File List   Data Fields   Globals  

sockets.h File Reference

#include <stdio.h>
#include <errno.h>
#include <stdarg.h>
#include <string.h>
#include <stdlib.h>
#include <sys/types.h>
#include <netinet/in.h>
#include <netdb.h>
#include <sys/param.h>
#include <sys/socket.h>
#include <arpa/inet.h>
#include <linux/if.h>
#include <linux/sockios.h>
#include <sys/ioctl.h>

Go to the source code of this file.

Defines

#define MAX_IP_ADDRESS_STR_SIZE   16
 Maximum number of characters for an IP address (XXX.XXX.XXX.XXX), including the terminal zero.


Functions

int create_socket (int port, struct sockaddr_in *add, char *host, char *interface, int len, unsigned long int *broadcast, unsigned long int *netmask, unsigned long int *myip, int(*syslog)(const char *file, const char *fmt,...), char *log)
 Create a UDP socket and bind it to a given port and a given network interface. Note that this socket is allowed to send broadcast messages. More...

char * get_last_socket_error ()
 Returns a pointer to the last error message. More...

void get_remote_address (struct sockaddr_in *sender, char *ip, int *port)
 Return the IP address and the port number of a remote end point. More...


Detailed Description

Header file for socket management module (sockets.c).

Definition in file sockets.h.


Function Documentation

int create_socket int    port,
struct sockaddr_in *    add,
char *    host,
char *    interface,
int    len,
unsigned long int *    broadcast,
unsigned long int *    netmask,
unsigned long int *    myip,
int(*    syslog)(const char *file, const char *fmt,...),
char *    log
 

Create a UDP socket and bind it to a given port and a given network interface. Note that this socket is allowed to send broadcast messages.

Author:
Denis BEURIVE
Parameters:
port  Port number: the socket is binded to this port.
add  Pointer to a sockaddr_in data structure that will be used to store the internet address of the created socket.
host  Pointer to a zero terminated string of characters that represents the host name (or IP address) of the network interface to bind with the socket.
interface  Pointer to a buffer used to store the name of the network interface. This buffer MUST be at least IFNAMSIZ bytes long.
len  Size, in bytes, of the buffer 'buff'.
broadcast  Pointer to a 4 bytes long integer used to store the binary representation of the IP address associated with broadcasts (in network byte order) - for the interface.
netmask  Pointer to a 4 bytes long integer used to store the binary representation of the netmask (in network byte order) - for the interface.
myip  Pointer to a 4 bytes long integer used to store the binary representation of the IP address associated with the interace.
syslog  Pointer to a function used to log messages. The function signature must be :

int syslog (const char *file, const char * fmt,...)

Upon successful completion, the function returns the value 0.

To desactivate logging, just set this pointer to NULL.

If NULL, logging service is not activated (no matter the value of 'log').

Parameters:
log  Pointer to the log file. If NULL, logging service is not activated (no matter the value of 'syslog').
Returns:
Upon successful completion, the function returns the newly created socket descriptor. Otherwise, the function returns the value -1.

Definition at line 67 of file sockets.c.

References get_doted_ip(), last_error, MAX_INTERFACE, my_fake_syslog(), my_syslog(), and SOCKET_ERROR_SIZE.

Referenced by main().

char* get_last_socket_error  
 

Returns a pointer to the last error message.

Author:
Denis BEURIVE
Returns:
The function returns a pointer to a zero terminated string of characters that represents the last error message.

Definition at line 30 of file sockets.c.

References last_error.

Referenced by main().

void get_remote_address struct sockaddr_in *    sender,
char *    ip,
int *    port
 

Return the IP address and the port number of a remote end point.

Author:
Denis BEURIVE
Parameters:
sender  Pointer to the address of the destant end point.
ip  Pointer to a string of character used to store the IP address. This string should be, at least MAX_IP_ADDRESS_STR_SIZE characters long.
port  Pointer to an integer used to store the port number.

Definition at line 409 of file sockets.c.

Referenced by packet_dump().


Generated on Mon Jun 19 12:31:07 2006 for MyDhcp_V2 by doxygen1.2.15