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 * Copyright (c) 1987 by the Massachusetts Institute of Technology.
7 * For copying and distribution information, see the file
16 #include <sys/socket.h>
19 Code_t
ZOpenPort(port
)
22 struct sockaddr_in bindin
;
26 memset(&bindin
, 0, sizeof(bindin
));
28 if ((__Zephyr_fd
= socket(AF_INET
, SOCK_DGRAM
, 0)) < 0) {
37 if (setsockopt(__Zephyr_fd
, SOL_SOCKET
, SO_BSDCOMPAT
,
38 (char *)&on
, sizeof(on
)) != 0)
40 purple_debug_warning("zephyr", "couldn't setsockopt\n");
45 bindin
.sin_family
= AF_INET
;
48 bindin
.sin_port
= *port
;
52 bindin
.sin_addr
.s_addr
= INADDR_ANY
;
54 if (bind(__Zephyr_fd
, (struct sockaddr
*)&bindin
, sizeof(bindin
)) < 0) {
55 if (errno
== EADDRINUSE
&& port
&& *port
)
56 return (ZERR_PORTINUSE
);
61 if (!bindin
.sin_port
) {
63 if (getsockname(__Zephyr_fd
, (struct sockaddr
*)&bindin
, &len
))
67 __Zephyr_port
= bindin
.sin_port
;
71 *port
= bindin
.sin_port
;