summaryrefslogtreecommitdiffstats
path: root/lib/sockunion.c
diff options
context:
space:
mode:
authorChris Hall <chris.hall@highwayman.com>2011-09-02 00:53:59 +0100
committerChris Hall <chris.hall@highwayman.com>2011-09-02 00:53:59 +0100
commit3690074a486cfada568975e287d9cbb9e687501f (patch)
treef6394c1ab1ca8381e9a77acca84f03dc701d10b2 /lib/sockunion.c
parent3f515315d5b17e432453eef67d7ac9e27bc39461 (diff)
downloadquagga-3690074a486cfada568975e287d9cbb9e687501f.tar.bz2
quagga-3690074a486cfada568975e287d9cbb9e687501f.tar.xz
Merging of euro_ix branch into pipework.
Bring in fixes for bgp dumping with pthreaded BGP Engine. Bring in new "show nexus xxx" command. Fix removal of '~' prompt.
Diffstat (limited to 'lib/sockunion.c')
-rw-r--r--lib/sockunion.c77
1 files changed, 76 insertions, 1 deletions
diff --git a/lib/sockunion.c b/lib/sockunion.c
index 9084c27e..9577b901 100644
--- a/lib/sockunion.c
+++ b/lib/sockunion.c
@@ -256,7 +256,32 @@ sockunion_init_new(sockunion su, sa_family_t family)
} ;
/*------------------------------------------------------------------------------
- * Get the length of the address in the given sockunion.
+ * Get the AFI for the sockaddr in the given sockunion.
+ *
+ * Returns zero if AF_UNSPEC or not any known address family.
+ */
+extern afi_t
+sockunion_get_afi(sockunion su)
+{
+ switch (su->sa.sa_family)
+ {
+ case AF_INET:
+ return AFI_IP ;
+
+#ifdef HAVE_IPV6
+ case AF_INET6:
+ return AFI_IP6 ;
+#endif
+
+ default:
+ return 0 ;
+ } ;
+} ;
+
+/*------------------------------------------------------------------------------
+ * Get the length of the sockaddr in the given sockunion.
+ *
+ * This length includes the family, port number, protocol address, etc.
*
* Returns zero if AF_UNSPEC or not any known address family.
*/
@@ -279,6 +304,56 @@ sockunion_get_len(sockunion su)
} ;
/*------------------------------------------------------------------------------
+ * Get the length of the protocol address in the given sockunion.
+ *
+ * This length is for just the IPv4, IPv6, etc. address.
+ *
+ * Returns zero if AF_UNSPEC or not any known address family.
+ */
+extern int
+sockunion_get_addr_len(sockunion su)
+{
+ switch (su->sa.sa_family)
+ {
+ case AF_INET:
+ return sizeof(su->sin.sin_addr.s_addr) ;
+
+#ifdef HAVE_IPV6
+ case AF_INET6:
+ return sizeof(su->sin6.sin6_addr.s6_addr) ;
+#endif
+
+ default:
+ return 0 ;
+ } ;
+} ;
+
+/*------------------------------------------------------------------------------
+ * Get pointer to the protocol address in the given sockunion.
+ *
+ * Note that IP and IPv6 addresses are in Network Order.
+ *
+ * Returns NULL if AF_UNSPEC or not any known address family.
+ */
+extern void*
+sockunion_get_addr(sockunion su)
+{
+ switch (su->sa.sa_family)
+ {
+ case AF_INET:
+ return &su->sin.sin_addr.s_addr ;
+
+#ifdef HAVE_IPV6
+ case AF_INET6:
+ return &su->sin6.sin6_addr.s6_addr ;
+#endif
+
+ default:
+ return 0 ;
+ } ;
+} ;
+
+/*------------------------------------------------------------------------------
* From the given string, fill in the given sockunion.
*
* Returns: 0 => OK -- sockunion filled in