Esempio n. 1
0
static VALUE
dnssd_service_browse(VALUE self, VALUE _flags, VALUE _iface, VALUE _type,
    VALUE _domain) {
  const char *type;
  const char *domain = NULL;
  DNSServiceFlags flags = 0;
  uint32_t iface = 0;

  DNSServiceErrorType e;
  DNSServiceRef *client;

  dnssd_utf8_cstr(_type, type);

  if (!NIL_P(_domain))
    dnssd_utf8_cstr(_domain, domain);

  if (!NIL_P(_flags))
    flags = (DNSServiceFlags)NUM2ULONG(_flags);

  if (!NIL_P(_iface))
    iface = (uint32_t)NUM2ULONG(_iface);

  get(cDNSSDService, self, DNSServiceRef, client);

  e = DNSServiceBrowse(client, flags, iface, type, domain,
      dnssd_service_browse_reply, (void *)self);

  dnssd_check_error_code(e);

  return self;
}
Esempio n. 2
0
static VALUE
dnssd_service_resolve(VALUE self, VALUE _flags, VALUE _interface, VALUE _name,
    VALUE _type, VALUE _domain) {
  const char *name, *type, *domain;
  DNSServiceFlags flags = 0;
  uint32_t interface = 0;

  DNSServiceErrorType e;
  DNSServiceRef *client;

  dnssd_utf8_cstr(_name, name);
  dnssd_utf8_cstr(_type, type);
  dnssd_utf8_cstr(_domain, domain);

  if (!NIL_P(_flags))
    flags = (uint32_t)NUM2ULONG(_flags);

  if (!NIL_P(_interface))
    interface = (uint32_t)NUM2ULONG(_interface);

  get(cDNSSDService, self, DNSServiceRef, client);

  e = DNSServiceResolve(client, flags, interface, name, type, domain,
      dnssd_service_resolve_reply, (void *)self);

  dnssd_check_error_code(e);

  return self;
}
Esempio n. 3
0
static VALUE
dnssd_service_s_fullname(VALUE klass, VALUE _name, VALUE _type, VALUE _domain) {
  char * name, * type, * domain;

  dnssd_utf8_cstr(_name, name);
  dnssd_utf8_cstr(_type, type);
  dnssd_utf8_cstr(_domain, domain);

  return create_fullname(name, type, domain);
}
Esempio n. 4
0
static VALUE
dnssd_service_register(VALUE self, VALUE _flags, VALUE _interface, VALUE _name,
    VALUE _type, VALUE _domain, VALUE _host, VALUE _port, VALUE _text_record) {
  const char *name, *type, *host = NULL, *domain = NULL;
  uint16_t port;
  uint16_t txt_len = 0;
  char *txt_rec = NULL;
  DNSServiceFlags flags = 0;
  uint32_t interface = 0;
  DNSServiceRegisterReply callback = NULL;

  DNSServiceErrorType e;
  DNSServiceRef *client;

  dnssd_utf8_cstr(_name, name);
  dnssd_utf8_cstr(_type, type);

  if (!NIL_P(_host))
    dnssd_utf8_cstr(_host, host);

  if (!NIL_P(_domain))
    dnssd_utf8_cstr(_domain, domain);

  port = htons((uint16_t)NUM2UINT(_port));

  if (!NIL_P(_text_record)) {
    txt_rec = RSTRING_PTR(_text_record);
    txt_len = RSTRING_LEN(_text_record);
  }

  if (!NIL_P(_flags))
    flags = (DNSServiceFlags)NUM2ULONG(_flags);

  if (!NIL_P(_interface))
    interface = (uint32_t)NUM2ULONG(_interface);

  if (rb_block_given_p())
    callback = dnssd_service_register_reply;

  get(cDNSSDService, self, DNSServiceRef, client);

  e = DNSServiceRegister(client, flags, interface, name, type,
      domain, host, port, txt_len, txt_rec, callback, (void*)self);

  dnssd_check_error_code(e);

  return self;
}
Esempio n. 5
0
static VALUE
dnssd_service_query_record(VALUE self, VALUE _flags, VALUE _interface,
    VALUE _fullname, VALUE _rrtype, VALUE _rrclass) {
  DNSServiceRef *client;
  DNSServiceFlags flags;
  DNSServiceErrorType e;
  char *fullname;
  uint32_t interface;
  uint16_t rrtype;
  uint16_t rrclass;

  flags = (DNSServiceFlags)NUM2ULONG(_flags);
  interface = (uint32_t)NUM2ULONG(_interface);
  dnssd_utf8_cstr(_fullname, fullname);
  rrtype = NUM2UINT(_rrtype);
  rrclass = NUM2UINT(_rrclass);

  get(cDNSSDService, self, DNSServiceRef, client);

  e = DNSServiceQueryRecord(client, flags, interface, fullname, rrtype,
      rrclass, dnssd_service_query_record_reply, (void *)self);

  dnssd_check_error_code(e);

  return self;
}
Esempio n. 6
0
static VALUE
dnssd_service_getaddrinfo(VALUE self, VALUE _flags, VALUE _interface,
    VALUE _protocol, VALUE _host) {
  DNSServiceFlags flags = 0;
  uint32_t interface = 0;
  DNSServiceProtocol protocol = 0;
  const char *host;

  DNSServiceErrorType e;
  DNSServiceRef *client;

  dnssd_utf8_cstr(_host, host);

  protocol = (DNSServiceProtocol)NUM2ULONG(_protocol);

  if (!NIL_P(_flags))
    flags = (DNSServiceFlags)NUM2ULONG(_flags);

  if (!NIL_P(_interface))
    interface = (uint32_t)NUM2ULONG(_interface);

  get(cDNSSDService, self, DNSServiceRef, client);

  e = DNSServiceGetAddrInfo(client, flags, interface, protocol, host,
      dnssd_service_getaddrinfo_reply, (void *)self);

  dnssd_check_error_code(e);

  return self;
}
Esempio n. 7
0
/*
 * call-seq:
 *   service.get_property(property)
 *
 * Binding for DNSServiceGetProperty.  The only property currently supported in
 * DNSSD is DaemonVersion
 */
static VALUE
dnssd_service_s_get_property(VALUE klass, VALUE _property) {
  char * property;
  uint32_t result = 0;
  uint32_t size = sizeof(result);
  DNSServiceErrorType e;

  dnssd_utf8_cstr(_property, property);

  e = DNSServiceGetProperty(property, (void *)&result, &size);

  dnssd_check_error_code(e);

  /* as of this writing only a uint32_t will be returned */
  return ULONG2NUM(result);
}