Assorted whitespace cleanup and typo fixes.
[haiku.git] / src / kits / network / r5_compatibility.cpp
blobac9c80a4ae54c4e27659762d294b93afc6f8797f
1 /*
2 * Copyright 2002-2006, Haiku, Inc. All Rights Reserved.
3 * Distributed under the terms of the MIT License.
5 * Authors:
6 * Philippe Houdoin
7 * Jérôme Duval, korli@users.berlios.de
8 * Axel Dörfler, axeld@pinc-software.de
9 */
12 #include <SupportDefs.h>
13 #include <TLS.h>
15 #include <stdio.h>
16 #include <string.h>
17 #include <unistd.h>
20 struct net_settings;
22 extern "C" {
23 int *_h_errnop(void);
24 int _netstat(int fd, char **output, int verbose);
25 int _socket_interrupt(void);
26 int closesocket(int socket);
27 char *find_net_setting(net_settings* settings, const char* heading,
28 const char* name, char* value, unsigned numBytes);
29 status_t set_net_setting(net_settings* settings, const char* heading,
30 const char* name, const char* value);
31 int getusername(char *user, size_t bufferLength);
32 int getpassword(char *password, size_t bufferLength);
33 char *_netconfig_find(const char *heaading, const char *name, char *value, int nbytes);
37 int32 __gHErrnoTLS = tls_allocate();
40 int *
41 _h_errnop(void)
43 return (int *)tls_address(__gHErrnoTLS);
47 int
48 _netstat(int fd, char **output, int verbose)
50 return ENOSYS;
54 int
55 _socket_interrupt(void)
57 return -1;
61 int
62 closesocket(int socket)
64 return close(socket);
68 /* TODO: This is a terrible hack :(
69 * TODO: We should really get these settings values by parsing the real settings
72 char *
73 find_net_setting(net_settings* settings, const char* heading,
74 const char* name, char* value, unsigned numBytes)
76 if (strcmp(heading, "GLOBAL") != 0)
77 return NULL;
79 if (!strcmp(name, "HOSTNAME"))
80 strlcpy(value, "hostname", numBytes);
81 else if (!strcmp(name, "USERNAME"))
82 strlcpy(value, "baron", numBytes);
83 else if (!strcmp(name, "PASSWORD"))
84 strlcpy(value, "password", numBytes);
85 else if (!strcmp(name, "FTP_ENABLED"))
86 strlcpy(value, "1", numBytes);
87 else if (!strcmp(name, "TELNETD_ENABLED"))
88 strlcpy(value, "1", numBytes);
89 else
90 return NULL;
92 return value;
96 status_t
97 set_net_setting(net_settings* settings, const char* heading,
98 const char* name, const char* value)
100 return B_UNSUPPORTED;
105 getusername(char *user, size_t length)
107 if (find_net_setting(NULL, "GLOBAL", "USERNAME", user, length) == NULL)
108 return B_ERROR;
110 return strlen(user);
115 getpassword(char *password, size_t length)
117 if (find_net_setting(NULL, "GLOBAL", "PASSWORD", password, length) == NULL)
118 return B_ERROR;
120 return strlen(password);
123 char *
124 _netconfig_find(const char *heading, const char *name, char *value, int nbytes)
126 return find_net_setting(NULL, heading, name, value, nbytes);