diff --git a/libft/Makefile b/libft/Makefile index 3fdf2b03..893f7397 100644 --- a/libft/Makefile +++ b/libft/Makefile @@ -23,7 +23,6 @@ INC_DIR = includes/ OBJ_DIR = objs/ SRC_BASE = \ -rs/rs.c\ btree/btree_apply_by_level.c\ btree/btree_apply_infix.c\ btree/btree_apply_prefix.c\ @@ -75,6 +74,7 @@ ft_printf/lib_pad.c\ ft_printf/lib_pad_sharp.c\ get_next_line/get_next_line.c\ lst/ft_id.c\ +lst/ft_lst2str.c\ lst/ft_lst_at.c\ lst/ft_lst_bfree.c\ lst/ft_lst_cfree.c\ @@ -85,6 +85,7 @@ lst/ft_lst_filterout.c\ lst/ft_lst_find.c\ lst/ft_lst_merge.c\ lst/ft_lst_order_delsub.c\ +lst/ft_lst_pop.c\ lst/ft_lst_print.c\ lst/ft_lst_print2.c\ lst/ft_lst_removeif.c\ @@ -104,11 +105,9 @@ lst/ft_lstnew.c\ lst/ft_lstnew_range.c\ lst/ft_lstsort.c\ lst/lst_insert_sort.c\ -lst/ft_lst_pop.c\ lst/pop.c\ lst/push.c\ lst/top.c\ -lst/ft_lst2str.c\ math/ft_addrcmp.c\ math/ft_ilen.c\ math/ft_ilen_base.c\ @@ -134,10 +133,10 @@ mem/ft_memset.c\ mem/ft_realloc.c\ net/create_client.c\ net/create_server.c\ +net/forge_ip.c\ +net/forge_tcp.c\ net/net_get.c\ net/net_send.c\ -net/forge_tcp.c\ -net/forge_ip.c\ net/reserve_port.c\ path/ft_path_notdir.c\ printing/ft_putchar.c\ @@ -145,6 +144,7 @@ printing/ft_putendl.c\ printing/ft_putnbr.c\ printing/ft_putstr.c\ printing/hexdump.c\ +rs/rs.c\ sstr/ft_sstradd.c\ sstr/ft_sstrcat.c\ sstr/ft_sstrdel.c\ @@ -155,7 +155,6 @@ sstr/ft_sstrprint.c\ sstr/ft_sstrprint_fd.c\ sstr/ft_sstrsort.c\ sstr/ft_sstrstr.c\ -str/ft_strsepjoin.c\ str/ft_atoi.c\ str/ft_convert_base.c\ str/ft_putaddr_fd.c\ @@ -174,7 +173,6 @@ str/ft_strcspn.c\ str/ft_strcut.c\ str/ft_strdel.c\ str/ft_strdup.c\ -str/ft_strndup.c\ str/ft_strdupchr.c\ str/ft_strduptr.c\ str/ft_strequ.c\ @@ -191,31 +189,24 @@ str/ft_strmapi.c\ str/ft_strncat.c\ str/ft_strncmp.c\ str/ft_strncpy.c\ +str/ft_strndup.c\ str/ft_strnequ.c\ str/ft_strnew.c\ str/ft_strnstr.c\ str/ft_strrchr.c\ str/ft_strreplace.c\ str/ft_strrev.c\ +str/ft_strsepjoin.c\ str/ft_strsplit.c\ str/ft_strstr.c\ str/ft_strsub.c\ str/ft_strtok.c\ str/ft_strtrim.c\ +sys/open_new.c\ +time/epoch.c\ time/ft_mytime_free.c\ time/ft_mytime_get.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\ +time/ft_time_isrecent.c SRCS = $(addprefix $(SRC_DIR), $(SRC_BASE)) 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]}")) @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 $@\ - -I $(INC_DIR) -lm + -I $(INC_DIR) @$(eval INDEX=$(shell echo $$(($(INDEX)+1)))) clean : diff --git a/libft/includes/cliopts.h b/libft/includes/cliopts.h index 9ea82890..31eecca6 100644 --- a/libft/includes/cliopts.h +++ b/libft/includes/cliopts.h @@ -6,7 +6,7 @@ /* 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 */ /* */ /* ************************************************************************** */ @@ -20,7 +20,7 @@ typedef struct s_cliopts t_cliopts; typedef struct s_data_template t_data_template; typedef long long t_flag; -struct s_cliopts +struct s_cliopts { char c; char *str; @@ -30,15 +30,15 @@ struct s_cliopts int arg_required:1; }; -struct s_data_template +struct s_data_template { t_flag flag; char **av_data; }; -int cliopts_get(char **av, t_cliopts opt_map[], void *data); +int cliopts_get(char **av, t_cliopts opt_map[], void *data); t_cliopts *cliopts_getmap_long(t_cliopts opt_map[], char *arg); t_cliopts *cliopts_getmap_short(t_cliopts opt_map[], char arg); -int cliopts_has(char **av, char c); +int cliopts_has(char **av, char c); #endif diff --git a/libft/includes/hashtab.h b/libft/includes/hashtab.h deleted file mode 100644 index 0cb7c7a7..00000000 --- a/libft/includes/hashtab.h +++ /dev/null @@ -1,52 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* hashtab.h :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: ariard +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* 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 diff --git a/libft/includes/libft.h b/libft/includes/libft.h index 27c04598..1b4b5402 100644 --- a/libft/includes/libft.h +++ b/libft/includes/libft.h @@ -6,7 +6,7 @@ /* 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 "dlst.h" # include "btree.h" -# include "hashtab.h" # include "str.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_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); diff --git a/libft/includes/net.h b/libft/includes/net.h index 284db344..768ac0cd 100644 --- a/libft/includes/net.h +++ b/libft/includes/net.h @@ -1,3 +1,15 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* net.h :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: jhalford +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2017/10/07 18:06:12 by jhalford #+# #+# */ +/* Updated: 2017/10/07 18:14:42 by jhalford ### ########.fr */ +/* */ +/* ************************************************************************** */ + #ifndef NET_H # define NET_H @@ -7,16 +19,19 @@ # include # include +# include # include # include # include +# include # include -#include "mytime.h" +# include "mytime.h" int create_server(int port, int backlog, 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_large(int sock, char *msg, int size); @@ -27,7 +42,6 @@ int net_get_large(int sock, int fd); int reserve_port(int *port); void tcphdr_init(struct tcphdr *header); -void iphdr_init(struct iphdr *header); - +void iphdr_init(struct ip *header); #endif diff --git a/libft/includes/rs.h b/libft/includes/rs.h index c5b716e4..279ba4e8 100644 --- a/libft/includes/rs.h +++ b/libft/includes/rs.h @@ -1,10 +1,23 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* rs.h :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: jhalford +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2017/10/07 18:05:30 by jhalford #+# #+# */ +/* Updated: 2017/10/07 18:18:16 by jhalford ### ########.fr */ +/* */ +/* ************************************************************************** */ + #ifndef LIBFT_RS_H # define LIBFT_RS_H -#include -#include +# include +# include +# include -extern struct s_stats { +extern struct s_stats { int count; double min; double max; @@ -14,8 +27,8 @@ extern struct s_stats { double var; } g_rs; -void rs_clear(); -void rs_push(double n); -void rs_calcmore(); +void rs_clear(); +void rs_push(double n); +void rs_calcmore(); #endif diff --git a/libft/includes/sys.h b/libft/includes/sys.h index c945ead7..4cb977e8 100644 --- a/libft/includes/sys.h +++ b/libft/includes/sys.h @@ -6,7 +6,7 @@ /* 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 # include -/* # if HAVE_SYS_ACL_H */ -/* # include */ -/* # endif */ # include # include -/* 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 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 diff --git a/libft/srcs/htb/ft_hash_string.c b/libft/srcs/htb/ft_hash_string.c deleted file mode 100644 index 55640299..00000000 --- a/libft/srcs/htb/ft_hash_string.c +++ /dev/null @@ -1,34 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* hash.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: ariard +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* 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); -} diff --git a/libft/srcs/htb/hashtab_del.c b/libft/srcs/htb/hashtab_del.c deleted file mode 100644 index 33aa1480..00000000 --- a/libft/srcs/htb/hashtab_del.c +++ /dev/null @@ -1,23 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* hashtab_del.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: ariard +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* 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); -} diff --git a/libft/srcs/htb/hashtab_destroy.c b/libft/srcs/htb/hashtab_destroy.c deleted file mode 100644 index 0ab4bfc2..00000000 --- a/libft/srcs/htb/hashtab_destroy.c +++ /dev/null @@ -1,22 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* hashtab_destroy.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: ariard +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* 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); -} diff --git a/libft/srcs/htb/hashtab_generator.c b/libft/srcs/htb/hashtab_generator.c deleted file mode 100644 index d2f1ab73..00000000 --- a/libft/srcs/htb/hashtab_generator.c +++ /dev/null @@ -1,33 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* hashtab_generator.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: ariard +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* 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); -} diff --git a/libft/srcs/htb/hashtab_init.c b/libft/srcs/htb/hashtab_init.c deleted file mode 100644 index 51673ad1..00000000 --- a/libft/srcs/htb/hashtab_init.c +++ /dev/null @@ -1,22 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* hashtab_init.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: ariard +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* 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; -} diff --git a/libft/srcs/htb/hashtab_insert.c b/libft/srcs/htb/hashtab_insert.c deleted file mode 100644 index 9d2135c1..00000000 --- a/libft/srcs/htb/hashtab_insert.c +++ /dev/null @@ -1,26 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* hashtab_insert.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: ariard +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* 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); -} diff --git a/libft/srcs/htb/hashtab_lookup.c b/libft/srcs/htb/hashtab_lookup.c deleted file mode 100644 index 97a1bd58..00000000 --- a/libft/srcs/htb/hashtab_lookup.c +++ /dev/null @@ -1,24 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* hashtab_lookup.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: ariard +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* 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); -} diff --git a/libft/srcs/htb/hashtab_print.c b/libft/srcs/htb/hashtab_print.c deleted file mode 100644 index 5040f894..00000000 --- a/libft/srcs/htb/hashtab_print.c +++ /dev/null @@ -1,22 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* hashtab_print.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: ariard +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* 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); -} diff --git a/libft/srcs/htb/hashtab_remove.c b/libft/srcs/htb/hashtab_remove.c deleted file mode 100644 index 80c7a619..00000000 --- a/libft/srcs/htb/hashtab_remove.c +++ /dev/null @@ -1,23 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* hashtab_remove.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: ariard +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* 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); -} diff --git a/libft/srcs/lst/ft_lst2str.c b/libft/srcs/lst/ft_lst2str.c index 4654dc7f..b985083d 100644 --- a/libft/srcs/lst/ft_lst2str.c +++ b/libft/srcs/lst/ft_lst2str.c @@ -1,3 +1,15 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_lst2str.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: jhalford +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2017/10/07 17:53:18 by jhalford #+# #+# */ +/* Updated: 2017/10/07 17:53:19 by jhalford ### ########.fr */ +/* */ +/* ************************************************************************** */ + #include "libft.h" char *ft_lst2str(t_list *list) diff --git a/libft/srcs/lst/ft_lst_pop.c b/libft/srcs/lst/ft_lst_pop.c index 47d8f606..1e22b0d7 100644 --- a/libft/srcs/lst/ft_lst_pop.c +++ b/libft/srcs/lst/ft_lst_pop.c @@ -1,3 +1,15 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_lst_pop.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: jhalford +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2017/10/07 17:53:30 by jhalford #+# #+# */ +/* Updated: 2017/10/07 17:53:31 by jhalford ### ########.fr */ +/* */ +/* ************************************************************************** */ + #include "libft.h" t_list *ft_lst_pop(t_list **lst) diff --git a/libft/srcs/net/create_client.c b/libft/srcs/net/create_client.c index dfc2628a..3cbd1730 100644 --- a/libft/srcs/net/create_client.c +++ b/libft/srcs/net/create_client.c @@ -1,3 +1,15 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* create_client.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: jhalford +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2017/10/07 17:59:28 by jhalford #+# #+# */ +/* Updated: 2017/10/07 18:02:25 by jhalford ### ########.fr */ +/* */ +/* ************************************************************************** */ + #include "libft.h" int create_client(char *addr, int port, char *protoname) @@ -17,25 +29,29 @@ int create_client(char *addr, int port, char *protoname) return (sock); } -void listener(int domain, int sock, int proto, void (*handler)(void *buf, int bytes, struct sockaddr_in *addr)) -{ int sd; - struct sockaddr_in addr; - unsigned char buf[1024]; +void listener(int domain, int sock, int proto, + void (*handler)(void *buf, int bytes, struct sockaddr_in *addr)) +{ + int sd; + struct sockaddr_in addr; + unsigned char buf[1024]; + int bytes; + socklen_t len; + len = sizeof(addr); sd = socket(domain, sock, proto); if (sd < 0) { perror("listener socket"); exit(0); } - for (;;) - { int bytes; - socklen_t len=sizeof(addr); - + while (1) + { 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) - handler(buf, bytes, &addr); + handler(buf, bytes, &addr); else perror("recvfrom"); } diff --git a/libft/srcs/net/create_server.c b/libft/srcs/net/create_server.c index 3ab05efb..ffba3385 100644 --- a/libft/srcs/net/create_server.c +++ b/libft/srcs/net/create_server.c @@ -1,3 +1,15 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* create_server.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: jhalford +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2017/10/07 18:02:51 by jhalford #+# #+# */ +/* Updated: 2017/10/07 18:02:51 by jhalford ### ########.fr */ +/* */ +/* ************************************************************************** */ + #include "libft.h" int create_server(int port, int backlog, char *protoname) diff --git a/libft/srcs/net/forge_ip.c b/libft/srcs/net/forge_ip.c index 40fc91da..c40ceeac 100644 --- a/libft/srcs/net/forge_ip.c +++ b/libft/srcs/net/forge_ip.c @@ -1,17 +1,29 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* forge_ip.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: jhalford +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2017/10/07 18:02:39 by jhalford #+# #+# */ +/* Updated: 2017/10/07 18:18:07 by jhalford ### ########.fr */ +/* */ +/* ************************************************************************** */ + #include "net.h" -void iphdr_init(struct iphdr *header) +void iphdr_init(struct ip *header) { memset(header, 0, sizeof(*header)); - header->version = 4; - header->ihl = 5; - header->tos = 0; - header->tot_len = 0; - header->id = ntohl(epoch_micro()); - header->frag_off = 0; - header->ttl = 255; - header->protocol = 0; - header->daddr = 0; - header->saddr = 0; - header->check = 0; + header->ip_v = 4; + header->ip_hl = 5; + header->ip_tos = 0; + header->ip_len = 0; + header->ip_id = ntohl(epoch_micro()); + header->ip_off = 0; + header->ip_ttl = 255; + header->ip_p = 0; + header->ip_sum = 0; + memset(&header->ip_src, 0, sizeof(struct in_addr)); + memset(&header->ip_dst, 0, sizeof(struct in_addr)); } diff --git a/libft/srcs/net/forge_tcp.c b/libft/srcs/net/forge_tcp.c index e78fea37..b0c84dcb 100644 --- a/libft/srcs/net/forge_tcp.c +++ b/libft/srcs/net/forge_tcp.c @@ -1,20 +1,27 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* forge_tcp.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: jhalford +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2017/10/07 18:02:34 by jhalford #+# #+# */ +/* Updated: 2017/10/07 18:17:04 by jhalford ### ########.fr */ +/* */ +/* ************************************************************************** */ + #include "net.h" void tcphdr_init(struct tcphdr *header) { memset(header, 0, sizeof(*header)); - header->source = htons(0); - header->dest = htons(0); - header->seq = epoch_micro(); - header->ack_seq = 0; - header->doff = 5; - header->fin = 0; - header->syn = 0; - header->rst = 0; - header->psh = 0; - header->ack = 0; - header->urg = 0; - header->window = htons(1024); - header->check = 0; - header->urg_ptr = 0; + header->th_sport = htons(0); + header->th_dport = htons(0); + header->th_seq = epoch_micro(); + header->th_ack = 0; + header->th_off = 5; + header->th_flags = 0; + header->th_win = htons(1024); + header->th_sum = 0; + header->th_urp = 0; } diff --git a/libft/srcs/net/net_get.c b/libft/srcs/net/net_get.c index 9541282c..e75b58ad 100644 --- a/libft/srcs/net/net_get.c +++ b/libft/srcs/net/net_get.c @@ -1,3 +1,15 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* net_get.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: jhalford +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2017/10/07 17:59:19 by jhalford #+# #+# */ +/* Updated: 2017/10/07 17:59:20 by jhalford ### ########.fr */ +/* */ +/* ************************************************************************** */ + #include "libft.h" int net_get(int sock, char *msg, int size) diff --git a/libft/srcs/net/net_send.c b/libft/srcs/net/net_send.c index de981f56..c9a026a1 100644 --- a/libft/srcs/net/net_send.c +++ b/libft/srcs/net/net_send.c @@ -1,3 +1,15 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* net_send.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: jhalford +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2017/10/07 18:03:19 by jhalford #+# #+# */ +/* Updated: 2017/10/07 18:03:31 by jhalford ### ########.fr */ +/* */ +/* ************************************************************************** */ + #include "libft.h" int net_send(int sock, char *msg, int size) @@ -25,10 +37,9 @@ int net_send_large(int sock, char *msg, int size) return (1); if (net_send(sock, (char*)&num_last_blk, sizeof(num_blks))) return (1); - num_blks = ntohs(num_blks); num_last_blk = ntohs(num_last_blk); - i = -1; + i = -1; while (++i < num_blks - 1) net_send(sock, msg + i * NET_MAXSIZE, NET_MAXSIZE); if (num_last_blk) diff --git a/libft/srcs/net/reserve_port.c b/libft/srcs/net/reserve_port.c index 89e251bd..53ebf566 100644 --- a/libft/srcs/net/reserve_port.c +++ b/libft/srcs/net/reserve_port.c @@ -1,10 +1,22 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* reserve_port.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: jhalford +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2017/10/07 18:02:55 by jhalford #+# #+# */ +/* Updated: 2017/10/07 18:03:15 by jhalford ### ########.fr */ +/* */ +/* ************************************************************************** */ + #include "net.h" int reserve_port(int *port) { - struct sockaddr_in sa; - int sockfd; - unsigned short i; + struct sockaddr_in sa; + int sockfd; + unsigned short i; if ((sockfd = socket(AF_INET, SOCK_STREAM, 0)) == -1) return (1); diff --git a/libft/srcs/printing/hexdump.c b/libft/srcs/printing/hexdump.c index 2a51dc6c..de933085 100644 --- a/libft/srcs/printing/hexdump.c +++ b/libft/srcs/printing/hexdump.c @@ -1,57 +1,48 @@ -#include -#include +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* hexdump.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: jhalford +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2017/10/07 17:56:14 by jhalford #+# #+# */ +/* Updated: 2017/10/07 17:56:40 by jhalford ### ########.fr */ +/* */ +/* ************************************************************************** */ +#include #include "libft.h" -void hexdump(void *pAddressIn, long lSize) +static void print_hex_contents(void *addr, unsigned int size) { - char szBuf[100]; - 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; + void *a; - buf.pData = (char *)pAddress; - buf.lSize = lSize; - - while (buf.lSize > 0) - { - pTmp = (unsigned char *)buf.pData; - lOutLen = (int)buf.lSize; - if (lOutLen > 16) - lOutLen = 16; - - // create a 64-character formatted output line: - 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; - } + a = addr; + while (a - addr < 16) + { + if ((a - addr) >= size) + break ; + else + ft_printf("%02x", *(unsigned char*)a); + ft_putchar(' '); + a++; + } +} + +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); } diff --git a/libft/srcs/rs/rs.c b/libft/srcs/rs/rs.c index 3cddd3ef..7e83bdff 100644 --- a/libft/srcs/rs/rs.c +++ b/libft/srcs/rs/rs.c @@ -1,10 +1,23 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* rs.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: jhalford +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2017/10/07 17:57:54 by jhalford #+# #+# */ +/* Updated: 2017/10/07 18:19:47 by jhalford ### ########.fr */ +/* */ +/* ************************************************************************** */ + #include "libft.h" #include -double sqrt(double x); 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.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) { g_rs.min = 0; @@ -48,10 +58,5 @@ void rs_calcmore() return ; } 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); } diff --git a/libft/srcs/str/ft_strndup.c b/libft/srcs/str/ft_strndup.c index ff3ed5be..ee942d34 100644 --- a/libft/srcs/str/ft_strndup.c +++ b/libft/srcs/str/ft_strndup.c @@ -1,3 +1,14 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_strndup.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: jhalford +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2017/10/07 17:53:55 by jhalford #+# #+# */ +/* Updated: 2017/10/07 17:54:30 by jhalford ### ########.fr */ +/* */ +/* ************************************************************************** */ #include "libft.h" diff --git a/libft/srcs/str/ft_strsepjoin.c b/libft/srcs/str/ft_strsepjoin.c index 8fbb0ee3..054e4061 100644 --- a/libft/srcs/str/ft_strsepjoin.c +++ b/libft/srcs/str/ft_strsepjoin.c @@ -1,3 +1,15 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_strsepjoin.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: jhalford +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2017/10/07 17:54:06 by jhalford #+# #+# */ +/* Updated: 2017/10/07 17:54:07 by jhalford ### ########.fr */ +/* */ +/* ************************************************************************** */ + #include "libft.h" char *ft_strsepjoin(char **tab, char sep) diff --git a/libft/srcs/sys/open_new.c b/libft/srcs/sys/open_new.c index 49491cce..2b5e24df 100644 --- a/libft/srcs/sys/open_new.c +++ b/libft/srcs/sys/open_new.c @@ -1,3 +1,15 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* open_new.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: jhalford +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2017/10/07 17:56:58 by jhalford #+# #+# */ +/* Updated: 2017/10/07 17:57:28 by jhalford ### ########.fr */ +/* */ +/* ************************************************************************** */ + #include "libft.h" /* @@ -18,9 +30,9 @@ int open_new(char *filename, int oflag) while (i < 10 && (fd = open(fname, oflag | O_CREAT | O_EXCL, 0644)) < 0 && errno == EEXIST) { - fname[len] = '('; - fname[len + 1] = ++i + '0'; - fname[len + 2] = ')'; + fname[len] = '('; + fname[len + 1] = ++i + '0'; + fname[len + 2] = ')'; } ft_strdel(&fname); return (fd); diff --git a/libft/srcs/time/epoch.c b/libft/srcs/time/epoch.c index eda297db..b6d68119 100644 --- a/libft/srcs/time/epoch.c +++ b/libft/srcs/time/epoch.c @@ -1,3 +1,15 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* epoch.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: jhalford +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2017/10/07 17:58:42 by jhalford #+# #+# */ +/* Updated: 2017/10/07 17:58:43 by jhalford ### ########.fr */ +/* */ +/* ************************************************************************** */ + #include "mytime.h" size_t epoch_micro(void)