Skip to content

Commit a4858df

Browse files
committed
[net] Remove stdint.h from ktcp source
1 parent ad38747 commit a4858df

3 files changed

Lines changed: 38 additions & 39 deletions

File tree

elkscmd/ktcp/dhcp.c

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
/*
22
* DHCP client, internal to ktcp.
33
*/
4-
#include <sys/types.h>
54
#include <stdio.h>
65
#include <string.h>
76
#include <arpa/inet.h>
@@ -25,11 +24,11 @@ static timeq_t dhcp_retry_time;
2524
static int dhcp_retry_count;
2625
static timeq_t dhcp_start_time;
2726

28-
static uint32_t dhcp_xid;
29-
static uint32_t dhcp_yiaddr;
30-
static uint32_t dhcp_server_ip;
31-
static uint32_t dhcp_netmask_val;
32-
static uint32_t dhcp_gateway_val;
27+
static __u32 dhcp_xid;
28+
static __u32 dhcp_yiaddr;
29+
static __u32 dhcp_server_ip;
30+
static __u32 dhcp_netmask_val;
31+
static __u32 dhcp_gateway_val;
3332

3433
static unsigned char dhcp_buf[DHCP_MSG_LEN];
3534

@@ -44,12 +43,12 @@ static void dhcp_send_discover(void)
4443
msg->htype = 1;
4544
msg->hlen = 6;
4645
msg->xid = htonl(dhcp_xid);
47-
msg->secs = htons((uint16_t)(((Now - dhcp_start_time) * 60) / 1000));
46+
msg->secs = htons((__u16)(((Now - dhcp_start_time) * 60) / 1000));
4847
msg->flags = htons(0x8000);
4948
memcpy(msg->chaddr, eth_local_addr, 6);
5049

5150
opts = (unsigned char *)(msg + 1);
52-
*(uint32_t *)opts = htonl(DHCP_MAGIC_COOKIE);
51+
*(__u32 *)opts = htonl(DHCP_MAGIC_COOKIE);
5352
opts += 4;
5453

5554
*opts++ = DHCP_OPT_MSG_TYPE;
@@ -80,12 +79,12 @@ static void dhcp_send_request(void)
8079
msg->htype = 1;
8180
msg->hlen = 6;
8281
msg->xid = htonl(dhcp_xid);
83-
msg->secs = htons((uint16_t)(((Now - dhcp_start_time) * 60) / 1000));
82+
msg->secs = htons((__u16)(((Now - dhcp_start_time) * 60) / 1000));
8483
msg->flags = htons(0x8000);
8584
memcpy(msg->chaddr, eth_local_addr, 6);
8685

8786
opts = (unsigned char *)(msg + 1);
88-
*(uint32_t *)opts = htonl(DHCP_MAGIC_COOKIE);
87+
*(__u32 *)opts = htonl(DHCP_MAGIC_COOKIE);
8988
opts += 4;
9089

9190
*opts++ = DHCP_OPT_MSG_TYPE;
@@ -94,12 +93,12 @@ static void dhcp_send_request(void)
9493

9594
*opts++ = DHCP_OPT_REQ_IP;
9695
*opts++ = 4;
97-
*(uint32_t *)opts = dhcp_yiaddr;
96+
*(__u32 *)opts = dhcp_yiaddr;
9897
opts += 4;
9998

10099
*opts++ = DHCP_OPT_SERVER_ID;
101100
*opts++ = 4;
102-
*(uint32_t *)opts = dhcp_server_ip;
101+
*(__u32 *)opts = dhcp_server_ip;
103102
opts += 4;
104103

105104
*opts++ = DHCP_OPT_END;
@@ -203,8 +202,10 @@ void dhcp_init(void)
203202
dhcp_retry_count = 0;
204203
dhcp_start_time = Now;
205204

206-
dhcp_xid = ((uint32_t)eth_local_addr[0] << 24) | ((uint32_t)eth_local_addr[1] << 16) |
207-
(eth_local_addr[2] << 8) | eth_local_addr[3];
205+
dhcp_xid = ((unsigned long)eth_local_addr[0] << 24) |
206+
((unsigned long)eth_local_addr[1] << 16) |
207+
(eth_local_addr[2] << 8) |
208+
eth_local_addr[3];
208209
dhcp_xid ^= (Now & 0xFF) << 8;
209210

