catalinux / Conn (public) (License: LGPLv2) (since 2016-03-01) (hash sha1)
Net library for easy building ipv4/ipv6 network daemons/clients
List of commits:
Subject Hash Author Date (UTC)
Added suport to bind to a specific IP. 5de8bd574a0bd2b57cc0ea98c4c20186dcfc9d8c Catalin(ux) M. BOIE 2009-03-02 13:59:07
TODO: Added bind to ip and access control. d7dd6bd61fdb4974da679979f05913cc24c9c0ae Catalin(ux) M. BOIE 2009-03-02 13:34:13
Lot of small changes that were need to fix epoll integration. 92877346e9cbecc7bea6f6d342e6d03475349878 Catalin(ux) M. BOIE 2009-02-26 12:20:07
Fixed the server example to output a \n terminated line. ed20ea84c9c6bd5dc9a3c066d03e4c8a049e1369 Catalin(ux) M. BOIE 2009-02-26 12:16:33
Added an accept_error callback to server example (s.c). 7014b75488c82c4b1f1c5b52cf7d4d2278719f4d Catalin(ux) M. BOIE 2009-02-26 12:15:56
Fixed exit from client example (c.c) to catch leaks. b912a406c59719919d3d98f4ca92cbbb3f986e99 Catalin(ux) M. BOIE 2009-02-26 12:15:08
Added queue stuff - not used for now. b913455733a88e63bea980e7490d4f36766e15fc Catalin(ux) M. BOIE 2009-02-26 10:50:56
Constify a lot of parameters and added more consistent logging. 8b15034895c7e63be9b9ca68e4b41c9a52618d10 Catalin(ux) M. BOIE 2009-02-26 10:46:05
Stuff in/out. 074bc88cec80384ade2f4309840a7d2c6f15a700 Catalin(ux) M. BOIE 2009-02-26 10:41:16
Remove 'slot' concept from anywhere I could. It was confusing. eacc7a0b5355ffa8f71dc07631209e2f805edd03 Catalin(ux) M. BOIE 2009-02-23 15:21:53
Use valgrind in examples to catch errors. 3520092ef3e946840bc13fd1891b22645cf085a5 Catalin(ux) M. BOIE 2009-02-23 15:21:23
Some cosmetic changes for examples. 2fc9e92d9fb24568a13355db191e5bf64d601ee8 Catalin(ux) M. BOIE 2009-02-23 15:21:02
More TODO entries added/removed. eb5a15672c8adf3c3da2425582b1e842c6127b13 Catalin(ux) M. BOIE 2009-02-23 15:20:04
Minor cosmetic changes. 5955b574710254e771bbf9d81a8712033c9f1464 Catalin(ux) M. BOIE 2009-02-23 11:32:20
Added support for multiple polling engines and added epoll engine. ecf8b9c40ddae857b9d7dd72dee6596c1689db3e Catalin(ux) M. BOIE 2009-02-23 10:02:39
Duilder updates. db4999d6737f84d17c3b9aa5863483c91d6ed1a7 Catalin(ux) M. BOIE 2008-12-08 14:17:02
Bump up the version to 1.0.11. c623ba1f66e79d758d88407b6224c3574d9fd730 Catalin(ux) M. BOIE 2008-07-16 06:38:33
Added Conn_for_every_line. e7b9ae7009aa9a5cafa1f0f4e3916729f69dbb6b Catalin(ux) M. BOIE 2008-07-15 14:38:29
Bump version to 1.0.10. 4919629756fe6236e2ff75e646e612ed534353e8 Catalin(ux) M. BOIE 2008-07-04 09:23:00
Updated duilder. a20257fddc85103b43978c64d9cd4a5d4c1451ea Catalin(ux) M. BOIE 2008-07-04 09:14:18
Commit 5de8bd574a0bd2b57cc0ea98c4c20186dcfc9d8c - Added suport to bind to a specific IP.
Signed-off-by: Catalin(ux) M. BOIE <catab@embedromix.ro>
Author: Catalin(ux) M. BOIE
Author date (UTC): 2009-03-02 13:59
Committer name: Catalin(ux) M. BOIE
Committer date (UTC): 2009-03-05 15:31
Parent(s): d7dd6bd61fdb4974da679979f05913cc24c9c0ae
Signing key:
Tree: aabfd83bc2ddd07e0244de2bcef3a0c4600cbc4c
File Lines added Lines deleted
.gitignore 2 1
Conn.c 24 8
Conn.h 2 0
TODO 0 4
examples/.gitignore 4 0
examples/Makefile 4 1
examples/s_bind.c 8 3
File .gitignore changed (mode: 100644) (index 762bb46..9964a59)
1 1 Changelog Changelog
2 ./Makefile
2 /Makefile
3 3 Conn.spec Conn.spec
4 4 Conn_config.h Conn_config.h
5 5 *.o *.o
6 6 *.a *.a
7 7 *.so *.so
8 8 *.so.* *.so.*
9 *.log
File Conn.c changed (mode: 100644) (index be20c99..2932696)
... ... static struct Conn *Conn_alloc(void)
389 389 return C; return C;
390 390 } }
391 391
392 struct Conn *Conn_socket(const int domain, const int type, const int port)
392 struct Conn *Conn_socket_addr(const int domain, const int type,
393 const char *addr, const int port)
393 394 { {
394 395 struct Conn *C; struct Conn *C;
395 396 int i, ret; int i, ret;
 
... ... struct Conn *Conn_socket(const int domain, const int type, const int port)
397 398 struct sockaddr_in sa; struct sockaddr_in sa;
398 399 struct sockaddr_in6 sa6; struct sockaddr_in6 sa6;
399 400 int sock_len = 0; int sock_len = 0;
400 char *addr = "?";
401 401 int do_bind = 1, do_listen = 1; int do_bind = 1, do_listen = 1;
402 402 int protocol = 0; int protocol = 0;
403 403 int first_state; int first_state;
 
... ... struct Conn *Conn_socket(const int domain, const int type, const int port)
406 406 case PF_INET: case PF_INET:
407 407 memset(&sa, 0, sizeof(sa)); memset(&sa, 0, sizeof(sa));
408 408 sa.sin_family = AF_INET; sa.sin_family = AF_INET;
409 sa.sin_addr.s_addr = htonl(INADDR_ANY);
409 ret = inet_pton(AF_INET, addr, &sa.sin_addr);
410 if (ret < 0) {
411 snprintf(Conn_error, sizeof(Conn_error),
412 "inet_pton(%s) failed", addr);
413 return NULL;
414 }
410 415 sa.sin_port = htons(port); sa.sin_port = htons(port);
411 416 psa = (struct sockaddr *) &sa; psa = (struct sockaddr *) &sa;
412 417 sock_len = sizeof(sa); sock_len = sizeof(sa);
413 addr = "0.0.0.0";
414 418 if (type == SOCK_STREAM) { if (type == SOCK_STREAM) {
415 419 first_state = CONN_STATE_LISTEN; first_state = CONN_STATE_LISTEN;
416 420 } else if (type == SOCK_DGRAM) { } else if (type == SOCK_DGRAM) {
 
... ... struct Conn *Conn_socket(const int domain, const int type, const int port)
422 426 case PF_INET6: case PF_INET6:
423 427 memset(&sa6, 0, sizeof(sa6)); memset(&sa6, 0, sizeof(sa6));
424 428 sa6.sin6_family = AF_INET6; sa6.sin6_family = AF_INET6;
425 ret = inet_pton(AF_INET6, "::", &sa6.sin6_addr);
429 ret = inet_pton(AF_INET6, addr, &sa6.sin6_addr);
426 430 if (ret < 0) { if (ret < 0) {
427 431 snprintf(Conn_error, sizeof(Conn_error), snprintf(Conn_error, sizeof(Conn_error),
428 "inet_pton(::) failed");
432 "inet_pton(%s) failed", addr);
429 433 return NULL; return NULL;
430 434 } }
431 435 sa6.sin6_port = htons(port); sa6.sin6_port = htons(port);
432 436 psa = (struct sockaddr *) &sa6; psa = (struct sockaddr *) &sa6;
433 437 sock_len = sizeof(sa6); sock_len = sizeof(sa6);
434 addr = "::";
435 438 if (type == SOCK_STREAM) { if (type == SOCK_STREAM) {
436 439 first_state = CONN_STATE_LISTEN; first_state = CONN_STATE_LISTEN;
437 440 } else if (type == SOCK_DGRAM) { } else if (type == SOCK_DGRAM) {
 
... ... struct Conn *Conn_socket(const int domain, const int type, const int port)
530 533 return NULL; return NULL;
531 534 } }
532 535
536 struct Conn *Conn_socket(const int domain, const int type, const int port)
537 {
538 char *addr;
539
540 switch (domain) {
541 case PF_INET: addr = "0.0.0.0"; break;
542 case PF_INET6: addr = "::"; break;
543 default: addr = NULL;
544 }
545
546 return Conn_socket_addr(domain, type, addr, port);
547 }
548
533 549 struct Conn *Conn_connect(const int domain, const int type, const char *addr, struct Conn *Conn_connect(const int domain, const int type, const char *addr,
534 550 const int port) const int port)
535 551 { {
 
... ... int Conn_poll(const int timeout)
1135 1151 if (ret < 0) if (ret < 0)
1136 1152 return -1; return -1;
1137 1153
1138 Log(9, "Compacting cells, do expiration and band stuff...\n");
1154 Log(9, "Do compacting, expiration and band stuff...\n");
1139 1155 i = 0; i = 0;
1140 1156 while (i < Conn_no) { while (i < Conn_no) {
1141 1157 C = &Conns[i]; C = &Conns[i];
File Conn.h changed (mode: 100644) (index 677f5d8..77f3d32)
... ... extern int Conn_init(const unsigned int max);
7 7 extern int Conn_shutdown(void); extern int Conn_shutdown(void);
8 8 extern ssize_t Conn_send(struct Conn *C, void *buf, const size_t count); extern ssize_t Conn_send(struct Conn *C, void *buf, const size_t count);
9 9 extern ssize_t Conn_recv(struct Conn *C, void *buf, const size_t count); extern ssize_t Conn_recv(struct Conn *C, void *buf, const size_t count);
10 extern struct Conn *Conn_socket_addr(const int domain, const int type,
11 const char *addr, const int port);
10 12 extern struct Conn *Conn_socket(const int domain, const int type, extern struct Conn *Conn_socket(const int domain, const int type,
11 13 const int port); const int port);
12 14 extern int Conn_poll(const int timeout); extern int Conn_poll(const int timeout);
File TODO changed (mode: 100644) (index e992c62..705e412)
2 2
3 3 == LOW PRIORITY == == LOW PRIORITY ==
4 4
5 [ ] Allow binding to a specific ip
6 Conn_bind(C, "127.0.0.1");
7 Conn_bind(C, "192.168.0.0");
8 Conn_bind(C, "::1");
9 5 [ ] Add access control [ ] Add access control
10 6 Conn_ac_set_default(C, CONN_AC_DENY) - default deny (or CONN_AC_ALLOW) Conn_ac_set_default(C, CONN_AC_DENY) - default deny (or CONN_AC_ALLOW)
11 7 Conn_ac_add(C, CONN_AC_ALLOW, "2001::1/64"); - for ipv6 Conn_ac_add(C, CONN_AC_ALLOW, "2001::1/64"); - for ipv6
File examples/.gitignore changed (mode: 100644) (index a54e886..515e0ce)
1 1 c c
2 c.run
2 3 raw raw
3 4 s s
5 s.debug
6 s.run
7 s_bind
4 8 timeout timeout
5 9 trigger trigger
6 10 udp_s udp_s
File examples/Makefile changed (mode: 100644) (index 1c5e9b6..d5cf65e)
1 TARGETS := s c raw udp_s timeout trigger line1
1 TARGETS := s s_bind c raw udp_s timeout trigger line1
2 2
3 3 all: $(TARGETS) all: $(TARGETS)
4 4
 
... ... DEPS := ../libConn.so.$(VER) $(OBJS)
10 10 s: s.c $(DEPS) s: s.c $(DEPS)
11 11 gcc $(CFLAGS) $(INCS) s.c -o s $(LIBS) gcc $(CFLAGS) $(INCS) s.c -o s $(LIBS)
12 12
13 s_bind: s_bind.c $(DEPS)
14 gcc $(CFLAGS) $(INCS) s_bind.c -o s_bind $(LIBS)
15
13 16 c: c.c $(DEPS) c: c.c $(DEPS)
14 17 gcc $(CFLAGS) $(INCS) c.c -o c $(LIBS) gcc $(CFLAGS) $(INCS) c.c -o c $(LIBS)
15 18
File examples/s_bind.c copied from file examples/s.c (similarity 92%) (mode: 100644) (index ac15060..f3fede1)
1 /*
2 * Copyright: Catalin(ux) M. BOIE
3 * Shows how to bind to a specific address.
4 */
5
1 6 #define _GNU_SOURCE #define _GNU_SOURCE
2 7
3 8 #include <errno.h> #include <errno.h>
 
23 28 static unsigned short debug = 20; static unsigned short debug = 20;
24 29
25 30 static FILE *Logf = NULL; static FILE *Logf = NULL;
26 static char *log_file = "s.log";
31 static char *log_file = "s_bind.log";
27 32 static int port = 9000; static int port = 9000;
28 33 static short ipv4 = 1, ipv6 = 1; static short ipv4 = 1, ipv6 = 1;
29 34 static int maxconn = 0; static int maxconn = 0;
 
... ... int main(void)
118 123
119 124 if (ipv4 == 1) { if (ipv4 == 1) {
120 125 Log(9, "Try to register IPv4 socket...\n"); Log(9, "Try to register IPv4 socket...\n");
121 I4 = Conn_socket(PF_INET, SOCK_STREAM, port);
126 I4 = Conn_socket_addr(PF_INET, SOCK_STREAM, "127.0.0.1", port);
122 127 if (!I4) if (!I4)
123 128 Log(1, "Cannot bind on ipv4 socket [%s].\n", Conn_strerror()); Log(1, "Cannot bind on ipv4 socket [%s].\n", Conn_strerror());
124 129 } }
125 130
126 131 if (ipv6 == 1) { if (ipv6 == 1) {
127 132 Log(9, "Try to register IPv6 socket...\n"); Log(9, "Try to register IPv6 socket...\n");
128 I6 = Conn_socket(PF_INET6, SOCK_STREAM, port);
133 I6 = Conn_socket_addr(PF_INET6, SOCK_STREAM, "::1", port);
129 134 if (!I6) if (!I6)
130 135 Log(1, "Cannot bind on ipv6 socket [%s].\n", Conn_strerror()); Log(1, "Cannot bind on ipv6 socket [%s].\n", Conn_strerror());
131 136 } }
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/catalinux/Conn

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

Clone this repository using git:
git clone git://git.rocketgit.com/user/catalinux/Conn

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