//DNSRecordRef returned by DNSServiceRegisterRecord or DNSServiceAddRecord
DNSServiceErrorType DNSSD_API DNSServiceUpdateRecord
    (
    DNSServiceRef    sdRef,
    DNSRecordRef     RecordRef,
    DNSServiceFlags  flags,
    uint16_t         rdlen,
    const void      *rdata,
    uint32_t         ttl
    )
    {
    ipc_msg_hdr *hdr;
    size_t len = 0;
    char *ptr;

	if (!sdRef) return kDNSServiceErr_BadReference;

    len += sizeof(uint16_t);
    len += rdlen;
    len += sizeof(uint32_t);
    len += sizeof(DNSServiceFlags);

    hdr = create_hdr(update_record_request, &len, &ptr, 0);
    if (!hdr) return kDNSServiceErr_Unknown;
    hdr->reg_index = RecordRef ? RecordRef->record_index : TXT_RECORD_INDEX;
    put_flags(flags, &ptr);
    put_short(rdlen, &ptr);
    put_rdata(rdlen, rdata, &ptr);
    put_long(ttl, &ptr);
    return deliver_request((char *)hdr, sdRef, 0);
    }
DNSServiceErrorType DNSSD_API DNSServiceQueryRecord
    (
    DNSServiceRef              *sdRef,
    DNSServiceFlags             flags,
    uint32_t                    interfaceIndex,
    const char                 *name,
    uint16_t                    rrtype,
    uint16_t                    rrclass,
    DNSServiceQueryRecordReply  callBack,
    void                       *context
    )
    {
    char *msg = NULL, *ptr;
    size_t len;
    ipc_msg_hdr *hdr;
    DNSServiceRef sdr;
    DNSServiceErrorType err;

    if (!sdRef) return kDNSServiceErr_BadParam;
    *sdRef = NULL;

    if (!name) name = "\0";

    // calculate total message length
    len = sizeof(flags);
    len += sizeof(uint32_t);  //interfaceIndex
    len += strlen(name) + 1;
    len += 2 * sizeof(uint16_t);  // rrtype, rrclass

    hdr = create_hdr(query_request, &len, &ptr, 1);
    if (!hdr) goto error;
    msg = (void *)hdr;

    put_flags(flags, &ptr);
    put_long(interfaceIndex, &ptr);
    put_string(name, &ptr);
    put_short(rrtype, &ptr);
    put_short(rrclass, &ptr);

    sdr = connect_to_server();
    if (!sdr) goto error;
    err = deliver_request(msg, sdr, 1);
    if (err)
        {
        DNSServiceRefDeallocate(sdr);
        return err;
        }

    sdr->op = query_request;
    sdr->process_reply = handle_query_response;
    sdr->app_callback = callBack;
    sdr->app_context = context;
    *sdRef = sdr;
    return err;

error:
    if (msg) free(msg);
    if (*sdRef) { free(*sdRef);  *sdRef = NULL; }
    return kDNSServiceErr_Unknown;
    }
Ejemplo n.º 3
0
Archivo: vm.c Proyecto: Hooman3/minix
static int
vm_mmap_out(struct trace_proc * proc, const message * m_out)
{

	if (m_out->m_mmap.flags & MAP_THIRDPARTY)
		put_endpoint(proc, "forwhom", m_out->m_mmap.forwhom);
	put_ptr(proc, "addr", (vir_bytes)m_out->m_mmap.addr);
	put_value(proc, "len", "%zu", m_out->m_mmap.len);
	put_flags(proc, "prot", mmap_prot, COUNT(mmap_prot), "0x%x",
	    m_out->m_mmap.prot);
	put_flags(proc, "flags", mmap_flags, COUNT(mmap_flags), "0x%x",
	    m_out->m_mmap.flags);
	put_fd(proc, "fd", m_out->m_mmap.fd);
	put_value(proc, "offset", "%"PRId64, m_out->m_mmap.offset);

	return CT_DONE;
}
DNSServiceErrorType DNSSD_API DNSServiceBrowse
	(
	DNSServiceRef         *sdRef,
	DNSServiceFlags        flags,
	uint32_t               interfaceIndex,
	const char            *regtype,
	const char            *domain,
	DNSServiceBrowseReply  callBack,
	void                  *context
	)
    {
    char *msg = NULL, *ptr;
    size_t len;
    ipc_msg_hdr *hdr;
    DNSServiceRef sdr;
    DNSServiceErrorType err;

    if (!sdRef) return kDNSServiceErr_BadParam;
    *sdRef = NULL;

    if (!domain) domain = "";

    len = sizeof(flags);
    len += sizeof(interfaceIndex);
    len += strlen(regtype) + 1;
    len += strlen(domain) + 1;

    hdr = create_hdr(browse_request, &len, &ptr, 1);
    if (!hdr) goto error;
    msg = (char *)hdr;
    put_flags(flags, &ptr);
    put_long(interfaceIndex, &ptr);
    put_string(regtype, &ptr);
    put_string(domain, &ptr);

    sdr = connect_to_server();
    if (!sdr) goto error;
    err = deliver_request(msg, sdr, 1);
    if (err)
        {
        DNSServiceRefDeallocate(sdr);
        return err;
        }
    sdr->op = browse_request;
    sdr->process_reply = handle_browse_response;
    sdr->app_callback = callBack;
    sdr->app_context = context;
    *sdRef = sdr;
    return err;

error:
    if (msg) free(msg);
    if (*sdRef) { free(*sdRef);  *sdRef = NULL; }
    return kDNSServiceErr_Unknown;
    }
