Back to index

courier  0.68.2
rfc1035sockaddrip.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 #include      <string.h>
00012 
00013 
00014 int rfc1035_sockaddrip(const RFC1035_NETADDR *a, int al, RFC1035_ADDR *ip)
00015 {
00016 int    af=((const struct sockaddr_in *)a)->sin_family;
00017 
00018        if ( af == AF_INET )
00019        {
00020               if (al >= sizeof(struct sockaddr_in))
00021               {
00022 #if RFC1035_IPV6
00023                      rfc1035_ipv4to6(ip,
00024                             &((const struct sockaddr_in *)a)->sin_addr);
00025 #else
00026                      *ip=((const struct sockaddr_in *)a)->sin_addr;
00027 #endif
00028                      return (0);
00029               }
00030        }
00031 
00032 #if RFC1035_IPV6
00033 
00034        if ( af == AF_INET6 )
00035        {
00036               if (al >= sizeof(struct sockaddr_in6))
00037               {
00038                      *ip=((const struct sockaddr_in6 *)a)->sin6_addr;
00039                      return (0);
00040               }
00041        }
00042 #endif
00043        return (-1);
00044 }
00045