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 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
Exported _alloc and _commit functions. 9a3159e89eff020cfb75b9eec49a45a637a6da57 Catalin(ux) M. BOIE 2009-08-21 16:39:27
Added blackhole example. 8a7ac49b018ad65ba386f8a50725745127b4cbd2 Catalin(ux) M. BOIE 2009-08-21 15:54:55
TODO in/out. fdcfbf9e18ed5fbe0135b9aa702e09432fa71e93 Catalin(ux) M. BOIE 2009-08-21 15:53:05
Commit 1b6e7e8a294ac88aa966e4e43bb77a4fdff0ca5a - Added Conn_set_address helper.
Signed-off-by: Catalin(ux) M. BOIE <catab@embedromix.ro>
Author: Catalin(ux) M. BOIE
Author date (UTC): 2009-08-25 19:21
Committer name: Catalin(ux) M. BOIE
Committer date (UTC): 2009-09-02 15:42
Parent(s): d431edba6699d1363e4d616aa6f96588272188b0
Signing key:
Tree: c999d476ed11f01a4dd58c99277c3018682fcfca
File Lines added Lines deleted
Conn.c 6 27
Conn_engine_core.c 63 0
Conn_engine_core.h 2 0
File Conn.c changed (mode: 100644) (index cc5689d..38cc411)
... ... static void Conn_accept(struct Conn *C)
771 771 return; return;
772 772 } }
773 773
774 err = getsockname(fd, psa, &sax_len);
775
776 switch (C->sock_domain) {
777 case PF_INET:
778 /* remote */
779 inet_ntop(C->sock_domain, &ca4.sin_addr, X->addr, sizeof(X->addr));
780 X->port = ntohs(ca4.sin_port);
781 /* local */
782 if (err == 0) {
783 inet_ntop(C->sock_domain, &sa4.sin_addr, X->bind_addr, sizeof(X->bind_addr));
784 X->bind_port = ntohs(sa4.sin_port);
785 }
786 break;
787
788 case PF_INET6:
789 /* remote */
790 inet_ntop(C->sock_domain, &ca6.sin6_addr, X->addr, sizeof(X->addr));
791 X->port = ntohs(ca6.sin6_port);
792 /* local */
793 if (err == 0) {
794 inet_ntop(C->sock_domain, &sa6.sin6_addr, X->bind_addr, sizeof(X->addr));
795 X->bind_port = ntohs(sa6.sin6_port);
796 }
797 break;
798 }
799
774 X->fd = fd;
800 775 X->type = CONN_TYPE_P2P; X->type = CONN_TYPE_P2P;
801 776 X->state = CONN_STATE_OPEN; X->state = CONN_STATE_OPEN;
802 777 X->via = C->id; X->via = C->id;
803 X->fd = fd;
804 778 X->events = CONN_POLLIN; X->events = CONN_POLLIN;
805 779
806 780 Conn_set_socket_domain(X, C->sock_domain); Conn_set_socket_domain(X, C->sock_domain);
 
... ... static void Conn_accept(struct Conn *C)
809 783
810 784 Conn_setnonblock(X->fd); Conn_setnonblock(X->fd);
811 785
786 Conn_set_address(X, 0);
787 Conn_set_address(X, 1);
788
812 789 err = Conn_engine_add_obj(X); err = Conn_engine_add_obj(X);
813 790 if (err != 0) { if (err != 0) {
814 791 Conn_error_raise(C, err); Conn_error_raise(C, err);
 
... ... static void Conn_poll_cb(struct Conn *C, int revents)
1194 1171
1195 1172 C->state = CONN_STATE_OPEN; C->state = CONN_STATE_OPEN;
1196 1173
1174 Conn_set_address(C, 0);
1175
1197 1176 if (C->cb_connected != NULL) if (C->cb_connected != NULL)
1198 1177 C->cb_connected(C); C->cb_connected(C);
1199 1178 else if (Conn_connected_cb) else if (Conn_connected_cb)
File Conn_engine_core.c changed (mode: 100644) (index f7e4747..3b1eab4)
... ... void Conn_queue_destroy(struct Conn_queue *q)
1030 1030 } }
1031 1031
1032 1032 /* Misc */ /* Misc */
1033 /*
1034 * Returns the string representation of an socket address
1035 * @flags: bit0==0 => local address, bit0==1 => peer address
1036 */
1037 int Conn_set_address(struct Conn *C, const int flags)
1038 {
1039 int err;
1040 struct sockaddr *psa;
1041 struct sockaddr_in sa4;
1042 struct sockaddr_in6 sa6;
1043 socklen_t sa_len;
1044 char *paddr;
1045 size_t addr_size;
1046 int *pport;
1047
1048 switch (C->sock_domain) {
1049 case PF_INET:
1050 psa = (struct sockaddr *) &sa4;
1051 sa_len = sizeof(struct sockaddr_in);
1052 break;
1053 case PF_INET6:
1054 psa = (struct sockaddr *) &sa6;
1055 sa_len = sizeof(struct sockaddr_in6);
1056 break;
1057 default:
1058 return -1;
1059 }
1060
1061 if (flags & 1) {
1062 /* peer */
1063 paddr = C->addr;
1064 addr_size = sizeof(C->addr);
1065 pport = &C->port;
1066 err = getpeername(C->fd, psa, &sa_len);
1067 } else {
1068 /* local */
1069 paddr = C->bind_addr;
1070 addr_size = sizeof(C->bind_addr);
1071 pport = &C->bind_port;
1072 err = getsockname(C->fd, psa, &sa_len);
1073 }
1074
1075 if (err != 0)
1076 return -1;
1077
1078 switch (C->sock_domain) {
1079 case PF_INET:
1080 inet_ntop(C->sock_domain, &sa4.sin_addr,
1081 paddr, addr_size);
1082 *pport = ntohs(sa4.sin_port);
1083 break;
1084 case PF_INET6:
1085 inet_ntop(C->sock_domain, &sa6.sin6_addr,
1086 paddr, addr_size);
1087 *pport = ntohs(sa6.sin6_port);
1088 break;
1089 default:
1090 return -1;
1091 }
1092
1093 return 0;
1094 }
1095
1033 1096 /* /*
1034 1097 * Returns the address family for address stored in @addr. * Returns the address family for address stored in @addr.
1035 1098 */ */
File Conn_engine_core.h changed (mode: 100644) (index 63d17ac..d5ee6e5)
... ... extern void Conn_error_raise(struct Conn *C, const int err);
316 316
317 317 extern void Conn_stop(void); extern void Conn_stop(void);
318 318
319 extern int Conn_set_address(struct Conn *C, const int flags);
320
319 321 /* queue stuff */ /* queue stuff */
320 322 extern void Conn_queue_init(struct Conn_queue *q); extern void Conn_queue_init(struct Conn_queue *q);
321 323 extern int Conn_queue_add(struct Conn_queue *q, extern int Conn_queue_add(struct Conn_queue *q,
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