File modules/sk/socket.c

  $Revision: 1.3 $

Example code: A socket module.
Status: NOT REVUED, NOT TESTED
Online References:


Included Files


Preprocessor definitions

String sizes

#define STR_S 63

#define STR_M 255

#define STR_L 1023

#define STR_XL 4095

#define STR_XXL 16383


Global Function SK_accept_connection()

   Wait for an incoming connection on the specified socket

int SK_accept_connection The socket for communicating to the client
More:
  Authors:
	joao
int SK_accept_connection ( int listening_socket )
int listening_socket
The socket that the server is bound to
Prototyped in: modules/sk/socket.h
Calls: log_print()modules/sk/socket.c
  accept(), close(), exit(), perror(), sprintf(), strcpy()

Global Function SK_atoport()

   Take a service name, and a service type, and return a port number.  If the
   service name is not found, it tries it as a decimal number.  The number
   returned is byte ordered for the network.

char *service Service name (or port number).
char *proto Protocol (eg "tcp").
More:
  Authors:
        ottrey

Online References:
int SK_atoport ( const char* service, const char* proto )
Prototyped in: modules/sk/socket.h
Calls: getservbyname(), strtol()

Global Function SK_close()

void SK_close ( int socket )
Prototyped in: modules/sk/socket.h
Calls: log_print()modules/sk/socket.c
  close(), sprintf(), strcpy()
Called by: PC_interact()modules/pc/protocol_config.c
  PW_interact()modules/pw/protocol_whois.c

Global Function SK_gets()

   This function reads from a socket, until it recieves a linefeed
   character.  It fills the buffer "str" up to the maximum size "count".

More:
  Authors:
        ottrey

Side Effects: This function will return -1 if the socket is closed during the read operation.
Note that if a single line exceeds the length of count, the extra data will be read and discarded! You have been warned.
To Do: Capture the control-c properly!
int SK_gets ( int sockfd, char* str, size_t count )
int SK_gets
The total_count of bytes read.
int sockfd
The socket file descriptor.
char* str
The buffer to be written from the socket.
size_t count
The number of bytes in the buffer.
Prototyped in: modules/sk/socket.h
Calls: printf(), read()
Called by: PC_interact()modules/pc/protocol_config.c
  PW_interact()modules/pw/protocol_whois.c
  authenticate_user()modules/pc/protocol_config.c

Global Function SK_getsock()

   This function creates a socket and binds to it

Online References:
int SK_getsock ( int socket_type, u_short port, uint32_t bind_address )
int SK_getsock
The new socket
int socket_type
SOCK_STREAM or SOCK_DGRAM (TCP or UDP sockets)
u_short port
The port to listen on. Remember that ports < 1024 are reserved for the root user. Must be passed in network byte order (see "man htons").
uint32_t bind_address
Address to bind to, in network order. More:
  Authors:
        ottrey
	joao
Prototyped in: modules/sk/socket.h
Calls: atexit(), bind(), close(), exit(), listen(), memset(), perror(), setsockopt(), signal(), socket()
References Functions: func_atexit()modules/sk/socket.c
  func_sighup()modules/sk/socket.c
  func_sigint()modules/sk/socket.c

Global Function SK_puts()

   This function writes a character string out to a socket.

char *str The buffer to be written from the socket.
More:
  Authors:
        ottrey

Side Effects: This function will return -1 if the socket is closed during the write operation.
Note that if a single line exceeds the length of count, the extra data will be read and discarded! You have been warned.
int SK_puts ( int sockfd, const char* str )
int SK_puts
The total_count of bytes read.
int sockfd
The socket file descriptor.
const char* str
 
Prototyped in: modules/sk/socket.h
Calls: sock_write()modules/sk/socket.c
  strlen()
Called by: PC_interact()modules/pc/protocol_config.c
  PW_interact()modules/pw/protocol_whois.c
  QC_new()modules/qc/query_command.c
  QI_execute()modules/qi/query_instructions.c
  authenticate_user()modules/pc/protocol_config.c
  process_input()modules/pc/protocol_config.c
  write_results()modules/qi/query_instructions.c

Local Function func_atexit()

  XXX Note: Not sure how long this function will last.  Shouldn't _really_ need it.

More:
  Authors:
        ottrey

Online References:
static void func_atexit ( void )
Calls: printf()
Used in: SK_getsock()modules/sk/socket.c

Local Function func_sighup()

static void func_sighup ( int n )
Calls: printf()
Used in: SK_getsock()modules/sk/socket.c

Local Function func_sigint()

static void func_sigint ( int n )
Calls: printf()
Used in: SK_getsock()modules/sk/socket.c

Local Function log_print()

static void log_print ( const char* arg )
Calls: CO_get_socket_logfile()modules/co/constants.c
  CO_get_socket_logging()modules/co/constants.c
  fclose(), fopen(), fprintf(), printf(), strcmp()
Called by: SK_accept_connection()modules/sk/socket.c
  SK_close()modules/sk/socket.c

Local Function sock_read()

   This is just like the read() system call, except that it will make
   sure that all your data goes through the socket.

More:
  Authors:
        ottrey
static int sock_read ( int sockfd, char* buf, size_t count )
int sock_read
The number of bytes read.
int sockfd
The socket file descriptor.
char* buf
The buffer to be read from the socket.
size_t count
The number of bytes in the buffer.
Calls: read()

Local Function sock_write()

   This is just like the write() system call, accept that it will
   make sure that all data is transmitted.

char *buf The buffer to be written to the socket.
More:
  Authors:
        ottrey

Online References:
static int sock_write ( int sockfd, const char* buf, size_t count )
int sockfd
The socket file descriptor.
const char* buf
 
size_t count
The number of bytes in the buffer.
Calls: write()
Called by: SK_puts()modules/sk/socket.c