static ArvStream * arv_gv_device_create_stream (ArvDevice *device, ArvStreamCallback callback, void *user_data) { ArvGvDevice *gv_device = ARV_GV_DEVICE (device); ArvGvDeviceIOData *io_data = gv_device->priv->io_data; ArvStream *stream; const guint8 *address_bytes; guint32 stream_port; guint packet_size; guint32 n_stream_channels; GInetAddress *interface_address; GInetAddress *device_address; arv_device_read_register (device, ARV_GVBS_N_STREAM_CHANNELS_OFFSET, &n_stream_channels, NULL); arv_debug_device ("[GvDevice::create_stream] Number of stream channels = %d", n_stream_channels); if (n_stream_channels < 1) return NULL; if (!io_data->is_controller) { arv_warning_device ("[GvDevice::create_stream] Can't create stream without control access"); return NULL; } interface_address = g_inet_socket_address_get_address (G_INET_SOCKET_ADDRESS (io_data->interface_address)); device_address = g_inet_socket_address_get_address (G_INET_SOCKET_ADDRESS (io_data->device_address)); address_bytes = g_inet_address_to_bytes (interface_address); /* On some cameras, the default packet size after reset is incorrect. * So, if the value is obviously incorrect, set it to a default size. */ packet_size = arv_gv_device_get_packet_size (gv_device); if (packet_size <= ARV_GVSP_PACKET_PROTOCOL_OVERHEAD) { arv_gv_device_set_packet_size (gv_device, ARV_GV_DEVICE_GVSP_PACKET_SIZE_DEFAULT); arv_debug_device ("[GvDevice::create_stream] Packet size set to default value (%d)", ARV_GV_DEVICE_GVSP_PACKET_SIZE_DEFAULT); } packet_size = arv_gv_device_get_packet_size (gv_device); arv_debug_device ("[GvDevice::create_stream] Packet size = %d byte(s)", packet_size); stream = arv_gv_stream_new (device_address, 0, callback, user_data, arv_gv_device_get_timestamp_tick_frequency (gv_device), packet_size); stream_port = arv_gv_stream_get_port (ARV_GV_STREAM (stream)); if (!arv_device_write_register (device, ARV_GVBS_STREAM_CHANNEL_0_IP_ADDRESS_OFFSET, g_htonl(*((guint32 *) address_bytes)), NULL) || !arv_device_write_register (device, ARV_GVBS_STREAM_CHANNEL_0_PORT_OFFSET, stream_port, NULL)) { arv_warning_device ("[GvDevice::create_stream] Stream configuration failed"); g_object_unref (stream); return NULL; } arv_debug_device ("[GvDevice::create_stream] Stream port = %d", stream_port); return stream; }
struct node *nodes_getNodeByNetAdr(GInetAddress *addr) { gint i; for(i=0; i<MAX_NODE; i++){ if( nodes[i].free == FALSE && nodes[i].netadr != NULL ){ if( g_inet_address_get_native_size(addr) == g_inet_address_get_native_size(nodes[i].netadr) && memcmp(g_inet_address_to_bytes(addr), g_inet_address_to_bytes(nodes[i].netadr), g_inet_address_get_native_size(addr)) == 0 ){ return &nodes[i]; } } } syslog(LOG_WARNING,"nodes.c: warning: getnodebynetadr: node not found\n"); return NULL; }
/* TODO: Return array of bytes instead? */ static VALUE rg_to_bytes(VALUE self) { gsize size; size = g_inet_address_get_native_size(_SELF(self)); return rb_str_new((const gchar *)g_inet_address_to_bytes(_SELF(self)), size); }
void xdmcp_client_send_request (XDMCPClient *client, guint16 display_number, GInetAddress **addresses, const gchar *authentication_name, const guint8 *authentication_data, guint16 authentication_data_length, gchar **authorization_names, const gchar *mfid) { gsize length = 11 + strlen (authentication_name) + authentication_data_length + strlen (mfid); gsize n_addresses = 0; for (GInetAddress **address = addresses; *address; address++) { gssize native_address_length = g_inet_address_get_native_size (*address); length += 4 + native_address_length; n_addresses++; } gsize n_names = 0; for (gchar **name = authorization_names; *name; name++) { length += 2 + strlen (*name); n_names++; } guint8 buffer[MAXIMUM_REQUEST_LENGTH]; gsize offset = 0; write_card16 (buffer, MAXIMUM_REQUEST_LENGTH, X_BYTE_ORDER_MSB, XDMCP_VERSION, &offset); write_card16 (buffer, MAXIMUM_REQUEST_LENGTH, X_BYTE_ORDER_MSB, XDMCP_Request, &offset); write_card16 (buffer, MAXIMUM_REQUEST_LENGTH, X_BYTE_ORDER_MSB, length, &offset); write_card16 (buffer, MAXIMUM_REQUEST_LENGTH, X_BYTE_ORDER_MSB, display_number, &offset); write_card8 (buffer, MAXIMUM_REQUEST_LENGTH, n_addresses, &offset); for (GInetAddress **address = addresses; *address; address++) write_card16 (buffer, MAXIMUM_REQUEST_LENGTH, X_BYTE_ORDER_MSB, 0, &offset); /* FamilyInternet */ write_card8 (buffer, MAXIMUM_REQUEST_LENGTH, n_addresses, &offset); for (GInetAddress **address = addresses; *address; address++) { gssize native_address_length = g_inet_address_get_native_size (*address); const guint8 *native_address = g_inet_address_to_bytes (*address); write_card16 (buffer, MAXIMUM_REQUEST_LENGTH, X_BYTE_ORDER_MSB, native_address_length, &offset); write_string8 (buffer, MAXIMUM_REQUEST_LENGTH, native_address, native_address_length, &offset); } write_card16 (buffer, MAXIMUM_REQUEST_LENGTH, X_BYTE_ORDER_MSB, strlen (authentication_name), &offset); write_string (buffer, MAXIMUM_REQUEST_LENGTH, authentication_name, &offset); write_card16 (buffer, MAXIMUM_REQUEST_LENGTH, X_BYTE_ORDER_MSB, authentication_data_length, &offset); write_string8 (buffer, MAXIMUM_REQUEST_LENGTH, authentication_data, authentication_data_length, &offset); write_card8 (buffer, MAXIMUM_REQUEST_LENGTH, n_names, &offset); for (gchar **name = authorization_names; *name; name++) { write_card16 (buffer, MAXIMUM_REQUEST_LENGTH, X_BYTE_ORDER_MSB, strlen (*name), &offset); write_string (buffer, MAXIMUM_REQUEST_LENGTH, *name, &offset); } write_card16 (buffer, MAXIMUM_REQUEST_LENGTH, X_BYTE_ORDER_MSB, strlen (mfid), &offset); write_string (buffer, MAXIMUM_REQUEST_LENGTH, mfid, &offset); xdmcp_write (client, buffer, offset); }
void arv_fake_camera_set_inet_address (ArvFakeCamera *camera, GInetAddress *address) { const guint8 *bytes; g_return_if_fail (ARV_IS_FAKE_CAMERA (camera)); g_return_if_fail (G_IS_INET_ADDRESS (address)); g_return_if_fail (g_inet_address_get_family (address) == G_SOCKET_FAMILY_IPV4); bytes = g_inet_address_to_bytes (address); arv_fake_camera_write_memory (camera, ARV_GVBS_CURRENT_IP_ADDRESS_OFFSET, g_inet_address_get_native_size (address), (char *) bytes); }
gint interface_createAddress(struct node *n) //GInetAddress *addr) { GError * e = NULL; GInetAddress *lo = g_inet_address_new_loopback( G_SOCKET_FAMILY_IPV6); GSocketAddress *sa = g_inet_socket_address_new( lo, 42); GSocket *s = n->ubnetd; if( s != NULL ){ g_socket_close(s,NULL); g_object_unref(s); } s = g_socket_new(G_SOCKET_FAMILY_IPV6, G_SOCKET_TYPE_STREAM, G_SOCKET_PROTOCOL_TCP, &e); if( e != NULL ){ syslog(LOG_ERR,"interface_pushAddress: Error while creating socket: %s\n", e->message); g_error_free(e); return -1; } g_socket_connect(s, sa, NULL, &e); if( e != NULL ){ syslog(LOG_ERR,"interface_pushAddress: Error while connecting: %s\n", e->message); g_error_free(e); return -1; } g_socket_send(s,"A",1,NULL,NULL); gchar *bytes = (gchar*)g_inet_address_to_bytes(n->netadr); g_socket_send(s,bytes,16,NULL,NULL); n->ubnetd = s; //gchar buf[1]; //g_socket_receive(s,buf,1,NULL,NULL); return 0; }
static gboolean fill_address (const gchar * address, guint16 port, Addr * addr, gboolean is_multicast) { GInetAddress *inet; inet = g_inet_address_new_from_string (address); if (inet == NULL) return FALSE; if (is_multicast != g_inet_address_get_is_multicast (inet)) { g_object_unref (inet); return FALSE; } addr->size = g_inet_address_get_native_size (inet); memcpy (addr->bytes, g_inet_address_to_bytes (inet), addr->size); g_object_unref (inet); addr->port = port; return TRUE; }
G_MODULE_EXPORT gchar * g_module_check_init(GModule *module) { gboolean enable; GError * err=NULL; gchar * url; enable = g_key_file_get_boolean(gkeyfile,GROUP_NAME,"enable",&err); if(err) { enable = TRUE; g_error_free(err); g_message("%s","[http_redirect]:[enable] not specified, default to enable"); err = NULL; } if (!enable) { return "[http_redirect]:[enable=false], user disabled me"; } url = g_key_file_get_string(gkeyfile, GROUP_NAME, "url", NULL); if(!url) { return "[http_redirect]:[url] not defined, please define one"; } http_redirector_init(url); gchar * ips = g_key_file_get_string(gkeyfile,GROUP_NAME,"whitelist",&err); if(err) { g_error_free(err); }else { GResolver * dns = g_resolver_get_default(); void resove_host_by_dns(GObject *source_object, GAsyncResult *res,gpointer user_data) { GList * hosts = g_resolver_lookup_by_name_finish(G_RESOLVER(source_object),res,NULL); if(hosts) { GList * it = g_list_first(hosts); do { GInetAddress * addr = (GInetAddress*)(it->data); if(g_inet_address_get_native_size(addr)==4) { in_addr_t ip; memcpy(&ip,g_inet_address_to_bytes(addr),4); whiteip = g_list_prepend(whiteip,GUINT_TO_POINTER(ip)); g_message(_("%s's DNS result : %s"),(char*)user_data,g_inet_address_to_string(addr)); } }while(( it = g_list_next(it))); g_resolver_free_addresses(hosts); } g_object_unref(source_object); g_free(user_data); } gchar *ptr; gchar * one_host =strtok_r(ips," \t",&ptr); while( one_host ) { in_addr_t ip = inet_addr(one_host); if (ip == INADDR_NONE) { g_object_ref(dns); g_debug(_("host %s is not an ipv4 address, will do async dns lookup"),one_host); g_resolver_lookup_by_name_async(dns,one_host,NULL,resove_host_by_dns,g_strdup(one_host)); }else { whiteip = g_list_prepend(whiteip,GUINT_TO_POINTER(ip)); } one_host = strtok_r(NULL," \t",&ptr); } g_object_unref(dns); }
static gint set_connect_msg (guint8 *msg, const gchar *hostname, guint16 port, const char *username, GError **error) { GInetAddress *addr; guint len = 0; gsize addr_len; gboolean is_ip; const gchar *ip; msg[len++] = SOCKS4_VERSION; msg[len++] = SOCKS4_CMD_CONNECT; { guint16 hp = g_htons (port); memcpy (msg + len, &hp, 2); len += 2; } is_ip = g_hostname_is_ip_address (hostname); if (is_ip) ip = hostname; else ip = "0.0.0.1"; addr = g_inet_address_new_from_string (ip); addr_len = g_inet_address_get_native_size (addr); if (addr_len != 4) { g_set_error (error, G_IO_ERROR, G_IO_ERROR_PROXY_FAILED, _("SOCKSv4 does not support IPv6 address '%s'"), ip); g_object_unref (addr); return -1; } memcpy (msg + len, g_inet_address_to_bytes (addr), addr_len); len += addr_len; g_object_unref (addr); if (username) { gsize user_len = strlen (username); if (user_len > SOCKS4_MAX_LEN) { g_set_error_literal (error, G_IO_ERROR, G_IO_ERROR_PROXY_FAILED, _("Username is too long for SOCKSv4 protocol")); return -1; } memcpy (msg + len, username, user_len); len += user_len; } msg[len++] = '\0'; if (!is_ip) { gsize host_len = strlen (hostname); if (host_len > SOCKS4_MAX_LEN) { g_set_error (error, G_IO_ERROR, G_IO_ERROR_PROXY_FAILED, _("Hostname '%s' is too long for SOCKSv4 protocol"), hostname); return -1; } memcpy (msg + len, hostname, host_len); len += host_len; msg[len++] = '\0'; } return len; }
static int _SSL_check_subject_altname (X509 *cert, const char *host) { STACK_OF(GENERAL_NAME) *altname_stack = NULL; GInetAddress *addr; GSocketFamily family; int type = GEN_DNS; int count, i; int rv = -1; altname_stack = X509_get_ext_d2i (cert, NID_subject_alt_name, NULL, NULL); if (altname_stack == NULL) return -1; addr = g_inet_address_new_from_string (host); if (addr != NULL) { family = g_inet_address_get_family (addr); if (family == G_SOCKET_FAMILY_IPV4 || family == G_SOCKET_FAMILY_IPV6) type = GEN_IPADD; } count = sk_GENERAL_NAME_num(altname_stack); for (i = 0; i < count; i++) { GENERAL_NAME *altname; altname = sk_GENERAL_NAME_value (altname_stack, i); if (altname->type != type) continue; if (type == GEN_DNS) { unsigned char *data; int format; format = ASN1_STRING_type (altname->d.dNSName); if (format == V_ASN1_IA5STRING) { data = ASN1_STRING_data (altname->d.dNSName); if (ASN1_STRING_length (altname->d.dNSName) != (int)strlen(data)) { g_warning("NUL byte in subjectAltName, probably a malicious certificate.\n"); rv = -2; break; } if (_SSL_match_hostname (data, host) == 0) { rv = 0; break; } } else g_warning ("unhandled subjectAltName dNSName encoding (%d)\n", format); } else if (type == GEN_IPADD) { unsigned char *data; const guint8 *addr_bytes; int datalen, addr_len; datalen = ASN1_STRING_length (altname->d.iPAddress); data = ASN1_STRING_data (altname->d.iPAddress); addr_bytes = g_inet_address_to_bytes (addr); addr_len = (int)g_inet_address_get_native_size (addr); if (datalen == addr_len && memcmp (data, addr_bytes, addr_len) == 0) { rv = 0; break; } } } if (addr != NULL) g_object_unref (addr); sk_GENERAL_NAME_free (altname_stack); return rv; }
makiDCCSend* maki_dcc_send_new_out (makiServer* serv, makiUser* user, const gchar* path) { guint i; gchar* basename; GInetAddress* inet_address; struct stat stbuf; makiInstance* inst = maki_instance_get_default(); makiNetwork* net = maki_instance_network(inst); makiDCCSend* dcc; dcc = g_new(makiDCCSend, 1); dcc->server = serv; dcc->id = maki_instance_get_dcc_send_id(inst); dcc->user = maki_user_ref(user); dcc->channel.file = NULL; dcc->channel.connection = NULL; dcc->path = g_strdup(path); dcc->position = 0; dcc->size = 0; dcc->resume = 0; dcc->address = 0; dcc->port = 0; dcc->token = 0; dcc->status = 0; dcc->d.out.ack.position = 0; dcc->d.out.ack.offset = 0; dcc->d.out.wait = FALSE; for (i = 0; i < s_out_num; i++) { dcc->d.out.sources[i] = 0; } dcc->d.out.upnp = FALSE; if (stat(dcc->path, &stbuf) != 0) { goto error; } dcc->size = stbuf.st_size; for (dcc->port = maki_instance_config_get_integer(inst, "dcc", "port_first"); dcc->port <= maki_instance_config_get_integer(inst, "dcc", "port_last"); dcc->port++) { if ((dcc->channel.connection = i_io_channel_unix_new_listen(NULL, dcc->port, TRUE)) != NULL) { break; } } if (dcc->channel.connection == NULL) { goto error; } g_io_channel_set_close_on_unref(dcc->channel.connection, TRUE); g_io_channel_set_encoding(dcc->channel.connection, NULL, NULL); if ((inet_address = maki_network_external_address(net)) != NULL) { if (g_inet_address_get_family(inet_address) == G_SOCKET_FAMILY_IPV4) { dcc->address = ntohl(*((guint32 const*)g_inet_address_to_bytes(inet_address))); } g_object_unref(inet_address); } else { makiNetworkAddress addr; socklen_t addrlen = sizeof(addr); getsockname(g_io_channel_unix_get_fd(dcc->channel.connection), &(addr.sa), &addrlen); dcc->address = ntohl(addr.sin.sin_addr.s_addr); } if ((dcc->channel.file = g_io_channel_new_file(dcc->path, "r", NULL)) == NULL) { goto error; } g_io_channel_set_close_on_unref(dcc->channel.file, TRUE); g_io_channel_set_encoding(dcc->channel.file, NULL, NULL); g_io_channel_set_buffered(dcc->channel.file, FALSE); dcc->d.out.upnp = maki_network_upnp_add_port(net, dcc->port, "maki DCC Send"); basename = g_path_get_basename(dcc->path); if (strstr(basename, " ") == NULL) { maki_server_send_printf(serv, "PRIVMSG %s :\001DCC SEND %s %" G_GUINT32_FORMAT " %" G_GUINT16_FORMAT " %" G_GUINT64_FORMAT "\001", maki_user_nick(dcc->user), basename, dcc->address, dcc->port, dcc->size); } else { maki_server_send_printf(serv, "PRIVMSG %s :\001DCC SEND \"%s\" %" G_GUINT32_FORMAT " %" G_GUINT16_FORMAT " %" G_GUINT64_FORMAT "\001", maki_user_nick(dcc->user), basename, dcc->address, dcc->port, dcc->size); } g_free(basename); dcc->d.out.sources[s_out_listen] = g_io_add_watch(dcc->channel.connection, G_IO_IN | G_IO_HUP | G_IO_ERR, maki_dcc_send_out_listen, dcc); maki_dcc_send_emit(dcc); return dcc; error: maki_dcc_send_free(dcc); return NULL; }