norme and net refactor
This commit is contained in:
parent
80837f0428
commit
ba333562dd
8 changed files with 74 additions and 13 deletions
|
|
@ -134,11 +134,12 @@ mem/ft_realloc.c\
|
|||
net/cksum.c\
|
||||
net/create_client.c\
|
||||
net/create_server.c\
|
||||
net/forge_ip.c\
|
||||
net/forge_tcp.c\
|
||||
net/host.c\
|
||||
net/ip.c\
|
||||
net/net_get.c\
|
||||
net/net_send.c\
|
||||
net/reserve_port.c\
|
||||
net/tcp.c\
|
||||
path/ft_path_notdir.c\
|
||||
printing/ft_putchar.c\
|
||||
printing/ft_putendl.c\
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/11/07 13:49:04 by jhalford #+# #+# */
|
||||
/* Updated: 2017/10/08 12:56:29 by jhalford ### ########.fr */
|
||||
/* Updated: 2017/10/08 15:59:49 by jhalford ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/11/07 13:27:46 by jhalford #+# #+# */
|
||||
/* Updated: 2017/05/20 20:01:20 by ariard ### ########.fr */
|
||||
/* Updated: 2017/10/08 16:00:12 by jhalford ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2017/10/07 18:06:12 by jhalford #+# #+# */
|
||||
/* Updated: 2017/10/08 14:36:35 by jhalford ### ########.fr */
|
||||
/* Updated: 2017/10/08 16:52:48 by jhalford ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -28,21 +28,40 @@
|
|||
|
||||
# include "mytime.h"
|
||||
|
||||
/*
|
||||
** utilities
|
||||
*/
|
||||
|
||||
int reserve_port(int *port);
|
||||
unsigned short cksum(void *b, int len);
|
||||
int host_format(struct sockaddr *addr);
|
||||
|
||||
/*
|
||||
** lazy setup
|
||||
*/
|
||||
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));
|
||||
|
||||
/*
|
||||
** lazy framing
|
||||
*/
|
||||
int net_send(int sock, char *msg, int size);
|
||||
int net_send_large(int sock, char *msg, int size);
|
||||
int net_get(int sock, char *msg, int size);
|
||||
int net_get_fd(int sock, int fd, int size);
|
||||
int net_get_large(int sock, int fd);
|
||||
|
||||
int reserve_port(int *port);
|
||||
/*
|
||||
** ip
|
||||
*/
|
||||
void ip_hdrinit(struct ip *hdr);
|
||||
void ip_load_icmp(struct icmp *icmp, void *buf);
|
||||
|
||||
void tcphdr_init(struct tcphdr *header);
|
||||
void iphdr_init(struct ip *header);
|
||||
/*
|
||||
** tcp
|
||||
*/
|
||||
void tcp_hdrinit(struct tcphdr *header);
|
||||
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2017/10/07 18:05:30 by jhalford #+# #+# */
|
||||
/* Updated: 2017/10/07 18:18:16 by jhalford ### ########.fr */
|
||||
/* Updated: 2017/10/08 15:59:58 by jhalford ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
|
|||
31
libft/srcs/net/host.c
Normal file
31
libft/srcs/net/host.c
Normal file
|
|
@ -0,0 +1,31 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* host.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2017/10/08 15:47:45 by jhalford #+# #+# */
|
||||
/* Updated: 2017/10/08 15:58:30 by jhalford ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "net.h"
|
||||
|
||||
int host_format(struct sockaddr *addr)
|
||||
{
|
||||
char dn[1024];
|
||||
char sv[20];
|
||||
char ip[INET_ADDRSTRLEN];
|
||||
|
||||
if (getnameinfo(addr, sizeof(*addr), dn, sizeof(dn),
|
||||
sv, sizeof(sv), 0))
|
||||
{
|
||||
perror("getnameinfo");
|
||||
return (1);
|
||||
}
|
||||
printf(" %s (%s)", dn,
|
||||
inet_ntop(AF_INET, &(((struct sockaddr_in*)addr)->sin_addr),
|
||||
ip, INET_ADDRSTRLEN));
|
||||
return (0);
|
||||
}
|
||||
|
|
@ -6,13 +6,13 @@
|
|||
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2017/10/07 18:02:39 by jhalford #+# #+# */
|
||||
/* Updated: 2017/10/07 18:18:07 by jhalford ### ########.fr */
|
||||
/* Updated: 2017/10/08 15:52:39 by jhalford ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "net.h"
|
||||
|
||||
void iphdr_init(struct ip *header)
|
||||
void ip_hdrinit(struct ip *header)
|
||||
{
|
||||
memset(header, 0, sizeof(*header));
|
||||
header->ip_v = 4;
|
||||
|
|
@ -27,3 +27,13 @@ void iphdr_init(struct ip *header)
|
|||
memset(&header->ip_src, 0, sizeof(struct in_addr));
|
||||
memset(&header->ip_dst, 0, sizeof(struct in_addr));
|
||||
}
|
||||
|
||||
void ip_load_icmp(struct icmp *icmp, void *buf)
|
||||
{
|
||||
struct ip *ip;
|
||||
int hlen;
|
||||
|
||||
ip = buf;
|
||||
hlen = ip->ip_hl << 2;
|
||||
ft_memcpy(icmp, buf + hlen, sizeof(struct icmp));
|
||||
}
|
||||
|
|
@ -6,13 +6,13 @@
|
|||
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2017/10/07 18:02:34 by jhalford #+# #+# */
|
||||
/* Updated: 2017/10/07 18:17:04 by jhalford ### ########.fr */
|
||||
/* Updated: 2017/10/08 15:54:16 by jhalford ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "net.h"
|
||||
|
||||
void tcphdr_init(struct tcphdr *header)
|
||||
void tcp_hdrinit(struct tcphdr *header)
|
||||
{
|
||||
memset(header, 0, sizeof(*header));
|
||||
header->th_sport = htons(0);
|
||||
Loading…
Reference in a new issue