210211
udp_register(DHCP_CLIENT_PORT, dhcp_input);
@@ -254,7 +255,7 @@ void dhcp_timer(void)
254255
* Handles OFFER, ACK, and NAK replies from the DHCP server.
255256
* Registered in dhcp_init() via udp_register().
256257
*/
257-
void dhcp_input(struct iphdr_s *iph, uint16_t src_port, unsigned char *data, int len)
258+
void dhcp_input(struct iphdr_s *iph, __u16 src_port, unsigned char *data, int len)
258259
{
259260
struct dhcp_message_s *msg = (struct dhcp_message_s *)data;
260261
unsigned char *opts;
@@ -275,7 +276,7 @@ void dhcp_input(struct iphdr_s *iph, uint16_t src_port, unsigned char *data, int
275276

276277
if (optlen < 4)
277278
return;
278-
if (*(uint32_t *)opts != htonl(DHCP_MAGIC_COOKIE)) /* DHCP option marker */
279+
if (*(__u32 *)opts != htonl(DHCP_MAGIC_COOKIE)) /* DHCP option marker */
279280
return;
280281
opts += 4;
281282
optlen -= 4;

elkscmd/ktcp/dhcp.h

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#ifndef DHCP_H
22
#define DHCP_H
33

4-
#include <stdint.h>
4+
#include <sys/types.h>
55

66
#define DHCP_CLIENT_PORT 68
77
#define DHCP_SERVER_PORT 67
@@ -39,27 +39,27 @@
3939
#define DHCP_MAX_TIMEOUT (16 << 4)
4040

4141
struct dhcp_message_s {
42-
uint8_t op;
43-
uint8_t htype;
44-
uint8_t hlen;
45-
uint8_t hops;
46-
uint32_t xid;
47-
uint16_t secs;
48-
uint16_t flags;
49-
uint32_t ciaddr;
50-
uint32_t yiaddr;
51-
uint32_t siaddr;
52-
uint32_t giaddr;
53-
uint8_t chaddr[16];
54-
uint8_t sname[64];
55-
uint8_t file[128];
42+
__u8 op;
43+
__u8 htype;
44+
__u8 hlen;
45+
__u8 hops;
46+
__u32 xid;
47+
__u16 secs;
48+
__u16 flags;
49+
__u32 ciaddr;
50+
__u32 yiaddr;
51+
__u32 siaddr;
52+
__u32 giaddr;
53+
unsigned char chaddr[16];
54+
unsigned char sname[64];
55+
unsigned char file[128];
5656
};
5757

5858
extern char dhcp_enabled;
5959
extern char dhcp_timer_active;
6060

6161
void dhcp_init(void);
6262
void dhcp_timer(void);
63-
void dhcp_input(struct iphdr_s *iph, uint16_t src_port, unsigned char *data, int len);
63+
void dhcp_input(struct iphdr_s *iph, __u16 src_port, unsigned char *data, int len);
6464

6565
#endif

elkscmd/ktcp/udp.c

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
/*
22
* Internal UDP implementation for DHCP. Not accessible through sockets.
33
*/
4-
#include <sys/types.h>
5-
#include <stdint.h>
64
#include <stdio.h>
75
#include <string.h>
86
#include <arpa/inet.h>
@@ -14,7 +12,7 @@
1412

1513
struct udp_sock udp_socks[MAX_UDP_SOCKS];
1614

17-
int udp_register(uint16_t local_port, udp_callback_t cb)
15+
int udp_register(__u16 local_port, udp_callback_t cb)
1816
{
1917
int i;
2018

@@ -31,7 +29,7 @@ int udp_register(uint16_t local_port, udp_callback_t cb)
3129
return 0;
3230
}
3331

34-
void udp_unregister(uint16_t local_port)
32+
void udp_unregister(__u16 local_port)
3533
{
3634
int i;
3735

@@ -43,7 +41,7 @@ void udp_unregister(uint16_t local_port)
4341
}
4442
}
4543

46-
void udp_send(ipaddr_t dst, uint16_t dstport, uint16_t srcport,
44+
void udp_send(ipaddr_t dst, __u16 dstport, __u16 srcport,
4745
unsigned char *data, int datalen, ipaddr_t src)
4846
{
4947
unsigned char buf[sizeof(struct udphdr_s) + 576];
@@ -69,8 +67,8 @@ void udp_process(struct iphdr_s *iph, unsigned char *packet)
6967
{
7068
struct udphdr_s *udp = (struct udphdr_s *)packet;
7169
int udplen = ntohs(udp->len);
72-
uint16_t dest = ntohs(udp->dest);
73-
uint16_t src = ntohs(udp->src);
70+
__u16 dest = ntohs(udp->dest);
71+
__u16 src = ntohs(udp->src);
7472
unsigned char *data = packet + sizeof(struct udphdr_s);
7573
int datalen = udplen - sizeof(struct udphdr_s);
7674
int i;

0 commit comments

Comments
 (0)