Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
L
libloc
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
nexedi
libloc
Commits
7a8ded5a
Commit
7a8ded5a
authored
Oct 18, 2019
by
Michael Tremer
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'apple'
parents
191830da
1d9cd868
Changes
13
Show whitespace changes
Inline
Side-by-side
Showing
13 changed files
with
146 additions
and
25 deletions
+146
-25
Makefile.am
Makefile.am
+20
-5
configure.ac
configure.ac
+1
-0
m4/ld-version-script.m4
m4/ld-version-script.m4
+48
-0
src/as.c
src/as.c
+5
-1
src/country.c
src/country.c
+1
-0
src/database.c
src/database.c
+12
-8
src/libloc.c
src/libloc.c
+1
-0
src/loc/compat.h
src/loc/compat.h
+40
-0
src/loc/private.h
src/loc/private.h
+1
-1
src/network.c
src/network.c
+5
-1
src/perl/Makefile.PL
src/perl/Makefile.PL
+0
-1
src/stringpool.c
src/stringpool.c
+3
-3
src/writer.c
src/writer.c
+9
-5
No files found.
Makefile.am
View file @
7a8ded5a
...
...
@@ -6,6 +6,8 @@ AM_MAKEFLAGS = --no-print-directory
SUBDIRS
=
.
po
BINDINGS
=
OS
=
$(
shell
uname
-s
)
if
ENABLE_PERL
BINDINGS
+=
perl
endif
...
...
@@ -19,9 +21,16 @@ AM_CFLAGS = ${my_CFLAGS} \
-ffunction-sections
\
-fdata-sections
AM_LDFLAGS
=
\
-Wl
,--gc-sections
\
-Wl
,--as-needed
AM_LDFLAGS
=
# leaving a space here to work around automake's conditionals
ifeq
($(OS),Darwin)
AM_LDFLAGS
+=
-Wl
,-dead_strip
else
AM_LDFLAGS
+=
\
-Wl
,--as-needed
\
-Wl
,--gc-sections
endif
LIBLOC_CURRENT
=
0
LIBLOC_REVISION
=
0
...
...
@@ -68,6 +77,7 @@ EXTRA_DIST += \
pkginclude_HEADERS
=
\
src/loc/libloc.h
\
src/loc/as.h
\
src/loc/compat.h
\
src/loc/country.h
\
src/loc/database.h
\
src/loc/format.h
\
...
...
@@ -97,8 +107,13 @@ src_libloc_la_CFLAGS = \
src_libloc_la_LDFLAGS
=
\
$(AM_LDFLAGS)
\
-version-info
$(LIBLOC_CURRENT)
:
$(LIBLOC_REVISION)
:
$(LIBLOC_AGE)
\
-Wl
,--version-script
=
$(top_srcdir)
/src/libloc.sym
-version-info
$(LIBLOC_CURRENT)
:
$(LIBLOC_REVISION)
:
$(LIBLOC_AGE)
if
HAVE_LD_VERSION_SCRIPT
src_libloc_la_LDFLAGS
+=
-Wl
,--version-script
=
$(top_srcdir)
/src/libloc.sym
else
src_libloc_la_LDFLAGS
+=
-export-symbols
$(top_srcdir)
/src/libloc.sym
endif
src_libloc_la_DEPENDENCIES
=
\
${top_srcdir}
/src/libloc.sym
...
...
configure.ac
View file @
7a8ded5a
...
...
@@ -28,6 +28,7 @@ LT_INIT([
pic-only
])
AC_PREFIX_DEFAULT([/usr])
gl_LD_VERSION_SCRIPT
IT_PROG_INTLTOOL([0.40.0])
GETTEXT_PACKAGE=${PACKAGE_TARNAME}
...
...
m4/ld-version-script.m4
0 → 100644
View file @
7a8ded5a
# ld-version-script.m4 serial 4
dnl Copyright (C) 2008-2015 Free Software Foundation, Inc.
dnl This file is free software; the Free Software Foundation
dnl gives unlimited permission to copy and/or distribute it,
dnl with or without modifications, as long as this notice is preserved.
dnl From Simon Josefsson
# FIXME: The test below returns a false positive for mingw
# cross-compiles, 'local:' statements does not reduce number of
# exported symbols in a DLL. Use --disable-ld-version-script to work
# around the problem.
# gl_LD_VERSION_SCRIPT
# --------------------
# Check if LD supports linker scripts, and define automake conditional
# HAVE_LD_VERSION_SCRIPT if so.
AC_DEFUN([gl_LD_VERSION_SCRIPT],
[
AC_ARG_ENABLE([ld-version-script],
[AS_HELP_STRING([--enable-ld-version-script],
[enable linker version script (default is enabled when possible)])],
[have_ld_version_script=$enableval],
[AC_CACHE_CHECK([if LD -Wl,--version-script works],
[gl_cv_sys_ld_version_script],
[gl_cv_sys_ld_version_script=no
save_LDFLAGS=$LDFLAGS
LDFLAGS="$LDFLAGS -Wl,--version-script=conftest.map"
echo foo >conftest.map
AC_LINK_IFELSE([AC_LANG_PROGRAM([], [])],
[],
[cat > conftest.map <<EOF
VERS_1 {
global: sym;
};
VERS_2 {
global: sym;
} VERS_1;
EOF
AC_LINK_IFELSE([AC_LANG_PROGRAM([], [])],
[gl_cv_sys_ld_version_script=yes])])
rm -f conftest.map
LDFLAGS=$save_LDFLAGS])
have_ld_version_script=$gl_cv_sys_ld_version_script])
AM_CONDITIONAL([HAVE_LD_VERSION_SCRIPT],
[test "$have_ld_version_script" = yes])
])
src/as.c
View file @
7a8ded5a
...
...
@@ -15,14 +15,18 @@
*/
#include <ctype.h>
#include <endian.h>
#include <errno.h>
#include <stdint.h>
#include <stdlib.h>
#include <string.h>
#ifdef HAVE_ENDIAN_H
# include <endian.h>
#endif
#include <loc/libloc.h>
#include <loc/as.h>
#include <loc/compat.h>
#include <loc/format.h>
#include <loc/private.h>
#include <loc/stringpool.h>
...
...
src/country.c
View file @
7a8ded5a
...
...
@@ -19,6 +19,7 @@
#include <string.h>
#include <loc/libloc.h>
#include <loc/compat.h>
#include <loc/country.h>
#include <loc/private.h>
...
...
src/database.c
View file @
7a8ded5a
...
...
@@ -16,7 +16,6 @@
#include <arpa/inet.h>
#include <ctype.h>
#include <endian.h>
#include <errno.h>
#include <netinet/in.h>
#include <stddef.h>
...
...
@@ -29,8 +28,13 @@
#include <time.h>
#include <unistd.h>
#ifdef HAVE_ENDIAN_H
# include <endian.h>
#endif
#include <loc/libloc.h>
#include <loc/as.h>
#include <loc/compat.h>
#include <loc/country.h>
#include <loc/database.h>
#include <loc/format.h>
...
...
@@ -132,7 +136,7 @@ static int loc_database_read_as_section_v0(struct loc_database* db,
off_t
as_offset
=
be32toh
(
header
->
as_offset
);
size_t
as_length
=
be32toh
(
header
->
as_length
);
DEBUG
(
db
->
ctx
,
"Reading AS section from %jd (%zu bytes)
\n
"
,
as_offset
,
as_length
);
DEBUG
(
db
->
ctx
,
"Reading AS section from %jd (%zu bytes)
\n
"
,
(
intmax_t
)
as_offset
,
as_length
);
if
(
as_length
>
0
)
{
db
->
as_v0
=
mmap
(
NULL
,
as_length
,
PROT_READ
,
...
...
@@ -155,7 +159,7 @@ static int loc_database_read_network_nodes_section_v0(struct loc_database* db,
size_t
network_nodes_length
=
be32toh
(
header
->
network_tree_length
);
DEBUG
(
db
->
ctx
,
"Reading network nodes section from %jd (%zu bytes)
\n
"
,
network_nodes_offset
,
network_nodes_length
);
(
intmax_t
)
network_nodes_offset
,
network_nodes_length
);
if
(
network_nodes_length
>
0
)
{
db
->
network_nodes_v0
=
mmap
(
NULL
,
network_nodes_length
,
PROT_READ
,
...
...
@@ -178,7 +182,7 @@ static int loc_database_read_networks_section_v0(struct loc_database* db,
size_t
networks_length
=
be32toh
(
header
->
network_data_length
);
DEBUG
(
db
->
ctx
,
"Reading networks section from %jd (%zu bytes)
\n
"
,
networks_offset
,
networks_length
);
(
intmax_t
)
networks_offset
,
networks_length
);
if
(
networks_length
>
0
)
{
db
->
networks_v0
=
mmap
(
NULL
,
networks_length
,
PROT_READ
,
...
...
@@ -397,7 +401,7 @@ static int loc_database_fetch_as(struct loc_database* db, struct loc_as** as, of
if
((
size_t
)
pos
>=
db
->
as_count
)
return
-
EINVAL
;
DEBUG
(
db
->
ctx
,
"Fetching AS at position %jd
\n
"
,
pos
);
DEBUG
(
db
->
ctx
,
"Fetching AS at position %jd
\n
"
,
(
intmax_t
)
pos
);
int
r
;
switch
(
db
->
version
)
{
...
...
@@ -466,7 +470,7 @@ static int loc_database_fetch_network(struct loc_database* db, struct loc_networ
if
((
size_t
)
pos
>=
db
->
networks_count
)
return
-
EINVAL
;
DEBUG
(
db
->
ctx
,
"Fetching network at position %jd
\n
"
,
pos
);
DEBUG
(
db
->
ctx
,
"Fetching network at position %jd
\n
"
,
(
intmax_t
)
pos
);
int
r
;
switch
(
db
->
version
)
{
...
...
@@ -497,13 +501,13 @@ static int __loc_database_lookup_handle_leaf(struct loc_database* db, const stru
const
struct
loc_database_network_node_v0
*
node
)
{
off_t
network_index
=
be32toh
(
node
->
network
);
DEBUG
(
db
->
ctx
,
"Handling leaf node at %jd (%jd)
\n
"
,
node
-
db
->
network_nodes_v0
,
network_index
);
DEBUG
(
db
->
ctx
,
"Handling leaf node at %jd (%jd)
\n
"
,
(
intmax_t
)(
node
-
db
->
network_nodes_v0
),
(
intmax_t
)
network_index
);
// Fetch the network
int
r
=
loc_database_fetch_network
(
db
,
network
,
network_address
,
prefix
,
network_index
);
if
(
r
)
{
ERROR
(
db
->
ctx
,
"Could not fetch network %jd from database
\n
"
,
network_index
);
ERROR
(
db
->
ctx
,
"Could not fetch network %jd from database
\n
"
,
(
intmax_t
)
network_index
);
return
r
;
}
...
...
src/libloc.c
View file @
7a8ded5a
...
...
@@ -26,6 +26,7 @@
#include <ctype.h>
#include <loc/libloc.h>
#include <loc/compat.h>
#include <loc/private.h>
struct
loc_ctx
{
...
...
src/loc/compat.h
0 → 100644
View file @
7a8ded5a
/*
libloc - A library to determine the location of someone on the Internet
Copyright (C) 2019 IPFire Development Team <info@ipfire.org>
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
*/
#ifndef LIBLOC_COMPAT_H
#define LIBLOC_COMPAT_H
#ifdef __APPLE__
/* Hacks to make this library compile on Mac OS X */
#include <libkern/OSByteOrder.h>
#define be16toh(x) OSSwapBigToHostInt16(x)
#define htobe16(x) OSSwapHostToBigInt16(x)
#define be32toh(x) OSSwapBigToHostInt32(x)
#define htobe32(x) OSSwapHostToBigInt32(x)
#define be64toh(x) OSSwapBigToHostInt64(x)
#define htobe64(x) OSSwapHostToBigInt64(x)
#ifndef s6_addr16
# define s6_addr16 __u6_addr.__u6_addr16
#endif
#ifndef s6_addr32
# define s6_addr32 __u6_addr.__u6_addr32
#endif
#endif
#endif
src/loc/private.h
View file @
7a8ded5a
...
...
@@ -47,7 +47,7 @@ loc_log_null(struct loc_ctx *ctx, const char *format, ...) {}
# ifdef HAVE___SECURE_GETENV
# define secure_getenv __secure_getenv
# else
#
error neither secure_getenv nor __secure_getenv is available
#
define secure_getenv getenv
# endif
#endif
...
...
src/network.c
View file @
7a8ded5a
...
...
@@ -16,13 +16,17 @@
#include <arpa/inet.h>
#include <assert.h>
#include <endian.h>
#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#ifdef HAVE_ENDIAN_H
# include <endian.h>
#endif
#include <loc/libloc.h>
#include <loc/compat.h>
#include <loc/country.h>
#include <loc/network.h>
#include <loc/private.h>
...
...
src/perl/Makefile.PL
View file @
7a8ded5a
use
5.028001;
use ExtUtils
::
MakeMaker;
# See lib/ExtUtils/MakeMaker.pm for details of how to influence
# the contents of the Makefile that is written.
...
...
src/stringpool.c
View file @
7a8ded5a
...
...
@@ -68,7 +68,7 @@ static int loc_stringpool_mmap(struct loc_stringpool* pool, FILE* f, size_t leng
if
(
pool
->
mode
!=
STRINGPOOL_MMAP
)
return
-
EINVAL
;
DEBUG
(
pool
->
ctx
,
"Reading string pool starting from %
zu (%zu bytes)
\n
"
,
offset
,
length
);
DEBUG
(
pool
->
ctx
,
"Reading string pool starting from %
jd (%zu bytes)
\n
"
,
(
intmax_t
)
offset
,
length
);
// Map file content into memory
pool
->
data
=
pool
->
pos
=
mmap
(
NULL
,
length
,
PROT_READ
,
...
...
@@ -236,7 +236,7 @@ static off_t loc_stringpool_append(struct loc_stringpool* pool, const char* stri
LOC_EXPORT
off_t
loc_stringpool_add
(
struct
loc_stringpool
*
pool
,
const
char
*
string
)
{
off_t
offset
=
loc_stringpool_find
(
pool
,
string
);
if
(
offset
>=
0
)
{
DEBUG
(
pool
->
ctx
,
"Found '%s' at position %jd
\n
"
,
string
,
offset
);
DEBUG
(
pool
->
ctx
,
"Found '%s' at position %jd
\n
"
,
string
,
(
intmax_t
)
offset
);
return
offset
;
}
...
...
@@ -251,7 +251,7 @@ LOC_EXPORT void loc_stringpool_dump(struct loc_stringpool* pool) {
if
(
!
string
)
break
;
printf
(
"%jd (%zu): %s
\n
"
,
offset
,
strlen
(
string
),
string
);
printf
(
"%jd (%zu): %s
\n
"
,
(
intmax_t
)
offset
,
strlen
(
string
),
string
);
offset
=
loc_stringpool_get_next_offset
(
pool
,
offset
);
}
...
...
src/writer.c
View file @
7a8ded5a
...
...
@@ -14,7 +14,6 @@
Lesser General Public License for more details.
*/
#include <endian.h>
#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
...
...
@@ -22,8 +21,13 @@
#include <sys/queue.h>
#include <time.h>
#ifdef HAVE_ENDIAN_H
# include <endian.h>
#endif
#include <loc/libloc.h>
#include <loc/as.h>
#include <loc/compat.h>
#include <loc/country.h>
#include <loc/format.h>
#include <loc/network.h>
...
...
@@ -231,7 +235,7 @@ static void align_page_boundary(off_t* offset, FILE* f) {
static
int
loc_database_write_pool
(
struct
loc_writer
*
writer
,
struct
loc_database_header_v0
*
header
,
off_t
*
offset
,
FILE
*
f
)
{
// Save the offset of the pool section
DEBUG
(
writer
->
ctx
,
"Pool starts at %jd bytes
\n
"
,
*
offset
);
DEBUG
(
writer
->
ctx
,
"Pool starts at %jd bytes
\n
"
,
(
intmax_t
)
*
offset
);
header
->
pool_offset
=
htobe32
(
*
offset
);
// Write the pool
...
...
@@ -246,7 +250,7 @@ static int loc_database_write_pool(struct loc_writer* writer,
static
int
loc_database_write_as_section
(
struct
loc_writer
*
writer
,
struct
loc_database_header_v0
*
header
,
off_t
*
offset
,
FILE
*
f
)
{
DEBUG
(
writer
->
ctx
,
"AS section starts at %jd bytes
\n
"
,
*
offset
);
DEBUG
(
writer
->
ctx
,
"AS section starts at %jd bytes
\n
"
,
(
intmax_t
)
*
offset
);
header
->
as_offset
=
htobe32
(
*
offset
);
size_t
as_length
=
0
;
...
...
@@ -321,7 +325,7 @@ static void free_network(struct network* network) {
static
int
loc_database_write_networks
(
struct
loc_writer
*
writer
,
struct
loc_database_header_v0
*
header
,
off_t
*
offset
,
FILE
*
f
)
{
// Write the network tree
DEBUG
(
writer
->
ctx
,
"Network tree starts at %jd bytes
\n
"
,
*
offset
);
DEBUG
(
writer
->
ctx
,
"Network tree starts at %jd bytes
\n
"
,
(
intmax_t
)
*
offset
);
header
->
network_tree_offset
=
htobe32
(
*
offset
);
size_t
network_tree_length
=
0
;
...
...
@@ -411,7 +415,7 @@ static int loc_database_write_networks(struct loc_writer* writer,
align_page_boundary
(
offset
,
f
);
DEBUG
(
writer
->
ctx
,
"Networks data section starts at %jd bytes
\n
"
,
*
offset
);
DEBUG
(
writer
->
ctx
,
"Networks data section starts at %jd bytes
\n
"
,
(
intmax_t
)
*
offset
);
header
->
network_data_offset
=
htobe32
(
*
offset
);
// We have now written the entire tree and have all networks
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment