updates. New data types.
[silc.git] / lib / silcutil / silcnet.c
index 6914ccceecbb817e3dfa40d81efee11865f0123e..bb55b3a2709ef7f867decb04834a711eb5e62b2b 100644 (file)
@@ -293,7 +293,7 @@ void silc_net_check_host_by_sock(int sock, char **hostname, char **ip)
 
 /* Return remote port by socket. */
 
-unsigned short silc_net_get_remote_port(int sock)
+uint16 silc_net_get_remote_port(int sock)
 {
   struct sockaddr_in remote;
   int len;
@@ -306,6 +306,21 @@ unsigned short silc_net_get_remote_port(int sock)
   return ntohs(remote.sin_port);
 }
 
+/* Return local port by socket. */
+
+uint16 silc_net_get_local_port(int sock)
+{
+  struct sockaddr_in local;
+  int len;
+
+  memset(&local, 0, sizeof(local));
+  len = sizeof(local);
+  if (getsockname(sock, (struct sockaddr *)&local, &len) < 0)
+    return 0;
+
+  return ntohs(local.sin_port);
+}
+
 /* Return name of localhost. */
 
 char *silc_net_localhost()