[quagga-dev 12196] [PATCH 3/7] sockunion: constify sockunion api

Timo Teräs timo.teras at iki.fi
Wed Apr 29 07:43:01 BST 2015


Add const to read-only api calls.

Signed-off-by: Timo Teräs <timo.teras at iki.fi>
---
 lib/sockunion.c | 22 +++++++++++-----------
 lib/sockunion.h | 14 +++++++-------
 2 files changed, 18 insertions(+), 18 deletions(-)

diff --git a/lib/sockunion.c b/lib/sockunion.c
index 1a355d3..5e6cf68 100644
--- a/lib/sockunion.c
+++ b/lib/sockunion.c
@@ -116,7 +116,7 @@ inet_ntop (int family, const void *addrptr, char *strptr, size_t len)
 #endif /* ! HAVE_INET_NTOP */
 
 const char *
-inet_sutop (union sockunion *su, char *str)
+inet_sutop (const union sockunion *su, char *str)
 {
   switch (su->sa.sa_family)
     {
@@ -163,7 +163,7 @@ str2sockunion (const char *str, union sockunion *su)
 }
 
 const char *
-sockunion2str (union sockunion *su, char *buf, size_t len)
+sockunion2str (const union sockunion *su, char *buf, size_t len)
 {
   if  (su->sa.sa_family == AF_INET)
     return inet_ntop (AF_INET, &su->sin.sin_addr, buf, len);
@@ -207,7 +207,7 @@ sockunion_normalise_mapped (union sockunion *su)
 
 /* Return socket of sockunion. */
 int
-sockunion_socket (union sockunion *su)
+sockunion_socket (const union sockunion *su)
 {
   int sock;
 
@@ -237,7 +237,7 @@ sockunion_accept (int sock, union sockunion *su)
 
 /* Return sizeof union sockunion.  */
 static int
-sockunion_sizeof (union sockunion *su)
+sockunion_sizeof (const union sockunion *su)
 {
   int ret;
 
@@ -258,7 +258,7 @@ sockunion_sizeof (union sockunion *su)
 
 /* return sockunion structure : this function should be revised. */
 static const char *
-sockunion_log (union sockunion *su, char *buf, size_t len)
+sockunion_log (const union sockunion *su, char *buf, size_t len)
 {
   switch (su->sa.sa_family) 
     {
@@ -282,7 +282,7 @@ sockunion_log (union sockunion *su, char *buf, size_t len)
    0 : connect success
    1 : connect is in progress */
 enum connect_result
-sockunion_connect (int fd, union sockunion *peersu, unsigned short port,
+sockunion_connect (int fd, const union sockunion *peersu, unsigned short port,
 		   unsigned int ifindex)
 {
   int ret;
@@ -547,7 +547,7 @@ sockopt_v6only (int family, int sock)
 
 /* If same family and same prefix return 1. */
 int
-sockunion_same (union sockunion *su1, union sockunion *su2)
+sockunion_same (const union sockunion *su1, const union sockunion *su2)
 {
   int ret = 0;
 
@@ -666,7 +666,7 @@ sockunion_getpeername (int fd)
 
 /* Print sockunion structure */
 static void __attribute__ ((unused))
-sockunion_print (union sockunion *su)
+sockunion_print (const union sockunion *su)
 {
   if (su == NULL)
     return;
@@ -705,7 +705,7 @@ sockunion_print (union sockunion *su)
 
 #ifdef HAVE_IPV6
 static int
-in6addr_cmp (struct in6_addr *addr1, struct in6_addr *addr2)
+in6addr_cmp (const struct in6_addr *addr1, const struct in6_addr *addr2)
 {
   unsigned int i;
   u_char *p1, *p2;
@@ -725,7 +725,7 @@ in6addr_cmp (struct in6_addr *addr1, struct in6_addr *addr2)
 #endif /* HAVE_IPV6 */
 
 int
-sockunion_cmp (union sockunion *su1, union sockunion *su2)
+sockunion_cmp (const union sockunion *su1, const union sockunion *su2)
 {
   if (su1->sa.sa_family > su2->sa.sa_family)
     return 1;
@@ -750,7 +750,7 @@ sockunion_cmp (union sockunion *su1, union sockunion *su2)
 
 /* Duplicate sockunion. */
 union sockunion *
-sockunion_dup (union sockunion *su)
+sockunion_dup (const union sockunion *su)
 {
   union sockunion *dup = XCALLOC (MTYPE_SOCKUNION, sizeof (union sockunion));
   memcpy (dup, su, sizeof (union sockunion));
diff --git a/lib/sockunion.h b/lib/sockunion.h
index b9f3514..2c79fb5 100644
--- a/lib/sockunion.h
+++ b/lib/sockunion.h
@@ -84,9 +84,9 @@ enum connect_result
 
 /* Prototypes. */
 extern int str2sockunion (const char *, union sockunion *);
-extern const char *sockunion2str (union sockunion *, char *, size_t);
-extern int sockunion_cmp (union sockunion *, union sockunion *);
-extern int sockunion_same (union sockunion *, union sockunion *);
+extern const char *sockunion2str (const union sockunion *, char *, size_t);
+extern int sockunion_cmp (const union sockunion *, const union sockunion *);
+extern int sockunion_same (const union sockunion *, const union sockunion *);
 
 extern union sockunion *sockunion_str2su (const char *str);
 extern int sockunion_accept (int sock, union sockunion *);
@@ -99,14 +99,14 @@ extern int sockunion_bind (int sock, union sockunion *,
 extern int sockopt_ttl (int family, int sock, int ttl);
 extern int sockopt_minttl (int family, int sock, int minttl);
 extern int sockopt_cork (int sock, int onoff);
-extern int sockunion_socket (union sockunion *su);
-extern const char *inet_sutop (union sockunion *su, char *str);
-extern enum connect_result sockunion_connect (int fd, union sockunion *su, 
+extern int sockunion_socket (const union sockunion *su);
+extern const char *inet_sutop (const union sockunion *su, char *str);
+extern enum connect_result sockunion_connect (int fd, const union sockunion *su,
                                               unsigned short port,
                                               unsigned int);
 extern union sockunion *sockunion_getsockname (int);
 extern union sockunion *sockunion_getpeername (int);
-extern union sockunion *sockunion_dup (union sockunion *);
+extern union sockunion *sockunion_dup (const union sockunion *);
 extern void sockunion_free (union sockunion *);
 
 #ifndef HAVE_INET_NTOP
-- 
2.3.6





More information about the Quagga-dev mailing list