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
8 * Copyright (c) 1987 by the Massachusetts Institute of Technology.
9 * For copying and distribution information, see the file
14 static char rcsid_ZOpenPort_c[] = "$Id$";
18 #include <sys/socket.h>
21 ZOpenPort(u_short *port)
23 struct sockaddr_in bindin;
28 if ((__Zephyr_fd = socket(AF_INET, SOCK_DGRAM, 0)) < 0) {
33 bindin.sin_family = AF_INET;
36 bindin.sin_port = *port;
40 bindin.sin_addr.s_addr = INADDR_ANY;
42 if (bind(__Zephyr_fd, (struct sockaddr *)&bindin, sizeof(bindin)) < 0) {
43 if (errno == EADDRINUSE && port && *port)
44 return (ZERR_PORTINUSE);
49 if (!bindin.sin_port) {
51 if (getsockname(__Zephyr_fd, (struct sockaddr *)&bindin, &len))
55 __Zephyr_port = bindin.sin_port;
59 *port = bindin.sin_port;