VirtualBox

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

最後變更 在這個檔案從15035是 14964,由 vboxsync 提交於 16 年 前

slirp: code cosmetics for better readability (no semantics change)

  • 屬性 svn:eol-style 設為 native
檔案大小: 3.4 KB
 
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
32#if SIZEOF_CHAR_P == 8 && !defined(VBOX_WITH_BSD_REASS)
33
34struct quehead_32
35{
36 u_int32_t qh_link;
37 u_int32_t qh_rlink;
38};
39
40void
41insque_32(PNATState pData, void *a, void *b)
42{
43 register struct quehead_32 *element = (struct quehead_32 *) a;
44 register struct quehead_32 *head = (struct quehead_32 *) b;
45 struct quehead_32 *link = u32_to_ptr(pData, head->qh_link, struct quehead_32 *);
46
47 element->qh_link = head->qh_link;
48 element->qh_rlink = ptr_to_u32(pData, head);
49 Assert(link->qh_rlink == element->qh_rlink);
50 link->qh_rlink = head->qh_link = ptr_to_u32(pData, element);
51}
52
53void
54remque_32(PNATState pData, void *a)
55{
56 register struct quehead_32 *element = (struct quehead_32 *) a;
57 struct quehead_32 *link = u32_to_ptr(pData, element->qh_link, struct quehead_32 *);
58 struct quehead_32 *rlink = u32_to_ptr(pData, element->qh_rlink, struct quehead_32 *);
59
60 u32ptr_done(pData, link->qh_rlink, element);
61 link->qh_rlink = element->qh_rlink;
62 rlink->qh_link = element->qh_link;
63 element->qh_rlink = 0;
64}
65
66#endif /* SIZEOF_CHAR_P == 8 && !VBOX_WITH_BSD_REASS */
67
68struct quehead
69{
70 struct quehead *qh_link;
71 struct quehead *qh_rlink;
72};
73
74void
75insque(PNATState pData, void *a, void *b)
76{
77 register struct quehead *element = (struct quehead *) a;
78 register struct quehead *head = (struct quehead *) b;
79 element->qh_link = head->qh_link;
80 head->qh_link = (struct quehead *)element;
81 element->qh_rlink = (struct quehead *)head;
82 ((struct quehead *)(element->qh_link))->qh_rlink = (struct quehead *)element;
83}
84
85void
86remque(PNATState pData, void *a)
87{
88 register struct quehead *element = (struct quehead *) a;
89 ((struct quehead *)(element->qh_link))->qh_rlink = element->qh_rlink;
90 ((struct quehead *)(element->qh_rlink))->qh_link = element->qh_link;
91 element->qh_rlink = NULL;
92 /* element->qh_link = NULL; TCP FIN1 crashes if you do this. Why ? */
93}
94
95int
96add_exec(struct ex_list **ex_ptr, int do_pty, char *exec, int addr, int port)
97{
98 struct ex_list *tmp_ptr;
99
100 /* First, check if the port is "bound" */
101 for (tmp_ptr = *ex_ptr; tmp_ptr; tmp_ptr = tmp_ptr->ex_next)
102 {
103 if (port == tmp_ptr->ex_fport && addr == tmp_ptr->ex_addr)
104 return -1;
105 }
106
107 tmp_ptr = *ex_ptr;
108 *ex_ptr = (struct ex_list *)malloc(sizeof(struct ex_list));
109 (*ex_ptr)->ex_fport = port;
110 (*ex_ptr)->ex_addr = addr;
111 (*ex_ptr)->ex_pty = do_pty;
112 (*ex_ptr)->ex_exec = strdup(exec);
113 (*ex_ptr)->ex_next = tmp_ptr;
114 return 0;
115}
116
117
118/*
119 * Set fd blocking and non-blocking
120 */
121void
122fd_nonblock(int fd)
123{
124#ifdef FIONBIO
125 int opt = 1;
126
127 ioctlsocket(fd, FIONBIO, &opt);
128#else
129 int opt;
130
131 opt = fcntl(fd, F_GETFL, 0);
132 opt |= O_NONBLOCK;
133 fcntl(fd, F_SETFL, opt);
134#endif
135}
136
137void
138fd_block(int fd)
139{
140#ifdef FIONBIO
141 int opt = 0;
142
143 ioctlsocket(fd, FIONBIO, &opt);
144#else
145 int opt;
146
147 opt = fcntl(fd, F_GETFL, 0);
148 opt &= ~O_NONBLOCK;
149 fcntl(fd, F_SETFL, opt);
150#endif
151}
152
注意: 瀏覽 TracBrowser 來幫助您使用儲存庫瀏覽器

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