DNSServiceErrorType DNSSD_API DNSServiceEnumerateDomains
	(
	DNSServiceRef             *sdRef,
	DNSServiceFlags            flags,
	uint32_t                   interfaceIndex,
	DNSServiceDomainEnumReply  callBack,
	void                      *context
	)
    {
    char *msg = NULL, *ptr;
    size_t len;
    ipc_msg_hdr *hdr;
    DNSServiceRef sdr;
    DNSServiceErrorType err;
    int f1 = (flags & kDNSServiceFlagsBrowseDomains) != 0;
    int f2 = (flags & kDNSServiceFlagsRegistrationDomains) != 0;
    if (f1 + f2 != 1) return kDNSServiceErr_BadParam;

    if (!sdRef) return kDNSServiceErr_BadParam;
    *sdRef = NULL;

	len = sizeof(DNSServiceFlags);
    len += sizeof(uint32_t);

    hdr = create_hdr(enumeration_request, &len, &ptr, 1);
    if (!hdr) goto error;
    msg = (void *)hdr;

    put_flags(flags, &ptr);
    put_long(interfaceIndex, &ptr);

    sdr = connect_to_server();
    if (!sdr) goto error;
    err = deliver_request(msg, sdr, 1);
    if (err)
        {
        DNSServiceRefDeallocate(sdr);
        return err;
        }

    sdr->op = enumeration_request;
    sdr->process_reply = handle_enumeration_response;
    sdr->app_callback = callBack;
    sdr->app_context = context;
    *sdRef = sdr;
    return err;

error:
    if (msg) free(msg);
    if (*sdRef) { free(*sdRef);  *sdRef = NULL; }
    return kDNSServiceErr_Unknown;
    }
//sdRef returned by DNSServiceRegister()
DNSServiceErrorType DNSSD_API DNSServiceAddRecord
    (
    DNSServiceRef    sdRef,
    DNSRecordRef    *RecordRef,
    DNSServiceFlags  flags,
    uint16_t         rrtype,
    uint16_t         rdlen,
    const void      *rdata,
    uint32_t         ttl
    )
    {
    ipc_msg_hdr *hdr;
    size_t len = 0;
    char *ptr;
    DNSRecordRef rref;

    if (!sdRef || (sdRef->op != reg_service_request) || !RecordRef)
        return kDNSServiceErr_BadReference;
    *RecordRef = NULL;

    len += 2 * sizeof(uint16_t);  //rrtype, rdlen
    len += rdlen;
    len += sizeof(uint32_t);
    len += sizeof(DNSServiceFlags);

    hdr = create_hdr(add_record_request, &len, &ptr, 0);
    if (!hdr) return kDNSServiceErr_Unknown;
    put_flags(flags, &ptr);
    put_short(rrtype, &ptr);
    put_short(rdlen, &ptr);
    put_rdata(rdlen, rdata, &ptr);
    put_long(ttl, &ptr);

    rref = malloc(sizeof(_DNSRecordRef_t));
    if (!rref) goto error;
    rref->app_context = NULL;
    rref->app_callback = NULL;
    rref->record_index = sdRef->max_index++;
    rref->sdr = sdRef;
    *RecordRef = rref;
    hdr->client_context.context = rref;
    hdr->reg_index = rref->record_index;
    return deliver_request((char *)hdr, sdRef, 0);

error:
    if (hdr) free(hdr);
    if (rref) free(rref);
    if (*RecordRef) *RecordRef = NULL;
    return kDNSServiceErr_Unknown;
}
DNSServiceErrorType DNSSD_API DNSServiceSetDefaultDomainForUser
	(
	DNSServiceFlags  flags,
	const char      *domain
	)
    {
    DNSServiceRef sdr;
    DNSServiceErrorType err;
    char *ptr = NULL;
    size_t len = sizeof(flags) + strlen(domain) + 1;
    ipc_msg_hdr *hdr = create_hdr(setdomain_request, &len, &ptr, 1);

    if (!hdr) return kDNSServiceErr_Unknown;
    put_flags(flags, &ptr);
    put_string(domain, &ptr);

    sdr = connect_to_server();
    if (!sdr) { free(hdr); return kDNSServiceErr_Unknown; }
    err = deliver_request((char *)hdr, sdr, 1); // deliver_request frees the message for us
	DNSServiceRefDeallocate(sdr);
	return err;
    }
