Main Page   Alphabetical List   Data Structures   File List   Data Fields   Globals  

sockets.c File Reference

#include "sockets.h"

Go to the source code of this file.

Defines

#define SOCKET_ERROR_SIZE   4096
 Maximum number of characters for the error message.

#define MAX_INTERFACE   16
 Maximum number of network interfaces fot the host.


Functions

char * get_doted_ip (unsigned long int ip)
 Convert IP address in binary representation (4 bytes in network byte order) into standard numbers-and-dots notation. More...

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

int my_fake_syslog (const char *file, const char *fmt,...)
 Fake logging service. More...

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...

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...


Variables

char last_error [SOCKET_ERROR_SIZE]
 Buffer that will contain the last error message.


Detailed Description

This file implements low level network functionalities.

Definition in file sockets.c.


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_doted_ip unsigned long int    ip [static]
 

Convert IP address in binary representation (4 bytes in network byte order) into standard numbers-and-dots notation.

Author:
Denis BEURIVE
Parameters:
ip  Binary representation of the IP address to convert (4 bytes in network byte order).
Returns:
The function returns a zero terminated string that represents the IP address in standard numbers-and-dots notation.
Warning:
The string is returned in a statically allocated buffer, which subsequent calls will overwrite. Do not try to free it!

Definition at line 430 of file sockets.c.

Referenced by create_socket().

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().

int my_fake_syslog const char *    file,
const char *    fmt,
...   
[static]
 

Fake logging service.

Author:
Denis BEURIVE

Definition at line 36 of file sockets.c.

Referenced by create_socket().


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