annotate src/protocols/jabber/socket.c @ 3388:83314a9985ef

[gaim-migrate @ 3407] Here it is. Added gettext 0.11.x support! It should work fine, but please let me know if anything is broken in 0.10.x or 0.11.x (in my tests, it all worked fine) committer: Tailor Script <tailor@pidgin.im>
author Christian Hammond <chipx86@chipx86.com>
date Thu, 08 Aug 2002 18:11:17 +0000
parents 4e7cefc55971
children 9682c0e022c6
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
3127
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents: 2086
diff changeset
1 /* --------------------------------------------------------------------------
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents: 2086
diff changeset
2 *
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents: 2086
diff changeset
3 * License
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents: 2086
diff changeset
4 *
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents: 2086
diff changeset
5 * The contents of this file are subject to the Jabber Open Source License
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents: 2086
diff changeset
6 * Version 1.0 (the "JOSL"). You may not copy or use this file, in either
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents: 2086
diff changeset
7 * source code or executable form, except in compliance with the JOSL. You
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents: 2086
diff changeset
8 * may obtain a copy of the JOSL at http://www.jabber.org/ or at
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents: 2086
diff changeset
9 * http://www.opensource.org/.
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents: 2086
diff changeset
10 *
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents: 2086
diff changeset
11 * Software distributed under the JOSL is distributed on an "AS IS" basis,
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents: 2086
diff changeset
12 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the JOSL
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents: 2086
diff changeset
13 * for the specific language governing rights and limitations under the
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents: 2086
diff changeset
14 * JOSL.
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents: 2086
diff changeset
15 *
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents: 2086
diff changeset
16 * Copyrights
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents: 2086
diff changeset
17 *
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents: 2086
diff changeset
18 * Portions created by or assigned to Jabber.com, Inc. are
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents: 2086
diff changeset
19 * Copyright (c) 1999-2002 Jabber.com, Inc. All Rights Reserved. Contact
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents: 2086
diff changeset
20 * information for Jabber.com, Inc. is available at http://www.jabber.com/.
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
21 *
3127
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents: 2086
diff changeset
22 * Portions Copyright (c) 1998-1999 Jeremie Miller.
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents: 2086
diff changeset
23 *
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents: 2086
diff changeset
24 * Acknowledgements
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents: 2086
diff changeset
25 *
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents: 2086
diff changeset
26 * Special thanks to the Jabber Open Source Contributors for their
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents: 2086
diff changeset
27 * suggestions and support of Jabber.
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents: 2086
diff changeset
28 *
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents: 2086
diff changeset
29 * Alternatively, the contents of this file may be used under the terms of the
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents: 2086
diff changeset
30 * GNU General Public License Version 2 or later (the "GPL"), in which case
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents: 2086
diff changeset
31 * the provisions of the GPL are applicable instead of those above. If you
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents: 2086
diff changeset
32 * wish to allow use of your version of this file only under the terms of the
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents: 2086
diff changeset
33 * GPL and not to allow others to use your version of this file under the JOSL,
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents: 2086
diff changeset
34 * indicate your decision by deleting the provisions above and replace them
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents: 2086
diff changeset
35 * with the notice and other provisions required by the GPL. If you do not
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents: 2086
diff changeset
36 * delete the provisions above, a recipient may use your version of this file
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents: 2086
diff changeset
37 * under either the JOSL or the GPL.
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents: 2086
diff changeset
38 *
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents: 2086
diff changeset
39 *
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents: 2086
diff changeset
40 * --------------------------------------------------------------------------*/
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
41
3127
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents: 2086
diff changeset
42 #include "lib.h"
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
43
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
44 /* socket.c
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
45 *
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
46 * Simple wrapper to make socket creation easy.
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
47 * type = NETSOCKET_SERVER is local listening socket
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
48 * type = NETSOCKET_CLIENT is connection socket
3127
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents: 2086
diff changeset
49 * type = NETSOCKET_UDP is a UDP connection socket
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
50 */
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
51
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
52 int make_netsocket(u_short port, char *host, int type)
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
53 {
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
54 int s, flag = 1;
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
55 struct sockaddr_in sa;
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
56 struct in_addr *saddr;
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
57 int socket_type;
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
58
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
59 /* is this a UDP socket or a TCP socket? */
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
60 socket_type = (type == NETSOCKET_UDP)?SOCK_DGRAM:SOCK_STREAM;
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
61
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
62 bzero((void *)&sa,sizeof(struct sockaddr_in));
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
63
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
64 if((s = socket(AF_INET,socket_type,0)) < 0)
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
65 return(-1);
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
66 if(setsockopt(s, SOL_SOCKET, SO_REUSEADDR, (char*)&flag, sizeof(flag)) < 0)
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
67 return(-1);
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
68
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
69 saddr = make_addr(host);
3127
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents: 2086
diff changeset
70 if(saddr == NULL && type != NETSOCKET_UDP)
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
71 return(-1);
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
72 sa.sin_family = AF_INET;
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
73 sa.sin_port = htons(port);
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
74
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
75 if(type == NETSOCKET_SERVER)
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
76 {
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
77 /* bind to specific address if specified */
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
78 if(host != NULL)
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
79 sa.sin_addr.s_addr = saddr->s_addr;
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
80
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
81 if(bind(s,(struct sockaddr*)&sa,sizeof sa) < 0)
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
82 {
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
83 close(s);
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
84 return(-1);
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
85 }
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
86 }
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
87 if(type == NETSOCKET_CLIENT)
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
88 {
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
89 sa.sin_addr.s_addr = saddr->s_addr;
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
90 if(connect(s,(struct sockaddr*)&sa,sizeof sa) < 0)
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
91 {
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
92 close(s);
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
93 return(-1);
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
94 }
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
95 }
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
96 if(type == NETSOCKET_UDP)
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
97 {
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
98 /* bind to all addresses for now */
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
99 if(bind(s,(struct sockaddr*)&sa,sizeof sa) < 0)
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
100 {
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
101 close(s);
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
102 return(-1);
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
103 }
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
104
3127
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents: 2086
diff changeset
105 /* if specified, use a default recipient for read/write */
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents: 2086
diff changeset
106 if(host != NULL && saddr != NULL)
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
107 {
3127
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents: 2086
diff changeset
108 sa.sin_addr.s_addr = saddr->s_addr;
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents: 2086
diff changeset
109 if(connect(s,(struct sockaddr*)&sa,sizeof sa) < 0)
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents: 2086
diff changeset
110 {
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents: 2086
diff changeset
111 close(s);
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents: 2086
diff changeset
112 return(-1);
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents: 2086
diff changeset
113 }
2086
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
114 }
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
115 }
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
116
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
117
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
118 return(s);
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
119 }
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
120
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
121
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
122 struct in_addr *make_addr(char *host)
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
123 {
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
124 struct hostent *hp;
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
125 static struct in_addr addr;
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
126 char myname[MAXHOSTNAMELEN + 1];
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
127
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
128 if(host == NULL || strlen(host) == 0)
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
129 {
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
130 gethostname(myname,MAXHOSTNAMELEN);
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
131 hp = gethostbyname(myname);
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
132 if(hp != NULL)
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
133 {
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
134 return (struct in_addr *) *hp->h_addr_list;
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
135 }
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
136 }else{
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
137 addr.s_addr = inet_addr(host);
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
138 if(addr.s_addr != -1)
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
139 {
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
140 return &addr;
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
141 }
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
142 hp = gethostbyname(host);
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
143 if(hp != NULL)
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
144 {
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
145 return (struct in_addr *) *hp->h_addr_list;
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
146 }
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
147 }
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
148 return NULL;
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
149 }
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
150
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
151 /* Sets a file descriptor to close on exec. "flag" is 1 to close on exec, 0 to
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
152 * leave open across exec.
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
153 * -- EJB 7/31/2000
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
154 */
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
155 int set_fd_close_on_exec(int fd, int flag)
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
156 {
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
157 int oldflags = fcntl(fd,F_GETFL);
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
158 int newflags;
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
159
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
160 if(flag)
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
161 newflags = oldflags | FD_CLOEXEC;
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
162 else
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
163 newflags = oldflags & (~FD_CLOEXEC);
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
164
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
165 if(newflags==oldflags)
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
166 return 0;
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
167 return fcntl(fd,F_SETFL,(long)newflags);
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
168 }
424a40f12a6c [gaim-migrate @ 2096]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
169