DNSServiceErrorType DNSSD_API DNSServiceReconfirmRecord
	(
	DNSServiceFlags  flags,
	uint32_t         interfaceIndex,
	const char      *fullname,
	uint16_t         rrtype,
	uint16_t         rrclass,
	uint16_t         rdlen,
	const void      *rdata
	)
    {
    char *ptr;
    size_t len;
    ipc_msg_hdr *hdr;
    DNSServiceRef tmp;

    len = sizeof(DNSServiceFlags);
    len += sizeof(uint32_t);
    len += strlen(fullname) + 1;
    len += 3 * sizeof(uint16_t);
    len += rdlen;
    tmp = connect_to_server();
    if (!tmp) return(kDNSServiceErr_Unknown);
    hdr = create_hdr(reconfirm_record_request, &len, &ptr, 1);
    if (!hdr) return(kDNSServiceErr_Unknown);

    put_flags(flags, &ptr);
    put_long(interfaceIndex, &ptr);
    put_string(fullname, &ptr);
    put_short(rrtype, &ptr);
    put_short(rrclass, &ptr);
    put_short(rdlen, &ptr);
    put_rdata(rdlen, rdata, &ptr);
	ConvertHeaderBytes(hdr);
    write_all(tmp->sockfd, (char *)hdr, (int) len);
    free(hdr);
    DNSServiceRefDeallocate(tmp);
    return(kDNSServiceErr_NoError);
    }
DNSServiceErrorType DNSSD_API DNSServiceRemoveRecord
	(
	DNSServiceRef    sdRef,
	DNSRecordRef     RecordRef,
	DNSServiceFlags  flags
	)
    {
    ipc_msg_hdr *hdr;
    size_t len = 0;
    char *ptr;
    DNSServiceErrorType err;

    if (!sdRef || !RecordRef || !sdRef->max_index)
        return kDNSServiceErr_BadReference;

    len += sizeof(flags);
    hdr = create_hdr(remove_record_request, &len, &ptr, 0);
    if (!hdr) return kDNSServiceErr_Unknown;
    hdr->reg_index = RecordRef->record_index;
    put_flags(flags, &ptr);
    err = deliver_request((char *)hdr, sdRef, 0);
    if (!err) free(RecordRef);
    return err;
    }
