Mercurial > pidgin
annotate src/protocols/zephyr/ZOpenPort.c @ 10302:581de78cf809
[gaim-migrate @ 11487]
Rename main.c to gtkmain.c
Change POTFILES.in to reflect the new file names
Update the po's so they use the new file names
Update the po's to use the correct line numbers (or whatever make dist does)
committer: Tailor Script <tailor@pidgin.im>
author | Mark Doliner <mark@kingant.net> |
---|---|
date | Thu, 02 Dec 2004 23:48:48 +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 } |