Skip to content

Commit cf9dcb8

Browse files
committed
Drop dependency on winsock2.h
1 parent d1db18b commit cf9dcb8

File tree

16 files changed

+35
-41
lines changed

16 files changed

+35
-41
lines changed

CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,7 @@ foreach(match ${matches})
227227
endforeach()
228228

229229
file(GENERATE OUTPUT config.h CONTENT "${template}")
230-
configure_file(src/fallback/endian.h.in src/fallback/endian.h @ONLY)
230+
configure_file(src/fallback/endian.h.in fallback/endian.h @ONLY)
231231

232232

233233
if(BUILD_TESTING)

src/fallback/endian.h.in

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,15 @@
4949
#elif __APPLE__
5050
#include <libkern/OSByteOrder.h>
5151

52-
#define BYTE_ORDER __BYTE_ORDER__
53-
#define LITTLE_ENDIAN __ORDER_LITTLE_ENDIAN__
54-
#define BIG_ENDIAN __ORDER_BIG_ENDIAN__
52+
#ifndef BYTE_ORDER
53+
# define BYTE_ORDER __BYTE_ORDER__
54+
#endif
55+
#ifndef LITTLE_ENDIAN
56+
# define LITTLE_ENDIAN __ORDER_LITTLE_ENDIAN__
57+
#endif
58+
#ifndef BIG_ENDIAN
59+
# define BIG_ENDIAN __ORDER_BIG_ENDIAN__
60+
#endif
5561

5662
#define htobe16(x) OSSwapHostToBigInt16(x)
5763
#define htobe32(x) OSSwapHostToBigInt32(x)

src/fallback/parser.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
#include "zone.h"
1010
#include "diagnostic.h"
1111
#include "log.h"
12+
#include "fallback/endian.h"
1213
#include "fallback/bits.h"
1314
#include "lexer.h"
1415
#include "table.h"