Ejemplo n.º 10
0
static void
put_struct_rs_start(struct trace_proc * proc, const char * name,
                    vir_bytes addr)
{
    struct rs_start buf;

    if (!put_open_struct(proc, name, 0, addr, &buf, sizeof(buf)))
        return;

    if (verbose > 0)
        put_flags(proc, "rss_flags", rss_flags, COUNT(rss_flags),
                  "0x%x", buf.rss_flags);
    put_buf(proc, "rss_cmd", 0, (vir_bytes)buf.rss_cmd, buf.rss_cmdlen);
    put_buf(proc, "rss_label", 0, (vir_bytes)buf.rss_label.l_addr,
            buf.rss_label.l_len);
    if (verbose > 0 || buf.rss_major != 0)
        put_value(proc, "rss_major", "%d", buf.rss_major);
    if (verbose > 0 || buf.devman_id != 0)
        put_value(proc, "devman_id", "%d", buf.devman_id);
    put_value(proc, "rss_uid", "%u", buf.rss_uid);
    if (verbose > 0) {
        put_endpoint(proc, "rss_sigmgr", buf.rss_sigmgr);
        put_endpoint(proc, "rss_scheduler", buf.rss_sigmgr);
    }
    if (verbose > 1) {
        put_value(proc, "rss_priority", "%d", buf.rss_priority);
        put_value(proc, "rss_quantum", "%d", buf.rss_quantum);
    }
    if (verbose > 0) {
        put_value(proc, "rss_period", "%ld", buf.rss_period);
        put_buf(proc, "rss_script", 0, (vir_bytes)buf.rss_script,
                buf.rss_scriptlen);
    }

    put_close_struct(proc, FALSE /*all*/); /* TODO: the remaining fields */
}
int
char_ioctl_arg(struct trace_proc * proc, unsigned long req, void * ptr,
	int dir)
{
	minix_i2c_ioctl_exec_t *iie;
	struct fb_var_screeninfo *fbvs;
	struct volume_level *level;
	struct inout_ctrl *inout;
	struct termios *tc;
	struct ptmget *pm;
	struct winsize *ws;
	struct kio_bell *bell;
	struct kio_leds *leds;
	struct pciio_cfgreg *pci_cfgreg;
	struct pciio_bdf_cfgreg *pci_bdf_cfgreg;
	struct pciio_businfo *pci_businfo;
	struct pciio_map *pci_iomap;
	struct pciio_acl *pci_acl;

	switch (req) {
	case MINIX_I2C_IOCTL_EXEC:
		if ((iie = (minix_i2c_ioctl_exec_t *)ptr) == NULL)
			return IF_OUT; /* we print only the request for now */

		put_i2c_op(proc, "iie_op", iie->iie_op);
		put_value(proc, "iie_addr", "0x%04x", iie->iie_addr);
		return 0; /* TODO: print command/data/result */

	case FBIOGET_VSCREENINFO:
		if ((fbvs = (struct fb_var_screeninfo *)ptr) == NULL)
			return IF_IN;

		put_value(proc, "xres", "%"PRIu32, fbvs->xres);
		put_value(proc, "yres", "%"PRIu32, fbvs->yres);
		put_value(proc, "xres_virtual", "%"PRIu32, fbvs->xres_virtual);
		put_value(proc, "yres_virtual", "%"PRIu32, fbvs->yres_virtual);
		put_value(proc, "xoffset", "%"PRIu32, fbvs->xoffset);
		put_value(proc, "yoffset", "%"PRIu32, fbvs->yoffset);
		put_value(proc, "bits_per_pixel", "%"PRIu32,
		    fbvs->bits_per_pixel);
		return 0;

	case FBIOPUT_VSCREENINFO:
	case FBIOPAN_DISPLAY:
		if ((fbvs = (struct fb_var_screeninfo *)ptr) == NULL)
			return IF_OUT;

		put_value(proc, "xoffset", "%"PRIu32, fbvs->xoffset);
		put_value(proc, "yoffset", "%"PRIu32, fbvs->yoffset);
		return 0;

	case DSPIORATE:
	case DSPIOSTEREO:
	case DSPIOSIZE:
	case DSPIOBITS:
	case DSPIOSIGN:
	case DSPIOMAX:
	case DSPIOFREEBUF:
	case DSPIOSAMPLESINBUF:
		if (ptr == NULL)
			return dir;

		put_value(proc, NULL, "%u", *(unsigned int *)ptr);
		return IF_ALL;

	case MIXIOGETVOLUME:
		if ((level = (struct volume_level *)ptr) == NULL)
			return dir;

		if (dir == IF_OUT)
			put_sound_device(proc, "device", level->device);
		else {
			put_value(proc, "left", "%d", level->left);
			put_value(proc, "right", "%d", level->right);
		}
		return IF_ALL;

	case MIXIOSETVOLUME:
		/* Print the corrected volume levels only with verbosity on. */
		if ((level = (struct volume_level *)ptr) == NULL)
			return IF_OUT | ((verbose > 0) ? IF_IN : 0);

		if (dir == IF_OUT)
			put_sound_device(proc, "device", level->device);
		put_value(proc, "left", "%d", level->left);
		put_value(proc, "right", "%d", level->right);
		return IF_ALL;

	case MIXIOGETINPUTLEFT:
	case MIXIOGETINPUTRIGHT:
	case MIXIOGETOUTPUT:
		if ((inout = (struct inout_ctrl *)ptr) == NULL)
			return dir;

		if (dir == IF_OUT)
			put_sound_device(proc, "device", inout->device);
		else {
			put_sound_state(proc, "left", inout->left);
			put_sound_state(proc, "right", inout->right);
		}
		return IF_ALL;

	case MIXIOSETINPUTLEFT:
	case MIXIOSETINPUTRIGHT:
	case MIXIOSETOUTPUT:
		if ((inout = (struct inout_ctrl *)ptr) == NULL)
			return IF_OUT;

		put_sound_device(proc, "device", inout->device);
		put_sound_state(proc, "left", inout->left);
		put_sound_state(proc, "right", inout->right);
		return IF_ALL;

	case TIOCFLUSH:
		if (ptr == NULL)
			return IF_OUT;

		put_flags(proc, NULL, flush_flags, COUNT(flush_flags), "0x%x",
		    *(int *)ptr);
		return IF_ALL;

	case TIOCGETA:
	case TIOCSETA:
	case TIOCSETAW:
	case TIOCSETAF:
		if ((tc = (struct termios *)ptr) == NULL)
			return dir;

		/*
		 * These are fairly common IOCTLs, so printing everything by
		 * default would create a lot of noise.  By default we limit
		 * ourselves to printing the field that contains what I
		 * consider to be the most important flag: ICANON.
		 * TODO: see if we can come up with a decent format for
		 * selectively printing (relatively important) flags.
		 */
		if (verbose > 0) {
			put_flags(proc, "c_iflag", tc_iflags, COUNT(tc_iflags),
			    "0x%x", tc->c_iflag);
			put_flags(proc, "c_oflag", tc_oflags, COUNT(tc_oflags),
			    "0x%x", tc->c_oflag);
			put_flags(proc, "c_cflag", tc_cflags, COUNT(tc_cflags),
			    "0x%x", tc->c_cflag);
		}
		put_flags(proc, "c_lflag", tc_lflags, COUNT(tc_lflags), "0x%x",
			tc->c_lflag);
		if (verbose > 0) {
			put_value(proc, "c_ispeed", "%d", tc->c_ispeed);
			put_value(proc, "c_ospeed", "%d", tc->c_ospeed);
		}
		return 0; /* TODO: print the c_cc fields */

	case TIOCGETD:
	case TIOCSETD:
		if (ptr == NULL)
			return dir;

		put_tty_disc(proc, NULL, *(int *)ptr);
		return IF_ALL;

	case TIOCGLINED:
	case TIOCSLINED:
		if (ptr == NULL)
			return dir;

		put_buf(proc, NULL, PF_LOCADDR | PF_STRING, (vir_bytes)ptr,
		    sizeof(linedn_t));
		return IF_ALL;

	case TIOCGPGRP:
	case TIOCSPGRP:
	case TIOCOUTQ:
	case TIOCPKT:
	case TIOCREMOTE:
	case TIOCUCNTL:
	case TIOCSTAT:		/* argument seems unused? */
	case TIOCGSID:
	case TIOCCONS:		/* argument seems unused? */
	case TIOCEXT:
	case TIOCSQSIZE:
	case TIOCGQSIZE:
		/* Print a simple integer. */
		if (ptr == NULL)
			return dir;

		put_value(proc, NULL, "%d", *(int *)ptr);
		return IF_ALL;

	case TIOCPTSNAME:
		if ((pm = (struct ptmget *)ptr) == NULL)
			return IF_IN;

		put_buf(proc, "sn", PF_LOCADDR | PF_STRING, (vir_bytes)pm->sn,
		    sizeof(pm->sn));
		return IF_ALL;

	case TIOCSTI:
		if (ptr == NULL)
			return dir;

		if (!valuesonly)
			put_value(proc, NULL, "'%s'",
			    get_escape(*(char *)ptr));
		else
			put_value(proc, NULL, "%u", *(char *)ptr);
		return IF_ALL;

	case TIOCGWINSZ:
	case TIOCSWINSZ:
		if ((ws = (struct winsize *)ptr) == NULL)
			return dir;

		/* This is a stupid order, but we follow the struct layout. */
		put_value(proc, "ws_row", "%u", ws->ws_row);
		put_value(proc, "ws_col", "%u", ws->ws_col);
		if (verbose > 0) {
			put_value(proc, "ws_xpixel", "%u", ws->ws_xpixel);
			put_value(proc, "ws_ypixel", "%u", ws->ws_ypixel);
		}
		return (verbose > 0) ? IF_ALL : 0;

	case KIOCBELL:
		if ((bell = (struct kio_bell *)ptr) == NULL)
			return IF_OUT;

		put_value(proc, "kb_pitch", "%u", bell->kb_pitch);
		put_value(proc, "kb_volume", "%lu", bell->kb_volume);
		put_struct_timeval(proc, "kb_duration", PF_LOCADDR,
		    (vir_bytes)&bell->kb_duration);

		return IF_ALL;

	case KIOCSLEDS:
		if ((leds = (struct kio_leds *)ptr) == NULL)
			return IF_OUT;

		put_flags(proc, "kl_bits", kbd_leds, COUNT(kbd_leds), "0x%x",
		    leds->kl_bits);
		return IF_ALL;

	case PCI_IOC_CFGREAD:
		if ((pci_cfgreg = (struct pciio_cfgreg *)ptr) == NULL)
			return IF_IN;

		put_ptr(proc, "reg", (vir_bytes)pci_cfgreg->reg);
		put_value(proc, "val", "%08x", pci_cfgreg->val);
		return IF_ALL;

	case PCI_IOC_CFGWRITE:
		if ((pci_cfgreg = (struct pciio_cfgreg *)ptr) == NULL)
			return IF_OUT;

		put_ptr(proc, "reg", (vir_bytes)pci_cfgreg->reg);
		put_value(proc, "val", "%08x", pci_cfgreg->val);
		return IF_ALL;

	case PCI_IOC_BDF_CFGREAD:
		if ((pci_bdf_cfgreg = (struct pciio_bdf_cfgreg *)ptr) == NULL)
			return IF_IN;

		put_value(proc, "bus", "%u", pci_bdf_cfgreg->bus);
		put_value(proc, "device", "%u", pci_bdf_cfgreg->device);
		put_value(proc, "function", "%u", pci_bdf_cfgreg->function);
		put_ptr(proc, "cfgreg.reg", (vir_bytes)pci_bdf_cfgreg->cfgreg.reg);
		put_value(proc, "cfgreg.val", "%08x", pci_bdf_cfgreg->cfgreg.val);
		return IF_ALL;

	case PCI_IOC_BDF_CFGWRITE:
		if ((pci_bdf_cfgreg = (struct pciio_bdf_cfgreg *)ptr) == NULL)
			return IF_OUT;

		put_value(proc, "bus", "%u", pci_bdf_cfgreg->bus);
		put_value(proc, "device", "%u", pci_bdf_cfgreg->device);
		put_value(proc, "function", "%u", pci_bdf_cfgreg->function);
		put_ptr(proc, "cfgreg.reg", (vir_bytes)pci_bdf_cfgreg->cfgreg.reg);
		put_value(proc, "cfgreg.val", "%08x", pci_bdf_cfgreg->cfgreg.val);
		return IF_ALL;

	case PCI_IOC_BUSINFO:
		if ((pci_businfo = (struct pciio_businfo *)ptr) == NULL)
			return IF_IN;

		put_value(proc, "busno", "%u", pci_businfo->busno);
		put_value(proc, "maxdevs", "%u", pci_businfo->maxdevs);
		return IF_ALL;

	case PCI_IOC_MAP:
		if ((pci_iomap = (struct pciio_map *)ptr) == NULL)
			return IF_OUT|IF_IN;

		put_value(proc, "flags", "%x", pci_iomap->flags);
		put_value(proc, "phys_offset", "%08x", pci_iomap->phys_offset);
		put_value(proc, "size", "%zu", pci_iomap->size);
		put_value(proc, "readonly", "%x", pci_iomap->readonly);

		if (IF_IN == dir)
			put_ptr(proc, "vaddr_ret", (vir_bytes)pci_iomap->vaddr_ret);

		return IF_ALL;

	case PCI_IOC_UNMAP:
		if ((pci_iomap = (struct pciio_map *)ptr) == NULL)
			return IF_OUT;

		put_ptr(proc, "vaddr", (vir_bytes)pci_iomap->vaddr);

		return IF_ALL;

	case PCI_IOC_RESERVE:
		if ((pci_acl = (struct pciio_acl *)ptr) == NULL)
			return IF_OUT;

		put_value(proc, "domain", "%u", pci_acl->domain);
		put_value(proc, "bus", "%u", pci_acl->bus);
		put_value(proc, "device", "%u", pci_acl->device);
		put_value(proc, "function", "%u", pci_acl->function);

		return IF_ALL;
	case PCI_IOC_RELEASE:
		if ((pci_acl = (struct pciio_acl *)ptr) == NULL)
			return IF_OUT;

		put_value(proc, "domain", "%u", pci_acl->domain);
		put_value(proc, "bus", "%u", pci_acl->bus);
		put_value(proc, "device", "%u", pci_acl->device);
		put_value(proc, "function", "%u", pci_acl->function);

		return IF_ALL;

	default:
		return 0;
	}
}
DNSServiceErrorType DNSSD_API DNSServiceRegister
    (
    DNSServiceRef                       *sdRef,
    DNSServiceFlags                     flags,
    uint32_t                            interfaceIndex,
    const char                          *name,
    const char                          *regtype,
    const char                          *domain,
    const char                          *host,
    uint16_t                            PortInNetworkByteOrder,
    uint16_t                            txtLen,
    const void                          *txtRecord,
    DNSServiceRegisterReply             callBack,
    void                                *context
    )
    {
    char *msg = NULL, *ptr;
    size_t len;
    ipc_msg_hdr *hdr;
    DNSServiceRef sdr;
    DNSServiceErrorType err;
    union { uint16_t s; u_char b[2]; } port = { PortInNetworkByteOrder };

    if (!sdRef) return kDNSServiceErr_BadParam;
    *sdRef = NULL;

    if (!name) name = "";
    if (!regtype) return kDNSServiceErr_BadParam;
    if (!domain) domain = "";
    if (!host) host = "";
    if (!txtRecord) txtRecord = (void*)"";

    // auto-name must also have auto-rename
    if (!name[0]  && (flags & kDNSServiceFlagsNoAutoRename))
        return kDNSServiceErr_BadParam;

    // no callback must have auto-rename
    if (!callBack && (flags & kDNSServiceFlagsNoAutoRename)) return kDNSServiceErr_BadParam;

    len = sizeof(DNSServiceFlags);
    len += sizeof(uint32_t);  // interfaceIndex
    len += strlen(name) + strlen(regtype) + strlen(domain) + strlen(host) + 4;
    len += 2 * sizeof(uint16_t);  // port, txtLen
    len += txtLen;

    hdr = create_hdr(reg_service_request, &len, &ptr, 1);
    if (!hdr) goto error;
    if (!callBack) hdr->flags |= IPC_FLAGS_NOREPLY;
    msg = (char *)hdr;
    put_flags(flags, &ptr);
    put_long(interfaceIndex, &ptr);
    put_string(name, &ptr);
    put_string(regtype, &ptr);
    put_string(domain, &ptr);
    put_string(host, &ptr);
    *ptr++ = port.b[0];
    *ptr++ = port.b[1];
    put_short(txtLen, &ptr);
    put_rdata(txtLen, txtRecord, &ptr);

    sdr = connect_to_server();
    if (!sdr) goto error;
    err = deliver_request(msg, sdr, 1);
    if (err)
        {
        DNSServiceRefDeallocate(sdr);
        return err;
        }

    sdr->op = reg_service_request;
    sdr->process_reply = callBack ? handle_regservice_response : NULL;
    sdr->app_callback = callBack;
    sdr->app_context = context;
    *sdRef = sdr;

    return err;

error:
    if (msg) free(msg);
    if (*sdRef) 	{ free(*sdRef);  *sdRef = NULL; }
    return kDNSServiceErr_Unknown;
    }
