List of commits:
Subject Hash Author Date (UTC)
ipv6 fb43322c6ef675674385db60cabb724d74ee4053 Sylvain BERTRAND 2016-08-31 15:30:45
fix exit codes 9914ed973ba73daf29e7135980277677da5b1b83 Sylvain BERTRAND 2016-05-06 05:46:05
warning about spurious line feed with text editors 81fa0e376b074d96c080611986d64ad4a2833802 Sylvain BERTRAND 2016-04-29 09:15:16
really bad advice fixed 167bc5818ef0c4392c3eb877d8d464bfef1a45c7 Sylvain BERTRAND 2016-04-29 00:00:15
content-type support 30ab51cd0ae1f9a3ebb55ca145b1ad8c1221533c root 2016-04-28 23:39:07
typo fix, thx Florian Bruhin from suckless 4bd12dd5d83edf9c216f470098341529e3c31a3e Sylvain BERTRAND 2016-04-20 14:27:01
handle other side closed connection (0 bytes read) 019e89b4327f902dd6d28264cda5f114b67172e4 Sylvain BERTRAND 2016-04-20 14:00:40
working enough for my personnal use 905534989172399ceb39502913c24ea51e5daf42 Sylvain BERTRAND 2016-04-20 00:13:48
Initial commit 143cb38e968fd7384da0d66a3cedee87c12852cc Sylvain BERTRAND 2016-04-20 00:04:50
Commit fb43322c6ef675674385db60cabb724d74ee4053 - ipv6
Author: Sylvain BERTRAND
Author date (UTC): 2016-08-31 15:30
Committer name: Sylvain BERTRAND
Committer date (UTC): 2016-08-31 15:30
Parent(s): 9914ed973ba73daf29e7135980277677da5b1b83
Signing key:
Tree: ea6747e2deadca34fcc33c0a083cd84b00fa5d60
File Lines added Lines deleted
lnanohttp.c 54 3
ulinux/ipv6.h 0 35
ulinux/socket/in.h 3 2
ulinux/socket/in6.h 29 0
ulinux/time.h 6 6
ulinux/utils/ascii/string/vsprintf.c 1 1
ulinux/utils/ipv6.h 20 3
ulinux/utsname.h 17 0
ulinux_namespace.h 5 1
File lnanohttp.c changed (mode: 100644) (index 8116863..38839b5)
6 6 #include <stdarg.h> #include <stdarg.h>
7 7 /*----------------------------------------------------------------------------*/ /*----------------------------------------------------------------------------*/
8 8
9 /*----------------------------------------------------------------------------*/
10 /* :( */
11 /* #define IPV4 1 */
12 /*----------------------------------------------------------------------------*/
13
9 14 /*----------------------------------------------------------------------------*/ /*----------------------------------------------------------------------------*/
10 15 /* ulinux stuff */ /* ulinux stuff */
11 16 #include <ulinux/compiler_types.h> #include <ulinux/compiler_types.h>
 
14 19
15 20 #include <ulinux/file.h> #include <ulinux/file.h>
16 21 #include <ulinux/socket/socket.h> #include <ulinux/socket/socket.h>
22 #ifdef IPV4
17 23 #include <ulinux/socket/in.h> #include <ulinux/socket/in.h>
24 #else
25 #include <ulinux/socket/in6.h>
26 #endif
18 27 #include <ulinux/signal/signal.h> #include <ulinux/signal/signal.h>
19 28 #include <ulinux/error.h> #include <ulinux/error.h>
20 29 #include <ulinux/epoll.h> #include <ulinux/epoll.h>
 
