Skip to content

Commit a719f2c

Browse files
committed
[networking] Add standard network headers to libc, remove kernel headers from network apps
1 parent 5df989d commit a719f2c

File tree

35 files changed

+125
-310
lines changed

35 files changed

+125
-310
lines changed

elks/include/linuxmt/in.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@ struct sockaddr_in {
1111
struct in_addr sin_addr;
1212
};
1313

14-
#define INADDR_ANY ((unsigned long) 0x00000000)
15-
#define PORT_ANY ((unsigned short) 0x0000)
16-
#define INADDR_NODE 0xffffffff
17-
#define INADDR_LOOPBACK 0x7f000001
14+
#define INADDR_ANY ((unsigned long) 0x00000000)
15+
#define PORT_ANY ((unsigned short) 0x0000)
16+
#define INADDR_NONE ((unsigned long) 0xffffffff)
17+
#define INADDR_LOOPBACK ((unsigned long) 0x7f000001)
1818

1919
#endif

elkscmd/inet/httpd/httpd.c

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,14 +30,8 @@
3030
#include <stdlib.h>
3131
#include <stdio.h>
3232
#include <errno.h>
33-
#ifndef __linux__
34-
#include <linuxmt/in.h>
35-
#include <linuxmt/net.h>
36-
#include <linuxmt/arpa/inet.h>
37-
#else
3833
#include <netinet/in.h>
3934
#include <arpa/inet.h>
40-
#endif
4135
#include <sys/wait.h>
4236
extern pid_t waitpid(pid_t, int *, int);
4337

elkscmd/inet/nettools/arp.c

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -13,27 +13,15 @@
1313
#include <stdlib.h>
1414
#include <sys/types.h>
1515
#include <sys/socket.h>
16-
#include <linuxmt/net.h>
17-
#include <linuxmt/in.h>
1816
#include <ktcp/tcp.h>
1917
#include <ktcp/netconf.h>
2018
#include <ktcp/deveth.h>
2119
#include <ktcp/arp.h>
22-
#include <linuxmt/arpa/inet.h>
20+
#include <arpa/inet.h>
2321

2422
struct sockaddr_in localadr,remaddr;
2523
struct arp_cache arp_cache[ARP_CACHE_MAX];
2624

