1 /* This file is part of the Project Athena Zephyr Notification System.
2 * It contains source for the ZOpenPort function.
4 * Created by: Robert French
7 * $Author: warmenhoven $
9 * Copyright (c) 1987 by the Massachusetts Institute of Technology.
10 * For copying and distribution information, see the file
16 static char rcsid_ZOpenPort_c
[] = "$Header$";
20 #include <sys/socket.h>
22 Code_t
ZOpenPort(port
)
25 struct sockaddr_in bindin
;
30 if ((__Zephyr_fd
= socket(AF_INET
, SOCK_DGRAM
, 0)) < 0) {
39 setsockopt(__Zephyr_fd
, SOL_SOCKET
, SO_BSDCOMPAT
, (char *)&on
,
44 bindin
.sin_family
= AF_INET
;
47 bindin
.sin_port
= *port
;
51 bindin
.sin_addr
.s_addr
= INADDR_ANY
;
53 if (bind(__Zephyr_fd
, (struct sockaddr
*)&bindin
, sizeof(bindin
)) < 0) {
54 if (errno
== EADDRINUSE
&& port
&& *port
)
55 return (ZERR_PORTINUSE
);
60 if (!bindin
.sin_port
) {
62 if (getsockname(__Zephyr_fd
, (struct sockaddr
*)&bindin
, &len
))
66 __Zephyr_port
= bindin
.sin_port
;
70 *port
= bindin
.sin_port
;