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
6 * $Id: ZOpenPort.c,v 1.15 1999/01/22 23:19:17 ghudson Exp $
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: ZOpenPort.c,v 1.15 1999/01/22 23:19:17 ghudson Exp $";
18 #include <sys/socket.h>
20 Code_t ZOpenPort(port)
23 struct sockaddr_in bindin;
31 if ((__Zephyr_fd = socket(AF_INET, SOCK_DGRAM, 0)) < 0) {
37 /* Prevent Linux from giving us socket errors we don't care about. */
38 setsockopt(__Zephyr_fd, SOL_SOCKET, SO_BSDCOMPAT, &on, sizeof(on));
41 bindin.sin_family = AF_INET;
44 bindin.sin_port = *port;
48 bindin.sin_addr.s_addr = INADDR_ANY;
50 if (bind(__Zephyr_fd, (struct sockaddr *)&bindin, sizeof(bindin)) < 0) {
51 if (errno == EADDRINUSE && port && *port)
52 return (ZERR_PORTINUSE);
57 if (!bindin.sin_port) {
59 if (getsockname(__Zephyr_fd, (struct sockaddr *)&bindin, &len))
63 __Zephyr_port = bindin.sin_port;
67 *port = bindin.sin_port;