Mercurial > pidgin
annotate src/protocols/zephyr/ZOpenPort.c @ 9125:668ffb8fec00
[gaim-migrate @ 9902]
(12:53:05) nosnilmot: LSchiere: not majorly important, but the pref changes
listed in the ChangeLog are out of sync
committer: Tailor Script <tailor@pidgin.im>
| author | Luke Schierer <lschiere@pidgin.im> |
|---|---|
| date | Sun, 30 May 2004 16:54:40 +0000 |
| parents | 43d6c08d7e96 |
| children | 5727afad0fb8 |
| 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$ | |
|
8792
43d6c08d7e96
[gaim-migrate @ 9554]
Christian Hammond <chipx86@chipx86.com>
parents:
7475
diff
changeset
|
7 * $Author: chipx86 $ |
| 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" |
| 2086 | 20 #include <sys/socket.h> |
| 21 | |
| 22 Code_t ZOpenPort(port) | |
| 7475 | 23 unsigned short *port; |
| 2086 | 24 { |
| 25 struct sockaddr_in bindin; | |
| 26 int len; | |
| 27 | |
| 28 (void) ZClosePort(); | |
| 29 | |
| 30 if ((__Zephyr_fd = socket(AF_INET, SOCK_DGRAM, 0)) < 0) { | |
| 31 __Zephyr_fd = -1; | |
| 32 return (errno); | |
| 33 } | |
| 34 | |
| 35 #ifdef SO_BSDCOMPAT | |
| 36 { | |
| 37 int on = 1; | |
| 38 | |
| 39 setsockopt(__Zephyr_fd, SOL_SOCKET, SO_BSDCOMPAT, (char *)&on, | |
| 40 sizeof(on)); | |
| 41 } | |
| 42 #endif | |
| 43 | |
| 44 bindin.sin_family = AF_INET; | |
| 45 | |
| 46 if (port && *port) | |
| 47 bindin.sin_port = *port; | |
| 48 else | |
| 49 bindin.sin_port = 0; | |
| 50 | |
| 51 bindin.sin_addr.s_addr = INADDR_ANY; | |
| 52 | |
| 53 if (bind(__Zephyr_fd, (struct sockaddr *)&bindin, sizeof(bindin)) < 0) { | |
| 54 if (errno == EADDRINUSE && port && *port) | |
| 55 return (ZERR_PORTINUSE); | |
| 56 else | |
| 57 return (errno); | |
| 58 } | |
| 59 | |
| 60 if (!bindin.sin_port) { | |
| 61 len = sizeof(bindin); | |
| 62 if (getsockname(__Zephyr_fd, (struct sockaddr *)&bindin, &len)) | |
| 63 return (errno); | |
| 64 } | |
| 65 | |
| 66 __Zephyr_port = bindin.sin_port; | |
| 67 __Zephyr_open = 1; | |
| 68 | |
| 69 if (port) | |
| 70 *port = bindin.sin_port; | |
| 71 | |
| 72 return (ZERR_NONE); | |
| 73 } |
