updates.
[silc.git] / lib / silcutil / unix / silcunixnet.c
index 5268d5540172eb8d7cf908c2acfea2f8c0f83e64..cc8a26b63ff38a8f89af9d65739a88b7dcaef98f 100644 (file)
@@ -57,15 +57,16 @@ int silc_net_create_server(int port, char *ip_addr)
     server.sin_port = htons(port);
 
   /* Convert IP address to network byte order */
-  if (ip_addr)
+  if (ip_addr) {
     silc_net_addr2bin(ip_addr, (unsigned char *)&server.sin_addr.s_addr, len);
+  }
   else
     server.sin_addr.s_addr = INADDR_ANY;
 
   /* Bind the server socket */
   rval = bind(sock, (struct sockaddr *)&server, sizeof(server));
   if (rval < 0) {
-    SILC_LOG_ERROR(("Cannot bind socket: %s", strerror(errno)));
+    SILC_LOG_DEBUG(("Cannot bind socket: %s", strerror(errno)));
     return -1;
   }
 
@@ -270,8 +271,25 @@ int silc_net_set_socket_nonblock(int sock)
 /* Converts the IP number string from numbers-and-dots notation to
    binary form. */
 
-bool silc_net_addr2bin(const char *addr, unsigned char *bin,
-                      uint32 bin_len)
+bool silc_net_addr2bin(const char *addr, void *bin, uint32 bin_len)
+{
+  struct in_addr tmp;
+  int ret;
+
+  ret = inet_aton(addr, &tmp);
+
+  if (bin_len < 4)
+    return FALSE;
+
+  memcpy(bin, (unsigned char *)&tmp.s_addr, 4);
+  return ret != 0;
+}
+
+/* Converts the IP number string from numbers-and-dots notation to
+   binary form in network byte order. */
+
+bool silc_net_addr2bin_ne(const char *addr, unsigned char *bin,
+                         uint32 bin_len)
 {
   struct in_addr tmp;
   int ret;
@@ -281,7 +299,7 @@ bool silc_net_addr2bin(const char *addr, unsigned char *bin,
   if (bin_len < 4)
     return FALSE;
 
-  SILC_PUT32_LSB(tmp.s_addr, bin);
+  SILC_PUT32_MSB(tmp.s_addr, bin);
 
   return ret != 0;
 }