208 * gst_netaddress_get_ip4_address: |
214 * gst_netaddress_get_ip4_address: |
209 * @naddr: a network address |
215 * @naddr: a network address |
210 * @address: a location to store the address. |
216 * @address: a location to store the address. |
211 * @port: a location to store the port. |
217 * @port: a location to store the port. |
212 * |
218 * |
213 * Get the IPv4 address stored in @naddr into @address. |
219 * Get the IPv4 address stored in @naddr into @address. This function requires |
|
220 * that the address type of @naddr is of type #GST_NET_TYPE_IP4. |
|
221 * |
|
222 * Note that @port and @address are expressed in network byte order, use |
|
223 * g_ntohs() and g_ntohl() to convert them to host order. |
214 * |
224 * |
215 * Returns: TRUE if the address could be retrieved. |
225 * Returns: TRUE if the address could be retrieved. |
216 */ |
226 */ |
217 #ifdef __SYMBIAN32__ |
227 #ifdef __SYMBIAN32__ |
218 EXPORT_C |
228 EXPORT_C |
219 #endif |
229 #endif |
220 |
230 |
221 gboolean |
231 gboolean |
222 gst_netaddress_get_ip4_address (GstNetAddress * naddr, guint32 * address, |
232 gst_netaddress_get_ip4_address (const GstNetAddress * naddr, guint32 * address, |
223 guint16 * port) |
233 guint16 * port) |
224 { |
234 { |
225 g_return_val_if_fail (naddr != NULL, FALSE); |
235 g_return_val_if_fail (naddr != NULL, FALSE); |
226 |
236 |
227 if (naddr->type == GST_NET_TYPE_UNKNOWN) |
237 if (naddr->type == GST_NET_TYPE_UNKNOWN || naddr->type == GST_NET_TYPE_IP6) |
228 return FALSE; |
238 return FALSE; |
229 |
239 |
230 if (address) |
240 if (address) |
231 *address = naddr->address.ip4; |
241 *address = naddr->address.ip4; |
232 if (port) |
242 if (port) |
241 * @address: a location to store the result. |
251 * @address: a location to store the result. |
242 * @port: a location to store the port. |
252 * @port: a location to store the port. |
243 * |
253 * |
244 * Get the IPv6 address stored in @naddr into @address. |
254 * Get the IPv6 address stored in @naddr into @address. |
245 * |
255 * |
|
256 * If @naddr is of type GST_NET_TYPE_IP4, the transitional IP6 address is |
|
257 * returned. |
|
258 * |
|
259 * Note that @port is expressed in network byte order, use g_ntohs() to convert |
|
260 * it to host order. |
|
261 * |
246 * Returns: TRUE if the address could be retrieved. |
262 * Returns: TRUE if the address could be retrieved. |
247 */ |
263 */ |
248 #ifdef __SYMBIAN32__ |
264 #ifdef __SYMBIAN32__ |
249 EXPORT_C |
265 EXPORT_C |
250 #endif |
266 #endif |
251 |
267 |
252 gboolean |
268 gboolean |
253 gst_netaddress_get_ip6_address (GstNetAddress * naddr, guint8 address[16], |
269 gst_netaddress_get_ip6_address (const GstNetAddress * naddr, guint8 address[16], |
254 guint16 * port) |
270 guint16 * port) |
255 { |
271 { |
|
272 static guint8 ip4_transition[16] = |
|
273 { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0xFF, 0xFF }; |
256 g_return_val_if_fail (naddr != NULL, FALSE); |
274 g_return_val_if_fail (naddr != NULL, FALSE); |
257 |
275 |
258 if (naddr->type == GST_NET_TYPE_UNKNOWN) |
276 if (naddr->type == GST_NET_TYPE_UNKNOWN) |
259 return FALSE; |
277 return FALSE; |
260 |
278 |
261 if (address) |
279 if (address) { |
262 memcpy (address, naddr->address.ip6, 16); |
280 if (naddr->type == GST_NET_TYPE_IP6) { |
|
281 memcpy (address, naddr->address.ip6, 16); |
|
282 } else { /* naddr->type == GST_NET_TYPE_IP4 */ |
|
283 memcpy (address, ip4_transition, 12); |
|
284 memcpy (address + 12, (guint8 *) & (naddr->address.ip4), 4); |
|
285 } |
|
286 } |
263 if (port) |
287 if (port) |
264 *port = naddr->port; |
288 *port = naddr->port; |
265 |
289 |
266 return TRUE; |
290 return TRUE; |
|
291 } |
|
292 |
|
293 /** |
|
294 * gst_netaddress_get_address_bytes: |
|
295 * @naddr: a network address |
|
296 * @address: a location to store the result. |
|
297 * @port: a location to store the port. |
|
298 * |
|
299 * Get just the address bytes stored in @naddr into @address. |
|
300 * |
|
301 * Note that @port is expressed in network byte order, use g_ntohs() to convert |
|
302 * it to host order. IP4 addresses are also stored in network byte order. |
|
303 * |
|
304 * Returns: number of bytes actually copied |
|
305 * |
|
306 * Since: 0.10.22 |
|
307 */ |
|
308 #ifdef __SYMBIAN32__ |
|
309 EXPORT_C |
|
310 #endif |
|
311 |
|
312 gint |
|
313 gst_netaddress_get_address_bytes (const GstNetAddress * naddr, |
|
314 guint8 address[16], guint16 * port) |
|
315 { |
|
316 gint ret = 0; |
|
317 |
|
318 g_return_val_if_fail (naddr != NULL, FALSE); |
|
319 |
|
320 if (naddr->type == GST_NET_TYPE_UNKNOWN) |
|
321 return 0; |
|
322 |
|
323 if (address) { |
|
324 if (naddr->type == GST_NET_TYPE_IP6) { |
|
325 memcpy (address, naddr->address.ip6, 16); |
|
326 ret = 16; |
|
327 } else { /* naddr->type == GST_NET_TYPE_IP4 */ |
|
328 memcpy (address, (guint8 *) & (naddr->address.ip4), 4); |
|
329 ret = 4; |
|
330 } |
|
331 } |
|
332 if (port) |
|
333 *port = naddr->port; |
|
334 |
|
335 return ret; |
|
336 } |
|
337 |
|
338 /** |
|
339 * gst_netaddress_set_address_bytes: |
|
340 * @naddr: a network address |
|
341 * @address: a location to store the result. |
|
342 * @port: a location to store the port. |
|
343 * |
|
344 * Set just the address bytes stored in @naddr into @address. |
|
345 * |
|
346 * Note that @port must be expressed in network byte order, use g_htons() to convert |
|
347 * it to network byte order order. IP4 address bytes must also be stored in |
|
348 * network byte order. |
|
349 * |
|
350 * Returns: number of bytes actually copied |
|
351 * |
|
352 * Since: 0.10.22 |
|
353 */ |
|
354 #ifdef __SYMBIAN32__ |
|
355 EXPORT_C |
|
356 #endif |
|
357 |
|
358 gint |
|
359 gst_netaddress_set_address_bytes (GstNetAddress * naddr, GstNetType type, |
|
360 guint8 address[16], guint16 port) |
|
361 { |
|
362 gint len = 0; |
|
363 |
|
364 g_return_val_if_fail (naddr != NULL, 0); |
|
365 |
|
366 naddr->type = type; |
|
367 switch (naddr->type) { |
|
368 case GST_NET_TYPE_UNKNOWN: |
|
369 case GST_NET_TYPE_IP6: |
|
370 len = 16; |
|
371 memcpy (naddr->address.ip6, address, 16); |
|
372 break; |
|
373 case GST_NET_TYPE_IP4: |
|
374 len = 4; |
|
375 memcpy ((guint8 *) & (naddr->address.ip4), address, 4); |
|
376 break; |
|
377 } |
|
378 |
|
379 if (port) |
|
380 naddr->port = port; |
|
381 |
|
382 return len; |
267 } |
383 } |
268 |
384 |
269 /** |
385 /** |
270 * gst_netaddress_equal: |
386 * gst_netaddress_equal: |
271 * @naddr1: The first #GstNetAddress |
387 * @naddr1: The first #GstNetAddress |
307 default: |
423 default: |
308 break; |
424 break; |
309 } |
425 } |
310 return TRUE; |
426 return TRUE; |
311 } |
427 } |
|
428 |
|
429 /** |
|
430 * gst_netaddress_to_string: |
|
431 * @naddr: a #GstNetAddress |
|
432 * @dest: destination |
|
433 * @len: len of @dest |
|
434 * |
|
435 * Copies a string representation of @naddr into @dest. Up to @len bytes are |
|
436 * copied. |
|
437 * |
|
438 * Returns: the number of bytes which would be produced if the buffer was large |
|
439 * enough |
|
440 * |
|
441 * Since: 0.10.24 |
|
442 */ |
|
443 |
|
444 #ifdef __SYMBIAN32__ |
|
445 EXPORT_C |
|
446 #endif |
|
447 |
|
448 gint |
|
449 gst_netaddress_to_string (const GstNetAddress * naddr, gchar * dest, gulong len) |
|
450 { |
|
451 gint result; |
|
452 |
|
453 g_return_val_if_fail (naddr != NULL, FALSE); |
|
454 g_return_val_if_fail (dest != NULL, FALSE); |
|
455 |
|
456 switch (naddr->type) { |
|
457 case GST_NET_TYPE_IP4: |
|
458 { |
|
459 guint32 address; |
|
460 guint16 port; |
|
461 |
|
462 gst_netaddress_get_ip4_address (naddr, &address, &port); |
|
463 address = g_ntohl (address); |
|
464 |
|
465 result = g_snprintf (dest, len, "%d.%d.%d.%d:%d", (address >> 24) & 0xff, |
|
466 (address >> 16) & 0xff, (address >> 8) & 0xff, address & 0xff, |
|
467 g_ntohs (port)); |
|
468 break; |
|
469 } |
|
470 case GST_NET_TYPE_IP6: |
|
471 { |
|
472 guint8 address[16]; |
|
473 guint16 port; |
|
474 |
|
475 gst_netaddress_get_ip6_address (naddr, address, &port); |
|
476 |
|
477 result = |
|
478 g_snprintf (dest, len, "[%04x:%04x:%04x:%04x:%04x:%04x:%04x:%04x]:%d", |
|
479 (address[0] << 8) | address[1], (address[2] << 8) | address[3], |
|
480 (address[4] << 8) | address[5], (address[6] << 8) | address[7], |
|
481 (address[8] << 8) | address[9], (address[10] << 8) | address[11], |
|
482 (address[12] << 8) | address[13], (address[14] << 8) | address[15], |
|
483 g_ntohs (port)); |
|
484 break; |
|
485 } |
|
486 default: |
|
487 dest[0] = 0; |
|
488 result = 0; |
|
489 break; |
|
490 } |
|
491 return result; |
|
492 } |