X-Git-Url: http://git.silcnet.org/gitweb/?a=blobdiff_plain;f=lib%2Fsilcutil%2Fsilcnet.c;h=5b060d1e5f5989f06504248dfc02b187e5d7ac9e;hb=2f8b86e0ca6551ed22ca1de45558b0bf93ab3470;hp=6914ccceecbb817e3dfa40d81efee11865f0123e;hpb=c49f7330c61ba13940fadef90377ec4012145e37;p=runtime.git diff --git a/lib/silcutil/silcnet.c b/lib/silcutil/silcnet.c index 6914ccce..5b060d1e 100644 --- a/lib/silcutil/silcnet.c +++ b/lib/silcutil/silcnet.c @@ -306,6 +306,21 @@ unsigned short silc_net_get_remote_port(int sock) return ntohs(remote.sin_port); } +/* Return local port by socket. */ + +unsigned short 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()