src/fallback/time.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ static zone_really_inline int32_t parse_time(
8080
const uint64_t minutes = hours * 60 + min;
8181
const uint64_t seconds = minutes * 60 + sec;
8282

83-
uint32_t time = htonl((uint32_t)seconds);
83+
uint32_t time = htobe32((uint32_t)seconds);
8484
memcpy(&parser->rdata->octets[parser->rdata->length], &time, sizeof(time));
8585
parser->rdata->length += sizeof(time);
8686
return ZONE_INT32;

src/fallback/type.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -400,7 +400,7 @@ static zone_really_inline int32_t parse_type(
400400
return r;
401401

402402
scan_type(parser, type, field, token, &c, &s);
403-
c = htons(c);
403+
c = htobe16(c);
404404
memcpy(&parser->rdata->octets[parser->rdata->length], &c, sizeof(c));
405405
parser->rdata->length += sizeof(c);
406406
return ZONE_TYPE;

src/generic/ilnp64.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,10 +50,10 @@ static zone_really_inline int32_t parse_ilnp64(
5050

5151
if (n != 3 || p == g || p - g > 4 || contiguous[(uint8_t)*p] == CONTIGUOUS)
5252
SYNTAX_ERROR(parser, "Invalid %s in %s", NAME(field), TNAME(type));
53-
a[0] = htons(a[0]);
54-
a[1] = htons(a[1]);
55-
a[2] = htons(a[2]);
56-
a[3] = htons(a[3]);
53+
a[0] = htobe16(a[0]);
54+
a[1] = htobe16(a[1]);
55+
a[2] = htobe16(a[2]);
56+
a[3] = htobe16(a[3]);
5757
memcpy(parser->rdata->octets+parser->rdata->length, a, 8);
5858
parser->rdata->length += 8;
5959
return ZONE_ILNP64;

src/generic/number.h

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,6 @@
99
#ifndef NUMBER_H
1010
#define NUMBER_H
1111

12-
#if _WIN32
13-
#include <winsock2.h>
14-
#else
15-
#include <netinet/in.h>
16-
#endif
17-
1812
zone_nonnull_all
1913
static zone_really_inline int32_t parse_symbol8(
2014
zone_parser_t *parser,
@@ -82,7 +76,7 @@ static zone_really_inline int32_t parse_symbol16(
8276
SYNTAX_ERROR(parser, "Invalid %s in %s", NAME(field), TNAME(type));
8377
}
8478

85-
uint16_t n16 = htons((uint16_t)n);
79+
uint16_t n16 = htobe16((uint16_t)n);
8680
memcpy(&parser->rdata->octets[parser->rdata->length], &n16, sizeof(n16));
8781
parser->rdata->length += sizeof(n16);
8882
return ZONE_INT16;
@@ -141,7 +135,7 @@ static zone_really_inline int32_t parse_int16(
141135
if (n > UINT16_MAX || p - token->data > 5 || is_contiguous((uint8_t)*p))
142136
SYNTAX_ERROR(parser, "Invalid %s in %s", NAME(field), TNAME(type));
143137

144-
uint16_t n16 = htons((uint16_t)n);
138+
uint16_t n16 = htobe16((uint16_t)n);
145139
memcpy(&parser->rdata->octets[parser->rdata->length], &n16, sizeof(n16));
146140
parser->rdata->length += sizeof(n16);
147141
return ZONE_INT16;
@@ -171,7 +165,7 @@ static zone_really_inline int32_t parse_int32(
171165
if (n > UINT32_MAX || p - token->data > 10 || is_contiguous((uint8_t)*p))
172166
SYNTAX_ERROR(parser, "Invalid %s in %s", NAME(field), TNAME(type));
173167

174-
const uint32_t n32 = htonl((uint32_t)n);
168+
const uint32_t n32 = htobe32((uint32_t)n);
175169
memcpy(&parser->rdata->octets[parser->rdata->length], &n32, sizeof(n32));
176170
parser->rdata->length += sizeof(n32);
177171
return ZONE_INT32;

src/generic/ttl.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ static zone_really_inline int32_t parse_ttl(
136136

137137
if ((r = scan_ttl(parser, type, field, token, &t)) < 0)
138138
return r;
139-
t = htonl(t);
139+
t = htobe32(t);
140140
memcpy(&parser->rdata->octets[parser->rdata->length], &t, sizeof(t));
141141
parser->rdata->length += sizeof(t);
142142
return ZONE_TTL;

src/haswell/parser.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
#include "diagnostic.h"
1111
#include "log.h"
1212
#include "haswell/simd.h"
13+
#include "fallback/endian.h"
1314
#include "haswell/bits.h"
1415
#include "lexer.h"
1516
#include "table.h"

src/types.h

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ static zone_really_inline ssize_t check_ttl(
121121
SYNTAX_ERROR(parser, "Missing %s in %s", NAME(field), TNAME(type));
122122

123123
memcpy(&number, data, sizeof(number));
124-
number = ntohl(number);
124+
number = be32toh(number);
125125

126126
if (number > INT32_MAX)
127127
SEMANTIC_ERROR(parser, "Invalid %s in %s", NAME(field), TNAME(type));
@@ -996,9 +996,9 @@ static int32_t parse_loc_rdata(
996996
return result;
997997
north_south:
998998
if (token->data[0] == 'N')
999-
latitude = htonl((1u<<31) + degrees);
999+
latitude = htobe32((1u<<31) + degrees);
10001000
else if (token->data[1] == 'S')
1001-
latitude = htonl((1u<<31) - degrees);
1001+
latitude = htobe32((1u<<31) - degrees);
10021002
else
10031003
SYNTAX_ERROR(parser, "Invalid %s in %s", NAME(&fields[4]), TNAME(type));
10041004

@@ -1024,9 +1024,9 @@ static int32_t parse_loc_rdata(
10241024
return result;
10251025
east_west:
10261026
if (token->data[0] == 'E')
1027-
longitude = htonl((1u<<31) + degrees);
1027+
longitude = htobe32((1u<<31) + degrees);
10281028
else if (token->data[0] == 'W')
1029-
longitude = htonl((1u<<31) - degrees);
1029+
longitude = htobe32((1u<<31) - degrees);
10301030
else
10311031
SYNTAX_ERROR(parser, "Invalid %s in %s", NAME(&fields[5]), TNAME(type));
10321032

@@ -1039,7 +1039,7 @@ static int32_t parse_loc_rdata(
10391039
if (scan_altitude(token->data, token->length, &altitude) == -1)
10401040
SYNTAX_ERROR(parser, "Invalid %s in %s", NAME(&fields[6]), TNAME(type));
10411041

1042-
altitude = htonl(altitude);
1042+
altitude = htobe32(altitude);
10431043
memcpy(&parser->rdata->octets[12], &altitude, sizeof(altitude));
10441044

10451045
// size
@@ -1827,7 +1827,7 @@ static int32_t parse_hip_rdata(
18271827

18281828
if (parser->rdata->length > 65535u + 4u + hit_length)
18291829
SYNTAX_ERROR(parser, "Invalid %s in %s", NAME(&type->rdata.fields[4]), TNAME(type));
1830-
uint16_t pk_length = htons((uint16_t)((parser->rdata->length - hit_length) - 4));
1830+
uint16_t pk_length = htobe16((uint16_t)((parser->rdata->length - hit_length) - 4));
18311831
memcpy(&parser->rdata->octets[2], &pk_length, sizeof(pk_length));
18321832

18331833
lex(parser, token);

0 commit comments

Comments
 (0)