| 399 | } |
| 400 | |
| 401 | void BuildAddress (sockaddr_in *address, const char *name) |
| 402 | { |
| 403 | hostent *hostentry; // host information entry |
| 404 | u_short port; |
| 405 | const char *portpart; |
| 406 | bool isnamed = false; |
| 407 | int curchar; |
| 408 | char c; |
| 409 | FString target; |
| 410 | |
| 411 | address->sin_family = AF_INET; |
| 412 | |
| 413 | if ( (portpart = strchr (name, ':')) ) |
| 414 | { |
| 415 | target = FString(name, portpart - name); |
| 416 | port = atoi (portpart + 1); |
| 417 | if (!port) |
| 418 | { |
| 419 | Printf ("Weird port: %s (using %d)\n", portpart + 1, DOOMPORT); |
| 420 | port = DOOMPORT; |
| 421 | } |
| 422 | } |
| 423 | else |
| 424 | { |
| 425 | target = name; |
| 426 | port = DOOMPORT; |
| 427 | } |
| 428 | address->sin_port = htons(port); |
| 429 | |
| 430 | for (curchar = 0; (c = target[curchar]) ; curchar++) |
| 431 | { |
| 432 | if ((c < '0' || c > '9') && c != '.') |
| 433 | { |
| 434 | isnamed = true; |
| 435 | break; |
| 436 | } |
| 437 | } |
| 438 | |
| 439 | if (!isnamed) |
| 440 | { |
| 441 | address->sin_addr.s_addr = inet_addr (target.GetChars()); |
| 442 | Printf ("Node number %d, address %s\n", doomcom.numnodes, target.GetChars()); |
| 443 | } |
| 444 | else |
| 445 | { |
| 446 | hostentry = gethostbyname (target.GetChars()); |
| 447 | if (!hostentry) |
| 448 | I_FatalError ("gethostbyname: couldn't find %s\n%s", target.GetChars(), neterror()); |
| 449 | address->sin_addr.s_addr = *(int *)hostentry->h_addr_list[0]; |
| 450 | Printf ("Node number %d, hostname %s\n", |
| 451 | doomcom.numnodes, hostentry->h_name); |
| 452 | } |
| 453 | } |
| 454 | |
| 455 | void CloseNetwork (void) |
| 456 | { |