Back to index

courier  0.68.2
rfc1035mksocket.c
Go to the documentation of this file.
00001 /*
00002 ** Copyright 1998 - 2011 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 /*
00014 **     Create a socket.  Duh.  If we've compiled IPv6 support, but we can't
00015 **     create an IPv6 socket, create an IPv4 socket.  This can happen, say,
00016 **     on Linux with IPv6 runtime libraries, but without IPv6 in the kernel.
00017 */
00018 
00019 int    rfc1035_mksocket(int sock_type, int sock_protocol, int *af)
00020 {
00021 #if    RFC1035_IPV6
00022        int    s;
00023        int    on=0;
00024 
00025        *af=AF_INET6;
00026        if ( (s=socket(PF_INET6, sock_type, sock_protocol)) >= 0)
00027        {
00028 #ifdef IPV6_V6ONLY
00029 
00030               setsockopt(s, IPPROTO_IPV6, IPV6_V6ONLY,
00031                         (char *)&on, sizeof(on));
00032 #endif
00033 
00034               return (s);
00035        }
00036 #endif
00037        *af=AF_INET;
00038        return (socket(PF_INET, sock_type, sock_protocol));
00039 }