#include <stdio.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <pthread.h>
Go to the source code of this file.
Data Structures | |
struct | AUTHINFO |
struct | LIBCOMMPTHREADP |
struct | LIBCOMMPTHREADS |
struct | LINEMONITOR_THREAD_DATA |
Defines | |
#define | true 1 |
#define | false 0 |
#define | authfile0 "./libcomm_md5auth.pwd" |
#define | authfile1 "/etc/libcomm_md5auth.pwd" |
#define | authfilefieldseperator ':' |
#define | authfilemaxlinelenght 4096 |
#define | authrandomstringsize (int) 16 |
#define | authmessagetype 65535 |
Functions | |
int | socket_md5auth (int fd, char *netname, char *name, struct AUTHINFO **locallogin, struct AUTHINFO **remotelogin) |
Do both side authentification. More... | |
AUTHINFO * | getauthinfo (char *netname, char *name) |
Load authentication informations (netname, name, passwd, keyencrypt, keydecrypt) from authfile. More... | |
void | socket_accept_thread (struct LIBCOMMPTHREADP *libcommpthreadp) |
This is a part of socket_accept() and must not called from the user. More... | |
int | socket_accept (int sockport, int id, void(*socket_accept_do)(int fd, int id, char *pip, struct sockaddr_in their_addr)) |
Start a new thread, wait for connections and start socket_accept_do() when someone connects. More... | |
void | thread1 (struct LIBCOMMPTHREADS *libcommpthreads) |
This is a part of block_call() and must not called from the user. More... | |
int | block_call (int fd, int id, int term, void(*block_call_do)(int fd, int id, unsigned int type, char *buf, unsigned int size, int term), void(*block_call_term)(int fd, int id)) |
Waits in a new thread for a datablock to be received and calls the function block_call_do() if this event occurs or block_call_term() when the connection terminates. More... | |
char * | block_receive_poll (int fd, unsigned int *type, char *buf, unsigned int *size, unsigned int maxsize, int term) |
Test if is there data available on the socket's input buffer and starts receiving a block if there is. More... | |
char * | block_receive (int fd, unsigned int *type, char *buf, unsigned int *size, unsigned int maxsize, int term) |
Receive a block (composition of: type, size of datablock and datablock) from a socket. More... | |
int | block_receive_integer (int fd, unsigned int *recvi) |
Receive an integer (two bytes; 16Bit) from the socket. More... | |
int | block_receive_nbytes (int fd, char *buf, int n) |
Receive n bytes from socket. More... | |
int | block_send (int fd, unsigned int type, char *buf, unsigned int size) |
Send a block (composition of: type, size of datablock and datablock (buf)) to a socket. More... | |
char * | block_random (char *buf, int size) |
Get random numbers/bytes. More... | |
int | socket_bind (int port, int cqueue) |
Bind a socket to a port (Server side). More... | |
int | socket_connect (char *host, int port) |
Connect a TCP-stream to a server (Client side). More... | |
void | linemonitor_server_thread (struct LINEMONITOR_THREAD_DATA *linemonitor_thread_data) |
Thread used by linemonitor_server() NOT for direct usage. More... | |
int | linemonitor_server (int port, int soft_msec, int hard_msec, int wait_msec, void(*linemonitor_exception)(char *server, int port, int type)) |
Monitor if the "line" is fast enough: Server Application. More... | |
void | linemonitor_emergencystop (int sock) |
Sends an "Emergency Stop" to the client's side, linemonitor() will produce an "Emergency Stop" exception (type 4). More... | |
int | linemonitor_thread (struct LINEMONITOR_THREAD_DATA *linemonitor_thread_data) |
Thread used by linemonitor() NOT for direct usage. More... | |
int | linemonitor (char *server, int port, int soft_msec, int hard_msec, int wait_msec, void(*linemonitor_exception)(char *server, int port, int type)) |
Monitor if the "line" is fast enough: Client/Robot Application. More... |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Waits in a new thread for a datablock to be received and calls the function block_call_do() if this event occurs or block_call_term() when the connection terminates.
|
|
Get random numbers/bytes. This function reads random numbers/bytes from /dev/urandom and stores this bytes in a buffer.
|
|
Receive a block (composition of: type, size of datablock and datablock) from a socket. Waits for a block to be received completely. WARNING: The integers (type and size; excluding fd) are only 16 bit values (0 - 65535).
|
|
Receive an integer (two bytes; 16Bit) from the socket.
|
|
Receive n bytes from socket.
|
|
Test if is there data available on the socket's input buffer and starts receiving a block if there is. WARNING: The integers (type and size; excluding fd) are only 16 bit values (0 - 65535).
|
|
Send a block (composition of: type, size of datablock and datablock (buf)) to a socket. The function blocks until the whole block is transfered to the buffer. If the buffer is full, data has to be sent first. WARNING: The integers (type and size; excluding fd) are only 16 bit values (0 - 65535).
|
|
Load authentication informations (netname, name, passwd, keyencrypt, keydecrypt) from authfile.
|
|
Monitor if the "line" is fast enough: Client/Robot Application. This function opens a socket stream, sents pings/bytes and wait for them to come back. The soft-timeout will called after soft_msec is timeouted. The hard-timeout will called after soft-timeout was called AND hard_msec is timeouted. wait_msec specifies the time which is waited after a ping is received befor the next one will be launched.
|
|
Sends an "Emergency Stop" to the client's side, linemonitor() will produce an "Emergency Stop" exception (type 4).
|
|
Monitor if the "line" is fast enough: Server Application. This function opens a port and wait for the first connection on this port. All data/pings which is sent by this first connection will be sent back. The soft-timeout will called after wait_msec AND soft_msec is timeouted. The hard-timeout will called after soft-timeout was called AND hard_msec is timeouted.
|
|
Thread used by linemonitor_server() NOT for direct usage.
|
|
Thread used by linemonitor() NOT for direct usage.
|
|
Start a new thread, wait for connections and start socket_accept_do() when someone connects.
|
|
This is a part of socket_accept() and must not called from the user. This function is the thread which is started from socket_accept() and runs in background. |
|
Bind a socket to a port (Server side). This function creates a socket and binds it to a local port.
|
|
Connect a TCP-stream to a server (Client side). Creates a socket and connect it over a TCP-stream to the specified port on the specified server.
|
|
Do both side authentification. This function is usually called just after a socket stream is established. The function must be called on both sides. WARNING: This authentication can be bypassed simply by using the multiple session attack if multiple session are allowd and the same password is used for both sides. Both sides following these steps: 1. get auth info ([login] name, passwd) by using getauthinfo() from name or netname for remote login 2. generate random numbers 3. exchange (first send, then receive) login names 4. exchange random numbers 5. calculate md5 checksum over the random numbers (received from other side) and the remote passwd. 6. exchange md5 checksums 7. get auth info from name (received from other side) for local login 8. calculate md5 checksum over the local random numbers and the local passwd. 9. check login -- compare the received md5sum (6.) with the generated one (8.); send acknowledgement 10. receive remote acknowledgement 11. return suitable values
|
|
This is a part of block_call() and must not called from the user. This function is the thread which is started from block_call() and runs in background.
|