norme good

This commit is contained in:
Jack Halford 2017-10-07 18:19:59 +02:00
parent cc5885aec3
commit a3f0bb0db8
31 changed files with 311 additions and 440 deletions

View file

@ -23,7 +23,6 @@ INC_DIR = includes/
OBJ_DIR = objs/ OBJ_DIR = objs/
SRC_BASE = \ SRC_BASE = \
rs/rs.c\
btree/btree_apply_by_level.c\ btree/btree_apply_by_level.c\
btree/btree_apply_infix.c\ btree/btree_apply_infix.c\
btree/btree_apply_prefix.c\ btree/btree_apply_prefix.c\
@ -75,6 +74,7 @@ ft_printf/lib_pad.c\
ft_printf/lib_pad_sharp.c\ ft_printf/lib_pad_sharp.c\
get_next_line/get_next_line.c\ get_next_line/get_next_line.c\
lst/ft_id.c\ lst/ft_id.c\
lst/ft_lst2str.c\
lst/ft_lst_at.c\ lst/ft_lst_at.c\
lst/ft_lst_bfree.c\ lst/ft_lst_bfree.c\
lst/ft_lst_cfree.c\ lst/ft_lst_cfree.c\
@ -85,6 +85,7 @@ lst/ft_lst_filterout.c\
lst/ft_lst_find.c\ lst/ft_lst_find.c\
lst/ft_lst_merge.c\ lst/ft_lst_merge.c\
lst/ft_lst_order_delsub.c\ lst/ft_lst_order_delsub.c\
lst/ft_lst_pop.c\
lst/ft_lst_print.c\ lst/ft_lst_print.c\
lst/ft_lst_print2.c\ lst/ft_lst_print2.c\
lst/ft_lst_removeif.c\ lst/ft_lst_removeif.c\
@ -104,11 +105,9 @@ lst/ft_lstnew.c\
lst/ft_lstnew_range.c\ lst/ft_lstnew_range.c\
lst/ft_lstsort.c\ lst/ft_lstsort.c\
lst/lst_insert_sort.c\ lst/lst_insert_sort.c\
lst/ft_lst_pop.c\
lst/pop.c\ lst/pop.c\
lst/push.c\ lst/push.c\
lst/top.c\ lst/top.c\
lst/ft_lst2str.c\
math/ft_addrcmp.c\ math/ft_addrcmp.c\
math/ft_ilen.c\ math/ft_ilen.c\
math/ft_ilen_base.c\ math/ft_ilen_base.c\
@ -134,10 +133,10 @@ mem/ft_memset.c\
mem/ft_realloc.c\ mem/ft_realloc.c\
net/create_client.c\ net/create_client.c\
net/create_server.c\ net/create_server.c\
net/forge_ip.c\
net/forge_tcp.c\
net/net_get.c\ net/net_get.c\
net/net_send.c\ net/net_send.c\
net/forge_tcp.c\
net/forge_ip.c\
net/reserve_port.c\ net/reserve_port.c\
path/ft_path_notdir.c\ path/ft_path_notdir.c\
printing/ft_putchar.c\ printing/ft_putchar.c\
@ -145,6 +144,7 @@ printing/ft_putendl.c\
printing/ft_putnbr.c\ printing/ft_putnbr.c\
printing/ft_putstr.c\ printing/ft_putstr.c\
printing/hexdump.c\ printing/hexdump.c\
rs/rs.c\
sstr/ft_sstradd.c\ sstr/ft_sstradd.c\
sstr/ft_sstrcat.c\ sstr/ft_sstrcat.c\
sstr/ft_sstrdel.c\ sstr/ft_sstrdel.c\
@ -155,7 +155,6 @@ sstr/ft_sstrprint.c\
sstr/ft_sstrprint_fd.c\ sstr/ft_sstrprint_fd.c\
sstr/ft_sstrsort.c\ sstr/ft_sstrsort.c\
sstr/ft_sstrstr.c\ sstr/ft_sstrstr.c\
str/ft_strsepjoin.c\
str/ft_atoi.c\ str/ft_atoi.c\
str/ft_convert_base.c\ str/ft_convert_base.c\
str/ft_putaddr_fd.c\ str/ft_putaddr_fd.c\
@ -174,7 +173,6 @@ str/ft_strcspn.c\
str/ft_strcut.c\ str/ft_strcut.c\
str/ft_strdel.c\ str/ft_strdel.c\
str/ft_strdup.c\ str/ft_strdup.c\
str/ft_strndup.c\
str/ft_strdupchr.c\ str/ft_strdupchr.c\
str/ft_strduptr.c\ str/ft_strduptr.c\
str/ft_strequ.c\ str/ft_strequ.c\
@ -191,31 +189,24 @@ str/ft_strmapi.c\
str/ft_strncat.c\ str/ft_strncat.c\
str/ft_strncmp.c\ str/ft_strncmp.c\
str/ft_strncpy.c\ str/ft_strncpy.c\
str/ft_strndup.c\
str/ft_strnequ.c\ str/ft_strnequ.c\
str/ft_strnew.c\ str/ft_strnew.c\
str/ft_strnstr.c\ str/ft_strnstr.c\
str/ft_strrchr.c\ str/ft_strrchr.c\
str/ft_strreplace.c\ str/ft_strreplace.c\
str/ft_strrev.c\ str/ft_strrev.c\
str/ft_strsepjoin.c\
str/ft_strsplit.c\ str/ft_strsplit.c\
str/ft_strstr.c\ str/ft_strstr.c\
str/ft_strsub.c\ str/ft_strsub.c\
str/ft_strtok.c\ str/ft_strtok.c\
str/ft_strtrim.c\ str/ft_strtrim.c\
sys/open_new.c\
time/epoch.c\
time/ft_mytime_free.c\ time/ft_mytime_free.c\
time/ft_mytime_get.c\ time/ft_mytime_get.c\
time/ft_time_isrecent.c\ time/ft_time_isrecent.c
time/epoch.c\
sys/open_new.c\
htb/ft_hash_string.c\
htb/hashtab_init.c\
htb/hashtab_insert.c\
htb/hashtab_lookup.c\
htb/hashtab_remove.c\
htb/hashtab_destroy.c\
htb/hashtab_print.c\
htb/hashtab_generator.c\
htb/hashtab_del.c\
SRCS = $(addprefix $(SRC_DIR), $(SRC_BASE)) SRCS = $(addprefix $(SRC_DIR), $(SRC_BASE))
OBJS = $(addprefix $(OBJ_DIR), $(SRC_BASE:.c=.o)) OBJS = $(addprefix $(OBJ_DIR), $(SRC_BASE:.c=.o))
@ -241,7 +232,7 @@ $(OBJ_DIR)%.o : $(SRC_DIR)%.c | $(OBJ_DIR)
@$(eval COLOR=$(shell list=(160 196 202 208 215 221 226 227 190 154 118 82 46); index=$$(($(PERCENT) * $${#list[@]} / 100)); echo "$${list[$$index]}")) @$(eval COLOR=$(shell list=(160 196 202 208 215 221 226 227 190 154 118 82 46); index=$$(($(PERCENT) * $${#list[@]} / 100)); echo "$${list[$$index]}"))
@printf "\r\033[38;5;%dm⌛ [%s]: %2d%% `printf '█%.0s' {0..$(DONE)}`%*s❙%*.*s\033[0m\033[K" $(COLOR) $(NAME) $(PERCENT) $(TO_DO) "" $(DELTA) $(DELTA) "$(shell echo "$@" | sed 's/^.*\///')" @printf "\r\033[38;5;%dm⌛ [%s]: %2d%% `printf '█%.0s' {0..$(DONE)}`%*s❙%*.*s\033[0m\033[K" $(COLOR) $(NAME) $(PERCENT) $(TO_DO) "" $(DELTA) $(DELTA) "$(shell echo "$@" | sed 's/^.*\///')"
@$(CC) $(FLAGS) -MMD -c $< -o $@\ @$(CC) $(FLAGS) -MMD -c $< -o $@\
-I $(INC_DIR) -lm -I $(INC_DIR)
@$(eval INDEX=$(shell echo $$(($(INDEX)+1)))) @$(eval INDEX=$(shell echo $$(($(INDEX)+1))))
clean : clean :

View file

@ -6,7 +6,7 @@
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */ /* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2017/03/14 20:22:56 by jhalford #+# #+# */ /* Created: 2017/03/14 20:22:56 by jhalford #+# #+# */
/* Updated: 2017/03/25 14:59:53 by jhalford ### ########.fr */ /* Updated: 2017/10/07 18:04:53 by jhalford ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */

View file

@ -1,52 +0,0 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* hashtab.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2017/05/15 19:16:49 by ariard #+# #+# */
/* Updated: 2017/06/22 20:25:20 by ariard ### ########.fr */
/* */
/* ************************************************************************** */
#ifndef HASHTAB_H
# define HASHTAB_H
# include "libft.h"
struct s_hashtab
{
int capacity;
int size;
int (*hashfunc)(const void *key, int capacity);
struct s_list **head;
};
typedef struct s_hashtab t_hashtab;
void hashtab_init(t_hashtab *htb, int capacity,
int (*hashfunc)(const void *key, int size));
int hashtab_insert(t_hashtab *htb, struct s_list *new, void *key,
int (*match)(const void *data_ref, const void *key));
struct s_list *hashtab_lookup(t_hashtab *htb, void *key,
int (*match)(const void *data_ref, const void *key));
struct s_list *hashtab_remove(t_hashtab *htb, void *key,
int (*match)(const void *data_ref, const void *key));
void hashtab_destroy(t_hashtab *htb, void (*destroy)());
void hashtab_print(t_hashtab *htb, int (*printer)());
int ft_hash_string(const void *key, int size);
struct s_list *hashtab_iterator(t_hashtab *htb, char init);
void hashtab_del(t_hashtab *htb, void *key,
int (*match)(const void *, const void *),
void (*del)(void *, size_t));
#endif

View file

@ -6,7 +6,7 @@
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */ /* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2016/11/07 13:49:04 by jhalford #+# #+# */ /* Created: 2016/11/07 13:49:04 by jhalford #+# #+# */
/* Updated: 2017/05/16 17:47:18 by ariard ### ########.fr */ /* Updated: 2017/10/07 18:07:31 by jhalford ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -31,7 +31,6 @@
# include "lst.h" # include "lst.h"
# include "dlst.h" # include "dlst.h"
# include "btree.h" # include "btree.h"
# include "hashtab.h"
# include "str.h" # include "str.h"
# include "sstr.h" # include "sstr.h"
@ -90,7 +89,7 @@ int ft_putendl_fd(char const *s, int fd);
int ft_putnbr_fd(long n, int fd); int ft_putnbr_fd(long n, int fd);
int ft_putnbr_hex_fd(long n, int fd); int ft_putnbr_hex_fd(long n, int fd);
void hexdump(void *pAddressIn, long lSize); void *hexdump(void *addr, unsigned int offset, unsigned int size);
void *ft_realloc(void *data, int size); void *ft_realloc(void *data, int size);

View file

@ -1,3 +1,15 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* net.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2017/10/07 18:06:12 by jhalford #+# #+# */
/* Updated: 2017/10/07 18:14:42 by jhalford ### ########.fr */
/* */
/* ************************************************************************** */
#ifndef NET_H #ifndef NET_H
# define NET_H # define NET_H
@ -7,16 +19,19 @@
# include <sys/socket.h> # include <sys/socket.h>
# include <netdb.h> # include <netdb.h>
# include <net/if.h>
# include <netinet/in.h> # include <netinet/in.h>
# include <netinet/ip.h> # include <netinet/ip.h>
# include <netinet/tcp.h> # include <netinet/tcp.h>
# include <netinet/ip_icmp.h>
# include <arpa/inet.h> # include <arpa/inet.h>
#include "mytime.h" # include "mytime.h"
int create_server(int port, int backlog, char *protoname); int create_server(int port, int backlog, char *protoname);
int create_client(char *addr, int port, char *protoname); int create_client(char *addr, int port, char *protoname);
void listener(int domain, int sock, int proto, void (*handler)(void *buf, int bytes, struct sockaddr_in *addr)); void listener(int domain, int sock, int proto,
void (*handler)(void *buf, int bytes, struct sockaddr_in *addr));
int net_send(int sock, char *msg, int size); int net_send(int sock, char *msg, int size);
int net_send_large(int sock, char *msg, int size); int net_send_large(int sock, char *msg, int size);
@ -27,7 +42,6 @@ int net_get_large(int sock, int fd);
int reserve_port(int *port); int reserve_port(int *port);
void tcphdr_init(struct tcphdr *header); void tcphdr_init(struct tcphdr *header);
void iphdr_init(struct iphdr *header); void iphdr_init(struct ip *header);
#endif #endif

View file

@ -1,8 +1,21 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* rs.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2017/10/07 18:05:30 by jhalford #+# #+# */
/* Updated: 2017/10/07 18:18:16 by jhalford ### ########.fr */
/* */
/* ************************************************************************** */
#ifndef LIBFT_RS_H #ifndef LIBFT_RS_H
# define LIBFT_RS_H # define LIBFT_RS_H
#include <float.h> # include <float.h>
#include <dlfcn.h> # include <dlfcn.h>
# include <math.h>
extern struct s_stats { extern struct s_stats {
int count; int count;

View file

@ -6,7 +6,7 @@
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */ /* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2017/03/14 17:24:23 by jhalford #+# #+# */ /* Created: 2017/03/14 17:24:23 by jhalford #+# #+# */
/* Updated: 2017/05/16 17:30:50 by ariard ### ########.fr */ /* Updated: 2017/10/07 18:10:34 by jhalford ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -24,23 +24,9 @@
# include <sys/types.h> # include <sys/types.h>
# include <sys/xattr.h> # include <sys/xattr.h>
/* # if HAVE_SYS_ACL_H */
/* # include <sys/acl.h> */
/* # endif */
# include <sys/stat.h> # include <sys/stat.h>
# include <fcntl.h> # include <fcntl.h>
/* int ft_xattr_print(char *path); */
/* int ft_xattr_count(char *path); */
/* char *ft_getenv(char **env, char *key); */
/* int open_access(char *file, t_flag a_flag, t_flag o_flag, t_flag o_perm); */
int open_new(char *filename, int oflag); int open_new(char *filename, int oflag);
/* int is_directory(const char *path); */
/* char *create_directory(const char *path, const char *old_pathnames); */
/* int dup2_close(int fd1, int fd2); */
/* int fd_replace(int fd1, int fd2); */
#endif #endif

View file

@ -1,34 +0,0 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* hash.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: ariard <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2017/01/02 16:35:24 by ariard #+# #+# */
/* Updated: 2017/05/16 17:33:47 by ariard ### ########.fr */
/* */
/* ************************************************************************** */
#include "hashtab.h"
int ft_hash_string(const void *key, int size)
{
const char *ptr;
unsigned int tmp;
unsigned int val;
val = 0;
ptr = key;
while (*ptr != '\0')
{
val = (val << 4) + (*ptr);
if ((tmp = (val & 0xf0000000)))
{
val = val ^ (tmp >> 24);
val = val ^ tmp;
}
ptr++;
}
return (val % size);
}

View file

@ -1,23 +0,0 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* hashtab_del.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2017/06/22 17:04:24 by ariard #+# #+# */
/* Updated: 2017/06/22 22:45:04 by ariard ### ########.fr */
/* */
/* ************************************************************************** */
#include "hashtab.h"
void hashtab_del(t_hashtab *htb, void *key,
int (*match)(const void *, const void *),
void (*del)(void *, size_t))
{
int bucket;
if ((bucket = htb->hashfunc(key, htb->capacity)))
ft_lst_delif(&htb->head[bucket], key, match, del);
}

View file

@ -1,22 +0,0 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* hashtab_destroy.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2017/05/15 21:35:07 by ariard #+# #+# */
/* Updated: 2017/05/16 20:42:05 by ariard ### ########.fr */
/* */
/* ************************************************************************** */
#include "hashtab.h"
void hashtab_destroy(t_hashtab *htb, void (*destroy)())
{
int bucket;
bucket = -1;
while (++bucket < htb->capacity)
ft_lstdel(&htb->head[bucket], destroy);
}

View file

@ -1,33 +0,0 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* hashtab_generator.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2017/06/21 18:21:30 by ariard #+# #+# */
/* Updated: 2017/06/22 22:43:01 by ariard ### ########.fr */
/* */
/* ************************************************************************** */
#include "hashtab.h"
struct s_list *hashtab_iterator(t_hashtab *htb, char init)
{
static int bucket;
static t_list *tmp;
static t_list *prev;
if (init)
{
bucket = 0;
tmp = htb->head[bucket];
return (NULL);
}
while (!tmp && ++bucket < htb->capacity)
tmp = htb->head[bucket];
prev = tmp;
if (tmp)
tmp = tmp->next;
return (prev);
}

View file

@ -1,22 +0,0 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* hashtab_init.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2017/05/15 19:13:06 by ariard #+# #+# */
/* Updated: 2017/06/21 19:48:34 by ariard ### ########.fr */
/* */
/* ************************************************************************** */
#include "hashtab.h"
void hashtab_init(t_hashtab *htb, int capacity,
int (*hashfunc)(const void *key, int capacity))
{
htb->head = (t_list **)ft_memalloc(capacity * sizeof(*htb->head));
htb->capacity = capacity;
htb->size = 0;
htb->hashfunc = hashfunc;
}

View file

@ -1,26 +0,0 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* hashtab_insert.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2017/05/15 19:30:39 by ariard #+# #+# */
/* Updated: 2017/06/22 22:42:56 by ariard ### ########.fr */
/* */
/* ************************************************************************** */
#include "hashtab.h"
int hashtab_insert(t_hashtab *htb, t_list *new, void *key,
int (*match)(const void *data_ref, const void *key))
{
int bucket;
if (hashtab_lookup(htb, key, match))
return (-1);
bucket = htb->hashfunc(key, htb->capacity);
ft_lsteadd(&htb->head[bucket], new);
htb->size++;
return (bucket);
}

View file

@ -1,24 +0,0 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* hashtab_lookup.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2017/05/15 19:38:41 by ariard #+# #+# */
/* Updated: 2017/06/22 22:43:14 by ariard ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
t_list *hashtab_lookup(t_hashtab *htb, void *key,
int (*match)(const void *data_ref, const void *key))
{
int bucket;
if ((bucket = htb->hashfunc(key, htb->capacity)))
return (ft_lst_find(htb->head[bucket], key, match));
return (NULL);
}

View file

@ -1,22 +0,0 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* hashtab_print.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2017/05/16 20:38:14 by ariard #+# #+# */
/* Updated: 2017/06/22 22:24:23 by ariard ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
void hashtab_print(t_hashtab *htb, int (*printer)())
{
int bucket;
bucket = -1;
while (++bucket != htb->capacity)
ft_lstiter(htb->head[bucket], printer, &bucket);
}

View file

@ -1,23 +0,0 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* hashtab_remove.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2017/05/15 19:46:48 by ariard #+# #+# */
/* Updated: 2017/06/22 18:15:01 by ariard ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
t_list *hashtab_remove(t_hashtab *htb, void *key,
int (*match)(const void *data_ref, const void *key))
{
t_list *data;
if ((data = hashtab_lookup(htb, key, match)))
return(ft_lst_removeif(&data, key, match));
return (NULL);
}

View file

@ -1,3 +1,15 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_lst2str.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2017/10/07 17:53:18 by jhalford #+# #+# */
/* Updated: 2017/10/07 17:53:19 by jhalford ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h" #include "libft.h"
char *ft_lst2str(t_list *list) char *ft_lst2str(t_list *list)

View file

@ -1,3 +1,15 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_lst_pop.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2017/10/07 17:53:30 by jhalford #+# #+# */
/* Updated: 2017/10/07 17:53:31 by jhalford ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h" #include "libft.h"
t_list *ft_lst_pop(t_list **lst) t_list *ft_lst_pop(t_list **lst)

View file

@ -1,3 +1,15 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* create_client.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2017/10/07 17:59:28 by jhalford #+# #+# */
/* Updated: 2017/10/07 18:02:25 by jhalford ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h" #include "libft.h"
int create_client(char *addr, int port, char *protoname) int create_client(char *addr, int port, char *protoname)
@ -17,23 +29,27 @@ int create_client(char *addr, int port, char *protoname)
return (sock); return (sock);
} }
void listener(int domain, int sock, int proto, void (*handler)(void *buf, int bytes, struct sockaddr_in *addr)) void listener(int domain, int sock, int proto,
{ int sd; void (*handler)(void *buf, int bytes, struct sockaddr_in *addr))
{
int sd;
struct sockaddr_in addr; struct sockaddr_in addr;
unsigned char buf[1024]; unsigned char buf[1024];
int bytes;
socklen_t len;
len = sizeof(addr);
sd = socket(domain, sock, proto); sd = socket(domain, sock, proto);
if (sd < 0) if (sd < 0)
{ {
perror("listener socket"); perror("listener socket");
exit(0); exit(0);
} }
for (;;) while (1)
{ int bytes; {
socklen_t len=sizeof(addr);
bzero(buf, sizeof(buf)); bzero(buf, sizeof(buf));
bytes = recvfrom(sd, buf, sizeof(buf), 0, (struct sockaddr*)&addr, &len); bytes = recvfrom(sd, buf, sizeof(buf), 0,
(struct sockaddr*)&addr, &len);
if (bytes > 0 && handler) if (bytes > 0 && handler)
handler(buf, bytes, &addr); handler(buf, bytes, &addr);
else else

View file

@ -1,3 +1,15 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* create_server.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2017/10/07 18:02:51 by jhalford #+# #+# */
/* Updated: 2017/10/07 18:02:51 by jhalford ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h" #include "libft.h"
int create_server(int port, int backlog, char *protoname) int create_server(int port, int backlog, char *protoname)

View file

@ -1,17 +1,29 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* forge_ip.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2017/10/07 18:02:39 by jhalford #+# #+# */
/* Updated: 2017/10/07 18:18:07 by jhalford ### ########.fr */
/* */
/* ************************************************************************** */
#include "net.h" #include "net.h"
void iphdr_init(struct iphdr *header) void iphdr_init(struct ip *header)
{ {
memset(header, 0, sizeof(*header)); memset(header, 0, sizeof(*header));
header->version = 4; header->ip_v = 4;
header->ihl = 5; header->ip_hl = 5;
header->tos = 0; header->ip_tos = 0;
header->tot_len = 0; header->ip_len = 0;
header->id = ntohl(epoch_micro()); header->ip_id = ntohl(epoch_micro());
header->frag_off = 0; header->ip_off = 0;
header->ttl = 255; header->ip_ttl = 255;
header->protocol = 0; header->ip_p = 0;
header->daddr = 0; header->ip_sum = 0;
header->saddr = 0; memset(&header->ip_src, 0, sizeof(struct in_addr));
header->check = 0; memset(&header->ip_dst, 0, sizeof(struct in_addr));
} }

View file

@ -1,20 +1,27 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* forge_tcp.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2017/10/07 18:02:34 by jhalford #+# #+# */
/* Updated: 2017/10/07 18:17:04 by jhalford ### ########.fr */
/* */
/* ************************************************************************** */
#include "net.h" #include "net.h"
void tcphdr_init(struct tcphdr *header) void tcphdr_init(struct tcphdr *header)
{ {
memset(header, 0, sizeof(*header)); memset(header, 0, sizeof(*header));
header->source = htons(0); header->th_sport = htons(0);
header->dest = htons(0); header->th_dport = htons(0);
header->seq = epoch_micro(); header->th_seq = epoch_micro();
header->ack_seq = 0; header->th_ack = 0;
header->doff = 5; header->th_off = 5;
header->fin = 0; header->th_flags = 0;
header->syn = 0; header->th_win = htons(1024);
header->rst = 0; header->th_sum = 0;
header->psh = 0; header->th_urp = 0;
header->ack = 0;
header->urg = 0;
header->window = htons(1024);
header->check = 0;
header->urg_ptr = 0;
} }

View file

@ -1,3 +1,15 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* net_get.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2017/10/07 17:59:19 by jhalford #+# #+# */
/* Updated: 2017/10/07 17:59:20 by jhalford ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h" #include "libft.h"
int net_get(int sock, char *msg, int size) int net_get(int sock, char *msg, int size)

View file

@ -1,3 +1,15 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* net_send.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2017/10/07 18:03:19 by jhalford #+# #+# */
/* Updated: 2017/10/07 18:03:31 by jhalford ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h" #include "libft.h"
int net_send(int sock, char *msg, int size) int net_send(int sock, char *msg, int size)
@ -25,7 +37,6 @@ int net_send_large(int sock, char *msg, int size)
return (1); return (1);
if (net_send(sock, (char*)&num_last_blk, sizeof(num_blks))) if (net_send(sock, (char*)&num_last_blk, sizeof(num_blks)))
return (1); return (1);
num_blks = ntohs(num_blks); num_blks = ntohs(num_blks);
num_last_blk = ntohs(num_last_blk); num_last_blk = ntohs(num_last_blk);
i = -1; i = -1;

View file

@ -1,3 +1,15 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* reserve_port.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2017/10/07 18:02:55 by jhalford #+# #+# */
/* Updated: 2017/10/07 18:03:15 by jhalford ### ########.fr */
/* */
/* ************************************************************************** */
#include "net.h" #include "net.h"
int reserve_port(int *port) int reserve_port(int *port)

View file

@ -1,57 +1,48 @@
#include <stdio.h> /* ************************************************************************** */
#include <ctype.h> /* */
/* ::: :::::::: */
/* hexdump.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2017/10/07 17:56:14 by jhalford #+# #+# */
/* Updated: 2017/10/07 17:56:40 by jhalford ### ########.fr */
/* */
/* ************************************************************************** */
#include <stdio.h>
#include "libft.h" #include "libft.h"
void hexdump(void *pAddressIn, long lSize) static void print_hex_contents(void *addr, unsigned int size)
{ {
char szBuf[100]; void *a;
long lIndent = 1;
long lOutLen, lIndex, lIndex2, lOutLen2;
long lRelPos;
struct { char *pData; unsigned long lSize; } buf;
unsigned char *pTmp,ucTmp;
unsigned char *pAddress = (unsigned char *)pAddressIn;
buf.pData = (char *)pAddress; a = addr;
buf.lSize = lSize; while (a - addr < 16)
while (buf.lSize > 0)
{ {
pTmp = (unsigned char *)buf.pData; if ((a - addr) >= size)
lOutLen = (int)buf.lSize; break ;
if (lOutLen > 16) else
lOutLen = 16; ft_printf("%02x", *(unsigned char*)a);
ft_putchar(' ');
// create a 64-character formatted output line: a++;
sprintf(szBuf, " > "
" "
" %08lX", pTmp-pAddress);
lOutLen2 = lOutLen;
for(lIndex = 1+lIndent, lIndex2 = 53-15+lIndent, lRelPos = 0;
lOutLen2;
lOutLen2--, lIndex += 2, lIndex2++
)
{
ucTmp = *pTmp++;
sprintf(szBuf + lIndex, "%02x ", (unsigned short)ucTmp);
if(!isprint(ucTmp)) ucTmp = '.'; // nonprintable char
szBuf[lIndex2] = ucTmp;
if (!(++lRelPos & 3)) // extra blank after 4 bytes
{ lIndex++; szBuf[lIndex+2] = ' '; }
}
if (!(lRelPos & 3)) lIndex--;
szBuf[lIndex ] = '<';
szBuf[lIndex+1] = ' ';
printf("%s\n", szBuf);
buf.pData += lOutLen;
buf.lSize -= lOutLen;
} }
} }
void *hexdump(void *addr, unsigned int offset, unsigned int size)
{
void *a;
addr += offset;
a = addr;
if (addr == NULL)
return (addr);
while ((a - addr) < size)
{
ft_printf("%0*llx\t", 16, (a - addr) + (unsigned long)offset);
print_hex_contents(a, (size - (a - addr)));
ft_putchar('\n');
a += 16;
}
return (addr);
}

View file

@ -1,10 +1,23 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* rs.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2017/10/07 17:57:54 by jhalford #+# #+# */
/* Updated: 2017/10/07 18:19:47 by jhalford ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h" #include "libft.h"
#include <math.h> #include <math.h>
double sqrt(double x);
struct s_stats g_rs = {0, 0, 0, 0, 0, 0, 0}; struct s_stats g_rs = {0, 0, 0, 0, 0, 0, 0};
void rs_clear() double sqrt(double x);
void rs_clear(void)
{ {
g_rs.count = 0; g_rs.count = 0;
g_rs.min = DBL_MAX; g_rs.min = DBL_MAX;
@ -31,11 +44,8 @@ void rs_push(double n)
} }
} }
void rs_calcmore() void rs_calcmore(void)
{ {
/* void *libm; */
/* double (*sqrt)(double); */
if (g_rs.count == 0) if (g_rs.count == 0)
{ {
g_rs.min = 0; g_rs.min = 0;
@ -48,10 +58,5 @@ void rs_calcmore()
return ; return ;
} }
g_rs.var = g_rs.m / (g_rs.count - 1); g_rs.var = g_rs.m / (g_rs.count - 1);
/* if ((libm = dlopen("libm.dylib", 0)) == NULL) */
/* printf("%s\n", dlerror()); */
/* else if ((sqrt = dlsym(libm, "sqrt")) == NULL) */
/* printf("%s\n", dlerror()); */
/* else */
g_rs.stdev = sqrt(g_rs.var); g_rs.stdev = sqrt(g_rs.var);
} }

View file

@ -1,3 +1,14 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strndup.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2017/10/07 17:53:55 by jhalford #+# #+# */
/* Updated: 2017/10/07 17:54:30 by jhalford ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h" #include "libft.h"

View file

@ -1,3 +1,15 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strsepjoin.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2017/10/07 17:54:06 by jhalford #+# #+# */
/* Updated: 2017/10/07 17:54:07 by jhalford ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h" #include "libft.h"
char *ft_strsepjoin(char **tab, char sep) char *ft_strsepjoin(char **tab, char sep)

View file

@ -1,3 +1,15 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* open_new.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2017/10/07 17:56:58 by jhalford #+# #+# */
/* Updated: 2017/10/07 17:57:28 by jhalford ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h" #include "libft.h"
/* /*

View file

@ -1,3 +1,15 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* epoch.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2017/10/07 17:58:42 by jhalford #+# #+# */
/* Updated: 2017/10/07 17:58:43 by jhalford ### ########.fr */
/* */
/* ************************************************************************** */
#include "mytime.h" #include "mytime.h"
size_t epoch_micro(void) size_t epoch_micro(void)