Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
P
Postgres FD Implementation
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
Abuhujair Javed
Postgres FD Implementation
Commits
eb3e640e
Commit
eb3e640e
authored
Oct 12, 1998
by
Bruce Momjian
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
New INET functions from D'Arcy J.M. Cain
parent
03ab5f01
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
235 additions
and
10 deletions
+235
-10
src/backend/utils/adt/cash.c
src/backend/utils/adt/cash.c
+13
-4
src/backend/utils/adt/inet.c
src/backend/utils/adt/inet.c
+196
-3
src/include/catalog/pg_proc.h
src/include/catalog/pg_proc.h
+14
-1
src/include/utils/builtins.h
src/include/utils/builtins.h
+11
-1
src/include/utils/cash.h
src/include/utils/cash.h
+1
-1
No files found.
src/backend/utils/adt/cash.c
View file @
eb3e640e
...
...
@@ -9,7 +9,7 @@
* workings can be found in the book "Software Solutions in C" by
* Dale Schumacher, Academic Press, ISBN: 0-12-632360-7.
*
* $Header: /cvsroot/pgsql/src/backend/utils/adt/cash.c,v 1.2
6 1998/09/01 04:32:26
momjian Exp $
* $Header: /cvsroot/pgsql/src/backend/utils/adt/cash.c,v 1.2
7 1998/10/12 04:07:44
momjian Exp $
*/
#include <stdio.h>
...
...
@@ -672,7 +672,7 @@ cashsmaller(Cash *c1, Cash *c2)
* This converts a int4 as well but to a representation using words
* Obviously way North American centric - sorry
*/
const
char
*
text
*
cash_words_out
(
Cash
*
value
)
{
static
char
buf
[
128
];
...
...
@@ -681,7 +681,8 @@ cash_words_out(Cash *value)
Cash
m1
;
Cash
m2
;
Cash
m3
;
text
*
result
;
/* work with positive numbers */
if
(
*
value
<
0
)
{
...
...
@@ -718,8 +719,16 @@ cash_words_out(Cash *value)
strcat
(
buf
,
(
int
)
(
*
value
/
100
)
==
1
?
" dollar and "
:
" dollars and "
);
strcat
(
buf
,
num_word
(
m0
));
strcat
(
buf
,
m0
==
1
?
" cent"
:
" cents"
);
/* capitalize output */
*
buf
=
toupper
(
*
buf
);
return
buf
;
/* make a text type for output */
result
=
(
text
*
)
palloc
(
strlen
(
buf
)
+
VARHDRSZ
);
VARSIZE
(
result
)
=
strlen
(
buf
)
+
VARHDRSZ
;
StrNCpy
(
VARDATA
(
result
),
buf
,
strlen
(
buf
));
return
result
;
}
/* cash_words_out() */
...
...
src/backend/utils/adt/inet.c
View file @
eb3e640e
...
...
@@ -3,7 +3,7 @@
* is for IP V4 CIDR notation, but prepared for V6: just
* add the necessary bits where the comments indicate.
*
* $Id: inet.c,v 1.
2 1998/10/08 02:08:44
momjian Exp $
* $Id: inet.c,v 1.
3 1998/10/12 04:07:46
momjian Exp $
*/
#include <sys/types.h>
...
...
@@ -57,7 +57,9 @@ inet_in(char *src)
}
/* First, try for an IP V4 address: */
ip_family
(
dst
)
=
AF_INET
;
bits
=
inet_net_pton
(
ip_family
(
dst
),
src
,
&
ip_v4addr
(
dst
),
ip_addrsize
(
dst
));
#ifdef BAD
bits
=
inet_net_pton
(
ip_family
(
dst
),
src
,
&
ip_v4addr
(
dst
),
ip_addrsize
(
dst
),
NULL
);
#endif
if
((
bits
<
0
)
||
(
bits
>
32
))
{
/* Go for an IPV6 address here, before faulting out: */
...
...
@@ -84,13 +86,15 @@ inet_out(inet *src)
if
(
ip_family
(
src
)
==
AF_INET
)
{
#ifdef BAD
/* It's an IP V4 address: */
if
(
inet_net_ntop
(
AF_INET
,
&
ip_v4addr
(
src
),
ip_bits
(
src
),
if
(
inet_net_ntop
(
AF_INET
,
&
ip_v4addr
(
src
),
4
,
ip_bits
(
src
),
tmp
,
sizeof
(
tmp
))
<
0
)
{
elog
(
ERROR
,
"unable to print address (%s)"
,
strerror
(
errno
));
return
(
NULL
);
}
#endif
}
else
{
...
...
@@ -265,6 +269,194 @@ inet_cmp(inet *a1, inet *a2)
return
0
;
}
text
*
inet_netmask
(
inet
*
ip
)
{
char
*
dst
,
tmp
[
sizeof
(
"255.255.255.255/32"
)];
if
(
ip_family
(
ip
)
==
AF_INET
)
{
/* It's an IP V4 address: */
int
addr
=
-
1
<<
(
32
-
ip_bits
(
ip
));
/* a little wasteful by why reinvent the wheel? */
#ifdef BAD
if
(
inet_cidr_ntop
(
AF_INET
,
&
addr
,
4
,
-
1
,
tmp
,
sizeof
(
tmp
))
<
0
)
{
elog
(
ERROR
,
"unable to print netmask (%s)"
,
strerror
(
errno
));
return
(
NULL
);
}
#endif
}
else
{
/* Go for an IPV6 address here, before faulting out: */
elog
(
ERROR
,
"unknown address family (%d)"
,
ip_family
(
ip
));
return
(
NULL
);
}
dst
=
palloc
(
strlen
(
tmp
)
+
1
);
if
(
dst
==
NULL
)
{
elog
(
ERROR
,
"unable to allocate memory in inet_netmask()"
);
return
(
NULL
);
}
strcpy
(
dst
,
tmp
);
return
(
dst
);
}
int4
inet_masklen
(
inet
*
ip
)
{
return
ip_bits
(
ip
);
}
text
*
inet_host
(
inet
*
ip
)
{
char
*
dst
,
tmp
[
sizeof
(
"255.255.255.255/32"
)];
if
(
ip_family
(
ip
)
==
AF_INET
)
{
#ifdef BAD
/* It's an IP V4 address: */
if
(
inet_cidr_ntop
(
AF_INET
,
&
ip_v4addr
(
ip
),
4
,
-
1
,
tmp
,
sizeof
(
tmp
))
<
0
)
{
elog
(
ERROR
,
"unable to print host (%s)"
,
strerror
(
errno
));
return
(
NULL
);
}
#endif
}
else
{
/* Go for an IPV6 address here, before faulting out: */
elog
(
ERROR
,
"unknown address family (%d)"
,
ip_family
(
ip
));
return
(
NULL
);
}
dst
=
palloc
(
strlen
(
tmp
)
+
1
);
if
(
dst
==
NULL
)
{
elog
(
ERROR
,
"unable to allocate memory in inet_out()"
);
return
(
NULL
);
}
strcpy
(
dst
,
tmp
);
return
(
dst
);
}
text
*
inet_network_without_bits
(
inet
*
ip
)
{
char
*
dst
,
tmp
[
sizeof
(
"255.255.255.255/32"
)];
if
(
ip_family
(
ip
)
==
AF_INET
)
{
/* It's an IP V4 address: */
int
addr
=
ip_v4addr
(
ip
)
&
(
-
1
<<
(
32
-
ip_bits
(
ip
)));
#ifdef BAD
if
(
inet_cidr_ntop
(
AF_INET
,
&
addr
,
(
int
)(
ip_bits
(
ip
)
/
8
),
-
1
,
tmp
,
sizeof
(
tmp
))
<
0
)
{
elog
(
ERROR
,
"unable to print address (%s)"
,
strerror
(
errno
));
return
(
NULL
);
}
#endif
}
else
{
/* Go for an IPV6 address here, before faulting out: */
elog
(
ERROR
,
"unknown address family (%d)"
,
ip_family
(
ip
));
return
(
NULL
);
}
dst
=
palloc
(
strlen
(
tmp
)
+
1
);
if
(
dst
==
NULL
)
{
elog
(
ERROR
,
"unable to allocate memory in inet_out()"
);
return
(
NULL
);
}
strcpy
(
dst
,
tmp
);
return
(
dst
);
}
text
*
inet_network_with_bits
(
inet
*
ip
)
{
char
*
dst
,
tmp
[
sizeof
(
"255.255.255.255/32"
)];
if
(
ip_family
(
ip
)
==
AF_INET
)
{
/* It's an IP V4 address: */
int
addr
=
ip_v4addr
(
ip
)
&
(
-
1
<<
(
32
-
ip_bits
(
ip
)));
#ifdef BAD
if
(
inet_cidr_ntop
(
AF_INET
,
&
addr
,
(
int
)(
ip_bits
(
ip
)
/
8
),
ip_bits
(
ip
),
tmp
,
sizeof
(
tmp
))
<
0
)
{
elog
(
ERROR
,
"unable to print address (%s)"
,
strerror
(
errno
));
return
(
NULL
);
}
#endif
}
else
{
/* Go for an IPV6 address here, before faulting out: */
elog
(
ERROR
,
"unknown address family (%d)"
,
ip_family
(
ip
));
return
(
NULL
);
}
dst
=
palloc
(
strlen
(
tmp
)
+
1
);
if
(
dst
==
NULL
)
{
elog
(
ERROR
,
"unable to allocate memory in inet_out()"
);
return
(
NULL
);
}
strcpy
(
dst
,
tmp
);
return
(
dst
);
}
text
*
inet_broadcast
(
inet
*
ip
)
{
char
*
dst
,
tmp
[
sizeof
(
"255.255.255.255/32"
)];
if
(
ip_family
(
ip
)
==
AF_INET
)
{
/* It's an IP V4 address: */
int
addr
=
ip_v4addr
(
ip
)
|
~
(
-
1
<<
(
32
-
ip_bits
(
ip
)));
#ifdef BAD
if
(
inet_cidr_ntop
(
AF_INET
,
&
addr
,
4
,
ip_bits
(
ip
),
tmp
,
sizeof
(
tmp
))
<
0
)
{
elog
(
ERROR
,
"unable to print address (%s)"
,
strerror
(
errno
));
return
(
NULL
);
}
#endif
}
else
{
/* Go for an IPV6 address here, before faulting out: */
elog
(
ERROR
,
"unknown address family (%d)"
,
ip_family
(
ip
));
return
(
NULL
);
}
dst
=
palloc
(
strlen
(
tmp
)
+
1
);
if
(
dst
==
NULL
)
{
elog
(
ERROR
,
"unable to allocate memory in inet_out()"
);
return
(
NULL
);
}
strcpy
(
dst
,
tmp
);
return
(
dst
);
}
/*
* Bitwise comparison for V4 addresses. Add V6 implementation!
*/
...
...
@@ -285,3 +477,4 @@ v4bitncmp(unsigned int a1, unsigned int a2, int bits)
return
(
1
);
return
(
0
);
}
src/include/catalog/pg_proc.h
View file @
eb3e640e
...
...
@@ -6,7 +6,7 @@
*
* Copyright (c) 1994, Regents of the University of California
*
* $Id: pg_proc.h,v 1.7
2 1998/10/08 00:19:40
momjian Exp $
* $Id: pg_proc.h,v 1.7
3 1998/10/12 04:07:48
momjian Exp $
*
* NOTES
* The script catalog/genbki.sh reads this file and generates .bki
...
...
@@ -2097,6 +2097,19 @@ DESCR("is-supernet");
DATA
(
insert
OID
=
930
(
inet_supeq
PGUID
11
f
t
f
2
f
16
"869 869"
100
0
0
100
foo
bar
));
DESCR
(
"is-supernet-or-equal"
);
DATA
(
insert
OID
=
940
(
inet_netmask
PGUID
11
f
t
f
1
f
25
"869"
100
0
0
100
foo
bar
));
DESCR
(
"netmask of inet address"
);
DATA
(
insert
OID
=
941
(
inet_masklen
PGUID
11
f
t
f
1
f
23
"869"
100
0
0
100
foo
bar
));
DESCR
(
"netmask length"
);
DATA
(
insert
OID
=
942
(
inet_host
PGUID
11
f
t
f
1
f
25
"869"
100
0
0
100
foo
bar
));
DESCR
(
"host adress"
);
DATA
(
insert
OID
=
943
(
inet_network_without_bits
PGUID
11
f
t
f
1
f
25
"869"
100
0
0
100
foo
bar
));
DESCR
(
"netmask without bits"
);
DATA
(
insert
OID
=
944
(
inet_network_with_bits
PGUID
11
f
t
f
1
f
25
"869"
100
0
0
100
foo
bar
));
DESCR
(
"netmask with bits"
);
DATA
(
insert
OID
=
945
(
inet_broadcast
PGUID
11
f
t
f
1
f
25
"869"
100
0
0
100
foo
bar
));
DESCR
(
"broadcast address"
);
/*
* prototypes for functions pg_proc.c
...
...
src/include/utils/builtins.h
View file @
eb3e640e
...
...
@@ -6,7 +6,7 @@
*
* Copyright (c) 1994, Regents of the University of California
*
* $Id: builtins.h,v 1.6
0 1998/10/08 18:30:49
momjian Exp $
* $Id: builtins.h,v 1.6
1 1998/10/12 04:07:51
momjian Exp $
*
* NOTES
* This should normally only be included by fmgr.h.
...
...
@@ -515,6 +515,9 @@ char *inet_net_ntop(int af, const void *src, int bits, char *dst, size_t size);
/* inet_net_pton.c */
int
inet_net_pton
(
int
af
,
const
char
*
src
,
void
*
dst
,
size_t
size
);
char
*
inet_cidr_ntop
(
int
af
,
const
void
*
src
,
size_t
len
,
int
bits
,
char
*
dst
,
size_t
size
);
int
inet_cidr_pton
(
int
af
,
const
void
*
src
,
void
*
dst
,
size_t
size
,
int
*
used
);
/* inet.c */
inet
*
inet_in
(
char
*
str
);
char
*
inet_out
(
inet
*
addr
);
...
...
@@ -530,6 +533,13 @@ bool inet_sup(inet * a1, inet * a2);
bool
inet_supeq
(
inet
*
a1
,
inet
*
a2
);
int4
inet_cmp
(
inet
*
a1
,
inet
*
a2
);
text
*
inet_netmask
(
inet
*
addr
);
int4
inet_masklen
(
inet
*
addr
);
text
*
inet_host
(
inet
*
addr
);
text
*
inet_network_without_bits
(
inet
*
addr
);
text
*
inet_network_with_bits
(
inet
*
addr
);
text
*
inet_broadcast
(
inet
*
addr
);
/* mac.c */
macaddr
*
macaddr_in
(
char
*
str
);
...
...
src/include/utils/cash.h
View file @
eb3e640e
...
...
@@ -44,6 +44,6 @@ extern Cash *int2_mul_cash(int2 s, Cash *c);
extern
Cash
*
cashlarger
(
Cash
*
c1
,
Cash
*
c2
);
extern
Cash
*
cashsmaller
(
Cash
*
c1
,
Cash
*
c2
);
extern
const
char
*
cash_words_out
(
Cash
*
value
);
extern
text
*
cash_words_out
(
Cash
*
value
);
#endif
/* CASH_H */
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