33 42
34 43 /******************************************************************************/ /******************************************************************************/
35 44 /* configuration */ /* configuration */
45
36 46 /* 16 bits value for the port (below 1024, must be root, that you must be for /* 16 bits value for the port (below 1024, must be root, that you must be for
37 47 chroot anyway) */ chroot anyway) */
38 48 #define LISTENING_PORT 80 #define LISTENING_PORT 80
39 /* 32 bits value for the IPv4, can be INADDR_ANY */
49
50 #ifdef IPV4
51 /* 32 bits value for the IPv4 address, can be INADDR_ANY */
40 52 #define LISTENING_IPV4 INADDR_ANY #define LISTENING_IPV4 INADDR_ANY
53 #else
54 static struct ulinux_in6_addr listening_ipv6;
55 /* 128 bits value for the IPv6 address, is "IN6ADDR_ANY" if all 0 */
56 static void listening_ipv6_init(void)
57 {
58 /* see ulinux/socket/in6.h for u16 or u8 access to the address */
59 listening_ipv6.s6_addr32[0] = 0;
60 listening_ipv6.s6_addr32[1] = 0;
61 listening_ipv6.s6_addr32[2] = 0;
62 listening_ipv6.s6_addr32[3] = 0;
63 }
64 #endif
65
41 66 /* the chroot patch used upon start */ /* the chroot patch used upon start */
42 67 #define CHROOT_PATH "/root/http/chroot" #define CHROOT_PATH "/root/http/chroot"
43 68 /* time out for a socket read/write, in seconds. 4 secs is huge */ /* time out for a socket read/write, in seconds. 4 secs is huge */
 
... ... content-type:%s\r\n\r\n"
60 85
61 86 /*----------------------------------------------------------------------------*/ /*----------------------------------------------------------------------------*/
62 87 /* sockets stuff */ /* sockets stuff */
88 #ifdef IPV4
63 89 static struct sockaddr_in srv_addr; static struct sockaddr_in srv_addr;
90 #else
91 static struct sockaddr_in6 srv_addr;
92 #endif
64 93 static si srv_sock; /* the main listening socket */ static si srv_sock; /* the main listening socket */
65 94 static si cnx_sock; /* a cnx socket from accept */ static si cnx_sock; /* a cnx socket from accept */
66 95
 
... ... static u8 cnx_sock_rd_wait(void)
177 206
178 207 loop { loop {
179 208 r = select(cnx_sock + 1, &cnx_sock_fd_set[0], 0, 0, &tv); r = select(cnx_sock + 1, &cnx_sock_fd_set[0], 0, 0, &tv);
209 /* XXX: to address some concerns: by design for the sake of
210 simplicity we ignore handled signals here. May do state
211 management around epoll_wait someday. */
180 212 if (r != -EINTR) if (r != -EINTR)
181 213 break; break;
182 214 } }
 
... ... static u8 cnx_sock_send_wait(void)
348 380
349 381 loop { loop {
350 382 r = select(cnx_sock + 1, 0, &cnx_sock_fd_set[0], 0, &tv); r = select(cnx_sock + 1, 0, &cnx_sock_fd_set[0], 0, &tv);
383 /* XXX: to address some concerns: by design for the sake of
384 simplicity we ignore handled signals here. May do state
385 management around epoll_wait someday. */
351 386 if (r != -EINTR) if (r != -EINTR)
352 387 break; break;
353 388 } }
 
