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)
Removed line1.c because duplicates code. 1119059afacde8d0b7b7dab77850dd6b71684190 Catalin(ux) M. BOIE 2009-08-25 20:11:52
Removed *.run becasue we have a generic run script. 007083cd9d1abefe4dd73e65c9026a2607fbcd4e Catalin(ux) M. BOIE 2009-08-25 20:09:00
Removed bind_s example because blackhole_s will take place. b9b06d98f00413b5a5df9d7bc9b3bd05b5536f28 Catalin(ux) M. BOIE 2009-08-25 20:07:38
Added Conn_set_address helper. 1b6e7e8a294ac88aa966e4e43bb77a4fdff0ca5a Catalin(ux) M. BOIE 2009-08-25 19:21:00
Fixed storing of local address (do not overwrite remote address). d431edba6699d1363e4d616aa6f96588272188b0 Catalin(ux) M. BOIE 2009-08-25 18:37:55
Added Conn_stop to eleganly stop Conn system. 4ca191771c5c119e9755a5af3158fabe43ddf5f2 Catalin(ux) M. BOIE 2009-08-25 18:30:32
Replaced Conn_protocol with Conn_get_socket_protocol. a1cbc5c612d82e6d1341524c67fe249648c81806 Catalin(ux) M. BOIE 2009-08-25 18:16:45
Compressed a little the POLL flags. 47b5dce395694c18c973e3ce6ba9a71c690a41bc Catalin(ux) M. BOIE 2009-08-25 18:16:16
Store also local address for incoming connections. 0548ce6434185cdd36e110c61315b4cb21849666 Catalin(ux) M. BOIE 2009-08-25 18:15:46
Added possibility to shutdown blackhole_s server by typing 'quit'. 5fd60900809e1a2d7554aa7fa93ce83b29214de0 Catalin(ux) M. BOIE 2009-08-25 17:54:27
Cosmetic changes. 7099dd49a270b9f4ecc0cb2e55254bef671202e5 Catalin(ux) M. BOIE 2009-08-25 17:54:15
Improved status output. 1ff597059bbb208b56ad18bf8324fae5b63950a2 Catalin(ux) M. BOIE 2009-08-25 17:53:44
Conn_type_* becomes CONN_TYPE_*. b284a20cc5430042cc662edc4d121c7f18cb3569 Catalin(ux) M. BOIE 2009-08-25 17:52:51
Improved status logging. 54fea00d8f16127244fd15b209c24f606adb20b3 Catalin(ux) M. BOIE 2009-08-25 17:33:14
Added Conn_strcasestr for case insensitive search in buffer. ca14b37b2a1f23887ad12fed729a3dd0ff253443 Catalin(ux) M. BOIE 2009-08-24 17:18:24
Improved ntime example. b63de9b82ffab1c0d759571a40f1d72f9b8df927 Catalin(ux) M. BOIE 2009-08-24 17:09:21
Removed unused includes. 8af81a4c311caa7d738000a5208d01d7620d1040 Catalin(ux) M. BOIE 2009-08-21 18:57:33
Improved blackhole example. 2fd7ff181a412f4ba060b0e89b97acdf89a8fb88 Catalin(ux) M. BOIE 2009-08-21 18:03:22
Fixed connections to outside. Still, it is a little mess there. 417ccd4a48508a810377676658d51c5103168472 Catalin(ux) M. BOIE 2009-08-21 17:42:37
addr and bind_addr are not pointers! Corrected them. e1deeb765500ee079802c2cd6543f9c9496d8f9b Catalin(ux) M. BOIE 2009-08-21 16:49:24
Commit 1119059afacde8d0b7b7dab77850dd6b71684190 - Removed line1.c because duplicates code.
Signed-off-by: Catalin(ux) M. BOIE <catab@embedromix.ro>
Author: Catalin(ux) M. BOIE
Author date (UTC): 2009-08-25 20:11
Committer name: Catalin(ux) M. BOIE
Committer date (UTC): 2009-09-02 15:42
Parent(s): 007083cd9d1abefe4dd73e65c9026a2607fbcd4e
Signer:
Signing key:
Signing status: N
Tree: e91aa108193b4ee1dc6e43fae076c7203717b946
File Lines added Lines deleted
examples/Makefile 1 1
examples/line1.c 0 144
File examples/Makefile changed (mode: 100644) (index 917d2e1..22c747d)
1 TARGETS := s s_bind c raw udp_s timeout trigger line1 reconnect ntime blackhole_s blackhole_c
1 TARGETS := s c raw udp_s timeout trigger reconnect ntime blackhole_s blackhole_c
2 2
3 3 all: $(TARGETS) all: $(TARGETS)
4 4
File examples/line1.c deleted (index 9326277..0000000)
1 #define _GNU_SOURCE
2
3 #include <errno.h>
4 #include <string.h>
5 #include <strings.h>
6 #include <stdlib.h>
7 #include <unistd.h>
8 #include <sys/poll.h>
9 #include <sys/types.h>
10 #include <sys/socket.h>
11 #include <stdio.h>
12 #include <fcntl.h>
13 #include <netinet/in.h>
14 #include <sys/time.h>
15 #include <sys/ioctl.h>
16 #include <time.h>
17 #include <arpa/inet.h>
18 #include <stdarg.h>
19
20 #include <Conn.h>
21
22 /* Global variables */
23 static unsigned short debug = 3;
24
25 static FILE *Logf = NULL;
26 static char *log_file = "line1.log";
27 static int port = 9000;
28 static short ipv4 = 1, ipv6 = 1;
29 static int maxconn = 0;
30
31 static void s_accept(struct Conn *C)
32 {
33 Log(4, "%s (A connection was accepted from [%s] on slot %d. Set POLLIN and enq greeting...\n",
34 __FUNCTION__, C->addr, C->slot);
35 }
36
37 static void s_close(struct Conn *C)
38 {
39 Log(5, "%s (A connection will be closed [%s] on slot %d)\n",
40 __FUNCTION__, C->addr, C->slot);
41 }
42
43 static int s_data_cb(struct Conn *C, char *line)
44 {
45 char *dump;
46
47 dump = Conn_dump(line, strlen(line));
48 Log(0, "%s: recv bytes head=%d tail=%d on slot %d: [%s]\n",
49 __FUNCTION__, C->ibuf_head, C->ibuf_tail,
50 C->slot, dump);
51 free(dump);
52
53 return 0;
54 }
55
56 static void s_data(struct Conn *C)
57 {
58 Conn_for_every_line(C, s_data_cb);
59 }
60
61 static void s_error(struct Conn *C)
62 {
63 Log(1, "%s: cid=%llu\n",
64 __FUNCTION__, Conn_getid(C));
65 }
66
67 int main(void)
68 {
69 struct Conn *I4 = NULL, *I6 = NULL;
70 int ret;
71 struct timeval start;
72 int loops = 0;
73
74 Logf = fopen(log_file, "w");
75 if (!Logf) {
76 fprintf(stderr, "Cannot open log file [%s] [%s]\n",
77 log_file, strerror(errno));
78 return 1;
79 }
80 if (debug > 0)
81 setlinebuf(Logf);
82
83 /*daemon(0, 0);*/
84
85 gettimeofday(&start, NULL);
86 Log(0, "\nStarting at %ld...\n", start.tv_sec);
87 Log(0, "\tPort=%d\n", port);
88 Log(0, "\tLogFile=%s Debug=%d\n", log_file, debug);
89 Log(0, "\tipv4=%s ipv6=%s\n", (ipv4 == 1) ? "on" : "off", (ipv6 == 1) ? "on" : "off");
90
91 /* set library output debug */
92 Conn_debug(Logf, debug);
93
94 ret = Conn_init(maxconn);
95 if (ret == -1) {
96 Log(0, "%s", Conn_strerror());
97 return 1;
98 }
99
100 if (ipv4 == 1) {
101 Log(9, "Try to register IPv4 socket...\n");
102 I4 = Conn_socket(PF_INET, SOCK_STREAM, port);
103 if (!I4)
104 Log(1, "Cannot bind on ipv4 socket [%s].\n", Conn_strerror());
105 }
106
107 if (ipv6 == 1) {
108 Log(9, "Try to register IPv6 socket...\n");
109 I6 = Conn_socket(PF_INET6, SOCK_STREAM, port);
110 if (!I6)
111 Log(1, "Cannot bind on ipv6 socket [%s].\n", Conn_strerror());
112 }
113
114 if ((I6 == NULL) && (I4 == NULL)) {
115 Log(0, "Cannot bind!\n");
116 return 1;
117 }
118
119 Conn_accept_cb = s_accept;
120 Conn_data_cb = s_data;
121 Conn_close_cb = s_close;
122 Conn_error_cb = s_error;
123
124 while (1) {
125 ret = Conn_poll(10000);
126 if (ret == -1) {
127 Log(0, "Error calling Conn_poll [%s]!\n", Conn_strerror());
128 return 1;
129 }
130
131 loops++;
132 if (ret == 0)
133 break;
134
135 /*
136 if (loops > 1000000)
137 break;
138 */
139 }
140
141 Log(0, "Finish!\n\n");
142
143 return 0;
144 }
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