1use crate::{ffi, SocketFamily};
6use glib::{
7 prelude::*,
8 signal::{connect_raw, SignalHandlerId},
9 translate::*,
10};
11use std::boxed::Box as Box_;
12
13glib::wrapper! {
14 #[doc(alias = "GInetAddress")]
113 pub struct InetAddress(Object<ffi::GInetAddress, ffi::GInetAddressClass>);
114
115 match fn {
116 type_ => || ffi::g_inet_address_get_type(),
117 }
118}
119
120impl InetAddress {
121 pub const NONE: Option<&'static InetAddress> = None;
122
123 #[doc(alias = "g_inet_address_new_any")]
134 pub fn new_any(family: SocketFamily) -> InetAddress {
135 unsafe { from_glib_full(ffi::g_inet_address_new_any(family.into_glib())) }
136 }
137
138 #[doc(alias = "g_inet_address_new_from_string")]
148 #[doc(alias = "new_from_string")]
149 pub fn from_string(string: &str) -> Option<InetAddress> {
150 unsafe { from_glib_full(ffi::g_inet_address_new_from_string(string.to_glib_none().0)) }
151 }
152
153 #[doc(alias = "g_inet_address_new_loopback")]
163 pub fn new_loopback(family: SocketFamily) -> InetAddress {
164 unsafe { from_glib_full(ffi::g_inet_address_new_loopback(family.into_glib())) }
165 }
166}
167
168impl std::fmt::Display for InetAddress {
169 #[inline]
170 fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
171 f.write_str(&InetAddressExt::to_str(self))
172 }
173}
174
175unsafe impl Send for InetAddress {}
176unsafe impl Sync for InetAddress {}
177
178pub trait InetAddressExt: IsA<InetAddress> + 'static {
184 #[doc(alias = "g_inet_address_equal")]
185 fn equal(&self, other_address: &impl IsA<InetAddress>) -> bool {
186 unsafe {
187 from_glib(ffi::g_inet_address_equal(
188 self.as_ref().to_glib_none().0,
189 other_address.as_ref().to_glib_none().0,
190 ))
191 }
192 }
193
194 #[doc(alias = "g_inet_address_get_family")]
200 #[doc(alias = "get_family")]
201 fn family(&self) -> SocketFamily {
202 unsafe {
203 from_glib(ffi::g_inet_address_get_family(
204 self.as_ref().to_glib_none().0,
205 ))
206 }
207 }
208
209 #[doc(alias = "g_inet_address_get_is_any")]
215 #[doc(alias = "get_is_any")]
216 #[doc(alias = "is-any")]
217 fn is_any(&self) -> bool {
218 unsafe {
219 from_glib(ffi::g_inet_address_get_is_any(
220 self.as_ref().to_glib_none().0,
221 ))
222 }
223 }
224
225 #[doc(alias = "g_inet_address_get_is_link_local")]
233 #[doc(alias = "get_is_link_local")]
234 #[doc(alias = "is-link-local")]
235 fn is_link_local(&self) -> bool {
236 unsafe {
237 from_glib(ffi::g_inet_address_get_is_link_local(
238 self.as_ref().to_glib_none().0,
239 ))
240 }
241 }
242
243 #[doc(alias = "g_inet_address_get_is_loopback")]
249 #[doc(alias = "get_is_loopback")]
250 #[doc(alias = "is-loopback")]
251 fn is_loopback(&self) -> bool {
252 unsafe {
253 from_glib(ffi::g_inet_address_get_is_loopback(
254 self.as_ref().to_glib_none().0,
255 ))
256 }
257 }
258
259 #[doc(alias = "g_inet_address_get_is_mc_global")]
265 #[doc(alias = "get_is_mc_global")]
266 #[doc(alias = "is-mc-global")]
267 fn is_mc_global(&self) -> bool {
268 unsafe {
269 from_glib(ffi::g_inet_address_get_is_mc_global(
270 self.as_ref().to_glib_none().0,
271 ))
272 }
273 }
274
275 #[doc(alias = "g_inet_address_get_is_mc_link_local")]
281 #[doc(alias = "get_is_mc_link_local")]
282 #[doc(alias = "is-mc-link-local")]
283 fn is_mc_link_local(&self) -> bool {
284 unsafe {
285 from_glib(ffi::g_inet_address_get_is_mc_link_local(
286 self.as_ref().to_glib_none().0,
287 ))
288 }
289 }
290
291 #[doc(alias = "g_inet_address_get_is_mc_node_local")]
297 #[doc(alias = "get_is_mc_node_local")]
298 #[doc(alias = "is-mc-node-local")]
299 fn is_mc_node_local(&self) -> bool {
300 unsafe {
301 from_glib(ffi::g_inet_address_get_is_mc_node_local(
302 self.as_ref().to_glib_none().0,
303 ))
304 }
305 }
306
307 #[doc(alias = "g_inet_address_get_is_mc_org_local")]
313 #[doc(alias = "get_is_mc_org_local")]
314 #[doc(alias = "is-mc-org-local")]
315 fn is_mc_org_local(&self) -> bool {
316 unsafe {
317 from_glib(ffi::g_inet_address_get_is_mc_org_local(
318 self.as_ref().to_glib_none().0,
319 ))
320 }
321 }
322
323 #[doc(alias = "g_inet_address_get_is_mc_site_local")]
329 #[doc(alias = "get_is_mc_site_local")]
330 #[doc(alias = "is-mc-site-local")]
331 fn is_mc_site_local(&self) -> bool {
332 unsafe {
333 from_glib(ffi::g_inet_address_get_is_mc_site_local(
334 self.as_ref().to_glib_none().0,
335 ))
336 }
337 }
338
339 #[doc(alias = "g_inet_address_get_is_multicast")]
345 #[doc(alias = "get_is_multicast")]
346 #[doc(alias = "is-multicast")]
347 fn is_multicast(&self) -> bool {
348 unsafe {
349 from_glib(ffi::g_inet_address_get_is_multicast(
350 self.as_ref().to_glib_none().0,
351 ))
352 }
353 }
354
355 #[doc(alias = "g_inet_address_get_is_site_local")]
364 #[doc(alias = "get_is_site_local")]
365 #[doc(alias = "is-site-local")]
366 fn is_site_local(&self) -> bool {
367 unsafe {
368 from_glib(ffi::g_inet_address_get_is_site_local(
369 self.as_ref().to_glib_none().0,
370 ))
371 }
372 }
373
374 #[doc(alias = "g_inet_address_get_native_size")]
381 #[doc(alias = "get_native_size")]
382 fn native_size(&self) -> usize {
383 unsafe { ffi::g_inet_address_get_native_size(self.as_ref().to_glib_none().0) }
384 }
385
386 #[doc(alias = "g_inet_address_to_string")]
393 #[doc(alias = "to_string")]
394 fn to_str(&self) -> glib::GString {
395 unsafe {
396 from_glib_full(ffi::g_inet_address_to_string(
397 self.as_ref().to_glib_none().0,
398 ))
399 }
400 }
401
402 #[doc(alias = "is-any")]
407 fn connect_is_any_notify<F: Fn(&Self) + Send + Sync + 'static>(&self, f: F) -> SignalHandlerId {
408 unsafe extern "C" fn notify_is_any_trampoline<
409 P: IsA<InetAddress>,
410 F: Fn(&P) + Send + Sync + 'static,
411 >(
412 this: *mut ffi::GInetAddress,
413 _param_spec: glib::ffi::gpointer,
414 f: glib::ffi::gpointer,
415 ) {
416 let f: &F = &*(f as *const F);
417 f(InetAddress::from_glib_borrow(this).unsafe_cast_ref())
418 }
419 unsafe {
420 let f: Box_<F> = Box_::new(f);
421 connect_raw(
422 self.as_ptr() as *mut _,
423 c"notify::is-any".as_ptr() as *const _,
424 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
425 notify_is_any_trampoline::<Self, F> as *const (),
426 )),
427 Box_::into_raw(f),
428 )
429 }
430 }
431
432 #[doc(alias = "is-link-local")]
433 fn connect_is_link_local_notify<F: Fn(&Self) + Send + Sync + 'static>(
434 &self,
435 f: F,
436 ) -> SignalHandlerId {
437 unsafe extern "C" fn notify_is_link_local_trampoline<
438 P: IsA<InetAddress>,
439 F: Fn(&P) + Send + Sync + 'static,
440 >(
441 this: *mut ffi::GInetAddress,
442 _param_spec: glib::ffi::gpointer,
443 f: glib::ffi::gpointer,
444 ) {
445 let f: &F = &*(f as *const F);
446 f(InetAddress::from_glib_borrow(this).unsafe_cast_ref())
447 }
448 unsafe {
449 let f: Box_<F> = Box_::new(f);
450 connect_raw(
451 self.as_ptr() as *mut _,
452 c"notify::is-link-local".as_ptr() as *const _,
453 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
454 notify_is_link_local_trampoline::<Self, F> as *const (),
455 )),
456 Box_::into_raw(f),
457 )
458 }
459 }
460
461 #[doc(alias = "is-loopback")]
462 fn connect_is_loopback_notify<F: Fn(&Self) + Send + Sync + 'static>(
463 &self,
464 f: F,
465 ) -> SignalHandlerId {
466 unsafe extern "C" fn notify_is_loopback_trampoline<
467 P: IsA<InetAddress>,
468 F: Fn(&P) + Send + Sync + 'static,
469 >(
470 this: *mut ffi::GInetAddress,
471 _param_spec: glib::ffi::gpointer,
472 f: glib::ffi::gpointer,
473 ) {
474 let f: &F = &*(f as *const F);
475 f(InetAddress::from_glib_borrow(this).unsafe_cast_ref())
476 }
477 unsafe {
478 let f: Box_<F> = Box_::new(f);
479 connect_raw(
480 self.as_ptr() as *mut _,
481 c"notify::is-loopback".as_ptr() as *const _,
482 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
483 notify_is_loopback_trampoline::<Self, F> as *const (),
484 )),
485 Box_::into_raw(f),
486 )
487 }
488 }
489
490 #[doc(alias = "is-mc-global")]
491 fn connect_is_mc_global_notify<F: Fn(&Self) + Send + Sync + 'static>(
492 &self,
493 f: F,
494 ) -> SignalHandlerId {
495 unsafe extern "C" fn notify_is_mc_global_trampoline<
496 P: IsA<InetAddress>,
497 F: Fn(&P) + Send + Sync + 'static,
498 >(
499 this: *mut ffi::GInetAddress,
500 _param_spec: glib::ffi::gpointer,
501 f: glib::ffi::gpointer,
502 ) {
503 let f: &F = &*(f as *const F);
504 f(InetAddress::from_glib_borrow(this).unsafe_cast_ref())
505 }
506 unsafe {
507 let f: Box_<F> = Box_::new(f);
508 connect_raw(
509 self.as_ptr() as *mut _,
510 c"notify::is-mc-global".as_ptr() as *const _,
511 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
512 notify_is_mc_global_trampoline::<Self, F> as *const (),
513 )),
514 Box_::into_raw(f),
515 )
516 }
517 }
518
519 #[doc(alias = "is-mc-link-local")]
520 fn connect_is_mc_link_local_notify<F: Fn(&Self) + Send + Sync + 'static>(
521 &self,
522 f: F,
523 ) -> SignalHandlerId {
524 unsafe extern "C" fn notify_is_mc_link_local_trampoline<
525 P: IsA<InetAddress>,
526 F: Fn(&P) + Send + Sync + 'static,
527 >(
528 this: *mut ffi::GInetAddress,
529 _param_spec: glib::ffi::gpointer,
530 f: glib::ffi::gpointer,
531 ) {
532 let f: &F = &*(f as *const F);
533 f(InetAddress::from_glib_borrow(this).unsafe_cast_ref())
534 }
535 unsafe {
536 let f: Box_<F> = Box_::new(f);
537 connect_raw(
538 self.as_ptr() as *mut _,
539 c"notify::is-mc-link-local".as_ptr() as *const _,
540 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
541 notify_is_mc_link_local_trampoline::<Self, F> as *const (),
542 )),
543 Box_::into_raw(f),
544 )
545 }
546 }
547
548 #[doc(alias = "is-mc-node-local")]
549 fn connect_is_mc_node_local_notify<F: Fn(&Self) + Send + Sync + 'static>(
550 &self,
551 f: F,
552 ) -> SignalHandlerId {
553 unsafe extern "C" fn notify_is_mc_node_local_trampoline<
554 P: IsA<InetAddress>,
555 F: Fn(&P) + Send + Sync + 'static,
556 >(
557 this: *mut ffi::GInetAddress,
558 _param_spec: glib::ffi::gpointer,
559 f: glib::ffi::gpointer,
560 ) {
561 let f: &F = &*(f as *const F);
562 f(InetAddress::from_glib_borrow(this).unsafe_cast_ref())
563 }
564 unsafe {
565 let f: Box_<F> = Box_::new(f);
566 connect_raw(
567 self.as_ptr() as *mut _,
568 c"notify::is-mc-node-local".as_ptr() as *const _,
569 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
570 notify_is_mc_node_local_trampoline::<Self, F> as *const (),
571 )),
572 Box_::into_raw(f),
573 )
574 }
575 }
576
577 #[doc(alias = "is-mc-org-local")]
578 fn connect_is_mc_org_local_notify<F: Fn(&Self) + Send + Sync + 'static>(
579 &self,
580 f: F,
581 ) -> SignalHandlerId {
582 unsafe extern "C" fn notify_is_mc_org_local_trampoline<
583 P: IsA<InetAddress>,
584 F: Fn(&P) + Send + Sync + 'static,
585 >(
586 this: *mut ffi::GInetAddress,
587 _param_spec: glib::ffi::gpointer,
588 f: glib::ffi::gpointer,
589 ) {
590 let f: &F = &*(f as *const F);
591 f(InetAddress::from_glib_borrow(this).unsafe_cast_ref())
592 }
593 unsafe {
594 let f: Box_<F> = Box_::new(f);
595 connect_raw(
596 self.as_ptr() as *mut _,
597 c"notify::is-mc-org-local".as_ptr() as *const _,
598 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
599 notify_is_mc_org_local_trampoline::<Self, F> as *const (),
600 )),
601 Box_::into_raw(f),
602 )
603 }
604 }
605
606 #[doc(alias = "is-mc-site-local")]
607 fn connect_is_mc_site_local_notify<F: Fn(&Self) + Send + Sync + 'static>(
608 &self,
609 f: F,
610 ) -> SignalHandlerId {
611 unsafe extern "C" fn notify_is_mc_site_local_trampoline<
612 P: IsA<InetAddress>,
613 F: Fn(&P) + Send + Sync + 'static,
614 >(
615 this: *mut ffi::GInetAddress,
616 _param_spec: glib::ffi::gpointer,
617 f: glib::ffi::gpointer,
618 ) {
619 let f: &F = &*(f as *const F);
620 f(InetAddress::from_glib_borrow(this).unsafe_cast_ref())
621 }
622 unsafe {
623 let f: Box_<F> = Box_::new(f);
624 connect_raw(
625 self.as_ptr() as *mut _,
626 c"notify::is-mc-site-local".as_ptr() as *const _,
627 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
628 notify_is_mc_site_local_trampoline::<Self, F> as *const (),
629 )),
630 Box_::into_raw(f),
631 )
632 }
633 }
634
635 #[doc(alias = "is-multicast")]
636 fn connect_is_multicast_notify<F: Fn(&Self) + Send + Sync + 'static>(
637 &self,
638 f: F,
639 ) -> SignalHandlerId {
640 unsafe extern "C" fn notify_is_multicast_trampoline<
641 P: IsA<InetAddress>,
642 F: Fn(&P) + Send + Sync + 'static,
643 >(
644 this: *mut ffi::GInetAddress,
645 _param_spec: glib::ffi::gpointer,
646 f: glib::ffi::gpointer,
647 ) {
648 let f: &F = &*(f as *const F);
649 f(InetAddress::from_glib_borrow(this).unsafe_cast_ref())
650 }
651 unsafe {
652 let f: Box_<F> = Box_::new(f);
653 connect_raw(
654 self.as_ptr() as *mut _,
655 c"notify::is-multicast".as_ptr() as *const _,
656 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
657 notify_is_multicast_trampoline::<Self, F> as *const (),
658 )),
659 Box_::into_raw(f),
660 )
661 }
662 }
663
664 #[doc(alias = "is-site-local")]
665 fn connect_is_site_local_notify<F: Fn(&Self) + Send + Sync + 'static>(
666 &self,
667 f: F,
668 ) -> SignalHandlerId {
669 unsafe extern "C" fn notify_is_site_local_trampoline<
670 P: IsA<InetAddress>,
671 F: Fn(&P) + Send + Sync + 'static,
672 >(
673 this: *mut ffi::GInetAddress,
674 _param_spec: glib::ffi::gpointer,
675 f: glib::ffi::gpointer,
676 ) {
677 let f: &F = &*(f as *const F);
678 f(InetAddress::from_glib_borrow(this).unsafe_cast_ref())
679 }
680 unsafe {
681 let f: Box_<F> = Box_::new(f);
682 connect_raw(
683 self.as_ptr() as *mut _,
684 c"notify::is-site-local".as_ptr() as *const _,
685 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
686 notify_is_site_local_trampoline::<Self, F> as *const (),
687 )),
688 Box_::into_raw(f),
689 )
690 }
691 }
692}
693
694impl<O: IsA<InetAddress>> InetAddressExt for O {}