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
178mod sealed {
179 pub trait Sealed {}
180 impl<T: super::IsA<super::InetAddress>> Sealed for T {}
181}
182
183pub trait InetAddressExt: IsA<InetAddress> + sealed::Sealed + 'static {
189 #[doc(alias = "g_inet_address_equal")]
190 fn equal(&self, other_address: &impl IsA<InetAddress>) -> bool {
191 unsafe {
192 from_glib(ffi::g_inet_address_equal(
193 self.as_ref().to_glib_none().0,
194 other_address.as_ref().to_glib_none().0,
195 ))
196 }
197 }
198
199 #[doc(alias = "g_inet_address_get_family")]
205 #[doc(alias = "get_family")]
206 fn family(&self) -> SocketFamily {
207 unsafe {
208 from_glib(ffi::g_inet_address_get_family(
209 self.as_ref().to_glib_none().0,
210 ))
211 }
212 }
213
214 #[doc(alias = "g_inet_address_get_is_any")]
220 #[doc(alias = "get_is_any")]
221 #[doc(alias = "is-any")]
222 fn is_any(&self) -> bool {
223 unsafe {
224 from_glib(ffi::g_inet_address_get_is_any(
225 self.as_ref().to_glib_none().0,
226 ))
227 }
228 }
229
230 #[doc(alias = "g_inet_address_get_is_link_local")]
238 #[doc(alias = "get_is_link_local")]
239 #[doc(alias = "is-link-local")]
240 fn is_link_local(&self) -> bool {
241 unsafe {
242 from_glib(ffi::g_inet_address_get_is_link_local(
243 self.as_ref().to_glib_none().0,
244 ))
245 }
246 }
247
248 #[doc(alias = "g_inet_address_get_is_loopback")]
254 #[doc(alias = "get_is_loopback")]
255 #[doc(alias = "is-loopback")]
256 fn is_loopback(&self) -> bool {
257 unsafe {
258 from_glib(ffi::g_inet_address_get_is_loopback(
259 self.as_ref().to_glib_none().0,
260 ))
261 }
262 }
263
264 #[doc(alias = "g_inet_address_get_is_mc_global")]
270 #[doc(alias = "get_is_mc_global")]
271 #[doc(alias = "is-mc-global")]
272 fn is_mc_global(&self) -> bool {
273 unsafe {
274 from_glib(ffi::g_inet_address_get_is_mc_global(
275 self.as_ref().to_glib_none().0,
276 ))
277 }
278 }
279
280 #[doc(alias = "g_inet_address_get_is_mc_link_local")]
286 #[doc(alias = "get_is_mc_link_local")]
287 #[doc(alias = "is-mc-link-local")]
288 fn is_mc_link_local(&self) -> bool {
289 unsafe {
290 from_glib(ffi::g_inet_address_get_is_mc_link_local(
291 self.as_ref().to_glib_none().0,
292 ))
293 }
294 }
295
296 #[doc(alias = "g_inet_address_get_is_mc_node_local")]
302 #[doc(alias = "get_is_mc_node_local")]
303 #[doc(alias = "is-mc-node-local")]
304 fn is_mc_node_local(&self) -> bool {
305 unsafe {
306 from_glib(ffi::g_inet_address_get_is_mc_node_local(
307 self.as_ref().to_glib_none().0,
308 ))
309 }
310 }
311
312 #[doc(alias = "g_inet_address_get_is_mc_org_local")]
318 #[doc(alias = "get_is_mc_org_local")]
319 #[doc(alias = "is-mc-org-local")]
320 fn is_mc_org_local(&self) -> bool {
321 unsafe {
322 from_glib(ffi::g_inet_address_get_is_mc_org_local(
323 self.as_ref().to_glib_none().0,
324 ))
325 }
326 }
327
328 #[doc(alias = "g_inet_address_get_is_mc_site_local")]
334 #[doc(alias = "get_is_mc_site_local")]
335 #[doc(alias = "is-mc-site-local")]
336 fn is_mc_site_local(&self) -> bool {
337 unsafe {
338 from_glib(ffi::g_inet_address_get_is_mc_site_local(
339 self.as_ref().to_glib_none().0,
340 ))
341 }
342 }
343
344 #[doc(alias = "g_inet_address_get_is_multicast")]
350 #[doc(alias = "get_is_multicast")]
351 #[doc(alias = "is-multicast")]
352 fn is_multicast(&self) -> bool {
353 unsafe {
354 from_glib(ffi::g_inet_address_get_is_multicast(
355 self.as_ref().to_glib_none().0,
356 ))
357 }
358 }
359
360 #[doc(alias = "g_inet_address_get_is_site_local")]
369 #[doc(alias = "get_is_site_local")]
370 #[doc(alias = "is-site-local")]
371 fn is_site_local(&self) -> bool {
372 unsafe {
373 from_glib(ffi::g_inet_address_get_is_site_local(
374 self.as_ref().to_glib_none().0,
375 ))
376 }
377 }
378
379 #[doc(alias = "g_inet_address_get_native_size")]
386 #[doc(alias = "get_native_size")]
387 fn native_size(&self) -> usize {
388 unsafe { ffi::g_inet_address_get_native_size(self.as_ref().to_glib_none().0) }
389 }
390
391 #[doc(alias = "g_inet_address_to_string")]
398 #[doc(alias = "to_string")]
399 fn to_str(&self) -> glib::GString {
400 unsafe {
401 from_glib_full(ffi::g_inet_address_to_string(
402 self.as_ref().to_glib_none().0,
403 ))
404 }
405 }
406
407 #[doc(alias = "is-any")]
412 fn connect_is_any_notify<F: Fn(&Self) + Send + Sync + 'static>(&self, f: F) -> SignalHandlerId {
413 unsafe extern "C" fn notify_is_any_trampoline<
414 P: IsA<InetAddress>,
415 F: Fn(&P) + Send + Sync + 'static,
416 >(
417 this: *mut ffi::GInetAddress,
418 _param_spec: glib::ffi::gpointer,
419 f: glib::ffi::gpointer,
420 ) {
421 let f: &F = &*(f as *const F);
422 f(InetAddress::from_glib_borrow(this).unsafe_cast_ref())
423 }
424 unsafe {
425 let f: Box_<F> = Box_::new(f);
426 connect_raw(
427 self.as_ptr() as *mut _,
428 b"notify::is-any\0".as_ptr() as *const _,
429 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
430 notify_is_any_trampoline::<Self, F> as *const (),
431 )),
432 Box_::into_raw(f),
433 )
434 }
435 }
436
437 #[doc(alias = "is-link-local")]
438 fn connect_is_link_local_notify<F: Fn(&Self) + Send + Sync + 'static>(
439 &self,
440 f: F,
441 ) -> SignalHandlerId {
442 unsafe extern "C" fn notify_is_link_local_trampoline<
443 P: IsA<InetAddress>,
444 F: Fn(&P) + Send + Sync + 'static,
445 >(
446 this: *mut ffi::GInetAddress,
447 _param_spec: glib::ffi::gpointer,
448 f: glib::ffi::gpointer,
449 ) {
450 let f: &F = &*(f as *const F);
451 f(InetAddress::from_glib_borrow(this).unsafe_cast_ref())
452 }
453 unsafe {
454 let f: Box_<F> = Box_::new(f);
455 connect_raw(
456 self.as_ptr() as *mut _,
457 b"notify::is-link-local\0".as_ptr() as *const _,
458 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
459 notify_is_link_local_trampoline::<Self, F> as *const (),
460 )),
461 Box_::into_raw(f),
462 )
463 }
464 }
465
466 #[doc(alias = "is-loopback")]
467 fn connect_is_loopback_notify<F: Fn(&Self) + Send + Sync + 'static>(
468 &self,
469 f: F,
470 ) -> SignalHandlerId {
471 unsafe extern "C" fn notify_is_loopback_trampoline<
472 P: IsA<InetAddress>,
473 F: Fn(&P) + Send + Sync + 'static,
474 >(
475 this: *mut ffi::GInetAddress,
476 _param_spec: glib::ffi::gpointer,
477 f: glib::ffi::gpointer,
478 ) {
479 let f: &F = &*(f as *const F);
480 f(InetAddress::from_glib_borrow(this).unsafe_cast_ref())
481 }
482 unsafe {
483 let f: Box_<F> = Box_::new(f);
484 connect_raw(
485 self.as_ptr() as *mut _,
486 b"notify::is-loopback\0".as_ptr() as *const _,
487 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
488 notify_is_loopback_trampoline::<Self, F> as *const (),
489 )),
490 Box_::into_raw(f),
491 )
492 }
493 }
494
495 #[doc(alias = "is-mc-global")]
496 fn connect_is_mc_global_notify<F: Fn(&Self) + Send + Sync + 'static>(
497 &self,
498 f: F,
499 ) -> SignalHandlerId {
500 unsafe extern "C" fn notify_is_mc_global_trampoline<
501 P: IsA<InetAddress>,
502 F: Fn(&P) + Send + Sync + 'static,
503 >(
504 this: *mut ffi::GInetAddress,
505 _param_spec: glib::ffi::gpointer,
506 f: glib::ffi::gpointer,
507 ) {
508 let f: &F = &*(f as *const F);
509 f(InetAddress::from_glib_borrow(this).unsafe_cast_ref())
510 }
511 unsafe {
512 let f: Box_<F> = Box_::new(f);
513 connect_raw(
514 self.as_ptr() as *mut _,
515 b"notify::is-mc-global\0".as_ptr() as *const _,
516 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
517 notify_is_mc_global_trampoline::<Self, F> as *const (),
518 )),
519 Box_::into_raw(f),
520 )
521 }
522 }
523
524 #[doc(alias = "is-mc-link-local")]
525 fn connect_is_mc_link_local_notify<F: Fn(&Self) + Send + Sync + 'static>(
526 &self,
527 f: F,
528 ) -> SignalHandlerId {
529 unsafe extern "C" fn notify_is_mc_link_local_trampoline<
530 P: IsA<InetAddress>,
531 F: Fn(&P) + Send + Sync + 'static,
532 >(
533 this: *mut ffi::GInetAddress,
534 _param_spec: glib::ffi::gpointer,
535 f: glib::ffi::gpointer,
536 ) {
537 let f: &F = &*(f as *const F);
538 f(InetAddress::from_glib_borrow(this).unsafe_cast_ref())
539 }
540 unsafe {
541 let f: Box_<F> = Box_::new(f);
542 connect_raw(
543 self.as_ptr() as *mut _,
544 b"notify::is-mc-link-local\0".as_ptr() as *const _,
545 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
546 notify_is_mc_link_local_trampoline::<Self, F> as *const (),
547 )),
548 Box_::into_raw(f),
549 )
550 }
551 }
552
553 #[doc(alias = "is-mc-node-local")]
554 fn connect_is_mc_node_local_notify<F: Fn(&Self) + Send + Sync + 'static>(
555 &self,
556 f: F,
557 ) -> SignalHandlerId {
558 unsafe extern "C" fn notify_is_mc_node_local_trampoline<
559 P: IsA<InetAddress>,
560 F: Fn(&P) + Send + Sync + 'static,
561 >(
562 this: *mut ffi::GInetAddress,
563 _param_spec: glib::ffi::gpointer,
564 f: glib::ffi::gpointer,
565 ) {
566 let f: &F = &*(f as *const F);
567 f(InetAddress::from_glib_borrow(this).unsafe_cast_ref())
568 }
569 unsafe {
570 let f: Box_<F> = Box_::new(f);
571 connect_raw(
572 self.as_ptr() as *mut _,
573 b"notify::is-mc-node-local\0".as_ptr() as *const _,
574 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
575 notify_is_mc_node_local_trampoline::<Self, F> as *const (),
576 )),
577 Box_::into_raw(f),
578 )
579 }
580 }
581
582 #[doc(alias = "is-mc-org-local")]
583 fn connect_is_mc_org_local_notify<F: Fn(&Self) + Send + Sync + 'static>(
584 &self,
585 f: F,
586 ) -> SignalHandlerId {
587 unsafe extern "C" fn notify_is_mc_org_local_trampoline<
588 P: IsA<InetAddress>,
589 F: Fn(&P) + Send + Sync + 'static,
590 >(
591 this: *mut ffi::GInetAddress,
592 _param_spec: glib::ffi::gpointer,
593 f: glib::ffi::gpointer,
594 ) {
595 let f: &F = &*(f as *const F);
596 f(InetAddress::from_glib_borrow(this).unsafe_cast_ref())
597 }
598 unsafe {
599 let f: Box_<F> = Box_::new(f);
600 connect_raw(
601 self.as_ptr() as *mut _,
602 b"notify::is-mc-org-local\0".as_ptr() as *const _,
603 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
604 notify_is_mc_org_local_trampoline::<Self, F> as *const (),
605 )),
606 Box_::into_raw(f),
607 )
608 }
609 }
610
611 #[doc(alias = "is-mc-site-local")]
612 fn connect_is_mc_site_local_notify<F: Fn(&Self) + Send + Sync + 'static>(
613 &self,
614 f: F,
615 ) -> SignalHandlerId {
616 unsafe extern "C" fn notify_is_mc_site_local_trampoline<
617 P: IsA<InetAddress>,
618 F: Fn(&P) + Send + Sync + 'static,
619 >(
620 this: *mut ffi::GInetAddress,
621 _param_spec: glib::ffi::gpointer,
622 f: glib::ffi::gpointer,
623 ) {
624 let f: &F = &*(f as *const F);
625 f(InetAddress::from_glib_borrow(this).unsafe_cast_ref())
626 }
627 unsafe {
628 let f: Box_<F> = Box_::new(f);
629 connect_raw(
630 self.as_ptr() as *mut _,
631 b"notify::is-mc-site-local\0".as_ptr() as *const _,
632 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
633 notify_is_mc_site_local_trampoline::<Self, F> as *const (),
634 )),
635 Box_::into_raw(f),
636 )
637 }
638 }
639
640 #[doc(alias = "is-multicast")]
641 fn connect_is_multicast_notify<F: Fn(&Self) + Send + Sync + 'static>(
642 &self,
643 f: F,
644 ) -> SignalHandlerId {
645 unsafe extern "C" fn notify_is_multicast_trampoline<
646 P: IsA<InetAddress>,
647 F: Fn(&P) + Send + Sync + 'static,
648 >(
649 this: *mut ffi::GInetAddress,
650 _param_spec: glib::ffi::gpointer,
651 f: glib::ffi::gpointer,
652 ) {
653 let f: &F = &*(f as *const F);
654 f(InetAddress::from_glib_borrow(this).unsafe_cast_ref())
655 }
656 unsafe {
657 let f: Box_<F> = Box_::new(f);
658 connect_raw(
659 self.as_ptr() as *mut _,
660 b"notify::is-multicast\0".as_ptr() as *const _,
661 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
662 notify_is_multicast_trampoline::<Self, F> as *const (),
663 )),
664 Box_::into_raw(f),
665 )
666 }
667 }
668
669 #[doc(alias = "is-site-local")]
670 fn connect_is_site_local_notify<F: Fn(&Self) + Send + Sync + 'static>(
671 &self,
672 f: F,
673 ) -> SignalHandlerId {
674 unsafe extern "C" fn notify_is_site_local_trampoline<
675 P: IsA<InetAddress>,
676 F: Fn(&P) + Send + Sync + 'static,
677 >(
678 this: *mut ffi::GInetAddress,
679 _param_spec: glib::ffi::gpointer,
680 f: glib::ffi::gpointer,
681 ) {
682 let f: &F = &*(f as *const F);
683 f(InetAddress::from_glib_borrow(this).unsafe_cast_ref())
684 }
685 unsafe {
686 let f: Box_<F> = Box_::new(f);
687 connect_raw(
688 self.as_ptr() as *mut _,
689 b"notify::is-site-local\0".as_ptr() as *const _,
690 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
691 notify_is_site_local_trampoline::<Self, F> as *const (),
692 )),
693 Box_::into_raw(f),
694 )
695 }
696 }
697}
698
699impl<O: IsA<InetAddress>> InetAddressExt for O {}