+/************************ Static utility functions **************************/
+
+static SilcBool silc_net_set_sockaddr(TInetAddr *addr, const char *ip_addr,
+ int port)
+{
+ /* Check for IPv4 and IPv6 addresses */
+ if (ip_addr) {
+ if (!silc_net_is_ip(ip_addr)) {
+ SILC_LOG_ERROR(("%s is not IP address", ip_addr));
+ return FALSE;
+ }
+
+ if (silc_net_is_ip4(ip_addr)) {
+ /* IPv4 address */
+ unsigned char buf[4];
+ TUint32 a;
+
+ if (!silc_net_addr2bin(ip_addr, buf, sizeof(buf)))
+ return FALSE;
+
+ SILC_GET32_MSB(a, buf);
+ addr->SetAddress(a);
+ addr->SetPort(port);
+ } else {
+#ifdef HAVE_IPV6
+ SILC_LOG_ERROR(("IPv6 not supported"));
+ return FALSE;
+#else
+ SILC_LOG_ERROR(("Operating System does not support IPv6"));
+ return FALSE;
+#endif
+ }
+ } else {
+ addr->SetAddress(0);
+ addr->SetPort(port);
+ }
+
+ return TRUE;
+}
+