Sun, 10 Nov 2019 05:20:10 -0500
zephyr: Modernize K&R function prototypes.
| 2086 | 1 | /* This file is part of the Project Athena Zephyr Notification System. |
| 2 | * It contains source for the ZOpenPort function. | |
| 3 | * | |
| 4 | * Created by: Robert French | |
| 5 | * | |
| 6 | * Copyright (c) 1987 by the Massachusetts Institute of Technology. | |
| 7 | * For copying and distribution information, see the file | |
|
31294
73607ab89c6f
Remove trailing whitespace
Richard Laager <rlaager@pidgin.im>
parents:
15435
diff
changeset
|
8 | * "mit-copyright.h". |
| 2086 | 9 | */ |
| 10 | ||
|
8792
b0645c9dc276
[gaim-migrate @ 9554]
Christian Hammond <chipx86@chipx86.com>
parents:
7475
diff
changeset
|
11 | #include "internal.h" |
| 35994 | 12 | #include "debug.h" |
| 10867 | 13 | #ifdef WIN32 |
| 14 | #include <winsock2.h> | |
| 15 | #else | |
| 2086 | 16 | #include <sys/socket.h> |
| 10867 | 17 | #endif |
| 2086 | 18 | |
|
40166
811f82db29dd
zephyr: Modernize K&R function prototypes.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
35994
diff
changeset
|
19 | Code_t |
|
811f82db29dd
zephyr: Modernize K&R function prototypes.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
35994
diff
changeset
|
20 | ZOpenPort(unsigned short *port) |
| 2086 | 21 | { |
| 22 | struct sockaddr_in bindin; | |
|
11318
13fa1d5134f3
[gaim-migrate @ 13521]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
11105
diff
changeset
|
23 | socklen_t len; |
|
31294
73607ab89c6f
Remove trailing whitespace
Richard Laager <rlaager@pidgin.im>
parents:
15435
diff
changeset
|
24 | |
| 2086 | 25 | (void) ZClosePort(); |
| 35970 | 26 | memset(&bindin, 0, sizeof(bindin)); |
| 2086 | 27 | |
| 28 | if ((__Zephyr_fd = socket(AF_INET, SOCK_DGRAM, 0)) < 0) { | |
| 29 | __Zephyr_fd = -1; | |
| 30 | return (errno); | |
| 31 | } | |
| 32 | ||
| 33 | #ifdef SO_BSDCOMPAT | |
|
35991
e6937e52930b
Fix some CWE-252 coverity warnings
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35970
diff
changeset
|
34 | { |
|
e6937e52930b
Fix some CWE-252 coverity warnings
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35970
diff
changeset
|
35 | int on = 1; |
| 2086 | 36 | |
|
35991
e6937e52930b
Fix some CWE-252 coverity warnings
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35970
diff
changeset
|
37 | if (setsockopt(__Zephyr_fd, SOL_SOCKET, SO_BSDCOMPAT, |
|
e6937e52930b
Fix some CWE-252 coverity warnings
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35970
diff
changeset
|
38 | (char *)&on, sizeof(on)) != 0) |
|
e6937e52930b
Fix some CWE-252 coverity warnings
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35970
diff
changeset
|
39 | { |
|
e6937e52930b
Fix some CWE-252 coverity warnings
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35970
diff
changeset
|
40 | purple_debug_warning("zephyr", "couldn't setsockopt\n"); |
|
e6937e52930b
Fix some CWE-252 coverity warnings
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35970
diff
changeset
|
41 | } |
|
e6937e52930b
Fix some CWE-252 coverity warnings
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35970
diff
changeset
|
42 | } |
| 2086 | 43 | #endif |
| 44 | ||
| 45 | bindin.sin_family = AF_INET; | |
| 46 | ||
| 47 | if (port && *port) | |
| 48 | bindin.sin_port = *port; | |
| 49 | else | |
| 50 | bindin.sin_port = 0; | |
| 51 | ||
| 52 | bindin.sin_addr.s_addr = INADDR_ANY; | |
| 53 | ||
| 54 | if (bind(__Zephyr_fd, (struct sockaddr *)&bindin, sizeof(bindin)) < 0) { | |
| 55 | if (errno == EADDRINUSE && port && *port) | |
| 56 | return (ZERR_PORTINUSE); | |
| 57 | else | |
| 58 | return (errno); | |
| 59 | } | |
| 60 | ||
| 61 | if (!bindin.sin_port) { | |
| 62 | len = sizeof(bindin); | |
| 63 | if (getsockname(__Zephyr_fd, (struct sockaddr *)&bindin, &len)) | |
| 64 | return (errno); | |
| 65 | } | |
|
31294
73607ab89c6f
Remove trailing whitespace
Richard Laager <rlaager@pidgin.im>
parents:
15435
diff
changeset
|
66 | |
| 2086 | 67 | __Zephyr_port = bindin.sin_port; |
| 68 | __Zephyr_open = 1; | |
| 69 | ||
| 70 | if (port) | |
| 71 | *port = bindin.sin_port; | |
| 72 | ||
| 73 | return (ZERR_NONE); | |
| 74 | } |