... ... static void cnxs_consume(void)
622 657 { {
623 658 loop { loop {
624 659 sl r; sl r;
660 #ifdef IPV6
625 661 struct sockaddr_in peer; struct sockaddr_in peer;
662 #else
663 struct sockaddr_in6 peer;
664 #endif
626 665 sl peer_len; sl peer_len;
627 666
628 667 peer_len = sizeof(peer); peer_len = sizeof(peer);
 
... ... static void srv_sock_create(void)
722 761 sl bool_true; sl bool_true;
723 762 sl r; sl r;
724 763
725 /* TCP on IPv4... erk! */
726 r = socket(PF_INET, SOCK_STREAM | SOCK_NONBLOCK, 0);
764 #ifdef IPV4
765 r = socket(AF_INET, SOCK_STREAM | SOCK_NONBLOCK, 0);
766 #else
767 r = socket(AF_INET6, SOCK_STREAM | SOCK_NONBLOCK, 0);
768 #endif
727 769 if (ISERR(r)) if (ISERR(r))
728 770 exit(SRV_SOCK_CREATE_FAILURE); exit(SRV_SOCK_CREATE_FAILURE);
729 771 srv_sock = (si)r; srv_sock = (si)r;
 
... ... static void setup(void)
801 843
802 844 static void globals_init(void) static void globals_init(void)
803 845 { {
846 #ifdef IPV4
804 847 srv_addr.sin_family = AF_INET; srv_addr.sin_family = AF_INET;
805 848
806 849 /* big endian port */ /* big endian port */
807 850 srv_addr.sin_port = cpu2be16(LISTENING_PORT); srv_addr.sin_port = cpu2be16(LISTENING_PORT);
808 851 srv_addr.sin_addr.s_addr = cpu2be32(LISTENING_IPV4); srv_addr.sin_addr.s_addr = cpu2be32(LISTENING_IPV4);
852 #else
853 srv_addr.sin6_family = AF_INET6;
854
855 /* big endian port */
856 srv_addr.sin6_port = cpu2be16(LISTENING_PORT);
857 listening_ipv6_init();
858 srv_addr.sin6_addr = listening_ipv6; /* C compiler block copy */
859 #endif
809 860
810 861 srv_sock = -1; /* our listening socket */ srv_sock = -1; /* our listening socket */
811 862 cnx_sock = -1; /* a cnx socket from accept */ cnx_sock = -1; /* a cnx socket from accept */
File ulinux/ipv6.h deleted (index 58fcd39..0000000)
1 #ifndef ULINUX_IPV6_H
2 #define ULINUX_IPV6_H
3 /*******************************************************************************
4 this code is protected by the GNU affero GPLv3
5 author:Sylvain BERTRAND (sylvain.bertrand AT gmail dot com)
6 *******************************************************************************/
7 struct ulinux_in6_addr{
8 union{
9 ulinux_u8 u6_addr8[16];
10 ulinux_u16 u6_addr16[8];
11 ulinux_u32 u6_addr32[4];
12 } in6_u;
13 #define s6_addr in6_u.u6_addr8
14 #define s6_addr16 in6_u.u6_addr16
15 #define s6_addr32 in6_u.u6_addr32
16 };
17
18 static inline ulinux_u8 ulinux_ipv6_addr_loopback(struct ulinux_in6_addr *a)
19 {
20 return ((a->s6_addr32[0]|a->s6_addr32[1]|
21 a->s6_addr32[2]|(a->s6_addr32[3]^ulinux_cpu2be32(1)))==0);
22 }
23
24 static inline ulinux_u8 ulinux_ipv6_addr_v4mapped(struct ulinux_in6_addr *a)
25 {
26 return ((a->s6_addr32[0]|a->s6_addr32[1]|
27 (a->s6_addr32[2]^ulinux_cpu2be32(0x0000ffff)))==0);
28 }
29
30 static inline ulinux_u8 ulinux_ipv6_addr_is_isatap(struct ulinux_in6_addr *addr)
31 {
32 return ((addr->s6_addr32[2]|ulinux_cpu2be32(0x02000000))
33 ==ulinux_cpu2be32(0x02005EFE));
34 }
35 #endif
File ulinux/socket/in.h changed (mode: 100644) (index e1225dc..b02032b)
4 4 this code is protected by the GNU affero GPLv3 this code is protected by the GNU affero GPLv3
5 5 author:Sylvain BERTRAND <sylvain.bertrand AT gmail dot com> author:Sylvain BERTRAND <sylvain.bertrand AT gmail dot com>
6 6 *******************************************************************************/ *******************************************************************************/
7 /* network order is big endian */
7 8 struct ulinux_in_addr { struct ulinux_in_addr {
8 9 ulinux_u32 s_addr; /* big endian */ ulinux_u32 s_addr; /* big endian */
9 10 }; };
10 11
11 struct ulinux_sockaddr_in{
12 ulinux_us sin_family; /* address family */
12 struct ulinux_sockaddr_in {
13 ulinux_us sin_family; /* AF_INET */
13 14 ulinux_u16 sin_port; /* port number, big endian */ ulinux_u16 sin_port; /* port number, big endian */
14 15 struct ulinux_in_addr sin_addr; /* internet address */ struct ulinux_in_addr sin_addr; /* internet address */
15 16
File ulinux/socket/in6.h added (mode: 100644) (index 0000000..0ce9d35)
1 #ifndef ULINUX_SOCKET_IN6_H
2 #define ULINUX_SOCKET_IN6_H
3 /*******************************************************************************
4 this code is protected by the GNU affero GPLv3
5 author:Sylvain BERTRAND (sylvain.bertrand AT gmail dot com)
6 *******************************************************************************/
7 /* network order is big endian */
8 struct ulinux_in6_addr {
9 union {
10 ulinux_u8 u6_addr8[16];
11 ulinux_u16 u6_addr16[8];
12 ulinux_u32 u6_addr32[4];
13 } in6_u;
14 #define s6_addr in6_u.u6_addr8
15 #define s6_addr16 in6_u.u6_addr16
16 #define s6_addr32 in6_u.u6_addr32
17 };
18
19 struct ulinux_sockaddr_in6 {
20 ulinux_us sin6_family; /* AF_INET6 */
21 /* Transport layer port #, big endian */
22 ulinux_u16 sin6_port;
23 /* IPv6 flow information, big endian */
24 ulinux_u32 sin6_flowinfo;
25 struct ulinux_in6_addr sin6_addr; /* IPv6 address */
26 /* scope id (new in RFC2553), endian not defined */
27 ulinux_u32 sin6_scope_id;
28 }; /* the sockaddr size is actually 16 bytes... then no need to pad */
29 #endif
File ulinux/time.h changed (mode: 100644) (index f240a58..306c23e)
4 4 this code is protected by the GNU affero GPLv3 this code is protected by the GNU affero GPLv3
5 5 author:Sylvain BERTRAND <sylvain.bertrand AT gmail dot com> author:Sylvain BERTRAND <sylvain.bertrand AT gmail dot com>
6 6 *******************************************************************************/ *******************************************************************************/
7 struct ulinux_timespec{
8 ulinux_sl sec;/*seconds*/
9 ulinux_sl nsec;/*nanoseconds*/
7 struct ulinux_timespec {
8 ulinux_sl sec; /*seconds*/
9 ulinux_sl nsec; /*nanoseconds*/
10 10 }; };
11 11
12 struct ulinux_timeval{
13 ulinux_sl sec;/*seconds*/
14 ulinux_sl usec;/*micro seconds, type can be arch dependent*/
12 struct ulinux_timeval {
13 ulinux_sl sec; /*seconds*/
14 ulinux_sl usec; /*micro seconds, type can be arch dependent (i.e. an int)*/
15 15 }; };
16 16 #endif #endif
File ulinux/utils/ascii/string/vsprintf.c changed (mode: 100644) (index a9da60b..84acd91)
... ... So Feb 1 16:51:32 CET 2004 Juergen Quade <quade@hsnr.de>
29 29 #include <ulinux/mmap.h> #include <ulinux/mmap.h>
30 30 #include <ulinux/utils/div.h> #include <ulinux/utils/div.h>
31 31 #include <ulinux/utils/endian.h> #include <ulinux/utils/endian.h>
32 #include <ulinux/ipv6.h>
32 #include <ulinux/socket/in6.h>
33 33 #include <ulinux/utils/ipv6.h> #include <ulinux/utils/ipv6.h>
34 34 #include <ulinux/utils/mem.h> #include <ulinux/utils/mem.h>
35 35 #include <ulinux/utils/ascii/ascii.h> #include <ulinux/utils/ascii/ascii.h>
File ulinux/utils/ipv6.h changed (mode: 100644) (index bec4b36..ebbeb00)
4 4 this code is protected by the GNU affero GPLv3 this code is protected by the GNU affero GPLv3
5 5 author:Sylvain BERTRAND (sylvain.bertrand AT gmail dot com) author:Sylvain BERTRAND (sylvain.bertrand AT gmail dot com)
6 6 *******************************************************************************/ *******************************************************************************/
7 #include <ulinux/utils/ipv6.h>
8 7 static inline ulinux_u8 ulinux_ipv6_addr_any(struct ulinux_in6_addr *a) static inline ulinux_u8 ulinux_ipv6_addr_any(struct ulinux_in6_addr *a)
9 8 { {
10 return ((a->s6_addr32[0]|a->s6_addr32[1]|
11 a->s6_addr32[2]|a->s6_addr32[3])==0);
9 return ((a->s6_addr32[0] | a->s6_addr32[1] | a->s6_addr32[2]
10 | a->s6_addr32[3]) == 0);
11 }
12
13 static inline ulinux_u8 ulinux_ipv6_addr_loopback(struct ulinux_in6_addr *a)
14 {
15 return ((a->s6_addr32[0] | a->s6_addr32[1] | a->s6_addr32[2]
16 | (a->s6_addr32[3] ^ ulinux_cpu2be32(1))) == 0);
17 }
18
19 static inline ulinux_u8 ulinux_ipv6_addr_v4mapped(struct ulinux_in6_addr *a)
20 {
21 return ((a->s6_addr32[0] | a->s6_addr32[1]
22 | (a->s6_addr32[2] ^ ulinux_cpu2be32(0x0000ffff))) == 0);
23 }
24
25 static inline ulinux_u8 ulinux_ipv6_addr_is_isatap(struct ulinux_in6_addr *addr)
26 {
27 return ((addr->s6_addr32[2] | ulinux_cpu2be32(0x02000000))
28 == ulinux_cpu2be32(0x02005EFE));
12 29 } }
13 30 #endif #endif
File ulinux/utsname.h added (mode: 100644) (index 0000000..0c0421f)
1 #ifndef ULINUX_UTSNAME_H
2 #define ULINUX_UTSNAME_H
3 /*******************************************************************************
4 this code is protected by the GNU affero GPLv3
5 author:Sylvain BERTRAND (sylvain.bertrand AT gmail dot com)
6 *******************************************************************************/
7 #define ULINUX_UTS_LEN 64
8
9 struct ulinux_utsname {
10 ulinux_u8 sysname[ULINUX_UTS_LEN + 1];
11 ulinux_u8 nodename[ULINUX_UTS_LEN + 1];
12 ulinux_u8 release[ULINUX_UTS_LEN + 1];
13 ulinux_u8 version[ULINUX_UTS_LEN + 1];
14 ulinux_u8 machine[ULINUX_UTS_LEN + 1];
15 ulinux_u8 domainname[ULINUX_UTS_LEN + 1];
16 };
17 #endif
File ulinux_namespace.h changed (mode: 100644) (index 058a330..c54f311)
77 77 #define epoll_wait(a,b,c,d) ulinux_sysc(epoll_wait,4,a,b,c,d) #define epoll_wait(a,b,c,d) ulinux_sysc(epoll_wait,4,a,b,c,d)
78 78 /*----------------------------------------------------------------------------*/ /*----------------------------------------------------------------------------*/
79 79 #define AF_INET ULINUX_AF_INET #define AF_INET ULINUX_AF_INET
80 #define PF_INET ULINUX_PF_INET
80 #define AF_INET6 ULINUX_AF_INET6
81 81 #define INADDR_ANY ULINUX_INADDR_ANY #define INADDR_ANY ULINUX_INADDR_ANY
82 82 #define SOL_SOCKET ULINUX_SOL_SOCKET #define SOL_SOCKET ULINUX_SOL_SOCKET
83 83 #define SO_REUSEADDR ULINUX_SO_REUSEADDR #define SO_REUSEADDR ULINUX_SO_REUSEADDR
84 84 #define SOCK_STREAM ULINUX_SOCK_STREAM #define SOCK_STREAM ULINUX_SOCK_STREAM
85 85 #define SOCK_NONBLOCK ULINUX_SOCK_NONBLOCK #define SOCK_NONBLOCK ULINUX_SOCK_NONBLOCK
86 #ifdef IPV6
86 87 #define sockaddr_in ulinux_sockaddr_in #define sockaddr_in ulinux_sockaddr_in
88 #else
89 #define sockaddr_in6 ulinux_sockaddr_in6
90 #endif
87 91 #ifdef __i386__ #ifdef __i386__
88 92 static sl socket(sl a, sl b, sl c) static sl socket(sl a, sl b, sl c)
89 93 { {
Hints:
Before first commit, do not forget to setup your git environment:
git config --global user.name "your_name_here"
git config --global user.email "your@email_here"

Clone this repository using HTTP(S):
git clone https://rocketgit.com/user/sylware/lnanohttp

Clone this repository using ssh (do not forget to upload a key first):
git clone ssh://rocketgit@ssh.rocketgit.com/user/sylware/lnanohttp

Clone this repository using git:
git clone git://git.rocketgit.com/user/sylware/lnanohttp

You are allowed to anonymously push to this repository.
This means that your pushed commits will automatically be transformed into a merge request:
... clone the repository ...
... make some changes and some commits ...
git push origin main