DNSServiceErrorType DNSSD_API DNSServiceRegisterRecord
    (
    DNSServiceRef                  sdRef,
    DNSRecordRef                  *RecordRef,
    DNSServiceFlags                flags,
    uint32_t                       interfaceIndex,
    const char                    *fullname,
    uint16_t                       rrtype,
    uint16_t                       rrclass,
    uint16_t                       rdlen,
    const void                    *rdata,
    uint32_t                       ttl,
    DNSServiceRegisterRecordReply  callBack,
    void                          *context
    )
    {
    char *msg = NULL, *ptr;
    size_t len;
    ipc_msg_hdr *hdr = NULL;
    DNSServiceRef tmp = NULL;
    DNSRecordRef rref = NULL;
    int f1 = (flags & kDNSServiceFlagsShared) != 0;
    int f2 = (flags & kDNSServiceFlagsUnique) != 0;
    if (f1 + f2 != 1) return kDNSServiceErr_BadParam;

    if (!sdRef || sdRef->op != connection || sdRef->sockfd < 0)
        return kDNSServiceErr_BadReference;
    *RecordRef = NULL;

	len = sizeof(DNSServiceFlags);
    len += 2 * sizeof(uint32_t);  // interfaceIndex, ttl
    len += 3 * sizeof(uint16_t);  // rrtype, rrclass, rdlen
    len += strlen(fullname) + 1;
    len += rdlen;

    hdr = create_hdr(reg_record_request, &len, &ptr, 0);
    if (!hdr) goto error;
    msg = (char *)hdr;
    put_flags(flags, &ptr);
    put_long(interfaceIndex, &ptr);
    put_string(fullname, &ptr);
    put_short(rrtype, &ptr);
    put_short(rrclass, &ptr);
    put_short(rdlen, &ptr);
    put_rdata(rdlen, rdata, &ptr);
    put_long(ttl, &ptr);

    rref = malloc(sizeof(_DNSRecordRef_t));
    if (!rref) goto error;
    rref->app_context = context;
    rref->app_callback = callBack;
    rref->record_index = sdRef->max_index++;
    rref->sdr = sdRef;
    *RecordRef = rref;
    hdr->client_context.context = rref;
    hdr->reg_index = rref->record_index;

    return deliver_request(msg, sdRef, 0);

error:
    if (rref) free(rref);
    if (tmp) free(tmp);
    if (hdr) free(hdr);
    return kDNSServiceErr_Unknown;
    }
