#include "i_config.h" #include <stdio.h> #include <string.h> #include <sys/time.h> #include <sys/socket.h> #include <Conn.h> #include "i_types.h" #include "i_util.h" #include "i_conf.h" #include "parser.h" static int log_fd = 1; static int conf_port = 9999; static char cmd[128]; static void connected_cb(struct Conn *C) { Log(1, "Enqueue [%s]...\n", cmd); if (Conn_enqueue(C, cmd, strlen(cmd)) == -1) { Log(0, "Cannot enqueue (%s)!\n", Conn_strerror()); } } static void data_cb(struct Conn *C, char *line) { printf("%s\n", line); Conn_close(C); } static void data(struct Conn *C) { Conn_for_every_line(C, data_cb); } static void error(struct Conn *C) { Log(0, "Error on id=%llu (%s).\n", Conn_getid(C), Conn_strerror()); } int main(int argc, char *argv[]) { struct Conn *C; int ret; if (argc < 2) { fprintf(stderr, "Usage: ip2clue <ip> [<ip2clue_daemon_port>]\n"); return 1; } /* prepare sending */ snprintf(cmd, sizeof(cmd), "R%s\n", argv[1]); Conn_debug(log_fd, 0); if (argc >= 3) conf_port = strtol(argv[2], NULL, 10); ret = Conn_init(0); if (ret == -1) { Log(0, "Cannot init Conn (%s)!\n", Conn_strerror()); return 1; } /* prefer IPv6 */ Log(1, "IPv6...\n"); C = Conn_alloc(); if (!C) { Log(0, "Cannot alloc a Conn v6 structure (%s)!\n", Conn_strerror()); return 1; } Conn_set_socket_domain(C, PF_INET6); Conn_set_socket_type(C, SOCK_STREAM); Conn_set_socket_addr(C, "::1"); Conn_set_socket_port(C, conf_port); ret = Conn_commit(C); if (ret != 0) { Log(0, "Cannot commit v6 (%s)!\n", Conn_strerror()); Log(1, "IPv4...\n"); Conn_set_socket_domain(C, PF_INET); Conn_set_socket_type(C, SOCK_STREAM); Conn_set_socket_addr(C, "127.0.0.1"); Conn_set_socket_port(C, conf_port); ret = Conn_commit(C); if (ret != 0) { Log(0, "Cannot commit v4 (%s)!\n", Conn_strerror()); return 1; } } Conn_set_cb(C, CONN_CB_DATA, data); Conn_set_cb(C, CONN_CB_ERROR, error); Conn_set_cb(C, CONN_CB_CONNECTED, connected_cb); Log(1, "Start polling...\n"); while (1) { ret = Conn_poll(-1); if (ret == -1) { Log(0, "Error in Conn_poll (%s)!\n", Conn_strerror()); break; } else if (ret == 0) { break; } } Conn_shutdown(); return 0; }
Mode | Type | Size | Ref | File |
---|---|---|---|---|
100644 | blob | 47 | a9a866602d44352da048bd6ae6970951275c9568 | .exclude |
100644 | blob | 115 | 8c323b0915d6cfb17e770cea790c7a688adf546f | .gitignore |
100644 | blob | 35147 | 94a9ed024d3859793618152ea559a168bbcbb5e2 | LICENSE |
100644 | blob | 1614 | a1a71bb742e512b346775f8c9d5e34f1dbe7f0ef | Makefile.in |
100644 | blob | 1780 | 89d08247cf7dd7e38b83fd9da500f6eee926e1ae | README |
100644 | blob | 965 | c06153174a6dbae1d92908e79493c6a2288bcc4b | TODO |
040000 | tree | - | 4183fb09e7128f53343a3a1c187af50171c19895 | clients |
100755 | blob | 30 | 92c4bc48245c00408cd7e1fd89bc1a03058f4ce4 | configure |
040000 | tree | - | 866ff01beda9a20ef5068a5a117504a1b2b496cf | crons |
100755 | blob | 15674 | c93b35dad5dedf498b90aafcbf409a4844b1bc8c | duilder |
100644 | blob | 728 | bf74b5b4239eac406de35ff628ebb00456335c15 | duilder.conf |
040000 | tree | - | ab6bf593a73be7b2cb422c2bf75a81958524b530 | etc |
100644 | blob | 1758 | 4a76efe2ee5125d6d19cee5d9f5abe06cde4883c | i_conf.c |
100644 | blob | 448 | fb8429f7ea61c8669a83f1279fce35eee492a6fc | i_conf.h |
100644 | blob | 90 | 8bc7f81e7fff1a5c7b350cb464131cb8f2fae6eb | i_config.h |
100644 | blob | 2140 | f029ed1d41c3b4cf9be580d4b39438c2dda2c803 | i_types.h |
100644 | blob | 11075 | c9658a4f24bd96c55c3a0b48b470020851e21e51 | i_util.c |
100644 | blob | 1293 | 619bd9eda37a3c700d2fa03dcda5c627f685551e | i_util.h |
100644 | blob | 2258 | e830c971aca34462dbcf4aed1c5f1b68d804d124 | ip2clue.c |
100644 | blob | 1200 | eadfb9d5cd34bf7004ad4710d59762316ad5c7f1 | ip2clue.spec.in |
100644 | blob | 6717 | d4d5cbc67f02e5e154bacc2beadfc23b470db2a1 | ip2clued.c |
100644 | blob | 630 | 58bdcc5108d0bc8b7e6d3e54515c5ff1027fcb2c | my.conf |
100644 | blob | 7035 | 88d5eb5f8b8e63ee404e7c292496bdd1fa57c1c0 | parser.c |
100644 | blob | 780 | af2e94d9ca6889d29c0dc89726f5ccfac6c01587 | parser.h |
100644 | blob | 548 | 92e5dd7d252934f699e58212eba66fe805079d5a | parser_core.c |
100644 | blob | 118 | 2130d9f9da8bf36eae902ad3ba11c570d647739f | parser_core.h |
100644 | blob | 11633 | d4620ff6accb1dd1057dd897ec465b304058e4b8 | parser_ip2location.c |
100644 | blob | 185 | 4775d2e989d7e830f71144d2492658214cb31c0a | parser_ip2location.h |
100644 | blob | 5064 | 7e96815b92eadb0cd89a1b6bd5684b80ad048557 | parser_text.c |
100644 | blob | 240 | 1643d56047dfd0609d6827ac475451e2db4bbef2 | parser_text.h |
100644 | blob | 4317 | d920b0b0e9574b4ffc9976ad3bdc7db7eab9b3b0 | test1.c |
100644 | blob | 4415 | 94663e1cd87b5a7d1cfda5c0230a972a05f7cbd9 | test2.c |