aboutsummaryrefslogtreecommitdiff
path: root/src/util/strings.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/util/strings.c')
-rw-r--r--src/util/strings.c30
1 files changed, 16 insertions, 14 deletions
diff --git a/src/util/strings.c b/src/util/strings.c
index 0d58ec567..37500b45b 100644
--- a/src/util/strings.c
+++ b/src/util/strings.c
@@ -921,7 +921,7 @@ GNUNET_STRINGS_path_is_absolute (const char *filename, int can_be_uri,
921 */ 921 */
922int 922int
923GNUNET_STRINGS_check_filename (const char *filename, 923GNUNET_STRINGS_check_filename (const char *filename,
924 enum GNUNET_STRINGS_FilenameCheck checks) 924 enum GNUNET_STRINGS_FilenameCheck checks)
925{ 925{
926 struct stat st; 926 struct stat st;
927 if (filename == NULL || filename[0] == '\0') 927 if (filename == NULL || filename[0] == '\0')
@@ -954,8 +954,9 @@ GNUNET_STRINGS_check_filename (const char *filename,
954#define MAX_IPV4_ADDRLEN 21 954#define MAX_IPV4_ADDRLEN 21
955#define MAX_IP_ADDRLEN MAX_IPV6_ADDRLEN 955#define MAX_IP_ADDRLEN MAX_IPV6_ADDRLEN
956 956
957
957/** 958/**
958 * Tries to convert @zt_addr string to an IPv6 address. 959 * Tries to convert 'zt_addr' string to an IPv6 address.
959 * 960 *
960 * @param zt_addr 0-terminated string. May be mangled by the function. 961 * @param zt_addr 0-terminated string. May be mangled by the function.
961 * @param addrlen length of zt_addr (not counting 0-terminator). 962 * @param addrlen length of zt_addr (not counting 0-terminator).
@@ -965,8 +966,9 @@ GNUNET_STRINGS_check_filename (const char *filename,
965 * case the contents of r_buf are undefined. 966 * case the contents of r_buf are undefined.
966 */ 967 */
967int 968int
968GNUNET_STRINGS_to_address_ipv6 (char *zt_addr, uint16_t addrlen, 969GNUNET_STRINGS_to_address_ipv6 (const char *zt_addr,
969 struct sockaddr_in6 *r_buf) 970 uint16_t addrlen,
971 struct sockaddr_in6 *r_buf)
970{ 972{
971 int ret; 973 int ret;
972 char *port_colon; 974 char *port_colon;
@@ -982,7 +984,6 @@ GNUNET_STRINGS_to_address_ipv6 (char *zt_addr, uint16_t addrlen,
982 if (ret != 1 || port > 65535) 984 if (ret != 1 || port > 65535)
983 return GNUNET_SYSERR; 985 return GNUNET_SYSERR;
984 port_colon[0] = '\0'; 986 port_colon[0] = '\0';
985
986 memset (r_buf, 0, sizeof (struct sockaddr_in6)); 987 memset (r_buf, 0, sizeof (struct sockaddr_in6));
987 ret = inet_pton (AF_INET6, zt_addr, &r_buf->sin6_addr); 988 ret = inet_pton (AF_INET6, zt_addr, &r_buf->sin6_addr);
988 if (ret <= 0) 989 if (ret <= 0)
@@ -992,8 +993,9 @@ GNUNET_STRINGS_to_address_ipv6 (char *zt_addr, uint16_t addrlen,
992 return GNUNET_OK; 993 return GNUNET_OK;
993} 994}
994 995
996
995/** 997/**
996 * Tries to convert @zt_addr string to an IPv4 address. 998 * Tries to convert 'zt_addr' string to an IPv4 address.
997 * 999 *
998 * @param zt_addr 0-terminated string. May be mangled by the function. 1000 * @param zt_addr 0-terminated string. May be mangled by the function.
999 * @param addrlen length of zt_addr (not counting 0-terminator). 1001 * @param addrlen length of zt_addr (not counting 0-terminator).
@@ -1002,8 +1004,8 @@ GNUNET_STRINGS_to_address_ipv6 (char *zt_addr, uint16_t addrlen,
1002 * the contents of r_buf are undefined. 1004 * the contents of r_buf are undefined.
1003 */ 1005 */
1004int 1006int
1005GNUNET_STRINGS_to_address_ipv4 (char *zt_addr, uint16_t addrlen, 1007GNUNET_STRINGS_to_address_ipv4 (const char *zt_addr, uint16_t addrlen,
1006 struct sockaddr_in *r_buf) 1008 struct sockaddr_in *r_buf)
1007{ 1009{
1008 unsigned int temps[5]; 1010 unsigned int temps[5];
1009 unsigned int port; 1011 unsigned int port;
@@ -1030,10 +1032,10 @@ GNUNET_STRINGS_to_address_ipv4 (char *zt_addr, uint16_t addrlen,
1030} 1032}
1031 1033
1032/** 1034/**
1033 * Tries to convert @addr string to an IP (v4 or v6) address. 1035 * Tries to convert 'addr' string to an IP (v4 or v6) address.
1034 * IPv6 address must have its address part enclosed in '()' parens 1036 * IPv6 address must have its address part enclosed in '()' parens
1035 * instead of '[]'. 1037 * instead of '[]'.
1036 * Will automatically decide whether to treat @addr as v4 or v6 address. 1038 * Will automatically decide whether to treat 'addr' as v4 or v6 address.
1037 * 1039 *
1038 * @param addr a string, may not be 0-terminated. 1040 * @param addr a string, may not be 0-terminated.
1039 * @param addrlen number of bytes in addr (if addr is 0-terminated, 1041 * @param addrlen number of bytes in addr (if addr is 0-terminated,
@@ -1043,8 +1045,9 @@ GNUNET_STRINGS_to_address_ipv4 (char *zt_addr, uint16_t addrlen,
1043 * case the contents of r_buf are undefined. 1045 * case the contents of r_buf are undefined.
1044 */ 1046 */
1045int 1047int
1046GNUNET_STRINGS_to_address_ip (const char *addr, uint16_t addrlen, 1048GNUNET_STRINGS_to_address_ip (const char *addr,
1047 struct sockaddr_storage *r_buf) 1049 uint16_t addrlen,
1050 struct sockaddr_storage *r_buf)
1048{ 1051{
1049 uint16_t i; 1052 uint16_t i;
1050 char zt_addr[MAX_IP_ADDRLEN + 1]; 1053 char zt_addr[MAX_IP_ADDRLEN + 1];
@@ -1078,8 +1081,7 @@ GNUNET_STRINGS_to_address_ip (const char *addr, uint16_t addrlen,
1078 } 1081 }
1079 return GNUNET_STRINGS_to_address_ipv6 (zt_addr, zt_len, (struct sockaddr_in6 *) r_buf); 1082 return GNUNET_STRINGS_to_address_ipv6 (zt_addr, zt_len, (struct sockaddr_in6 *) r_buf);
1080 } 1083 }
1081 else 1084 return GNUNET_STRINGS_to_address_ipv4 (zt_addr, zt_len, (struct sockaddr_in *) r_buf);
1082 return GNUNET_STRINGS_to_address_ipv4 (zt_addr, zt_len, (struct sockaddr_in *) r_buf);
1083} 1085}
1084 1086
1085/* end of strings.c */ 1087/* end of strings.c */