$Revision: 1.22 $
Socket module - routines facilitating calls to socket library.
Status: NOT REVUED, TESTED
Basic code adapted by Chris Ottrey from
http://www.ibrado.com/sock-faq/sfaq.html#faq65 - sample source code.
Included Files
Preprocessor definitions
Wait for an incoming connection on the specified socket
int SK_accept_connection The socket for communicating to the client
int listening_socket The socket that the server is bound to
Authors:
joao,
marek.
#define MAX_ACCEPT_ERRORS 3
pthread_mutex_t Lock
Wait for an incoming connection on the specified socket
int SK_accept_connection The socket for communicating to the client
Authors:
joao,
marek.
int SK_accept_connection ( int listening_socket )
- int listening_socket
- The socket that the server is bound to
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").
Author:
ottrey.
int SK_atoport ( const char* service, const char* proto )
Author:
ottrey
int SK_close ( int socket )
- int SK_close
- wrapper around closing the socket. Returns the value
returned by close(2)
- int socket
- socket to be closed
int port port to connect to
int timeout in seconds
Author: marek
er_ret_t SK_connect ( int* sock, char* hostname, unsigned int port, unsigned int timeout )
- er_ret_t SK_connect
- wrapper around connect(), doing non-blocking
connection with timeout
- int* sock
- pointer to the storage for socket descriptor
- char* hostname
- host to connect to
- unsigned int port
-
- unsigned int timeout
-
Prototyped in:
| /home/shane/release/RIP/include/sk.h
|
Calls:
| ___errno(), bcopy(), bind(), bzero(), connect(), fcntl(), fdwrap_close(), gethostbyname_r(), getsockopt(), memset(), select(), socket()
|
This function will check the ip of the connected peer and store it in the
ip_addr_t structure defined in the IP module.
Author:
marek
int SK_getpeerip ( int sockfd, ip_addr_t* ip )
- int SK_getpeerip
- returns 0 on success, -1 on failure.
- int sockfd
- The socket descriptor (file will result in -1)
- ip_addr_t* ip
- Pointer to where the address should be stored.
This function will tell you who is at the other end of a connected stream socket.
Authors:
ottrey,
marek (modified error handling, made MT-Safe).
char* SK_getpeername ( int sockfd )
- char* SK_getpeername
- Returns allocated string with the IP in it,
or "--" if the descriptor is not a socket,
or NULL on error.
- int sockfd
- The socket or file descriptor.
unsigned port The port to listen on. Ports < 1024 are
reserved for the root user. Host byte order.
Authors:
ottrey,
joao,
marek (added htons conversion for port).
int SK_getsock ( int socket_type, unsigned h_port, int backlog, uint32_t bind_address )
- int SK_getsock
- This function creates a socket and binds to it.
Returns the number of the created
descriptor/listening socket.
- int socket_type
- SOCK_STREAM or SOCK_DGRAM (TCP or UDP sockets)
- unsigned h_port
-
- int backlog
- Size of the backlog queue to be set on that
socket.
- uint32_t bind_address
- Address to bind to, in network order.
Prototyped in:
| /home/shane/release/RIP/include/sk.h
|
Calls:
| ___errno(), bind(), exit(), fdwrap_close(), fprintf(), inet_ntoa(), listen(), memset(), perror(), setsockopt(), socket(), strerror()
|
This function writes a single character out to a socket.
int SK_putc ( int sockfd, char ch, const struct timeval* timeout )
- int SK_putc
- Returns the number of characters written.
- int sockfd
- socket
- char ch
- character
- const struct timeval* timeout
- Maximum time to wait between each
write() call, or NULL for "forever".
This function writes a character string out to a socket.
char *str The buffer to be written from the socket.
int SK_puts ( int sockfd, const char* str, const struct timeval* timeout )
- int SK_puts
- The total_count of bytes written,
or -1 on hangup, error, or timeout
- int sockfd
- The socket file descriptor.
- const char* str
-
- const struct timeval* timeout
- Maximum time to wait between each
write() call, or NULL for "forever".
int SK_write ( int sockfd, const char* buf, int count, const struct timeval* timeout, int* count_sent )
- int SK_write
- Returns:
-1 on error
0 on timeout
1 on success (all bytes written)
- int sockfd
- The socket file descriptor.
- const char* buf
- The buffer to be written to the socket.
- int count
- The number of bytes in the buffer.
- const struct timeval* timeout
- Maximum time to wait between each
write() call, or NULL for "forever".
- int* count_sent
- Set to the number of bytes sucessfully
written. This value is always valid,
although it will be less than the
total number of bytes to send if
the function returns -1 or 0. NULL
may be sent if the caller does not
care about the number of bytes sent on
failure.
static char* asctime_r ( const struct tm* __tm, char* __buf )
static char* ctime_r ( const time_t* __time, char* __buf )
static int getlogin_r ( char* __name, int __len )
static int readdir_r ( DIR* __dp, struct dirent* __ent, struct dirent** __res )
static int sigwait ( const sigset_t* __setp, int* __signo )
static int ttyname_r ( int __fildes, char* __buf, size_t __size )