27-
char *in_ntoa(ipaddr_t in)
28-
{
29-
register unsigned char *p;
30-
static char b[18];
31-
32-
p = (unsigned char *)&in;
33-
sprintf(b, "%d.%d.%d.%d", p[0], p[1], p[2], p[3]);
34-
return b;
35-
}
36-
3725
char *mac_ntoa(eth_addr_t eth_addr)
3826
{
3927
unsigned char *p = (unsigned char *)eth_addr;

elkscmd/inet/nettools/netstat.c

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,9 @@
2323
#include <stdlib.h>
2424
#include <sys/types.h>
2525
#include <sys/socket.h>
26-
#include <linuxmt/net.h>
27-
#include <linuxmt/in.h>
26+
#include <arpa/inet.h>
2827
#include <ktcp/tcp.h>
2928
#include <ktcp/netconf.h>
30-
#include <linuxmt/arpa/inet.h>
3129

3230
char tcp_states[11][13] = {
3331
"CLOSED",

elkscmd/inet/nettools/nslookup.c

Lines changed: 2 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,10 @@
1-
21
#include <stdio.h>
32
#include <unistd.h>
43
#include <stdlib.h>
54
#include <string.h>
6-
75
#include <sys/socket.h>
8-
9-
#ifndef __linux__
10-
#include <linuxmt/un.h>
11-
#include <linuxmt/in.h>
12-
#include "linuxmt/arpa/inet.h"
13-
#else
14-
#include <sys/types.h>
6+
#include <arpa/inet.h>
157
#include <netdb.h>
16-
#endif
178

189
struct DNS_HEADER
1910
{
@@ -32,28 +23,6 @@ struct QUESTION
3223
__u16 qclass;
3324
};
3425

35-
unsigned long int in_aton(const char *str)
36-
{
37-
unsigned long l = 0;
38-
unsigned int val;
39-
int i;
40-
41-
for (i = 0; i < 4; i++) {
42-
l <<= 8;
43-
if (*str != '\0') {
44-
val = 0;
45-
while (*str != '\0' && *str != '.') {
46-
val *= 10;
47-
val += *str++ - '0';
48-
}
49-
l |= val;
50-
if (*str != '\0')
51-
str++;
52-
}
53-
}
54-
return htonl(l);
55-
}
56-
5726
/* convert e.g. www.google.com (host) to 3www6google3com (dns) */
5827
void ChangetoDnsNameFormat(unsigned char* dns,unsigned char* host)
5928
{
@@ -147,7 +116,7 @@ int main(int argc, char *argv[]) {
147116
addr.sin_family = AF_INET;
148117
nameserver=get_dns_server();
149118
printf("Nameserver queried:%s\n",nameserver);
150-
addr.sin_addr.s_addr = in_aton(nameserver);
119+
addr.sin_addr.s_addr = in_gethostbyname(nameserver);
151120
addr.sin_port = htons(53);
152121

153122
if (connect(fd, (struct sockaddr*)&addr, sizeof(addr)) == -1) {

elkscmd/inet/telnet/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ include $(BASEDIR)/Make.rules
1212

1313
###############################################################################
1414

15-
SRCS = ttn.c ttn_conf.c netlib.c
15+
SRCS = ttn.c ttn_conf.c
1616
OBJS = $(SRCS:.c=.o)
1717

1818
all: telnet

elkscmd/inet/telnet/netlib.h

Lines changed: 0 additions & 7 deletions
This file was deleted.

elkscmd/inet/telnet/ttn.c

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -18,19 +18,9 @@
1818
#include <string.h>
1919
#include <unistd.h>
2020
#include <sys/socket.h>
21-
22-
#ifndef __linux__
23-
#include <linuxmt/in.h>
24-
#include <linuxmt/net.h>
25-
#include <linuxmt/time.h>
26-
#include <linuxmt/arpa/inet.h>
27-
#include "netlib.h"
28-
#else
2921
#include <sys/time.h>
3022
#include <netinet/in.h>
3123
#include <arpa/inet.h>
32-
#endif
33-
3424
#include "ttn.h"
3525

3626
//#define DEBUG 1

elkscmd/inet/telnetd/telnetd.c

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,9 @@
1313
#include <termios.h>
1414
#include <signal.h>
1515
#include <string.h>
16-
#include <sys/socket.h>
17-
#include <linuxmt/socket.h>
18-
#include <linuxmt/in.h>
19-
#include <linuxmt/arpa/inet.h>
2016
#include <sys/wait.h>
17+
#include <sys/socket.h>
18+
#include <arpa/inet.h>
2119
#include "telnet.h"
2220

2321
//#define RAWTELNET /* set in telnet and telnetd for raw telnet without IAC*/

elkscmd/inet/tinyirc/tinyirc.c

Lines changed: 1 addition & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -56,15 +56,8 @@
5656
#include <sys/time.h>
5757
#include <fcntl.h>
5858
#include <sys/socket.h>
59-
#ifdef ELKS
60-
#include <linuxmt/in.h>
61-
#include <linuxmt/net.h>
62-
#include <linuxmt/time.h>
63-
#include <linuxmt/arpa/inet.h>
64-
#else
6559
#include <netinet/in.h>
6660
#include <netdb.h>
67-
#endif
6861
#include <signal.h>
6962
#include <utmp.h>
7063
struct dlist {
@@ -111,31 +104,6 @@ int _res_flg;
111104
(void) ioctl(my_tty, TIOCSETP, &_tty))
112105
#endif
113106
#endif
114-
#ifdef ELKS
115-
unsigned long int in_aton(str)
116-
const char *str;
117-
{
118-
unsigned long l = 0;
119-
unsigned int val;
120-
int i;
121-
122-
for (i = 0; i < 4; i++) {
123-
l <<= 8;
124-
if (*str != '\0') {
125-
val = 0;
126-
while (*str != '\0' && *str != '.') {
127-
val *= 10;
128-
val += *str - '0';
129-
str++;
130-
}
131-
l |= val;
132-
if (*str != '\0')
133-
str++;
134-
}
135-
}
136-
return(htonl(l));
137-
}
138-
#endif
139107
int putchar_x(c)
140108
int c;
141109
{
@@ -933,7 +901,7 @@ char *hostname;
933901
sa.sin_port = htons((unsigned short) IRCPORT);
934902
s = socket(hp->h_addrtype, SOCK_STREAM, 0);
935903
#else
936-
sa.sin_addr.s_addr = in_aton(hostname);
904+
sa.sin_addr.s_addr = in_gethostbyname(hostname);
937905
sa.sin_family = AF_INET;
938906
sa.sin_port = htons((unsigned short) IRCPORT);
939907
s = socket(AF_INET, SOCK_STREAM, 0);

0 commit comments

Comments
 (0)