From e3d341843d9c8a862dd77bf10f4269ae87fcb058 Mon Sep 17 00:00:00 2001 From: Nick Peng Date: Sun, 3 Jun 2018 16:39:54 +0800 Subject: [PATCH] Basic Tests pass --- dns_server.c | 35 +---------------------------------- fast_ping.c | 8 +++++++- include/atomic.h | 4 ++-- 3 files changed, 10 insertions(+), 37 deletions(-) diff --git a/dns_server.c b/dns_server.c index db9cad0..c2ca076 100644 --- a/dns_server.c +++ b/dns_server.c @@ -98,40 +98,7 @@ struct dns_request { static struct dns_server server; -void _dns_server_period_run() -{ - return; - unsigned char packet_data[DNS_PACKSIZE]; - unsigned char data[DNS_IN_PACKSIZE]; - - struct dns_packet *packet = (struct dns_packet *)packet_data; - - struct dns_head head; - memset(&head, 0, sizeof(head)); - head.rcode = 0; - head.qr = 0; - head.rd = 1; - head.ra = 0; - head.id = 1; - - int len; - struct sockaddr_in to; - socklen_t to_len = sizeof(to); - - dns_packet_init(packet, DNS_PACKSIZE, &head); - dns_add_domain(packet, "www.huawei.com", DNS_T_A, 1); - len = dns_encode(data, DNS_IN_PACKSIZE, packet); - - memset(&to, 0, sizeof(to)); - to.sin_addr.s_addr = inet_addr("192.168.1.1"); - to.sin_port = htons(53); - - len = sendto(server.fd, data, len, 0, (struct sockaddr *)&to, to_len); - if (len < 0) { - tlog(TLOG_ERROR, "send failed."); - } - tlog(TLOG_ERROR, "send.\n"); -} +void _dns_server_period_run() {} static int _dns_server_forward_request(unsigned char *inpacket, int inpacket_len) { diff --git a/fast_ping.c b/fast_ping.c index 5eb1b9d..1e39620 100755 --- a/fast_ping.c +++ b/fast_ping.c @@ -246,6 +246,12 @@ static void _fast_ping_host_put(struct ping_host_struct *ping_host) return; } + struct timeval tv; + tv.tv_sec = 0; + tv.tv_usec = 0; + + ping_host->ping_callback(ping_host, ping_host->host, PING_RESULT_END, &ping_host->addr, ping_host->addr_len, ping_host->seq, &tv, ping_host->userptr); + free(ping_host); } @@ -265,7 +271,7 @@ static void _fast_ping_host_put_locked(struct ping_host_struct *ping_host) struct timeval tv; tv.tv_sec = 0; tv.tv_usec = 0; - + ping_host->ping_callback(ping_host, ping_host->host, PING_RESULT_END, &ping_host->addr, ping_host->addr_len, ping_host->seq, &tv, ping_host->userptr); free(ping_host); diff --git a/include/atomic.h b/include/atomic.h index 1c25211..e5dbbea 100755 --- a/include/atomic.h +++ b/include/atomic.h @@ -76,7 +76,7 @@ static inline int atomic_sub_and_test( int i, atomic_t *v ) */ static inline void atomic_inc( atomic_t *v ) { - (void)__sync_fetch_and_add(&v->counter, 1); + (void)__sync_add_and_fetch(&v->counter, 1); } /** @@ -88,7 +88,7 @@ static inline void atomic_inc( atomic_t *v ) */ static inline void atomic_dec( atomic_t *v ) { - (void)__sync_fetch_and_sub(&v->counter, 1); + (void)__sync_sub_and_fetch(&v->counter, 1); } /**