From 3dcbd4a231b33324d85cfa3a062ea66658878c75 Mon Sep 17 00:00:00 2001 From: hyung-hwan Date: Fri, 8 Feb 2019 10:13:24 +0000 Subject: [PATCH] started dns protocol implementation --- mio/Makefile.in | 9 ++--- mio/configure | 14 +------ mio/lib/Makefile.am | 1 + mio/lib/Makefile.in | 2 +- mio/lib/mio-dns.h | 90 +++++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 97 insertions(+), 19 deletions(-) create mode 100644 mio/lib/mio-dns.h diff --git a/mio/Makefile.in b/mio/Makefile.in index 2fe5d77..e8308fe 100644 --- a/mio/Makefile.in +++ b/mio/Makefile.in @@ -347,7 +347,6 @@ pdfdir = @pdfdir@ prefix = @prefix@ program_transform_name = @program_transform_name@ psdir = @psdir@ -runstatedir = @runstatedir@ sbindir = @sbindir@ sharedstatedir = @sharedstatedir@ srcdir = @srcdir@ @@ -578,7 +577,7 @@ distdir: $(DISTFILES) ! -type d ! -perm -444 -exec $(install_sh) -c -m a+r {} {} \; \ || chmod -R a+r "$(distdir)" dist-gzip: distdir - tardir=$(distdir) && $(am__tar) | GZIP=$(GZIP_ENV) gzip -c >$(distdir).tar.gz + tardir=$(distdir) && $(am__tar) | eval GZIP= gzip $(GZIP_ENV) -c >$(distdir).tar.gz $(am__post_remove_distdir) dist-bzip2: distdir @@ -604,7 +603,7 @@ dist-shar: distdir @echo WARNING: "Support for shar distribution archives is" \ "deprecated." >&2 @echo WARNING: "It will be removed altogether in Automake 2.0" >&2 - shar $(distdir) | GZIP=$(GZIP_ENV) gzip -c >$(distdir).shar.gz + shar $(distdir) | eval GZIP= gzip $(GZIP_ENV) -c >$(distdir).shar.gz $(am__post_remove_distdir) dist-zip: distdir @@ -622,7 +621,7 @@ dist dist-all: distcheck: dist case '$(DIST_ARCHIVES)' in \ *.tar.gz*) \ - GZIP=$(GZIP_ENV) gzip -dc $(distdir).tar.gz | $(am__untar) ;;\ + eval GZIP= gzip $(GZIP_ENV) -dc $(distdir).tar.gz | $(am__untar) ;;\ *.tar.bz2*) \ bzip2 -dc $(distdir).tar.bz2 | $(am__untar) ;;\ *.tar.lz*) \ @@ -632,7 +631,7 @@ distcheck: dist *.tar.Z*) \ uncompress -c $(distdir).tar.Z | $(am__untar) ;;\ *.shar.gz*) \ - GZIP=$(GZIP_ENV) gzip -dc $(distdir).shar.gz | unshar ;;\ + eval GZIP= gzip $(GZIP_ENV) -dc $(distdir).shar.gz | unshar ;;\ *.zip*) \ unzip $(distdir).zip ;;\ esac diff --git a/mio/configure b/mio/configure index ae0ee03..b3bc195 100755 --- a/mio/configure +++ b/mio/configure @@ -771,7 +771,6 @@ infodir docdir oldincludedir includedir -runstatedir localstatedir sharedstatedir sysconfdir @@ -862,7 +861,6 @@ datadir='${datarootdir}' sysconfdir='${prefix}/etc' sharedstatedir='${prefix}/com' localstatedir='${prefix}/var' -runstatedir='${localstatedir}/run' includedir='${prefix}/include' oldincludedir='/usr/include' docdir='${datarootdir}/doc/${PACKAGE_TARNAME}' @@ -1115,15 +1113,6 @@ do | -silent | --silent | --silen | --sile | --sil) silent=yes ;; - -runstatedir | --runstatedir | --runstatedi | --runstated \ - | --runstate | --runstat | --runsta | --runst | --runs \ - | --run | --ru | --r) - ac_prev=runstatedir ;; - -runstatedir=* | --runstatedir=* | --runstatedi=* | --runstated=* \ - | --runstate=* | --runstat=* | --runsta=* | --runst=* | --runs=* \ - | --run=* | --ru=* | --r=*) - runstatedir=$ac_optarg ;; - -sbindir | --sbindir | --sbindi | --sbind | --sbin | --sbi | --sb) ac_prev=sbindir ;; -sbindir=* | --sbindir=* | --sbindi=* | --sbind=* | --sbin=* \ @@ -1261,7 +1250,7 @@ fi for ac_var in exec_prefix prefix bindir sbindir libexecdir datarootdir \ datadir sysconfdir sharedstatedir localstatedir includedir \ oldincludedir docdir infodir htmldir dvidir pdfdir psdir \ - libdir localedir mandir runstatedir + libdir localedir mandir do eval ac_val=\$$ac_var # Remove trailing slashes. @@ -1414,7 +1403,6 @@ Fine tuning of the installation directories: --sysconfdir=DIR read-only single-machine data [PREFIX/etc] --sharedstatedir=DIR modifiable architecture-independent data [PREFIX/com] --localstatedir=DIR modifiable single-machine data [PREFIX/var] - --runstatedir=DIR modifiable per-process data [LOCALSTATEDIR/run] --libdir=DIR object code libraries [EPREFIX/lib] --includedir=DIR C header files [PREFIX/include] --oldincludedir=DIR C header files for non-gcc [/usr/include] diff --git a/mio/lib/Makefile.am b/mio/lib/Makefile.am index c6efc8f..3a6a6fe 100644 --- a/mio/lib/Makefile.am +++ b/mio/lib/Makefile.am @@ -22,6 +22,7 @@ LIBADD_LIB_COMMON = $(LIBM) $(LIBLTDL) include_HEADERS = \ mio-cfg.h \ mio-cmn.h \ + mio-dns.h \ mio-pro.h \ mio-sck.h \ mio-utl.h \ diff --git a/mio/lib/Makefile.in b/mio/lib/Makefile.in index b17aa12..3e180d8 100644 --- a/mio/lib/Makefile.in +++ b/mio/lib/Makefile.in @@ -365,7 +365,6 @@ pdfdir = @pdfdir@ prefix = @prefix@ program_transform_name = @program_transform_name@ psdir = @psdir@ -runstatedir = @runstatedir@ sbindir = @sbindir@ sharedstatedir = @sharedstatedir@ srcdir = @srcdir@ @@ -395,6 +394,7 @@ LIBADD_LIB_COMMON = $(LIBM) $(LIBLTDL) include_HEADERS = \ mio-cfg.h \ mio-cmn.h \ + mio-dns.h \ mio-pro.h \ mio-sck.h \ mio-utl.h \ diff --git a/mio/lib/mio-dns.h b/mio/lib/mio-dns.h new file mode 100644 index 0000000..fe68d87 --- /dev/null +++ b/mio/lib/mio-dns.h @@ -0,0 +1,90 @@ +/* + * $Id$ + * + Copyright (c) 2015-2016 Chung, Hyung-Hwan. All rights reserved. + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions + are met: + 1. Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + 2. Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + + THIS SOFTWARE IS PROVIDED BY THE AUTHOR "AS IS" AND ANY EXPRESS OR + IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WAfRRANTIES + OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, + INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _MIO_DNS_H_ +#define _MIO_DNS_H_ + +#include + +#define MIO_DNS_PORT (53) + +enum mio_dns_opcode_t +{ + MIO_DNS_OPCODE_QUERY = 0, /* standard query */ + MIO_DNS_OPCODE_IQUERY = 1, /* inverse query */ + MIO_DNS_OPCODE_STATUS = 2, /* status request */ + /* 3 unassigned */ + MIO_DNS_OPCODE_NOTIFY = 4, + MIO_DNS_OPCODE_UPDATE = 5 +}; +typedef enum mio_dns_opcode_t mio_dns_opcode_t; + +enum mio_dns_rcode_t +{ + MIO_DNS_RCODE_NOERROR = 0, + MIO_DNS_RCODE_FORMERR = 1, /* format error */ + MIO_DNS_RCODE_SERVFAIL = 2, /* server failure */ + MIO_DNS_RCODE_NXDOMAIN = 3, /* non-existent domain */ + MIO_DNS_RCODE_NOTIMPL = 4, /* not implemented */ + MIO_DNS_RCODE_REFUSED = 5, /* query refused */ + MIO_DNS_RCODE_YXDOMAIN = 6, /* name exists when it should not */ + MIO_DNS_RCODE_YXRRSET = 7, /* RR set exists when it should not */ + MIO_DNS_RCODE_NXRRSET = 8, /* RR set exists when it should not */ + MIO_DNS_RCODE_NOTAUTH = 9, /* not authorized or server not authoritative for zone*/ + MIO_DNS_RCODE_NOTZONE = 10, /* name not contained in zone */ + MIO_DNS_RCODE_BADVERS = 16, + MIO_DNS_RCODE_BADSIG = 17, + MIO_DNS_RCODE_BADTIME = 18, + MIO_DNS_RCODE_BADMODE = 19, + MIO_DNS_RCODE_BADNAME = 20, + MIO_DNS_RCODE_BADALG = 21, + MIO_DNS_RCODE_BADTRUNC = 22, + MIO_DNS_RCODE_BADCOOKIE = 23 +}; +typedef enum mio_dns_rcode_t mio_dns_rcode_t; + +struct mio_dns_msg_t +{ + mio_uint16_t id; + mio_uint16_t qr: 1; /* query(0), answer(1) */ + mio_uint16_t opcode: 4; /* operation type */ + mio_uint16_t aa: 1; /* authoritative answer */ + mio_uint16_t tc: 1; /* truncated. response too large for UDP */ + mio_uint16_t rd: 1; /* recursion desired */ + mio_uint16_t ra: 1; /* recursion available */ + mio_uint16_t unused_1: 1; + mio_uint16_t ad: 1; /* authentication data - dnssec */ + mio_uint16_t cd: 1; /* checking disabled - dnssec */ + mio_uint16_t rcode: 4; + mio_uint16_t qdcount; + mio_uint16_t ancount; + mio_uint16_t nscount; + mio_uint16_t arcount; +}; + +typedef struct mio_dns_msg_t mio-dns + +#endif