author | David Powell <david.e.powell@oracle.com> |
Thu, 05 May 2011 13:16:34 -0700 | |
changeset 698 | 3c730b38d1b0 |
parent 696 | 1ce0573e4536 |
permissions | -rw-r--r-- |
391 | 1 |
/* |
2 |
* CDDL HEADER START |
|
3 |
* |
|
4 |
* The contents of this file are subject to the terms of the |
|
5 |
* Common Development and Distribution License (the "License"). |
|
6 |
* You may not use this file except in compliance with the License. |
|
7 |
* |
|
8 |
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE |
|
9 |
* or http://www.opensolaris.org/os/licensing. |
|
10 |
* See the License for the specific language governing permissions |
|
11 |
* and limitations under the License. |
|
12 |
* |
|
13 |
* When distributing Covered Code, include this CDDL HEADER in each |
|
14 |
* file and include the License file at usr/src/OPENSOLARIS.LICENSE. |
|
15 |
* If applicable, add the following below this CDDL HEADER, with the |
|
16 |
* fields enclosed by brackets "[]" replaced with your own identifying |
|
17 |
* information: Portions Copyright [yyyy] [name of copyright owner] |
|
18 |
* |
|
19 |
* CDDL HEADER END |
|
20 |
*/ |
|
21 |
||
22 |
/* |
|
698
3c730b38d1b0
18261 panel packages should depend on visual-panels-core
David Powell <david.e.powell@oracle.com>
parents:
696
diff
changeset
|
23 |
* Copyright (c) 2009, 2011, Oracle and/or its affiliates. All rights reserved. |
391 | 24 |
*/ |
25 |
||
26 |
#include <sys/types.h> |
|
27 |
#include <sys/socket.h> |
|
28 |
#include <stdio.h> |
|
29 |
#include <string.h> |
|
30 |
#include <stdlib.h> |
|
31 |
#include <errno.h> |
|
32 |
#include <unistd.h> |
|
696
1ce0573e4536
18149 - Add tests for connection assertions (connectLocalTCP6)
Dan Labrecque <dan.labrecque@oracle.com>
parents:
540
diff
changeset
|
33 |
#include <netinet/in.h> |
391 | 34 |
|
540
2a0d274b1469
16571 move all content module interfaces into rad_modapi.h
David Powell <david.e.powell@oracle.com>
parents:
391
diff
changeset
|
35 |
#include "rad_modapi.h" |
391 | 36 |
|
37 |
int |
|
38 |
listen_on_port(int port, boolean_t local) |
|
39 |
{ |
|
698
3c730b38d1b0
18261 panel packages should depend on visual-panels-core
David Powell <david.e.powell@oracle.com>
parents:
696
diff
changeset
|
40 |
struct sockaddr_in6 sa = { |
3c730b38d1b0
18261 panel packages should depend on visual-panels-core
David Powell <david.e.powell@oracle.com>
parents:
696
diff
changeset
|
41 |
.sin6_family = AF_INET6, |
3c730b38d1b0
18261 panel packages should depend on visual-panels-core
David Powell <david.e.powell@oracle.com>
parents:
696
diff
changeset
|
42 |
.sin6_port = htons(port), |
3c730b38d1b0
18261 panel packages should depend on visual-panels-core
David Powell <david.e.powell@oracle.com>
parents:
696
diff
changeset
|
43 |
.sin6_addr = (local ? in6addr_loopback : in6addr_any) |
3c730b38d1b0
18261 panel packages should depend on visual-panels-core
David Powell <david.e.powell@oracle.com>
parents:
696
diff
changeset
|
44 |
}; |
391 | 45 |
int fd, option; |
46 |
||
47 |
rad_log(RL_DEBUG, "attempting to listen on port %d (%s)", port, |
|
48 |
local ? "loopback only" : "all addresses"); |
|
49 |
||
696
1ce0573e4536
18149 - Add tests for connection assertions (connectLocalTCP6)
Dan Labrecque <dan.labrecque@oracle.com>
parents:
540
diff
changeset
|
50 |
if ((fd = socket(AF_INET6, SOCK_STREAM, 0)) == -1) { |
391 | 51 |
rad_log(RL_ERROR, "failed to create socket: %s", |
52 |
strerror(errno)); |
|
53 |
return (-1); |
|
54 |
} |
|
55 |
||
56 |
option = 1; |
|
57 |
if (setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, &option, |
|
58 |
sizeof (option)) == -1) { |
|
59 |
rad_log(RL_ERROR, "failed to set socket options: %s", |
|
60 |
strerror(errno)); |
|
61 |
return (-1); |
|
62 |
} |
|
63 |
||
64 |
if (bind(fd, (struct sockaddr *)&sa, sizeof (sa)) == -1) { |
|
65 |
rad_log(RL_ERROR, "failed to bind to address: %s", |
|
66 |
strerror(errno)); |
|
67 |
return (-1); |
|
68 |
} |
|
69 |
||
70 |
if (listen(fd, 15) == -1) { |
|
71 |
rad_log(RL_ERROR, "failed to listen on socket: %s", |
|
72 |
strerror(errno)); |
|
73 |
return (-1); |
|
74 |
} |
|
75 |
||
76 |
rad_log(RL_DEBUG, "listening on port %d (%s)", port, |
|
77 |
local ? "loopback only" : "all addresses"); |
|
78 |
||
79 |
return (fd); |
|
80 |
} |