I am having an issue using getservbyport. Here is a little program to demonstrate the problem (removed the includes):
Here is how I am compiling and running this program
I was expecting to see "service name = smtp", since my /etc/services file contains the following two lines:
I tried this on two hosts with the same result. One has gcc 4.1.2 and the other has gcc 2.96. I also get the same result, on both hosts, if I specify the protocol to use when calling getservbyport (instead of NULL which matches any protocol).
Can anyone see what I am doing wrong, or why a NULL result from the call to getservbyport would say "Success" from the perror call? The man page for getservbyport says the following:
It could be reaching EOF, but again, the two lines are present for smtp in my /etc/services file.
I've got a very peculiar situation. I'm trying to find out if we can compare null fields with non-null. I've output csv files from SQL and Oracle. I need to compare each field from the files, and then find out any differences. The files usualy have over 500 fields, and send the resule to DBA.... (8 Replies)
Hi All,
In my application malloc is returning NULL even though there is sufficient amount of free memory is available but swap memory is low.
Is this possible that, if free memory is high & swap memory is low, malloc will not be able to allocate memory & return NULL ?:)
Kindly look into... (5 Replies)
Hi All,:)
In my application malloc is returning NULL even though there is sufficient amount of free memory available but the swap memory is low.
Is this possible that, if free memory is high & swap memory is low, malloc will not be able to allocate memory & return NULL ?
Few details:
... (4 Replies)
Hi,
The following shell script returning null results could you please tell me whats the problem in script,
*********************************
#!/bin/ksh
. $HOME/conf/systemProperties/EnvSetup.properties
a=`date +"%y%m%d"`
set -x
for i in `cat... (2 Replies)
I have an input file having 7 fields delimited by ,
eg :
1,ABC,hg,1,2,34,3
2,hj,YU,2,3,4,
3,JU,kl,4,5,7,
4,JK,KJ,3,56,4,5
The seventh field here in some lines is empty, whereas the other lines there is a value.
How do I insert string NULL at this location (7th loc) for these lines where... (8 Replies)
How are these two different? They both prevent output and error from being displayed. I don't see the use of the "&"
echo "hello" > /dev/null 2>&1
echo "hello" > /dev/null 2>1 (3 Replies)
OS : Solaris 10
When I try to get the "echo" service port, getservbyname is returning null.
I checked - /etc/services having an entry for echo -
echo 7/tcp (But still getservbyname returning null)
Any other config required to consider? (1 Reply)
I apologize if this question has been answered else where or is too elementary.
I ran across a KSH script (long unimportant story) that does this:
if ; then
CAS_SRC_LOG="/var/log/cas_src.log 2>&1"
else
CAS_SRC_LOG="/dev/null 2>&1"
fithen does this:
/usr/bin/echo "heartbeat:... (5 Replies)
I am calling getpwnam_r with all proper argument as below:-
rv = getpwnam_r(name, result, buffer, buflen);
This program runs fine on sol 8/9/10.
But on sol 11 it returns NULL with errno set to 25
(#define ENOTTY 25 /* Inappropriate ioctl for device */)
All boxes are... (2 Replies)
Hi All,
I am using malloc function for allocating dynamic memory.
When I am using below code on Linux server its working fine, but When I am trying the same code on HP UNIX server its returning NULL.
below is a fragment of code in which it is giving problem.
tmp = (format_tree... (4 Replies)
Discussion started by: Taher Saifuddin
4 Replies
LEARN ABOUT NETBSD
setservent
GETSERVENT(3) BSD Library Functions Manual GETSERVENT(3)NAME
getservent, getservbyport, getservbyname, setservent, endservent -- get service entry
LIBRARY
Standard C Library (libc, -lc)
SYNOPSIS
#include <netdb.h>
struct servent *
getservent();
struct servent *
getservbyname(const char *name, const char *proto);
struct servent *
getservbyport(int port, const char *proto);
void
setservent(int stayopen);
void
endservent(void);
DESCRIPTION
The getservent(), getservbyname(), and getservbyport() functions each return a pointer to an object with the following structure containing
the broken-out fields of a line in the network services data base, /etc/services.
struct servent {
char *s_name; /* official name of service */
char **s_aliases; /* alias list */
int s_port; /* port service resides at */
char *s_proto; /* protocol to use */
};
The members of this structure are:
s_name The official name of the service.
s_aliases A NULL terminated list of alternative names for the service.
s_port The port number at which the service resides. Port numbers must be given and are returned in network byte order.
s_proto The name of the protocol to use when contacting the service.
The getservent() function reads the next line of the file, opening the file if necessary.
The setservent() function opens and rewinds the file. If the stayopen flag is non-zero, the net data base will not be closed after each call
to getservbyname() or getservbyport().
The endservent() function closes the file.
The getservbyname() and getservbyport() functions sequentially search from the beginning of the file until a matching protocol name or port
number is found, or until EOF is encountered. If a protocol name is also supplied (non-NULL), searches must also match the protocol.
FILES
/etc/services
DIAGNOSTICS
Null pointer (0) returned on EOF or error.
SEE ALSO getprotoent(3), services(5)HISTORY
The getservent(), getservbyport(), getservbyname(), setservent(), and endservent() functions appeared in 4.2BSD.
BUGS
These functions use static data storage; if the data is needed for future use, it should be copied before any subsequent calls overwrite it.
Expecting port numbers to fit in a 32 bit quantity is probably naive.
BSD May 25, 1995 BSD