1use crate::{SocketFamily, ffi};
6use glib::{
7 prelude::*,
8 signal::{SignalHandlerId, connect_raw},
9 translate::*,
10};
11use std::boxed::Box as Box_;
12
13glib::wrapper! {
14 #[doc(alias = "GInetAddress")]
127 pub struct InetAddress(Object<ffi::GInetAddress, ffi::GInetAddressClass>);
128
129 match fn {
130 type_ => || ffi::g_inet_address_get_type(),
131 }
132}
133
134impl InetAddress {
135 pub const NONE: Option<&'static InetAddress> = None;
136
137 #[doc(alias = "g_inet_address_new_any")]
148 pub fn new_any(family: SocketFamily) -> InetAddress {
149 unsafe { from_glib_full(ffi::g_inet_address_new_any(family.into_glib())) }
150 }
151
152 #[doc(alias = "g_inet_address_new_from_string")]
166 #[doc(alias = "new_from_string")]
167 pub fn from_string(string: &str) -> Option<InetAddress> {
168 unsafe { from_glib_full(ffi::g_inet_address_new_from_string(string.to_glib_none().0)) }
169 }
170
171 #[doc(alias = "g_inet_address_new_loopback")]
181 pub fn new_loopback(family: SocketFamily) -> InetAddress {
182 unsafe { from_glib_full(ffi::g_inet_address_new_loopback(family.into_glib())) }
183 }
184}
185
186impl std::fmt::Display for InetAddress {
187 #[inline]
188 fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
189 f.write_str(&InetAddressExt::to_str(self))
190 }
191}
192
193unsafe impl Send for InetAddress {}
194unsafe impl Sync for InetAddress {}
195
196pub trait InetAddressExt: IsA<InetAddress> + 'static {
202 #[doc(alias = "g_inet_address_equal")]
203 fn equal(&self, other_address: &impl IsA<InetAddress>) -> bool {
204 unsafe {
205 from_glib(ffi::g_inet_address_equal(
206 self.as_ref().to_glib_none().0,
207 other_address.as_ref().to_glib_none().0,
208 ))
209 }
210 }
211
212 #[doc(alias = "g_inet_address_get_family")]
218 #[doc(alias = "get_family")]
219 fn family(&self) -> SocketFamily {
220 unsafe {
221 from_glib(ffi::g_inet_address_get_family(
222 self.as_ref().to_glib_none().0,
223 ))
224 }
225 }
226
227 #[cfg(feature = "v2_86")]
233 #[cfg_attr(docsrs, doc(cfg(feature = "v2_86")))]
234 #[doc(alias = "g_inet_address_get_flowinfo")]
235 #[doc(alias = "get_flowinfo")]
236 fn flowinfo(&self) -> u32 {
237 unsafe { ffi::g_inet_address_get_flowinfo(self.as_ref().to_glib_none().0) }
238 }
239
240 #[doc(alias = "g_inet_address_get_is_any")]
246 #[doc(alias = "get_is_any")]
247 #[doc(alias = "is-any")]
248 fn is_any(&self) -> bool {
249 unsafe {
250 from_glib(ffi::g_inet_address_get_is_any(
251 self.as_ref().to_glib_none().0,
252 ))
253 }
254 }
255
256 #[doc(alias = "g_inet_address_get_is_link_local")]
264 #[doc(alias = "get_is_link_local")]
265 #[doc(alias = "is-link-local")]
266 fn is_link_local(&self) -> bool {
267 unsafe {
268 from_glib(ffi::g_inet_address_get_is_link_local(
269 self.as_ref().to_glib_none().0,
270 ))
271 }
272 }
273
274 #[doc(alias = "g_inet_address_get_is_loopback")]
280 #[doc(alias = "get_is_loopback")]
281 #[doc(alias = "is-loopback")]
282 fn is_loopback(&self) -> bool {
283 unsafe {
284 from_glib(ffi::g_inet_address_get_is_loopback(
285 self.as_ref().to_glib_none().0,
286 ))
287 }
288 }
289
290 #[doc(alias = "g_inet_address_get_is_mc_global")]
296 #[doc(alias = "get_is_mc_global")]
297 #[doc(alias = "is-mc-global")]
298 fn is_mc_global(&self) -> bool {
299 unsafe {
300 from_glib(ffi::g_inet_address_get_is_mc_global(
301 self.as_ref().to_glib_none().0,
302 ))
303 }
304 }
305
306 #[doc(alias = "g_inet_address_get_is_mc_link_local")]
312 #[doc(alias = "get_is_mc_link_local")]
313 #[doc(alias = "is-mc-link-local")]
314 fn is_mc_link_local(&self) -> bool {
315 unsafe {
316 from_glib(ffi::g_inet_address_get_is_mc_link_local(
317 self.as_ref().to_glib_none().0,
318 ))
319 }
320 }
321
322 #[doc(alias = "g_inet_address_get_is_mc_node_local")]
328 #[doc(alias = "get_is_mc_node_local")]
329 #[doc(alias = "is-mc-node-local")]
330 fn is_mc_node_local(&self) -> bool {
331 unsafe {
332 from_glib(ffi::g_inet_address_get_is_mc_node_local(
333 self.as_ref().to_glib_none().0,
334 ))
335 }
336 }
337
338 #[doc(alias = "g_inet_address_get_is_mc_org_local")]
344 #[doc(alias = "get_is_mc_org_local")]
345 #[doc(alias = "is-mc-org-local")]
346 fn is_mc_org_local(&self) -> bool {
347 unsafe {
348 from_glib(ffi::g_inet_address_get_is_mc_org_local(
349 self.as_ref().to_glib_none().0,
350 ))
351 }
352 }
353
354 #[doc(alias = "g_inet_address_get_is_mc_site_local")]
360 #[doc(alias = "get_is_mc_site_local")]
361 #[doc(alias = "is-mc-site-local")]
362 fn is_mc_site_local(&self) -> bool {
363 unsafe {
364 from_glib(ffi::g_inet_address_get_is_mc_site_local(
365 self.as_ref().to_glib_none().0,
366 ))
367 }
368 }
369
370 #[doc(alias = "g_inet_address_get_is_multicast")]
376 #[doc(alias = "get_is_multicast")]
377 #[doc(alias = "is-multicast")]
378 fn is_multicast(&self) -> bool {
379 unsafe {
380 from_glib(ffi::g_inet_address_get_is_multicast(
381 self.as_ref().to_glib_none().0,
382 ))
383 }
384 }
385
386 #[doc(alias = "g_inet_address_get_is_site_local")]
395 #[doc(alias = "get_is_site_local")]
396 #[doc(alias = "is-site-local")]
397 fn is_site_local(&self) -> bool {
398 unsafe {
399 from_glib(ffi::g_inet_address_get_is_site_local(
400 self.as_ref().to_glib_none().0,
401 ))
402 }
403 }
404
405 #[doc(alias = "g_inet_address_get_native_size")]
412 #[doc(alias = "get_native_size")]
413 fn native_size(&self) -> usize {
414 unsafe { ffi::g_inet_address_get_native_size(self.as_ref().to_glib_none().0) }
415 }
416
417 #[cfg(feature = "v2_86")]
423 #[cfg_attr(docsrs, doc(cfg(feature = "v2_86")))]
424 #[doc(alias = "g_inet_address_get_scope_id")]
425 #[doc(alias = "get_scope_id")]
426 #[doc(alias = "scope-id")]
427 fn scope_id(&self) -> u32 {
428 unsafe { ffi::g_inet_address_get_scope_id(self.as_ref().to_glib_none().0) }
429 }
430
431 #[doc(alias = "g_inet_address_to_string")]
438 #[doc(alias = "to_string")]
439 fn to_str(&self) -> glib::GString {
440 unsafe {
441 from_glib_full(ffi::g_inet_address_to_string(
442 self.as_ref().to_glib_none().0,
443 ))
444 }
445 }
446
447 #[doc(alias = "is-any")]
452 fn connect_is_any_notify<F: Fn(&Self) + Send + Sync + 'static>(&self, f: F) -> SignalHandlerId {
453 unsafe extern "C" fn notify_is_any_trampoline<
454 P: IsA<InetAddress>,
455 F: Fn(&P) + Send + Sync + 'static,
456 >(
457 this: *mut ffi::GInetAddress,
458 _param_spec: glib::ffi::gpointer,
459 f: glib::ffi::gpointer,
460 ) {
461 unsafe {
462 let f: &F = &*(f as *const F);
463 f(InetAddress::from_glib_borrow(this).unsafe_cast_ref())
464 }
465 }
466 unsafe {
467 let f: Box_<F> = Box_::new(f);
468 connect_raw(
469 self.as_ptr() as *mut _,
470 c"notify::is-any".as_ptr() as *const _,
471 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
472 notify_is_any_trampoline::<Self, F> as *const (),
473 )),
474 Box_::into_raw(f),
475 )
476 }
477 }
478
479 #[doc(alias = "is-link-local")]
480 fn connect_is_link_local_notify<F: Fn(&Self) + Send + Sync + 'static>(
481 &self,
482 f: F,
483 ) -> SignalHandlerId {
484 unsafe extern "C" fn notify_is_link_local_trampoline<
485 P: IsA<InetAddress>,
486 F: Fn(&P) + Send + Sync + 'static,
487 >(
488 this: *mut ffi::GInetAddress,
489 _param_spec: glib::ffi::gpointer,
490 f: glib::ffi::gpointer,
491 ) {
492 unsafe {
493 let f: &F = &*(f as *const F);
494 f(InetAddress::from_glib_borrow(this).unsafe_cast_ref())
495 }
496 }
497 unsafe {
498 let f: Box_<F> = Box_::new(f);
499 connect_raw(
500 self.as_ptr() as *mut _,
501 c"notify::is-link-local".as_ptr() as *const _,
502 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
503 notify_is_link_local_trampoline::<Self, F> as *const (),
504 )),
505 Box_::into_raw(f),
506 )
507 }
508 }
509
510 #[doc(alias = "is-loopback")]
511 fn connect_is_loopback_notify<F: Fn(&Self) + Send + Sync + 'static>(
512 &self,
513 f: F,
514 ) -> SignalHandlerId {
515 unsafe extern "C" fn notify_is_loopback_trampoline<
516 P: IsA<InetAddress>,
517 F: Fn(&P) + Send + Sync + 'static,
518 >(
519 this: *mut ffi::GInetAddress,
520 _param_spec: glib::ffi::gpointer,
521 f: glib::ffi::gpointer,
522 ) {
523 unsafe {
524 let f: &F = &*(f as *const F);
525 f(InetAddress::from_glib_borrow(this).unsafe_cast_ref())
526 }
527 }
528 unsafe {
529 let f: Box_<F> = Box_::new(f);
530 connect_raw(
531 self.as_ptr() as *mut _,
532 c"notify::is-loopback".as_ptr() as *const _,
533 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
534 notify_is_loopback_trampoline::<Self, F> as *const (),
535 )),
536 Box_::into_raw(f),
537 )
538 }
539 }
540
541 #[doc(alias = "is-mc-global")]
542 fn connect_is_mc_global_notify<F: Fn(&Self) + Send + Sync + 'static>(
543 &self,
544 f: F,
545 ) -> SignalHandlerId {
546 unsafe extern "C" fn notify_is_mc_global_trampoline<
547 P: IsA<InetAddress>,
548 F: Fn(&P) + Send + Sync + 'static,
549 >(
550 this: *mut ffi::GInetAddress,
551 _param_spec: glib::ffi::gpointer,
552 f: glib::ffi::gpointer,
553 ) {
554 unsafe {
555 let f: &F = &*(f as *const F);
556 f(InetAddress::from_glib_borrow(this).unsafe_cast_ref())
557 }
558 }
559 unsafe {
560 let f: Box_<F> = Box_::new(f);
561 connect_raw(
562 self.as_ptr() as *mut _,
563 c"notify::is-mc-global".as_ptr() as *const _,
564 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
565 notify_is_mc_global_trampoline::<Self, F> as *const (),
566 )),
567 Box_::into_raw(f),
568 )
569 }
570 }
571
572 #[doc(alias = "is-mc-link-local")]
573 fn connect_is_mc_link_local_notify<F: Fn(&Self) + Send + Sync + 'static>(
574 &self,
575 f: F,
576 ) -> SignalHandlerId {
577 unsafe extern "C" fn notify_is_mc_link_local_trampoline<
578 P: IsA<InetAddress>,
579 F: Fn(&P) + Send + Sync + 'static,
580 >(
581 this: *mut ffi::GInetAddress,
582 _param_spec: glib::ffi::gpointer,
583 f: glib::ffi::gpointer,
584 ) {
585 unsafe {
586 let f: &F = &*(f as *const F);
587 f(InetAddress::from_glib_borrow(this).unsafe_cast_ref())
588 }
589 }
590 unsafe {
591 let f: Box_<F> = Box_::new(f);
592 connect_raw(
593 self.as_ptr() as *mut _,
594 c"notify::is-mc-link-local".as_ptr() as *const _,
595 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
596 notify_is_mc_link_local_trampoline::<Self, F> as *const (),
597 )),
598 Box_::into_raw(f),
599 )
600 }
601 }
602
603 #[doc(alias = "is-mc-node-local")]
604 fn connect_is_mc_node_local_notify<F: Fn(&Self) + Send + Sync + 'static>(
605 &self,
606 f: F,
607 ) -> SignalHandlerId {
608 unsafe extern "C" fn notify_is_mc_node_local_trampoline<
609 P: IsA<InetAddress>,
610 F: Fn(&P) + Send + Sync + 'static,
611 >(
612 this: *mut ffi::GInetAddress,
613 _param_spec: glib::ffi::gpointer,
614 f: glib::ffi::gpointer,
615 ) {
616 unsafe {
617 let f: &F = &*(f as *const F);
618 f(InetAddress::from_glib_borrow(this).unsafe_cast_ref())
619 }
620 }
621 unsafe {
622 let f: Box_<F> = Box_::new(f);
623 connect_raw(
624 self.as_ptr() as *mut _,
625 c"notify::is-mc-node-local".as_ptr() as *const _,
626 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
627 notify_is_mc_node_local_trampoline::<Self, F> as *const (),
628 )),
629 Box_::into_raw(f),
630 )
631 }
632 }
633
634 #[doc(alias = "is-mc-org-local")]
635 fn connect_is_mc_org_local_notify<F: Fn(&Self) + Send + Sync + 'static>(
636 &self,
637 f: F,
638 ) -> SignalHandlerId {
639 unsafe extern "C" fn notify_is_mc_org_local_trampoline<
640 P: IsA<InetAddress>,
641 F: Fn(&P) + Send + Sync + 'static,
642 >(
643 this: *mut ffi::GInetAddress,
644 _param_spec: glib::ffi::gpointer,
645 f: glib::ffi::gpointer,
646 ) {
647 unsafe {
648 let f: &F = &*(f as *const F);
649 f(InetAddress::from_glib_borrow(this).unsafe_cast_ref())
650 }
651 }
652 unsafe {
653 let f: Box_<F> = Box_::new(f);
654 connect_raw(
655 self.as_ptr() as *mut _,
656 c"notify::is-mc-org-local".as_ptr() as *const _,
657 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
658 notify_is_mc_org_local_trampoline::<Self, F> as *const (),
659 )),
660 Box_::into_raw(f),
661 )
662 }
663 }
664
665 #[doc(alias = "is-mc-site-local")]
666 fn connect_is_mc_site_local_notify<F: Fn(&Self) + Send + Sync + 'static>(
667 &self,
668 f: F,
669 ) -> SignalHandlerId {
670 unsafe extern "C" fn notify_is_mc_site_local_trampoline<
671 P: IsA<InetAddress>,
672 F: Fn(&P) + Send + Sync + 'static,
673 >(
674 this: *mut ffi::GInetAddress,
675 _param_spec: glib::ffi::gpointer,
676 f: glib::ffi::gpointer,
677 ) {
678 unsafe {
679 let f: &F = &*(f as *const F);
680 f(InetAddress::from_glib_borrow(this).unsafe_cast_ref())
681 }
682 }
683 unsafe {
684 let f: Box_<F> = Box_::new(f);
685 connect_raw(
686 self.as_ptr() as *mut _,
687 c"notify::is-mc-site-local".as_ptr() as *const _,
688 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
689 notify_is_mc_site_local_trampoline::<Self, F> as *const (),
690 )),
691 Box_::into_raw(f),
692 )
693 }
694 }
695
696 #[doc(alias = "is-multicast")]
697 fn connect_is_multicast_notify<F: Fn(&Self) + Send + Sync + 'static>(
698 &self,
699 f: F,
700 ) -> SignalHandlerId {
701 unsafe extern "C" fn notify_is_multicast_trampoline<
702 P: IsA<InetAddress>,
703 F: Fn(&P) + Send + Sync + 'static,
704 >(
705 this: *mut ffi::GInetAddress,
706 _param_spec: glib::ffi::gpointer,
707 f: glib::ffi::gpointer,
708 ) {
709 unsafe {
710 let f: &F = &*(f as *const F);
711 f(InetAddress::from_glib_borrow(this).unsafe_cast_ref())
712 }
713 }
714 unsafe {
715 let f: Box_<F> = Box_::new(f);
716 connect_raw(
717 self.as_ptr() as *mut _,
718 c"notify::is-multicast".as_ptr() as *const _,
719 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
720 notify_is_multicast_trampoline::<Self, F> as *const (),
721 )),
722 Box_::into_raw(f),
723 )
724 }
725 }
726
727 #[doc(alias = "is-site-local")]
728 fn connect_is_site_local_notify<F: Fn(&Self) + Send + Sync + 'static>(
729 &self,
730 f: F,
731 ) -> SignalHandlerId {
732 unsafe extern "C" fn notify_is_site_local_trampoline<
733 P: IsA<InetAddress>,
734 F: Fn(&P) + Send + Sync + 'static,
735 >(
736 this: *mut ffi::GInetAddress,
737 _param_spec: glib::ffi::gpointer,
738 f: glib::ffi::gpointer,
739 ) {
740 unsafe {
741 let f: &F = &*(f as *const F);
742 f(InetAddress::from_glib_borrow(this).unsafe_cast_ref())
743 }
744 }
745 unsafe {
746 let f: Box_<F> = Box_::new(f);
747 connect_raw(
748 self.as_ptr() as *mut _,
749 c"notify::is-site-local".as_ptr() as *const _,
750 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
751 notify_is_site_local_trampoline::<Self, F> as *const (),
752 )),
753 Box_::into_raw(f),
754 )
755 }
756 }
757}
758
759impl<O: IsA<InetAddress>> InetAddressExt for O {}