Back to index

courier  0.68.2
rfc1035sockaddrport.c
Go to the documentation of this file.
00001 /*
00002 ** Copyright 1998 - 2000 Double Precision, Inc.
00003 ** See COPYING for distribution information.
00004 */
00005 #include      "config.h"
00006 #include      "rfc1035.h"
00007 #include      <sys/types.h>
00008 #include      <sys/socket.h>
00009 #include      <arpa/inet.h>
00010 #include      <errno.h>
00011 
00012 
00013 int rfc1035_sockaddrport(const RFC1035_NETADDR *a, int al, int *port)
00014 {
00015 int    af=((const struct sockaddr_in *)a)->sin_family;
00016 
00017        if ( af == AF_INET )
00018        {
00019               if (al >= sizeof(struct sockaddr_in))
00020               {
00021                      *port=((const struct sockaddr_in *)a)->sin_port;
00022                      return (0);
00023               }
00024        }
00025 
00026 #if RFC1035_IPV6
00027 
00028        if ( af == AF_INET6 )
00029        {
00030               if (al >= sizeof(struct sockaddr_in6))
00031               {
00032                      *port=((const struct sockaddr_in6 *)a)->sin6_port;
00033                      return (0);
00034               }
00035        }
00036 #endif
00037        return (-1);
00038 }