Mercurial > pidgin
annotate src/protocols/zephyr/ZOpenPort.c @ 10888:29bec53bd2d2
[gaim-migrate @ 12592]
Update the spec file here too, before I forget.
(I'd actually already forgotten).
committer: Tailor Script <tailor@pidgin.im>
| author | Stu Tomlinson <stu@nosnilmot.com> |
|---|---|
| date | Thu, 28 Apr 2005 20:48:12 +0000 |
| parents | 5727afad0fb8 |
| children | 64895571248f |
| rev | line source |
|---|---|
| 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 * $Source$ | |
| 10867 | 7 * $Author: thekingant $ |
| 2086 | 8 * |
| 9 * Copyright (c) 1987 by the Massachusetts Institute of Technology. | |
| 10 * For copying and distribution information, see the file | |
| 11 * "mit-copyright.h". | |
| 12 */ | |
| 13 /* $Header$ */ | |
| 14 | |
| 15 #ifndef lint | |
| 16 static char rcsid_ZOpenPort_c[] = "$Header$"; | |
| 17 #endif | |
| 18 | |
|
8792
43d6c08d7e96
[gaim-migrate @ 9554]
Christian Hammond <chipx86@chipx86.com>
parents:
7475
diff
changeset
|
19 #include "internal.h" |
| 10867 | 20 #ifdef WIN32 |
| 21 #include <winsock2.h> | |
| 22 #else | |
| 2086 | 23 #include <sys/socket.h> |
| 10867 | 24 #endif |
| 2086 | 25 |
| 26 Code_t ZOpenPort(port) | |
| 7475 | 27 unsigned short *port; |
| 2086 | 28 { |
| 29 struct sockaddr_in bindin; | |
| 30 int len; | |
| 31 | |
| 32 (void) ZClosePort(); | |
| 33 | |
| 34 if ((__Zephyr_fd = socket(AF_INET, SOCK_DGRAM, 0)) < 0) { | |
| 35 __Zephyr_fd = -1; | |
| 36 return (errno); | |
| 37 } | |
| 38 | |
| 39 #ifdef SO_BSDCOMPAT | |
| 40 { | |
| 41 int on = 1; | |
| 42 | |
| 43 setsockopt(__Zephyr_fd, SOL_SOCKET, SO_BSDCOMPAT, (char *)&on, | |
| 44 sizeof(on)); | |
| 45 } | |
| 46 #endif | |
| 47 | |
| 48 bindin.sin_family = AF_INET; | |
| 49 | |
| 50 if (port && *port) | |
| 51 bindin.sin_port = *port; | |
| 52 else | |
| 53 bindin.sin_port = 0; | |
| 54 | |
| 55 bindin.sin_addr.s_addr = INADDR_ANY; | |
| 56 | |
| 57 if (bind(__Zephyr_fd, (struct sockaddr *)&bindin, sizeof(bindin)) < 0) { | |
| 58 if (errno == EADDRINUSE && port && *port) | |
| 59 return (ZERR_PORTINUSE); | |
| 60 else | |
| 61 return (errno); | |
| 62 } | |
| 63 | |
| 64 if (!bindin.sin_port) { | |
| 65 len = sizeof(bindin); | |
| 66 if (getsockname(__Zephyr_fd, (struct sockaddr *)&bindin, &len)) | |
| 67 return (errno); | |
| 68 } | |
| 69 | |
| 70 __Zephyr_port = bindin.sin_port; | |
| 71 __Zephyr_open = 1; | |
| 72 | |
| 73 if (port) | |
| 74 *port = bindin.sin_port; | |
| 75 | |
| 76 return (ZERR_NONE); | |
| 77 } |
