+++ /dev/null
-fwp_msgtest - test of modules: fwp_msgb, fwp_msgq, fwp_msg
-#fwp_vrestest - test of modules: fwp_ac, fwp_vres
-fwp_prototest - test of modules: fwp_proto - sending and receiving data
- through vres
-fwp_fnatest - TODO: test of modules: fwp_fna
-
-unixsocktest - just for simple testing of unix socket behavioural
-hashtest- test for fwp_hashtable implemented in the future(maybe)
+++ /dev/null
-#ifndef _HASHTABLE_H
-#define _HASHTABLE_H
-
-/* Zbyva nadefinovat iteraci pres zretazeny seznam
- *
- *mozno vyheldavat zaznamu dle label
- *
- */
-
-#include "list.h"
-//#include "ul_list.h"
-#include <stdlib.h>
-
-/* Hash table with linked list per each entry*/
-struct hash_table {
- struct list_head *entries;
- unsigned int size;
-};
-
-static inline int htable_init(struct hash_table *htable, int size)
-{
- int i;
-
- void *entries = malloc(sizeof(struct list_head) * size);
- if (!entries)
- return -1;
-
- htable->entries = (struct list_head*) entries;
- htable->size = size;
- for ( i = 0; i < size; i++)
- INIT_LIST_HEAD(&htable->entries[i]);
-
- return 0;
-}
-
-static inline void htable_free(struct hash_table *htable)
-{
- free(htable->entries);
- htable->entries = NULL;
- htable->size = 0;
-}
-
-
-static inline void htable_add(struct hash_table *htable, unsigned int hash,
- struct list_head *new)
-{
- __list_add(new, htable->entries[hash].prev, &htable->entries[hash]);
-}
-
-
-static inline void htable_del(struct hash_table *htable, unsigned int hash,
- struct list_head *new)
-{
- __list_add(new, htable->entries[hash].prev, &htable->entries[hash]);
-}
-
-
-#endif /* _HASHTABLE_H */
+++ /dev/null
-#include <stdio.h>
-#include "list.h"
-#include "hashtable.h"
-#include <string.h>
-
-
-#define MAX_CHARS 48
-
-struct item {
- struct list_head node;
- int value;
- char label[MAX_CHARS];
-};
-
-unsigned int hash_func(char *key, unsigned int modulus)
-{
- unsigned int hash = 0;
- int i;
-
- // loop while max_chars is not reached and a null character is not found
- for (i=0; i < MAX_CHARS && key[i]!=0; i++) {
- hash = (hash*37+ key[i]);
- }
-
- return (hash % modulus);
-}
-
-
-int main()
-{
- struct hash_table htable;
- struct item a,c;
- //struct item a = {{NULL, NULL}, 5, "FRESCOR"};
- //struct item c = {{NULL, NULL}, 100, "FRSH"};
-
- unsigned int hash;
-
- INIT_LIST_HEAD(&a.node);
- a.value = 5;
- strcpy(a.label,"FRESCOR");
-
- INIT_LIST_HEAD(&c.node);
- c.value = 100;
- strcpy(c.label,"FRSH");
-
- htable_init(&htable, 5);
-
- hash = hash_func(a.label, htable.size);
- printf("hash(a) = %d\n", hash);
- htable_add(&htable, hash, &a.node);
-
- hash = hash_func(c.label, htable.size);
- printf("hash(b) = %d\n", hash);
- htable_add(&htable, hash, &c.node);
-
- htable_free(&htable);
-
- return 0;
-}
+++ /dev/null
-# Generic directory or leaf node makefile for OCERA make framework
-
-ifndef MAKERULES_DIR
-MAKERULES_DIR := $(shell ( old_pwd="" ; while [ ! -e Makefile.rules ] ; do if [ "$$old_pwd" = `pwd` ] ; then exit 1 ; else old_pwd=`pwd` ; cd -L .. 2>/dev/null ; fi ; done ; pwd ) )
-endif
-
-ifeq ($(MAKERULES_DIR),)
-all : default
-.DEFAULT::
- @echo -e "\nThe Makefile.rules has not been found in this or partent directory\n"
-else
-include $(MAKERULES_DIR)/Makefile.rules
-endif
-
+++ /dev/null
-CFLAGS += -Wall -D_REENTRANT -g
-
-test_PROGRAMS = unixclient unixclient_thread unixclient_thread_dgram unixserver\
- unixserver_dgram
-
-unixclient_SOURCES+= unixclient.c
-unixclient_thread_SOURCES+= unixclient_thread.c
-unixclient_thread_dgram_SOURCES+= unixclient_thread_dgram.c
-unixserver_SOURCES+= unixserver.c
-unixserver_dgram_SOURCES+= unixserver_dgram.c
-lib_LOADLIBES += fwp pthread
-
-#utils_PROGRAMS = hashtest
-
-#lib_LIBRARIES =
-
-#include_HEADERS = ../libfwp/include/list.h ../libfwp/include/hashtable.h
-
+++ /dev/null
-#include <sys/types.h>
-#include <sys/socket.h>
-#include <stdio.h>
-#include <sys/un.h>
-#include <unistd.h>
-#include <errno.h>
-
-#define SOCKET_PATH_SERVER "server_socket"
-
-int main(int argc, char *argv[])
-{
- int sockfd;
- struct sockaddr_un server_addr;
- int result;
- char msg[20];
- char buf[20];
- unsigned int msglen;
-
- if (argc < 2) {
- printf("%s: Missing string parameter\n",argv[0]);
- return -1;
- }
-
- msglen = strlen(argv[1]) + 1;
- //printf("msg= %lu \n", sizeof(msg));
-
- if (msglen > sizeof(msg))
- msglen = sizeof(msg);
-
- strncpy(msg, argv[1], msglen);
-
- /* Create a socket for the client. */
-
- sockfd = socket(AF_UNIX, SOCK_STREAM, 0);
-
- /* Name the socket, as agreed with the server. */
-
- server_addr.sun_family = AF_UNIX;
- strcpy(server_addr.sun_path, SOCKET_PATH_SERVER);
-
- /* Now connect our socket to the server's socket. */
-
- result = connect(sockfd, (struct sockaddr *)&server_addr,
- sizeof(server_addr));
-
- if(result == -1) {
- return -1;
- }
-
- while (1) {
- while (send(sockfd, msg, msglen, 0) == -1){
- if (errno == EINTR) continue;
- goto out_err;
- }
-
- while (recv(sockfd, buf, sizeof(buf),0) == -1){
- if (errno == EINTR) continue;
- goto out_err;
- }
-
- printf("sent=%s received=%s\n", msg,buf);
- }
-
- unlink(SOCKET_PATH_SERVER);
- close(sockfd);
- return 0;
-out_err:
- unlink(SOCKET_PATH_SERVER);
- close(sockfd);
- return -1;
-}
+++ /dev/null
-#include <sys/types.h>
-#include <sys/socket.h>
-#include <stdio.h>
-#include <sys/un.h>
-#include <unistd.h>
-#include <errno.h>
-#include <pthread.h>
-
-void* messenger(void* arg)
-{
- struct sockaddr_un server_addr;
- int result;
- char buf[20];
- char *msg;
- int sockfd;
- unsigned int msglen;
-
- msg = (char*) arg;
- msglen = strlen(msg) + 1;
- //printf("msg=%lu \n", sizeof(msg));
-
- /* Create a socket for the client. */
-
- sockfd = socket(AF_UNIX, SOCK_SEQPACKET, 0);
-
- /* Name the socket, as agreed with the server. */
-
- server_addr.sun_family = AF_UNIX;
- strcpy(server_addr.sun_path, "server_socket");
-
- /* Now connect our socket to the server's socket. */
-
- result = connect(sockfd, (struct sockaddr *)&server_addr,
- sizeof(server_addr));
-
- if(result == -1) {
- return NULL;
- }
-
- /* We can now read/write via sockfd. */
- while (1) {
- while (send(sockfd, msg, msglen, 0) == -1){
- if (errno == EINTR) continue;
- goto out_err;
- }
-
- while (recv(sockfd, buf, sizeof(buf),0) == -1){
- if (errno == EINTR) continue;
- goto out_err;
- }
-
- printf("sent=%s received=%s", msg,buf);
- if (!strcmp(msg,buf))
- printf(" -- OK\n");
- else
- printf(" -- FAILED!!!\n");
- }
-
- close(sockfd);
- return NULL;
-out_err:
- close(sockfd);
- return NULL;
-}
-
-
-
-int main(int argc, char *argv[])
-{
- char msg1[20]="Thread1";
- char msg2[20]="Thread2";
- pthread_attr_t attr;
- pthread_t thread;
-
- pthread_attr_init(&attr);
- pthread_create(&thread, &attr, messenger, (void*) msg1);
- pthread_create(&thread, &attr, messenger, (void*) msg2);
-
- while (1) { /* primitive wait but enough ;-) */
- sleep(100000);
- }
-}
+++ /dev/null
-#include <sys/types.h>
-#include <sys/socket.h>
-#include <stdio.h>
-#include <sys/un.h>
-#include <unistd.h>
-#include <errno.h>
-#include <pthread.h>
-
-#define SOCKET_PATH_CLIENT "client_socket"
-#define SOCKET_PATH_SERVER "server_socket"
-
-void* messenger(void* arg)
-{
- struct sockaddr_un server_addr;
- struct sockaddr_un client_addr;
- char buf[20];
- char *msg;
- int sockfd;
- unsigned int msglen;
- socklen_t server_addr_len;
-
- msg = (char*) arg;
- msglen = strlen(msg) + 1;
- //printf("msg=%lu \n", sizeof(msg));
-
- sockfd = socket(AF_UNIX, SOCK_DGRAM, 0);
-
- bzero(&client_addr, sizeof(client_addr));
- client_addr.sun_family = AF_UNIX;
- strcpy(client_addr.sun_path, SOCKET_PATH_CLIENT);
-
-// unlink(SOCKET_PATH_CLIENT);
-
- if (bind(sockfd,(struct sockaddr*)&client_addr,
- sizeof(client_addr)) < 0) {
- fprintf(stderr,"Client--bind");
- goto out_err;
- }
-
- bzero(&server_addr, sizeof(server_addr));
- server_addr.sun_family = AF_UNIX;
- strcpy(server_addr.sun_path, SOCKET_PATH_SERVER);
-
- while (1) {
- while (sendto(sockfd, msg, msglen, 0,
- (struct sockaddr*)&server_addr,
- sizeof(server_addr)) == -1){
- if (errno == EINTR) continue;
- fprintf(stderr,"Sendto ");
- goto out_err;
- }
-
- server_addr_len = sizeof(server_addr);
- while (recvfrom(sockfd, buf, sizeof(buf), 0,
- (struct sockaddr*)&server_addr,
- &server_addr_len) == -1){
- if (errno == EINTR) continue;
- fprintf(stderr,"Recvfrom ");
- goto out_err;
- }
-
- printf("sent=%s received=%s", msg,buf);
- if (!strcmp(msg,buf))
- printf(" -- OK\n");
- else
- printf(" -- FAILED!!!\n");
- }
-
- unlink(SOCKET_PATH_CLIENT);
- close(sockfd);
- return NULL;
-out_err:
- unlink(SOCKET_PATH_CLIENT);
- perror("- client");
- close(sockfd);
- return NULL;
-}
-
-int main(int argc, char *argv[])
-{
- char msg1[20]="Thread1";
- /*char msg2[20]="Thread2";*/
- pthread_attr_t attr;
- pthread_t thread;
-
- pthread_attr_init(&attr);
- pthread_create(&thread, &attr, messenger, (void*) msg1);
- /*pthread_create(&thread, &attr, messenger, (void*) msg2);*/
-
- while (1) { /* primitive wait but enough ;-) */
- sleep(100000);
- }
-}
+++ /dev/null
-#include <sys/types.h>
-#include <sys/socket.h>
-#include <stdio.h>
-#include <sys/un.h>
-#include <unistd.h>
-#include <errno.h>
-
-int main()
-{
- int server_sockfd, client_sockfd;
- socklen_t client_len;
- struct sockaddr_un server_addr;
- struct sockaddr_un client_addr;
- int mlen;
-
- char buf[20];
-
- /* Remove any old socket and create
- * an unnamed socket for the server. */
-
- unlink("server_socket");
- server_sockfd = socket(AF_UNIX, SOCK_SEQPACKET, 0);
-
- /* Name the socket. */
-
- server_addr.sun_family = AF_UNIX;
- strcpy(server_addr.sun_path, "server_socket");
- bind(server_sockfd, (struct sockaddr *)&server_addr, sizeof(server_addr));
-
- /* Create a connection queue and wait for clients. */
-
- listen(server_sockfd, 5);
- while(1) {
- client_sockfd = accept(server_sockfd,
- (struct sockaddr *)&client_addr,
- &client_len);
-/* if (client_sockfd < 0) {
- if (errno==EINTR) continue;
- printf("Accept error \n");
- goto out_err;
- }
-*/
-
- switch (fork())
- {
- case 0:
- close(server_sockfd);
- while (1) {
- while ((mlen = recv(client_sockfd, buf, sizeof(buf),
- 0)) == -1){
- if (errno == EINTR) continue;
- goto out_err;
- }
-
- while (send(client_sockfd, buf, mlen, 0) == -1){
- if (errno == EINTR) continue;
- goto out_err;
- }
- }
-
- case -1:
- return -1;
- default:
- close(client_sockfd);
- }
- }
-
- close(server_sockfd);
- close(client_sockfd);
- return 0;
-
-out_err:
- perror("\n");
- close(server_sockfd);
- close(client_sockfd);
- return -1;
-}
-
+++ /dev/null
-#include <sys/types.h>
-#include <sys/socket.h>
-#include <stdio.h>
-#include <sys/un.h>
-#include <unistd.h>
-#include <errno.h>
-
-#define SOCKET_PATH_SERVER "server_socket"
-
-int main()
-{
- int server_sockfd;
- socklen_t addr_len;
- struct sockaddr_un server_addr;
- struct sockaddr_un client_addr;
- int mlen;
-
- char buf[100];
-
- server_sockfd = socket(AF_UNIX, SOCK_DGRAM, 0);
-
- unlink(SOCKET_PATH_SERVER);
- server_addr.sun_family = AF_UNIX;
- strcpy(server_addr.sun_path, SOCKET_PATH_SERVER);
-
- if (bind(server_sockfd, (struct sockaddr *)&server_addr,
- sizeof(server_addr)) < 0){
- fprintf(stderr,"Bind ");
- goto out_err;
- }
-
-
- while (1) {
- addr_len = sizeof(client_addr);
- while ((mlen = recvfrom(server_sockfd, buf, sizeof(buf), 0,
- (struct sockaddr*)&client_addr,
- &addr_len)) == -1){
- if (errno == EINTR) continue;
- fprintf(stderr,"Recvfrom ");
- goto out_err;
- }
-
- printf("Prijate z %s\n",client_addr.sun_path);
- while (sendto(server_sockfd, buf, mlen, 0,
- (struct sockaddr*)&client_addr,
- addr_len) == -1){
- if (errno == EINTR) continue;
- fprintf(stderr,"Sendto ");
- goto out_err;
- }
- }
-
- close(server_sockfd);
- unlink(SOCKET_PATH_SERVER);
- return 0;
-
-out_err:
- unlink(SOCKET_PATH_SERVER);
- perror("-server error");
- close(server_sockfd);
- return -1;
-}
-