~ubuntu-branches/ubuntu/karmic/edbrowse/karmic-security

« back to all changes in this revision

Viewing changes to tcp.c

  • Committer: Bazaar Package Importer
  • Author(s): Kapil Hari Paranjape
  • Date: 2007-05-09 07:33:04 UTC
  • mfrom: (1.1.2 upstream)
  • Revision ID: james.westby@ubuntu.com-20070509073304-ywptg9g6iiitsg17
Tags: 3.2.1-1
* New upstream version (3.2.1). Closes: #421451.
  - can fetch and execute a local javascript file
    if required by local html file.
  - provide COPYING and CHANGES files.
* debian/rules:
  - add CHANGES to dh_installchangelogs line.
  - add dh_installman entry to install the man page.
* debian/copyright: updated to include the COPYING file.
* debian/edbrowse.1: added a basic man page.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* tcp.c: NT/Unix TCP layer for Intellivoice */
 
1
/* tcp.c: NT/Unix TCP layer for portable socket applications */
2
2
 
3
3
 
4
4
/*********************************************************************
46
46
/* Global variables.  See tcp.h for comments. */
47
47
char tcp_thisMachineName[MAXHOSTNAMELEN];
48
48
char tcp_thisMachineDots[20];
49
 
long tcp_thisMachineIP;
 
49
IP32bit tcp_thisMachineIP;
50
50
char tcp_farMachineDots[20];
51
 
long tcp_farMachineIP;
 
51
IP32bit tcp_farMachineIP;
52
52
short tcp_farMachinePort;
53
53
 
54
54
 
90
90
Routines to convert between names and IP addresses.
91
91
*********************************************************************/
92
92
 
93
 
long
 
93
IP32bit
94
94
tcp_name_ip(const char *name)
95
95
{
96
96
    struct hostent *hp;
97
 
    long *ip;
 
97
    IP32bit *ip;
98
98
 
99
99
    hp = gethostbyname(name);
100
100
#if 0
101
101
    printf("%s\n", hstrerror(h_errno));
102
102
#endif
103
103
    if(!hp)
104
 
        return -1;
 
104
        return NULL_IP;
105
105
#if 0
106
106
    puts("found it");
107
107
    if(hp->h_aliases) {
113
113
        }
114
114
    }
115
115
#endif
116
 
    ip = (long *)*(hp->h_addr_list);
 
116
    ip = (IP32bit *)*(hp->h_addr_list);
117
117
    if(!ip)
118
 
        return -1;
 
118
        return NULL_IP;
119
119
    return *ip;
120
120
}                               /* tcp_name_ip */
121
121
 
122
122
char *
123
123
tcp_name_dots(const char *name)
124
124
{
125
 
    long ip = tcp_name_ip(name);
126
 
    if(ip == -1)
 
125
    IP32bit ip = tcp_name_ip(name);
 
126
    if(ip == NULL_IP)
127
127
        return 0;
128
128
    return tcp_ip_dots(ip);
129
129
}                               /* tcp_name_dots */
130
130
 
131
131
char *
132
 
tcp_ip_dots(long ip)
 
132
tcp_ip_dots(IP32bit ip)
133
133
{
134
134
    return inet_ntoa(*(struct in_addr *)&ip);
135
135
}                               /* tcp_ip_dots */
157
157
    return (nd == 3);
158
158
}                               /* tcp_isDots */
159
159
 
160
 
long
 
160
IP32bit
161
161
tcp_dots_ip(const char *s)
162
162
{
163
163
    struct in_addr a;
165
165
#ifdef SCO
166
166
    inet_aton(s, &a);
167
167
#else
168
 
    *(long *)&a = inet_addr(s);
 
168
    *(IP32bit *)&a = inet_addr(s);
169
169
#endif
170
 
    return *(long *)&a;
 
170
    return *(IP32bit *)&a;
171
171
}                               /* tcp_dots_ip */
172
172
 
173
173
char *
174
 
tcp_ip_name(long ip)
 
174
tcp_ip_name(IP32bit ip)
175
175
{
176
176
    struct hostent *hp = gethostbyaddr((char *)&ip, 4, AF_INET);
177
177
    if(!hp)
225
225
}                               /* makeSocket */
226
226
 
227
227
int
228
 
tcp_connect(long ip, int portnum, int timeout)
 
228
tcp_connect(IP32bit ip, int portnum, int timeout)
229
229
{
230
230
    struct sockaddr_in sa;
231
231
    int s;                      /* file descriptor of socket */
381
381
int
382
382
tcp_write(int fh, const char *buf, int buflen)
383
383
{
384
 
    int n = send(fh, buf, buflen, 0);
385
 
    if(n < 0)
386
 
        setErrnoNT();
387
 
    return n;
 
384
    int savelen = buflen;
 
385
    int n;
 
386
    while(buflen) {
 
387
        n = send(fh, buf, buflen, 0);
 
388
        if(n < 0) {
 
389
            setErrnoNT();
 
390
            return n;
 
391
        }
 
392
        buf += n, buflen -= n;
 
393
    }
 
394
    return savelen;
388
395
}                               /* tcp_write */
389
396
 
390
397
 
400
407
int
401
408
main(int argc, char **argv)
402
409
{
403
 
    long ip;
 
410
    IP32bit ip;
404
411
    int port;
405
412
    int fh;
406
413
    int nb;                     /* number of bytes */
445
452
    /* listen */
446
453
    ip = tcp_name_ip(argv[2]);
447
454
    port = atoi(argv[3]);
448
 
    if(ip == -1) {
 
455
    if(ip == NULL_IP) {
449
456
        fprintf(stderr, "no such machine %s\n", argv[2]);
450
457
        exit(0);
451
458
    }