Просмотр исходного кода

totemip.h: const'ify

* include/corosync/totem/totemip.h: Add const to prototypes.
* exec/totemip.c (totemip_equal, totemip_copy): Adjust.
(totemip_copy_endian_convert, totemip_localhost_check): Likewise.
(totemip_sockaddr_to_totemip_convert): Likewise.

git-svn-id: http://svn.fedorahosted.org/svn/corosync/trunk@2012 fd59a12c-fef9-0310-b244-a6a79926bd2f
Jim Meyering 17 лет назад
Родитель
Сommit
eb5919f0cc
2 измененных файлов с 28 добавлено и 15 удалено
  1. 12 7
      exec/totemip.c
  2. 16 8
      include/corosync/totem/totemip.h

+ 12 - 7
exec/totemip.c

@@ -87,7 +87,8 @@ void totemip_nosigpipe(int s)
 #endif
 #endif
 
 
 /* Compare two addresses */
 /* Compare two addresses */
-int totemip_equal(struct totem_ip_address *addr1, struct totem_ip_address *addr2)
+int totemip_equal(const struct totem_ip_address *addr1,
+		  const struct totem_ip_address *addr2)
 {
 {
 	int addrlen = 0;
 	int addrlen = 0;
 
 
@@ -110,12 +111,14 @@ int totemip_equal(struct totem_ip_address *addr1, struct totem_ip_address *addr2
 }
 }
 
 
 /* Copy a totem_ip_address */
 /* Copy a totem_ip_address */
-void totemip_copy(struct totem_ip_address *addr1, struct totem_ip_address *addr2)
+void totemip_copy(struct totem_ip_address *addr1,
+		  const struct totem_ip_address *addr2)
 {
 {
 	memcpy(addr1, addr2, sizeof(struct totem_ip_address));
 	memcpy(addr1, addr2, sizeof(struct totem_ip_address));
 }
 }
 
 
-void totemip_copy_endian_convert(struct totem_ip_address *addr1, struct totem_ip_address *addr2)
+void totemip_copy_endian_convert(struct totem_ip_address *addr1,
+				 const struct totem_ip_address *addr2)
 {
 {
 	addr1->nodeid = swab32(addr2->nodeid);
 	addr1->nodeid = swab32(addr2->nodeid);
 	addr1->family = swab16(addr2->family);
 	addr1->family = swab16(addr2->family);
@@ -198,7 +201,7 @@ int totemip_localhost(int family, struct totem_ip_address *localhost)
 	return 0;
 	return 0;
 }
 }
 
 
-int totemip_localhost_check(struct totem_ip_address *addr)
+int totemip_localhost_check(const struct totem_ip_address *addr)
 {
 {
 	struct totem_ip_address localhost;
 	struct totem_ip_address localhost;
 
 
@@ -287,7 +290,8 @@ int totemip_parse(struct totem_ip_address *totemip, const char *addr, int family
 }
 }
 
 
 /* Make a sockaddr_* into a totem_ip_address */
 /* Make a sockaddr_* into a totem_ip_address */
-int totemip_sockaddr_to_totemip_convert(struct sockaddr_storage *saddr, struct totem_ip_address *ip_addr)
+int totemip_sockaddr_to_totemip_convert(const struct sockaddr_storage *saddr,
+					struct totem_ip_address *ip_addr)
 {
 {
 	int ret = -1;
 	int ret = -1;
 
 
@@ -295,14 +299,15 @@ int totemip_sockaddr_to_totemip_convert(struct sockaddr_storage *saddr, struct t
 	ip_addr->nodeid = 0;
 	ip_addr->nodeid = 0;
 
 
 	if (saddr->ss_family == AF_INET) {
 	if (saddr->ss_family == AF_INET) {
-		struct sockaddr_in *sin = (struct sockaddr_in *)saddr;
+		const struct sockaddr_in *sin = (const struct sockaddr_in *)saddr;
 
 
 		memcpy(ip_addr->addr, &sin->sin_addr, sizeof(struct in_addr));
 		memcpy(ip_addr->addr, &sin->sin_addr, sizeof(struct in_addr));
 		ret = 0;
 		ret = 0;
 	}
 	}
 
 
 	if (saddr->ss_family == AF_INET6) {
 	if (saddr->ss_family == AF_INET6) {
-		struct sockaddr_in6 *sin = (struct sockaddr_in6 *)saddr;
+		const struct sockaddr_in6 *sin
+		  = (const struct sockaddr_in6 *)saddr;
 
 
 		memcpy(ip_addr->addr, &sin->sin6_addr, sizeof(struct in6_addr));
 		memcpy(ip_addr->addr, &sin->sin6_addr, sizeof(struct in6_addr));
 
 

+ 16 - 8
include/corosync/totem/totemip.h

@@ -6,7 +6,7 @@
  * Author: Patrick Caulfield (pcaulfie@redhat.com)
  * Author: Patrick Caulfield (pcaulfie@redhat.com)
  *
  *
  * This software licensed under BSD license, the text of which follows:
  * This software licensed under BSD license, the text of which follows:
- * 
+ *
  * Redistribution and use in source and binary forms, with or without
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions are met:
  * modification, are permitted provided that the following conditions are met:
  *
  *
@@ -61,26 +61,34 @@ struct totem_ip_address
 } __attribute__((packed));
 } __attribute__((packed));
 
 
 
 
-extern int totemip_equal(struct totem_ip_address *addr1, struct totem_ip_address *addr2);
+extern int totemip_equal(const struct totem_ip_address *addr1,
+			 const struct totem_ip_address *addr2);
 extern int totemip_compare(const void *a, const void *b);
 extern int totemip_compare(const void *a, const void *b);
-extern void totemip_copy(struct totem_ip_address *addr1, struct totem_ip_address *addr2);
-extern void totemip_copy_endian_convert(struct totem_ip_address *addr1, struct totem_ip_address *addr2);
+extern void totemip_copy(struct totem_ip_address *addr1,
+			 const struct totem_ip_address *addr2);
+extern void totemip_copy_endian_convert(struct totem_ip_address *addr1,
+					const struct totem_ip_address *addr2);
 int totemip_localhost(int family, struct totem_ip_address *localhost);
 int totemip_localhost(int family, struct totem_ip_address *localhost);
-extern int totemip_localhost_check(struct totem_ip_address *addr);
+extern int totemip_localhost_check(const struct totem_ip_address *addr);
 extern const char *totemip_print(const struct totem_ip_address *addr);
 extern const char *totemip_print(const struct totem_ip_address *addr);
-extern int totemip_sockaddr_to_totemip_convert(struct sockaddr_storage *saddr, struct totem_ip_address *ip_addr);
+extern int totemip_sockaddr_to_totemip_convert(const struct sockaddr_storage *saddr,
+					       struct totem_ip_address *ip_addr);
 extern int totemip_totemip_to_sockaddr_convert(struct totem_ip_address *ip_addr,
 extern int totemip_totemip_to_sockaddr_convert(struct totem_ip_address *ip_addr,
 					       uint16_t port, struct sockaddr_storage *saddr, int *addrlen);
 					       uint16_t port, struct sockaddr_storage *saddr, int *addrlen);
 extern int totemip_parse(struct totem_ip_address *totemip, const char *addr,
 extern int totemip_parse(struct totem_ip_address *totemip, const char *addr,
 			 int family);
 			 int family);
-extern int totemip_iface_check(struct totem_ip_address *bindnet, struct totem_ip_address *boundto, int *interface_up, int *interface_num, int mask_high_bit);
+extern int totemip_iface_check(struct totem_ip_address *bindnet,
+			       struct totem_ip_address *boundto,
+			       int *interface_up,
+			       int *interface_num,
+			       int mask_high_bit);
 
 
 /* These two simulate a zero in_addr by clearing the family field */
 /* These two simulate a zero in_addr by clearing the family field */
 static inline void totemip_zero_set(struct totem_ip_address *addr)
 static inline void totemip_zero_set(struct totem_ip_address *addr)
 {
 {
 	addr->family = 0;
 	addr->family = 0;
 }
 }
-static inline int totemip_zero_check(struct totem_ip_address *addr)
+static inline int totemip_zero_check(const struct totem_ip_address *addr)
 {
 {
 	return (addr->family == 0);
 	return (addr->family == 0);
 }
 }