Ejemplo n.º 14
0
int
block_ioctl_arg(struct trace_proc * proc, unsigned long req, void * ptr,
	int dir)
{
	struct part_geom *part;
	struct fbd_rule *rule;
	struct vnd_ioctl *vnd;
	struct vnd_user *vnu;
	int i;

	switch (req) {
	case BIOCTRACEBUF:
		if (ptr == NULL)
			return IF_OUT;

		put_value(proc, NULL, "%zu", *(size_t *)ptr);
		return IF_ALL;

	case BIOCTRACECTL:
		if (ptr == NULL)
			return IF_OUT;

		i = *(int *)ptr;
		if (!valuesonly && i == BTCTL_START)
			put_field(proc, NULL, "BTCTL_START");
		else if (!valuesonly && i == BTCTL_STOP)
			put_field(proc, NULL, "BTCTL_STOP");
		else
			put_value(proc, NULL, "%d", i);
		return IF_ALL;

	case DIOCSETP:
		if ((part = (struct part_geom *)ptr) == NULL)
			return IF_OUT;

		put_value(proc, "base", "%"PRIu64, part->base);
		put_value(proc, "size", "%"PRIu64, part->size);
		return IF_ALL;

	case DIOCGETP:
		if ((part = (struct part_geom *)ptr) == NULL)
			return IF_IN;

		put_value(proc, "base", "%"PRIu64, part->base);
		put_value(proc, "size", "%"PRIu64, part->size);
		if (verbose > 0) {
			put_value(proc, "cylinders", "%u", part->cylinders);
			put_value(proc, "heads", "%u", part->heads);
			put_value(proc, "sectors", "%u", part->sectors);
			return IF_ALL;
		} else
			return 0;

	case DIOCTIMEOUT:
		/* Print the old timeout only if verbosity is high enough. */
		if (ptr == NULL)
			return IF_OUT | ((verbose > 0) ? IF_IN : 0);

		/* Same action for out and in. */
		put_value(proc, NULL, "%d", *(int *)ptr);
		return IF_ALL;

	case DIOCOPENCT:
		if (ptr == NULL)
			return IF_IN;

		put_value(proc, NULL, "%d", *(int *)ptr);
		return IF_ALL;

	case DIOCSETWC:
	case DIOCGETWC:
		if (ptr == NULL)
			return dir; /* out or in, depending on the request */

		put_value(proc, NULL, "%d", *(int *)ptr);
		return IF_ALL;

	case FBDCDELRULE:
		if (ptr == NULL)
			return IF_OUT;

		put_value(proc, NULL, "%d", *(fbd_rulenum_t *)ptr);
		return IF_ALL;

	case FBDCGETRULE:
		if ((rule = (struct fbd_rule *)ptr) == NULL)
			return IF_OUT | IF_IN;

		if (dir == IF_OUT) {
			put_value(proc, "num", "%d", rule->num);
			return IF_ALL;
		}

		/*
		 * The returned result is the same as what is passed to the
		 * add request, so we can use the same code to print both.
		 */
		/* FALLTHROUGH */
	case FBDCADDRULE:
		if ((rule = (struct fbd_rule *)ptr) == NULL)
			return IF_OUT;

		if (rule->start != 0 || rule->end != 0 || verbose > 0) {
			put_value(proc, "start", "%"PRIu64, rule->start);
			put_value(proc, "end", "%"PRIu64, rule->end);
		}
		if (rule->flags != (FBD_FLAG_READ | FBD_FLAG_WRITE) ||
		    verbose > 0)
			put_flags(proc, "flags", fbd_flags, COUNT(fbd_flags),
			    "0x%x", rule->flags);
		if (rule->skip != 0 || verbose > 0)
			put_value(proc, "skip", "%u", rule->skip);
		if (rule->count != 0 || verbose > 0)
			put_value(proc, "count", "%u", rule->count);
		put_fbd_action(proc, "action", rule->action);

		return 0; /* TODO: optionally print the union fields */

	case MIOCRAMSIZE:
		if (ptr == NULL)
			return IF_OUT;

		put_value(proc, NULL, "%"PRIu32, *(u32_t *)ptr);
		return IF_ALL;

	case VNDIOCSET:
		if ((vnd = (struct vnd_ioctl *)ptr) == NULL)
			return IF_OUT | IF_IN;

		if (dir == IF_OUT) {
			put_value(proc, "vnd_fildes", "%d", vnd->vnd_fildes);
			put_flags(proc, "vnd_flags", vnd_flags,
			    COUNT(vnd_flags), "0x%x", vnd->vnd_flags);
			return 0; /* TODO: print geometry if given */
		} else {
			put_value(proc, "vnd_size", "%"PRIu64, vnd->vnd_size);
			return IF_ALL;
		}

	case VNDIOCCLR:
		if ((vnd = (struct vnd_ioctl *)ptr) == NULL)
			return IF_OUT;

		put_flags(proc, "vnd_flags", vnd_flags, COUNT(vnd_flags),
		    "0x%x", vnd->vnd_flags);
		return IF_ALL;

	case VNDIOCGET:
		if ((vnu = (struct vnd_user *)ptr) == NULL)
			return IF_IN;

		put_value(proc, "vnu_unit", "%d", vnu->vnu_unit);
		put_dev(proc, "vnu_dev", vnu->vnu_dev);
		put_value(proc, "vnu_ino", "%"PRId64, vnu->vnu_ino);
		return IF_ALL;

	default:
		return 0;
	}
}