Changeset 1335:548e9191245b in roaraudio for libroar/vio_socket.c
- Timestamp:
- 03/23/09 13:57:58 (15 years ago)
- Branch:
- default
- Phase:
- public
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
libroar/vio_socket.c
r1333 r1335 49 49 len = sizeof(struct sockaddr_in); 50 50 51 if ( roar_vio_socket_init_inet4host_def(def) == -1 ) 52 return -1; 53 51 54 switch (def->d.socket.type) { 52 55 case SOCK_STREAM: … … 144 147 } 145 148 149 int roar_vio_socket_init_dstr_def (struct roar_vio_defaults * def, char * dstr, int hint, int type, 150 struct roar_vio_defaults * odef) { 151 char * host; 152 int port; 153 154 if ( def == NULL || dstr == NULL ) 155 return -1; 156 157 ROAR_WARN("roar_vio_socket_init_dstr_def(def=%p, dstr='%s', hint=%i, type=%i, odef=%p) = ?", def, dstr, hint, type, odef); 158 159 if ( hint == -1 ) { 160 if ( 0 ) { // this is needed to keep the syntx ok, compiler will throw it away 161 #ifdef ROAR_HAVE_IPV6 162 } else if ( strstr(dstr, "[") != NULL ) { // [ip]:service 163 hint = AF_INET6; 164 #endif 165 #ifdef ROAR_HAVE_LIBDNET 166 } else if ( strstr(dstr, "::") != NULL ) { // node::object 167 hint = AF_DECnet; 168 #endif 169 #ifdef ROAR_HAVE_IPX 170 } else if ( strstr(dstr, "(") != NULL ) { // net:mac(service) 171 hint = AF_IPX; 172 #endif 173 #ifdef ROAR_HAVE_UNIX 174 } else if ( strstr(dstr, "/") != NULL ) { // /path/to/sock 175 hint = AF_UNIX; 176 #endif 177 } else if ( strstr(dstr, ":") != NULL ) { // host:port 178 hint = AF_INET; 179 } 180 } 181 182 if ( hint == -1 && odef != NULL ) { // if we still don't know what this is we try 183 // to use the parent objects request 184 if ( odef->type == ROAR_VIO_DEF_TYPE_SOCKET ) { 185 hint = odef->d.socket.domain; 186 } 187 } 188 189 if ( hint == -1 ) /* we really have no glue what this is... */ 190 return -1; 191 192 #ifdef ROAR_HAVE_UNIX 193 if ( hint == AF_UNIX ) { 194 if ( *dstr != 0 && strcmp(dstr, "//") != 0 ) { 195 return roar_vio_socket_init_unix_def(def, dstr); 196 } else { 197 if ( roar_vio_socket_conv_def(odef, AF_UNIX) == -1 ) 198 return -1; 199 200 return roar_vio_socket_init_unix_def(def, odef->d.socket.sa.un.sun_path); 201 } 202 } 203 #endif 204 205 for (; *dstr == '/'; dstr++); 206 207 switch (hint) { 208 case AF_INET: 209 host = dstr; 210 for (; *dstr != 0 && *dstr != ':'; dstr++); 211 212 if ( *dstr == ':' ) { // we have a port :) 213 *dstr++ = 0; 214 if ( (port = roar_vio_socket_get_port(dstr, AF_INET, type)) == -1 ) 215 return -1; 216 217 return roar_vio_socket_init_inet4_def(def, host, port, type); 218 } else { 219 if ( roar_vio_socket_conv_def(odef, AF_INET) == -1 ) 220 return -1; 221 222 return roar_vio_socket_init_inet4_def(def, host, ROAR_NET2HOST16(odef->d.socket.sa.in.sin_port), type); 223 } 224 break; 225 #ifdef ROAR_HAVE_LIBDNET 226 case AF_DECnet: 227 return -1; 228 break; 229 #endif 230 #ifdef ROAR_HAVE_IPV6 231 case AF_INET6: 232 return -1; 233 break; 234 #endif 235 #ifdef ROAR_HAVE_IPX 236 case AF_IPX: 237 return -1; 238 break; 239 #endif 240 default: 241 return -1; 242 } 243 244 return 0; 245 } 246 247 int roar_vio_socket_conv_def (struct roar_vio_defaults * def, int domain) { 248 return -1; 249 } 250 251 int roar_vio_socket_get_port (char * service, int domain, int type) { 252 if ( service == NULL || domain == -1 || type == -1 ) 253 return -1; 254 255 // TODO: we should write something better 256 return atoi(service); 257 } 258 259 // AF_UNIX: 146 260 int roar_vio_socket_init_unix_def (struct roar_vio_defaults * def, char * path) { 261 #ifdef ROAR_HAVE_UNIX 147 262 if ( roar_vio_socket_init_socket_def(def, AF_UNIX, SOCK_STREAM) == -1 ) 148 263 return -1; … … 151 266 152 267 return 0; 153 } 154 268 #else 269 return -1; 270 #endif 271 } 272 273 // AF_DECnet: 155 274 int roar_vio_socket_init_decnet_def (struct roar_vio_defaults * def, char * node, int object, char * objname); 156 275 157 int roar_vio_socket_init_inet4host_def(struct roar_vio_defaults * def, char * host) { 276 277 // AF_INET: 278 int roar_vio_socket_init_inet4host_def(struct roar_vio_defaults * def) { 158 279 struct hostent * he; 159 280 160 if ( def == NULL || host == NULL ) 161 return -1; 162 163 if ( (he = gethostbyname(host)) == NULL ) { 281 if ( def == NULL ) 282 return -1; 283 284 if ( def->d.socket.host == NULL ) 285 return -1; 286 287 if ( (he = gethostbyname(def->d.socket.host)) == NULL ) { 164 288 ROAR_ERR("roar_vio_socket_init_inet4host_def(*): Can\'t resolve host name '%s'", 165 host);289 def->d.socket.host); 166 290 return -1; 167 291 } … … 172 296 } 173 297 298 int roar_vio_socket_init_inet4_def (struct roar_vio_defaults * def, char * host, int port, int type) { 299 if ( roar_vio_socket_init_socket_def(def, AF_INET, type) == -1 ) 300 return -1; 301 302 def->d.socket.host = host; 303 304 def->d.socket.sa.in.sin_port = ROAR_HOST2NET16(port); 305 306 return 0; 307 } 308 174 309 int roar_vio_socket_init_tcp4_def (struct roar_vio_defaults * def, char * host, int port) { 175 if ( roar_vio_socket_init_socket_def(def, AF_INET, SOCK_STREAM) == -1 ) 176 return -1; 177 178 if ( roar_vio_socket_init_inet4host_def(def, host) == -1 ) 179 return -1; 180 181 def->d.socket.sa.in.sin_port = ROAR_HOST2NET16(port); 182 183 return 0; 184 } 185 186 int roar_vio_socket_init_udp4_def (struct roar_vio_defaults * def, char * host, int port); 187 int roar_vio_socket_init_inet6host_def(struct roar_vio_defaults * def, char * host); 188 int roar_vio_socket_init_tcp6_def (struct roar_vio_defaults * def, char * host, int port); 189 int roar_vio_socket_init_udp6_def (struct roar_vio_defaults * def, char * host, int port); 310 return roar_vio_socket_init_inet4_def(def, host, port, SOCK_STREAM); 311 } 312 313 int roar_vio_socket_init_udp4_def (struct roar_vio_defaults * def, char * host, int port) { 314 return roar_vio_socket_init_inet4_def(def, host, port, SOCK_DGRAM); 315 } 316 317 318 // AF_INET6: 319 int roar_vio_socket_init_inet6host_def(struct roar_vio_defaults * def); 320 int roar_vio_socket_init_inet6_def (struct roar_vio_defaults * def, char * host, int port, int type) { 321 return -1; 322 } 323 324 int roar_vio_socket_init_tcp6_def (struct roar_vio_defaults * def, char * host, int port) { 325 return roar_vio_socket_init_inet6_def(def, host, port, SOCK_STREAM); 326 } 327 328 int roar_vio_socket_init_udp6_def (struct roar_vio_defaults * def, char * host, int port) { 329 return roar_vio_socket_init_inet6_def(def, host, port, SOCK_DGRAM); 330 } 190 331 191 332 //ll
Note: See TracChangeset
for help on using the changeset viewer.