Subversion Repositories SvarDOS

Rev

Rev 329 | Rev 335 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 329 Rev 333
Line 12... Line 12...
12
#include <tcp.h>
12
#include <tcp.h>
13
 
13
 
14
#include "net.h" /* include self for control */
14
#include "net.h" /* include self for control */
15
 
15
 
16
 
16
 
-
 
17
struct net_tcpsocket {
-
 
18
  tcp_Socket *sock;
-
 
19
  tcp_Socket _sock; /* watt32 socket */
-
 
20
};
-
 
21
 
-
 
22
 
17
int net_dnsresolve(char *ip, const char *name) {
23
int net_dnsresolve(char *ip, const char *name) {
18
  unsigned long ipnum;
24
  unsigned long ipnum;
19
  ipnum = resolve(name); /* I could use WatTCP's lookup_host() here to do all
25
  ipnum = resolve(name); /* I could use WatTCP's lookup_host() here to do all
20
                            the job for me, unfortunately lookup_host() issues
26
                            the job for me, unfortunately lookup_host() issues
21
                            wild outs() calls putting garbage on screen... */
27
                            wild outs() calls putting garbage on screen... */
Line 45... Line 51...
45
 
51
 
46
  /* convert ip to value */
52
  /* convert ip to value */
47
  ipaddr = _inet_addr(ipstr);
53
  ipaddr = _inet_addr(ipstr);
48
  if (ipaddr == 0) return(NULL);
54
  if (ipaddr == 0) return(NULL);
49
 
55
 
50
  resultsock = calloc(sizeof(struct net_tcpsocket) + sizeof(tcp_Socket), 1);
56
  resultsock = calloc(sizeof(struct net_tcpsocket), 1);
51
  if (resultsock == NULL) return(NULL);
57
  if (resultsock == NULL) return(NULL);
52
  resultsock->sock = resultsock->buffer;
58
  resultsock->sock = &(resultsock->_sock);
53
  if (resultsock->sock == NULL) {
-
 
54
    free(resultsock);
-
 
55
    return(NULL);
-
 
56
  }
-
 
57
 
59
 
58
  /* explicitely set user-managed buffer to none (watt32 will use its own internal buffer) */
60
  /* explicitely set user-managed buffer to none (watt32 will use its own internal buffer) */
59
  sock_setbuf(resultsock->sock, NULL, 0);
61
  sock_setbuf(resultsock->sock, NULL, 0);
60
 
62
 
61
  if (!tcp_open(resultsock->sock, 0, ipaddr, port, NULL)) {
63
  if (!tcp_open(resultsock->sock, 0, ipaddr, port, NULL)) {
Line 97... Line 99...
97
/* Close the 'sock' socket. */
99
/* Close the 'sock' socket. */
98
void net_close(struct net_tcpsocket *socket) {
100
void net_close(struct net_tcpsocket *socket) {
99
  /* I could use sock_close() and sock_wait_closed() if I'd want to be
101
  /* I could use sock_close() and sock_wait_closed() if I'd want to be
100
   * friendly, but it's much easier on the tcp stack to send a single RST and
102
   * friendly, but it's much easier on the tcp stack to send a single RST and
101
   * forget about the connection (esp. if the peer is misbehaving) */
103
   * forget about the connection (esp. if the peer is misbehaving) */
102
  net_abort(socket);
-
 
103
}
-
 
104
 
-
 
105
 
-
 
106
/* Close the 'sock' socket immediately (to be used when the peer is behaving wrongly) - this is much faster than net_close(). */
-
 
107
void net_abort(struct net_tcpsocket *socket) {
-
 
108
  sock_abort(socket->sock);
104
  sock_abort(socket->sock);
109
  free(socket);
105
  free(socket);
110
}
106
}
111
 
107
 
112
 
108