VirtualBox

source: vbox/trunk/src/VBox/Devices/Network/slirp/misc.c@ 16303

Last change on this file since 16303 was 15791, checked in by vboxsync, 16 years ago

NAT: malloc/free/realloc/strdup => iprt functions; fixed VBOX_WITH_SLIRP_MEMORY_CHECK

  • Property svn:eol-style set to native
File size: 2.4 KB
Line 
1/*
2 * Copyright (c) 1995 Danny Gasparovski.
3 *
4 * Please read the file COPYRIGHT for the
5 * terms and conditions of the copyright.
6 */
7
8#define WANT_SYS_IOCTL_H
9#include <slirp.h>
10
11#ifndef HAVE_INET_ATON
12int
13inet_aton(const char *cp, struct in_addr *ia)
14{
15 u_int32_t addr = inet_addr(cp);
16 if (addr == 0xffffffff)
17 return 0;
18 ia->s_addr = addr;
19 return 1;
20}
21#endif
22
23/*
24 * Get our IP address and put it in our_addr
25 */
26void
27getouraddr(PNATState pData)
28{
29 our_addr.s_addr = loopback_addr.s_addr;
30}
31
32struct quehead
33{
34 struct quehead *qh_link;
35 struct quehead *qh_rlink;
36};
37
38void
39insque(PNATState pData, void *a, void *b)
40{
41 register struct quehead *element = (struct quehead *) a;
42 register struct quehead *head = (struct quehead *) b;
43 element->qh_link = head->qh_link;
44 head->qh_link = (struct quehead *)element;
45 element->qh_rlink = (struct quehead *)head;
46 ((struct quehead *)(element->qh_link))->qh_rlink = (struct quehead *)element;
47}
48
49void
50remque(PNATState pData, void *a)
51{
52 register struct quehead *element = (struct quehead *) a;
53 ((struct quehead *)(element->qh_link))->qh_rlink = element->qh_rlink;
54 ((struct quehead *)(element->qh_rlink))->qh_link = element->qh_link;
55 element->qh_rlink = NULL;
56 /* element->qh_link = NULL; TCP FIN1 crashes if you do this. Why ? */
57}
58
59int
60add_exec(struct ex_list **ex_ptr, int do_pty, char *exec, int addr, int port)
61{
62 struct ex_list *tmp_ptr;
63
64 /* First, check if the port is "bound" */
65 for (tmp_ptr = *ex_ptr; tmp_ptr; tmp_ptr = tmp_ptr->ex_next)
66 {
67 if (port == tmp_ptr->ex_fport && addr == tmp_ptr->ex_addr)
68 return -1;
69 }
70
71 tmp_ptr = *ex_ptr;
72 *ex_ptr = (struct ex_list *)RTMemAlloc(sizeof(struct ex_list));
73 (*ex_ptr)->ex_fport = port;
74 (*ex_ptr)->ex_addr = addr;
75 (*ex_ptr)->ex_pty = do_pty;
76 (*ex_ptr)->ex_exec = RTStrDup(exec);
77 (*ex_ptr)->ex_next = tmp_ptr;
78 return 0;
79}
80
81
82/*
83 * Set fd blocking and non-blocking
84 */
85void
86fd_nonblock(int fd)
87{
88#ifdef FIONBIO
89 int opt = 1;
90
91 ioctlsocket(fd, FIONBIO, &opt);
92#else
93 int opt;
94
95 opt = fcntl(fd, F_GETFL, 0);
96 opt |= O_NONBLOCK;
97 fcntl(fd, F_SETFL, opt);
98#endif
99}
100
101void
102fd_block(int fd)
103{
104#ifdef FIONBIO
105 int opt = 0;
106
107 ioctlsocket(fd, FIONBIO, &opt);
108#else
109 int opt;
110
111 opt = fcntl(fd, F_GETFL, 0);
112 opt &= ~O_NONBLOCK;
113 fcntl(fd, F_SETFL, opt);
114#endif
115}
116
Note: See TracBrowser for help on using the repository browser.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette