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")]
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 let f: &F = &*(f as *const F);
462 f(InetAddress::from_glib_borrow(this).unsafe_cast_ref())
463 }
464 unsafe {
465 let f: Box_<F> = Box_::new(f);
466 connect_raw(
467 self.as_ptr() as *mut _,
468 c"notify::is-any".as_ptr() as *const _,
469 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
470 notify_is_any_trampoline::<Self, F> as *const (),
471 )),
472 Box_::into_raw(f),
473 )
474 }
475 }
476
477 #[doc(alias = "is-link-local")]
478 fn connect_is_link_local_notify<F: Fn(&Self) + Send + Sync + 'static>(
479 &self,
480 f: F,
481 ) -> SignalHandlerId {
482 unsafe extern "C" fn notify_is_link_local_trampoline<
483 P: IsA<InetAddress>,
484 F: Fn(&P) + Send + Sync + 'static,
485 >(
486 this: *mut ffi::GInetAddress,
487 _param_spec: glib::ffi::gpointer,
488 f: glib::ffi::gpointer,
489 ) {
490 let f: &F = &*(f as *const F);
491 f(InetAddress::from_glib_borrow(this).unsafe_cast_ref())
492 }
493 unsafe {
494 let f: Box_<F> = Box_::new(f);
495 connect_raw(
496 self.as_ptr() as *mut _,
497 c"notify::is-link-local".as_ptr() as *const _,
498 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
499 notify_is_link_local_trampoline::<Self, F> as *const (),
500 )),
501 Box_::into_raw(f),
502 )
503 }
504 }
505
506 #[doc(alias = "is-loopback")]
507 fn connect_is_loopback_notify<F: Fn(&Self) + Send + Sync + 'static>(
508 &self,
509 f: F,
510 ) -> SignalHandlerId {
511 unsafe extern "C" fn notify_is_loopback_trampoline<
512 P: IsA<InetAddress>,
513 F: Fn(&P) + Send + Sync + 'static,
514 >(
515 this: *mut ffi::GInetAddress,
516 _param_spec: glib::ffi::gpointer,
517 f: glib::ffi::gpointer,
518 ) {
519 let f: &F = &*(f as *const F);
520 f(InetAddress::from_glib_borrow(this).unsafe_cast_ref())
521 }
522 unsafe {
523 let f: Box_<F> = Box_::new(f);
524 connect_raw(
525 self.as_ptr() as *mut _,
526 c"notify::is-loopback".as_ptr() as *const _,
527 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
528 notify_is_loopback_trampoline::<Self, F> as *const (),
529 )),
530 Box_::into_raw(f),
531 )
532 }
533 }
534
535 #[doc(alias = "is-mc-global")]
536 fn connect_is_mc_global_notify<F: Fn(&Self) + Send + Sync + 'static>(
537 &self,
538 f: F,
539 ) -> SignalHandlerId {
540 unsafe extern "C" fn notify_is_mc_global_trampoline<
541 P: IsA<InetAddress>,
542 F: Fn(&P) + Send + Sync + 'static,
543 >(
544 this: *mut ffi::GInetAddress,
545 _param_spec: glib::ffi::gpointer,
546 f: glib::ffi::gpointer,
547 ) {
548 let f: &F = &*(f as *const F);
549 f(InetAddress::from_glib_borrow(this).unsafe_cast_ref())
550 }
551 unsafe {
552 let f: Box_<F> = Box_::new(f);
553 connect_raw(
554 self.as_ptr() as *mut _,
555 c"notify::is-mc-global".as_ptr() as *const _,
556 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
557 notify_is_mc_global_trampoline::<Self, F> as *const (),
558 )),
559 Box_::into_raw(f),
560 )
561 }
562 }
563
564 #[doc(alias = "is-mc-link-local")]
565 fn connect_is_mc_link_local_notify<F: Fn(&Self) + Send + Sync + 'static>(
566 &self,
567 f: F,
568 ) -> SignalHandlerId {
569 unsafe extern "C" fn notify_is_mc_link_local_trampoline<
570 P: IsA<InetAddress>,
571 F: Fn(&P) + Send + Sync + 'static,
572 >(
573 this: *mut ffi::GInetAddress,
574 _param_spec: glib::ffi::gpointer,
575 f: glib::ffi::gpointer,
576 ) {
577 let f: &F = &*(f as *const F);
578 f(InetAddress::from_glib_borrow(this).unsafe_cast_ref())
579 }
580 unsafe {
581 let f: Box_<F> = Box_::new(f);
582 connect_raw(
583 self.as_ptr() as *mut _,
584 c"notify::is-mc-link-local".as_ptr() as *const _,
585 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
586 notify_is_mc_link_local_trampoline::<Self, F> as *const (),
587 )),
588 Box_::into_raw(f),
589 )
590 }
591 }
592
593 #[doc(alias = "is-mc-node-local")]
594 fn connect_is_mc_node_local_notify<F: Fn(&Self) + Send + Sync + 'static>(
595 &self,
596 f: F,
597 ) -> SignalHandlerId {
598 unsafe extern "C" fn notify_is_mc_node_local_trampoline<
599 P: IsA<InetAddress>,
600 F: Fn(&P) + Send + Sync + 'static,
601 >(
602 this: *mut ffi::GInetAddress,
603 _param_spec: glib::ffi::gpointer,
604 f: glib::ffi::gpointer,
605 ) {
606 let f: &F = &*(f as *const F);
607 f(InetAddress::from_glib_borrow(this).unsafe_cast_ref())
608 }
609 unsafe {
610 let f: Box_<F> = Box_::new(f);
611 connect_raw(
612 self.as_ptr() as *mut _,
613 c"notify::is-mc-node-local".as_ptr() as *const _,
614 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
615 notify_is_mc_node_local_trampoline::<Self, F> as *const (),
616 )),
617 Box_::into_raw(f),
618 )
619 }
620 }
621
622 #[doc(alias = "is-mc-org-local")]
623 fn connect_is_mc_org_local_notify<F: Fn(&Self) + Send + Sync + 'static>(
624 &self,
625 f: F,
626 ) -> SignalHandlerId {
627 unsafe extern "C" fn notify_is_mc_org_local_trampoline<
628 P: IsA<InetAddress>,
629 F: Fn(&P) + Send + Sync + 'static,
630 >(
631 this: *mut ffi::GInetAddress,
632 _param_spec: glib::ffi::gpointer,
633 f: glib::ffi::gpointer,
634 ) {
635 let f: &F = &*(f as *const F);
636 f(InetAddress::from_glib_borrow(this).unsafe_cast_ref())
637 }
638 unsafe {
639 let f: Box_<F> = Box_::new(f);
640 connect_raw(
641 self.as_ptr() as *mut _,
642 c"notify::is-mc-org-local".as_ptr() as *const _,
643 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
644 notify_is_mc_org_local_trampoline::<Self, F> as *const (),
645 )),
646 Box_::into_raw(f),
647 )
648 }
649 }
650
651 #[doc(alias = "is-mc-site-local")]
652 fn connect_is_mc_site_local_notify<F: Fn(&Self) + Send + Sync + 'static>(
653 &self,
654 f: F,
655 ) -> SignalHandlerId {
656 unsafe extern "C" fn notify_is_mc_site_local_trampoline<
657 P: IsA<InetAddress>,
658 F: Fn(&P) + Send + Sync + 'static,
659 >(
660 this: *mut ffi::GInetAddress,
661 _param_spec: glib::ffi::gpointer,
662 f: glib::ffi::gpointer,
663 ) {
664 let f: &F = &*(f as *const F);
665 f(InetAddress::from_glib_borrow(this).unsafe_cast_ref())
666 }
667 unsafe {
668 let f: Box_<F> = Box_::new(f);
669 connect_raw(
670 self.as_ptr() as *mut _,
671 c"notify::is-mc-site-local".as_ptr() as *const _,
672 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
673 notify_is_mc_site_local_trampoline::<Self, F> as *const (),
674 )),
675 Box_::into_raw(f),
676 )
677 }
678 }
679
680 #[doc(alias = "is-multicast")]
681 fn connect_is_multicast_notify<F: Fn(&Self) + Send + Sync + 'static>(
682 &self,
683 f: F,
684 ) -> SignalHandlerId {
685 unsafe extern "C" fn notify_is_multicast_trampoline<
686 P: IsA<InetAddress>,
687 F: Fn(&P) + Send + Sync + 'static,
688 >(
689 this: *mut ffi::GInetAddress,
690 _param_spec: glib::ffi::gpointer,
691 f: glib::ffi::gpointer,
692 ) {
693 let f: &F = &*(f as *const F);
694 f(InetAddress::from_glib_borrow(this).unsafe_cast_ref())
695 }
696 unsafe {
697 let f: Box_<F> = Box_::new(f);
698 connect_raw(
699 self.as_ptr() as *mut _,
700 c"notify::is-multicast".as_ptr() as *const _,
701 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
702 notify_is_multicast_trampoline::<Self, F> as *const (),
703 )),
704 Box_::into_raw(f),
705 )
706 }
707 }
708
709 #[doc(alias = "is-site-local")]
710 fn connect_is_site_local_notify<F: Fn(&Self) + Send + Sync + 'static>(
711 &self,
712 f: F,
713 ) -> SignalHandlerId {
714 unsafe extern "C" fn notify_is_site_local_trampoline<
715 P: IsA<InetAddress>,
716 F: Fn(&P) + Send + Sync + 'static,
717 >(
718 this: *mut ffi::GInetAddress,
719 _param_spec: glib::ffi::gpointer,
720 f: glib::ffi::gpointer,
721 ) {
722 let f: &F = &*(f as *const F);
723 f(InetAddress::from_glib_borrow(this).unsafe_cast_ref())
724 }
725 unsafe {
726 let f: Box_<F> = Box_::new(f);
727 connect_raw(
728 self.as_ptr() as *mut _,
729 c"notify::is-site-local".as_ptr() as *const _,
730 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
731 notify_is_site_local_trampoline::<Self, F> as *const (),
732 )),
733 Box_::into_raw(f),
734 )
735 }
736 }
737}
738
739impl<O: IsA<InetAddress>> InetAddressExt for O {}