473,405 Members | 2,185 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,405 software developers and data experts.

passing function's output into C function

I have table with column of type "inet". Then I have my own function
resolveip(text). It works okay when I store IP addres into column typed
as text or varchar. But with type of inet I run into this problem:
select host(acc_ip), resolveip(host(acc_ip)) from access_test limit 15

host | resolveip
----------------+-----------------------------------
212.80.81.141 | Bad IP address: '212.80.81.141.'
212.80.81.141 | Bad IP address: '212.80.81.141'
212.80.81.141 | Bad IP address: '212.80.81.141'
212.80.81.141 | Bad IP address: '212.80.81.141'
80.139.171.208 | Bad IP address: '80.139.171.208*'
212.80.81.141 | Bad IP address: '212.80.81.1418'
212.80.81.141 | Bad IP address: '212.80.81.1418'
211.22.169.82 | Bad IP address: '211.22.169.828'
81.0.234.52 |
62.24.89.106 | Bad IP address: '62.24.89.106`'
81.0.234.52 | Bad IP address: '81.0.234.526'
212.80.81.141 | Bad IP address: '212.80.81.1415'
62.84.131.161 | Bad IP address: '62.84.131.1615'
212.80.81.141 | Bad IP address: '212.80.81.1415'
195.122.204.15 | e0-a11.b1.lan.prg.vol.cz

Is there something I'm missing when data are passed from function to
function?

--
Kamil Kukura

---------------------------(end of broadcast)---------------------------
TIP 1: subscribe and unsubscribe commands go to ma*******@postgresql.org

Nov 12 '05 #1
3 1662
Kamil Kukura wrote:
Is there something I'm missing when data are passed from function to
function?


It is difficult to know what you might be missing when you haven't shown
us the function. Post the code.

Joe
---------------------------(end of broadcast)---------------------------
TIP 4: Don't 'kill -9' the postmaster

Nov 12 '05 #2
Kamil Kukura <ka**@volny.cz> writes:
Is there something I'm missing when data are passed from function to
function?


I get the impression your function is expecting the contents of a text
datum to be null-terminated. It's not.

regards, tom lane

---------------------------(end of broadcast)---------------------------
TIP 9: the planner will ignore your desire to choose an index scan if your
joining column's datatypes do not match

Nov 12 '05 #3
It was problem with allocating needed space, now it's okay. Anyway, the
code of function is being attached..

--
Kamil Kukura

#include <stdio.h>
#include <netdb.h>
#include <sys/socket.h>

#include "postgres.h"
#include "fmgr.h"
#include "utils/palloc.h"
text *create_text(char *data) {
unsigned long r_size;
text *result;

r_size = strlen(data);
result = palloc(r_size + VARHDRSZ);
VARATT_SIZEP(result) = r_size + VARHDRSZ;
memcpy(VARDATA(result), data, r_size);
return(result);
}
PG_FUNCTION_INFO_V1(resolveip);

Datum resolveip(PG_FUNCTION_ARGS) {
struct hostent *host;
struct in_addr addr;
text *ipaddress = (text *)PG_GETARG_TEXT_P(0);
const char *bad_ip_txt = "Bad IP address: '";
char *message;

unsigned long r_size, a_size = VARSIZE(ipaddress) - VARHDRSZ;
char *saddress = (char *)palloc(a_size + 1);

memcpy(saddress, VARDATA(ipaddress), a_size);
saddress[a_size] = 0; /* terminate string */

if (! inet_aton(saddress, &addr)) {
message = palloc(strlen(bad_ip_txt) + a_size + 2);
message[0] = 0;
strcat(message, bad_ip_txt);
strcat(message, saddress);
strcat(message, "'");

PG_RETURN_TEXT_P(create_text(message));
}
host = gethostbyaddr(&addr, sizeof addr, AF_INET);

if (! host) {
PG_RETURN_NULL();
}

PG_RETURN_TEXT_P(create_text(host->h_name));
}
---------------------------(end of broadcast)---------------------------
TIP 5: Have you checked our extensive FAQ?

http://www.postgresql.org/docs/faqs/FAQ.html

Nov 12 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: domeceo | last post by:
can anyone tell me why I cannot pass values in a setTimeout function whenever I use this function it says "menu is undefined" after th alert. function imgOff(menu, num) { if (document.images) {...
58
by: jr | last post by:
Sorry for this very dumb question, but I've clearly got a long way to go! Can someone please help me pass an array into a function. Here's a starting point. void TheMainFunc() { // Body of...
17
by: BlindHorse | last post by:
Help!!! I need someone to tell me why I am getting the err msg error C2440: '=' : cannot convert from 'char *' to 'char' //==================== #include <iostream>
25
by: Victor Bazarov | last post by:
In the project I'm maintaining I've seen two distinct techniques used for returning an object from a function. One is AType function(AType const& arg) { AType retval(arg); // or default...
5
by: Michael | last post by:
Hi, once I read here that it is not 'a good idea' to pass variables that are not initialized to a function. I have void something ( double *vector ); ....
5
by: Bucky Pollard | last post by:
I am calling a PVCS DLL function from C#. According to the documentation, I can pass NULL to any output parameter that I do not want to receive data back for. How do I do this? Every thing I've...
11
by: John Pass | last post by:
Hi, In the attached example, I do understand that the references are not changed if an array is passed by Val. What I do not understand is the result of line 99 (If one can find this by line...
2
by: Nab | last post by:
I have just tried to pass parameters to a procedure in VB 2005 and realised that you only need to pass the input parameter. The output parameter's value will be returned without the need to pass it...
5
by: Markus Ernst | last post by:
Hello A class that composes the output of shop-related data gets some info from the main shop class. Now I wonder whether it is faster to store the info in the output class or get it from the...
0
by: kencana | last post by:
hi All, I got problem in passing data (more than one) from soap client to the soap server. but if i only passing one data at a time, it works successfully.. The following is the error message i...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.