more dns code
This commit is contained in:
parent
b40bdf3e8e
commit
af86c6a95e
@ -29,6 +29,7 @@
|
||||
#include <mio-utl.h>
|
||||
#include <mio-sck.h>
|
||||
#include <mio-pro.h>
|
||||
#include <mio-dns.h>
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
@ -804,8 +805,25 @@ for (i = 0; i < 5; i++)
|
||||
//mio_dev_pro_close (pro, MIO_DEV_PRO_ERR);
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
{
|
||||
mio_dnsc_t* dnsc;
|
||||
dnsc = mio_dnsc_start (mio/*, "8.8.8.8:53,1.1.1.1:53"*/); /* option - send to all, send one by one */
|
||||
{
|
||||
mio_dns_bqrr_t qrr;
|
||||
qrr.name = "code.miflux.com";
|
||||
qrr.qclass = MIO_DNS_QCLASS_IN;
|
||||
qrr.qtype = MIO_DNS_QTYPE_A;
|
||||
mio_dnsc_sendreq (dnsc, &qrr, 1);
|
||||
}
|
||||
|
||||
mio_loop (mio);
|
||||
|
||||
/* TODO: let mio close it ... dnsc is svc. sck is dev. */
|
||||
mio_dnsc_stop (dnsc);
|
||||
}
|
||||
|
||||
g_mio = MIO_NULL;
|
||||
mio_close (mio);
|
||||
#if defined(USE_SSL)
|
||||
@ -831,6 +849,7 @@ int main (int argc, char* argv[])
|
||||
mio_dev_sck_make_t tcp_make;
|
||||
mio_dev_sck_connect_t tcp_conn;
|
||||
tcp_server_t* ts;
|
||||
mio_dnsc_t dnsc = MIO_NULL;
|
||||
|
||||
mio = mio_open(&mmgr, 0, MIO_NULL, 512, MIO_NULL);
|
||||
if (!mio)
|
||||
|
@ -72,11 +72,15 @@ enum mio_dns_qtype_t
|
||||
MIO_DNS_QTYPE_NS = 2,
|
||||
MIO_DNS_QTYPE_CNAME = 5,
|
||||
MIO_DNS_QTYPE_SOA = 6,
|
||||
MIO_DNS_QTYPE_NULL = 10,
|
||||
MIO_DNS_QTYPE_PTR = 12,
|
||||
MIO_DNS_QTYPE_MX = 15,
|
||||
MIO_DNS_QTYPE_TXT = 16,
|
||||
MIO_DNS_QTYPE_AAAA = 28,
|
||||
MIO_DNS_QTYPE_EID = 31,
|
||||
MIO_DNS_QTYPE_SRV = 33,
|
||||
MIO_DNS_QTYPE_OPT = 41,
|
||||
MIO_DNS_QTYPE_RRSIG = 46,
|
||||
MIO_DNS_QTYPE_ANY = 255
|
||||
};
|
||||
typedef enum mio_dns_qtype_t mio_dns_qtype_t;
|
||||
@ -123,28 +127,73 @@ struct mio_dns_msg_t
|
||||
#endif
|
||||
|
||||
mio_uint16_t qdcount; /* number of questions */
|
||||
mio_uint16_t ancount; /* number of answers */
|
||||
mio_uint16_t nscount; /* number of name servers */
|
||||
mio_uint16_t arcount; /* number of additional resource */
|
||||
mio_uint16_t ancount; /* number of answers (answer section) */
|
||||
mio_uint16_t nscount; /* number of name servers (authority section. only NS types) */
|
||||
mio_uint16_t arcount; /* number of additional resource (additional section) */
|
||||
};
|
||||
typedef struct mio_dns_msg_t mio_dns_msg_t;
|
||||
|
||||
struct mio_dns_qdrechdr_t
|
||||
/* question
|
||||
* name, qtype, qclass
|
||||
* answer
|
||||
* name, qtype, qclass, ttl, rlength, rdata
|
||||
*/
|
||||
|
||||
/* trailing part after the domain name in a resource record in a question */
|
||||
struct mio_dns_qrrtr_t
|
||||
{
|
||||
/* qname upto 64 bytes */
|
||||
mio_uint16_t qtype;
|
||||
mio_uint16_t qclass;
|
||||
};
|
||||
typedef struct moo_dns_qdrechdr_t moo_dns_qdrechdr_t;
|
||||
typedef struct mio_dns_qrrtr_t mio_dns_qrrtr_t;
|
||||
|
||||
struct mio_dns_anrechdr_t
|
||||
/* trailing part after the domain name in a resource record in an answer */
|
||||
struct mio_dns_arrtr_t
|
||||
{
|
||||
/* qname upto 64 bytes */
|
||||
mio_uint16_t qtype;
|
||||
mio_uint16_t qclass;
|
||||
mio_uint32_t ttl;
|
||||
mio_uint16_t dlen; /* data length */
|
||||
/* actual data if if dlen > 0 */
|
||||
};
|
||||
typedef struct moo_dns_ansrechdr_t moo_dns_ansrechdr_t;
|
||||
typedef struct mio_dns_arrtr_t mio_dns_arrtr_t;
|
||||
|
||||
|
||||
#include <mio-upac.h>
|
||||
|
||||
typedef struct mio_dnss_t mio_dnss_t;
|
||||
typedef struct mio_dnsc_t mio_dnsc_t;
|
||||
|
||||
struct mio_dns_bqrr_t
|
||||
{
|
||||
mio_bch_t* name;
|
||||
mio_uint16_t qtype;
|
||||
mio_uint16_t qclass;
|
||||
};
|
||||
typedef struct mio_dns_bqrr_t mio_dns_bqrr_t;
|
||||
|
||||
#if defined(__cplusplus)
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
MIO_EXPORT mio_dnsc_t* mio_dnsc_start (
|
||||
mio_t* mio
|
||||
);
|
||||
|
||||
MIO_EXPORT void mio_dnsc_stop (
|
||||
mio_dnsc_t* dnsc
|
||||
);
|
||||
|
||||
MIO_EXPORT int mio_dnsc_sendreq (
|
||||
mio_dnsc_t* dnsc,
|
||||
mio_dns_bqrr_t* qrr,
|
||||
mio_oow_t count
|
||||
);
|
||||
|
||||
#if defined(__cplusplus)
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
@ -401,7 +401,7 @@ oops:
|
||||
i--;
|
||||
if (rdev->slave[i])
|
||||
{
|
||||
mio_killdev (mio, (mio_dev_t*)rdev->slave[i]);
|
||||
mio_dev_kill ((mio_dev_t*)rdev->slave[i]);
|
||||
rdev->slave[i] = MIO_NULL;
|
||||
}
|
||||
}
|
||||
@ -440,12 +440,12 @@ static int dev_pro_kill_master (mio_dev_t* dev, int force)
|
||||
mio_dev_pro_slave_t* sdev = rdev->slave[i];
|
||||
|
||||
/* nullify the pointer to the slave device
|
||||
* before calling mio_killdev() on the slave device.
|
||||
* before calling mio_dev_kill() on the slave device.
|
||||
* the slave device can check this pointer to tell from
|
||||
* self-initiated termination or master-driven termination */
|
||||
rdev->slave[i] = MIO_NULL;
|
||||
|
||||
mio_killdev (mio, (mio_dev_t*)sdev);
|
||||
mio_dev_kill ((mio_dev_t*)sdev);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -516,9 +516,9 @@ static int dev_pro_kill_slave (mio_dev_t* dev, int force)
|
||||
* if this is the last slave, kill the master also */
|
||||
if (master->slave_count <= 0)
|
||||
{
|
||||
mio_killdev (mio, (mio_dev_t*)master);
|
||||
mio_dev_kill ((mio_dev_t*)master);
|
||||
/* the master pointer is not valid from this point onwards
|
||||
* as the actual master device object is freed in mio_killdev() */
|
||||
* as the actual master device object is freed in mio_dev_kill() */
|
||||
}
|
||||
}
|
||||
else
|
||||
@ -608,7 +608,7 @@ static int dev_pro_ioctl (mio_dev_t* dev, int cmd, void* arg)
|
||||
/* unlike dev_pro_kill_master(), i don't nullify rdev->slave[sid].
|
||||
* so i treat the closing ioctl as if it's a kill request
|
||||
* initiated by the slave device itself. */
|
||||
mio_killdev (mio, (mio_dev_t*)rdev->slave[sid]);
|
||||
mio_dev_kill ((mio_dev_t*)rdev->slave[sid]);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
@ -688,7 +688,7 @@ static mio_dev_evcb_t dev_pro_event_callbacks =
|
||||
static int pro_ready_slave (mio_dev_t* dev, int events)
|
||||
{
|
||||
mio_t* mio = dev->mio;
|
||||
mio_dev_pro_t* pro = (mio_dev_pro_t*)dev;
|
||||
/*mio_dev_pro_t* pro = (mio_dev_pro_t*)dev;*/
|
||||
|
||||
if (events & MIO_DEV_EVENT_ERR)
|
||||
{
|
||||
@ -785,6 +785,11 @@ mio_dev_pro_t* mio_dev_pro_make (mio_t* mio, mio_oow_t xtnsize, const mio_dev_pr
|
||||
&dev_pro_methods, &dev_pro_event_callbacks, (void*)info);
|
||||
}
|
||||
|
||||
void mio_dev_pro_kill (mio_dev_pro_t* dev)
|
||||
{
|
||||
mio_dev_kill ((mio_dev_t*)dev);
|
||||
}
|
||||
|
||||
void mio_dev_pro_halt (mio_dev_pro_t* dev)
|
||||
{
|
||||
mio_dev_halt ((mio_dev_t*)dev);
|
||||
|
@ -128,6 +128,11 @@ MIO_EXPORT mio_dev_pro_t* mio_dev_pro_make (
|
||||
const mio_dev_pro_make_t* data
|
||||
);
|
||||
|
||||
|
||||
MIO_EXPORT void mio_dev_pro_kill (
|
||||
mio_dev_pro_t* pro
|
||||
);
|
||||
|
||||
MIO_EXPORT void mio_dev_pro_halt (
|
||||
mio_dev_pro_t* pro
|
||||
);
|
||||
|
@ -327,7 +327,7 @@ enum mio_dev_sck_type_t
|
||||
{
|
||||
MIO_DEV_SCK_TCP4,
|
||||
MIO_DEV_SCK_TCP6,
|
||||
MIO_DEV_SCK_UPD4,
|
||||
MIO_DEV_SCK_UDP4,
|
||||
MIO_DEV_SCK_UDP6,
|
||||
|
||||
/* ARP at the ethernet layer */
|
||||
@ -554,6 +554,11 @@ MIO_EXPORT int mio_dev_sck_timedwrite (
|
||||
|
||||
#if defined(MIO_HAVE_INLINE)
|
||||
|
||||
static MIO_INLINE void mio_dev_sck_kill (mio_dev_sck_t* sck)
|
||||
{
|
||||
mio_dev_kill ((mio_dev_t*)sck);
|
||||
}
|
||||
|
||||
static MIO_INLINE void mio_dev_sck_halt (mio_dev_sck_t* sck)
|
||||
{
|
||||
mio_dev_halt ((mio_dev_t*)sck);
|
||||
@ -570,6 +575,7 @@ static MIO_INLINE int mio_dev_sck_timedread (mio_dev_sck_t* sck, int enabled, mi
|
||||
}
|
||||
#else
|
||||
|
||||
#define mio_dev_sck_kill(sck) mio_dev_kill((mio_dev_t*)sck)
|
||||
#define mio_dev_sck_halt(sck) mio_dev_halt((mio_dev_t*)sck)
|
||||
#define mio_dev_sck_read(sck,enabled) mio_dev_read((mio_dev_t*)sck, enabled)
|
||||
#define mio_dev_sck_timedread(sck,enabled,tmout) mio_dev_timedread((mio_dev_t*)sck, enabled, tmout)
|
||||
|
@ -152,13 +152,13 @@ void mio_fini (mio_t* mio)
|
||||
/* kill all registered devices */
|
||||
while (mio->actdev.head)
|
||||
{
|
||||
mio_killdev (mio, mio->actdev.head);
|
||||
mio_dev_kill (mio->actdev.head);
|
||||
}
|
||||
|
||||
/* kill all halted devices */
|
||||
while (mio->hltdev.head)
|
||||
{
|
||||
mio_killdev (mio, mio->hltdev.head);
|
||||
mio_dev_kill (mio->hltdev.head);
|
||||
}
|
||||
|
||||
/* clean up all zombie devices */
|
||||
@ -583,7 +583,7 @@ int mio_exec (mio_t* mio)
|
||||
while (mio->hltdev.head)
|
||||
{
|
||||
MIO_DEBUG1 (mio, "Killing HALTED device %p\n", mio->hltdev.head);
|
||||
mio_killdev (mio, mio->hltdev.head);
|
||||
mio_dev_kill (mio->hltdev.head);
|
||||
}
|
||||
|
||||
MIO_ASSERT (mio, mio->hltdev.tail == MIO_NULL);
|
||||
@ -775,9 +775,9 @@ static int schedule_kill_zombie_job (mio_dev_t* dev)
|
||||
return mio_instmrjob (mio, &kill_zombie_job) == MIO_TMRIDX_INVALID? -1: 0;
|
||||
}
|
||||
|
||||
void mio_killdev (mio_t* mio, mio_dev_t* dev)
|
||||
void mio_dev_kill (mio_dev_t* dev)
|
||||
{
|
||||
MIO_ASSERT (mio, mio == dev->mio);
|
||||
mio_t* mio = dev->mio;
|
||||
|
||||
if (dev->dev_cap & MIO_DEV_CAP_ZOMBIE)
|
||||
{
|
||||
@ -841,7 +841,7 @@ kill_device:
|
||||
MIO_ASSERT (mio, dev->dev_cap & MIO_DEV_CAP_ZOMBIE);
|
||||
if (schedule_kill_zombie_job (dev) <= -1)
|
||||
{
|
||||
/* i have to choice but to free up the devide by force */
|
||||
/* i have no choice but to free up the devide by force */
|
||||
while (kill_and_free_device (dev, 1) <= -1)
|
||||
{
|
||||
if (mio->stopreq != MIO_STOPREQ_NONE)
|
||||
|
@ -160,7 +160,7 @@ struct mio_dev_mth_t
|
||||
int (*make) (mio_dev_t* dev, void* ctx);
|
||||
|
||||
/* ------------------------------------------------------------------ */
|
||||
/* mandatory. called in mio_killdev(). also called in mio_makedev() upon
|
||||
/* mandatory. called in mio_dev_kill(). also called in mio_makedev() upon
|
||||
* failure after make() success.
|
||||
*
|
||||
* when 'force' is 0, the return value of -1 causes the device to be a
|
||||
@ -688,8 +688,7 @@ MIO_EXPORT mio_dev_t* mio_makedev (
|
||||
void* make_ctx
|
||||
);
|
||||
|
||||
MIO_EXPORT void mio_killdev (
|
||||
mio_t* mio,
|
||||
MIO_EXPORT void mio_dev_kill (
|
||||
mio_dev_t* dev
|
||||
);
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user