Home » Archimedes archive » Acorn User » AU 1997-Xmas B.adf » PD » NetPlex/!Netplex/SocketFS/C/Nameproc
NetPlex/!Netplex/SocketFS/C/Nameproc
This website contains an archive of files for the Acorn Electron, BBC Micro, Acorn Archimedes, Commodore 16 and Commodore 64 computers, which Dominic Ford has rescued from his private collection of floppy disks and cassettes.
Some of these files were originally commercial releases in the 1980s and 1990s, but they are now widely available online. I assume that copyright over them is no longer being asserted. If you own the copyright and would like files to be removed, please contact me.
| Tape/disk: | Home » Archimedes archive » Acorn User » AU 1997-Xmas B.adf » PD |
| Filename: | NetPlex/!Netplex/SocketFS/C/Nameproc |
| Read OK: | ✔ |
| File size: | 27F3 bytes |
| Load address: | 0000 |
| Exec address: | 0000 |
File contents
/***************************************************************************/
/* Program : SocketFS */
/* Purpose : Treat Internet sockets as file streams */
/* File : Nameproc.c */
/* Author : R G Gammans */
/* Date Created : 04-07-97 */
/* Last Edited : 07-09-97 */
/* */
/* Copyright Date: July 1997 (C) R G Gammans */
/* */
/***************************************************************************/
/*
* SocketFS - BSD sockets filing system for RISC-OS.
* Copyright (C) 1997 Roger G Gammans
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*
* Author: R Gammans <rgammans@compsurg,demon.co.uk>
* Snailmail : 20 Trenches Rd, Crowborough, E Sussex, TN6 1ES UK.
*/
#include <stdio.h>
#include <sys/param.h>
#include <sys/file.h>
#include <sys/stat.h>
#include <sys/socket.h>
#include <sys/ioctl.h>
#include <sys/un.h>
#include <netinet/in.h>
#include <netdb.h>
#include <pwd.h>
#include <sys/syslog.h>
#include <sys/wait.h>
#include <sgtty.h>
#include <ctype.h>
#include <errnum.h>
#include <string.h>
#ifndef FIOMODE
#define FIOMODE FIOSLEEPTW
#endif
#ifdef DEBUG
#include "trackerlib.h"
#endif
/*
* Most the code in here is pretty naff but it works.
*
* At some point this lot may as well be re-written in asm,
* which will remove our dependendcy on stubs/sharedclib.
*
* Also the exceutable will drop in size considerably
*/
typedef
struct {
int addr_family;
int proto_family;
char* special_field;
int (*makesocket)(char* fname);
} Thandler_struct;
typedef
struct TS_hand {
Thandler_struct *data;
struct TS_hand *next;
} Thandler_list;
Thandler_list *handler_list_root;
char* errstr;
Thandler_struct IPhandler,fdhandler;
Thandler_list IPouter,fdouter;
int makeInetStream(char* filename);
int sock2fd(char* filename);
void inithandlerlist()
{
IPhandler.special_field="IPv4";
IPhandler.makesocket=makeInetStream;
fdhandler.special_field="s2fd";
fdhandler.makesocket=sock2fd;
IPouter.data=&IPhandler;
IPouter.next=&fdouter;
fdouter.data=&fdhandler;
fdouter.next=NULL;
handler_list_root=&IPouter;
}
int makeSocket(char* specialfield,char* filename)
{
int a_socket;
Thandler_list *traversee;
int found;
if (!specialfield)
{
/*Default AF_INET*/
specialfield="IPv4";
#ifdef DEBUG
tracker_simple(" - special reset to \"IPv4\" (or is it)\n");
#endif
};
traversee=handler_list_root;
found=0;
while ((traversee!=NULL) && !found) {
found=!strcmp(specialfield,traversee->data->special_field);
if (traversee!=NULL && !found) {
traversee=traversee->next;
}
}
if (!found)
{
/*File not found.. */
a_socket=-1;
}
else
{
#ifdef DEBUG
tracker_simple("About the call makesocket for af..\n");
#endif
a_socket=traversee->data->makesocket(filename);
}
return a_socket;
}
int makeInetStream(char* filename)
{
/* The aim here is two extract protocol over which where opening the
* connection. (assuming ICMP/TCP/UDP.)
* We also need to extract the host:port designation of both ends.
*
* We do this by processing each directory in turn.
* eg. socket#IPv4::Tcp.$.www/demon/co/uk\80 -Talk to a Httpd - from any port.
* socket#IPv4::Tcp.$.192/168/0/3\515.auto\768 -Talk to my lpd server.. from a resvered port
*/
char *section,*divisor,*serv,*tmpptr;
char proto[99],lcl_host[255],lcl_serv[255],rem_host[255],rem_serv[255];
struct hostent *hp;
struct servent *sp;
struct sockaddr_in sin,sout;
int s;
char olddiv;
int one =1;
section=strstr(filename,":"); /*Should be 1st char */
divisor=strstr(filename,".$.");
if (!divisor)
return -1;
*divisor='\0';
strcpy(proto,section+1);
#ifdef DEBUG
tracker_printf("Protocol = %s\n",proto);
#endif
*divisor='.';
section=divisor+3;
serv=strstr(section,"\\");
divisor=strstr(section,".");
if ((divisor) && (divisor<serv) || !serv)
{
/*
* We must have both a port and a host at the
* remote end.
*/
return -1;
}
else
{
/* '\' in the remote part*/
if (divisor) {
olddiv= *divisor;
*divisor='\0';
}
strcpy(rem_serv,serv+1);
if (divisor)
*divisor=olddiv;
#ifdef DEBUG
tracker_printf("Remote port name = %s\n",rem_serv);
#endif
olddiv=*serv;
*serv='\0';
strcpy(rem_host,section);
*serv=olddiv;
#ifdef DEBUG
tracker_printf("Remote host part = %s\n",rem_host);
#endif
/* Do '.' and '/' replacement. */
tmpptr=rem_host;
while (*tmpptr!='\0') {
if (*tmpptr=='/')
{
*tmpptr='.';
}
tmpptr++;
}
#ifdef DEBUG
tracker_printf("Remote host = %s\n",rem_host);
#endif
hp=gethostbyname(rem_host);
if (hp == NULL) {
errstr="Can't find remote interface\n";
return -1;
}
bzero((char *)&sin, sizeof(sin));
bcopy(hp->h_addr, (caddr_t)&sin.sin_addr, hp->h_length);
sin.sin_family= hp->h_addrtype;
sin.sin_port=htons(atoi(rem_serv));
/* There is an implicit assumation here that our hosts */
/* and network representations of 0 are the same */
/* This will be true for all big & little endian */
/* machines, which use 2's complement */
if (sin.sin_port==0) {
sp=getservbyname(rem_serv,proto);
if (sp == NULL) {
errstr="Can't resolve remote service\n";
return -1;
}
sin.sin_port = sp->s_port;
}
#ifdef DEBUG
tracker_printf("Remote port no = %d\n",ntohs(sin.sin_port));
#endif
}
if (*divisor=='\0')
{
#ifdef DEBUG
tracker_simple("Creating socket... ");
#endif
s=socket(AF_INET,SOCK_STREAM,0);
#ifdef DEBUG
tracker_simple("done\n");
#endif
if (s==-1) return s;
}
else
{
section=divisor+1;
serv=strstr(section,"\\");
if (!serv)
{
/*
* No '\' in local part....
* Currently we ignore all then!
*/
s=socket(AF_INET,SOCK_STREAM,0);
}
else
{
/* '\' in the local part */
#ifdef DEBUG
tracker_printf("local port specified - %s\n",section);
#endif
*divisor='\0';
strcpy(lcl_serv,serv+1);
#ifdef DEBUG
tracker_printf("Local port name = %s\n",lcl_serv);
#endif
*serv='\0';
strcpy(lcl_host,section);
#ifdef DEBUG
tracker_printf("Local Host part = %s\n",lcl_host);
#endif
/*Do '.' and '/' replacement.*/
tmpptr=lcl_host;
while (*tmpptr=='\0') {
if (*tmpptr=='/')
{
*tmpptr='.';
}
}
#ifdef DEBUG
tracker_printf("Local host = %s\n",lcl_host);
#endif
if (!strcmp(lcl_host,"auto")) {
gethostname(lcl_host,sizeof(lcl_host));
lcl_host[sizeof(lcl_host)-1]='\0';
}
hp=gethostbyname(lcl_host);
if (hp == NULL) {
errstr="Can't find local interface\n";
return -1;
}
s=socket(AF_INET,SOCK_STREAM,0);
if (s==-1) return s;
bzero((char *)&sout, sizeof(sout));
bcopy(hp->h_addr, (caddr_t)&sout.sin_addr, hp->h_length);
sout.sin_family= hp->h_addrtype;
#ifdef DEBUG
tracker_printf("Local i/f = %s\n",lcl_host);
#endif
if (strcmp(lcl_serv,"auto")) {
sout.sin_port=htons(atoi(lcl_serv));
/* There is an implicit assumation here that our hosts */
/* and the network representations of 0 are the same */
/* This will be true for all big & little endian */
/* machines, which use 2's complement. */
if (sout.sin_port==0) {
sp=getservbyname(lcl_serv,proto);
if (sp == NULL) {
errstr="Can't resolve local service\n";
return -1;
}
sout.sin_port = sp->s_port;
}
}
#ifdef DEBUG
tracker_printf("Remote port no = %d\n",ntohs(sin.sin_port));
#endif
#ifdef DEBUG
tracker_simple("trying to bind socket .... ");
#endif
if (bind(s,&sout,sizeof(sout))==-1) return -1;
#ifdef DEBUG
tracker_simple("done\n");
#endif
}
}
ioctl(s,FIOMODE,&one);
#ifdef DEBUG
tracker_simple("trying to connect .... ");
#endif
if (connect(s,&sin,sizeof(sin))==-1) return -1;
#ifdef DEBUG
tracker_simple("done\n");
#endif
return s;
}
int sock2fd(char* filename)
{
char *flags,*desc;
flags=strstr(filename,":"); /*Should be 1st char */
desc=strstr(filename,".$.");
if (!desc)
return -1;
if isdigit(desc[3])
{
return atoi(desc[3]);
}
return -1;
/*We ignore the meaning of the flags section currently */
}
00000000 2f 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a |/***************|
00000010 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a |****************|
*
00000040 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2f 0a 2f 2a |************/./*|
00000050 20 50 72 6f 67 72 61 6d 20 20 20 20 20 20 20 3a | Program :|
00000060 20 53 6f 63 6b 65 74 46 53 20 20 20 20 20 20 20 | SocketFS |
00000070 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 | |
*
00000090 20 20 20 20 20 20 20 20 20 2a 2f 0a 2f 2a 20 50 | */./* P|
000000a0 75 72 70 6f 73 65 20 20 20 20 20 20 20 3a 20 54 |urpose : T|
000000b0 72 65 61 74 20 49 6e 74 65 72 6e 65 74 20 73 6f |reat Internet so|
000000c0 63 6b 65 74 73 20 61 73 20 66 69 6c 65 20 73 74 |ckets as file st|
000000d0 72 65 61 6d 73 20 20 20 20 20 20 20 20 20 20 20 |reams |
000000e0 20 20 20 20 20 20 20 2a 2f 0a 2f 2a 20 46 69 6c | */./* Fil|
000000f0 65 20 20 20 20 20 20 20 20 20 20 3a 20 4e 61 6d |e : Nam|
00000100 65 70 72 6f 63 2e 63 20 20 20 20 20 20 20 20 20 |eproc.c |
00000110 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 | |
*
00000130 20 20 20 20 20 2a 2f 0a 2f 2a 20 41 75 74 68 6f | */./* Autho|
00000140 72 20 20 20 20 20 20 20 20 3a 20 52 20 47 20 47 |r : R G G|
00000150 61 6d 6d 61 6e 73 20 20 20 20 20 20 20 20 20 20 |ammans |
00000160 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 | |
*
00000180 20 20 20 2a 2f 0a 2f 2a 20 44 61 74 65 20 43 72 | */./* Date Cr|
00000190 65 61 74 65 64 20 20 3a 20 30 34 2d 30 37 2d 39 |eated : 04-07-9|
000001a0 37 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 |7 |
000001b0 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 | |
*
000001d0 20 2a 2f 0a 2f 2a 20 4c 61 73 74 20 45 64 69 74 | */./* Last Edit|
000001e0 65 64 20 20 20 3a 20 30 37 2d 30 39 2d 39 37 20 |ed : 07-09-97 |
000001f0 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 | |
*
00000210 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 2a | *|
00000220 2f 0a 2f 2a 20 20 20 20 20 20 20 20 20 20 20 20 |/./* |
00000230 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 | |
*
00000260 20 20 20 20 20 20 20 20 20 20 20 20 20 2a 2f 0a | */.|
00000270 2f 2a 20 43 6f 70 79 72 69 67 68 74 20 44 61 74 |/* Copyright Dat|
00000280 65 3a 20 4a 75 6c 79 20 31 39 39 37 20 28 43 29 |e: July 1997 (C)|
00000290 20 52 20 47 20 47 61 6d 6d 61 6e 73 20 20 20 20 | R G Gammans |
000002a0 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 | |
000002b0 20 20 20 20 20 20 20 20 20 20 20 2a 2f 0a 2f 2a | */./*|
000002c0 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 | |
*
00000300 20 20 20 20 20 20 20 20 20 2a 2f 0a 2f 2a 2a 2a | */./***|
00000310 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a |****************|
*
00000350 2a 2a 2a 2a 2a 2a 2a 2a 2f 0a 2f 2a 0a 20 2a 20 |********/./*. * |
00000360 20 20 53 6f 63 6b 65 74 46 53 20 2d 20 42 53 44 | SocketFS - BSD|
00000370 20 73 6f 63 6b 65 74 73 20 66 69 6c 69 6e 67 20 | sockets filing |
00000380 73 79 73 74 65 6d 20 66 6f 72 20 52 49 53 43 2d |system for RISC-|
00000390 4f 53 2e 0a 20 2a 20 20 20 43 6f 70 79 72 69 67 |OS.. * Copyrig|
000003a0 68 74 20 28 43 29 20 31 39 39 37 20 52 6f 67 65 |ht (C) 1997 Roge|
000003b0 72 20 47 20 47 61 6d 6d 61 6e 73 0a 20 2a 0a 20 |r G Gammans. *. |
000003c0 2a 20 20 20 54 68 69 73 20 70 72 6f 67 72 61 6d |* This program|
000003d0 20 69 73 20 66 72 65 65 20 73 6f 66 74 77 61 72 | is free softwar|
000003e0 65 3b 20 79 6f 75 20 63 61 6e 20 72 65 64 69 73 |e; you can redis|
000003f0 74 72 69 62 75 74 65 20 69 74 20 61 6e 64 2f 6f |tribute it and/o|
00000400 72 20 6d 6f 64 69 66 79 0a 20 2a 20 20 20 69 74 |r modify. * it|
00000410 20 75 6e 64 65 72 20 74 68 65 20 74 65 72 6d 73 | under the terms|
00000420 20 6f 66 20 74 68 65 20 47 4e 55 20 47 65 6e 65 | of the GNU Gene|
00000430 72 61 6c 20 50 75 62 6c 69 63 20 4c 69 63 65 6e |ral Public Licen|
00000440 73 65 20 61 73 20 70 75 62 6c 69 73 68 65 64 20 |se as published |
00000450 62 79 0a 20 2a 20 20 20 74 68 65 20 46 72 65 65 |by. * the Free|
00000460 20 53 6f 66 74 77 61 72 65 20 46 6f 75 6e 64 61 | Software Founda|
00000470 74 69 6f 6e 3b 20 65 69 74 68 65 72 20 76 65 72 |tion; either ver|
00000480 73 69 6f 6e 20 32 20 6f 66 20 74 68 65 20 4c 69 |sion 2 of the Li|
00000490 63 65 6e 73 65 2c 20 6f 72 0a 20 2a 20 20 20 28 |cense, or. * (|
000004a0 61 74 20 79 6f 75 72 20 6f 70 74 69 6f 6e 29 20 |at your option) |
000004b0 61 6e 79 20 6c 61 74 65 72 20 76 65 72 73 69 6f |any later versio|
000004c0 6e 2e 0a 20 2a 0a 20 2a 0a 20 2a 20 20 20 54 68 |n.. *. *. * Th|
000004d0 69 73 20 70 72 6f 67 72 61 6d 20 69 73 20 64 69 |is program is di|
000004e0 73 74 72 69 62 75 74 65 64 20 69 6e 20 74 68 65 |stributed in the|
000004f0 20 68 6f 70 65 20 74 68 61 74 20 69 74 20 77 69 | hope that it wi|
00000500 6c 6c 20 62 65 20 75 73 65 66 75 6c 2c 0a 20 2a |ll be useful,. *|
00000510 20 20 20 62 75 74 20 57 49 54 48 4f 55 54 20 41 | but WITHOUT A|
00000520 4e 59 20 57 41 52 52 41 4e 54 59 3b 20 77 69 74 |NY WARRANTY; wit|
00000530 68 6f 75 74 20 65 76 65 6e 20 74 68 65 20 69 6d |hout even the im|
00000540 70 6c 69 65 64 20 77 61 72 72 61 6e 74 79 20 6f |plied warranty o|
00000550 66 0a 20 2a 20 20 20 4d 45 52 43 48 41 4e 54 41 |f. * MERCHANTA|
00000560 42 49 4c 49 54 59 20 6f 72 20 46 49 54 4e 45 53 |BILITY or FITNES|
00000570 53 20 46 4f 52 20 41 20 50 41 52 54 49 43 55 4c |S FOR A PARTICUL|
00000580 41 52 20 50 55 52 50 4f 53 45 2e 20 20 53 65 65 |AR PURPOSE. See|
00000590 20 74 68 65 0a 20 2a 20 20 20 47 4e 55 20 47 65 | the. * GNU Ge|
000005a0 6e 65 72 61 6c 20 50 75 62 6c 69 63 20 4c 69 63 |neral Public Lic|
000005b0 65 6e 73 65 20 66 6f 72 20 6d 6f 72 65 20 64 65 |ense for more de|
000005c0 74 61 69 6c 73 2e 0a 20 2a 0a 20 2a 20 20 20 59 |tails.. *. * Y|
000005d0 6f 75 20 73 68 6f 75 6c 64 20 68 61 76 65 20 72 |ou should have r|
000005e0 65 63 65 69 76 65 64 20 61 20 63 6f 70 79 20 6f |eceived a copy o|
000005f0 66 20 74 68 65 20 47 4e 55 20 47 65 6e 65 72 61 |f the GNU Genera|
00000600 6c 20 50 75 62 6c 69 63 20 4c 69 63 65 6e 73 65 |l Public License|
00000610 0a 20 2a 20 20 20 61 6c 6f 6e 67 20 77 69 74 68 |. * along with|
00000620 20 74 68 69 73 20 70 72 6f 67 72 61 6d 3b 20 69 | this program; i|
00000630 66 20 6e 6f 74 2c 20 77 72 69 74 65 20 74 6f 20 |f not, write to |
00000640 74 68 65 20 46 72 65 65 20 53 6f 66 74 77 61 72 |the Free Softwar|
00000650 65 0a 20 2a 20 20 20 46 6f 75 6e 64 61 74 69 6f |e. * Foundatio|
00000660 6e 2c 20 49 6e 63 2e 2c 20 36 37 35 20 4d 61 73 |n, Inc., 675 Mas|
00000670 73 20 41 76 65 2c 20 43 61 6d 62 72 69 64 67 65 |s Ave, Cambridge|
00000680 2c 20 4d 41 20 30 32 31 33 39 2c 20 55 53 41 2e |, MA 02139, USA.|
00000690 0a 20 2a 0a 20 2a 20 20 20 41 75 74 68 6f 72 3a |. *. * Author:|
000006a0 20 52 20 47 61 6d 6d 61 6e 73 20 3c 72 67 61 6d | R Gammans <rgam|
000006b0 6d 61 6e 73 40 63 6f 6d 70 73 75 72 67 2c 64 65 |mans@compsurg,de|
000006c0 6d 6f 6e 2e 63 6f 2e 75 6b 3e 0a 20 2a 20 20 20 |mon.co.uk>. * |
000006d0 53 6e 61 69 6c 6d 61 69 6c 20 20 3a 20 32 30 20 |Snailmail : 20 |
000006e0 54 72 65 6e 63 68 65 73 20 52 64 2c 20 43 72 6f |Trenches Rd, Cro|
000006f0 77 62 6f 72 6f 75 67 68 2c 20 45 20 53 75 73 73 |wborough, E Suss|
00000700 65 78 2c 20 54 4e 36 20 31 45 53 20 55 4b 2e 0a |ex, TN6 1ES UK..|
00000710 20 2a 2f 0a 0a 0a 23 69 6e 63 6c 75 64 65 20 3c | */...#include <|
00000720 73 74 64 69 6f 2e 68 3e 0a 23 69 6e 63 6c 75 64 |stdio.h>.#includ|
00000730 65 20 3c 73 79 73 2f 70 61 72 61 6d 2e 68 3e 0a |e <sys/param.h>.|
00000740 23 69 6e 63 6c 75 64 65 20 3c 73 79 73 2f 66 69 |#include <sys/fi|
00000750 6c 65 2e 68 3e 0a 23 69 6e 63 6c 75 64 65 20 3c |le.h>.#include <|
00000760 73 79 73 2f 73 74 61 74 2e 68 3e 0a 23 69 6e 63 |sys/stat.h>.#inc|
00000770 6c 75 64 65 20 3c 73 79 73 2f 73 6f 63 6b 65 74 |lude <sys/socket|
00000780 2e 68 3e 0a 23 69 6e 63 6c 75 64 65 20 3c 73 79 |.h>.#include <sy|
00000790 73 2f 69 6f 63 74 6c 2e 68 3e 0a 23 69 6e 63 6c |s/ioctl.h>.#incl|
000007a0 75 64 65 20 3c 73 79 73 2f 75 6e 2e 68 3e 0a 23 |ude <sys/un.h>.#|
000007b0 69 6e 63 6c 75 64 65 20 3c 6e 65 74 69 6e 65 74 |include <netinet|
000007c0 2f 69 6e 2e 68 3e 0a 23 69 6e 63 6c 75 64 65 20 |/in.h>.#include |
000007d0 3c 6e 65 74 64 62 2e 68 3e 0a 23 69 6e 63 6c 75 |<netdb.h>.#inclu|
000007e0 64 65 20 3c 70 77 64 2e 68 3e 0a 23 69 6e 63 6c |de <pwd.h>.#incl|
000007f0 75 64 65 20 3c 73 79 73 2f 73 79 73 6c 6f 67 2e |ude <sys/syslog.|
00000800 68 3e 0a 23 69 6e 63 6c 75 64 65 20 3c 73 79 73 |h>.#include <sys|
00000810 2f 77 61 69 74 2e 68 3e 0a 23 69 6e 63 6c 75 64 |/wait.h>.#includ|
00000820 65 20 3c 73 67 74 74 79 2e 68 3e 0a 23 69 6e 63 |e <sgtty.h>.#inc|
00000830 6c 75 64 65 20 3c 63 74 79 70 65 2e 68 3e 0a 23 |lude <ctype.h>.#|
00000840 69 6e 63 6c 75 64 65 20 3c 65 72 72 6e 75 6d 2e |include <errnum.|
00000850 68 3e 0a 23 69 6e 63 6c 75 64 65 20 3c 73 74 72 |h>.#include <str|
00000860 69 6e 67 2e 68 3e 0a 0a 23 69 66 6e 64 65 66 20 |ing.h>..#ifndef |
00000870 46 49 4f 4d 4f 44 45 0a 23 64 65 66 69 6e 65 20 |FIOMODE.#define |
00000880 46 49 4f 4d 4f 44 45 20 46 49 4f 53 4c 45 45 50 |FIOMODE FIOSLEEP|
00000890 54 57 0a 23 65 6e 64 69 66 0a 0a 23 69 66 64 65 |TW.#endif..#ifde|
000008a0 66 20 44 45 42 55 47 0a 23 69 6e 63 6c 75 64 65 |f DEBUG.#include|
000008b0 20 22 74 72 61 63 6b 65 72 6c 69 62 2e 68 22 0a | "trackerlib.h".|
000008c0 23 65 6e 64 69 66 0a 0a 0a 20 2f 2a 0a 20 20 2a |#endif... /*. *|
000008d0 20 4d 6f 73 74 20 74 68 65 20 63 6f 64 65 20 69 | Most the code i|
000008e0 6e 20 68 65 72 65 20 69 73 20 70 72 65 74 74 79 |n here is pretty|
000008f0 20 6e 61 66 66 20 62 75 74 20 69 74 20 77 6f 72 | naff but it wor|
00000900 6b 73 2e 0a 20 20 2a 0a 20 20 2a 20 41 74 20 73 |ks.. *. * At s|
00000910 6f 6d 65 20 70 6f 69 6e 74 20 74 68 69 73 20 6c |ome point this l|
00000920 6f 74 20 6d 61 79 20 61 73 20 77 65 6c 6c 20 62 |ot may as well b|
00000930 65 20 72 65 2d 77 72 69 74 74 65 6e 20 69 6e 20 |e re-written in |
00000940 61 73 6d 2c 0a 20 20 2a 20 77 68 69 63 68 20 77 |asm,. * which w|
00000950 69 6c 6c 20 72 65 6d 6f 76 65 20 6f 75 72 20 64 |ill remove our d|
00000960 65 70 65 6e 64 65 6e 64 63 79 20 6f 6e 20 73 74 |ependendcy on st|
00000970 75 62 73 2f 73 68 61 72 65 64 63 6c 69 62 2e 0a |ubs/sharedclib..|
00000980 20 20 2a 0a 20 20 2a 20 41 6c 73 6f 20 74 68 65 | *. * Also the|
00000990 20 65 78 63 65 75 74 61 62 6c 65 20 77 69 6c 6c | exceutable will|
000009a0 20 64 72 6f 70 20 69 6e 20 73 69 7a 65 20 63 6f | drop in size co|
000009b0 6e 73 69 64 65 72 61 62 6c 79 0a 20 20 2a 2f 0a |nsiderably. */.|
000009c0 74 79 70 65 64 65 66 0a 20 20 73 74 72 75 63 74 |typedef. struct|
000009d0 20 7b 0a 20 20 20 20 20 20 20 20 20 69 6e 74 20 | {. int |
000009e0 20 20 61 64 64 72 5f 66 61 6d 69 6c 79 3b 0a 20 | addr_family;. |
000009f0 20 20 20 20 20 20 20 20 69 6e 74 20 20 20 70 72 | int pr|
00000a00 6f 74 6f 5f 66 61 6d 69 6c 79 3b 0a 0a 20 20 20 |oto_family;.. |
00000a10 20 20 20 20 20 20 63 68 61 72 2a 20 73 70 65 63 | char* spec|
00000a20 69 61 6c 5f 66 69 65 6c 64 3b 0a 20 20 20 20 20 |ial_field;. |
00000a30 20 20 20 20 69 6e 74 20 28 2a 6d 61 6b 65 73 6f | int (*makeso|
00000a40 63 6b 65 74 29 28 63 68 61 72 2a 20 66 6e 61 6d |cket)(char* fnam|
00000a50 65 29 3b 0a 0a 20 20 20 20 20 20 20 20 20 20 7d |e);.. }|
00000a60 20 54 68 61 6e 64 6c 65 72 5f 73 74 72 75 63 74 | Thandler_struct|
00000a70 3b 0a 0a 0a 74 79 70 65 64 65 66 0a 20 20 73 74 |;...typedef. st|
00000a80 72 75 63 74 20 54 53 5f 68 61 6e 64 20 7b 0a 20 |ruct TS_hand {. |
00000a90 20 20 20 20 20 20 20 20 20 54 68 61 6e 64 6c 65 | Thandle|
00000aa0 72 5f 73 74 72 75 63 74 20 2a 64 61 74 61 3b 0a |r_struct *data;.|
00000ab0 20 20 20 20 20 20 20 20 20 20 73 74 72 75 63 74 | struct|
00000ac0 20 54 53 5f 68 61 6e 64 20 2a 6e 65 78 74 3b 0a | TS_hand *next;.|
00000ad0 20 20 20 20 20 20 20 20 20 7d 20 54 68 61 6e 64 | } Thand|
00000ae0 6c 65 72 5f 6c 69 73 74 3b 0a 0a 54 68 61 6e 64 |ler_list;..Thand|
00000af0 6c 65 72 5f 6c 69 73 74 20 2a 68 61 6e 64 6c 65 |ler_list *handle|
00000b00 72 5f 6c 69 73 74 5f 72 6f 6f 74 3b 0a 63 68 61 |r_list_root;.cha|
00000b10 72 2a 20 65 72 72 73 74 72 3b 0a 0a 54 68 61 6e |r* errstr;..Than|
00000b20 64 6c 65 72 5f 73 74 72 75 63 74 20 49 50 68 61 |dler_struct IPha|
00000b30 6e 64 6c 65 72 2c 66 64 68 61 6e 64 6c 65 72 3b |ndler,fdhandler;|
00000b40 0a 54 68 61 6e 64 6c 65 72 5f 6c 69 73 74 20 20 |.Thandler_list |
00000b50 20 49 50 6f 75 74 65 72 2c 66 64 6f 75 74 65 72 | IPouter,fdouter|
00000b60 3b 0a 0a 0a 0a 69 6e 74 20 6d 61 6b 65 49 6e 65 |;....int makeIne|
00000b70 74 53 74 72 65 61 6d 28 63 68 61 72 2a 20 66 69 |tStream(char* fi|
00000b80 6c 65 6e 61 6d 65 29 3b 0a 69 6e 74 20 73 6f 63 |lename);.int soc|
00000b90 6b 32 66 64 28 63 68 61 72 2a 20 66 69 6c 65 6e |k2fd(char* filen|
00000ba0 61 6d 65 29 3b 0a 0a 76 6f 69 64 20 69 6e 69 74 |ame);..void init|
00000bb0 68 61 6e 64 6c 65 72 6c 69 73 74 28 29 0a 20 20 |handlerlist(). |
00000bc0 7b 0a 20 20 20 20 49 50 68 61 6e 64 6c 65 72 2e |{. IPhandler.|
00000bd0 73 70 65 63 69 61 6c 5f 66 69 65 6c 64 3d 22 49 |special_field="I|
00000be0 50 76 34 22 3b 0a 20 20 20 20 49 50 68 61 6e 64 |Pv4";. IPhand|
00000bf0 6c 65 72 2e 6d 61 6b 65 73 6f 63 6b 65 74 3d 6d |ler.makesocket=m|
00000c00 61 6b 65 49 6e 65 74 53 74 72 65 61 6d 3b 0a 20 |akeInetStream;. |
00000c10 20 20 20 66 64 68 61 6e 64 6c 65 72 2e 73 70 65 | fdhandler.spe|
00000c20 63 69 61 6c 5f 66 69 65 6c 64 3d 22 73 32 66 64 |cial_field="s2fd|
00000c30 22 3b 0a 20 20 20 20 66 64 68 61 6e 64 6c 65 72 |";. fdhandler|
00000c40 2e 6d 61 6b 65 73 6f 63 6b 65 74 3d 73 6f 63 6b |.makesocket=sock|
00000c50 32 66 64 3b 0a 20 20 20 20 49 50 6f 75 74 65 72 |2fd;. IPouter|
00000c60 2e 64 61 74 61 3d 26 49 50 68 61 6e 64 6c 65 72 |.data=&IPhandler|
00000c70 3b 0a 20 20 20 20 49 50 6f 75 74 65 72 2e 6e 65 |;. IPouter.ne|
00000c80 78 74 3d 26 66 64 6f 75 74 65 72 3b 0a 20 20 20 |xt=&fdouter;. |
00000c90 20 66 64 6f 75 74 65 72 2e 64 61 74 61 3d 26 66 | fdouter.data=&f|
00000ca0 64 68 61 6e 64 6c 65 72 3b 0a 20 20 20 20 66 64 |dhandler;. fd|
00000cb0 6f 75 74 65 72 2e 6e 65 78 74 3d 4e 55 4c 4c 3b |outer.next=NULL;|
00000cc0 0a 20 20 20 20 68 61 6e 64 6c 65 72 5f 6c 69 73 |. handler_lis|
00000cd0 74 5f 72 6f 6f 74 3d 26 49 50 6f 75 74 65 72 3b |t_root=&IPouter;|
00000ce0 0a 20 20 7d 0a 0a 69 6e 74 20 20 6d 61 6b 65 53 |. }..int makeS|
00000cf0 6f 63 6b 65 74 28 63 68 61 72 2a 20 73 70 65 63 |ocket(char* spec|
00000d00 69 61 6c 66 69 65 6c 64 2c 63 68 61 72 2a 20 66 |ialfield,char* f|
00000d10 69 6c 65 6e 61 6d 65 29 0a 20 20 7b 0a 20 20 20 |ilename). {. |
00000d20 20 69 6e 74 20 20 20 20 20 20 20 20 20 20 20 20 | int |
00000d30 20 61 5f 73 6f 63 6b 65 74 3b 0a 20 20 20 20 54 | a_socket;. T|
00000d40 68 61 6e 64 6c 65 72 5f 6c 69 73 74 20 20 20 2a |handler_list *|
00000d50 74 72 61 76 65 72 73 65 65 3b 0a 20 20 20 20 69 |traversee;. i|
00000d60 6e 74 20 20 20 20 20 20 20 20 20 20 20 20 20 66 |nt f|
00000d70 6f 75 6e 64 3b 0a 0a 20 20 20 20 69 66 20 28 21 |ound;.. if (!|
00000d80 73 70 65 63 69 61 6c 66 69 65 6c 64 29 0a 20 20 |specialfield). |
00000d90 20 20 20 20 7b 0a 20 20 20 20 20 20 20 20 2f 2a | {. /*|
00000da0 44 65 66 61 75 6c 74 20 41 46 5f 49 4e 45 54 2a |Default AF_INET*|
00000db0 2f 0a 20 20 20 20 20 20 20 20 73 70 65 63 69 61 |/. specia|
00000dc0 6c 66 69 65 6c 64 3d 22 49 50 76 34 22 3b 0a 0a |lfield="IPv4";..|
00000dd0 23 69 66 64 65 66 20 44 45 42 55 47 0a 74 72 61 |#ifdef DEBUG.tra|
00000de0 63 6b 65 72 5f 73 69 6d 70 6c 65 28 22 20 2d 20 |cker_simple(" - |
00000df0 73 70 65 63 69 61 6c 20 72 65 73 65 74 20 74 6f |special reset to|
00000e00 20 5c 22 49 50 76 34 5c 22 20 28 6f 72 20 69 73 | \"IPv4\" (or is|
00000e10 20 69 74 29 5c 6e 22 29 3b 0a 23 65 6e 64 69 66 | it)\n");.#endif|
00000e20 0a 20 20 20 20 20 20 7d 3b 0a 0a 20 20 20 20 74 |. };.. t|
00000e30 72 61 76 65 72 73 65 65 3d 68 61 6e 64 6c 65 72 |raversee=handler|
00000e40 5f 6c 69 73 74 5f 72 6f 6f 74 3b 0a 20 20 20 20 |_list_root;. |
00000e50 66 6f 75 6e 64 3d 30 3b 0a 20 20 20 20 77 68 69 |found=0;. whi|
00000e60 6c 65 20 28 28 74 72 61 76 65 72 73 65 65 21 3d |le ((traversee!=|
00000e70 4e 55 4c 4c 29 20 26 26 20 21 66 6f 75 6e 64 29 |NULL) && !found)|
00000e80 20 7b 0a 20 20 20 20 20 20 66 6f 75 6e 64 3d 21 | {. found=!|
00000e90 73 74 72 63 6d 70 28 73 70 65 63 69 61 6c 66 69 |strcmp(specialfi|
00000ea0 65 6c 64 2c 74 72 61 76 65 72 73 65 65 2d 3e 64 |eld,traversee->d|
00000eb0 61 74 61 2d 3e 73 70 65 63 69 61 6c 5f 66 69 65 |ata->special_fie|
00000ec0 6c 64 29 3b 0a 20 20 20 20 20 20 20 69 66 20 28 |ld);. if (|
00000ed0 74 72 61 76 65 72 73 65 65 21 3d 4e 55 4c 4c 20 |traversee!=NULL |
00000ee0 26 26 20 21 66 6f 75 6e 64 29 20 7b 0a 20 20 20 |&& !found) {. |
00000ef0 20 20 20 20 20 20 74 72 61 76 65 72 73 65 65 3d | traversee=|
00000f00 74 72 61 76 65 72 73 65 65 2d 3e 6e 65 78 74 3b |traversee->next;|
00000f10 0a 20 20 20 20 20 20 20 7d 0a 20 20 20 20 7d 0a |. }. }.|
00000f20 0a 20 20 20 20 69 66 20 28 21 66 6f 75 6e 64 29 |. if (!found)|
00000f30 0a 20 20 20 20 20 20 7b 0a 20 20 20 20 20 20 20 |. {. |
00000f40 20 20 2f 2a 46 69 6c 65 20 6e 6f 74 20 66 6f 75 | /*File not fou|
00000f50 6e 64 2e 2e 20 20 20 20 20 20 2a 2f 0a 20 20 20 |nd.. */. |
00000f60 20 20 20 20 20 61 5f 73 6f 63 6b 65 74 3d 2d 31 | a_socket=-1|
00000f70 3b 0a 20 20 20 20 20 20 7d 0a 20 20 20 20 20 20 |;. }. |
00000f80 65 6c 73 65 0a 20 20 20 20 20 20 7b 0a 23 69 66 |else. {.#if|
00000f90 64 65 66 20 44 45 42 55 47 0a 74 72 61 63 6b 65 |def DEBUG.tracke|
00000fa0 72 5f 73 69 6d 70 6c 65 28 22 41 62 6f 75 74 20 |r_simple("About |
00000fb0 74 68 65 20 63 61 6c 6c 20 6d 61 6b 65 73 6f 63 |the call makesoc|
00000fc0 6b 65 74 20 66 6f 72 20 61 66 2e 2e 5c 6e 22 29 |ket for af..\n")|
00000fd0 3b 0a 23 65 6e 64 69 66 0a 20 20 20 20 20 20 20 |;.#endif. |
00000fe0 20 61 5f 73 6f 63 6b 65 74 3d 74 72 61 76 65 72 | a_socket=traver|
00000ff0 73 65 65 2d 3e 64 61 74 61 2d 3e 6d 61 6b 65 73 |see->data->makes|
00001000 6f 63 6b 65 74 28 66 69 6c 65 6e 61 6d 65 29 3b |ocket(filename);|
00001010 0a 20 20 20 20 20 20 7d 0a 0a 20 20 20 20 72 65 |. }.. re|
00001020 74 75 72 6e 20 61 5f 73 6f 63 6b 65 74 3b 0a 20 |turn a_socket;. |
00001030 20 7d 0a 0a 0a 69 6e 74 20 6d 61 6b 65 49 6e 65 | }...int makeIne|
00001040 74 53 74 72 65 61 6d 28 63 68 61 72 2a 20 66 69 |tStream(char* fi|
00001050 6c 65 6e 61 6d 65 29 0a 20 7b 0a 20 20 20 2f 2a |lename). {. /*|
00001060 20 54 68 65 20 61 69 6d 20 68 65 72 65 20 69 73 | The aim here is|
00001070 20 74 77 6f 20 65 78 74 72 61 63 74 20 70 72 6f | two extract pro|
00001080 74 6f 63 6f 6c 20 6f 76 65 72 20 77 68 69 63 68 |tocol over which|
00001090 20 77 68 65 72 65 20 6f 70 65 6e 69 6e 67 20 74 | where opening t|
000010a0 68 65 0a 20 20 20 20 2a 20 63 6f 6e 6e 65 63 74 |he. * connect|
000010b0 69 6f 6e 2e 20 28 61 73 73 75 6d 69 6e 67 20 49 |ion. (assuming I|
000010c0 43 4d 50 2f 54 43 50 2f 55 44 50 2e 29 0a 20 20 |CMP/TCP/UDP.). |
000010d0 20 20 2a 20 57 65 20 61 6c 73 6f 20 6e 65 65 64 | * We also need|
000010e0 20 74 6f 20 65 78 74 72 61 63 74 20 74 68 65 20 | to extract the |
000010f0 68 6f 73 74 3a 70 6f 72 74 20 64 65 73 69 67 6e |host:port design|
00001100 61 74 69 6f 6e 20 6f 66 20 62 6f 74 68 20 65 6e |ation of both en|
00001110 64 73 2e 0a 20 20 20 20 2a 0a 20 20 20 20 2a 20 |ds.. *. * |
00001120 57 65 20 64 6f 20 74 68 69 73 20 62 79 20 70 72 |We do this by pr|
00001130 6f 63 65 73 73 69 6e 67 20 65 61 63 68 20 64 69 |ocessing each di|
00001140 72 65 63 74 6f 72 79 20 69 6e 20 74 75 72 6e 2e |rectory in turn.|
00001150 0a 20 20 20 20 2a 20 65 67 2e 20 73 6f 63 6b 65 |. * eg. socke|
00001160 74 23 49 50 76 34 3a 3a 54 63 70 2e 24 2e 77 77 |t#IPv4::Tcp.$.ww|
00001170 77 2f 64 65 6d 6f 6e 2f 63 6f 2f 75 6b 5c 38 30 |w/demon/co/uk\80|
00001180 20 20 20 20 20 20 20 20 2d 54 61 6c 6b 20 74 6f | -Talk to|
00001190 20 61 20 48 74 74 70 64 20 2d 20 66 72 6f 6d 20 | a Httpd - from |
000011a0 61 6e 79 20 70 6f 72 74 2e 0a 20 20 20 20 2a 20 |any port.. * |
000011b0 20 20 20 73 6f 63 6b 65 74 23 49 50 76 34 3a 3a | socket#IPv4::|
000011c0 54 63 70 2e 24 2e 31 39 32 2f 31 36 38 2f 30 2f |Tcp.$.192/168/0/|
000011d0 33 5c 35 31 35 2e 61 75 74 6f 5c 37 36 38 20 20 |3\515.auto\768 |
000011e0 2d 54 61 6c 6b 20 74 6f 20 6d 79 20 6c 70 64 20 |-Talk to my lpd |
000011f0 73 65 72 76 65 72 2e 2e 20 66 72 6f 6d 20 61 20 |server.. from a |
00001200 72 65 73 76 65 72 65 64 20 70 6f 72 74 0a 20 20 |resvered port. |
00001210 20 20 2a 2f 0a 0a 20 20 20 63 68 61 72 20 20 20 | */.. char |
00001220 2a 73 65 63 74 69 6f 6e 2c 2a 64 69 76 69 73 6f |*section,*diviso|
00001230 72 2c 2a 73 65 72 76 2c 2a 74 6d 70 70 74 72 3b |r,*serv,*tmpptr;|
00001240 0a 20 20 20 63 68 61 72 20 20 20 70 72 6f 74 6f |. char proto|
00001250 5b 39 39 5d 2c 6c 63 6c 5f 68 6f 73 74 5b 32 35 |[99],lcl_host[25|
00001260 35 5d 2c 6c 63 6c 5f 73 65 72 76 5b 32 35 35 5d |5],lcl_serv[255]|
00001270 2c 72 65 6d 5f 68 6f 73 74 5b 32 35 35 5d 2c 72 |,rem_host[255],r|
00001280 65 6d 5f 73 65 72 76 5b 32 35 35 5d 3b 0a 20 20 |em_serv[255];. |
00001290 20 73 74 72 75 63 74 20 68 6f 73 74 65 6e 74 20 | struct hostent |
000012a0 2a 68 70 3b 0a 20 20 20 73 74 72 75 63 74 20 73 |*hp;. struct s|
000012b0 65 72 76 65 6e 74 20 2a 73 70 3b 0a 20 20 20 73 |ervent *sp;. s|
000012c0 74 72 75 63 74 20 73 6f 63 6b 61 64 64 72 5f 69 |truct sockaddr_i|
000012d0 6e 20 73 69 6e 2c 73 6f 75 74 3b 0a 20 20 20 69 |n sin,sout;. i|
000012e0 6e 74 20 20 20 20 73 3b 0a 20 20 20 63 68 61 72 |nt s;. char|
000012f0 20 20 20 6f 6c 64 64 69 76 3b 0a 20 20 20 69 6e | olddiv;. in|
00001300 74 20 20 20 20 6f 6e 65 20 3d 31 3b 0a 0a 20 20 |t one =1;.. |
00001310 20 73 65 63 74 69 6f 6e 3d 73 74 72 73 74 72 28 | section=strstr(|
00001320 66 69 6c 65 6e 61 6d 65 2c 22 3a 22 29 3b 20 2f |filename,":"); /|
00001330 2a 53 68 6f 75 6c 64 20 62 65 20 31 73 74 20 63 |*Should be 1st c|
00001340 68 61 72 20 2a 2f 0a 20 20 20 64 69 76 69 73 6f |har */. diviso|
00001350 72 3d 73 74 72 73 74 72 28 66 69 6c 65 6e 61 6d |r=strstr(filenam|
00001360 65 2c 22 2e 24 2e 22 29 3b 0a 20 20 20 69 66 20 |e,".$.");. if |
00001370 28 21 64 69 76 69 73 6f 72 29 0a 20 20 20 20 20 |(!divisor). |
00001380 72 65 74 75 72 6e 20 2d 31 3b 0a 0a 20 20 20 2a |return -1;.. *|
00001390 64 69 76 69 73 6f 72 3d 27 5c 30 27 3b 0a 20 20 |divisor='\0';. |
000013a0 20 73 74 72 63 70 79 28 70 72 6f 74 6f 2c 73 65 | strcpy(proto,se|
000013b0 63 74 69 6f 6e 2b 31 29 3b 0a 23 69 66 64 65 66 |ction+1);.#ifdef|
000013c0 20 44 45 42 55 47 0a 20 20 20 74 72 61 63 6b 65 | DEBUG. tracke|
000013d0 72 5f 70 72 69 6e 74 66 28 22 50 72 6f 74 6f 63 |r_printf("Protoc|
000013e0 6f 6c 20 3d 20 25 73 5c 6e 22 2c 70 72 6f 74 6f |ol = %s\n",proto|
000013f0 29 3b 0a 23 65 6e 64 69 66 0a 20 20 20 2a 64 69 |);.#endif. *di|
00001400 76 69 73 6f 72 3d 27 2e 27 3b 0a 20 20 20 73 65 |visor='.';. se|
00001410 63 74 69 6f 6e 3d 64 69 76 69 73 6f 72 2b 33 3b |ction=divisor+3;|
00001420 0a 0a 20 20 20 73 65 72 76 3d 73 74 72 73 74 72 |.. serv=strstr|
00001430 28 73 65 63 74 69 6f 6e 2c 22 5c 5c 22 29 3b 0a |(section,"\\");.|
00001440 20 20 20 64 69 76 69 73 6f 72 3d 73 74 72 73 74 | divisor=strst|
00001450 72 28 73 65 63 74 69 6f 6e 2c 22 2e 22 29 3b 0a |r(section,".");.|
00001460 0a 20 20 20 69 66 20 28 28 64 69 76 69 73 6f 72 |. if ((divisor|
00001470 29 20 26 26 20 28 64 69 76 69 73 6f 72 3c 73 65 |) && (divisor<se|
00001480 72 76 29 20 7c 7c 20 21 73 65 72 76 29 0a 20 20 |rv) || !serv). |
00001490 20 20 20 7b 0a 20 20 20 20 20 20 2f 2a 0a 20 20 | {. /*. |
000014a0 20 20 20 20 20 2a 20 57 65 20 6d 75 73 74 20 68 | * We must h|
000014b0 61 76 65 20 62 6f 74 68 20 61 20 70 6f 72 74 20 |ave both a port |
000014c0 61 6e 64 20 61 20 68 6f 73 74 20 61 74 20 74 68 |and a host at th|
000014d0 65 0a 20 20 20 20 20 20 20 2a 20 72 65 6d 6f 74 |e. * remot|
000014e0 65 20 65 6e 64 2e 0a 20 20 20 20 20 20 20 2a 2f |e end.. */|
000014f0 0a 0a 20 20 20 20 20 20 72 65 74 75 72 6e 20 2d |.. return -|
00001500 31 3b 0a 20 20 20 20 20 7d 0a 20 20 20 20 20 65 |1;. }. e|
00001510 6c 73 65 0a 20 20 20 20 20 7b 0a 20 20 20 20 20 |lse. {. |
00001520 20 2f 2a 20 27 5c 27 20 69 6e 20 74 68 65 20 72 | /* '\' in the r|
00001530 65 6d 6f 74 65 20 70 61 72 74 2a 2f 0a 0a 20 20 |emote part*/.. |
00001540 20 20 20 20 20 69 66 20 28 64 69 76 69 73 6f 72 | if (divisor|
00001550 29 20 7b 0a 20 20 20 20 20 20 20 20 20 6f 6c 64 |) {. old|
00001560 64 69 76 3d 20 2a 64 69 76 69 73 6f 72 3b 0a 20 |div= *divisor;. |
00001570 20 20 20 20 20 20 20 20 2a 64 69 76 69 73 6f 72 | *divisor|
00001580 3d 27 5c 30 27 3b 0a 20 20 20 20 20 20 20 7d 0a |='\0';. }.|
00001590 20 20 20 20 20 20 20 73 74 72 63 70 79 28 72 65 | strcpy(re|
000015a0 6d 5f 73 65 72 76 2c 73 65 72 76 2b 31 29 3b 0a |m_serv,serv+1);.|
000015b0 20 20 20 20 20 20 20 69 66 20 28 64 69 76 69 73 | if (divis|
000015c0 6f 72 29 0a 20 20 20 20 20 20 20 20 20 20 2a 64 |or). *d|
000015d0 69 76 69 73 6f 72 3d 6f 6c 64 64 69 76 3b 0a 23 |ivisor=olddiv;.#|
000015e0 69 66 64 65 66 20 44 45 42 55 47 0a 20 20 20 74 |ifdef DEBUG. t|
000015f0 72 61 63 6b 65 72 5f 70 72 69 6e 74 66 28 22 52 |racker_printf("R|
00001600 65 6d 6f 74 65 20 70 6f 72 74 20 6e 61 6d 65 20 |emote port name |
00001610 3d 20 25 73 5c 6e 22 2c 72 65 6d 5f 73 65 72 76 |= %s\n",rem_serv|
00001620 29 3b 0a 23 65 6e 64 69 66 0a 20 20 20 20 20 20 |);.#endif. |
00001630 20 6f 6c 64 64 69 76 3d 2a 73 65 72 76 3b 0a 20 | olddiv=*serv;. |
00001640 20 20 20 20 20 20 2a 73 65 72 76 3d 27 5c 30 27 | *serv='\0'|
00001650 3b 0a 20 20 20 20 20 20 20 73 74 72 63 70 79 28 |;. strcpy(|
00001660 72 65 6d 5f 68 6f 73 74 2c 73 65 63 74 69 6f 6e |rem_host,section|
00001670 29 3b 0a 20 20 20 20 20 20 20 2a 73 65 72 76 3d |);. *serv=|
00001680 6f 6c 64 64 69 76 3b 0a 23 69 66 64 65 66 20 44 |olddiv;.#ifdef D|
00001690 45 42 55 47 0a 20 20 20 74 72 61 63 6b 65 72 5f |EBUG. tracker_|
000016a0 70 72 69 6e 74 66 28 22 52 65 6d 6f 74 65 20 68 |printf("Remote h|
000016b0 6f 73 74 20 70 61 72 74 20 3d 20 25 73 5c 6e 22 |ost part = %s\n"|
000016c0 2c 72 65 6d 5f 68 6f 73 74 29 3b 0a 23 65 6e 64 |,rem_host);.#end|
000016d0 69 66 0a 20 20 20 20 20 20 2f 2a 20 44 6f 20 27 |if. /* Do '|
000016e0 2e 27 20 61 6e 64 20 27 2f 27 20 72 65 70 6c 61 |.' and '/' repla|
000016f0 63 65 6d 65 6e 74 2e 20 2a 2f 0a 0a 20 20 20 20 |cement. */.. |
00001700 20 20 20 74 6d 70 70 74 72 3d 72 65 6d 5f 68 6f | tmpptr=rem_ho|
00001710 73 74 3b 0a 20 20 20 20 20 20 20 77 68 69 6c 65 |st;. while|
00001720 20 28 2a 74 6d 70 70 74 72 21 3d 27 5c 30 27 29 | (*tmpptr!='\0')|
00001730 20 7b 0a 20 20 20 20 20 20 20 20 20 69 66 20 28 | {. if (|
00001740 2a 74 6d 70 70 74 72 3d 3d 27 2f 27 29 0a 20 20 |*tmpptr=='/'). |
00001750 20 20 20 20 20 20 20 20 20 7b 0a 20 20 20 20 20 | {. |
00001760 20 20 20 20 20 20 20 20 2a 74 6d 70 70 74 72 3d | *tmpptr=|
00001770 27 2e 27 3b 0a 20 20 20 20 20 20 20 20 20 20 20 |'.';. |
00001780 7d 0a 20 20 20 20 20 20 20 20 20 74 6d 70 70 74 |}. tmppt|
00001790 72 2b 2b 3b 0a 20 20 20 20 20 20 20 7d 0a 23 69 |r++;. }.#i|
000017a0 66 64 65 66 20 44 45 42 55 47 0a 20 20 20 74 72 |fdef DEBUG. tr|
000017b0 61 63 6b 65 72 5f 70 72 69 6e 74 66 28 22 52 65 |acker_printf("Re|
000017c0 6d 6f 74 65 20 68 6f 73 74 20 3d 20 25 73 5c 6e |mote host = %s\n|
000017d0 22 2c 72 65 6d 5f 68 6f 73 74 29 3b 0a 23 65 6e |",rem_host);.#en|
000017e0 64 69 66 0a 20 20 20 20 20 20 20 68 70 3d 67 65 |dif. hp=ge|
000017f0 74 68 6f 73 74 62 79 6e 61 6d 65 28 72 65 6d 5f |thostbyname(rem_|
00001800 68 6f 73 74 29 3b 0a 20 20 20 20 20 20 20 69 66 |host);. if|
00001810 20 28 68 70 20 3d 3d 20 4e 55 4c 4c 29 20 7b 0a | (hp == NULL) {.|
00001820 20 20 20 20 20 20 20 20 20 65 72 72 73 74 72 3d | errstr=|
00001830 22 43 61 6e 27 74 20 66 69 6e 64 20 72 65 6d 6f |"Can't find remo|
00001840 74 65 20 69 6e 74 65 72 66 61 63 65 5c 6e 22 3b |te interface\n";|
00001850 0a 20 20 20 20 20 20 20 20 20 72 65 74 75 72 6e |. return|
00001860 20 2d 31 3b 0a 20 20 20 20 20 20 20 7d 0a 0a 20 | -1;. }.. |
00001870 20 20 20 20 20 20 62 7a 65 72 6f 28 28 63 68 61 | bzero((cha|
00001880 72 20 2a 29 26 73 69 6e 2c 20 73 69 7a 65 6f 66 |r *)&sin, sizeof|
00001890 28 73 69 6e 29 29 3b 0a 20 20 20 20 20 20 20 62 |(sin));. b|
000018a0 63 6f 70 79 28 68 70 2d 3e 68 5f 61 64 64 72 2c |copy(hp->h_addr,|
000018b0 20 28 63 61 64 64 72 5f 74 29 26 73 69 6e 2e 73 | (caddr_t)&sin.s|
000018c0 69 6e 5f 61 64 64 72 2c 20 68 70 2d 3e 68 5f 6c |in_addr, hp->h_l|
000018d0 65 6e 67 74 68 29 3b 0a 20 20 20 20 20 20 20 73 |ength);. s|
000018e0 69 6e 2e 73 69 6e 5f 66 61 6d 69 6c 79 3d 20 68 |in.sin_family= h|
000018f0 70 2d 3e 68 5f 61 64 64 72 74 79 70 65 3b 0a 20 |p->h_addrtype;. |
00001900 20 20 20 20 20 20 73 69 6e 2e 73 69 6e 5f 70 6f | sin.sin_po|
00001910 72 74 3d 68 74 6f 6e 73 28 61 74 6f 69 28 72 65 |rt=htons(atoi(re|
00001920 6d 5f 73 65 72 76 29 29 3b 0a 0a 20 20 20 20 20 |m_serv));.. |
00001930 20 20 2f 2a 20 54 68 65 72 65 20 69 73 20 61 6e | /* There is an|
00001940 20 69 6d 70 6c 69 63 69 74 20 61 73 73 75 6d 61 | implicit assuma|
00001950 74 69 6f 6e 20 68 65 72 65 20 74 68 61 74 20 6f |tion here that o|
00001960 75 72 20 68 6f 73 74 73 20 2a 2f 0a 20 20 20 20 |ur hosts */. |
00001970 20 20 20 2f 2a 20 61 6e 64 20 6e 65 74 77 6f 72 | /* and networ|
00001980 6b 20 72 65 70 72 65 73 65 6e 74 61 74 69 6f 6e |k representation|
00001990 73 20 6f 66 20 30 20 61 72 65 20 74 68 65 20 73 |s of 0 are the s|
000019a0 61 6d 65 20 20 20 20 20 20 20 2a 2f 0a 20 20 20 |ame */. |
000019b0 20 20 20 20 2f 2a 20 54 68 69 73 20 77 69 6c 6c | /* This will|
000019c0 20 62 65 20 74 72 75 65 20 66 6f 72 20 61 6c 6c | be true for all|
000019d0 20 62 69 67 20 26 20 6c 69 74 74 6c 65 20 65 6e | big & little en|
000019e0 64 69 61 6e 20 20 20 20 20 20 20 2a 2f 0a 20 20 |dian */. |
000019f0 20 20 20 20 20 2f 2a 20 6d 61 63 68 69 6e 65 73 | /* machines|
00001a00 2c 20 77 68 69 63 68 20 75 73 65 20 32 27 73 20 |, which use 2's |
00001a10 63 6f 6d 70 6c 65 6d 65 6e 74 20 20 20 20 20 20 |complement |
00001a20 20 20 20 20 20 20 20 20 20 20 20 20 2a 2f 0a 20 | */. |
00001a30 20 20 20 20 20 20 69 66 20 28 73 69 6e 2e 73 69 | if (sin.si|
00001a40 6e 5f 70 6f 72 74 3d 3d 30 29 20 7b 0a 20 20 20 |n_port==0) {. |
00001a50 20 20 20 20 20 20 73 70 3d 67 65 74 73 65 72 76 | sp=getserv|
00001a60 62 79 6e 61 6d 65 28 72 65 6d 5f 73 65 72 76 2c |byname(rem_serv,|
00001a70 70 72 6f 74 6f 29 3b 0a 20 20 20 20 20 20 20 20 |proto);. |
00001a80 20 69 66 20 28 73 70 20 3d 3d 20 4e 55 4c 4c 29 | if (sp == NULL)|
00001a90 20 7b 0a 20 20 20 20 20 20 20 20 20 20 20 65 72 | {. er|
00001aa0 72 73 74 72 3d 22 43 61 6e 27 74 20 72 65 73 6f |rstr="Can't reso|
00001ab0 6c 76 65 20 72 65 6d 6f 74 65 20 73 65 72 76 69 |lve remote servi|
00001ac0 63 65 5c 6e 22 3b 0a 20 20 20 20 20 20 20 20 20 |ce\n";. |
00001ad0 20 20 72 65 74 75 72 6e 20 2d 31 3b 0a 20 20 20 | return -1;. |
00001ae0 20 20 20 20 20 20 20 7d 0a 20 20 20 20 20 20 20 | }. |
00001af0 20 20 73 69 6e 2e 73 69 6e 5f 70 6f 72 74 20 20 | sin.sin_port |
00001b00 3d 20 73 70 2d 3e 73 5f 70 6f 72 74 3b 0a 20 20 |= sp->s_port;. |
00001b10 20 20 20 20 20 20 7d 0a 23 69 66 64 65 66 20 44 | }.#ifdef D|
00001b20 45 42 55 47 0a 74 72 61 63 6b 65 72 5f 70 72 69 |EBUG.tracker_pri|
00001b30 6e 74 66 28 22 52 65 6d 6f 74 65 20 70 6f 72 74 |ntf("Remote port|
00001b40 20 6e 6f 20 3d 20 25 64 5c 6e 22 2c 6e 74 6f 68 | no = %d\n",ntoh|
00001b50 73 28 73 69 6e 2e 73 69 6e 5f 70 6f 72 74 29 29 |s(sin.sin_port))|
00001b60 3b 0a 23 65 6e 64 69 66 0a 20 20 20 20 20 20 20 |;.#endif. |
00001b70 7d 0a 0a 20 20 20 20 20 69 66 20 28 2a 64 69 76 |}.. if (*div|
00001b80 69 73 6f 72 3d 3d 27 5c 30 27 29 0a 20 20 20 20 |isor=='\0'). |
00001b90 20 20 7b 0a 23 69 66 64 65 66 20 44 45 42 55 47 | {.#ifdef DEBUG|
00001ba0 0a 74 72 61 63 6b 65 72 5f 73 69 6d 70 6c 65 28 |.tracker_simple(|
00001bb0 22 43 72 65 61 74 69 6e 67 20 73 6f 63 6b 65 74 |"Creating socket|
00001bc0 2e 2e 2e 20 22 29 3b 0a 23 65 6e 64 69 66 0a 20 |... ");.#endif. |
00001bd0 20 20 20 20 20 20 20 73 3d 73 6f 63 6b 65 74 28 | s=socket(|
00001be0 41 46 5f 49 4e 45 54 2c 53 4f 43 4b 5f 53 54 52 |AF_INET,SOCK_STR|
00001bf0 45 41 4d 2c 30 29 3b 0a 23 69 66 64 65 66 20 44 |EAM,0);.#ifdef D|
00001c00 45 42 55 47 0a 74 72 61 63 6b 65 72 5f 73 69 6d |EBUG.tracker_sim|
00001c10 70 6c 65 28 22 64 6f 6e 65 5c 6e 22 29 3b 0a 23 |ple("done\n");.#|
00001c20 65 6e 64 69 66 0a 20 20 20 20 20 20 20 20 69 66 |endif. if|
00001c30 20 28 73 3d 3d 2d 31 29 20 72 65 74 75 72 6e 20 | (s==-1) return |
00001c40 73 3b 0a 20 20 20 20 20 20 7d 0a 20 20 20 20 20 |s;. }. |
00001c50 20 65 6c 73 65 0a 20 20 20 20 20 20 7b 0a 20 20 | else. {. |
00001c60 20 20 20 20 20 73 65 63 74 69 6f 6e 3d 64 69 76 | section=div|
00001c70 69 73 6f 72 2b 31 3b 0a 20 20 20 20 20 20 20 73 |isor+1;. s|
00001c80 65 72 76 3d 73 74 72 73 74 72 28 73 65 63 74 69 |erv=strstr(secti|
00001c90 6f 6e 2c 22 5c 5c 22 29 3b 0a 0a 20 20 20 20 20 |on,"\\");.. |
00001ca0 20 20 69 66 20 28 21 73 65 72 76 29 0a 20 20 20 | if (!serv). |
00001cb0 20 20 20 20 20 20 7b 0a 20 20 20 20 20 20 20 20 | {. |
00001cc0 20 2f 2a 0a 20 20 20 20 20 20 20 20 20 20 2a 20 | /*. * |
00001cd0 4e 6f 20 27 5c 27 20 69 6e 20 6c 6f 63 61 6c 20 |No '\' in local |
00001ce0 70 61 72 74 2e 2e 2e 2e 0a 20 20 20 20 20 20 20 |part..... |
00001cf0 20 20 20 2a 20 43 75 72 72 65 6e 74 6c 79 20 77 | * Currently w|
00001d00 65 20 69 67 6e 6f 72 65 20 61 6c 6c 20 74 68 65 |e ignore all the|
00001d10 6e 21 0a 20 20 20 20 20 20 20 20 20 20 2a 2f 0a |n!. */.|
00001d20 0a 20 20 20 20 20 20 20 20 20 73 3d 73 6f 63 6b |. s=sock|
00001d30 65 74 28 41 46 5f 49 4e 45 54 2c 53 4f 43 4b 5f |et(AF_INET,SOCK_|
00001d40 53 54 52 45 41 4d 2c 30 29 3b 0a 20 20 20 20 20 |STREAM,0);. |
00001d50 20 20 20 20 7d 0a 0a 20 20 20 20 20 20 20 20 20 | }.. |
00001d60 65 6c 73 65 0a 20 20 20 20 20 20 20 20 20 7b 0a |else. {.|
00001d70 20 20 20 20 20 20 20 20 20 2f 2a 20 27 5c 27 20 | /* '\' |
00001d80 69 6e 20 74 68 65 20 6c 6f 63 61 6c 20 70 61 72 |in the local par|
00001d90 74 20 2a 2f 0a 23 69 66 64 65 66 20 44 45 42 55 |t */.#ifdef DEBU|
00001da0 47 0a 74 72 61 63 6b 65 72 5f 70 72 69 6e 74 66 |G.tracker_printf|
00001db0 28 22 6c 6f 63 61 6c 20 70 6f 72 74 20 73 70 65 |("local port spe|
00001dc0 63 69 66 69 65 64 20 2d 20 25 73 5c 6e 22 2c 73 |cified - %s\n",s|
00001dd0 65 63 74 69 6f 6e 29 3b 0a 23 65 6e 64 69 66 0a |ection);.#endif.|
00001de0 0a 20 20 20 20 20 20 20 20 20 20 2a 64 69 76 69 |. *divi|
00001df0 73 6f 72 3d 27 5c 30 27 3b 0a 20 20 20 20 20 20 |sor='\0';. |
00001e00 20 20 20 20 73 74 72 63 70 79 28 6c 63 6c 5f 73 | strcpy(lcl_s|
00001e10 65 72 76 2c 73 65 72 76 2b 31 29 3b 0a 0a 23 69 |erv,serv+1);..#i|
00001e20 66 64 65 66 20 44 45 42 55 47 0a 20 20 20 74 72 |fdef DEBUG. tr|
00001e30 61 63 6b 65 72 5f 70 72 69 6e 74 66 28 22 4c 6f |acker_printf("Lo|
00001e40 63 61 6c 20 70 6f 72 74 20 6e 61 6d 65 20 3d 20 |cal port name = |
00001e50 25 73 5c 6e 22 2c 6c 63 6c 5f 73 65 72 76 29 3b |%s\n",lcl_serv);|
00001e60 0a 23 65 6e 64 69 66 0a 20 20 20 20 20 20 20 20 |.#endif. |
00001e70 20 20 2a 73 65 72 76 3d 27 5c 30 27 3b 0a 20 20 | *serv='\0';. |
00001e80 20 20 20 20 20 20 20 20 73 74 72 63 70 79 28 6c | strcpy(l|
00001e90 63 6c 5f 68 6f 73 74 2c 73 65 63 74 69 6f 6e 29 |cl_host,section)|
00001ea0 3b 0a 0a 23 69 66 64 65 66 20 44 45 42 55 47 0a |;..#ifdef DEBUG.|
00001eb0 20 20 20 74 72 61 63 6b 65 72 5f 70 72 69 6e 74 | tracker_print|
00001ec0 66 28 22 4c 6f 63 61 6c 20 48 6f 73 74 20 70 61 |f("Local Host pa|
00001ed0 72 74 20 3d 20 25 73 5c 6e 22 2c 6c 63 6c 5f 68 |rt = %s\n",lcl_h|
00001ee0 6f 73 74 29 3b 0a 23 65 6e 64 69 66 0a 20 20 20 |ost);.#endif. |
00001ef0 20 20 20 20 20 20 20 2f 2a 44 6f 20 27 2e 27 20 | /*Do '.' |
00001f00 61 6e 64 20 27 2f 27 20 72 65 70 6c 61 63 65 6d |and '/' replacem|
00001f10 65 6e 74 2e 2a 2f 0a 20 20 20 20 20 20 20 20 20 |ent.*/. |
00001f20 20 74 6d 70 70 74 72 3d 6c 63 6c 5f 68 6f 73 74 | tmpptr=lcl_host|
00001f30 3b 0a 20 20 20 20 20 20 20 20 20 20 77 68 69 6c |;. whil|
00001f40 65 20 28 2a 74 6d 70 70 74 72 3d 3d 27 5c 30 27 |e (*tmpptr=='\0'|
00001f50 29 20 7b 0a 20 20 20 20 20 20 20 20 20 20 20 20 |) {. |
00001f60 69 66 20 28 2a 74 6d 70 70 74 72 3d 3d 27 2f 27 |if (*tmpptr=='/'|
00001f70 29 0a 20 20 20 20 20 20 20 20 20 20 20 20 20 20 |). |
00001f80 7b 0a 20 20 20 20 20 20 20 20 20 20 20 20 20 20 |{. |
00001f90 20 20 2a 74 6d 70 70 74 72 3d 27 2e 27 3b 0a 20 | *tmpptr='.';. |
00001fa0 20 20 20 20 20 20 20 20 20 20 20 20 20 7d 0a 20 | }. |
00001fb0 20 20 20 20 20 20 20 20 20 7d 0a 0a 23 69 66 64 | }..#ifd|
00001fc0 65 66 20 44 45 42 55 47 0a 20 20 20 74 72 61 63 |ef DEBUG. trac|
00001fd0 6b 65 72 5f 70 72 69 6e 74 66 28 22 4c 6f 63 61 |ker_printf("Loca|
00001fe0 6c 20 68 6f 73 74 20 3d 20 25 73 5c 6e 22 2c 6c |l host = %s\n",l|
00001ff0 63 6c 5f 68 6f 73 74 29 3b 0a 23 65 6e 64 69 66 |cl_host);.#endif|
00002000 0a 20 20 20 20 20 20 20 20 20 20 69 66 20 28 21 |. if (!|
00002010 73 74 72 63 6d 70 28 6c 63 6c 5f 68 6f 73 74 2c |strcmp(lcl_host,|
00002020 22 61 75 74 6f 22 29 29 20 7b 0a 20 20 20 20 20 |"auto")) {. |
00002030 20 20 20 20 20 20 20 67 65 74 68 6f 73 74 6e 61 | gethostna|
00002040 6d 65 28 6c 63 6c 5f 68 6f 73 74 2c 73 69 7a 65 |me(lcl_host,size|
00002050 6f 66 28 6c 63 6c 5f 68 6f 73 74 29 29 3b 0a 20 |of(lcl_host));. |
00002060 20 20 20 20 20 20 20 20 20 20 20 6c 63 6c 5f 68 | lcl_h|
00002070 6f 73 74 5b 73 69 7a 65 6f 66 28 6c 63 6c 5f 68 |ost[sizeof(lcl_h|
00002080 6f 73 74 29 2d 31 5d 3d 27 5c 30 27 3b 0a 20 20 |ost)-1]='\0';. |
00002090 20 20 20 20 20 20 20 20 7d 0a 0a 20 20 20 20 20 | }.. |
000020a0 20 20 20 20 20 68 70 3d 67 65 74 68 6f 73 74 62 | hp=gethostb|
000020b0 79 6e 61 6d 65 28 6c 63 6c 5f 68 6f 73 74 29 3b |yname(lcl_host);|
000020c0 0a 20 20 20 20 20 20 20 20 20 20 69 66 20 28 68 |. if (h|
000020d0 70 20 3d 3d 20 4e 55 4c 4c 29 20 7b 0a 20 20 20 |p == NULL) {. |
000020e0 20 20 20 20 20 20 20 20 20 65 72 72 73 74 72 3d | errstr=|
000020f0 22 43 61 6e 27 74 20 66 69 6e 64 20 6c 6f 63 61 |"Can't find loca|
00002100 6c 20 69 6e 74 65 72 66 61 63 65 5c 6e 22 3b 0a |l interface\n";.|
00002110 20 20 20 20 20 20 20 20 20 20 20 20 72 65 74 75 | retu|
00002120 72 6e 20 2d 31 3b 0a 20 20 20 20 20 20 20 20 20 |rn -1;. |
00002130 20 7d 0a 0a 20 20 20 20 20 20 20 20 20 20 73 3d | }.. s=|
00002140 73 6f 63 6b 65 74 28 41 46 5f 49 4e 45 54 2c 53 |socket(AF_INET,S|
00002150 4f 43 4b 5f 53 54 52 45 41 4d 2c 30 29 3b 0a 20 |OCK_STREAM,0);. |
00002160 20 20 20 20 20 20 20 20 20 69 66 20 28 73 3d 3d | if (s==|
00002170 2d 31 29 20 72 65 74 75 72 6e 20 73 3b 0a 0a 20 |-1) return s;.. |
00002180 20 20 20 20 20 20 20 20 20 62 7a 65 72 6f 28 28 | bzero((|
00002190 63 68 61 72 20 2a 29 26 73 6f 75 74 2c 20 73 69 |char *)&sout, si|
000021a0 7a 65 6f 66 28 73 6f 75 74 29 29 3b 0a 20 20 20 |zeof(sout));. |
000021b0 20 20 20 20 20 20 20 62 63 6f 70 79 28 68 70 2d | bcopy(hp-|
000021c0 3e 68 5f 61 64 64 72 2c 20 28 63 61 64 64 72 5f |>h_addr, (caddr_|
000021d0 74 29 26 73 6f 75 74 2e 73 69 6e 5f 61 64 64 72 |t)&sout.sin_addr|
000021e0 2c 20 68 70 2d 3e 68 5f 6c 65 6e 67 74 68 29 3b |, hp->h_length);|
000021f0 0a 20 20 20 20 20 20 20 20 20 20 73 6f 75 74 2e |. sout.|
00002200 73 69 6e 5f 66 61 6d 69 6c 79 3d 20 68 70 2d 3e |sin_family= hp->|
00002210 68 5f 61 64 64 72 74 79 70 65 3b 0a 23 69 66 64 |h_addrtype;.#ifd|
00002220 65 66 20 44 45 42 55 47 0a 74 72 61 63 6b 65 72 |ef DEBUG.tracker|
00002230 5f 70 72 69 6e 74 66 28 22 4c 6f 63 61 6c 20 69 |_printf("Local i|
00002240 2f 66 20 20 3d 20 25 73 5c 6e 22 2c 6c 63 6c 5f |/f = %s\n",lcl_|
00002250 68 6f 73 74 29 3b 0a 23 65 6e 64 69 66 0a 0a 20 |host);.#endif.. |
00002260 20 20 20 20 20 20 20 20 20 69 66 20 28 73 74 72 | if (str|
00002270 63 6d 70 28 6c 63 6c 5f 73 65 72 76 2c 22 61 75 |cmp(lcl_serv,"au|
00002280 74 6f 22 29 29 20 7b 0a 20 20 20 20 20 20 20 20 |to")) {. |
00002290 20 20 20 20 73 6f 75 74 2e 73 69 6e 5f 70 6f 72 | sout.sin_por|
000022a0 74 3d 68 74 6f 6e 73 28 61 74 6f 69 28 6c 63 6c |t=htons(atoi(lcl|
000022b0 5f 73 65 72 76 29 29 3b 0a 0a 20 20 20 20 20 20 |_serv));.. |
000022c0 20 2f 2a 20 54 68 65 72 65 20 69 73 20 61 6e 20 | /* There is an |
000022d0 69 6d 70 6c 69 63 69 74 20 61 73 73 75 6d 61 74 |implicit assumat|
000022e0 69 6f 6e 20 68 65 72 65 20 74 68 61 74 20 6f 75 |ion here that ou|
000022f0 72 20 68 6f 73 74 73 20 2a 2f 0a 20 20 20 20 20 |r hosts */. |
00002300 20 20 2f 2a 20 61 6e 64 20 74 68 65 20 6e 65 74 | /* and the net|
00002310 77 6f 72 6b 20 72 65 70 72 65 73 65 6e 74 61 74 |work representat|
00002320 69 6f 6e 73 20 6f 66 20 30 20 61 72 65 20 74 68 |ions of 0 are th|
00002330 65 20 73 61 6d 65 20 20 20 2a 2f 0a 20 20 20 20 |e same */. |
00002340 20 20 20 2f 2a 20 54 68 69 73 20 77 69 6c 6c 20 | /* This will |
00002350 62 65 20 74 72 75 65 20 66 6f 72 20 61 6c 6c 20 |be true for all |
00002360 62 69 67 20 26 20 6c 69 74 74 6c 65 20 65 6e 64 |big & little end|
00002370 69 61 6e 20 20 20 20 20 20 20 2a 2f 0a 20 20 20 |ian */. |
00002380 20 20 20 20 2f 2a 20 6d 61 63 68 69 6e 65 73 2c | /* machines,|
00002390 20 77 68 69 63 68 20 75 73 65 20 32 27 73 20 63 | which use 2's c|
000023a0 6f 6d 70 6c 65 6d 65 6e 74 2e 20 20 20 20 20 20 |omplement. |
000023b0 20 20 20 20 20 20 20 20 20 20 20 2a 2f 0a 20 20 | */. |
000023c0 20 20 20 20 20 20 20 20 20 20 69 66 20 28 73 6f | if (so|
000023d0 75 74 2e 73 69 6e 5f 70 6f 72 74 3d 3d 30 29 20 |ut.sin_port==0) |
000023e0 7b 0a 20 20 20 20 20 20 20 20 20 20 20 20 20 20 |{. |
000023f0 73 70 3d 67 65 74 73 65 72 76 62 79 6e 61 6d 65 |sp=getservbyname|
00002400 28 6c 63 6c 5f 73 65 72 76 2c 70 72 6f 74 6f 29 |(lcl_serv,proto)|
00002410 3b 0a 20 20 20 20 20 20 20 20 20 20 20 20 20 20 |;. |
00002420 69 66 20 28 73 70 20 3d 3d 20 4e 55 4c 4c 29 20 |if (sp == NULL) |
00002430 7b 0a 20 20 20 20 20 20 20 20 20 20 20 20 20 20 |{. |
00002440 20 20 65 72 72 73 74 72 3d 22 43 61 6e 27 74 20 | errstr="Can't |
00002450 72 65 73 6f 6c 76 65 20 6c 6f 63 61 6c 20 73 65 |resolve local se|
00002460 72 76 69 63 65 5c 6e 22 3b 0a 20 20 20 20 20 20 |rvice\n";. |
00002470 20 20 20 20 20 20 20 20 20 20 72 65 74 75 72 6e | return|
00002480 20 2d 31 3b 0a 20 20 20 20 20 20 20 20 20 20 20 | -1;. |
00002490 20 20 20 20 7d 0a 20 20 20 20 20 20 20 20 20 20 | }. |
000024a0 20 20 20 20 73 6f 75 74 2e 73 69 6e 5f 70 6f 72 | sout.sin_por|
000024b0 74 20 20 3d 20 73 70 2d 3e 73 5f 70 6f 72 74 3b |t = sp->s_port;|
000024c0 0a 20 20 20 20 20 20 20 20 20 20 20 20 7d 0a 20 |. }. |
000024d0 20 20 20 20 20 20 20 20 20 7d 0a 23 69 66 64 65 | }.#ifde|
000024e0 66 20 44 45 42 55 47 0a 74 72 61 63 6b 65 72 5f |f DEBUG.tracker_|
000024f0 70 72 69 6e 74 66 28 22 52 65 6d 6f 74 65 20 70 |printf("Remote p|
00002500 6f 72 74 20 6e 6f 20 3d 20 25 64 5c 6e 22 2c 6e |ort no = %d\n",n|
00002510 74 6f 68 73 28 73 69 6e 2e 73 69 6e 5f 70 6f 72 |tohs(sin.sin_por|
00002520 74 29 29 3b 0a 23 65 6e 64 69 66 0a 0a 23 69 66 |t));.#endif..#if|
00002530 64 65 66 20 44 45 42 55 47 0a 74 72 61 63 6b 65 |def DEBUG.tracke|
00002540 72 5f 73 69 6d 70 6c 65 28 22 74 72 79 69 6e 67 |r_simple("trying|
00002550 20 74 6f 20 62 69 6e 64 20 73 6f 63 6b 65 74 20 | to bind socket |
00002560 2e 2e 2e 2e 20 22 29 3b 0a 23 65 6e 64 69 66 0a |.... ");.#endif.|
00002570 20 20 20 20 20 20 20 20 20 20 20 20 69 66 20 28 | if (|
00002580 62 69 6e 64 28 73 2c 26 73 6f 75 74 2c 73 69 7a |bind(s,&sout,siz|
00002590 65 6f 66 28 73 6f 75 74 29 29 3d 3d 2d 31 29 20 |eof(sout))==-1) |
000025a0 72 65 74 75 72 6e 20 2d 31 3b 0a 23 69 66 64 65 |return -1;.#ifde|
000025b0 66 20 44 45 42 55 47 0a 74 72 61 63 6b 65 72 5f |f DEBUG.tracker_|
000025c0 73 69 6d 70 6c 65 28 22 64 6f 6e 65 5c 6e 22 29 |simple("done\n")|
000025d0 3b 0a 23 65 6e 64 69 66 0a 0a 0a 20 20 20 20 20 |;.#endif... |
000025e0 20 20 20 20 7d 0a 20 20 20 20 20 20 7d 0a 20 20 | }. }. |
000025f0 20 20 69 6f 63 74 6c 28 73 2c 46 49 4f 4d 4f 44 | ioctl(s,FIOMOD|
00002600 45 2c 26 6f 6e 65 29 3b 0a 23 69 66 64 65 66 20 |E,&one);.#ifdef |
00002610 44 45 42 55 47 0a 74 72 61 63 6b 65 72 5f 73 69 |DEBUG.tracker_si|
00002620 6d 70 6c 65 28 22 74 72 79 69 6e 67 20 74 6f 20 |mple("trying to |
00002630 63 6f 6e 6e 65 63 74 20 2e 2e 2e 2e 20 22 29 3b |connect .... ");|
00002640 0a 23 65 6e 64 69 66 0a 20 20 20 20 69 66 20 28 |.#endif. if (|
00002650 63 6f 6e 6e 65 63 74 28 73 2c 26 73 69 6e 2c 73 |connect(s,&sin,s|
00002660 69 7a 65 6f 66 28 73 69 6e 29 29 3d 3d 2d 31 29 |izeof(sin))==-1)|
00002670 20 72 65 74 75 72 6e 20 2d 31 3b 0a 23 69 66 64 | return -1;.#ifd|
00002680 65 66 20 44 45 42 55 47 0a 74 72 61 63 6b 65 72 |ef DEBUG.tracker|
00002690 5f 73 69 6d 70 6c 65 28 22 64 6f 6e 65 5c 6e 22 |_simple("done\n"|
000026a0 29 3b 0a 23 65 6e 64 69 66 0a 20 20 20 20 72 65 |);.#endif. re|
000026b0 74 75 72 6e 20 73 3b 0a 20 7d 0a 0a 0a 69 6e 74 |turn s;. }...int|
000026c0 20 73 6f 63 6b 32 66 64 28 63 68 61 72 2a 20 66 | sock2fd(char* f|
000026d0 69 6c 65 6e 61 6d 65 29 0a 20 7b 0a 20 20 20 63 |ilename). {. c|
000026e0 68 61 72 20 2a 66 6c 61 67 73 2c 2a 64 65 73 63 |har *flags,*desc|
000026f0 3b 0a 0a 20 20 20 66 6c 61 67 73 3d 73 74 72 73 |;.. flags=strs|
00002700 74 72 28 66 69 6c 65 6e 61 6d 65 2c 22 3a 22 29 |tr(filename,":")|
00002710 3b 20 2f 2a 53 68 6f 75 6c 64 20 62 65 20 31 73 |; /*Should be 1s|
00002720 74 20 63 68 61 72 20 2a 2f 0a 20 20 20 64 65 73 |t char */. des|
00002730 63 3d 73 74 72 73 74 72 28 66 69 6c 65 6e 61 6d |c=strstr(filenam|
00002740 65 2c 22 2e 24 2e 22 29 3b 0a 20 20 20 69 66 20 |e,".$.");. if |
00002750 28 21 64 65 73 63 29 0a 20 20 20 20 20 72 65 74 |(!desc). ret|
00002760 75 72 6e 20 2d 31 3b 0a 20 20 20 69 66 20 69 73 |urn -1;. if is|
00002770 64 69 67 69 74 28 64 65 73 63 5b 33 5d 29 0a 20 |digit(desc[3]). |
00002780 20 20 7b 0a 20 20 20 20 20 72 65 74 75 72 6e 20 | {. return |
00002790 61 74 6f 69 28 64 65 73 63 5b 33 5d 29 3b 0a 20 |atoi(desc[3]);. |
000027a0 20 20 7d 0a 0a 20 20 20 72 65 74 75 72 6e 20 2d | }.. return -|
000027b0 31 3b 0a 20 20 20 2f 2a 57 65 20 69 67 6e 6f 72 |1;. /*We ignor|
000027c0 65 20 74 68 65 20 6d 65 61 6e 69 6e 67 20 6f 66 |e the meaning of|
000027d0 20 74 68 65 20 66 6c 61 67 73 20 73 65 63 74 69 | the flags secti|
000027e0 6f 6e 20 63 75 72 72 65 6e 74 6c 79 20 2a 2f 0a |on currently */.|
000027f0 20 7d 0a | }.|
000027f3
.